/*
  Nocturne: infrastructure monitoring dashboard
  1. Tokens and browser surfaces  2. Top bar  3. Service map (transit diagram)
  4. Desk zones: incidents, signals, on call and deploys  5. Log tail  6. Station panel
  7. Components: toast (notice), scope listbox (select), order slip (confirmation dialog), tooltip, line bullet
  Layout: a fixed control-room frame on tall desktops; a scrolling page with the map across the top down to
  1000px; a strip map beside the charts on tablets; one stacked column on phones.
*/

/* ---------- 1. Tokens ---------- */
:root {
  --bg: #0b0e14;
  --bg-raise: #10141d;
  --bg-well: #080a0f;
  --rule: #1e2633;
  --rule-strong: #303b4e;
  --text: #c9d3e0;
  --text-bright: #eef3f9;
  --text-dim: #a8b3c4;
  --text-faint: #8794a8;

  --cyan: #5cc8ff;
  --cyan-dim: #3a86b3;
  --ok: #58d6a0;
  --warn: #f2b84b;
  --crit: #ff6f6f;

  --line-a: #a48cff;
  --line-b: #5d8dff;
  --line-c: #f086c2;
  --line-d: #d8d2c2;

  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Type scale: nothing on the screen is set below 12px */
  --fs-meta: 12px;   /* timestamps, counts, tags */
  --fs-data: 13px;   /* mono values, log lines, secondary sans */
  --fs-body: 14px;
  --fs-lead: 15px;   /* the open incident, current chart values */
  --fs-h2: 16px;
  --fs-h1: clamp(28px, 2.5vw, 36px);   /* the network headline */

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r1: 3px; --r2: 5px; --r3: 10px;
  --ctl: 32px;
  --ctl-sm: 28px;
  --bar-h: 52px;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --shadow: 0 18px 48px -12px rgb(0 0 0 / .7), 0 4px 12px rgb(0 0 0 / .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; scrollbar-color: var(--rule-strong) var(--bg); scrollbar-width: thin; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-body)/1.45 var(--sans);
  accent-color: var(--cyan);
  caret-color: var(--cyan);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
}
::selection { background: color-mix(in srgb, var(--cyan) 34%, transparent); color: var(--text-bright); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--rule-strong); border: 3px solid var(--bg); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: var(--r1); }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
h1, h2, h3 { text-wrap: balance; }
button, input { font: inherit; color: inherit; }
input:-webkit-autofill, input:-webkit-autofill:focus { -webkit-text-fill-color: var(--text-bright); box-shadow: 0 0 0 100px var(--bg) inset; caret-color: var(--cyan); }
button { cursor: pointer; }
a { color: var(--cyan); text-underline-offset: 3px; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--s3); top: -60px; z-index: 50; background: var(--cyan); color: var(--bg); padding: 8px 12px; border-radius: var(--r2); font-weight: 600; text-decoration: none; }
.skip:focus { top: var(--s3); }

/* State colour is always paired with a glyph and a word */
[data-state="ok"] { --state: var(--ok); }
[data-state="warn"] { --state: var(--warn); }
[data-state="crit"] { --state: var(--crit); }
[data-state="info"] { --state: var(--cyan); }

