/* IoT Hub Gateway console.
   Palette values come from the validated reference instance: categorical slots
   1 and 2 for series, the fixed status palette for state. Both modes are
   selected rather than flipped — the dark steps are chosen for the dark
   surface. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  /* Badge-only override: slot-1 blue is 4.42:1 on white, fractionally under the
     4.5 that 10px text requires. Blue ramp step 500, same hue, 5.39:1. */
  --badge-1: #256abf;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;

  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --success-text: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }

h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 13px; font-weight: 600; margin: 0 0 10px; color: var(--text-secondary); }

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- login */

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--page); z-index: 50; padding: 20px;
}
.login-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { margin: 0; }
.login-card label { font-size: 12px; color: var(--text-secondary); }
.login-error { color: var(--critical); font-size: 13px; margin: 0; }

/* ---------------------------------------------------------------- chrome */

.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex: none; }
.dot.ok { background: var(--good); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--critical); }

.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs a {
  padding: 6px 12px; border-radius: 6px; color: var(--text-secondary);
  font-weight: 500; text-decoration: none;
}
.tabs a:hover { background: var(--page); text-decoration: none; }
.tabs a.active { background: var(--page); color: var(--text-primary); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

main { padding: 20px; max-width: 1440px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------- controls */

button, select, input, textarea {
  font: inherit; color: inherit; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-1); padding: 6px 10px;
}
button { cursor: pointer; font-weight: 500; }
button:hover { border-color: var(--axis); }
button[type="submit"], #command-send {
  background: var(--series-1); border-color: transparent; color: #fff;
}
button[type="submit"]:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

input[type="search"], input[type="text"], input[type="password"], textarea, select { width: 100%; }
textarea { resize: vertical; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="search"], .toolbar input[type="text"] { max-width: 260px; }
.toolbar select { width: auto; }
.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--text-secondary); }
.check input { width: auto; }
.back { display: inline-block; font-size: 13px; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; min-width: 0;
}
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
figure.card { margin: 0; }
figcaption { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
figcaption h2 { margin: 0; }

/* ---------------------------------------------------------------- figures */

.hero-row { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 16px; }
.hero {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; justify-content: center;
}
.hero .label { font-size: 13px; color: var(--text-secondary); }
.hero-value { font-size: 56px; font-weight: 600; line-height: 1.05; margin: 4px 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 22px; font-weight: 600; }
.tile .sub { font-size: 11px; color: var(--text-muted); }
.tile svg { margin-top: 4px; }

/* ---------------------------------------------------------------- charts */

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--text-secondary); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 100;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .16); max-width: 280px;
}
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .tt-key { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .tt-val { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- status */

.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status .icon { font-size: 11px; line-height: 1; }
.s-good { color: var(--success-text); }
.s-warning { color: var(--text-primary); }
.s-serious { color: var(--text-primary); }
.s-critical { color: var(--critical); }
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border);
}
.chip.online { color: var(--success-text); }
.chip.offline { color: var(--text-muted); }

.notice { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.notice > div { min-width: 0; overflow-wrap: anywhere; }
.notice:last-child { border-bottom: none; }
.notice .when { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.empty { color: var(--text-muted); padding: 10px 0; }

.bar-track { display: flex; gap: 2px; margin: 8px 0 10px; }
.bar-seg { height: 14px; border-radius: 2px; }
.bar-seg:first-child { border-radius: 4px 2px 2px 4px; }
.bar-seg:last-child { border-radius: 2px 4px 4px 2px; }
.outcome-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); padding: 9px 12px;
  border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 8px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--page); }
td.imei { font-family: var(--mono); }
/* .wrap lets a cell break. white-space:normal alone is not enough — a device
   reply like [VERSION]KMC28_..._250904.1907 is one 51-character token with no
   spaces, so normal wrapping has nothing to break on. overflow-wrap:anywhere
   breaks it *and* lowers the cell's min-content width, which is what actually
   allows the column to shrink instead of forcing the table wide. */
