:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #0f1b2d;
  --muted: #5a6778;
  --brand: #0b1f3a;
  --accent: #1c69d4;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --ok-bg: #e3f4ea;
  --warn: #9a6200;
  --warn-bg: #fff2d6;
  --bad: #c0352b;
  --bad-bg: #fde6e4;
  --info-bg: #e6f0fd;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .06);
  --radius: 14px;
  --nav-h: 64px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a111c;
    --surface: #121c2b;
    --surface-2: #1a2638;
    --border: #2a3a52;
    --text: #e8eef7;
    --muted: #9aa8bc;
    --brand: #061426;
    --accent: #4d9bff;
    --accent-ink: #04101f;
    --ok: #5fd08f;
    --ok-bg: #12301f;
    --warn: #f3bd4f;
    --warn-bg: #33270d;
    --bad: #ff7b70;
    --bad-bg: #3a1614;
    --info-bg: #13263f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.mono { font-family: var(--mono); letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.right { text-align: right; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: .75rem; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.topbar .brand { font-weight: 700; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; color: #fff; }
.topbar .brand img { width: 26px; height: 26px; border-radius: 6px; }
.topbar .who { margin-left: auto; font-size: .85rem; opacity: .85; text-align: right; }
.topbar .who a { color: #cfe3ff; }
.topnav { display: none; gap: 4px; margin-left: 16px; }
.topnav a { color: #cfd9e8; padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.topnav a.active, .topnav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.net-pill { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.15); }
.net-pill.off { background: #c0352b; }
main.content { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
main.content.flush { padding: 0; max-width: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600; text-decoration: none; position: relative;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }
.tabbar .badge { position: absolute; top: 6px; right: calc(50% - 22px); }
@media (min-width: 900px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  main.content { padding-bottom: 32px; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.pad-0 { padding: 0; overflow: hidden; }
.card + .card { margin-top: 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 900px) { .grid.split { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); align-items: start; } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.stat.bad .v { color: var(--bad); }
.stat.ok .v { color: var(--ok); }
button.stat { text-align: left; cursor: pointer; font: inherit; color: inherit; }
button.stat.sel { outline: 2px solid var(--accent); }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.big { min-height: 60px; font-size: 1.15rem; border-radius: 14px; padding: 14px 20px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: .85rem; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

label.f { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
.field + .field { margin-top: 10px; }
.inline-check { display: flex; gap: 8px; align-items: center; font-weight: 500; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--accent); }
.badge.count { background: var(--bad); color: #fff; min-width: 18px; justify-content: center; }

.alert { border-radius: 12px; padding: 10px 12px; font-size: .9rem; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--info-bg); color: var(--text); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 14px; scrollbar-width: none; }
.tabs a, .tabs button { background: none; border: 0; font: inherit; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; text-decoration: none; }
.tabs .active { color: var(--accent); border-bottom-color: var(--accent); }

table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow: auto; max-height: 70vh; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list > li.click { cursor: pointer; }
.list > li.click:hover { background: var(--surface-2); }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); display: grid; justify-items: center; z-index: 2100; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; max-width: 92vw; }
@media (min-width: 900px) { .toast-wrap { bottom: 24px; } }

.sheet-back { position: fixed; inset: 0; background: rgba(5, 12, 22, .55); z-index: 2000; /* above map panes and controls (Leaflet uses up to 1000) */ display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h2 { margin-bottom: 12px; }

/* ---------- Scanner ---------- */
.scan-wrap { position: relative; background: #000; height: calc(100vh - var(--nav-h) - 58px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 420px; overflow: hidden; color: #fff; }
@media (min-width: 900px) { .scan-wrap { height: calc(100vh - 58px); max-width: 720px; margin: 0 auto; border-radius: 0 0 16px 16px; } }
.scan-wrap video, .scan-wrap .cam-fallback { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-fallback { display: grid; place-items: center; text-align: center; padding: 24px; background: #0b1523; }
.scan-guide { position: absolute; left: 6%; right: 6%; top: 38%; height: 16%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.38); pointer-events: none; transition: border-color .15s; }
.scan-guide.hit { border-color: #4dff9a; }
.scan-guide .hint { position: absolute; top: -30px; left: 0; right: 0; text-align: center; font-size: .85rem; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scan-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: flex-start; z-index: 2; }
.zone-chip { display: flex; align-items: center; gap: 8px; background: rgba(8, 18, 32, .82); backdrop-filter: blur(6px); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 12px; padding: 8px 12px; font-weight: 700; cursor: pointer; font-size: .95rem; text-align: left; min-height: 48px; }
.zone-chip .lbl { font-size: .68rem; opacity: .75; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; display: block; }
.zone-chip.warn { border-color: #f3bd4f; box-shadow: 0 0 0 2px rgba(243,189,79,.4); }
.zone-chip .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid #fff; }
.scan-status { margin-left: auto; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.pill-dark { background: rgba(8, 18, 32, .82); color: #fff; border-radius: 99px; padding: 5px 10px; font-size: .75rem; font-weight: 700; border: 1px solid rgba(255,255,255,.2); white-space: nowrap; }
.pill-dark.warn { background: #8a5a00; }
.pill-dark.bad { background: #9b2a22; }
.scan-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px 14px; display: grid; gap: 10px; z-index: 2; background: linear-gradient(transparent, rgba(0,0,0,.75) 35%); }
.scan-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.scan-actions .btn { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25); min-height: 54px; font-size: .88rem; flex-direction: column; gap: 2px; }
.scan-actions .btn svg { width: 22px; height: 22px; }
.scan-actions .btn.on { background: rgba(77, 163, 255, .45); }
.saved-banner { background: #14532d; border: 1px solid #4ade80; color: #fff; border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; }
.saved-banner.pending { background: #5a4100; border-color: #f3bd4f; }
.saved-banner .mono { font-size: 1.05rem; font-weight: 700; }
.ocr-busy { position: absolute; top: 56%; left: 0; right: 0; text-align: center; font-weight: 700; text-shadow: 0 1px 3px #000; }

.review { max-width: 640px; margin: 0 auto; }
.vin-display { font-family: var(--mono); font-size: clamp(1.25rem, 6.2vw, 2rem); font-weight: 700; letter-spacing: .06em; display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; padding: 12px 6px; background: var(--surface-2); border-radius: 12px; }
.vin-display span { padding: 0 1px; border-radius: 4px; }
.vin-display .amb { background: var(--warn-bg); color: var(--warn); box-shadow: inset 0 -3px 0 var(--warn); }
.vin-display .inv { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 -3px 0 var(--bad); }
.vin-display .cd { text-decoration: underline; text-underline-offset: 5px; }
.vin-display .suffix { color: var(--accent); }
.vin-input { font-family: var(--mono); font-size: 1.2rem; letter-spacing: .08em; text-transform: uppercase; text-align: center; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest button { font-family: var(--mono); }
.zone-picker .opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; margin-bottom: 6px; min-height: 52px; }
.zone-picker .opt.sub { margin-left: 22px; width: calc(100% - 22px); font-weight: 500; }
.zone-picker .opt.sel { border-color: var(--accent); background: var(--info-bg); }
.zone-picker .opt .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.gps-line { display: flex; align-items: center; gap: 8px; font-size: .85rem; }

/* ---------- Vehicle ---------- */
.veh-head h1 { margin-bottom: 2px; }
.vin-copy { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-weight: 600; background: var(--surface-2); padding: 4px 10px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; color: var(--text); font-size: .95rem; }
.lastseen { border-left: 4px solid var(--accent); }
.lastseen.low { border-left-color: var(--warn); }
.lastseen.none { border-left-color: var(--border); }
.lastseen .big { font-size: 1.15rem; font-weight: 700; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 12px 14px 12px 34px; border-bottom: 1px solid var(--border); }
.timeline li::before { content: ""; position: absolute; left: 14px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline li.invalid { opacity: .62; }
.timeline li.invalid::before { background: var(--bad); }
.timeline li.invalid .zl { text-decoration: line-through; }
.timeline li.latest::before { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }
.timeline .annot { margin-top: 6px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; font-size: .85rem; }
.map { width: 100%; height: 340px; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.map.tall { height: calc(100vh - 58px - var(--nav-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top)); border-radius: 0; }
@media (min-width: 900px) { .map.tall { height: calc(100vh - 58px); } }
.map-caption { font-size: .78rem; color: var(--muted); margin-top: 6px; }
.map-overlay { position: absolute; z-index: 1000; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.map-overlay .card { padding: 8px 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 12px; font-size: .78rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars-x { display: flex; gap: 3px; font-size: .65rem; color: var(--muted); }
.bars-x span { flex: 1; text-align: center; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 40px; gap: 8px; align-items: center; font-size: .85rem; margin-bottom: 6px; }
.hbar .track { background: var(--surface-2); border-radius: 99px; height: 10px; overflow: hidden; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 99px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0b1f3a, #16345e); }
.login .card { width: 100%; max-width: 400px; }
.login .logo { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.login .logo img { width: 44px; height: 44px; border-radius: 10px; }

.leaflet-popup-content { font: 13px/1.4 -apple-system, BlinkMacSystemFont, sans-serif; }
.map-pop b { display: block; }
.zone-label { background: rgba(8,18,32,.75); color: #fff; border: 0; border-radius: 6px; padding: 2px 6px; font-weight: 700; font-size: 11px; box-shadow: none; }
.zone-label::before { display: none; }
