/* ============================================================
   DRIVERWATCH — design system
   Brand: Deep Navy #0A2540 · Steel Teal #5B8A9A · Soft Gray #F2F4F7
   Type: Inter (modern geometric sans). Mirrors driverwatch.tech.
   ============================================================ */

:root {
  --navy: #0A2540;
  --navy-hover: #0d2d4d;
  --teal: #5B8A9A;
  --teal-dark: #4a7585;
  --white: #FFFFFF;

  --bg: #F2F4F7;
  --bg-sunken: #E8ECF0;
  --surface: #FFFFFF;
  --border: #E8ECF0;
  --border-strong: #D5DCE3;
  --text: #1C1C1C;
  --text-muted: #6B7280;
  --heading: #0A2540;
  --nav-bg: rgba(242, 244, 247, 0.92);

  --ok: #2D7D46;
  --ok-bg: #EBF5EE;
  --warn: #B45309;
  --warn-bg: #FEF3E2;
  --danger: #C0392B;
  --danger-bg: #FDECEA;

  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(10,37,64,.06), 0 1px 2px rgba(10,37,64,.04);
  --shadow-md: 0 4px 16px rgba(10,37,64,.08), 0 2px 6px rgba(10,37,64,.04);
  --shadow-lg: 0 8px 32px rgba(10,37,64,.12);
  --ease: .2s ease;
  --max-w: 1120px;
  --nav-h: 64px;
  --tabbar-h: 64px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Aliases still referenced by inline styles inside app.js */
  --font-display: var(--font);
  --primary: var(--teal);
  --border-hi: var(--border-strong);
  --sys-border-high: var(--border-strong);
  --acc-muted: var(--text-muted);
  --stat-warn: var(--warn);
  --stat-info: var(--teal);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #071B2E;
  --bg-sunken: #05162A;
  --surface: #0C2740;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.16);
  --text: #E6EDF3;
  --text-muted: #93A4B6;
  --heading: #FFFFFF;
  --nav-bg: rgba(7, 27, 46, 0.92);

  --ok: #5CC28A;
  --ok-bg: rgba(92,194,138,.12);
  --warn: #F0A848;
  --warn-bg: rgba(240,168,72,.12);
  --danger: #F07167;
  --danger-bg: rgba(240,113,103,.12);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.45);

  color-scheme: dark;
}

/* ============================================================
   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);
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
img, video, canvas { max-width: 100%; display: block; }
h1, h2, h3, h4 { font-weight: 600; color: var(--heading); letter-spacing: -.02em; line-height: 1.15; }
h3 { font-size: 1rem; letter-spacing: -.01em; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.text-teal { color: var(--teal); }

.label {
  display: block;
  font-size: .75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--teal);
}

/* ── Brand logo lockup ───────────────────── */
.brand-logo { display: inline-flex; align-items: center; gap: 9px; color: var(--heading); }
.brand-logo__mark { height: 26px; width: auto; flex-shrink: 0; }
/* Real brand mark: navy eye on light surfaces, reversed (white eye) on dark */
.mark-on-dark { display: none; }
:root[data-theme="dark"] .mark-on-light { display: none; }
:root[data-theme="dark"] .mark-on-dark { display: block; }
.brand-logo__word { font-weight: 500; font-size: 1.125rem; letter-spacing: -.02em; line-height: 1; white-space: nowrap; }
.brand-logo--dark { color: var(--white); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius);
  font-size: .9375rem; font-weight: 600; line-height: 1;
  border: 1.5px solid transparent;
  white-space: nowrap;
  transition: transform var(--ease), box-shadow var(--ease), background var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
}
.btn:hover:not(:disabled) { transform: scale(1.02); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(91,138,154,.35); }

.btn--primary { background: var(--teal); color: var(--white); border-color: var(--teal); }
.btn--primary:hover:not(:disabled) { background: var(--teal-dark); border-color: var(--teal-dark); box-shadow: 0 0 0 3px rgba(91,138,154,.22), var(--shadow-md); }
.btn--navy { background: var(--navy); color: var(--white); border-color: var(--navy); }
.btn--navy:hover:not(:disabled) { background: var(--navy-hover); box-shadow: var(--shadow-md); }
.btn--outline { background: var(--surface); color: var(--heading); border-color: var(--border-strong); }
.btn--outline:hover:not(:disabled) { border-color: var(--heading); box-shadow: var(--shadow-sm); }
.btn--danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn--danger-outline:hover:not(:disabled) { background: var(--danger-bg); }
.btn--sm { padding: 8px 14px; font-size: .875rem; }
.btn--lg { padding: 14px 28px; font-size: 1rem; }
.btn--block { width: 100%; }

