/* MPWT blue & gold theme. Loaded last; restyles only, no markup or behaviour changes. */

/* ---------- Tokens ---------- */
:root {
  --navy-900: #071a36;
  --navy-800: #0b2550;
  --navy-700: #12346c;
  --blue-600: #1c4fa0;
  --blue-500: #2563c4;
  --gold-500: #c9a227;
  --gold-400: #ddb94a;
  --gold-300: #ecd48a;
  --gold-700: #8a6a10;

  --canvas: #f4f6fb;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f6f8fc;
  --surface-strong: #e9eef7;
  --text: #0e1c33;
  --text-soft: #3e4d66;
  --text-muted: #5f6e86;
  --border: #dfe5ef;
  --border-strong: #bfcadb;
  --primary: var(--blue-600);
  --primary-hover: #163f82;
  --on-primary: #ffffff;
  --primary-soft: #e8effb;
  --accent: var(--gold-500);
  --on-accent: #241a00;
  --gold-soft: #fbf4dd;
  --gold-text: var(--gold-700);
  --sidebar: var(--navy-800);
  --sidebar-raised: var(--navy-700);
  --sidebar-text: #eef3fb;
  --sidebar-muted: #a9b8d2;
  --success: #17794b;
  --success-soft: #e5f5ec;
  --warning: #b2560a;
  --warning-soft: #fdf0e3;
  --danger: #b4232f;
  --danger-soft: #fdecef;
  --info: var(--blue-600);
  --info-soft: #e8effb;
  --focus: var(--gold-500);
  --chart-1: #1c4fa0;
  --chart-2: #c9a227;
  --chart-3: #17794b;
  --chart-4: #6b7fb8;
  --chart-5: #b4235c;
  --chart-6: #0f7c8c;

  --font-ui: "Segoe UI", "Noto Sans Khmer", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-data: "Segoe UI", "Noto Sans Khmer", system-ui, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(11, 37, 80, .06), 0 1px 1px rgba(11, 37, 80, .04);
  --shadow-md: 0 10px 28px -12px rgba(11, 37, 80, .22);
  --shadow-lg: 0 24px 60px -20px rgba(7, 26, 54, .45);
  --sidebar-width: 264px;
  --content-max: 1360px;
  --transition: 200ms cubic-bezier(.2, .7, .2, 1);
}
:root:lang(km) { --font-ui: "Noto Sans Khmer", "Segoe UI", system-ui, sans-serif; --font-data: "Noto Sans Khmer", "Segoe UI", sans-serif; }

:root[data-resolved-theme="dark"] {
  --canvas: #08142a;
  --surface: #0e1d38;
  --surface-raised: #132546;
  --surface-muted: #112241;
  --surface-strong: #1a2e55;
  --text: #eef3fb;
  --text-soft: #c4d0e4;
  --text-muted: #9caccb;
  --border: #22375e;
  --border-strong: #345082;
  --primary: #86aef2;
  --primary-hover: #a9c6f7;
  --on-primary: #071a36;
  --primary-soft: #16305c;
  --accent: var(--gold-400);
  --gold-soft: #2e2810;
  --gold-text: var(--gold-300);
  --sidebar: #061430;
  --sidebar-raised: #0e2149;
  --success: #5fd59c;
  --success-soft: #0f3527;
  --warning: #f2a85a;
  --warning-soft: #3a2611;
  --danger: #ff8994;
  --danger-soft: #451e27;
  --info: #86aef2;
  --info-soft: #16305c;
  --focus: var(--gold-400);
  --chart-1: #86aef2;
  --chart-2: #ddb94a;
  --chart-3: #5fd59c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 12px 30px -10px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
body { font-size: 15px; line-height: 1.6; }
h1, h2, h3 { color: var(--text); text-wrap: balance; }
p { text-wrap: pretty; }
a { transition: color var(--transition); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--gold-300); color: var(--navy-900); }

