/* ============================================================
   SUPLEN INVENTÁRIO — DESIGN SYSTEM (Mobile-First v2)
   ============================================================ */
:root {
  --bg-base:     #001a3d;
  --bg-surface:  #002452;
  --bg-card:     #002d66;
  --bg-input:    #f1f5f9;
  --border:      #003d8a;
  --border-light:#004dab;

  --accent:      #ff6b00;
  --accent-hover:#e56000;
  --accent-glow: rgba(255,107,0,0.25);

  --success:     #22c55e;
  --success-bg:  rgba(34,197,94,0.12);
  --danger:      #ef4444;
  --danger-bg:   rgba(239,68,68,0.12);
  --warning:     #f59e0b;
  --warning-bg:  rgba(245,158,11,0.12);

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  --font:       'Inter', system-ui, -apple-system, sans-serif;
  --radius:     12px;
  --radius-sm:  8px;
  --radius-lg:  18px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);
  --transition: 0.2s ease;

  /* Bottom nav height on mobile */
  --bottom-nav-h: 68px;
  /* Header height */
  --header-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ============================================================
   SCREENS
   ============================================================ */
.screen { display: none; }
.screen.active { display: block; }

/* Content screens sit below header and above bottom nav */
.content-screen {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--bottom-nav-h) + 12px);
  min-height: 100dvh;   /* dvh = dynamic viewport height (handles mobile browser chrome) */
}

.screen-inner {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 8px;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-bg {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59,130,246,0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(99,102,241,0.14) 0%, transparent 55%),
    var(--bg-base);
  padding: 20px 16px;
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 24px 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon {
  font-size: 52px;
  margin-bottom: 12px;
  display: block;
  filter: drop-shadow(0 0 18px var(--accent));
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo h1 {
  font-size: 1.55rem;
  font-weight: 800;
  color: #fff;
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 5px;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.field-group {
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 7px;
}

.field-group input,
.field-group select,
.select-small {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-sm);
  color: #0f172a;
  font-family: var(--font);
  font-size: 1rem;
  padding: 13px 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.field-group input:focus,
.field-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }

.btn-eye {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.05rem;
  padding: 6px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 22px;
  min-height: 48px;
  transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 14px var(--accent-glow);
  touch-action: manipulation;
}
.btn-primary:hover { opacity: 0.88; transform: translateY(-1px); }
.btn-primary:active { opacity: 0.75; transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 12px 20px;
  min-height: 48px;
  transition: background var(--transition), border-color var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
.btn-secondary:hover { background: var(--bg-surface); border-color: var(--border-light); }
.btn-secondary:active { opacity: 0.75; }

.btn-export {
  background: rgba(34,197,94,0.15);
  border: 1.5px solid var(--success);
  border-radius: var(--radius-sm);
  color: var(--success);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
  touch-action: manipulation;
}
.btn-export:hover  { background: rgba(34,197,94,0.25); }
.btn-export:active { opacity: 0.75; }

.btn-full  { width: 100%; }
.btn-large { padding: 17px 28px; font-size: 1.1rem; min-height: 54px; }

.btn-danger-outline {
  background: rgba(239,68,68,0.1);
  border: 1.5px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 18px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  touch-action: manipulation;
}
.btn-danger-outline:hover  { background: var(--danger); color: #fff; }
.btn-danger-outline:active { opacity: 0.75; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 8px;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  touch-action: manipulation;
}
.btn-icon:hover { color: var(--accent); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.9rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-error   { background: var(--danger-bg);  border-color: var(--danger);  color: #fca5a5; }
.alert-success { background: var(--success-bg); border-color: var(--success); color: #86efac; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: #fde68a; }

/* ============================================================
   HEADER (top bar — compact on mobile)
   ============================================================ */
#global-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(15,23,42,0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.header-logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex: 1;
}

/* Desktop nav inside header — hidden on mobile, shown via bottom nav */
#header-nav {
  display: none;
}

.btn-logout {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 8px 12px;
  min-height: 40px;
  white-space: nowrap;
  transition: all var(--transition);
  touch-action: manipulation;
}
.btn-logout:hover  { border-color: var(--danger); color: var(--danger); }
.btn-logout:active { opacity: 0.75; }

/* ============================================================
   BOTTOM NAVIGATION (mobile-first)
   ============================================================ */
#bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--bottom-nav-h);
  background: rgba(15,23,42,0.96);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  align-items: stretch;
  justify-content: stretch;
}
#nav-painel, #nav-usuarios,
#bnav-painel, #bnav-usuarios { display: none; }

.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color var(--transition), background var(--transition);
  touch-action: manipulation;
  padding: 6px 4px 0;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-btn .nav-icon {
  font-size: 1.5rem;
  line-height: 1;
  transition: transform var(--transition);
}

.bottom-nav-btn:active .nav-icon {
  transform: scale(0.88);
}

.bottom-nav-btn.active {
  color: var(--accent);
}

.bottom-nav-btn.active .nav-icon {
  filter: drop-shadow(0 0 6px var(--accent));
}

/* Active indicator bar */
.bottom-nav-btn::before {
  content: '';
  position: absolute;
  top: 0;
  width: 32px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
  opacity: 0;
  transition: opacity var(--transition);
}

.bottom-nav-btn { position: relative; }

.bottom-nav-btn.active::before {
  opacity: 1;
}

/* ============================================================
   SCANNER SCREEN
   ============================================================ */
.scanner-header {
  text-align: center;
  margin-bottom: 14px;
}

.scanner-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.scanner-subtitle {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-top: 3px;
}

/* Scanner box: use most of viewport height for camera */
.scanner-box {
  position: relative;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 14px;
  /* Take up to 45% of viewport height — enough room for controls below */
  height: min(340px, 45dvh);
  width: 100%;
}

.qr-reader-area {
  width: 100% !important;
  height: 100% !important;
}

/* Override html5-qrcode injected styles */
#reader {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
}
#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}
#reader__scan_region     { border: none !important; }
#reader__dashboard       { display: none !important; }
#reader__header_message  { display: none !important; }
#reader__status_span     { display: none !important; }
#reader__scan_region img { display: none !important; }

.scanner-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-surface);
}

.scanner-icon { font-size: 3.5rem; }
.scanner-idle p { color: var(--text-muted); font-size: 0.9rem; }

@keyframes pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%       { transform: scale(1.08); opacity: 0.7; }
}
.pulse { animation: pulse 2s ease-in-out infinite; }