/* Legacy small button (still emitted by app.js for camera errors) */
.btn-sm {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius);
  border: 1.5px solid var(--border-strong); background: var(--surface);
  color: var(--heading); font-size: .875rem; font-weight: 600;
}

.btn-icon {
  width: 36px; height: 36px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background var(--ease), color var(--ease);
}
.btn-icon:hover { background: var(--bg-sunken); color: var(--heading); }

.text-link { color: var(--teal); font-weight: 500; transition: color var(--ease); }
.text-link:hover { color: var(--heading); }

/* ============================================================
   FORMS
   ============================================================ */
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: .875rem; font-weight: 600; color: var(--heading); }
.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit; font-size: .9375rem;
  color: var(--text); background: var(--surface);
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
  -webkit-appearance: none; appearance: none;
}
.form-input::placeholder { color: var(--text-muted); }
.form-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(91,138,154,.18); }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 36px; cursor: pointer;
}
.input-affix { position: relative; }
.input-affix .form-input { padding-right: 64px; }
.input-affix__btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  padding: 6px 10px; border-radius: 6px;
  font-size: .8125rem; font-weight: 600; color: var(--teal);
}
.input-affix__btn:hover { background: var(--bg); }
.code-input { font-size: 1.5rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }

/* intl-tel-input */
.iti { width: 100%; }
.iti__country-list { color: #1C1C1C; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.iti--separate-dial-code .iti__selected-flag { background: var(--bg); border-radius: var(--radius) 0 0 var(--radius); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card-hd { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-hint { font-size: .8125rem; color: var(--text-muted); }

/* ============================================================
   SPLASH
   ============================================================ */
#splash-guard {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease, visibility .5s ease;
}
body.auth-ready #splash-guard { opacity: 0; visibility: hidden; }
.splash-inner { display: flex; flex-direction: column; align-items: center; color: var(--white); animation: splash-breathe 2.4s ease-in-out infinite; }
.splash-mark { width: 132px; height: auto; }
.splash-word { margin-top: 18px; font-size: 1.75rem; font-weight: 500; letter-spacing: -.02em; }
.splash-tag { margin-top: 6px; font-size: .9375rem; color: rgba(255,255,255,.7); }
.splash-tag span { color: var(--teal); }
@keyframes splash-breathe { 0%,100% { opacity: 1; } 50% { opacity: .75; } }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  background: var(--nav-bg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: content-box;
}
.app-nav__inner {
  height: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.app-nav__logo .brand-logo__mark { height: 24px; }
.app-nav__right { display: flex; align-items: center; gap: 10px; }

.sys-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .04em;
  color: var(--text-muted); background: var(--bg-sunken);
}
.sys-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.sys-badge.ACTIVE { color: var(--ok); background: var(--ok-bg); }
.sys-badge.ACTIVE::before { animation: blink 1.4s ease infinite; opacity: 1; }
.nav-clock { display: none; font-size: .875rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Tab bar — bottom on mobile */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 210;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(10,37,64,.04);
}
.nav-tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-muted);
  font-size: .75rem; font-weight: 500;
  transition: color var(--ease);
}
.nav-tab svg { width: 22px; height: 22px; }
.nav-tab::before {
  content: ''; position: absolute; top: 0; left: 30%; right: 30%; height: 2px;
  background: var(--teal); border-radius: 0 0 2px 2px;
  transform: scaleX(0); transition: transform var(--ease);
}
.nav-tab.active { color: var(--heading); font-weight: 600; }
.nav-tab.active svg { color: var(--teal); }
.nav-tab.active::before { transform: scaleX(1); }

.app-main {
  max-width: var(--max-w); margin: 0 auto;
  padding: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + 20px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
}
.tab-panel { display: none; animation: page-enter .18s ease; }
.tab-panel.active { display: block; }
@keyframes page-enter { from { opacity: 0; } to { opacity: 1; } }

