:root {
  --bg: #070c12;
  --panel: rgba(12, 19, 28, 0.92);
  --line: #1e2c3a;
  --text: #cbd5e1;
  --muted: #8494a7;
  --accent: #22d3ee;
  --on-accent: #041016;
  --alert: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --field: #0c141d;
  --raised: #111c28;
  --line-strong: #33485d;
  --strong: #f1f5f9;
  --head: #0b131c;
  --topbar: rgba(7, 12, 18, 0.9);
  --row-hover: rgba(34, 211, 238, 0.05);
  --row-chosen: rgba(34, 211, 238, 0.09);
  --swatch-border: rgba(255, 255, 255, 0.25);
  --ok-soft: rgba(52, 211, 153, 0.12);
  --warn-soft: rgba(251, 191, 36, 0.12);
  --alert-soft: rgba(248, 113, 113, 0.12);
  --accent-soft: rgba(34, 211, 238, 0.12);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  --radius: 10px;
  --radius-sm: 6px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace;
}

/* Day: for bright rooms and daylight at the ramp. Set by static/theme.js; night is the default above.
   Accent and state colours are darkened so they keep at least 4.5:1 contrast on the light panels. */
:root[data-theme="day"] {
  --bg: #eef2f6;
  --panel: rgba(255, 255, 255, 0.96);
  --line: #dbe2ea;
  --text: #1e293b;
  --muted: #526173;
  --accent: #0e7490;
  --on-accent: #ffffff;
  --alert: #dc2626;
  --ok: #15803d;
  --warn: #b45309;
  --field: #ffffff;
  --raised: #f4f7fa;
  --line-strong: #a8b5c4;
  --strong: #0f172a;
  --head: #f4f7fa;
  --topbar: rgba(255, 255, 255, 0.92);
  --row-hover: rgba(14, 116, 144, 0.05);
  --row-chosen: rgba(14, 116, 144, 0.1);
  --swatch-border: rgba(15, 23, 42, 0.35);
  --ok-soft: rgba(21, 128, 61, 0.1);
  --warn-soft: rgba(180, 83, 9, 0.1);
  --alert-soft: rgba(220, 38, 38, 0.08);
  --accent-soft: rgba(14, 116, 144, 0.1);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.12), 0 1px 2px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
/* Only the map is a fixed, non-scrolling canvas; the other pages scroll as documents. */
body.map-page { overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { flex: none; }

/* -- Controls shared by every page ------------------------------------------------- */

button { font: inherit; color: var(--text); background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 5px 11px; cursor: pointer; transition: border-color 0.15s, background-color 0.15s, color 0.15s; touch-action: manipulation; }
button:hover { border-color: var(--line-strong); }
button:active { transform: translateY(0.5px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
button.quiet:hover { color: var(--text); background: var(--raised); }
.icon-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; font-size: 18px; line-height: 1; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--field); border: 1px solid var(--line); border-radius: 8px; }
.seg button { border: none; background: transparent; color: var(--muted); border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 500; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { color: var(--on-accent); background: var(--accent); }

.title { color: var(--accent); font-weight: 700; letter-spacing: 0.06em; font-size: 12px; text-transform: uppercase; }
.clock { color: var(--muted); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Toggle switch built on a real checkbox (keyboard and screen readers get the native control). */
.switch { position: relative; display: flex; align-items: center; gap: 10px; padding: 5px 0; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 30px; height: 18px; margin: 0; cursor: pointer; }
.switch .track { position: relative; width: 30px; height: 18px; flex: none; border-radius: 9px; background: var(--line-strong); transition: background-color 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); transition: transform 0.15s ease-out; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.4; }
.switch.primary { color: var(--strong); font-weight: 600; }

.status { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--field); border: 1px solid var(--line); border-left: 3px solid var(--muted); color: var(--text); font-size: 12px; }
.status.ok { border-left-color: var(--ok); }
.status.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.status.bad { border-left-color: var(--alert); background: var(--alert-soft); }

/* -- Map page -------------------------------------------------------------------------- */

canvas#scope { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
canvas#scope.dragging { cursor: grabbing; }

.panel { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); }
.panel header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }

