/* Relay Navigation — operator design system.
 * Scene: a tired driver glancing at a phone in a cab, often at night, at speed.
 * Principles applied: instrument-grade legibility, mono tabular numerals, honest
 * hierarchy (the decision number leads), semantic hazard color, zero slop, theme-aware.
 * Type is a designed system (IBM Plex Sans + Mono) — distinctive, not the AI-default face. */

:root {
  /* light (day) */
  --sans: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ink: #0b1220;
  --muted: #59616f;
  --faint: #616b78;   /* darkened to meet WCAG 4.5:1 for labels/counts (Change 7) */
  --panel: #ffffff;
  --panel-2: #f5f7fa;
  --line: #e7eaf0;
  --line-strong: #d6dbe4;

  --route: #2f6bff;          /* the one bold color — "your path" */
  --route-ink: #ffffff;
  --focus: rgba(47, 107, 255, .30);

  /* semantic hazards — shared by map markers and the panel legend */
  --danger: #e5484d;         /* low clearance / closed */
  --warn:   #f59e0b;         /* closure / advisory */
  --rail:   #8b5cf6;
  --camera: #0891b2;
  --good:   #17a673;

  --shadow: 0 1px 2px rgba(11,18,32,.07), 0 10px 30px -14px rgba(11,18,32,.28);
  --r: 14px; --r-sm: 10px; --r-xs: 7px;
}

/* Dark tokens — applied when the system is dark (unless the user forced light),
   OR when the user explicitly picks dark via the toggle (data-theme="dark"). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eef2f8; --muted: #99a3b2; --faint: #7d8794;
    --panel: #0e1420; --panel-2: #151d2b; --line: #223049; --line-strong: #2d3c56;
    --route: #5b8bff; --focus: rgba(91, 139, 255, .38);
    --danger: #ff5a5f; --warn: #f7b955; --rail: #a78bfa; --camera: #22b8cf; --good: #3ecf8e;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 14px 36px -16px rgba(0,0,0,.72);
  }
}
:root[data-theme="dark"] {
  --ink: #eef2f8; --muted: #99a3b2; --faint: #7d8794;
  --panel: #0e1420; --panel-2: #151d2b; --line: #223049; --line-strong: #2d3c56;
  --route: #5b8bff; --focus: rgba(91, 139, 255, .38);
  --danger: #ff5a5f; --warn: #f7b955; --rail: #a78bfa; --camera: #22b8cf; --good: #3ecf8e;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 14px 36px -16px rgba(0,0,0,.72);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink); background: var(--panel-2); overflow: hidden;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}

#map { position: absolute; inset: 0; }

/* ---- the floating operator panel (a HUD, not a card stack) ---- */
#panel {
  position: absolute;
  top: 14px; left: 14px;
  width: 366px; max-width: calc(100vw - 28px);
  max-height: calc(100vh - 28px);
  display: flex; flex-direction: column; gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: auto;
  z-index: 10;
}

/* ---- header: brand + persistent profile control on one line ---- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.theme-btn { width: 30px; height: 30px; flex: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: var(--r-sm); font-size: 14px; line-height: 1; cursor: pointer; display: grid; place-items: center; transition: border-color .12s, background .12s; }
.theme-btn:hover { border-color: var(--route); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex: none; color: var(--route); display: grid; place-items: center; }
.brand-mark svg { display: block; width: 26px; height: 26px; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -.015em; line-height: 1.05; }
.brand-sub { font-size: 11px; color: var(--faint); margin-top: 1px; letter-spacing: .01em; }

/* segmented profile toggle */
.profiles { display: inline-flex; padding: 3px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.profile {
  border: 0; background: transparent; color: var(--muted);
  border-radius: 7px; padding: 6px 10px; font: 550 13px var(--sans);
  cursor: pointer; transition: color .12s, background .12s; white-space: nowrap;
}
.profile:hover { color: var(--ink); }
.profile.is-on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(11,18,32,.12); }
@media (prefers-color-scheme: dark) { .profile.is-on { box-shadow: 0 1px 2px rgba(0,0,0,.5); } }

/* ---- rig / vehicle profile ---- */
.rig { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.rig-label { font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); }
.rig label { display: inline-flex; align-items: center; gap: 5px; }
.rig input[type=number] { width: 50px; border: 1px solid var(--line-strong); border-radius: var(--r-xs); padding: 4px 6px; font: 500 12.5px var(--mono); color: var(--ink); background: var(--panel-2); font-variant-numeric: tabular-nums; }
.rig input[type=number]:focus { outline: none; border-color: var(--route); box-shadow: 0 0 0 3px var(--focus); }
.rig-haz { cursor: pointer; }

/* ---- search ---- */
.search { position: relative; }
.search input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 11px 12px 11px 34px; font: 400 15px var(--sans); color: var(--ink);
  background: var(--panel-2)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2359616f' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E")
    no-repeat 11px center;
  transition: border-color .12s, box-shadow .12s;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; border-color: var(--route); box-shadow: 0 0 0 3px var(--focus); }
