/* ================================================================
   Chawkidar 2.0 — Light Theme · Mobile-First Design System
   ================================================================ */

/* ── DESIGN TOKENS ─────────────────────────────────────────── */
:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --success:       #16a34a;
  --success-light: #f0fdf4;
  --warning:       #d97706;
  --warning-light: #fffbeb;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;

  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;

  --text1:     #0f172a;
  --text2:     #475569;
  --text3:     #94a3b8;

  --platform-amazon:  #ea580c;
  --platform-flipkart:#2563eb;
  --platform-cash:    #16a34a;
  --platform-web:     #7c3aed;

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.08);

  --nav-h:    64px;
  --header-h: 56px;
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text1);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font-family: var(--font);
  font-size: 16px; /* prevents iOS zoom */
}

a { color: var(--primary); text-decoration: none; }

.hidden { display: none !important; }

/* ── TYPOGRAPHY ───────────────────────────────────────────── */
.text-sm   { font-size: 0.8125rem; }
.text-muted { color: var(--text2); }
.text-danger { color: var(--danger); }
.imei-mono  { font-family: 'SF Mono', 'Menlo', monospace; font-size: 0.875rem; letter-spacing: 0.02em; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mb-3 { margin-bottom: 0.75rem; }

/* ── AUTH PAGES ────────────────────────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #eff6ff 0%, #f1f5f9 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.auth-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.auth-title { font-size: 1.625rem; font-weight: 700; color: var(--text1); }
.auth-subtitle { color: var(--text2); font-size: 0.9rem; margin-top: 0.25rem; }

/* ── HEADER ────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: var(--header-h);
}

.header-brand { display: flex; align-items: center; gap: 0.5rem; }
.header-logo  { font-size: 1.25rem; }
.header-title { font-size: 1.125rem; font-weight: 700; color: var(--text1); }
.header-actions { display: flex; gap: 0.25rem; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface2); }

/* Global search bar */
.global-search {
  padding: 0.5rem 1rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.search-input {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--primary); }

/* ── BOTTOM NAV ────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  font-size: 0.625rem;
  font-weight: 500;
  padding: 6px 4px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-item:active { opacity: 0.7; }
.nav-icon { width: 22px; height: 22px; stroke-width: 2; }
.nav-item.active .nav-icon { stroke-width: 2.5; }

/* ── MORE MENU ─────────────────────────────────────────────── */
.more-menu { position: fixed; inset: 0; z-index: 200; }
.more-menu-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.more-menu-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
  animation: slideUp .2s ease-out;
}
.more-menu-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 0 0.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.more-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text1);
  border-radius: var(--radius);
  transition: background .1s;
}
.more-menu-item:active { background: var(--surface2); }
.more-menu-item svg { color: var(--text2); flex-shrink: 0; }
.more-menu-item span:nth-child(2) { flex: 1; text-align: left; }

/* ── PAGE CONTENT ──────────────────────────────────────────── */
.page-content {
  padding-top: calc(var(--header-h) + 0.5rem);
  padding-bottom: calc(var(--nav-h) + 0.5rem);
  min-height: 100dvh;
}

.page-inner {
  max-width: 680px;
  margin: 0 auto;
  padding: 0.75rem 0.875rem;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.page-title { font-size: 1.375rem; font-weight: 700; color: var(--text1); }
.page-date { font-size: 0.8125rem; color: var(--text2); }
.page-bottom-spacer { height: 1rem; }

.page-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40vh;
}

.section-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 1.25rem 0 0.5rem;
}

/* ── CARDS ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.card-table { padding: 0; overflow: hidden; }

.card-list { display: flex; flex-direction: column; gap: 0.625rem; }

/* ── STATS GRID ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  margin-bottom: 1rem;
}
.stats-grid .stat-card:first-child { grid-column: 1 / -1; }

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.stat-card-primary { background: var(--primary); color: white; border-color: var(--primary-dark); }
.stat-card-blue    { background: var(--primary-light); border-color: #bfdbfe; }
.stat-card-orange  { background: var(--warning-light); border-color: #fde68a; }
.stat-card-green   { background: var(--success-light); border-color: #bbf7d0; }
.stat-card-gray    { background: var(--surface2); }

.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.75rem; font-weight: 600; opacity: .75; margin-top: 0.25rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-card-primary .stat-value { color: white; }
.stat-card-primary .stat-label { color: rgba(255,255,255,.85); }

/* ── QUICK ACTIONS ─────────────────────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  padding: 0.875rem 0.25rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: transform .1s, box-shadow .1s;
}
.quick-action-btn:active { transform: scale(0.96); box-shadow: none; }
.qa-icon { font-size: 1.375rem; }
.qa-label { font-size: 0.6875rem; font-weight: 600; color: var(--text2); text-align: center; }

/* ── PLATFORM ROW ──────────────────────────────────────────── */
.platform-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.platform-row:last-child { border-bottom: none; }
.platform-name { min-width: 90px; }
.platform-stats { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; font-size: 0.8125rem; color: var(--text2); }
.ps-sep { color: var(--text3); }