/* Scanner targeting overlay */
.scanner-box.scanning::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(#3b82f6 1px, transparent 1px) 0 0 / 100% 100%,
    linear-gradient(90deg, #3b82f6 1px, transparent 1px) 0 0 / 100% 100%;
  background-size: 30% 30%;
  opacity: 0;
  animation: scanLine 2s linear infinite;
}

@keyframes scanLine {
  0%   { opacity: 0; background-position: 0 0; }
  10%  { opacity: 0.08; }
  90%  { opacity: 0.06; }
  100% { opacity: 0; background-position: 0 100%; }
}

.scanner-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.scanner-controls .btn-primary,
.scanner-controls .btn-secondary {
  flex: 1;
}

/* BIP / TECLADO SECTION */
.bip-section {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 14px;
  animation: feedbackIn 0.2s ease;
}
.bip-section.hidden {
  display: none;
}
.btn-bip-toggle {
  flex: 1;
}
.bip-desc {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 0 14px 0;
  line-height: 1.4;
}
.input-bip {
  width: 100%;
  padding: 16px 18px;
  font-size: 18px;
  border: 2px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--surface-0);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease;
}
.input-bip:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 0, 0.15);
}
.input-bip::placeholder {
  color: var(--text-muted);
  font-size: 16px;
}
/* SCAN FEEDBACK */
.scan-feedback {
  margin-bottom: 14px;
  animation: feedbackIn 0.25s ease;
}

@keyframes feedbackIn {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

.feedback-card {
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 2px solid;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
}
.feedback-card.success   { background: var(--success-bg); border-color: var(--success); }
.feedback-card.duplicate { background: var(--danger-bg);  border-color: var(--danger); }

.feedback-icon   { font-size: 1.8rem; }
.feedback-status { font-size: 1.05rem; font-weight: 700; }
.feedback-card.success   .feedback-status { color: var(--success); }
.feedback-card.duplicate .feedback-status { color: var(--danger); }
.feedback-detail { font-size: 0.82rem; color: var(--text-secondary); }
.feedback-qr     { font-size: 0.78rem; color: var(--text-muted); font-family: monospace; word-break: break-all; }

/* ============================================================
   LEITURAS LIST
   ============================================================ */
.recent-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h3 { font-size: 0.95rem; font-weight: 600; }

.leituras-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 280px;
  overflow-y: auto;
}