/* Shared controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--ctl); padding: 0 12px;
  background: var(--bg-raise); border: 1px solid var(--rule-strong); border-radius: var(--r2);
  font-size: var(--fs-data); font-weight: 500; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: #171d29; border-color: #3f4c63; color: var(--text-bright); }
.btn:active { background: var(--bg-well); }
.btn[aria-pressed="true"] { border-color: var(--cyan-dim); color: var(--cyan); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-icon { width: var(--ctl); padding: 0; }
.btn-sm { height: var(--ctl-sm); padding: 0 10px; }
.btn-go { background: var(--cyan); border-color: var(--cyan); color: #06121b; font-weight: 600; }
.btn-go:hover { background: #8ad8ff; border-color: #8ad8ff; color: #06121b; }
.btn-go:active { background: #45b4ec; }
.btn-ack { border-color: color-mix(in srgb, var(--warn) 60%, transparent); color: var(--warn); }
.btn-ack:hover { border-color: var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--bg-raise)); }
.btn-res { border-color: color-mix(in srgb, var(--ok) 60%, transparent); color: var(--ok); }
.btn-res:hover { border-color: var(--ok); color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--bg-raise)); }
.link { background: none; border: 0; padding: 0; color: var(--cyan); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--cyan) 45%, transparent); }
.link:hover { text-decoration-color: var(--cyan); }
kbd {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px;
  font: 500 var(--fs-meta)/1 var(--mono); color: var(--text-bright);
  background: var(--bg-well); border: 1px solid var(--rule-strong); border-radius: var(--r1);
}

/* ---------- 2. Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s4);
  min-height: var(--bar-h); padding: 0 var(--s5);
  background: var(--bg-raise); border-bottom: 1px solid var(--rule);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text-bright); text-decoration: none; font-weight: 600; font-size: var(--fs-h2); letter-spacing: -.01em; }
.brand svg { color: var(--cyan); }
.env { font: 400 var(--fs-meta)/1 var(--mono); color: var(--text-dim); padding: 6px 8px; border: 1px solid var(--rule); border-radius: var(--r1); white-space: nowrap; }
/* Network status: a quiet line when all is well, a tinted plate as soon as a station is not */
.net {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  height: var(--ctl-sm); padding: 0 10px; margin-left: -10px;
  font-weight: 500; color: var(--text-bright);
  border: 1px solid transparent; border-radius: var(--r2);
  transition: background-color .3s, border-color .3s, color .3s;
}
.net span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net .glyph { color: var(--state); }
.net[data-state="warn"], .net[data-state="crit"] {
  margin-left: 0; color: var(--state); font-weight: 600;
  background: color-mix(in srgb, var(--state) 11%, transparent);
  border-color: color-mix(in srgb, var(--state) 45%, transparent);
}
.bar-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.seg { display: inline-flex; background: var(--bg-well); border: 1px solid var(--rule-strong); border-radius: var(--r2); padding: 2px; height: var(--ctl); }
.seg button { border: 0; background: none; padding: 0 10px; border-radius: var(--r1); font: 500 var(--fs-meta)/1 var(--mono); color: var(--text-dim); white-space: nowrap; transition: background-color .15s, color .15s; }
.seg button:hover { color: var(--text-bright); }
.seg button[aria-pressed="true"] { background: #1d2635; color: var(--cyan); }
.clock { font: 400 var(--fs-meta)/1 var(--mono); color: var(--text-dim); font-variant-numeric: tabular-nums; padding: 0 var(--s2); white-space: nowrap; }
.help-wrap { position: relative; }
.help {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 30; width: min(340px, calc(100vw - 2 * var(--s4)));
  background: #121722; border: 1px solid var(--rule-strong); border-radius: var(--r3);
  padding: var(--s4) var(--s4) var(--s3); box-shadow: var(--shadow);
  animation: drop .22s var(--ease);
}
.help h2 { font-size: var(--fs-body); font-weight: 600; color: var(--text-bright); margin-bottom: var(--s3); }
.help dl div { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: var(--s3); padding: 5px 0; }
.help dl div + div { border-top: 1px solid var(--rule); }
.help dt { display: flex; gap: 4px; }
.help dd { font-size: var(--fs-data); color: var(--text); }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- 3. Service map ---------- */
.topo { border-bottom: 1px solid var(--rule); background:
  radial-gradient(120% 140% at 50% 0%, #0f141e 0%, var(--bg) 70%); min-width: 0; }
.topo { position: relative; }
.topo-head { display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--s3) var(--s5); padding: 14px var(--s5) 6px; }
/* The page headline is the state of the network: it changes colour and wording the moment a station does */
.headline { margin-right: auto; min-width: 0; }
.headline h1 { font-size: var(--fs-h1); line-height: 1.08; font-weight: 600; color: var(--text-bright); letter-spacing: -.03em; transition: color .3s; }
.headline h1[data-state="warn"], .headline h1[data-state="crit"] { color: var(--state); }
.headline h1 b { font: 500 .94em/1 var(--mono); letter-spacing: -.04em; }
.headline p { margin-top: 7px; font-size: var(--fs-data); color: var(--text-dim); text-wrap: pretty; max-width: 62ch; }
/* Line status board: the key to the map, and the first place a disrupted line shows */
.board { display: flex; gap: var(--s2); }
@media (max-width: 1279.98px) { .headline, .board { width: 100%; } .board li { flex: 1; } }
.board li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "b name val" "b stat stat";
  align-items: center; column-gap: 10px; row-gap: 2px; min-width: 184px; padding: 7px 12px 7px 8px;
  background: var(--bg-raise); border: 1px solid var(--rule); border-radius: var(--r2);
  transition: background-color .3s, border-color .3s;
}
.board li[data-state="warn"], .board li[data-state="crit"] { background: color-mix(in srgb, var(--state) 12%, var(--bg)); border-color: color-mix(in srgb, var(--state) 55%, transparent); }
.board .bullet { grid-area: b; width: 30px; height: 30px; font-size: 14px; }
.b-name { grid-area: name; font-size: var(--fs-data); font-weight: 500; color: var(--text-bright); white-space: nowrap; }
.b-val { grid-area: val; font: 400 var(--fs-meta)/1.3 var(--mono); color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.b-stat { grid-area: stat; display: flex; align-items: center; gap: 6px; font: 500 var(--fs-meta)/1.3 var(--mono); color: var(--state); white-space: nowrap; }
.board li[data-state="warn"] .b-stat, .board li[data-state="crit"] .b-stat { font-weight: 600; }
.legend { display: flex; gap: var(--s4); font-size: var(--fs-data); color: var(--text-dim); }
.legend li { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-state { position: absolute; left: var(--s5); bottom: 14px; }
.legend-state svg { color: var(--state); }
.topo-scroll { padding: 0 var(--s5) var(--s1); }
/* script.js draws the map at the pixel width of this box, so label sizes below are real pixels */
.map { width: 100%; height: auto; max-width: 1640px; margin: 0 auto; overflow: visible; }
.nojs { padding: var(--s5); color: var(--text-dim); }

.map .ln { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.map .ln-bed { fill: none; stroke: var(--bg); stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; }
.map .train { stroke: var(--bg); stroke-width: 1.25; }
.map .st { cursor: pointer; outline: none; }
.map .st-hit { fill: transparent; }
.map .st-mark { fill: var(--bg); stroke: var(--state); stroke-width: 2.5; transition: stroke .3s; }
.map .st-g { display: none; color: var(--state); }
.map .st[data-state="ok"] .g-ok, .map .st[data-state="warn"] .g-warn, .map .st[data-state="crit"] .g-crit { display: block; }
.map .st-name { font: 500 13px/1 var(--mono); fill: var(--text-bright); transition: fill .15s; }
.map .st-sub { font: 400 12px/1 var(--mono); fill: var(--text-dim); font-variant-numeric: tabular-nums; }
.map .st-sub .w { fill: var(--state); font-weight: 500; }
.map .st:hover .st-name { fill: #fff; }
.map .st:hover .st-ring { stroke: var(--rule-strong); }
.map .st-ring { fill: none; stroke: transparent; stroke-width: 1.5; transition: stroke .15s; }
.map .st[aria-pressed="true"] .st-ring { stroke: var(--cyan); }
.map .st[aria-pressed="true"] .st-name { fill: var(--cyan); }
.map .st:focus-visible .st-ring { stroke: var(--text-bright); stroke-dasharray: 3 2; }
.map .st-halo { fill: none; stroke: var(--state); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.map .st[data-state="warn"] .st-halo, .map .st[data-state="crit"] .st-halo { opacity: .4; transform: scale(1.5); }
.map .st[data-state="warn"] .st-mark, .map .st[data-state="crit"] .st-mark { fill: color-mix(in srgb, var(--state) 18%, var(--bg)); }
/* A station in trouble is the loudest thing on the map */
.map .st[data-state="warn"] .st-name, .map .st[data-state="crit"] .st-name { font-weight: 600; fill: var(--state); }
.map .st[data-state="warn"] .st-sub .w, .map .st[data-state="crit"] .st-sub .w { font-weight: 600; letter-spacing: .04em; }

/* ---------- 4. Desk zones ---------- */
.desk {
  position: relative;
  display: grid; grid-template-columns: 328px minmax(0, 1fr) 312px; gap: 1px;
  background: var(--rule); min-height: 0;
}
.zone { background: var(--bg); min-width: 0; min-height: 0; }
.zone-head { display: flex; align-items: baseline; gap: var(--s3); padding: 14px var(--s4) 10px; }
.zone-head h2, .log-head h2 { font-size: var(--fs-h2); line-height: 1.25; font-weight: 600; color: var(--text-bright); letter-spacing: -.005em; }
.count { margin-left: auto; font: 400 var(--fs-meta)/1.3 var(--mono); color: var(--text-dim); white-space: nowrap; }

/* Incidents: a vertical line of stops, newest first */
.incidents { overflow-y: auto; }
.quiet { margin: 0 var(--s4) var(--s4); padding: 10px var(--s3); font-size: var(--fs-data); color: var(--text-dim); background: var(--bg-raise); border: 1px solid var(--rule); border-radius: var(--r2); text-wrap: pretty; }
.timeline { padding: 2px var(--s4) var(--s5); }
.inc { position: relative; padding: 0 0 18px 26px; }
.inc::before { content: ""; position: absolute; left: 6px; top: 18px; bottom: -2px; width: 2px; background: var(--rule-strong); }
.inc:last-child { padding-bottom: 0; }
.inc:last-child::before { display: none; }
.inc-dot { position: absolute; left: 0; top: 2px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--state, var(--text-faint)); background: var(--bg); display: grid; place-items: center; color: var(--state); }
.inc-dot svg { width: 7px; height: 7px; }
.inc[data-status="resolved"] .inc-dot { border-color: var(--rule-strong); color: var(--text-faint); }
.inc-top { display: flex; align-items: baseline; gap: var(--s2); font: 400 var(--fs-meta)/1.4 var(--mono); color: var(--text-dim); }
.inc-top .sev { color: var(--text); font-weight: 500; }
.inc-top .st-word { margin-left: auto; color: var(--state, var(--text-faint)); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.inc-title { font-weight: 500; color: var(--text); margin-top: 3px; text-wrap: pretty; }
.inc-meta { font-size: var(--fs-data); color: var(--text-dim); margin-top: 2px; }
.inc-meta button { font-family: var(--mono); }
/* The open incident is the one thing on the desk that must not be missed */
.inc-open {
  padding: 12px var(--s3) 14px 34px; margin-bottom: var(--s5);
  background: color-mix(in srgb, var(--state) 9%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--state) 55%, transparent); border-radius: var(--r2);
  box-shadow: 0 10px 28px -14px color-mix(in srgb, var(--state) 55%, transparent);
  animation: arrive .5s var(--ease);
}
.inc-open + .inc-open { margin-top: calc(-1 * var(--s3)); }
.inc-open .inc-dot { left: 10px; top: 14px; background: transparent; }
.inc-open::before { display: none; }
.inc-open .inc-top .sev { color: var(--text-bright); font-weight: 600; }
.inc-open .inc-top .st-word { font-weight: 600; }
.inc-open .inc-title { font-size: var(--fs-lead); line-height: 1.35; font-weight: 600; color: var(--text-bright); margin-top: 5px; }
.inc-open .inc-meta { margin-top: 4px; color: var(--text); }
.inc-actions { display: flex; gap: var(--s2); margin-top: var(--s3); }
.inc-actions .btn { flex: 1; height: var(--ctl); }
.inc-events { margin-top: 14px; padding-top: 10px; border-top: 1px solid color-mix(in srgb, var(--state) 22%, transparent); display: grid; gap: 5px; font: 400 var(--fs-meta)/1.45 var(--mono); color: var(--text); }
.inc-events li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; }
.inc-events time { color: var(--text-dim); font-variant-numeric: tabular-nums; }
@keyframes arrive { from { opacity: 0; transform: translateY(-8px); clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }

/* Signals: latency is the anchor chart, error rate and throughput support it */
.signals {
  display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(104px, 1fr) minmax(104px, 1fr);
  column-gap: var(--s5); row-gap: 6px; padding-bottom: var(--s3); outline: none;
}
.signals .zone-head { grid-column: 1 / -1; align-items: center; }
.live { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font: 400 var(--fs-meta)/1 var(--mono); color: var(--text-dim); white-space: nowrap; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); }
.live[data-live="false"] { color: var(--warn); }
.live[data-live="false"] i { background: none; width: 8px; height: 9px; border-radius: 0; border-left: 3px solid var(--warn); border-right: 3px solid var(--warn); }
.chart { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; }
.chart-lat { grid-column: 1; grid-row: 2 / span 2; padding-left: var(--s4); }
.chart-err, .chart-rps { grid-column: 2; padding-right: var(--s4); }
.chart figcaption { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px var(--s4); padding: 0 0 var(--s2); }
.chart h3 { font-size: var(--fs-data); font-weight: 600; color: var(--text-bright); }
.keys { display: flex; flex-wrap: wrap; gap: 2px var(--s4); font: 400 var(--fs-meta)/1.3 var(--mono); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.keys li { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.keys b { font-size: 17px; font-weight: 500; letter-spacing: -.02em; color: var(--text-bright); }
.k { width: 14px; height: 0; border-top: 2.5px solid var(--cyan); align-self: center; }
.k-95 { border-top-color: #a6e0ff; border-top-width: 2px; }
.k-99 { border-top: 2px dashed #8fb6d0; }
.plot { position: relative; min-height: 0; border-top: 1px solid var(--rule); }
.plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }

/* On call and deploys */
.side { overflow-y: auto; display: flex; flex-direction: column; }
.side > section + section { border-top: 1px solid var(--rule); margin-top: var(--s3); }
.roster { padding-bottom: 2px; }
.roster li { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: var(--s3); padding: 7px var(--s4); }
.who { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font: 500 var(--fs-meta)/1 var(--mono); color: var(--text-bright); background: #18202d; border: 1px solid var(--rule-strong); }
.roster li:first-child .who { border-color: var(--cyan-dim); color: var(--cyan); }
.roster .nm { font-weight: 500; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .rl { font-size: var(--fs-data); color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .paged { font: 400 var(--fs-meta)/1.2 var(--mono); color: var(--ok); text-align: right; }
.roster .paged.shift { color: var(--text-dim); }
.deploys li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px var(--s3); padding: 9px var(--s4); }
.deploys li + li { border-top: 1px solid var(--rule); }
.deploys .svc { font: 500 var(--fs-data)/1.4 var(--mono); }
.deploys .ver { font: 400 var(--fs-data)/1.4 var(--mono); color: var(--text); }
.deploys .by { grid-column: 1; font-size: var(--fs-data); color: var(--text-dim); }
.deploys .when { font: 400 var(--fs-meta)/1.5 var(--mono); color: var(--text-dim); text-align: right; }
.deploys .dstate { font: 500 var(--fs-meta)/1.5 var(--mono); color: var(--text); text-align: right; }
.deploys .dstate[data-kind="rolled"] { color: var(--warn); }
.deploys .dstate[data-kind="canary"] { color: var(--cyan); }
.deploys li.new { animation: arrive .5s var(--ease); }

/* ---------- 5. Log tail ---------- */
.logs { border-top: 1px solid var(--rule-strong); background: var(--bg-well); display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); height: 212px; min-height: 0; min-width: 0; }
.log-head { display: flex; align-items: center; gap: var(--s3); padding: 7px var(--s5); border-bottom: 1px solid var(--rule); }
.log-head h2 { margin-right: var(--s1); white-space: nowrap; }
.levels { display: inline-flex; gap: 4px; }
.lvl { height: var(--ctl-sm); padding: 0 9px; border-radius: var(--r2); background: none; border: 1px solid var(--rule); font: 500 var(--fs-meta)/1 var(--mono); color: var(--text-faint); display: inline-flex; align-items: center; gap: 6px; text-decoration: line-through; text-decoration-color: var(--text-faint); transition: border-color .15s, color .15s, background-color .15s; }
.lvl b { font-weight: 400; color: inherit; text-decoration: none; display: inline-block; font-variant-numeric: tabular-nums; }
.lvl:hover { border-color: var(--rule-strong); color: var(--text); }
.lvl[aria-pressed="true"] { text-decoration: none; background: var(--bg-raise); border-color: var(--rule-strong); color: var(--lv, var(--text)); }
.lvl[data-level="debug"] { --lv: var(--text-dim); }
.lvl[data-level="info"] { --lv: var(--text-bright); }
.lvl[data-level="warn"] { --lv: var(--warn); }
.lvl[data-level="error"] { --lv: var(--crit); }
.search { display: flex; align-items: center; gap: 6px; height: var(--ctl-sm); padding: 0 8px; flex: 0 1 300px; min-width: 120px; background: var(--bg); border: 1px solid var(--rule-strong); border-radius: var(--r2); color: var(--text-dim); }
.search:focus-within { border-color: var(--cyan); outline: 2px solid color-mix(in srgb, var(--cyan) 35%, transparent); outline-offset: 1px; }
.search input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: 0; font: 400 var(--fs-data)/1 var(--mono); color: var(--text-bright); }
.search input::placeholder { color: var(--text-faint); opacity: 1; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; width: 12px; height: 12px; cursor: pointer; background: linear-gradient(45deg, transparent 44%, var(--text-dim) 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, var(--text-dim) 44% 56%, transparent 56%); }
.log-count { margin-left: auto; font: 400 var(--fs-meta)/1 var(--mono); color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-body { overflow-y: auto; min-height: 0; padding: 6px 0; scrollbar-color: var(--rule-strong) var(--bg-well); }
.log-body:focus-visible { outline-offset: -2px; }
#logList li { display: grid; grid-template-columns: 100px 46px 108px minmax(0, 1fr); gap: var(--s3); padding: 2px var(--s5); font: 400 var(--fs-data)/1.35 var(--mono); color: var(--text); white-space: nowrap; }
#logList li:hover { background: #10151e; }
#logList .ts { color: var(--text-faint); font-variant-numeric: tabular-nums; }
#logList .lv { font-weight: 500; }
#logList [data-l="debug"] .lv { color: var(--text-faint); }
#logList [data-l="info"] .lv { color: var(--text-dim); }
#logList [data-l="warn"] .lv { color: var(--warn); }
#logList [data-l="error"] .lv { color: var(--crit); }
#logList [data-l="debug"] .msg { color: var(--text-dim); }
#logList [data-l="warn"] .msg, #logList [data-l="error"] .msg { color: var(--text-bright); }
#logList [data-l="error"] { background: color-mix(in srgb, var(--crit) 7%, transparent); }
#logList .sv { color: var(--cyan); overflow: hidden; text-overflow: ellipsis; }
#logList .msg { overflow: hidden; text-overflow: ellipsis; }
mark { background: color-mix(in srgb, var(--cyan) 30%, transparent); color: var(--text-bright); border-radius: 2px; }
.log-empty { padding: var(--s5); display: flex; align-items: center; gap: var(--s4); color: var(--text-dim); }
.log-empty strong { color: var(--text-bright); font-weight: 500; }

/* ---------- 6. Station panel ---------- */
.panel {
  position: absolute; z-index: 5; top: 0; right: 0; bottom: 0; width: 312px;
  overflow-y: auto; overscroll-behavior: contain;
  background: #10151e; border-left: 1px solid var(--rule-strong);
  padding: var(--s3) var(--s4) var(--s4);
  animation: slide .32s var(--ease);
}
.desk:has(.panel:not([hidden])) .side { visibility: hidden; }
@keyframes slide { from { transform: translateX(28px); opacity: 0; } }
.panel-head { display: flex; align-items: center; gap: var(--s3); }
.panel-head h2 { font: 500 var(--fs-h2)/1.2 var(--mono); color: var(--text-bright); margin-right: auto; outline: none; letter-spacing: -.01em; min-width: 0; overflow-wrap: anywhere; }
.state-tag { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border-radius: var(--r1); font: 600 var(--fs-meta)/1 var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--state); border: 1px solid color-mix(in srgb, var(--state) 50%, transparent); background: color-mix(in srgb, var(--state) 10%, transparent); white-space: nowrap; }
.panel-sum { margin-top: var(--s3); color: var(--text); text-wrap: pretty; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s3); }
.chips li { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-data); padding: 3px 10px 3px 3px; border: 1px solid var(--rule-strong); border-radius: 14px; }
.chips .bullet { width: 20px; height: 20px; font-size: 11px; }
.metrics { margin-top: var(--s4); display: grid; grid-template-columns: 1fr 1fr 1fr; border-top: 1px solid var(--rule); }
.metrics div { padding: var(--s2) 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.metrics dt { font-size: var(--fs-meta); color: var(--text-dim); }
.metrics dd { font: 500 var(--fs-body)/1.4 var(--mono); letter-spacing: -.02em; white-space: nowrap; color: var(--text-bright); font-variant-numeric: tabular-nums; }
.stops { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); margin-top: var(--s4); }
.stops h3, .panel-sub { font-size: var(--fs-data); font-weight: 600; color: var(--text-bright); margin-bottom: 4px; }
.stops li { font: 400 var(--fs-data)/1.9 var(--mono); }
.stops .none { color: var(--text-dim); font-family: var(--sans); }
.panel-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.panel-actions .btn { flex: 1; }
.panel-sub { margin-top: var(--s5); }
.panel-log { font: 400 var(--fs-meta)/1.6 var(--mono); color: var(--text); background: var(--bg-well); border: 1px solid var(--rule); border-radius: var(--r2); padding: var(--s2) var(--s3); margin-bottom: var(--s3); }
.panel-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-log .ts { color: var(--text-faint); margin-right: 8px; }
.panel > .link { font-size: var(--fs-data); }

/* ==========================================================================
   7. Components
   A themed kit drawn from the tokens above. Nothing here is a browser default.
   - .toast          notice / alert (script: toast())
   - .pick           select: button + listbox drawn as a strip map (script: scope listbox)
   - .modal .order   confirmation dialog, a dispatcher's order slip (script: confirmOrder())
   - .tip            tooltip plate for any control with data-tip (and data-key for a shortcut)
   - .bullet         line roundel; set --c to a line colour
   ========================================================================== */

/* Line bullet */
.bullet { display: inline-grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #0b0e14; font: 600 12px/1 var(--mono); }

/* Select: scope listbox */
.pick { position: relative; min-width: 0; }
.pick-btn {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: var(--ctl-sm); padding: 0 6px 0 10px;
  background: var(--bg-raise); border: 1px solid var(--rule-strong); border-radius: var(--r2);
  font: 400 var(--fs-meta)/1 var(--mono); color: var(--text-dim); transition: background-color .15s, border-color .15s;
}
.pick-btn:hover { background: #171d29; border-color: #3f4c63; }
.pick-btn[aria-expanded="true"] { border-color: var(--cyan-dim); }
.pick-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-value b { font-weight: 500; color: var(--text-bright); margin-right: 4px; }
.pick-btn svg { color: var(--text-dim); transition: transform .25s var(--ease); }
.pick-btn[aria-expanded="true"] svg { transform: rotate(180deg); color: var(--cyan); }
.pick-list {
  position: absolute; z-index: 15; left: 0; top: calc(100% + 6px);
  width: 312px; max-width: calc(100vw - 2 * var(--s4)); max-height: min(396px, 58dvh); overflow-y: auto; overscroll-behavior: contain;
  padding: 6px; background: #121722; border: 1px solid var(--rule-strong); border-radius: var(--r3); box-shadow: var(--shadow);
  scrollbar-color: var(--rule-strong) #121722; outline: none;
  transform-origin: 24px 0; animation: unroll .26s var(--ease);
}
.pick-list:focus-visible { border-color: var(--cyan-dim); }
.pick-list li {
  position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  min-height: 34px; padding: 0 8px 0 10px; border-radius: var(--r1);
  font: 400 var(--fs-data)/1.2 var(--mono); color: var(--text); cursor: pointer;
}
/* the rail: every option is a stop on one vertical line */
.pick-list li::before { content: ""; position: absolute; left: 17px; top: 0; bottom: 0; width: 2px; background: var(--rule-strong); }
.pick-list li:first-child::before { top: 50%; }
.pick-list li:last-child::before { bottom: 50%; }
.o-mark { position: relative; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: #121722; border: 2px solid var(--state, var(--text-dim)); color: var(--state); }
.o-mark svg { width: 8px; height: 8px; }
.o-all { border-radius: 4px; border-color: var(--text-bright); background: var(--text-bright); }
.o-sub { color: var(--text-dim); font-size: var(--fs-meta); }
.o-lines { display: flex; gap: 3px; }
.o-lines .bullet { width: 18px; height: 18px; font-size: 10px; }
.pick-list li.is-active { background: #1d2635; color: var(--text-bright); }
.pick-list li.is-active .o-mark { background: #1d2635; }
.pick-list li[aria-selected="true"] .o-name { color: var(--cyan); font-weight: 500; }
.pick-list li[aria-selected="true"] { box-shadow: inset 0 0 0 1px var(--cyan-dim); }
.pick-list li[data-state="warn"] .o-name, .pick-list li[data-state="crit"] .o-name { color: var(--state); font-weight: 500; }
@keyframes unroll { from { opacity: 0; transform: translateY(-4px) scaleY(.92); clip-path: inset(0 0 60% 0 round 10px); } to { clip-path: inset(0 0 0 0 round 10px); } }

/* Confirmation dialog: order slip */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--s4); }
.modal-shade { position: absolute; inset: 0; background: rgb(4 6 10 / .8); animation: shade-in .2s ease-out; }
.order {
  position: relative; width: min(452px, 100%); max-height: calc(100dvh - 2 * var(--s4)); overflow-y: auto;
  background: #121722; border: 1px solid var(--state); border-radius: var(--r3); box-shadow: var(--shadow);
  animation: order-in .32s var(--ease);
}
.order-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px var(--s4); background: var(--state); color: #0b0e14; }
.order-head svg { margin-top: 4px; }
.order-head h2 { font-size: 19px; line-height: 1.25; font-weight: 600; letter-spacing: -.015em; overflow-wrap: anywhere; }
.order-rows { padding: 6px var(--s4) 0; }
.order-rows div { display: grid; grid-template-columns: 116px minmax(0, 1fr); gap: var(--s3); padding: 9px 0; border-bottom: 1px dashed var(--rule-strong); }
.order-rows dt { font-size: var(--fs-data); color: var(--text-dim); }
.order-rows dd { font: 400 var(--fs-data)/1.45 var(--mono); color: var(--text-bright); overflow-wrap: anywhere; }
.order-note { padding: var(--s3) var(--s4) 0; font-size: var(--fs-data); color: var(--text); text-wrap: pretty; }
.order-actions { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4); }
.btn-state { background: var(--state); border-color: var(--state); color: #0b0e14; font-weight: 600; }
.btn-state:hover { background: color-mix(in srgb, var(--state) 80%, white); border-color: color-mix(in srgb, var(--state) 80%, white); color: #0b0e14; }
.btn-state:active { background: color-mix(in srgb, var(--state) 85%, black); }
.modal.closing .modal-shade { animation: shade-out .17s ease-in forwards; }
.modal.closing .order { animation: order-out .17s ease-in forwards; }
@keyframes shade-in { from { opacity: 0; } }
@keyframes shade-out { to { opacity: 0; } }
@keyframes order-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes order-out { to { opacity: 0; transform: translateY(6px) scale(.98); } }

/* Tooltip: a light plate, the one bright surface on the desk */
.tip {
  position: fixed; z-index: 70; left: 0; top: 0; pointer-events: none;
  display: flex; align-items: center; gap: 8px; max-width: 280px; padding: 5px 6px 5px 9px;
  background: var(--text-bright); color: #0b0e14; border-radius: var(--r1); box-shadow: 0 6px 18px -6px rgb(0 0 0 / .8);
  font: 500 var(--fs-meta)/1.35 var(--sans); animation: tip-in .16s var(--ease);
}
.tip span { padding: 1px 3px 1px 0; }
.tip kbd { min-width: 20px; height: 20px; padding: 0 5px; background: #0b0e14; border-color: #0b0e14; color: var(--text-bright); }
.tip[data-side="above"] { --from: 3px; }
@keyframes tip-in { from { opacity: 0; transform: translateY(var(--from, -3px)); } }

/* Notice: toast */
.toasts { position: fixed; z-index: 40; bottom: var(--s4); right: var(--s4); display: grid; gap: var(--s2); width: min(400px, calc(100vw - 2 * var(--s4))); pointer-events: none; }
.toast {
  pointer-events: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px var(--s3);
  background: #131924; border: 1px solid color-mix(in srgb, var(--state, var(--rule-strong)) 55%, var(--rule-strong));
  border-radius: var(--r3); padding: var(--s3) var(--s3) var(--s3) var(--s4); box-shadow: var(--shadow);
  animation: toast-in .4s var(--ease);
}
.toast.out { animation: toast-out .25s ease-in forwards; }
.toast-title { font-weight: 500; color: var(--text-bright); text-wrap: pretty; }
.toast[role="alert"] .toast-title { font-size: var(--fs-lead); font-weight: 600; line-height: 1.35; }
.toast-meta { font: 400 var(--fs-meta)/1.45 var(--mono); color: var(--text-dim); grid-column: 1; }
.toast .state-tag { justify-self: start; margin-bottom: 4px; }
.toast .x { grid-column: 2; grid-row: 1 / span 2; align-self: start; width: 28px; height: 28px; margin: -4px -4px 0 0; border: 0; background: none; border-radius: var(--r2); display: grid; place-items: center; color: var(--text-dim); }
.toast .x:hover { color: var(--text-bright); background: #1d2635; }
.toast-actions { grid-column: 1 / -1; display: flex; gap: var(--s2); margin-top: var(--s2); }
/* Only the newest alert keeps its detail and actions; older ones fold to a tag and a title */
.toast[role="alert"] ~ .toast[role="alert"] :is(.toast-meta, .toast-actions) { display: none; }
.toast[role="alert"] ~ .toast[role="alert"] .toast-title { font-size: var(--fs-body); font-weight: 500; }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); filter: blur(4px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  .live[data-live="true"] i { animation: blink 2s steps(2, jump-none) infinite; }
  .map .st[data-state="warn"] .st-halo { animation: halo 1.8s ease-out infinite; }
  .map .st[data-state="crit"] .st-halo { animation: halo .9s ease-out infinite; }
}
@keyframes blink { from { opacity: 1; } to { opacity: .3; } }
@keyframes halo { from { transform: scale(.75); opacity: .8; } to { transform: scale(1.9); opacity: 0; } }
/* Reduced motion: trains hold at their stops, charts step once a second, the halo is a still ring */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Layout modes ---------- */
/* Control-room frame: everything in one screen, zones scroll inside */
@media (min-width: 1180px) and (min-height: 820px) {
  body { height: 100dvh; overflow: hidden; }
  .logs { height: clamp(176px, 20dvh, 280px); }
}
/* Shorter desktop windows: the page scrolls, zones keep a working height */
@media (min-width: 1180px) and (max-height: 819.98px) {
  .desk { min-height: 440px; }
  .incidents, .side { max-height: 440px; }
}

/* Small laptops and landscape tablets: map across the top, charts full width, two columns under them */
@media (max-width: 1179.98px) {
  .desk { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .signals { grid-column: 1 / -1; grid-row: 1; grid-template-rows: auto 168px 168px; padding-bottom: var(--s4); }
  .logs { height: 340px; }
  .env { display: none; }
  .panel { position: fixed; z-index: 25; top: var(--bar-h); width: 372px; max-width: 100%; box-shadow: var(--shadow); padding: var(--s4) var(--s5) var(--s5); }
  .desk:has(.panel:not([hidden])) .side { visibility: visible; }
}
@media (max-width: 1099.98px) {
  .clock { display: none; }
}

/* Tablets: the map turns into a strip map and stands beside the charts */
@media (max-width: 999.98px) {
  .bar { gap: var(--s3); padding: 0 var(--s4); }
  .btn-go .more { display: none; }
  .log-head { padding-inline: var(--s4); }
  .search { min-width: 96px; }
  .topo-head { gap: var(--s3); padding: var(--s4) var(--s4) 0; }
  .headline { width: 100%; }
  /* the board becomes four timetable rows */
  .board { flex-direction: column; gap: 0; width: 100%; border-top: 1px solid var(--rule); }
  .board li { flex: none; grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "b name stat val"; min-width: 0; padding: 7px 0; background: none; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0; }
  .board li[data-state="warn"], .board li[data-state="crit"] { padding-inline: 8px; margin-inline: -8px; border-radius: var(--r2); border: 1px solid color-mix(in srgb, var(--state) 55%, transparent); }
  .board .bullet { width: 26px; height: 26px; font-size: 13px; }
  .b-val { min-width: 52px; }
  .legend-state { position: static; padding: 0 var(--s4) var(--s4); }
  .topo-scroll { padding: var(--s3) var(--s2) var(--s3) var(--s4); }
  .map { max-width: 430px; }
  .signals { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(200px, 1.5fr) minmax(140px, 1fr) minmax(140px, 1fr); row-gap: var(--s3); }
  .chart-lat, .chart-err, .chart-rps { grid-column: 1; grid-row: auto; padding: 0 var(--s4); }
  .signals .zone-head { flex-wrap: wrap; row-gap: 6px; }
}
@media (min-width: 760px) and (max-width: 999.98px) {
  body { grid-template-columns: 372px minmax(0, 1fr); }
  .bar, .logs { grid-column: 1 / -1; }
  .desk { display: contents; }
  .topo { grid-column: 1; grid-row: 2; border-right: 1px solid var(--rule); }
  .signals { grid-column: 2; grid-row: 2; border-bottom: 1px solid var(--rule); }
  .incidents { grid-column: 1; grid-row: 3; border-right: 1px solid var(--rule); }
  .side { grid-column: 2; grid-row: 3; }
  #pauseBtn { width: var(--ctl); padding: 0; }
  #pauseBtn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* Phones: one column, 44px controls, the station panel becomes a bottom sheet */
@media (max-width: 759.98px) {
  :root { --ctl: 44px; --ctl-sm: 44px; --bar-h: 108px; }
  .bar { position: static; flex-wrap: wrap; gap: var(--s2) var(--s3); padding: 10px var(--s4) var(--s3); }
  .net { margin-left: auto; height: 32px; }
  .net[data-state="ok"] { padding-right: 0; }
  .bar-tools { width: 100%; margin: 0; }
  .seg { flex: 1; }
  .seg button { flex: 1; padding: 0 4px; position: relative; }
  .seg button::after { content: ""; position: absolute; inset: -4px 0; }   /* 44px touch target */
  .brand { min-height: 44px; }
  .btn-go { padding: 0 14px; }

  .topo-scroll { padding: var(--s2) var(--s2) var(--s3); }

  .desk { grid-template-columns: minmax(0, 1fr); }
  .signals { grid-template-rows: auto 220px 156px 156px; }
  .roster li, .deploys li { padding-top: 10px; padding-bottom: 10px; }
  .inc-actions .btn, .toast-actions .btn, .panel-actions .btn, .order-actions .btn { flex: 1; }
  .signals .zone-head { position: relative; }
  .pick { position: static; order: 3; width: 100%; }
  .pick-btn { width: 100%; justify-content: space-between; font-size: var(--fs-data); }
  .pick-list { left: var(--s4); right: var(--s4); top: calc(100% - 2px); width: auto; max-width: none; max-height: min(420px, 60dvh); }
  .pick-list li { min-height: 44px; }
  .modal { place-items: end center; padding: var(--s2); }
  .order { width: 100%; }
  .order-rows div { grid-template-columns: 104px minmax(0, 1fr); }
  .stops .link, .inc-meta .link, .deploys .link, .panel > .link { padding-block: 13px; }
  .inc-meta .link, .deploys .link { margin-block: -8px; }
  .deploys li { align-items: baseline; }
  .toast .x { width: 44px; height: 44px; margin: -8px -8px 0 0; }

  .logs { height: auto; }
  .log-head { flex-wrap: wrap; padding: var(--s3) var(--s4); gap: var(--s2); }
  .log-head h2 { margin-right: auto; order: 0; }
  #followBtn { order: 1; }
  .levels { order: 2; width: 100%; }
  .lvl { flex: 1; justify-content: center; padding: 0 4px; }
  .search { order: 3; flex: 1 1 100%; }
  .log-count { order: 4; margin: 0; }
  .log-body { height: 360px; }
  #logList li { grid-template-columns: 92px 44px minmax(0, 1fr); gap: 0 var(--s2); padding: 6px var(--s4); white-space: normal; border-bottom: 1px solid var(--rule); }
  #logList .ts { font-size: var(--fs-meta); align-self: center; }
  #logList .sv { grid-column: 3; }
  #logList .msg { grid-column: 1 / -1; overflow-wrap: anywhere; }
  .log-empty { flex-direction: column; align-items: flex-start; padding: var(--s4); }

  .panel { top: auto; left: 0; width: 100%; max-height: 72dvh; border-left: 0; border-top: 1px solid var(--rule-strong); border-radius: var(--r3) var(--r3) 0 0; padding: var(--s4) var(--s4) var(--s6); animation-name: rise; }
  /* alerts sit at the thumb, so the headline and the line board stay readable above them */
  .toasts { bottom: var(--s2); right: var(--s2); width: calc(100vw - 2 * var(--s2)); }
}
/* Narrow phones: short window labels and an icon-only pause keep the shortcuts button in the bar */
@media (max-width: 429.98px) {
  #pauseBtn { width: var(--ctl); padding: 0; }
  #pauseBtn span, .seg button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .seg button::before { content: attr(data-short); }
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