/* ── TABLE ─────────────────────────────────────────────────── */
.table-head {
  display: grid;
  grid-template-columns: 2fr 1.5fr 1.5fr 1.2fr;
  padding: 0.5rem 1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.th { font-size: 0.6875rem; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .06em; }
.table-row {
  display: grid;
  grid-template-columns: 2fr 1.5fr 1.5fr 1.2fr;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.table-row:last-child { border-bottom: none; }
.table-row:active { background: var(--surface2); }
.td { font-size: 0.8125rem; display: flex; align-items: center; }
.imei-cell { font-family: monospace; font-size: 0.8125rem; }

/* ── DEVICE / DISPATCH CARDS ───────────────────────────────── */
.device-card, .dispatch-card, .team-card, .audit-row {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow .1s;
}
.dispatch-card-done  { opacity: .7; }
.dispatch-card-warn  { border-left: 3px solid var(--warning); }
.device-card-expanded { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

.dc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.375rem; }
.dc-mid { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.dc-bot { display: flex; align-items: center; justify-content: space-between; }
.dc-model { font-size: 0.875rem; color: var(--text2); }
.dc-track { font-size: 0.8125rem; color: var(--text2); font-family: monospace; }
.dc-actions { display: flex; gap: 0.375rem; }

/* ── TEAM CARD ─────────────────────────────────────────────── */
.team-card { display: flex; align-items: center; gap: 0.875rem; }
.team-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 1.125rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.team-info { flex: 1; }
.team-name { font-weight: 600; font-size: 0.9375rem; }
.team-actions { display: flex; gap: 0.25rem; }

/* ── AUDIT ROW ─────────────────────────────────────────────── */
.audit-row { display: flex; align-items: center; gap: 0.875rem; }
.audit-badge {
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 700;
  flex-shrink: 0;
}
.badge-green .audit-badge, .audit-action.badge-green  { background: var(--success-light); color: var(--success); }
.audit-action.badge-blue   { background: var(--primary-light); color: var(--primary); }
.audit-action.badge-danger { background: var(--danger-light); color: var(--danger); }
.audit-detail { flex: 1; }
.audit-table  { font-weight: 600; font-size: 0.875rem; }

/* ── ALERTS & INFO BOXES ───────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.alert-warn {
  background: var(--warning-light);
  border: 1px solid #fde68a;
  color: #92400e;
}
.alert-box {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
}
.info-box {
  padding: 0.75rem;
  background: var(--primary-light);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--primary-dark);
}

/* ── FILTERS & SEARCH ──────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}
.search-wrap {
  position: relative;
  flex: 1;
}
.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}
.search-inner { padding-left: 2.25rem !important; }
.filter-select { width: auto; min-width: 110px; }

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.count-label { font-size: 0.8125rem; color: var(--text2); }

/* ── FORMS ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 0.375rem;
}
.required { color: var(--danger); }

.form-input {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text1);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input-lg { font-size: 1.125rem; padding: 0.875rem 1rem; }

.form-select {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text1);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  transition: border-color .15s;
}
.form-select:focus { border-color: var(--primary); }

.form-error {
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  margin-top: 0.375rem;
}

/* ── SCAN INPUT ROW ─────────────────────────────────────────── */
.input-scan-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.input-scan-row .form-input { flex: 1; min-width: 0; }

.btn-scan {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  transition: background .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn-scan:active { background: var(--primary-dark); transform: scale(0.95); }
.btn-scan-lg {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-lg);
}

.scan-big-row { margin-bottom: 0.75rem; }
.scan-lookup-card { padding: 1.25rem; }
.scan-hint { color: var(--text2); font-size: 0.9rem; margin-bottom: 1rem; text-align: center; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: opacity .15s, transform .1s, background .15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary  { background: var(--primary); color: white; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success); color: white; }
.btn-success:hover  { background: #15803d; }
.btn-ghost    { background: var(--surface2); color: var(--text2); border: 1.5px solid var(--border); }
.btn-ghost:hover    { background: var(--bg); }
.btn-outline-white  { background: rgba(255,255,255,.15); color: white; border: 1.5px solid rgba(255,255,255,.4); }
.btn-outline-white:hover { background: rgba(255,255,255,.25); }

.btn-full     { width: 100%; }
.btn-sm       { padding: 0.4375rem 0.875rem; font-size: 0.8125rem; }
.btn-xs       { padding: 0.3125rem 0.625rem; font-size: 0.75rem; }
.btn-icon     { padding: 0.4375rem; border-radius: var(--radius-sm); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem 0.5625rem;
  border-radius: 99px;
  font-size: 0.6875rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-blue    { background: var(--primary-light); color: var(--primary); }
.badge-orange  { background: var(--warning-light);  color: var(--warning); }
.badge-green   { background: var(--success-light);  color: var(--success); }
.badge-gray    { background: var(--surface2);        color: var(--text2); }
.badge-purple  { background: #f5f3ff;               color: #7c3aed; }
.badge-danger  { background: var(--danger-light);   color: var(--danger); }
.badge-warn    { background: var(--warning-light);  color: var(--warning); }

/* ── MODALS ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.modal-open .modal-sheet { transform: translateY(0); }

.modal-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(0.32,0.72,0,1);
  padding-bottom: calc(env(safe-area-inset-bottom, 0) + 0.5rem);
}
.modal-overlay:not(.hidden) .modal-sheet { transform: translateY(0); }

.modal-sheet-sm { max-height: 70dvh; }
.modal-handle { width: 40px; height: 4px; background: var(--border2); border-radius: 99px; margin: 0.75rem auto; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.0625rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text3);
  transition: background .1s;
}
.modal-close:active { background: var(--surface2); }
.modal-body   { padding: 1rem 1.25rem; }
.modal-footer {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── SCANNER OVERLAY ─────────────────────────────────────────── */
.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  display: flex;
  flex-direction: column;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  padding-top: calc(1rem + env(safe-area-inset-top, 0));
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
}
.scanner-title { color: white; font-size: 1rem; font-weight: 600; }
.scanner-close {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.15);
  border-radius: 50%;
  color: white;
}

.scanner-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#scanner-video {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
#scanner-video video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  inset: 50%;
  transform: translate(-50%, -50%);
  width: min(70vw, 280px);
  height: min(70vw, 280px);
}

/* Corners */
.scanner-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: #2563eb;
  border-style: solid;
  border-width: 0;
}
.scanner-corner.tl { top: 0; left: 0;  border-top-width: 3px; border-left-width: 3px;  border-radius: 4px 0 0 0; }
.scanner-corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-radius: 0 4px 0 0; }
.scanner-corner.bl { bottom: 0; left: 0;  border-bottom-width: 3px; border-left-width: 3px;  border-radius: 0 0 0 4px; }
.scanner-corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 4px 0; }