.page-hd { margin-bottom: 20px; }
.page-hd .label { margin-bottom: 6px; }
.page-hd--row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-title { font-size: clamp(1.5rem, 3vw, 2rem); }
.page-sub { margin-top: 6px; font-size: .9375rem; color: var(--text-muted); max-width: 560px; }

.app-footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-top: 40px; padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: .8125rem; color: var(--text-muted);
}
body[data-tab="map"] .app-footer { display: none; }

@media (min-width: 900px) {
  .app-nav__inner { padding: 0 24px; }
  .nav-clock { display: inline; }
  .tabbar {
    top: env(safe-area-inset-top, 0px); bottom: auto; left: 50%; right: auto;
    transform: translateX(-50%);
    height: var(--nav-h); padding: 0;
    display: flex; gap: 2px;
    background: transparent; border: none; box-shadow: none;
  }
  .nav-tab { flex-direction: row; gap: 8px; padding: 0 14px; font-size: .9375rem; }
  .nav-tab svg { width: 18px; height: 18px; }
  .nav-tab:hover { color: var(--teal); }
  .nav-tab::before { top: auto; bottom: 0; left: 14px; right: 14px; height: 2px; border-radius: 2px 2px 0 0; transform-origin: left; }
  .nav-tab:hover::before { transform: scaleX(1); }
  .app-main { padding: calc(var(--nav-h) + 32px) 24px 48px; }
}

/* ============================================================
   MONITOR
   ============================================================ */
.monitor-grid { display: grid; gap: 16px; }
.monitor-main, .monitor-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 960px) {
  .monitor-grid { grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
  .monitor-side { position: sticky; top: calc(var(--nav-h) + 24px); }
}

.camera-hero {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  background: var(--navy);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  outline: 3px solid transparent; outline-offset: -3px;
  transition: outline-color .3s ease;
}
.camera-hero.awake  { outline-color: rgba(45,125,70,.55); }
.camera-hero.sleepy { animation: ring-warn 1s ease infinite; }
.camera-hero.impact { animation: ring-danger .4s ease infinite; }
@keyframes ring-warn   { 0%,100% { outline-color: rgba(192,57,43,.9); } 50% { outline-color: rgba(192,57,43,.25); } }
@keyframes ring-danger { 0%,100% { outline-color: #C0392B; } 50% { outline-color: transparent; } }

#webcam-wrapper { position: absolute; inset: 0; }
#webcam-wrapper canvas { width: 100% !important; height: 100% !important; object-fit: cover; display: block; }

.standby-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px; text-align: center;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(91,138,154,.28), transparent 60%),
    var(--navy);
  color: rgba(255,255,255,.75);
}
.standby-icon { width: 104px; height: auto; opacity: .9; }
.standby-text { font-size: .9375rem; font-weight: 500; color: rgba(255,255,255,.8); }

.camera-overlay { position: absolute; inset: 0; pointer-events: none; }
.cam-badge {
  position: absolute; top: 12px; left: 12px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(10,37,64,.72); color: rgba(255,255,255,.85);
  font-size: .6875rem; font-weight: 600; letter-spacing: .08em;
  backdrop-filter: blur(6px);
}
.cam-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.cam-badge.ONLINE::before { background: #5CC28A; box-shadow: 0 0 0 3px rgba(92,194,138,.25); }
.live-dot {
  position: absolute; top: 16px; right: 16px;
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255,255,255,.3);
}
.live-dot.active { background: #E5484D; animation: blink 1.2s ease infinite; box-shadow: 0 0 0 4px rgba(229,72,77,.25); }

.camera-bottom-hud {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.rec-indicator, .fps-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(10,37,64,.72); color: rgba(255,255,255,.85);
  font-size: .6875rem; font-weight: 600; letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}
.rec-pulse { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.35); }
.rec-pulse.active { background: #E5484D; animation: blink 1s ease infinite; }

@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* Status card */
.status-card {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color .3s ease, background .3s ease;
}
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; background: var(--border-strong); }
.status-title { font-size: 1.0625rem; font-weight: 600; color: var(--heading); letter-spacing: .01em; }
.status-sub { font-size: .875rem; color: var(--text-muted); margin-top: 2px; }

.status-card.awake { border-left-color: var(--ok); }
.status-card.awake .status-dot, .status-dot.awake { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); }
.status-title.awake { color: var(--ok); }
.status-card.sleepy { border-left-color: var(--danger); background: var(--danger-bg); }
.status-card.sleepy .status-dot, .status-dot.sleepy { background: var(--danger); animation: blink .9s ease infinite; }
.status-title.sleepy { color: var(--danger); }
.status-card.impact { border-left-color: var(--danger); background: var(--danger-bg); }
.status-card.impact .status-dot, .status-dot.impact { background: var(--danger); animation: blink .4s ease infinite; }
.status-title.impact { color: var(--danger); }