.leitura-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
  transition: border-color var(--transition);
}
.leitura-item:hover { border-color: var(--border-light); }

.leitura-badge {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.leitura-badge.novo      { background: var(--success); box-shadow: 0 0 7px var(--success); }
.leitura-badge.duplicado { background: var(--danger);  box-shadow: 0 0 7px var(--danger); }

.leitura-qr {
  font-family: monospace;
  font-size: 0.88rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leitura-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
  flex-shrink: 0;
}
.leitura-status { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.leitura-status.novo      { color: var(--success); }
.leitura-status.duplicado { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.875rem;
}

/* ============================================================
   PAINEL ADMIN
   ============================================================ */
.painel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.painel-header h2 { font-size: 1.25rem; font-weight: 700; }

.stats-cards {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  flex: 1;
  max-width: 180px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  transition: border-color var(--transition);
}
.stat-total { border-color: var(--accent);   background: rgba(59,130,246,0.08); }
.stat-novo  { border-color: var(--success);  background: var(--success-bg); }
.stat-dup   { border-color: var(--danger);   background: var(--danger-bg); }

.stat-number {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 5px;
}
.stat-total .stat-number { color: var(--accent); }
.stat-novo  .stat-number { color: var(--success); }
.stat-dup   .stat-number { color: var(--danger); }

.stat-label {
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* Filtros */
.filtros-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.filtros-filial-box { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.field-group-full { flex: 1; }

.filtros-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.filtros-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.filtros-actions > * { flex: 1; min-width: 100px; }

/* Ranking */
.ranking-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.ranking-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; }

.ranking-lista { display: flex; flex-direction: column; gap: 9px; }

.ranking-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color var(--transition);
}
.ranking-item:hover { border-color: var(--border-light); }

.ranking-pos { font-size: 1.1rem; font-weight: 800; width: 22px; text-align: center; flex-shrink: 0; }
.ranking-pos.pos-1 { color: #fbbf24; }
.ranking-pos.pos-2 { color: #94a3b8; }
.ranking-pos.pos-3 { color: #b45309; }

.ranking-info { flex: 1; min-width: 0; }
.ranking-nome { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-sub  { font-size: 0.73rem; color: var(--text-muted); margin-top: 2px; }

.ranking-count { text-align: right; flex-shrink: 0; }
.ranking-count .num   { font-size: 1.2rem; font-weight: 800; color: var(--accent); display: block; }
.ranking-count .label { font-size: 0.66rem; color: var(--text-muted); text-transform: uppercase; }

.ranking-progress {
  width: 100%;
  background: var(--bg-surface);
  border-radius: 4px;
  height: 3px;
  margin-top: 5px;
  overflow: hidden;
}
.ranking-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  border-radius: 4px;
  transition: width 0.6s ease;
}

/* ============================================================
   USUÁRIOS TABLE — cards on mobile, table on desktop
   ============================================================ */
.usuarios-table-wrap { overflow-x: auto; }

/* Mobile: card layout */
.user-cards { display: flex; flex-direction: column; gap: 10px; }

.user-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.user-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-card-info { flex: 1; min-width: 0; }
.user-card-nome  { font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card-login { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }

.user-card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.user-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-admin    { background: rgba(99,102,241,0.2);  color: #818cf8; border: 1px solid rgba(99,102,241,0.4); }
.badge-operador { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.badge-ativo    { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.badge-inativo  { background: var(--danger-bg);  color: var(--danger);  border: 1px solid rgba(239,68,68,0.3); }

.action-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-tbl {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 7px 10px;
  min-height: 36px;
  transition: all var(--transition);
  flex: 1;
  text-align: center;
  touch-action: manipulation;
}
.btn-tbl:hover        { border-color: var(--accent); color: var(--accent); }
.btn-tbl.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-tbl:active { opacity: 0.7; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: flex-end;  /* Sheet from bottom on mobile */
  justify-content: center;
  padding: 0;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  animation: slideSheet 0.28s ease;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@keyframes slideSheet {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}
/* Drag handle visual hint */
.modal-header::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
}

.modal-header h3 { font-size: 1.05rem; font-weight: 700; }

.btn-modal-close {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
  touch-action: manipulation;
}
.btn-modal-close:hover  { color: var(--danger); }
.btn-modal-close:active { opacity: 0.7; }

.modal-corpo { padding: 18px 20px 24px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  /* Sit above bottom nav */
  bottom: calc(var(--bottom-nav-h) + 12px);
  left: 12px;
  right: 12px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);

  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 15px;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInUp 0.3s ease, fadeOutDown 0.3s ease 2.8s forwards;
  pointer-events: all;
}
@keyframes slideInUp   { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOutDown { from { opacity: 1; transform: translateY(0); }    to { opacity: 0; transform: translateY(8px); } }

.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }

/* ============================================================
   OFFLINE INDICATOR & PENDING BADGE
   ============================================================ */
.offline-indicator {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--warning);
  color: #000;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

.pending-badge {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 99;
  background: var(--warning);
  color: #000;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  box-shadow: 0 2px 12px rgba(245,158,11,0.4);
  white-space: nowrap;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.select-small {
  font-size: 0.82rem;
  padding: 8px 10px;
  width: auto;
  min-width: 140px;
  min-height: 38px;
}

/* ============================================================
   DESKTOP BREAKPOINT (≥ 768px)
   Switch to top nav, hide bottom nav, expand layouts
   ============================================================ */
@media (min-width: 768px) {
  :root {
    --header-h: 64px;
    --bottom-nav-h: 0px;
  }

  .content-screen {
    padding-bottom: 48px;
  }

  /* Show top nav, hide bottom nav */
  #header-nav   { display: flex; gap: 4px; }
  #bottom-nav   { display: none; }

  .header-logo  { flex: 0 0 auto; }

  .nav-btn {
    background: none;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 7px 13px;
    white-space: nowrap;
    transition: all var(--transition);
  }
  .nav-btn:hover  { background: var(--bg-card); color: var(--text-primary); }
  .nav-btn.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); font-weight: 600; }

  /* Modal as centered dialog on desktop */
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  .modal-box {
    border-radius: var(--radius-lg);
    max-width: 480px;
    padding-bottom: 0;
  }
  .modal-box::before { display: none; }
  .modal-header::before { display: none; }

  @keyframes slideSheet {
    from { transform: translateY(12px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0)    scale(1);    opacity: 1; }
  }

  /* Scanner larger on desktop */
  .scanner-box { height: 400px; }

  /* Bigger stats numbers */
  .stat-number { font-size: 2.2rem; }
  .stat-label  { font-size: 0.72rem; }

  /* Toast back to bottom-right on desktop */
  .toast-container {
    bottom: 20px;
    left: auto;
    right: 20px;
    max-width: 340px;
  }
}

/* ============================================================
   VERY SMALL PHONES (≤ 360px)
   ============================================================ */
@media (max-width: 360px) {
  .stats-cards { gap: 7px; }
  .stat-number { font-size: 1.5rem; }
  .stat-label  { font-size: 0.62rem; }
  .filtros-row { grid-template-columns: 1fr; }
  .login-card  { padding: 28px 18px 22px; }
}

/* ============================================================
   SELEÇÃO DE FILIAL
   ============================================================ */
.filial-bg {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59,130,246,0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(99,102,241,0.14) 0%, transparent 55%),
    var(--bg-base);
  padding: 20px 16px;
}

.filial-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 24px 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.4s ease;
}

.filial-logo {
  text-align: center;
  margin-bottom: 20px;
}
.filial-logo .logo-icon {
  font-size: 2.8rem;
  margin-bottom: 8px;
}
.filial-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.filial-subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.filial-user-info {
  text-align: center;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 20px;
  padding: 8px 12px;
  background: var(--accent-glow);
  border-radius: var(--radius-sm);
}

.filiais-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.filial-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px 10px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform 0.15s ease;
  color: var(--text-primary);
  text-align: center;
}
.filial-btn:hover {
  border-color: var(--accent);
  background: rgba(255,107,0,0.08);
  transform: translateY(-2px);
}
.filial-btn.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 0 3px rgba(255,107,0,0.2);
}
.filial-codigo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
}
.filial-nome {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Badge no scanner */
.filial-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.btn-trocar-filial {
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-trocar-filial:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Resumo de filiais no painel admin */
.filiais-resumo {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.filial-resumo-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex: 1;
  min-width: 140px;
}
.filial-resumo-codigo {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
}
.filial-resumo-nome {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.filial-resumo-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Tag de filial nas leituras do painel */
.leitura-filial-tag {
  display: inline-block;
  padding: 1px 7px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
}