.controls { top: 16px; left: 16px; width: 300px; max-height: calc(100% - 64px); overflow-y: auto; padding: 0; }
.controls .panel-head { position: sticky; top: 0; z-index: 1; margin: 0; padding: 12px 10px 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.controls.collapsed .panel-head { border-bottom-color: transparent; }
.controls.collapsed .panel-body { display: none; }
.controls.collapsed #panel-toggle svg { transform: rotate(180deg); }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { width: 26px; height: 26px; padding: 5px; border-radius: 7px; background: var(--accent); fill: var(--on-accent); }
.brand-name { color: var(--strong); font-weight: 700; font-size: 14px; letter-spacing: 0.01em; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: 11px; white-space: nowrap; }
.brand-sub .clock { font-size: 11px; }
.panel-body { display: grid; gap: 12px; padding: 12px 14px 12px; }
.group { display: grid; gap: 2px; }
.group-title { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.row > span { color: var(--muted); }
.row.stack { flex-wrap: wrap; }
.row.stack .seg { flex: 1 1 100%; }
.row.stack .seg button { flex: 1; }
.note { margin: 2px 0 0; color: var(--warn); font-size: 12px; flex: 1 1 100%; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.legend:empty { display: none; }
.legend .item { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; border: 1px solid var(--swatch-border); }
.legend .count { color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }

.nav-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.nav-links a { display: grid; justify-items: center; gap: 4px; color: var(--text); background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 4px; text-decoration: none; font-size: 12px; transition: border-color 0.15s; }
.nav-links a:hover { border-color: var(--accent); color: var(--strong); }
.nav-links svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.panel-foot { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.panel-foot .hint { color: var(--muted); font-size: 11px; line-height: 1.3; }
.panel-foot button { margin-left: auto; white-space: nowrap; }

/* Floating view tools, top right */
.map-tools { position: fixed; top: 16px; right: 16px; display: grid; gap: 10px; justify-items: end; }
.tool-group { display: grid; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.tool-group .tool + .tool { border-top: 1px solid var(--line); }
.tool { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: none; border-radius: 0; background: transparent; color: var(--text); }
.tool:hover { background: var(--raised); color: var(--strong); }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool.compass { width: 44px; height: 44px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.tool.compass svg { width: 32px; height: 32px; stroke: none; transition: transform 0.12s linear; }
.compass .n { fill: var(--alert); }
.compass .s { fill: var(--muted); }
.compass text { fill: #fff; font: 700 7px var(--sans); }
.compass.turned { border-color: var(--accent); }

.scale { position: fixed; left: 16px; bottom: 14px; display: flex; align-items: center; gap: 8px; color: var(--strong); font-size: 11px; font-weight: 600; pointer-events: none; text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg); }
.scale-bar { height: 7px; border: 2px solid var(--strong); border-top: none; box-shadow: 0 1px 0 var(--bg); transition: width 0.1s; }

.map-credit { position: fixed; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; max-width: 70%; padding: 2px 8px; background: rgba(255, 255, 255, 0.78); color: #333; font: 10px/1.6 Roboto, Arial, sans-serif; border-top-left-radius: 4px; }
.map-credit #map-copyright { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.google-mark { font: 500 14px/1 "Product Sans", Roboto, Arial, sans-serif; color: #5f6368; letter-spacing: -0.2px; }

/* Vehicle bubble: anchored above the selected vehicle by app.js (transform + --tail-x). */
.bubble { position: fixed; left: 0; top: 0; z-index: 20; width: 300px; max-width: calc(100vw - 16px); padding: 12px 14px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); transform: translate3d(-9999px, 0, 0); will-change: transform; animation: pop 0.14s ease-out; }
.bubble.away { visibility: hidden; }
@keyframes pop { from { opacity: 0; } }
.bubble-tail { position: absolute; left: var(--tail-x, 50%); bottom: -7px; width: 14px; height: 14px; margin-left: -7px; background: var(--panel); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.bubble.below .bubble-tail { bottom: auto; top: -7px; transform: rotate(225deg); }
.bubble-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.bubble-name { color: var(--strong); font: 700 16px/1.2 var(--mono); letter-spacing: 0.02em; }
.bubble-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.bubble-head .icon-btn { margin: -4px -6px 0 0; }
.bubble-state { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 8px; padding: 8px 10px; border-radius: 8px; background: var(--field); border: 1px solid var(--line); }
.bubble-speed { display: grid; justify-items: end; line-height: 1.15; }
.bubble-speed b { color: var(--strong); font-size: 18px; font-variant-numeric: tabular-nums; }
.bubble-speed span { color: var(--muted); font-size: 11px; font-family: var(--mono); }
.bubble-grid { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 12.5px; }
.bubble-grid dt { color: var(--muted); }
.bubble-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.bubble-grid dd.mono { font-family: var(--mono); font-size: 12px; }
.tone-ok { color: var(--ok); font-weight: 600; }
.tone-warn { color: var(--warn); font-weight: 600; }
.tone-bad { color: var(--alert); font-weight: 600; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 11px; vertical-align: -1px; }
.bars i { width: 3px; background: var(--line-strong); border-radius: 1px; }
.bars i:nth-child(1) { height: 3px; } .bars i:nth-child(2) { height: 5px; } .bars i:nth-child(3) { height: 7px; }
.bars i:nth-child(4) { height: 9px; } .bars i:nth-child(5) { height: 11px; }
.bars i.on { background: var(--accent); }
.bubble-trail { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.bubble-note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
/* Pills on the map page (pages.css has the same for the admin pages). */
.bubble .pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--raised); color: var(--muted); }
.bubble .pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.bubble .pill.ok { color: var(--ok); background: var(--ok-soft); }
.bubble .pill.warn { color: var(--warn); background: var(--warn-soft); }
.bubble .pill.bad { color: var(--alert); background: var(--alert-soft); }

.replay { left: 50%; transform: translateX(-50%); bottom: 16px; width: min(760px, calc(100% - 32px)); display: grid; gap: 8px; }
.with-credit .replay { bottom: 32px; }
.replay header { margin: 0; }
.replay .meta { color: var(--muted); }
.replay .bar { display: flex; align-items: center; gap: 10px; }
.replay input[type="range"] { flex: 1; accent-color: var(--accent); }
.replay .clock { min-width: 72px; text-align: right; color: var(--strong); }
.replay select { font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 6px; }

@media (pointer: coarse) {
  .tool { width: 46px; height: 46px; }
  .seg button { padding: 7px 12px; }
  .switch { padding: 8px 0; }
}

@media (max-width: 640px) {
  .controls { left: 8px; right: 68px; top: 8px; width: auto; max-height: 55%; }
  .map-tools { top: 8px; right: 8px; }
  .replay { bottom: 8px; width: calc(100% - 16px); }
  .scale { bottom: 30px; left: 10px; }
  .panel-foot .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* Count of trackers needing attention, on the Vehicles nav item. */
.nav-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px; background: var(--alert); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }
.nav-count[hidden] { display: none; }
.bubble-issues { margin: 8px 0 0; padding: 6px 10px; list-style: none; border-radius: 8px; background: var(--alert-soft); color: var(--alert); font-size: 12px; font-weight: 600; }
.bubble-issues[hidden] { display: none; }