/* CTA */
.cta-zone { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Metrics */
.bento-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bento-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px; border-radius: var(--radius);
  background: var(--bg);
  transition: background .3s ease;
}
.bento-label { font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.bento-val { font-size: 1.25rem; font-weight: 600; color: var(--heading); letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.bento-card.speeding { background: var(--danger-bg); }
.bento-card.speeding .bento-val, .bento-card.speeding .bento-label { color: var(--danger); }
.stat-card.active-monitoring { background: color-mix(in srgb, var(--teal) 9%, var(--bg)); }

/* AI confidence bars */
.nn-section { display: flex; flex-direction: column; gap: 12px; }
.nn-row { display: grid; grid-template-columns: 76px 1fr 44px; align-items: center; gap: 10px; }
.nn-label { font-size: .75rem; font-weight: 600; letter-spacing: .04em; color: var(--text-muted); }
.nn-track { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.nn-fill { height: 100%; border-radius: 999px; background: var(--teal); transition: width .2s ease; }
.nn-fill.awake { background: var(--ok); }
.nn-fill.sleepy { background: var(--danger); }
.nn-val { font-size: .8125rem; font-weight: 600; color: var(--heading); text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================
   VAULT
   ============================================================ */
.vault-card { padding: 0; overflow: hidden; }
.search-wrap { position: relative; padding: 16px; border-bottom: 1px solid var(--border); }
.search-wrap svg { position: absolute; left: 30px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-wrap .form-input { padding-left: 40px; background: var(--bg); border-color: transparent; }
.search-wrap .form-input:focus { background: var(--surface); border-color: var(--teal); }

.vault-item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--ease);
}
.vault-item:last-child { border-bottom: none; }
.vault-item:hover { background: var(--bg); }
.vault-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vault-type { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--heading); text-transform: capitalize; }
.vault-time { font-size: .875rem; color: var(--text-muted); }
.vault-ref { font-size: .75rem; color: var(--text-muted); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vault-src {
  padding: 2px 8px; border-radius: 999px;
  font-size: .6875rem; font-weight: 600; text-transform: none; letter-spacing: .02em;
  color: var(--text-muted); background: var(--bg-sunken);
}
.vault-src.cloud { color: var(--teal-dark); background: rgba(91,138,154,.14); }
:root[data-theme="dark"] .vault-src.cloud { color: #9CC3D0; }
.vault-actions { display: flex; gap: 6px; flex-shrink: 0; }
.vault-actions button {
  padding: 7px 12px; border-radius: var(--radius);
  font-size: .8125rem; font-weight: 600;
  border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--heading);
  transition: border-color var(--ease), background var(--ease), color var(--ease);
}
.vault-actions button:hover { border-color: var(--heading); }
.vault-actions .btn-play { background: var(--teal); border-color: var(--teal); color: var(--white); }
.vault-actions .btn-play:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.vault-actions .btn-del { color: var(--danger); border-color: transparent; background: transparent; }
.vault-actions .btn-del:hover { background: var(--danger-bg); border-color: transparent; }
@media (max-width: 560px) {
  .vault-item { flex-direction: column; align-items: stretch; }
  .vault-actions button { flex: 1; }
}

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

/* ============================================================
   PROFILE
   ============================================================ */
.profile-grid { display: grid; gap: 16px; }
.profile-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 900px) { .profile-grid { grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; } }

.profile-header-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile-avatar-circle {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--navy); color: var(--white);
  font-size: 1.25rem; font-weight: 600; letter-spacing: .02em;
  box-shadow: 0 0 0 4px rgba(91,138,154,.25);
  flex-shrink: 0;
}
.profile-header-text { flex: 1; min-width: 0; }
.profile-name { font-size: 1.25rem; font-weight: 600; color: var(--heading); letter-spacing: -.01em; }
.profile-role { font-size: .875rem; color: var(--text-muted); }
.btn-toggle-edit.active { background: var(--teal); border-color: var(--teal); color: var(--white); }

.profile-info-stack { padding: 4px 20px; }
.profile-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.profile-row:last-child { border-bottom: none; }
.profile-row--accent .profile-label { color: var(--teal); }
.profile-label { font-size: .875rem; color: var(--text-muted); flex-shrink: 0; }
.profile-value { font-size: .9375rem; font-weight: 500; color: var(--heading); text-align: right; word-break: break-word; }
.profile-editable-input {
  width: 100%; max-width: 240px;
  padding: 8px 10px; border-radius: var(--radius);
  border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9375rem; outline: none;
}
.profile-editable-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(91,138,154,.18); }

