/* uat-viz page. Colors are tokens: light first, dark under the OS setting
   (unless the viewer picked light) and under an explicit data-theme="dark". */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hair: #e1e0d9;
  --edge: rgba(11, 11, 11, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);

  /* product groups: categorical slots 1-4 (identity) */
  --g-text: #2a78d6;
  --g-block: #eb6834;
  --g-twgo: #1baf7a;
  --g-traffic: #eda100;

  /* status (reserved): always with an icon and a label */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-ink: #006300;
  --warning-ink: #8a5a00;

  /* map */
  --map: #f3f2ee;
  --map-line: rgba(82, 81, 78, 0.7);
  --map-state: rgba(82, 81, 78, 0.36);
  --wx-none: #dde5ee;          /* received, below 20 dBZ ("None") */
  --wx-green: #2f9e44;
  --wx-amber: #f2b705;
  --wx-red: #e03131;
  --ltg: #6250d6;
  --station: #0b0b0b;
  --target: #eda100;
  --target-edge: #0b0b0b;
  --heard: #898781;
  --flash: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hair: #2c2c2a;
    --edge: rgba(255, 255, 255, 0.10);
    --shadow: none;
    --g-text: #3987e5;
    --g-block: #d95926;
    --g-twgo: #199e70;
    --g-traffic: #c98500;
    --good-ink: #0ca30c;
    --warning-ink: #fab219;
    --map: #121211;
    --map-line: rgba(195, 194, 183, 0.42);
    --map-state: rgba(195, 194, 183, 0.18);
    --wx-none: #25303b;
    --ltg: #9085e9;
    --station: #f0efec;
    --target: #fab219;
    --target-edge: #0d0d0d;
    --flash: #ec835a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hair: #2c2c2a;
  --edge: rgba(255, 255, 255, 0.10);
  --shadow: none;
  --g-text: #3987e5;
  --g-block: #d95926;
  --g-twgo: #199e70;
  --g-traffic: #c98500;
  --good-ink: #0ca30c;
  --warning-ink: #fab219;
  --map: #121211;
  --map-line: rgba(195, 194, 183, 0.42);
  --map-state: rgba(195, 194, 183, 0.18);
  --wx-none: #25303b;
  --ltg: #9085e9;
  --station: #f0efec;
  --target: #fab219;
  --target-edge: #0d0d0d;
  --flash: #ec835a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}
button { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---- header ---- */
.bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--hair);
}
.bar h1 { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; }
.bar .source { color: var(--ink-2); flex: 1 1 260px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .clock { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar .clock b { font-weight: 600; }
.bar .clock span { color: var(--ink-2); margin-left: 6px; }
.live { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--edge); color: var(--ink-2); white-space: nowrap; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.ok .dot { background: var(--good); }
.live.warn .dot { background: var(--warning); }
.live.bad .dot { background: var(--critical); }
.icon-btn { background: none; border: 1px solid var(--edge); border-radius: 8px; padding: 3px 9px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* ---- layout ---- */
main { display: grid; grid-template-columns: minmax(420px, 46%) minmax(0, 1fr); min-height: 0; min-width: 0; }
.tiles { overflow-y: auto; padding: 12px 16px 24px; border-right: 1px solid var(--hair); min-width: 0; }
.mapwrap { position: relative; min-height: 420px; background: var(--map); overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
@media (min-width: 901px) {
  body { height: 100vh; }  /* tiles and map each fill the window; the tiles scroll */
}
@media (max-width: 900px) {
  body { display: block; }
  main { display: block; }
  .tiles { border-right: none; border-bottom: 1px solid var(--hair); overflow: visible; }
  .mapwrap { height: 70vh; }
  .map-tools .layers { display: none; }  /* room for the map; zoom stays */
}

/* ---- tiles ---- */
.group { margin-bottom: 14px; }
.group h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink-2); margin: 6px 0 8px; display: flex; align-items: center; gap: 8px; }
.group h2 .chip { width: 10px; height: 10px; border-radius: 3px; background: var(--gc); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(190px, 100%), 1fr)); gap: 8px; }
.tile {
  --gc: var(--g-text);
  position: relative; text-align: left; border-radius: 12px; padding: 10px 12px 9px; min-width: 0;
  background: var(--surface); border: 1px solid var(--edge); box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; gap: 3px;
  min-height: 124px; cursor: pointer;
  transition: opacity 600ms ease, border-color 600ms ease, background-color 600ms ease;
}
.tile:focus-visible { outline: 2px solid var(--gc); outline-offset: 2px; }
.tile.text { --gc: var(--g-text); }
.tile.block { --gc: var(--g-block); }
.tile.twgo { --gc: var(--g-twgo); }
.tile.traffic { --gc: var(--g-traffic); }
.tile::before { /* the group accent: lit tiles carry it */
  content: ""; position: absolute; left: 12px; right: 12px; top: 0; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--gc); opacity: 0; transition: opacity 600ms ease;
}
.tile.on::before, .tile.late::before { opacity: 1; }
.tile.off { opacity: 0.5; background: transparent; box-shadow: none; }
.tile.selected { border-color: var(--gc); }
.tile .glow { position: absolute; inset: -1px; border-radius: 12px; pointer-events: none; opacity: 0;
  box-shadow: 0 0 0 2px var(--gc), 0 0 18px 2px color-mix(in srgb, var(--gc) 45%, transparent); }