td.wrap { white-space: normal; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- packets */

.split { display: grid; grid-template-columns: 1fr minmax(300px, 420px); gap: 16px; align-items: start; }
.packet-list {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  height: 62vh; overflow-y: auto; font-family: var(--mono); font-size: 12px;
}
.pkt { padding: 4px 10px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.pkt-line { display: flex; gap: 8px; align-items: baseline; }
/* The decoded meaning, subordinate to the frame above it but still meant to be
   read, so it keeps secondary ink rather than muted. */
.pkt-meaning {
  font-size: 11px; color: var(--text-secondary); padding-left: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pkt-meaning:empty { display: none; }
.pkt-meaning.bad { color: var(--critical); }
.pkt:hover { background: var(--page); }
.pkt.sel { background: var(--page); }
.pkt .t { color: var(--text-muted); }
.pkt .d { font-weight: 700; width: 12px; flex: none; text-align: center; }
.pkt .in { color: var(--series-1); }
.pkt .out { color: var(--series-2); }
.pkt .bad { color: var(--critical); }
.pkt .hex { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; }
.packet-detail { position: sticky; top: 76px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 12px; margin: 8px 0; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
pre.json {
  background: var(--page); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; font-size: 11px; overflow-x: auto; margin: 8px 0 0;
}

.command-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.result { padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); margin-top: 10px; font-size: 13px; }

@media (max-width: 900px) {
  .card-row, .hero-row, .split { grid-template-columns: 1fr; }
  .packet-detail { position: static; }
  main { padding: 12px; }
}

/* ---------------------------------------------------------------- live video */

.live-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.live-bar select { width: auto; }

.video-wrap { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; }
.video-wrap video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.video-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px; text-align: center;
  padding: 16px; background: var(--surface-1);
}
.video-overlay p { margin: 0; }
.video-overlay.transparent { background: rgba(0, 0, 0, .55); }
.video-overlay.transparent p { color: #fff; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--series-1);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---------------------------------------------------------------- support */

.device-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.device-head h1 { margin: 0; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.tl { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--grid); align-items: baseline; }
.tl:last-child { border-bottom: none; }
.tl .when { color: var(--text-muted); font-size: 11px; white-space: nowrap; min-width: 108px; font-variant-numeric: tabular-nums; }
.tl .kind {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid var(--border); border-radius: 999px; padding: 0 6px;
  white-space: nowrap; color: var(--text-secondary);
}
.tl .what { min-width: 0; overflow-wrap: anywhere; }
time[title] { text-decoration: none; cursor: help; }

/* ---------------------------------------------------------------- triage */

.banner {
  padding: 10px 20px; font-size: 13px; font-weight: 500;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.banner .icon { color: var(--critical); }

.verdict {
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius); background: var(--surface-1); padding: 14px 16px;
}
.verdict .headline { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.verdict .detail { margin: 0; color: var(--text-secondary); }
.verdict .action { margin: 8px 0 0; }
.verdict.v-ok { border-left-color: var(--good); }
.verdict.v-info { border-left-color: var(--axis); }
.verdict.v-warn { border-left-color: var(--warning); }
.verdict.v-critical { border-left-color: var(--critical); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: transparent; }
.chip-btn.active { background: var(--series-1); border-color: transparent; color: #fff; }

.role-badge {
  font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary);
}

/* ------------------------------------------------------- device detail split */

/* Live video on the left, everything else stacked on the right. The video is
   sticky because the timeline on the right is long: an operator scrolling
   through events still wants to see what the camera is showing. */
.detail-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.detail-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.detail-col-left { position: sticky; top: 76px; }

@media (max-width: 1100px) {
  .detail-split { grid-template-columns: 1fr; }
  .detail-col-left { position: static; }
}

/* ---------------------------------------------------------------- alarms */

.alarm { padding: 9px 0; border-bottom: 1px solid var(--grid); }
.alarm:last-child { border-bottom: none; }
.alarm-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.alarm-head .label { font-weight: 600; }
.alarm-head .when { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.alarm .meta { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }

.clip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 6px; padding: 6px 8px;
  background: var(--page); border-radius: 6px; font-size: 12px;
}
.clip .name { font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; min-width: 0; flex: 1; }
.clip button { font-size: 12px; padding: 3px 9px; }
.clip .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; white-space: nowrap;
  color: var(--text-secondary);
}

/* ------------------------------------------------------- timeline detail */

.tl-item { border-bottom: 1px solid var(--grid); }
.tl-item:last-child { border-bottom: none; }
.tl-item .tl { border-bottom: none; }

.tl-toggle {
  margin-left: auto; font-size: 11px; padding: 2px 8px;
  background: transparent; color: var(--text-secondary); white-space: nowrap;
}

.tl-detail { padding: 4px 0 12px 118px; }
@media (max-width: 700px) { .tl-detail { padding-left: 0; } }

.fields { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 3px 16px; margin: 0 0 10px; font-size: 12px; }
.fields dt { color: var(--text-secondary); }
.fields dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.tl-actions { display: flex; gap: 6px; }
.tl-actions button { font-size: 11px; padding: 2px 10px; }
.tl-actions button.active-view { background: var(--series-1); border-color: transparent; color: #fff; }

/* ---------------------------------------------------------- camera dialog */

.cam-dialog {
  width: min(900px, 94vw); padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface-1); color: var(--text-primary);
}
.cam-dialog::backdrop { background: rgba(0, 0, 0, .6); }
.cam-dialog-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cam-dialog-head h2 { margin: 0; margin-right: auto; }

/* The detail split is no longer sticky: both columns are now long, so pinning
   one of them would strand the other. */
.detail-col-left { position: static; }

/* ------------------------------------------------------------------- map */

.map { height: 320px; border-radius: 8px; overflow: hidden; background: var(--page); }
.map .leaflet-container { background: var(--page); font: inherit; }
/* Tiles are bright; in dark mode knock them back so the marker still reads. */
:root[data-theme="dark"] .map .leaflet-tile,
:root:where(:not([data-theme="light"])) .map .leaflet-tile {
  filter: brightness(.72) contrast(1.08);
}
@media (prefers-color-scheme: light) {
  :root[data-theme="light"] .map .leaflet-tile { filter: none; }
}
.map .leaflet-control-attribution { font-size: 10px; }
.map-empty { display: grid; place-items: center; height: 100%; text-align: center; padding: 20px; }

/* --------------------------------------------------- timeline event badges

   Event type is categorical identity, so it uses the categorical slots in
   fixed order rather than status colours — an event is not good or bad, it is
   a kind of thing. Low-signal types (echo, bare acks) stay muted so they do not
   compete with the events someone is actually looking for.

   Text inside a filled badge takes its colour from the fill's luminance, which
   is the one place text may leave the ink tokens: on a coloured fill nothing
   else guarantees contrast. */

.tl .kind { border-color: transparent; font-weight: 600; }
.tl .kind.k-muted { background: transparent; border-color: var(--border); color: var(--text-muted); }

/* ------------------------------------------------------- status-lit tiles */

.tile.st { border-left: 3px solid var(--border); }
.tile.st-good     { border-left-color: var(--good); }
.tile.st-warn     { border-left-color: var(--warning); }
.tile.st-critical { border-left-color: var(--critical); }
.tile.st-good     { background: color-mix(in srgb, var(--good) 7%, var(--surface-1)); }
.tile.st-warn     { background: color-mix(in srgb, var(--warning) 9%, var(--surface-1)); }
.tile.st-critical { background: color-mix(in srgb, var(--critical) 8%, var(--surface-1)); }

/* The icon carries the state alongside the colour, so it survives greyscale,
   colour-blindness and forced-colours mode. */
.tile .state-icon { font-size: 10px; margin-right: 4px; }
.tile.st-good     .state-icon { color: var(--success-text); }
.tile.st-warn     .state-icon { color: var(--text-primary); }
.tile.st-critical .state-icon { color: var(--critical); }

/* Replies range from "OK!" to a full firmware banner, so the column wraps and
   is capped rather than stretching the table until the others are unreadable. */
/* Widths are in ch so they track the font rather than assuming a viewport. */
#device-commands td.wrap, #device-commands td.cmd { max-width: 32ch; font-size: 11px; }
#device-frames td.wrap { max-width: 44ch; }

/* Command history is a 7-column table, and the two free-text columns are the
   widest real content on the site: a 69-char UPLOADFILE,EVENT_... command and a
   51-char firmware banner. Uncapped they push the table past 170ch. */
#command-rows td.wrap { max-width: 40ch; }
#command-rows td.cmd { max-width: 34ch; }

/* Any cell carrying a device string breaks rather than stretching its column. */
td.cmd { white-space: normal; overflow-wrap: anywhere; }

/* ------------------------------------------------------- table containment

   A table inside a card scrolls within its own box. Without this a single long
   value — a firmware banner, a clip filename — widens the table past the card
   and pushes the whole page sideways. */
.table-scroll { overflow-x: auto; max-width: 100%; }

/* Long single-token values must break rather than stretch their container. */
.tile .value, .tile .sub { overflow-wrap: anywhere; }
.alarm-head .label, .verdict .headline { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- log viewer

   Lines are single-line JSON and can be long. The pane scrolls in both
   directions rather than wrapping, so line boundaries stay meaningful. */
.log-view { max-height: 62vh; overflow: auto; margin-top: 10px; }
.log-view pre { margin: 0; white-space: pre; overflow: visible; }
.log-view pre .hit { background: var(--grid); border-radius: 3px; }
a.button-link {
  display: inline-flex; align-items: center; text-decoration: none;
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px;
  font-size: 13px; color: var(--text-primary); background: transparent;
}
a.button-link:hover { border-color: var(--axis); }
a.button-link[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* ---------------------------------------------------------------- combobox

   A select with typeahead, built here rather than pulled in: the console has no
   third-party JavaScript and a fleet has more devices than a plain <select> is
   comfortable to scroll. */
.combo { position: relative; min-width: 200px; }
.combo input { width: 100%; }
.combo-list {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none; max-height: 260px; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.combo-list li {
  padding: 6px 9px; border-radius: 5px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.combo-list li .note { font-family: var(--sans); color: var(--text-muted); font-size: 11px; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--page); }
.combo-list li.active { background: var(--page); outline: 1px solid var(--axis); }
.combo-list li.none { cursor: default; color: var(--text-muted); font-family: var(--sans); }

/* A match inside the log body. A translucent wash rather than bold or a solid
   colour: the body is monospace, so bolding would shift every column, and alpha
   composites correctly over both the light and dark surface without needing a
   second value per theme. Text keeps its own ink and its own contrast. */
.log-view mark {
  background: rgba(201, 133, 0, .32);
  color: inherit; border-radius: 2px; padding: 0 1px;
}
#log-search { max-width: 320px; }

/* ---------------------------------------------------------------- driver cards */

.swipe { padding: 9px 0; border-bottom: 1px solid var(--grid); }
.swipe:last-child { border-bottom: none; }
.swipe-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.swipe-head .when { font-variant-numeric: tabular-nums; }
.swipe-head .ago { color: var(--text-muted); font-size: 11px; }
/* The card text is the read itself: monospace so the masked runs line up, and
   breakable so a long track does not stretch the panel. */
.swipe .card {
  font-family: var(--mono); font-size: 12px; margin-top: 3px;
  overflow-wrap: anywhere; color: var(--text-primary);
}
.swipe .card.empty { color: var(--text-muted); font-family: var(--sans); }
.swipe .meta { color: var(--text-secondary); font-size: 11px; margin-top: 2px; }

/* The stream URL under the player. Operators paste this into VLC when they want
   the feed outside the console, so it is selectable text rather than a title. */
/* Two cameras sit side by side when both were asked for, and stack on a narrow
   screen. One camera fills the dialog as before. */
.video-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.video-grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 800px) { .video-grid.two { grid-template-columns: 1fr; } }
.video-wrap .cam-name {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 4px;
}

.cam-url {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 12px; min-width: 0;
}
.cam-url .label { color: var(--text-secondary); flex: none; }
.cam-url code {
  flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap;
  background: var(--page); border: 1px solid var(--border);
  border-radius: 5px; padding: 5px 8px; color: var(--text-primary);
}
.cam-url button { flex: none; }

/* ---------------------------------------------------------------- fleet row */

.row-heading { font-size: 14px; margin: 4px 0 -4px; color: var(--text-secondary); }

/* A tile that leads somewhere. The border, not the text, carries the hover:
   these are numbers, and underlining a number makes it harder to read. */
.tile.actionable { cursor: pointer; }
.tile.actionable:hover, .tile.actionable:focus-visible { border-color: var(--axis); }
.tile.actionable:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.tile .detail {
  font-size: 11px; color: var(--text-muted); margin-top: 4px;
  font-family: var(--mono); overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- settings */

.settings-form { display: flex; flex-direction: column; gap: 14px; max-width: 620px; }
.settings-form .field { display: flex; flex-direction: column; gap: 4px; border: none; padding: 0; margin: 0; }
.settings-form .field > .label, .settings-form legend.label {
  font-size: 12px; color: var(--text-secondary); padding: 0;
}
.settings-form .hint { font-size: 11px; color: var(--text-muted); }
.settings-form .hint code { font-family: var(--mono); }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.switch input { width: auto; }
.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.checks label { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.checks input { width: auto; }
.checks .what { color: var(--text-secondary); font-size: 12px; }
/* Card data is the one choice here with a consequence outside this system. */
.checks .sensitive .what { color: var(--warning); }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#fwd-meta { margin-top: 12px; }

/* ------------------------------------------------------- forwarding feed */

.fwd-feed {
  max-height: 320px; overflow-y: auto; font-family: var(--mono); font-size: 12px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); margin-top: 8px;
}
.fwd-line { display: flex; gap: 8px; align-items: baseline; padding: 4px 10px; border-bottom: 1px solid var(--grid); }
.fwd-line:last-child { border-bottom: none; }
.fwd-line .t { color: var(--text-muted); }
.fwd-line .path { color: var(--text-primary); }
.fwd-line .why { color: var(--text-secondary); overflow-wrap: anywhere; }
/* The outcome is the thing being scanned for, so it carries the colour. */
.fwd-line .outcome { font-weight: 600; flex: none; min-width: 58px; }
.fwd-line.sent .outcome, .fwd-line.resent .outcome { color: var(--good); }
.fwd-line.retry .outcome { color: var(--warning); }
.fwd-line.failed .outcome { color: var(--critical); }
.fwd-line.dropped .outcome { color: var(--serious); }
.fwd-line.dryrun .outcome { color: var(--text-muted); }

/* Shown only when the console cannot start. Anything is better than the blank
   page that both panels being hidden would otherwise leave. */
#fatal { text-align: center; }
#fatal h1 { font-size: 20px; margin-bottom: 8px; }
#fatal button { margin-top: 12px; }

/* ------------------------------------------------------------- tab dropdown

   The Commands tab holds two pages now. A menu rather than two more top-level
   tabs: the bar is already six items wide and they belong together. */
.tab-menu { position: relative; display: inline-flex; }
.tab-toggle {
  background: none; border: none; padding: 6px 2px; font: inherit;
  color: var(--text-secondary); cursor: pointer; display: inline-flex;
  align-items: center; gap: 4px; border-bottom: 2px solid transparent;
}
.tab-toggle:hover { color: var(--text-primary); }
.tab-menu.active .tab-toggle { color: var(--text-primary); border-bottom-color: var(--text-primary); }
.tab-toggle .caret { font-size: 10px; }
.tab-drop {
  position: absolute; z-index: 70; top: calc(100% + 6px); left: 0; min-width: 210px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column;
}
.tab-drop a {
  padding: 7px 10px; border-radius: 5px; text-decoration: none;
  color: var(--text-primary); font-size: 13px; border: none;
}
.tab-drop a:hover, .tab-drop a.active { background: var(--page); }

/* ---------------------------------------------------------- bulk command */

#bulk-devices { max-height: 60vh; overflow-y: auto; }
#bulk-devices td.pick { width: 34px; }
#bulk-devices input[type="checkbox"] { width: auto; }
#bulk-devices tr.chosen { background: var(--page); }
.bulk-bar { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; margin: 10px 0 6px; }
.bulk-bar > span { display: block; height: 100%; background: var(--series-1); transition: width .3s; }
#bulk-report td.reply { max-width: 34ch; }

/* The command pickers are comboboxes now, and sit in a form column rather than
   a toolbar, so they take the full width like the input beneath them. */
#command-preset-combo, #bulk-preset-combo { width: 100%; min-width: 0; }
.combo-list li .note { white-space: normal; }

/* ------------------------------------------------------------------ notes */

#note-text { width: 100%; resize: vertical; }
.note-item { padding: 9px 0; border-bottom: 1px solid var(--grid); }
.note-item:last-child { border-bottom: none; }
/* A pinned note is standing instruction, so it reads as one rather than as
   another line of history. */
.note-item.pinned { border-left: 3px solid var(--warning); padding-left: 9px; }
.note-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 11px; }
.note-head .who { font-weight: 600; color: var(--text-primary); font-size: 12px; }
.note-head .when { color: var(--text-muted); }
.note-head .spacer { margin-left: auto; }
.note-body { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.note-act {
  background: none; border: none; padding: 0 2px; font: inherit; font-size: 11px;
  color: var(--text-secondary); cursor: pointer; text-decoration: underline;
}
.note-act:hover { color: var(--text-primary); }
.note-act:disabled { opacity: .4; cursor: not-allowed; text-decoration: none; }

/* A date field with its label beside it, so the row reads "From [ ] To [ ]"
   rather than as two unlabelled boxes. */
.toolbar label.inline {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
}
.toolbar label.inline input[type="date"] { width: auto; }

/* ------------------------------------------------------------------ users */

.user-row { padding: 10px 0; border-bottom: 1px solid var(--grid); }
.user-row:last-child { border-bottom: none; }
.user-row.disabled { opacity: .55; }
.user-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.user-head .name { font-family: var(--mono); font-weight: 600; }
.user-head .display { color: var(--text-secondary); font-size: 12px; }
.user-head .spacer { margin-left: auto; }
.user-perms { margin-top: 4px; display: flex; gap: 5px; flex-wrap: wrap; }
.perm-chip {
  font-size: 11px; padding: 1px 7px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--text-secondary);
}
/* The two that reach outside this console read differently from the rest. */
.perm-chip.perm-users, .perm-chip.perm-cards { border-color: var(--warning); color: var(--warning); }
.user-row .meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.env-account {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 9px 11px; margin-bottom: 10px; font-size: 12px; color: var(--text-secondary);
}
.env-account .name { font-family: var(--mono); color: var(--text-primary); }
