/* ── Reset e variáveis ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #1e40af;
  --blue-lt: #3b82f6;
  --green:   #15803d;
  --red:     #b91c1c;
  --amber:   #b45309;
  --bg:      #f0f4f8;
  --card:    #ffffff;
  --text:    #0f172a;
  --muted:   #64748b;
  --border:  #cbd5e1;
  --radius:  14px;
  --shadow:  0 2px 12px rgba(0,0,0,.10);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Utilitários ── */
.hidden { display: none !important; }
.text-muted { color: var(--muted); font-size: .85rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

/* ── Topbar ── */
.topbar {
  background: var(--blue);
  color: #fff;
  padding: .9rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar h1 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.topbar .btn-icon {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.topbar .btn-icon:active { background: rgba(255,255,255,.3); }

/* Status online/offline */
.status-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
  background: rgba(255,255,255,.12);
  padding: .2rem .6rem;
  border-radius: 20px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4ade80;
  animation: pulse 2s infinite;
}
.status-dot.offline { background: #f87171; animation: none; }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.5 } }

/* Pendências badge */
.badge-pending {
  background: #f59e0b;
  color: #000;
  border-radius: 20px;
  padding: .1rem .5rem;
  font-size: .72rem;
  font-weight: 700;
}

/* ── Página de login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #1e40af 0%, #3b82f6 100%);
}
.login-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo .logo-icon { font-size: 3rem; margin-bottom: .5rem; }
.login-logo h1 { font-size: 1.6rem; font-weight: 800; color: var(--blue); }
.login-logo p  { font-size: .85rem; color: var(--muted); margin-top: .25rem; }

/* ── Formulários ── */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .4rem;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .85rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  transition: border-color .2s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: var(--blue-lt); }
.form-group textarea { resize: vertical; min-height: 80px; }

.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 3rem; }
.password-wrapper .btn-icon {
  position: absolute; right: .5rem; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  font-size: 1.1rem; cursor: pointer; padding: .5rem;
}

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .85rem 1.5rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  min-height: 52px;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1d3a9e; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red);   color: #fff; }
.btn-gray    { background: #e2e8f0; color: var(--text); }
.btn-outline { background: transparent; border: 2px solid var(--blue); color: var(--blue); }
.btn-full    { width: 100%; }
.btn-sm      { padding: .5rem 1rem; min-height: 38px; font-size: .875rem; }

/* ── Alerts ── */
.alert {
  padding: .85rem 1rem;
  border-radius: 10px;
  font-size: .9rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1e3a8a; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #78350f; border: 1px solid #fde68a; }

/* ── Lista de lotes ── */
.lista-page { padding-bottom: 2rem; }
.lista-search {
  padding: .75rem 1rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 50;
}
.lista-search input {
  width: 100%;
  padding: .7rem 1rem .7rem 2.5rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.868-3.834zM6.5 11a4.5 4.5 0 1 1 0-9 4.5 4.5 0 0 1 0 9z'/%3E%3C/svg%3E") no-repeat .8rem center;
}
.lista-search input:focus { outline: none; border-color: var(--blue-lt); }

.quadra-group { margin-top: .5rem; }
.quadra-header {
  padding: .5rem 1rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--blue);
  background: #e0e7ff;
}

.lote-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 1rem 1rem;
  background: var(--card);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  min-height: 68px;
  gap: .75rem;
  transition: background .1s;
}
.lote-item:active { background: #e0e7ff; }
.lote-item.sem-leitura { border-left: 4px solid var(--amber); }
.lote-item.com-leitura { border-left: 4px solid var(--green); }

.lote-badge {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  padding: .35rem .65rem;
  border-radius: 8px;
  min-width: 56px;
  text-align: center;
  flex-shrink: 0;
}
.lote-badge.verde { background: var(--green); }
.lote-info { flex: 1; }
.lote-nome { font-weight: 600; font-size: 1rem; display: block; }
.lote-status { font-size: .78rem; color: var(--muted); margin-top: .15rem; display: block; }
.lote-arrow { color: var(--muted); font-size: 1.4rem; }

.lista-vazia { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.lista-vazia .icon { font-size: 3rem; margin-bottom: .75rem; }

/* Botão transmitir pendentes */
.btn-transmitir {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--amber);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: .75rem 1.25rem;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  display: flex;
  align-items: center;
  gap: .5rem;
  z-index: 200;
}

/* ── Página de leitura ── */
.leitura-page { padding: 1.25rem; max-width: 600px; margin: 0 auto; }
.leitura-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.leitura-card h2 { font-size: 1rem; color: var(--muted); font-weight: 500; margin-bottom: .25rem; }
.leitura-card h3 { font-size: 1.3rem; font-weight: 700; }
.leitura-badge {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  padding: .3rem .7rem;
  font-size: .9rem;
  font-weight: 700;
  margin-bottom: .5rem;
}

/* Área de foto */
.foto-area {
  border: 3px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 1.25rem;
}
.foto-area:hover, .foto-area.dragging { border-color: var(--blue-lt); background: #eff6ff; }
.foto-area .icon { font-size: 3.5rem; display: block; margin-bottom: .75rem; }
.foto-area p { color: var(--muted); font-size: .9rem; }
.foto-area input[type="file"] { display: none; }

.foto-preview {
  width: 100%;
  border-radius: 10px;
  max-height: 300px;
  object-fit: contain;
  margin-bottom: 1rem;
  background: #000;
}
.btn-trocar-foto {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem 1rem;
  font-size: .85rem;
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}

/* Input de leitura — grande para digitar em campo */
.input-leitura {
  font-size: 2rem !important;
  font-weight: 700 !important;
  text-align: center !important;
  letter-spacing: .1em;
  padding: 1rem !important;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Admin ── */
.admin-page { padding: 1rem; }
.admin-tabs {
  display: flex;
  overflow-x: auto;
  gap: .5rem;
  padding-bottom: .5rem;
  margin-bottom: 1rem;
  scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: .6rem 1.1rem;
  border: 2px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  color: var(--muted);
}
.tab-btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* Cards de dashboard */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.dash-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.dash-card .num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--blue);
  display: block;
}
.dash-card .lbl { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* Tabela */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--card); }
thead th {
  background: var(--blue);
  color: #fff;
  padding: .75rem .9rem;
  text-align: left;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
tbody tr:nth-child(even) { background: #f8fafc; }
tbody td {
  padding: .75rem .9rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: .4rem; }

/* Modal / overlay */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 500;
  padding: 1rem;
}
.modal-sheet {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sheet h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.modal-footer { display: flex; gap: .75rem; margin-top: 1.25rem; }
.modal-footer .btn { flex: 1; }

/* Paginação */
.pagination { display: flex; gap: .4rem; justify-content: center; margin-top: 1rem; }
.page-btn {
  padding: .4rem .75rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
}
.page-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 1rem; left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: min(90vw, 360px);
  pointer-events: none;
}
.toast {
  padding: .9rem 1.1rem;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 500;
  color: #fff;
  animation: slideUp .3s ease;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: .6rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.info    { background: var(--blue); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Foto no admin */
.foto-thumb {
  width: 48px; height: 48px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid var(--border);
}
.foto-full {
  max-width: 100%;
  border-radius: 10px;
  margin: .5rem 0;
}

/* Loading page */
.loading-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 1rem;
  color: var(--muted);
}
.loading-page .spinner.dark { width: 36px; height: 36px; border-width: 4px; }

/* Responsivo */
@media (min-width: 600px) {
  .leitura-page { padding: 2rem; }
  .admin-page { padding: 1.5rem; }
}