/* Scanning line animation */
.scanner-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #2563eb, transparent);
  animation: scanLine 2s linear infinite;
}
@keyframes scanLine {
  0%   { top: 0; }
  100% { top: 100%; }
}

.scanner-footer {
  padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0));
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  text-align: center;
}
.scanner-hint { color: rgba(255,255,255,.7); font-size: 0.875rem; margin-bottom: 0.875rem; }

/* ── TOAST ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + 0.75rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: min(90vw, 360px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translateY(-12px);
  opacity: 0;
  transition: transform .2s ease-out, opacity .2s ease-out;
  pointer-events: all;
}
.toast-show { transform: translateY(0); opacity: 1; }
.toast-success { background: var(--success); color: white; }
.toast-error   { background: var(--danger);  color: white; }
.toast-warn    { background: var(--warning); color: white; }
.toast-info    { background: var(--text1);   color: white; }
.toast-icon    { font-size: 1rem; flex-shrink: 0; }

/* ── SPINNER ─────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-lg { width: 36px; height: 36px; border-color: var(--border2); border-top-color: var(--primary); border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY & ERROR STATES ───────────────────────────────────── */
.empty-state, .error-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text2);
}
.empty-icon, .error-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-msg  { font-size: 0.9375rem; }
.error-title  { font-weight: 600; font-size: 1rem; color: var(--text1); }
.error-detail { font-size: 0.875rem; margin-top: 0.25rem; }