.profile-actions { display: flex; flex-direction: column; gap: 10px; }

/* Theme switch */
.theme-toggle-row { display: flex; align-items: center; gap: 12px; }
.theme-opt { font-size: .9375rem; color: var(--text-muted); transition: color var(--ease); }
.theme-opt.active { color: var(--heading); font-weight: 600; }
.switch-container { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch-input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch-slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border-strong); border-radius: 999px;
  transition: background var(--ease);
}
.switch-slider::before {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--white); box-shadow: var(--shadow-sm);
  transition: transform var(--ease);
}
.switch-input:checked + .switch-slider { background: var(--teal); }
.switch-input:checked + .switch-slider::before { transform: translateX(20px); }
.switch-input:focus-visible + .switch-slider { box-shadow: 0 0 0 3px rgba(91,138,154,.35); }

/* System log */
.terminal-container {
  height: 220px; overflow-y: auto;
  padding: 12px; border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--font-mono); font-size: .75rem; line-height: 1.6;
}
.terminal-line { color: var(--text-muted); padding: 1px 0; word-break: break-word; }
.terminal-line .time { color: var(--teal); opacity: .8; }
.terminal-line.t-succ { color: var(--ok); }
.terminal-line.t-warn { color: var(--warn); }
.terminal-line.t-crit { color: var(--danger); font-weight: 600; }
.terminal-line a { color: var(--teal); text-decoration: underline; }

/* ============================================================
   MAP
   ============================================================ */
.map-wrapper {
  position: relative;
  height: calc(100vh - var(--nav-h) - var(--tabbar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 130px);
  min-height: 360px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--bg-sunken);
}
@media (min-width: 900px) {
  .map-wrapper { height: calc(100vh - var(--nav-h) - 150px); }
}
#mapbox-map { position: absolute; inset: 0; }

.map-search-container { position: absolute; top: 12px; left: 12px; right: 60px; z-index: 5; max-width: 520px; }
.map-search-row {
  display: flex; gap: 8px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.map-search-row .form-input { flex: 1; min-width: 0; padding: 9px 12px; }
.map-search-row .btn { padding: 9px 14px; }
#map-search-dropdown {
  display: none; margin-top: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  overflow: hidden; max-height: 280px; overflow-y: auto;
}
#map-search-dropdown.open { display: block; }
.map-search-result { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; }
.map-search-result:last-child { border-bottom: none; }
.map-search-result:hover { background: var(--bg); }
.map-search-result-name { font-weight: 600; color: var(--heading); font-size: .9375rem; }
.map-search-result-sub { font-size: .8125rem; color: var(--text-muted); }