/* ---------- Sidebar: always visible on desktop, drawer on tablet/phone ---------- */
.app-sidebar {
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(201, 162, 39, .10), transparent 60%),
    linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
  color: var(--sidebar-text);
  border-right: 0;
  padding: 20px 14px 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.18) transparent;
}
:root[data-resolved-theme="dark"] .app-sidebar { background: linear-gradient(180deg, #071733 0%, #040e22 100%); border-right: 1px solid var(--border); }
.sidebar-header { padding: 0 6px 18px; margin-bottom: 8px; border-bottom: 1px solid rgba(255,255,255,.10); }
.sidebar-header .brand { gap: 10px; color: #fff; }
.sidebar-header .brand-logo, .mobile-brand .brand-logo { width: 42px; height: 43px; border: 2px solid var(--gold-500); box-shadow: 0 0 0 3px rgba(201,162,39,.18); }
.sidebar-header .brand-copy strong { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.sidebar-header .brand-copy small { color: var(--gold-300); font-size: 11px; display: block; }
.sidebar-close { color: #fff; }
.sidebar-close:hover { background: rgba(255,255,255,.1); }

.main-nav { padding: 0; display: flex; flex-direction: column; gap: 2px; }
.main-nav .nav-label, .nav-label {
  margin: 18px 10px 6px; color: var(--sidebar-muted); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
}
.nav-workspace + .nav-workspace { margin-top: 10px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.10); }
.nav-workspace .nav-workspace-title { color: var(--gold-300); font-size: 13px; font-weight: 700; letter-spacing: 0; text-transform: none; margin: 14px 10px 8px; }
.nav-section-number { background: var(--gold-500); color: var(--navy-900); font-size: 12px; font-weight: 800; width: 22px; height: 22px; }

.main-nav a {
  position: relative; min-height: 44px; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: #d5deee; font-size: 14px; font-weight: 500; border: 0;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.main-nav a .icon { width: 19px; height: 19px; opacity: .85; }
.main-nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.main-nav a:active { transform: scale(.985); }
.main-nav a[aria-current="page"] {
  color: #fff; font-weight: 600;
  background: linear-gradient(90deg, rgba(201,162,39,.22), rgba(201,162,39,.06));
  box-shadow: inset 3px 0 0 var(--gold-500);
}
.main-nav a[aria-current="page"] .icon { color: var(--gold-400); opacity: 1; }

.nav-settings { margin: 6px 0 2px; border-radius: 10px; }
.nav-settings > summary {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  color: #d5deee; font-size: 14px; font-weight: 500; cursor: pointer; list-style: none;
}
.nav-settings > summary::-webkit-details-marker { display: none; }
.nav-settings > summary::after { content: ""; margin-left: auto; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform var(--transition); opacity: .7; }
.nav-settings[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.nav-settings > summary:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-settings[open] { background: rgba(255,255,255,.05); padding-bottom: 4px; }
.nav-settings a { padding-left: 22px; }

.sidebar-footer { margin-top: 16px; padding: 12px 6px 0; border-top: 1px solid rgba(255,255,255,.10); background: transparent; }
.user-card { border-top: 0; padding-top: 0; gap: 10px; }
.user-avatar { width: 36px; height: 36px; border-radius: 10px; background: var(--gold-500); color: var(--navy-900); font-weight: 800; }
.user-copy strong { color: #fff; }
.user-copy small { color: var(--sidebar-muted); }
.user-card .icon-button { color: #d5deee; }
.user-card .icon-button:hover { background: rgba(255,255,255,.1); color: var(--gold-300); }

@media (min-width: 1025px) {
  .app-sidebar { transform: none !important; visibility: visible !important; width: var(--sidebar-width); box-shadow: none; }
  .app-main { margin-left: var(--sidebar-width); }
  .desktop-navigation-toggle, .sidebar-close, .sidebar-scrim { display: none !important; }
  body.sidebar-open { overflow: auto; }
}
.sidebar-scrim { background: rgba(7, 26, 54, .55); backdrop-filter: blur(2px); }

/* ---------- Top bars ---------- */
.mobile-topbar {
  background: var(--navy-800) !important; color: #fff; border-bottom: 2px solid var(--gold-500) !important;
  min-height: 60px; padding: 8px 14px;
}
.mobile-topbar .icon-button { color: #fff; }
.mobile-topbar .icon-button:hover { background: rgba(255,255,255,.1); }
.mobile-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; }
.mobile-brand .brand-logo { width: 36px; height: 37px; }
.mobile-brand:hover { color: var(--gold-300); }

.context-toolbar {
  min-height: 48px; margin-bottom: 22px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.context-toolbar .system-state {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px;
  background: var(--gold-soft); color: var(--gold-text); font-size: 12px; font-weight: 700;
}
.context-toolbar .system-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--gold-500); }
.toolbar-actions { gap: 10px; }
.toolbar-actions .table-link {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); color: var(--text); font-weight: 600; background: var(--surface);
}
.toolbar-actions .table-link:hover { border-color: var(--primary); color: var(--primary); }
.toolbar-actions select { min-height: 36px; border-radius: 8px; border: 1px solid var(--border-strong); background-color: var(--surface); color: var(--text); }

/* ---------- Page layout ---------- */
.page-shell { width: min(var(--content-max), calc(100% - 56px)); padding: 20px 0 56px; }
.back-link { color: var(--text-muted); font-weight: 600; font-size: 13px; gap: 4px; }
.back-link:hover { color: var(--primary); }
.eyebrow { color: var(--gold-text); font-weight: 700; letter-spacing: .08em; }

.page-heading { margin-bottom: 22px; }
.page-heading h1 { font-size: clamp(24px, 2.4vw, 32px); font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.page-heading p { color: var(--text-muted); }

/* Welcome banner (dashboard and overview pages) */
.page-hero {
  position: relative; overflow: hidden; padding: 30px 32px !important; margin-bottom: 22px;
  border: 0 !important; border-radius: var(--radius-lg);
  background:
    radial-gradient(80% 140% at 100% 0%, rgba(201,162,39,.28), transparent 55%),
    linear-gradient(120deg, var(--navy-800) 0%, var(--blue-600) 100%) !important;
  color: #fff; box-shadow: var(--shadow-md) !important;
}
.page-hero::after {
  content: ""; display: block !important; position: absolute; inset: auto 0 0 0; height: 4px;
  background: linear-gradient(90deg, var(--gold-500), var(--gold-300), var(--gold-500));
}
.page-hero h1 { color: #fff !important; font-size: clamp(26px, 3vw, 36px); font-weight: 700; letter-spacing: -.02em; }
.page-hero p, .page-hero .hero-copy > p { color: #d7e2f5 !important; font-size: 15px; max-width: 62ch; }
.page-hero .eyebrow { display: block !important; color: var(--gold-300); }
.page-hero a:not(.btn) { color: var(--gold-300); }
.page-hero .btn-primary { background: var(--gold-500); color: var(--navy-900); border-color: var(--gold-500); }
.page-hero .btn-primary:hover { background: var(--gold-400); color: var(--navy-900); }
.page-hero .btn-secondary { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.4); }
.page-hero .btn-secondary:hover { background: rgba(255,255,255,.16); color: #fff; border-color: #fff; }
.page-hero .hero-aside { border-color: rgba(255,255,255,.2); color: #d7e2f5; }
.page-hero .muted, .page-hero small { color: #c3d1ea; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 42px; padding: 9px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; gap: 8px;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 120ms ease, box-shadow var(--transition);
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--primary); color: var(--on-primary); border: 1px solid var(--primary); box-shadow: 0 6px 16px -8px rgba(28,79,160,.7); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.btn-small { min-height: 36px; padding: 6px 13px; font-size: 13px; }
.btn .icon { width: 18px; height: 18px; }
.button-count { display: inline-grid; min-width: 22px; height: 22px; place-items: center; padding: 0 6px; border-radius: 999px; background: var(--gold-500); color: var(--navy-900); font-size: 12px; font-weight: 800; }
.table-link { color: var(--primary); font-weight: 600; }
.table-link:hover { color: var(--primary-hover); text-decoration: underline; }

/* ---------- Cards / panels ---------- */
.panel, .form-panel {
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
  box-shadow: var(--shadow-sm); padding: 24px;
}
.panel-heading { align-items: center; }
.panel-heading h2, .panel > h2 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.panel-heading p { color: var(--text-muted); }

/* KPI tiles */
.kpi-grid { gap: 14px; }
.kpi {
  position: relative; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); box-shadow: var(--shadow-sm); transition: transform var(--transition), box-shadow var(--transition);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi::before { width: 36px; height: 4px; margin-bottom: 14px; border-radius: 4px; background: var(--primary); }
.kpi.warning::before { background: var(--gold-500); }
.kpi.success::before { background: var(--success); }
.kpi.ink::before { background: var(--navy-800); }
:root[data-resolved-theme="dark"] .kpi.ink::before { background: var(--text-soft); }
.kpi span { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: none; }
.kpi strong { color: var(--text); font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--text-muted); font-size: 12.5px; }

/* Expandable "about" boxes */
.workspace-details, .reference-disclosure, .help-topic details {
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
}
.workspace-details > summary, .reference-disclosure > summary { cursor: pointer; font-weight: 600; color: var(--text); }
.workspace-details > summary:hover, .reference-disclosure > summary:hover { color: var(--primary); }
.overview-note { padding: 4px 16px; margin-bottom: 22px; background: var(--gold-soft); border-color: color-mix(in srgb, var(--gold-500) 35%, var(--border)); }
.overview-note > summary { padding: 10px 0; color: var(--gold-text); }
.overview-note[open] { padding-bottom: 14px; }

.callout { border-left: 4px solid var(--gold-500); background: var(--gold-soft); border-radius: 10px; }

/* ---------- Project steps (workflow strip) ---------- */
.workflow-strip { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 6px; gap: 6px; box-shadow: var(--shadow-sm); }
.workflow-strip a { border-radius: 9px; color: var(--text); transition: background var(--transition); }
.workflow-strip a:hover { background: var(--surface-muted); }
.workflow-strip strong { border-color: var(--border-strong); color: var(--text-muted); background: var(--surface); }
.workflow-strip a.complete { background: var(--success-soft); color: var(--success); }
.workflow-strip a.complete strong { border-color: var(--success); color: var(--success); background: var(--surface); }
.workflow-strip a.active { background: var(--gold-soft); color: var(--gold-text); }
.workflow-strip a.active strong { border-color: var(--gold-500); background: var(--gold-500); color: var(--navy-900); }
.workflow-strip a.current { outline: 2px solid var(--primary); outline-offset: -2px; }

.study-actions, .setup-navigation { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 20px; }

/* ---------- Tables ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { font-size: 14px; }
caption { padding: 14px 16px; color: var(--text-soft); font-weight: 600; font-size: 13px; }
th, table th {
  background: var(--surface-muted); color: var(--text-muted); font-size: 12.5px; font-weight: 600;
  letter-spacing: 0; text-transform: none;
}
thead th { border-bottom: 1px solid var(--border); }
td, th { padding: 13px 16px; }
tbody tr { transition: background var(--transition); }
tbody tr:hover td, tbody tr:hover th[scope="row"] { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
tbody th[scope="row"] { background: transparent; color: var(--text); font-size: 14px; font-weight: 500; }
tbody th[scope="row"] strong { color: var(--text); font-weight: 700; letter-spacing: 0; }
tbody th[scope="row"] .muted { color: var(--text-muted); text-transform: none; letter-spacing: 0; font-weight: 400; }

/* Status badges */
.status { border-radius: 999px; padding: 4px 11px; font-size: 12px; font-weight: 600; }
.status-needs_review, .status-pending, .status-queued, .status-cancel_requested, .status-unverified, .status-draft { background: var(--gold-soft); color: var(--gold-text); }
.status-processing, .status-running, .status-published { background: var(--primary-soft); color: var(--primary); }

/* ---------- Forms ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), select, textarea {
  border: 1px solid var(--border-strong); border-radius: 9px; background-color: var(--surface); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:hover:not(:focus):not([type="checkbox"]):not([type="radio"]), select:hover:not(:focus), textarea:hover:not(:focus) { border-color: var(--primary); }
.form-control:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold-500) 35%, transparent); outline: 0;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
input[type="file"] { width: 100%; padding: 14px; border: 2px dashed var(--border-strong); border-radius: 12px; background: var(--surface-muted); color: var(--text-soft); cursor: pointer; }
input[type="file"]:hover { border-color: var(--primary); background: var(--primary-soft); }
input[type="file"]::file-selector-button { margin-right: 12px; padding: 8px 16px; border: 0; border-radius: 8px; background: var(--primary); color: var(--on-primary); font-weight: 600; cursor: pointer; }
label, .input-field label { color: var(--text); font-weight: 600; }
.helptext, .input-field small, .form-help { color: var(--text-muted); }
.filter-bar { border-radius: var(--radius-md); }

/* ---------- Alerts ---------- */
.alert { border-radius: 10px; }
.alert-info, .alert:not(.alert-success):not(.alert-error):not(.alert-warning) { background: var(--info-soft); border-color: color-mix(in srgb, var(--primary) 25%, var(--border)); }

/* Dropdown menus (e.g. Project options) */
.action-menu > summary { border-radius: 10px; }
.action-menu-content { border-radius: 12px; box-shadow: var(--shadow-lg); }

/* ---------- Help center ---------- */
.help-nav a[aria-current="true"], .help-nav a[aria-current="page"], .help-nav a.active { background: var(--primary-soft); color: var(--primary); box-shadow: inset 3px 0 0 var(--gold-500); }

/* ---------- Survey section ---------- */
.survey-nav a { border-radius: 9px; font-weight: 600; }
.survey-nav a:hover { background: var(--primary-soft); color: var(--primary); }
.survey-card meter { accent-color: var(--primary); }
.analysis-dashboard { --dash-teal: var(--blue-600); --dash-blue: #6b7fb8; --dash-amber: var(--gold-500); }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; padding: 16px 28px; background: var(--surface); }
footer span:first-child { color: var(--text); font-weight: 600; }
footer span:first-child::before { content: ""; display: inline-block; width: 18px; height: 3px; margin-right: 8px; vertical-align: middle; border-radius: 3px; background: var(--gold-500); }

/* ---------- Sign-in page ---------- */
.public-page { background: var(--navy-900); }
.login-layout {
  background:
    radial-gradient(60% 80% at 85% 10%, rgba(201,162,39,.20), transparent 60%),
    radial-gradient(70% 90% at 0% 100%, rgba(37,99,196,.35), transparent 60%),
    linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 60%, var(--navy-700) 100%);
  gap: 5vw;
}
.login-intro .eyebrow { color: var(--gold-300); letter-spacing: .1em; }
.login-intro h1 { color: #fff; font-weight: 700; letter-spacing: -.03em; line-height: 1.08; font-size: clamp(36px, 5vw, 64px); }
.login-intro p { color: #c9d6ec; }
.feature-row span { color: var(--gold-300); border: 1px solid rgba(221,185,74,.4); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-family: var(--font-ui); }
.login-card { border-radius: 20px; border-top: 4px solid var(--gold-500); box-shadow: 0 30px 80px -20px rgba(0,0,0,.55); }
.login-card .brand-logo.large { border: 3px solid var(--gold-500); }
.login-card h2 { font-weight: 700; }
.login-card .btn-primary { min-height: 48px; font-size: 15px; }
.public-preferences select { border-color: rgba(221,185,74,.45); background: rgba(7,26,54,.7); color: #fff; border-radius: 8px; }

/* ---------- Motion ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out 160ms ease both; }
::view-transition-new(root) { animation: vt-in 260ms cubic-bezier(.2,.8,.2,1) both; }
.app-sidebar { view-transition-name: app-sidebar; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }

.js-motion .reveal { opacity: 0; transform: translateY(16px); }
.js-motion .reveal.is-visible {
  opacity: 1; transform: none;
  transition: opacity 520ms cubic-bezier(.2,.8,.2,1) var(--reveal-delay, 0ms), transform 620ms cubic-bezier(.2,.8,.2,1) var(--reveal-delay, 0ms);
}

/* Primary button light sweep */
.btn-primary { position: relative; overflow: hidden; isolation: isolate; }
.btn-primary::after {
  content: ""; position: absolute; inset: 0; z-index: -1; transform: translateX(-120%);
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.28) 50%, transparent 70%);
}
.btn-primary:hover::after { transform: translateX(120%); transition: transform 700ms ease; }
.btn .icon { transition: transform var(--transition); }
.btn:hover .icon { transform: translateX(2px); }
.main-nav a .icon { transition: transform var(--transition), color var(--transition); }
.main-nav a:hover .icon { transform: scale(1.12); color: var(--gold-400); }

/* Live states */
.status-processing::before, .status-running::before, .status-queued::before { animation: dot-pulse 1.4s ease-in-out infinite; }
@keyframes dot-pulse { 50% { transform: scale(1.6); opacity: .45; } }
.workflow-strip a.active strong { animation: ring 2.2s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(201,162,39,.55); } 70%, 100% { box-shadow: 0 0 0 10px rgba(201,162,39,0); } }
.page-hero { background-size: 160% 160%, 100% 100% !important; animation: rise 560ms cubic-bezier(.2,.8,.2,1) both, hero-glow 14s ease-in-out 560ms infinite alternate; }
.page-heading, .login-intro { animation: rise 520ms cubic-bezier(.2,.8,.2,1) both; }
.login-card { animation: rise 620ms cubic-bezier(.2,.8,.2,1) 120ms both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes hero-glow { from { background-position: 100% 0%, 0 0; } to { background-position: 60% 40%, 0 0; } }

/* ---------- Animated traffic scene ---------- */
.traffic-scene {
  position: relative; display: flex; flex-direction: column; justify-content: center; border-radius: 14px; overflow: hidden;
  background: linear-gradient(180deg, rgba(7,26,54,.55), rgba(7,26,54,.25));
  border: 1px solid rgba(255,255,255,.14); box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.scene-road { display: block; width: 100%; height: auto; }
.road-surface { fill: rgba(255,255,255,.05); }
.road-edge { stroke: rgba(255,255,255,.28); stroke-width: 2; }
.lane-divider { stroke: var(--gold-400); stroke-width: 2; stroke-dasharray: 2 6; opacity: .6; }
.lane-dash { stroke: rgba(255,255,255,.45); stroke-width: 2; stroke-dasharray: 18 14; animation: lane-move 1.2s linear infinite; }
@keyframes lane-move { to { stroke-dashoffset: -32; } }
.count-line { stroke: var(--gold-400); stroke-width: 3; stroke-dasharray: 6 5; filter: drop-shadow(0 0 6px rgba(221,185,74,.6)); }
.count-line.flash { animation: line-flash 600ms ease-out; }
@keyframes line-flash { 0% { stroke: #fff; stroke-width: 6; filter: drop-shadow(0 0 14px rgba(255,236,170,1)); } }
.count-node { fill: var(--gold-500); stroke: #fff; stroke-width: 2; }
.veh { color: #fff; stroke-width: 2.4; transform-box: fill-box; transform-origin: center; animation: drive var(--dur, 8s) linear var(--delay, 0s) infinite; }
.veh[data-kind="truck"], .veh[data-kind="bus"] { color: var(--gold-300); }
.veh-back { animation-name: drive-back; color: #b9cdf1; }
@keyframes drive { from { transform: translateX(-100px); } to { transform: translateX(620px); } }
@keyframes drive-back { from { transform: translateX(620px) scaleX(-1); } to { transform: translateX(-100px) scaleX(-1); } }
.scene-counter {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 12px;
}
.scene-counter span {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 999px;
  background: rgba(7,26,54,.72); border: 1px solid rgba(255,255,255,.16); color: #fff; backdrop-filter: blur(6px);
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.scene-counter b { font-weight: 700; }
.scene-counter span.tick { animation: tick 500ms cubic-bezier(.3,1.6,.5,1); border-color: var(--gold-400); }
@keyframes tick { 40% { transform: translateY(-3px) scale(1.06); } }
.scene-icon { width: 30px; height: 17px; stroke: var(--gold-300); stroke-width: 2.6; }

/* Dashboard hero with scene */
.page-hero.has-scene { display: grid !important; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 28px; align-items: stretch; }
.page-hero.has-scene .hero-copy { align-self: center; }

/* ---------- "How a count works" journey ---------- */
.journey { margin-bottom: 22px; padding: 22px 24px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.journey h2 { margin: 0 0 16px; font-size: 17px; font-weight: 700; }
.journey-steps { position: relative; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
.journey-steps::before {
  content: ""; position: absolute; top: 23px; left: 10%; right: 10%; height: 2px;
  background: repeating-linear-gradient(90deg, var(--gold-500) 0 10px, transparent 10px 18px);
  background-size: 18px 2px; animation: flow 1.4s linear infinite; opacity: .7;
}
@keyframes flow { to { background-position: 18px 0; } }
.journey-step { position: relative; display: grid; justify-items: center; gap: 10px; text-align: center; counter-increment: step; }
.journey-icon {
  position: relative; display: grid; width: 48px; height: 48px; place-items: center; border-radius: 14px;
  background: var(--navy-800); color: var(--gold-300); box-shadow: 0 8px 18px -8px rgba(11,37,80,.6);
  transition: transform var(--transition), background var(--transition);
}
.journey-icon::after {
  content: counter(step); position: absolute; top: -7px; right: -7px; display: grid; width: 20px; height: 20px; place-items: center;
  border-radius: 50%; background: var(--gold-500); color: var(--navy-900); font-size: 11px; font-weight: 800; border: 2px solid var(--surface);
}
.journey-icon .icon { width: 22px; height: 22px; }
.journey-step:hover .journey-icon { transform: translateY(-3px) rotate(-3deg); background: var(--blue-600); }
.journey-step strong { font-size: 13.5px; font-weight: 600; color: var(--text); line-height: 1.35; }
:root[data-resolved-theme="dark"] .journey-icon { background: var(--surface-strong); }

@media (max-width: 1100px) {
  .page-hero.has-scene { grid-template-columns: 1fr; }
  
}
@media (max-width: 760px) {
  .journey { padding: 18px; }
  .journey-steps { grid-template-columns: 1fr; gap: 10px; }
  .journey-steps::before { top: 24px; bottom: 24px; left: 23px; right: auto; width: 2px; height: auto;
    background: repeating-linear-gradient(180deg, var(--gold-500) 0 10px, transparent 10px 18px); background-size: 2px 18px; animation-name: flow-down; }
  @keyframes flow-down { to { background-position: 0 18px; } }
  .journey-step { grid-template-columns: 48px 1fr; justify-items: start; align-items: center; text-align: left; gap: 14px; }

  .scene-counter span { font-size: 12px; padding: 3px 8px 3px 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .veh, .lane-dash, .journey-steps::before, .page-hero, .status-processing::before, .status-running::before,
  .status-queued::before, .workflow-strip a.active strong, .page-heading, .login-intro, .login-card { animation: none !important; }
  .veh { opacity: 0; }
  .veh:nth-of-type(1), .veh:nth-of-type(3), .veh:nth-of-type(5) { opacity: 1; transform: translateX(160px); }
  .veh-back:nth-of-type(5) { transform: translateX(220px) scaleX(-1); }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ---------- Phone bottom bar ---------- */
.mobile-tabbar { display: none; }
@media (max-width: 760px) {
  .mobile-tabbar {
    position: fixed; z-index: 80; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; padding: 6px;
    border-radius: 18px; background: rgba(11,37,80,.94); border: 1px solid rgba(221,185,74,.35);
    box-shadow: 0 16px 40px -12px rgba(7,26,54,.7); backdrop-filter: blur(10px);
  }
  .mobile-tabbar a {
    display: grid; justify-items: center; gap: 2px; min-height: 52px; padding: 6px 2px; border-radius: 12px;
    color: #c9d6ec; font-size: 11px; font-weight: 600; line-height: 1.2; text-align: center;
    transition: background var(--transition), color var(--transition);
  }
  .mobile-tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-tabbar a .icon { width: 22px; height: 22px; }
  .mobile-tabbar a[aria-current="page"] { background: var(--gold-500); color: var(--navy-900); }
  .mobile-tabbar a:active { transform: scale(.95); }
  .app-main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  body.sidebar-open .mobile-tabbar { display: none; }
}

/* ---------- Dashboard layout (Home + Results) ---------- */
.dash-grid { display: grid !important; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; margin-bottom: 22px; align-items: start; }
.dash-grid > .panel { margin-bottom: 0; }
.dash-span-4 { grid-column: span 4; }
.dash-span-8 { grid-column: span 8; }
.dash-span-12 { grid-column: 1 / -1; }
.dash-grid > .panel.dash-span-4 { align-self: stretch; }
.dash-side { display: grid; gap: 18px; }
.dash-side .journey { margin: 0; }
.dash-side .overview-note { margin: 0; }
.dash-side .journey-steps { grid-template-columns: 1fr; gap: 12px; }
.dash-side .journey-steps::before { top: 24px; bottom: 24px; left: 23px; right: auto; width: 2px; height: auto;
  background: repeating-linear-gradient(180deg, var(--gold-500) 0 10px, transparent 10px 18px); background-size: 2px 18px; animation-name: flow-down; }
@keyframes flow-down { to { background-position: 0 18px; } }
.dash-side .journey-step { grid-template-columns: 48px 1fr; justify-items: start; align-items: center; text-align: left; gap: 14px; }

/* KPI tiles with icons */
.kpi:has(.kpi-icon) { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label icon" "value icon" "note note"; column-gap: 12px; align-items: start; }
.kpi:has(.kpi-icon)::before { display: none; }
.kpi:has(.kpi-icon) > span:not(.kpi-icon) { grid-area: label; }
.kpi:has(.kpi-icon) > strong { grid-area: value; }
.kpi:has(.kpi-icon) > small { grid-area: note; }
.kpi .kpi-icon {
  grid-area: icon; display: grid !important; width: 44px; height: 44px; place-items: center; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary); letter-spacing: 0; text-transform: none;
}
.kpi .kpi-icon .icon { width: 22px; height: 22px; }
.kpi .kpi-icon use[href^="#vehicle"] { stroke-width: 3; }
.kpi .kpi-icon svg:has(use[href^="#vehicle"]) { width: 30px; height: 17px; }
.kpi.warning .kpi-icon { background: var(--gold-soft); color: var(--gold-text); }
.kpi.success .kpi-icon { background: var(--success-soft); color: var(--success); }
.kpi.ink .kpi-icon { background: var(--navy-800); color: var(--gold-300); }
:root[data-resolved-theme="dark"] .kpi.ink .kpi-icon { background: var(--surface-strong); }
.kpi strong { font-size: 34px; letter-spacing: -.02em; }

.dash-grid .table-wrap table { min-width: 0; }
.chart-panel .panel-heading form { flex-wrap: nowrap; }
.chart-panel .panel-heading form select { width: auto; }
.speed-summary .panel-heading .status { align-self: flex-start; }

/* Progress bar in tables */
.progress-track { display: block; width: 100%; max-width: 140px; height: 6px; margin-top: 6px; border-radius: 6px; background: var(--chart-track, var(--surface-strong)); overflow: hidden; }
.progress-track i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--primary), var(--gold-500)); }

/* Chart cards */
.chart-panel h2, .axle-summary > strong, .speed-summary h2 { display: block; margin: 0 0 4px; font-size: 16px; font-weight: 700; color: var(--text); }
.chart-panel .panel-heading { align-items: flex-start; margin-bottom: 12px; }
.chart-panel .panel-heading form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chart-panel .panel-heading select { min-height: 36px; padding: 4px 30px 4px 10px; }
.chart-panel canvas { display: block; margin: 8px 0 4px; }
.chart-summary { margin: 8px 0 0; color: var(--text-muted); font-size: 12.5px; }
.chart-panel details { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.chart-panel details > summary { cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 600; }
.chart-panel details .table-wrap { margin-top: 10px; }
:root { --chart-track: #edf1f8; --chart-grid: #e3e8f1; --chart-text: #5f6e86; }
:root[data-resolved-theme="dark"] { --chart-track: #1a2e55; --chart-grid: #22375e; --chart-text: #9caccb; }

/* Trucks by axle */
.axle-summary > .muted { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); }
.axle-summary dl { display: grid; gap: 0; margin: 0 0 10px; }
.axle-summary dl > div { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.axle-summary dl > div:last-child { border-bottom: 0; }
.axle-summary dt { color: var(--text-soft); font-size: 14px; }
.axle-summary dd { margin: 0; min-width: 36px; padding: 2px 10px; border-radius: 999px; background: var(--surface-muted); color: var(--text); font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.axle-summary > small { color: var(--text-muted); font-size: 12px; }

/* Speed summary */
.speed-summary .panel-heading { flex-direction: column; gap: 8px; margin-bottom: 14px; }
.speed-summary .panel-heading p { font-size: 12.5px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.stat-grid > div { padding: 12px; border-radius: 10px; background: var(--surface-muted); }
.stat-grid > div.is-key { background: var(--navy-800); }
.stat-grid > div.is-key dt { color: var(--gold-300); }
.stat-grid > div.is-key dd { color: #fff; }
.stat-grid dt { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.stat-grid dd { margin: 2px 0 0; color: var(--text); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Download strip */
.download-panel { background: linear-gradient(120deg, var(--navy-800), var(--blue-600)); border: 0; color: #fff; }
.download-panel h2 { color: #fff; }
.download-panel p { color: #d7e2f5 !important; }
.download-actions a { min-height: 42px; padding: 8px 16px; border-radius: 10px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.3); color: #fff; font-weight: 600; transition: background var(--transition); }
.download-actions a:hover { background: var(--gold-500); border-color: var(--gold-500); color: var(--navy-900); }

@media (max-width: 1200px) {
  .dash-span-8 { grid-column: span 12; }
  .dash-span-4 { grid-column: span 6; }
  .dash-side.dash-span-4 { grid-column: span 12; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .dash-grid { gap: 14px; }
  .dash-span-4, .dash-span-8 { grid-column: 1 / -1; }
  .dash-side.dash-span-4 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .kpi-icon { width: 36px; height: 36px; }
  .kpi strong { font-size: 26px; }
}

/* ---------- Survey section: match the rest of the app ---------- */
.survey-workspace { max-width: none; }
.survey-workspace .survey-nav {
  display: inline-flex; flex-wrap: wrap; gap: 4px; margin: 0 0 22px; padding: 5px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); font-size: 14px;
}
.survey-workspace .survey-nav a { display: inline-flex; align-items: center; min-height: 38px; padding: 6px 14px; border-radius: 8px; color: var(--text-soft); font-weight: 600; }
.survey-workspace .survey-nav a:hover { background: var(--primary-soft); color: var(--primary); }
.survey-workspace .survey-nav a[aria-current="page"] { background: var(--navy-800); color: #fff; box-shadow: inset 0 -2px 0 var(--gold-500); }
.survey-workspace > h1, .survey-workspace .survey-heading h1 { margin: 0 0 6px; font-size: clamp(24px, 2.4vw, 32px); font-weight: 700; letter-spacing: -.02em; line-height: 1.2; animation: rise 520ms cubic-bezier(.2,.8,.2,1) both; }
.survey-workspace > h1 + p, .survey-workspace > h1 + p + p { max-width: 72ch; color: var(--text-muted); font-size: 14px; }
.survey-workspace .survey-card, .survey-workspace .survey-stats > div, html[data-resolved-theme=dark] .survey-workspace .survey-card, html[data-resolved-theme=dark] .survey-workspace .survey-stats > div {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); padding: 24px;
}
.survey-workspace .survey-form { max-width: 820px; }
.survey-workspace .survey-field label { color: var(--text); font-weight: 600; }
.survey-workspace .survey-field small { color: var(--text-muted); opacity: 1; margin-top: 4px; }
.survey-workspace .survey-stats > div { position: relative; padding: 18px 20px; }
.survey-workspace .survey-stats > div::before { content: ""; display: block; width: 36px; height: 4px; margin-bottom: 14px; border-radius: 4px; background: var(--primary); }
.survey-workspace .survey-stats > div:nth-child(2)::before { background: var(--gold-500); }
.survey-workspace .survey-stats > div:nth-child(3)::before { background: var(--success); }
.survey-workspace .survey-stats strong { font-size: 32px; font-weight: 700; color: var(--text); }
.survey-workspace .survey-stats span { color: var(--text-muted); opacity: 1; font-size: 13px; }
.survey-workspace .survey-card meter { accent-color: var(--primary); }
.survey-workspace .survey-card meter::-webkit-meter-optimum-value { background: linear-gradient(90deg, var(--primary), var(--gold-500)); }
.survey-workspace .errorlist { color: var(--danger); }
.survey-status-reviewed { color: var(--success) !important; }
.survey-quick-section > summary { color: var(--primary) !important; }

/* Traffic reports landing: same hero as other overview pages */
.analysis-dashboard .analysis-hero, .analysis-dashboard .dashboard-hero { border-radius: var(--radius-lg); }

.analysis-dashboard { gap: 20px; }
.analysis-dashboard .ad-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; animation: rise 520ms cubic-bezier(.2,.8,.2,1) both; }
.analysis-dashboard .ad-heading h1 { margin: 0 0 6px; font-size: clamp(24px, 2.4vw, 32px); font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.analysis-dashboard .ad-heading .ad-kicker { display: none; }
.analysis-dashboard .ad-subtitle, .analysis-dashboard .ad-help { color: var(--text-muted); font-size: 14px; max-width: 72ch; }
.analysis-dashboard .ad-kpis { gap: 14px; }
.analysis-dashboard .ad-stat { position: relative; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); transition: transform var(--transition), box-shadow var(--transition); }
.analysis-dashboard .ad-stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.analysis-dashboard .ad-stat::before { content: ""; display: block; width: 36px; height: 4px; margin-bottom: 14px; border-radius: 4px; background: var(--primary); }
.analysis-dashboard .ad-stat:nth-child(2)::before { background: var(--gold-500); }
.analysis-dashboard .ad-stat:nth-child(3)::before { background: var(--success); }
.analysis-dashboard .ad-stat:nth-child(4)::before { background: var(--navy-800); }
.analysis-dashboard .ad-stat-label { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: 0; text-transform: none; }
.analysis-dashboard .ad-stat-value { color: var(--text); font-size: 32px; font-weight: 700; }
.analysis-dashboard .ad-hero {
  border: 0; border-radius: var(--radius-lg); color: #fff; box-shadow: var(--shadow-md); overflow: hidden; position: relative;
  background: radial-gradient(80% 140% at 100% 0%, rgba(201,162,39,.28), transparent 55%), linear-gradient(120deg, var(--navy-800) 0%, var(--blue-600) 100%);
}
.analysis-dashboard .ad-hero::after { content: ""; position: absolute; inset: auto 0 0 0; height: 4px; background: linear-gradient(90deg, var(--gold-500), var(--gold-300), var(--gold-500)); }
.analysis-dashboard .ad-hero h2 { color: #fff; font-size: clamp(22px, 2.4vw, 30px); }
.analysis-dashboard .ad-hero p { color: #d7e2f5; }
.analysis-dashboard .ad-hero .ad-badge { background: rgba(221,185,74,.18); color: var(--gold-300); border-color: rgba(221,185,74,.4); }
.analysis-dashboard .ad-hero .btn-primary { background: var(--gold-500); border-color: var(--gold-500); color: var(--navy-900); }
.analysis-dashboard .ad-road-list a { border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.3); color: #fff; }
.analysis-dashboard .ad-road-list a:hover { background: var(--gold-500); color: var(--navy-900); }
.analysis-dashboard .ad-workflow li { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 12px; color: #fff; }
.analysis-dashboard .ad-workflow li span { background: var(--gold-500); color: var(--navy-900); border: 0; }
.analysis-dashboard .ad-workflow strong { color: #fff; }
.analysis-dashboard .ad-workflow p { color: #c9d6ec; }
.analysis-dashboard .ad-badge { border-radius: 999px; background: var(--gold-soft); color: var(--gold-text); }
.analysis-dashboard .ad-workspace, .analysis-dashboard .ad-empty, .analysis-dashboard .ad-panel, .analysis-dashboard .ad-card {
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm);
}
.analysis-dashboard .ad-workspace { border-left: 4px solid var(--gold-500); transition: transform var(--transition), box-shadow var(--transition); }
.analysis-dashboard .ad-workspace:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.analysis-dashboard .ad-kicker { color: var(--gold-text); }
.analysis-dashboard .ad-info { border-left: 4px solid var(--gold-500); background: var(--gold-soft); border-radius: 10px; color: var(--text-soft); }

/* ---------- Folded long text ---------- */
.is-clamped { display: -webkit-box !important; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-toggle {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px; margin: 2px 0 6px; padding: 0; border: 0; background: none;
  color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer;
}
.clamp-toggle::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform var(--transition); }
.clamp-toggle[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-2px); }
.alert + .clamp-toggle { margin-top: -6px; margin-bottom: 12px; }

/* ---------- Review queue: calmer summary ---------- */
[data-route=review_queue] .review-summary { border-radius: var(--radius-md); padding: 0 18px 14px; box-shadow: var(--shadow-sm); }
[data-route=review_queue] .review-totals strong { font-size: 26px; font-weight: 700; }
[data-route=review_queue] .review-totals span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
[data-route=review_queue] .review-totals > div:nth-child(2) strong { color: var(--gold-text); }
[data-route=review_queue] .review-totals > div:nth-child(3) strong { color: var(--success); }
[data-route=review_queue] .review-category-count { border-radius: 999px; padding: 5px 12px 5px 8px; background: var(--surface); }
[data-route=review_queue] .review-category-count.is-active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

[data-route=review_queue] .result-summary { color: var(--text-muted); font-size: 12.5px; }
[data-route=review_queue] .review-selection-toolbar { border-radius: 12px; box-shadow: var(--shadow-sm); }
.review-direct-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.review-direct-actions .btn[value="approve"] { background: var(--success); border-color: var(--success); color: #fff; }
.review-direct-actions .btn[value="approve"]:hover { filter: brightness(1.08); }
.review-direct-actions .btn[value="reject"] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: var(--surface); }
.review-direct-actions .btn[value="duplicate"] { background: var(--surface); border: 1px solid var(--border-strong); }
.review-row.review-selected { box-shadow: inset 4px 0 var(--gold-500); }

/* ---------- Review queue on desktop: every column fits ---------- */
@media (min-width: 1025px) {
  .review-table, .review-table.large-previews { min-width: 0; }
  .review-col-select { width: 44px; }
  .large-previews .review-col-image, .review-col-image { width: 186px; }
  .large-previews .review-thumbnail { width: 164px; height: 96px; }
  .review-col-time { width: 14%; } .review-col-class { width: 22%; } .review-col-direction { width: 11%; }
  .review-col-confidence { width: 9%; } .review-col-status { width: 14%; } .review-col-actions { width: 132px; }
  .review-table .review-direct-actions { flex-direction: column; }
  .review-table .review-direct-actions .btn { width: 100%; justify-content: center; }
  .review-table .review-inline-class select { width: 100%; }
}

/* ---------- Review queue on phones and tablets: one card per vehicle ---------- */
@media (min-width: 761px) and (max-width: 1024px) {
  .review-table tbody { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review-table tr.review-group-row { grid-column: 1 / -1; }
  [data-route=review_queue] .review-selection-toolbar:has([data-bulk-submit]) { bottom: 16px !important; }
}
@media (max-width: 1024px) {
  [data-route=review_queue] .preview-size-control { display: none; }
}
@media (max-width: 1024px) {

  [data-route=review_queue] .review-totals { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  [data-route=review_queue] .review-totals > div { padding: 10px 8px; border-right: 0; }
  [data-route=review_queue] .review-category-counts { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; scrollbar-width: none; }
  [data-route=review_queue] .review-category-count { flex: none; scroll-snap-align: start; }

  .review-table-scroll { overflow: visible; border: 0; background: transparent; }
  .review-table, .review-table.large-previews { display: block; min-width: 0 !important; width: 100%; table-layout: auto; }
  .review-table colgroup, .review-table thead { display: none; }
  .review-table tbody { display: grid; gap: 14px; }
  .review-table tr.review-group-row { display: block; }
  .review-table tr.review-group-row th { display: block; padding: 6px 2px; background: none; color: var(--text); font-size: 15px; }
  .review-table tr.review-row {
    position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px;
    grid-template-areas: "img img" "class class" "time dir" "conf status" "act act";
    padding: 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface) !important; box-shadow: var(--shadow-sm);
  }
  .review-table tr.review-row.review-selected { border-color: var(--gold-500); box-shadow: 0 0 0 2px var(--gold-500); }
  .review-table td { display: block; padding: 0; border: 0; font-size: 14px; min-width: 0; }
  .review-table td small { font-size: 12px; }
  .review-table .review-select-cell { position: absolute; z-index: 2; top: 20px; left: 20px; }
  .review-table .review-select-cell label { width: 40px; height: 40px; border-radius: 10px; background: rgba(255,255,255,.92); box-shadow: var(--shadow-sm); }
  .review-table .review-select-cell input { width: 22px; height: 22px; }
  .review-table .review-preview-cell { grid-area: img; }
  .review-table .review-thumbnail, .large-previews .review-thumbnail { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 12px; background: var(--surface-muted); }
  .review-table .review-thumbnail img { object-fit: contain; }
  .review-table .review-image-links { gap: 4px 16px; margin-top: 8px; font-size: 13px; }
  .review-table .review-image-links a { min-height: 32px; display: inline-flex; align-items: center; }
  .review-table .review-vehicle-cell { grid-area: class; }
  .review-table .review-vehicle-type { display: flex; align-items: center; gap: 10px; }
  .review-table .review-inline-class { flex: 1; margin: 0; }
  .review-table .review-inline-class select { width: 100%; min-height: 50px; font-size: 16px; font-weight: 600; border-radius: 12px; border-width: 2px; }

  .review-table .review-saved-class { display: block; }
  .review-table .review-time-cell { grid-area: time; }
  .review-table .review-time-cell strong { font-size: 15px; }
  .review-table tr.review-row > td:nth-last-child(4) { grid-area: dir; }
  .review-table .review-confidence-cell { grid-area: conf; }
  .review-table .review-confidence-cell strong { font-size: 18px; }
  .review-table tr.review-row > td[data-label]:not(.review-preview-cell):not(.review-vehicle-cell):not(.review-actions-cell):not(.review-select-cell)::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--text-muted); font-size: 11.5px; font-weight: 600; }
  .review-table tr.review-row > td:nth-last-child(2) { grid-area: status; }
  .review-table .review-actions-cell { grid-area: act; padding-top: 10px; border-top: 1px solid var(--border); }
  .review-table .review-direct-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .review-table .review-direct-actions .btn { min-height: 46px; font-size: 15px; justify-content: center; }
  .review-table .review-direct-actions .btn[value="approve"] { grid-column: 1 / -1; min-height: 54px; font-size: 17px; }
  .review-table .review-reopen { width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; }
  .review-table .review-row-edit { margin-top: 8px; }
  .review-table .review-row-edit { display: block; width: 100%; }
  .review-table .review-row-edit > summary { display: flex !important; width: 100%; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; background: var(--surface-muted); color: var(--primary); font-size: 14px; font-weight: 600; list-style: none; }
  .review-table .review-direct-actions .btn[value="duplicate"], .review-table .review-direct-actions .btn[value="reject"] { border: 1px solid var(--border-strong); }
  [data-route=review_queue] .review-totals > div.review-completion { display: block !important; }
  .review-table .quick-fields { grid-template-columns: 1fr !important; }
  .review-table .quick-fields select, .review-table .quick-fields input { min-height: 46px; font-size: 16px; }
  .review-table .quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .review-table .quick-actions .btn { min-height: 46px; }
  .review-table .review-all-evidence { display: block; margin-top: 8px; text-align: center; font-size: 13px; }

  /* "Approve selected" bar pinned above the bottom menu */
  [data-route=review_queue] .review-selection-toolbar:has([data-bulk-submit]) {
    position: fixed; z-index: 79; left: 10px; right: 10px; bottom: calc(86px + env(safe-area-inset-bottom)); margin: 0;
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 12px;
    background: var(--surface); border: 1px solid var(--border-strong); box-shadow: 0 14px 34px -12px rgba(7,26,54,.55);
  }
  [data-route=review_queue] .review-selection-toolbar [data-selection-count] { font-size: 13px; color: var(--text-muted); }
  [data-route=review_queue] .review-selection-toolbar [data-bulk-submit] { min-height: 44px; font-size: 14px; background: var(--success); border-color: var(--success); }
  [data-route=review_queue] .review-selection-toolbar:not(:has([data-bulk-submit])) { display: none; }
  [data-route=review_queue] .app-main:has(.review-selection-toolbar [data-bulk-submit]) { padding-bottom: calc(160px + env(safe-area-inset-bottom)); }
}

/* ---------- Single vehicle review: clear decision buttons ---------- */
.review-primary { display: grid !important; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.review-primary .btn { justify-content: center; min-height: 46px; }
.review-primary .btn[value="approve"] { background: var(--success); border-color: var(--success); color: #fff; }
.review-primary .btn[value="reject"] { background: var(--surface); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); }
.review-primary .btn[value="duplicate"] { background: var(--surface); border: 1px solid var(--border-strong); }
@media (hover: none), (max-width: 760px) { .keyboard-hint { display: none !important; } }
@media (max-width: 760px) {
  [data-route=review_event] .workflow-strip { display: none; }
  .review-primary {
    position: sticky; z-index: 5; bottom: calc(86px + env(safe-area-inset-bottom)); grid-template-columns: 1fr 1fr;
    margin: 0 -6px; padding: 10px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface);
    box-shadow: 0 14px 34px -12px rgba(7,26,54,.5);
  }
  .review-primary .btn[value="approve"] { grid-column: 1 / -1; min-height: 54px; font-size: 17px; }
  [data-route=review_event] .stack-form select, [data-route=review_event] .stack-form input:not([type=checkbox]):not([type=radio]) { min-height: 50px; font-size: 16px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .page-shell { width: calc(100% - 40px); padding-top: 16px; }
  .app-sidebar { width: min(300px, 88vw); }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .page-shell { width: calc(100% - 28px); padding-bottom: 40px; }
  .page-hero { padding: 22px 20px !important; border-radius: 14px; }
  .page-hero .form-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .page-hero .form-actions .btn { width: 100%; justify-content: center; }
  .panel, .form-panel { padding: 18px; }
  .panel-heading { align-items: flex-start; }
  .kpi { padding: 14px 16px; }
  .kpi strong { font-size: 26px; }
  .study-actions .btn, .setup-navigation .btn { flex: 1 1 100%; justify-content: center; }
  .toolbar-actions .table-link { display: none; }
  .context-toolbar { padding-bottom: 10px; margin-bottom: 16px; }
  footer { padding: 14px 16px; text-align: center; align-items: center; }
  .btn { min-height: 44px; }
}
@media (max-width: 640px) {
  /* Simple tables become one card per row */
  .table-wrap:has(> table.stack-on-phone) { border: 0; background: transparent; overflow: visible; }
  .table-wrap > table.stack-on-phone { min-width: 0; display: block; }
  table.stack-on-phone caption { display: block; padding: 0 2px 10px; }
  table.stack-on-phone thead { display: none; }
  .two-column, .training-history-grid { grid-template-columns: minmax(0, 1fr) !important; }
  table.stack-on-phone tbody { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  table.stack-on-phone tbody td, table.stack-on-phone tbody th { min-width: 0; overflow-wrap: anywhere; }
  table.stack-on-phone tbody tr {
    display: grid; grid-template-columns: 1fr; gap: 6px; padding: 14px 16px;
    border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 12px; background: var(--surface);
  }
  table.stack-on-phone tbody tr:hover td, table.stack-on-phone tbody tr:hover th[scope="row"] { background: transparent; }
  table.stack-on-phone tbody td, table.stack-on-phone tbody th { display: block; padding: 0; border: 0; text-align: left; }
  table.stack-on-phone tbody th[scope="row"] { display: block; text-align: left; padding-bottom: 6px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
  table.stack-on-phone tbody td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 1px; color: var(--text-muted); font-size: 12px; font-weight: 600; }
  table.stack-on-phone tbody td * { max-width: 100%; }

  table.stack-on-phone tbody td:last-child .table-link { display: inline-flex; min-height: 40px; align-items: center; }
  table.stack-on-phone tbody td.empty { display: block; text-align: center; }
}
@media (max-width: 500px) {
  .kpi-grid, .kpi-grid.five, .kpi-grid.three { grid-template-columns: 1fr 1fr; }
  .kpi strong { font-size: 24px; }
  .page-heading h1 { font-size: 24px; }
  .login-card { border-radius: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .kpi:hover { transform: none; }
}
@media print {
  .page-hero { background: none !important; color: #000; box-shadow: none !important; }
  .page-hero h1, .page-hero p { color: #000 !important; }
}

.login-intro .traffic-scene { margin-top: 22px; max-width: 640px; }
.login-card .muted { max-width: none; }

/* Production integration: preserve native hidden state, complete evidence and usable tables. */
[hidden] { display: none !important; }
.survey-workspace, .panel, .dash-side, .dash-grid > *, .table-wrap { min-width: 0; }
.survey-workspace .survey-nav a[aria-current="page"] { border-color: var(--gold-500); }
@media (max-width: 1024px) {
  .review-table .review-history-link, .review-table .review-row-metadata { display: block; }
  .review-table .review-vehicle-cell a[data-class-reference]:not([hidden]) { display: inline-block; }
  .review-table .review-row-metadata { overflow-wrap: anywhere; }
  [data-route=review_queue] .review-selection-toolbar:has([data-bulk-submit]) { position: static; }
}
@media print {
  .app-sidebar, .mobile-tabbar, .mobile-topbar { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .page-shell { width: 100%; }
}

.review-table .review-all-evidence { display: block !important; margin-top: 8px; }

@media (max-width: 1024px) { .review-table-scroll { max-height: none; } }

/* ---------- Home banner: status cards + road band ---------- */
.page-hero.home-hero { display: block !important; padding: 0 !important; }
.home-hero-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 28px; align-items: center; padding: 30px 32px 24px; }
.home-hero h1 { margin: 4px 0 8px; }
.home-hero .hero-copy > p { margin: 0 0 18px; }
.home-hero .form-actions { margin: 0; }
.home-status { display: grid; gap: 12px; }
.home-card {
  display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; text-decoration: none;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.16); color: #fff !important;
  backdrop-filter: blur(6px); transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.home-card:hover { background: rgba(255,255,255,.12); border-color: var(--gold-400); transform: translateY(-1px); }
.home-card strong { font-size: 16px; font-weight: 700; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-card small { display: flex; align-items: center; gap: 6px; color: #c3d1ea; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-card small .icon { width: 14px; height: 14px; flex: none; color: var(--gold-300); }
.home-card-label { display: inline-flex; align-items: center; gap: 8px; color: var(--gold-300); font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.home-card.is-done .home-card-label { color: #8fe0b0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,.6); animation: live-ping 1.6s ease-out infinite; }
@keyframes live-ping { 70%, 100% { box-shadow: 0 0 0 8px rgba(74,222,128,0); } }
.home-progress { display: block; height: 6px; border-radius: 999px; background: rgba(255,255,255,.14); overflow: hidden; }
.home-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold-500), var(--gold-300)); transition: width .6s ease; }

.home-road { position: relative; aspect-ratio: 1200 / 132; min-height: 72px; max-height: 132px; border-top: 1px solid rgba(255,255,255,.1); background: rgba(5,18,40,.35); }
.home-road svg { display: block; width: 100%; height: 100%; }
.hr-asphalt { fill: rgba(255,255,255,.03); }
.hr-edge { stroke: rgba(255,255,255,.22); stroke-width: 1.5; }
.hr-median { stroke: var(--gold-400); stroke-width: 1.5; stroke-dasharray: 3 5; opacity: .55; }
.hr-dash { stroke: rgba(255,255,255,.35); stroke-width: 1.5; stroke-dasharray: 22 18; animation: hr-lane 1.4s linear infinite; }
.hr-dash-back { animation-direction: reverse; }
@keyframes hr-lane { to { stroke-dashoffset: -40; } }
.hr-count { stroke: var(--gold-400); stroke-width: 2.5; stroke-dasharray: 5 4; filter: drop-shadow(0 0 6px rgba(221,185,74,.7)); }
.hr-veh { color: #e6eefb; stroke-width: 2.6; animation: hr-drive var(--dur, 9s) linear var(--delay, 0s) infinite; }
.hr-veh use { fill: none; stroke: currentColor; }
.hr-back { color: #9fb8e6; animation-name: hr-drive-back; }
.hr-tracked { color: var(--gold-300); }
.hr-box { fill: rgba(221,185,74,.08); stroke: var(--gold-400); stroke-width: 1.2; }
@keyframes hr-drive { from { transform: translateX(-80px); } to { transform: translateX(1280px); } }
@keyframes hr-drive-back { from { transform: translateX(1280px) scaleX(-1); } to { transform: translateX(-80px) scaleX(-1); } }
.hr-back { transform-box: fill-box; transform-origin: center; }

@media (max-width: 1100px) { .home-hero-grid { grid-template-columns: 1fr; gap: 20px; } }
@media (max-width: 760px) {
  .page-hero.home-hero { padding: 0 !important; }
  .home-hero-grid { padding: 22px 20px 18px; }
  .home-road { min-height: 60px; }
  .home-hero .form-actions .btn-secondary { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hr-veh, .hr-dash, .live-dot { animation: none !important; }
  .hr-veh:nth-of-type(odd) { transform: translateX(420px); }
  .hr-veh:nth-of-type(even) { transform: translateX(900px); }
}