.search-results {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0; z-index: 20;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: var(--shadow); max-height: 244px; overflow: auto;
}
.sr-item { padding: 10px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sr-item:last-child { border-bottom: 0; }
.sr-item:hover { background: var(--panel-2); color: var(--route); }
.sr-empty { padding: 10px 12px; font-size: 12.5px; color: var(--muted); }

/* ---- section labels ---- */
.label { font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin-bottom: 7px; }

/* ---- route summary: ETA is the hero (the decision number) ---- */
.summary { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.sum-top { display: flex; align-items: baseline; gap: 12px; }
.sum-eta { font: 600 34px var(--mono); letter-spacing: -.02em; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.sum-dist { font: 500 16px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; margin-left: auto; }
.eta-live { font: 700 9px var(--mono); color: #fff; background: var(--good); padding: 2px 5px; border-radius: 4px; vertical-align: middle; margin-left: 8px; letter-spacing: .06em; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 600 11px var(--mono); padding: 3px 8px; border-radius: 999px; background: color-mix(in srgb, var(--route) 12%, transparent); color: var(--route); letter-spacing: .01em; }
.chip.muted { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.chip-traffic { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

/* ---- on-route safety block: first-class, severity-ranked, calm ---- */
.on-route { display: flex; flex-direction: column; gap: 0; padding: 4px 0 2px; border-top: 1px solid var(--line); }
.onr-head { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 8px 0 6px; }
.onr-item {
  display: flex; gap: 9px; align-items: baseline; font-size: 14px; line-height: 1.42;
  padding: 9px 10px; margin-bottom: 6px; border-radius: var(--r-xs);
  background: var(--panel-2); border-left: 3px solid var(--faint);
}
.onr-item:last-child { margin-bottom: 0; }
.onr-item b { font-weight: 600; }
.onr-ico { flex: none; font-size: 13px; }
/* Relay Intelligence detail rides INSIDE its item rather than adding a ninth on-route line —
   the panel already exceeds the ~4-item glance budget (docs/strategy/04). 13px is the
   ISO-15008 floor for glanceable text; do not shrink it to buy space. */
.onr-body { min-width: 0; }
.onr-sub { display: block; margin-top: 3px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.onr-item.danger { border-left-color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, var(--panel)); }
.onr-item.warn   { border-left-color: var(--warn);   background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.onr-item.info   { border-left-color: var(--route); }

/* ---- turn steps ---- */
.steps { list-style: none; margin: 0; padding: 0; max-height: 32vh; overflow: auto; }
.steps li { display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13.5px; line-height: 1.45; }
.steps li:last-child { border-bottom: 0; }
.steps .dist { color: var(--muted); font: 500 12.5px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 48px; padding-top: 1px; }

/* ---- utility footer (quiet) ---- */
.presets .presets-label { display: none; } /* label handled by .label wrapper */
#presetRow { display: flex; flex-direction: column; gap: 6px; }
.preset {
  text-align: left; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--r-xs); padding: 8px 10px; font: 400 12.5px var(--sans); cursor: pointer;
  transition: border-color .12s, color .12s;
}
.preset:hover { border-color: var(--route); color: var(--route); }

.layers .layer-toggles { display: flex; gap: 7px; flex-wrap: wrap; }
.layer-chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 6px 11px; font: 550 12px var(--sans); cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; transition: all .12s;
}
.layer-chip .cnt { font: 500 11px var(--mono); color: var(--faint); }
.layer-chip.is-on { border-color: color-mix(in srgb, var(--route) 45%, var(--line)); background: color-mix(in srgb, var(--route) 8%, var(--panel)); color: var(--ink); }
.layer-chip.is-on .cnt { color: var(--muted); }

.crime-legend { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.leg-chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; padding: 4px 9px; font: 550 11px var(--sans); cursor: pointer; transition: opacity .12s, border-color .12s; }
.leg-chip.is-on { color: var(--ink); border-color: var(--line-strong); }
.leg-chip:not(.is-on) { opacity: .45; }
.leg-chip .sw { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
/* crime severity = magenta family (kept off the reserved hazard-red + closure-amber); matches the map dots */
.sw-violent { background: #a21caf; } .sw-theft { background: #d946ef; } .sw-other { background: #8b93a3; }
.crime-range { display: inline-flex; margin-top: 7px; padding: 2px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.rng-chip { border: 0; background: transparent; color: var(--muted); border-radius: 6px; padding: 3px 9px; font: 550 11px var(--mono); cursor: pointer; }
.rng-chip.is-on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(11,18,32,.12); }
.rng-chip:hover:not(.is-on) { color: var(--ink); }

.border-status { font-size: 13px; color: var(--muted); padding: 9px 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-xs); line-height: 1.45; }
.border-status b { color: var(--ink); font-weight: 600; }

.status { font-size: 13px; color: var(--muted); line-height: 1.45; }
.status.err { color: var(--danger); }

.clear {
  align-self: flex-start; border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: var(--r-xs); padding: 8px 13px; font: 550 12.5px var(--sans); cursor: pointer;
  transition: border-color .12s, color .12s;
}
.clear:hover { border-color: var(--danger); color: var(--danger); }

.disclaimer { margin: 0; font-size: 10.5px; line-height: 1.5; color: var(--faint); border-top: 1px solid var(--line); padding-top: 11px; }
.disclaimer strong { color: var(--muted); }

/* ---- map markers + controls ---- */
.mk { width: 15px; height: 15px; border-radius: 50%; border: 3px solid var(--panel); box-shadow: 0 1px 5px rgba(0,0,0,.45); }
.mk.from { background: var(--good); }
.mk.to { background: var(--danger); }

.maplibregl-popup-content { font-family: var(--sans); font-size: 12.5px; border-radius: 10px; box-shadow: var(--shadow); }
.maplibregl-ctrl-group { border-radius: 10px !important; overflow: hidden; box-shadow: var(--shadow) !important; }

/* respect reduced-motion: kill any non-essential transition */
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* narrow screens (a phone in the cab): panel spans the width */
@media (max-width: 480px) {
  #panel { top: 8px; left: 8px; right: 8px; width: auto; max-width: none; padding: 14px; }
  .sum-eta { font-size: 30px; }
}