.route-info-card {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 5;
  max-width: 420px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.route-info-main { display: flex; gap: 24px; }
.route-eta-block, .route-dist-block { display: flex; flex-direction: column; }
.route-eta-label, .route-dist-label { font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.route-eta-val, .route-dist-val { font-size: 1.25rem; font-weight: 600; color: var(--heading); font-variant-numeric: tabular-nums; }

.directions-panel {
  position: absolute; top: 80px; right: 12px; z-index: 5;
  width: min(320px, calc(100% - 24px));
  max-height: calc(100% - 180px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  overflow: hidden;
}
.directions-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border); }
.directions-title { font-weight: 600; color: var(--heading); font-size: .9375rem; }
.directions-steps { overflow-y: auto; }
.directions-panel.minimized .directions-steps { display: none; }
.directions-panel.minimized .directions-header { border-bottom: none; }
.direction-step { display: flex; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.direction-step:last-child { border-bottom: none; }
.step-icon { width: 24px; flex-shrink: 0; text-align: center; color: var(--teal); }
.step-instr { font-size: .875rem; color: var(--text); }
.step-dist { font-size: .75rem; color: var(--text-muted); }

.map-advisory {
  position: absolute; left: 50%; top: 80px; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; width: min(360px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.map-advisory-icon { color: var(--warn); flex-shrink: 0; }
.map-advisory-title { font-weight: 600; color: var(--heading); }
.map-advisory-text { font-size: .875rem; color: var(--text-muted); }

.map-user-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--teal); border: 3px solid #fff;
  position: relative; box-shadow: 0 2px 8px rgba(10,37,64,.35);
}
.map-user-pulse { position: absolute; inset: -9px; border-radius: 50%; background: rgba(91,138,154,.3); animation: pulse-ring 2s ease-out infinite; }
@keyframes pulse-ring { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }

.map-bottom-bar { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.map-status-bar { font-size: .875rem; color: var(--text-muted); }
.map-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.map-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: .8125rem; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); }
@media (min-width: 700px) { .map-bottom-bar { flex-direction: row; justify-content: space-between; align-items: center; } }

.maplibregl-popup-content { font-family: var(--font); border-radius: var(--radius) !important; color: #1C1C1C; }

/* ============================================================
   OVERLAYS
   ============================================================ */
.overlay-modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(10,37,64,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: page-enter .15s ease;
}
.modal-inner {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 28px;
}

/* Alarm */
.alarm-wrap { background: rgba(120,20,20,.72); animation: alarm-bg 1s ease infinite; }
@keyframes alarm-bg { 0%,100% { background: rgba(120,20,20,.78); } 50% { background: rgba(10,37,64,.7); } }
.alarm-panel { text-align: center; border-top: 6px solid var(--danger); }
.alarm-icon-ring {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--danger); background: var(--danger-bg);
  animation: blink .9s ease infinite;
}
.alarm-topic-label { font-size: .75rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--danger); }
.alarm-big-title { margin-top: 6px; font-size: 1.5rem; font-weight: 700; color: var(--heading); letter-spacing: -.01em; }
.alarm-countdown-block { margin: 20px 0 24px; padding: 16px; border-radius: var(--radius-lg); background: var(--bg); }
.alarm-countdown-lbl { font-size: .8125rem; color: var(--text-muted); }
.alarm-countdown-num { font-size: 4rem; font-weight: 700; line-height: 1.05; color: var(--danger); font-variant-numeric: tabular-nums; }
.btn-dismiss { background: var(--danger); border-color: var(--danger); color: var(--white); }
.btn-dismiss:hover { filter: brightness(1.08); }