.tile .head { display: flex; align-items: center; gap: 6px; }
.tile .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .state { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); white-space: nowrap; }
.tile .state i { font-style: normal; font-size: 11px; }
.tile.on .state i { color: var(--good); }
.tile.late .state i { color: var(--warning); }
.tile.late .state { color: var(--warning-ink); }
.tile .value { display: flex; align-items: baseline; gap: 6px; }
.tile .value b { font-size: 24px; font-weight: 600; line-height: 1.1; }
.tile .value span { color: var(--ink-2); font-size: 12px; }
.tile .latest { font-size: 11.5px; line-height: 1.35; color: var(--ink-2); overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; min-height: 2.7em; }
.tile .foot { font-size: 11.5px; color: var(--muted); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 8px;
  font-variant-numeric: tabular-nums; }
.tile .foot .crl { white-space: nowrap; }
.crl.complete { color: var(--good-ink); }
.crl.incomplete { color: var(--critical); }
.crl.indeterminate { color: var(--warning-ink); }

/* ---- map chrome ---- */
.map-tools { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.panel { background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--edge);
  border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; }
.layers label { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 1px 0; white-space: nowrap; }
.zoom { display: flex; gap: 4px; }
.zoom button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--edge);
  background: var(--surface); cursor: pointer; font-size: 16px; line-height: 1; }
.zoom button:hover { background: var(--surface-2); }
.legend { position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px); }
.legend .row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.legend .row + .row { margin-top: 5px; }
.legend .lbl { color: var(--ink-2); font-weight: 600; margin-right: 2px; }
.legend .sw { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); }
.legend .sw i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid var(--edge); }
.legend .age { color: var(--muted); }
.tip { position: absolute; pointer-events: none; z-index: 5; max-width: 300px; }
.tip b { font-weight: 600; }
.tip .sub { color: var(--ink-2); }

/* ---- detail (the table view of a tile) ---- */
.detail { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 6;
  background: var(--surface); border-left: 1px solid var(--hair); display: grid; grid-template-rows: auto 1fr; }
.detail > header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--hair); }
.detail > header h2 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.detail > header h2 .chip { width: 10px; height: 10px; border-radius: 3px; }
.detail > header .sub { color: var(--ink-2); flex: 1; font-size: 12px; }
.detail-body { overflow: auto; padding: 0 14px 16px; }
.detail table { width: 100%; border-collapse: collapse; font-size: 12px; }
.detail th { text-align: left; font-weight: 600; color: var(--ink-2); position: sticky; top: 0; background: var(--surface);
  padding: 8px 6px 6px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
.detail td { padding: 6px; border-bottom: 1px solid var(--hair); vertical-align: top; font-variant-numeric: tabular-nums; }
.detail td.txt { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11.5px; }
.detail td.late { color: var(--warning-ink); }
.detail tr.fresh td { animation: fresh 1600ms ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--gc, var(--g-text)) 22%, transparent); } to { background: transparent; } }
.detail .kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 12px 0; font-size: 12.5px; }
.detail .kv dt { color: var(--ink-2); }
.detail .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.detail .note { color: var(--muted); font-size: 12px; margin: 10px 0; }

/* ---- footer ---- */
.status { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 7px 16px; font-size: 12px; color: var(--ink-2);
  background: var(--surface); border-top: 1px solid var(--hair); font-variant-numeric: tabular-nums; }
.status b { color: var(--ink); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .tile, .tile::before { transition: none; }
}