/* ── SCAN PAGE RESULTS ──────────────────────────────────────── */
.result-found, .result-not-found, .result-error { padding: 1.25rem; }
.result-header { display: flex; align-items: center; gap: 0.625rem; margin-bottom: 1rem; }
.result-icon   { font-size: 1.25rem; }
.result-title  { font-weight: 700; flex: 1; }
.result-details { display: flex; flex-direction: column; gap: 0.5rem; }
.detail-row    { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label  { font-size: 0.8125rem; color: var(--text2); font-weight: 500; }
.detail-val    { font-size: 0.875rem; color: var(--text1); text-align: right; }

.loading-inline { display: flex; align-items: center; gap: 0.625rem; color: var(--text2); padding: 1rem; }
.loading-inline .spinner { border-top-color: var(--primary); border-color: var(--border2); }

/* ── ANIMATIONS ─────────────────────────────────────────────── */
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── TABLET / DESKTOP ───────────────────────────────────────── */
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .stats-grid .stat-card:first-child { grid-column: auto; }
  .quick-actions { grid-template-columns: repeat(4, 1fr); }

  .modal-overlay { align-items: center; }
  .modal-sheet {
    border-radius: var(--radius-xl);
    transform: scale(0.96);
  }
  .modal-overlay:not(.hidden) .modal-sheet { transform: scale(1); }

  .page-inner { padding: 1rem 1.25rem; }

  .scanner-overlay { padding: 2rem; background: rgba(0,0,0,.8); }
  #scanner-video { border-radius: var(--radius-xl); }
}

@media (min-width: 1024px) {
  :root { --header-h: 64px; --nav-h: 72px; }

  .bottom-nav {
    top: 0; bottom: auto;
    height: var(--nav-h);
    border-top: none;
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: none;
  }
  .nav-item { flex-direction: row; gap: 0.5rem; font-size: 0.875rem; flex: none; padding: 0.625rem 1rem; border-radius: var(--radius); }
  .nav-item.active { background: var(--primary-light); }
  .app-header { border-bottom: none; }
  .header-inner { max-width: 1200px; margin: 0 auto; }

  .page-content {
    padding-top: calc(var(--nav-h) + var(--header-h) - 4px);
    max-width: 960px;
    margin: 0 auto;
  }
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
  .stats-grid .stat-card:first-child { grid-column: auto; }
}


/* ── STAT CARD LINKS ───────────────────────────────────────── */
.stat-card-link {
  transition: transform .15s, box-shadow .15s;
}
.stat-card-link:hover, .stat-card-link:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

/* ── DARK THEME ─────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #263245;
  --border:    #334155;
  --border2:   #475569;
  --text1:     #f1f5f9;
  --text2:     #94a3b8;
  --text3:     #64748b;
  --primary-light: #1e3a5f;
  --success-light: #052e16;
  --warning-light: #1c1004;
  --danger-light:  #1c0505;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.3), 0 2px 4px -1px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.4), 0 8px 10px -6px rgba(0,0,0,.3);
}

[data-theme="dark"] .auth-page {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

[data-theme="dark"] body { color-scheme: dark; }

[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .search-input {
  background: var(--surface2);
  color: var(--text1);
  border-color: var(--border2);
}

[data-theme="dark"] .form-input::placeholder,
[data-theme="dark"] .search-input::placeholder { color: var(--text3); }

/* Theme icon: show moon in light mode, sun in dark mode */
.theme-icon-sun  { display: none; }
.theme-icon-moon { display: block; }
[data-theme="dark"] .theme-icon-sun  { display: block; }
[data-theme="dark"] .theme-icon-moon { display: none; }


/* ─── RETURN BUTTON ──────────────────────────────────────────── */
.btn-danger  { background: var(--danger); color: white; }
.btn-danger:hover  { background: #b91c1c; }
.btn-return  { background: var(--warning); color: white; }
.btn-return:hover  { background: #b45309; }

/* ─── DISPATCH CARD ENHANCEMENTS ─────────────────────────────── */
.dispatch-card .dc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}
.dispatch-card .dc-top .imei-mono {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dispatch-card .dc-mid {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.375rem;
}
.dispatch-card .dc-bot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.dispatch-card .dc-actions {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}
.dc-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text3);
  margin-right: 0.2rem;
}
.dispatch-card .dc-track {
  font-size: 0.78rem;
  color: var(--text2);
  font-family: var(--font-mono);
}

/* Status left-border accent */
.dispatch-card.shipped  { border-left: 3px solid var(--primary); }
.dispatch-card.delivered { border-left: 3px solid var(--success); opacity: 0.85; }
.dispatch-card.returned  { border-left: 3px solid var(--warning); opacity: 0.8; }
.dispatch-card.in_stock  { border-left: 3px solid var(--border); }

/* ─── RETURN MODAL ────────────────────────────────────────────── */
.return-device-info {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  margin-bottom: 1rem;
}
.return-device-info p { margin: 0; }
.return-device-info .mb-1 { margin-bottom: 0.25rem; }
.return-device-info .mb-3 { margin-bottom: 0.75rem; }