/* Dispatch */
.dispatch-hdr { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.dispatch-icon-ring {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--white); background: var(--danger);
  animation: blink 1.2s ease infinite;
}
.dispatch-topic { font-size: 1.0625rem; font-weight: 600; color: var(--heading); }
.dispatch-status { font-size: .8125rem; font-weight: 600; letter-spacing: .04em; color: var(--warn); }
.dispatch-meta-box { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: var(--radius-lg); background: var(--bg); }
.dispatch-meta-line { font-size: .875rem; color: var(--text); }
.dispatch-meta-line > span:first-child {
  display: inline-block; min-width: 78px;
  font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted);
}
.dispatch-meta-line b { font-weight: 600; color: var(--heading); }
.progress-track { height: 6px; margin: 18px 0 10px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; }
.transfer-fill { height: 100%; background: var(--teal); border-radius: 999px; transition: width .5s ease; }
.call-metrics { display: flex; justify-content: space-between; margin-bottom: 18px; font-size: .8125rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.call-metrics b { color: var(--heading); }
.online { color: var(--ok); font-weight: 600; }

.nearby-services {
  margin: 14px 0 0; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  font-size: .8125rem; max-height: 160px; overflow-y: auto;
}
.nearby-services__title { font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.nearby-services > div { border-bottom-color: var(--border) !important; }
.nearby-services a { color: var(--teal) !important; font-weight: 600; }

/* Vault player */
.vault-player-panel {
  width: 100%; max-width: 880px;
  background: var(--surface); border-radius: var(--radius-xl);
  overflow: hidden; box-shadow: var(--shadow-lg);
}
.vault-player-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 12px 20px; font-weight: 600; color: var(--heading);
}
#vault-player { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; }

/* ============================================================
   AUTH (login.html)
   ============================================================ */
.auth-body { background: var(--bg); }
.auth-layout { min-height: 100vh; display: grid; }
@media (min-width: 960px) { .auth-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.auth-aside { display: none; }
@media (min-width: 960px) {
  .auth-aside {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 40px 56px;
    background:
      radial-gradient(ellipse at 85% 110%, rgba(91,138,154,.35), transparent 55%),
      var(--navy);
    color: var(--white);
  }
  .auth-aside::after {
    content: ''; position: absolute; right: -120px; bottom: -40px;
    width: 520px; height: 400px;
    border: 28px solid rgba(255,255,255,.04); border-radius: 50%;
    pointer-events: none;
  }
}
.auth-aside__logo .brand-logo__mark { height: 28px; }
.auth-aside__body { max-width: 460px; position: relative; z-index: 1; }
.auth-aside__body .label { margin-bottom: 18px; }
.auth-aside__title { font-size: clamp(2.5rem, 4vw, 3.5rem); color: var(--white); line-height: 1.06; letter-spacing: -.03em; }
.auth-aside__title span { color: var(--teal); }
.auth-aside__sub { margin-top: 20px; font-size: 1.0625rem; line-height: 1.7; color: rgba(255,255,255,.68); }
.auth-points { list-style: none; margin-top: 32px; display: flex; flex-direction: column; gap: 14px; }
.auth-points li { display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,.88); }
.auth-points__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(91,138,154,.25); flex-shrink: 0; }
.auth-aside__foot { font-size: .75rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.4); }

.auth-main {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(32px + env(safe-area-inset-top, 0px)) 16px calc(32px + env(safe-area-inset-bottom, 0px));
}
.auth-main__logo { margin-bottom: 28px; }
.auth-main__logo .brand-logo__mark { height: 30px; }
.auth-main__logo .brand-logo__word { font-size: 1.375rem; }
@media (min-width: 960px) { .auth-main__logo { display: none; } }

.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 28px;
}
@media (max-width: 420px) { .auth-card { padding: 22px 18px; } }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin-bottom: 24px;
  background: var(--bg); border-radius: var(--radius);
}
.auth-tab {
  padding: 9px 12px; border-radius: 6px;
  font-size: .875rem; font-weight: 600; color: var(--text-muted);
  transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}
.auth-tab.active { background: var(--surface); color: var(--heading); box-shadow: var(--shadow-sm); }

.auth-title { font-size: 1.5rem; }
.auth-card .label { margin-bottom: 8px; }
.auth-sub { margin: 6px 0 22px; font-size: .9375rem; color: var(--text-muted); }
.auth-sub strong { color: var(--heading); font-weight: 600; }
.auth-card .btn-google + .btn, .auth-card .btn + .btn { margin-top: 10px; }

.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 22px 0;
  font-size: .8125rem; color: var(--text-muted);
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.auth-msg { padding: 10px 14px; border-radius: var(--radius); font-size: .875rem; line-height: 1.5; }
.auth-msg.error { color: var(--danger); background: var(--danger-bg); }
.auth-msg.success { color: var(--ok); background: var(--ok-bg); border: 1px solid rgba(45,125,70,.2); }

.auth-back { display: block; margin: 18px auto 0; font-size: .875rem; }

.consent-row { display: flex; gap: 10px; align-items: flex-start; font-size: .875rem; color: var(--text-muted); line-height: 1.5; cursor: pointer; }
.consent-row input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--teal); flex-shrink: 0; }

.auth-legal { margin-top: 24px; font-size: .8125rem; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
