:root {
  color-scheme: light;
  --page: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e8e7e1;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --accent: #1c5cab;
  /* event classes - one hue per class across the whole app */
  --c-noise: #d6d5cf;
  --c-impact: #2a78d6;
  --c-vehicle: #eb6834;
  --c-idle: #1baf7a;
  --c-personnel: #e87ba4;    /* footsteps, ball retrieval, handling */
  --c-unlabeled: #f1f0ec;
  --c-activity: #6f6e69;     /* reference detector: activity it cannot classify */
  --good: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  /* signal energy: neutral sequential ramp, so it never reads as an event class */
  --seq-energy: #ffffff,#ecebe6,#c9c8c0,#94938c,#5c5b57,#262624;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
h3, h4 { margin: 0; font-weight: 600; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 32px; height: 64px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #1c5cab 0 50%, #2a78d6 50% 100%); }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 16px; letter-spacing: .01em; }
.brand span { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.tabs button:hover { background: var(--surface-2); }
.tabs button.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.tab { display: none; }
.tab.active { display: block; }
.page { max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* ---------- buttons & small controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.toggle.on { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--ink); }
.btn.toggle.on:disabled { background: transparent; box-shadow: none; }
.agent-link { margin-left: auto; gap: 8px; padding: 9px 18px; font-size: 15px; font-weight: 600; color: var(--ink); text-decoration: none; }
.agent-link svg { width: 17px; height: 17px; fill: var(--accent); }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--ink-2); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; font-size: 12px; color: var(--ink-2); }
.seg button.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 3px 11px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot.impact { background: var(--c-impact); }
.dot.vehicle { background: var(--c-vehicle); }
.dot.idle { background: var(--c-idle); }
.dot.personnel { background: var(--c-personnel); }
.dot.noise { background: var(--c-noise); }
.dot.unlabeled { background: var(--c-unlabeled); box-shadow: inset 0 0 0 1px var(--axis); }
.dot.unknown { background: transparent; border: 1.5px solid var(--muted); }
.dot.activity { background: var(--c-activity); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 12px; }
.badge.ok, .tick.ok { color: var(--good); }
.badge.bad, .tick.bad { color: var(--critical); }
.tick { font-weight: 700; font-size: 14px; }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; margin-left: 4px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); font-weight: 600; color: var(--ink); font-size: 13px; }
/* alerts: solid status pill in a card header, icon + label */
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.status-pill.warn { background: var(--warning); color: #0b0b0b; }

/* ---------- reading bar ---------- */
.reading-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 20px; }
.reading-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 520px; }
.reading-info .title { font-size: 18px; font-weight: 600; }
.reading-info .line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.reading-info .lbl { color: var(--muted); font-size: 12px; margin-right: -4px; }
.reading-info .meta { color: var(--ink-2); margin-left: 6px; }
.reading-actions { display: flex; gap: 8px; flex-wrap: wrap; flex: none; }
.fold-tag { font: inherit; font-size: 12px; font-weight: 500; color: var(--ink-2); background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; cursor: pointer; white-space: nowrap; }
.fold-tag:hover { background: var(--surface-2); }
.fold-tag.static { cursor: default; }
.fold-tag.static:hover { background: transparent; }

/* ---------- result ---------- */
.result-card .card-head { margin-bottom: 4px; align-items: center; min-height: 26px; }
.result-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 32px; align-items: center; transition: opacity .2s; }
.result-grid.stale { opacity: .55; }
.consensus { display: flex; flex-direction: column; gap: 4px; }
.consensus .big { font-size: 24px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.consensus .big .dot { width: 14px; height: 14px; }
.consensus .est { font-size: 15px; color: var(--ink); }
.consensus .agree { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.votes { width: 100%; border-collapse: collapse; font-size: 13px; }
.votes td { padding: 6px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.votes tr:last-child td { border-bottom: 0; }
.votes .algo { color: var(--ink-2); width: 46%; }
.votes .v { font-weight: 600; }
.votes .v .dot { margin-right: 8px; vertical-align: -1px; }
.votes .res { width: 32px; text-align: right; }
.loading-row td { color: var(--muted); }

/* ---------- timeline ---------- */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend .sw.noise { background: var(--c-noise); }
.legend .sw.impact { background: var(--c-impact); }
.legend .sw.vehicle { background: var(--c-vehicle); }
.legend .sw.idle { background: var(--c-idle); }
.legend .sw.personnel { background: var(--c-personnel); }
.legend .sw.activity { background: var(--c-activity); }
.legend .sw.unlabeled { background: var(--c-unlabeled); outline: 1px solid var(--axis); }
.mark-chip { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 3px 10px; }

/* ---------- event location ---------- */
.loc-grid { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); gap: 28px; align-items: center; }
.loc-side { display: flex; flex-direction: column; gap: 12px; }
.loc-result { font-size: 15px; color: var(--ink); }
.loc-result b { font-weight: 700; }
.loc-legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }
.loc-legend > span { display: inline-flex; align-items: center; gap: 8px; }
.loc-legend svg { width: 16px; height: 16px; color: var(--ink); }
.lg-bar { display: inline-block; width: 22px; height: 7px; border-radius: 2px; flex: none; }
.lg-bar.truth { background: #fff; box-shadow: 0 0 0 2px var(--ink); height: 6px; margin: 0 2px; width: 18px; }
.lg-bar.est.impact { background: var(--c-impact); }
.lg-bar.est.vehicle { background: var(--c-vehicle); }
.lg-path { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--ink-2); }
.lg-int { display: inline-block; width: 22px; height: 8px; border: 2px solid var(--ink); border-top: 0; border-bottom: 0; position: relative; }
.lg-int::after { content: ""; position: absolute; left: 0; right: 0; top: 3px; border-top: 2px solid var(--ink); }
.site-map svg { width: 100%; height: auto; display: block; }
.site-map .lbl { font: 28px var(--font); fill: var(--ink-2); }
.site-map .lbl.on { font-weight: 700; fill: var(--ink); }
.site-map .muted-lbl { fill: var(--muted); font-size: 24px; }
.site-map.photo svg { border-radius: 8px; }
.site-map .pl { font: 600 32px var(--font); fill: var(--ink); }
.site-map .pl.on { font-weight: 700; }

/* ---------- advanced ---------- */
details.advanced > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; font-weight: 600; }
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary::before { content: "▸"; color: var(--muted); display: inline-block; width: 12px; transition: transform .15s; }
details.advanced[open] > summary::before { transform: rotate(90deg); }
details.advanced[open] > summary { margin-bottom: 4px; }
.adv-sec { padding: 16px 0 4px; border-top: 1px solid var(--grid); margin-top: 12px; }
.adv-sec h4 + .sub { margin-bottom: 8px; }
.sec-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.adv-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 24px; }
details.inner summary { cursor: pointer; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.controls { display: flex; flex-direction: column; gap: 12px; }
.ctrl { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.ctrl label { font-size: 13px; }
.ctrl output { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ctrl input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.ctrl .help { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.status-line { font-size: 12px; color: var(--muted); min-height: 16px; }
.wave-controls { display: flex; gap: 8px; align-items: center; }
.wave-controls select { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; }

/* incidents */
.inc-table td { vertical-align: middle; padding: 7px 10px; }
.inc-table tr[data-t] { cursor: pointer; }
.inc-table td.t { white-space: nowrap; font-variant-numeric: tabular-nums; }
.inc-table tr[data-t]:hover td { background: var(--surface-2); }
.status-word { font-size: 13px; color: var(--ink-2); }
.status-word.unk { font-weight: 700; color: var(--ink); }
.status-word .wicon { color: #b07a00; font-size: 11px; }
.chip-set { display: inline-flex; align-items: center; gap: 6px; padding: 1px 10px; border-radius: 999px; background: var(--surface-2); font-weight: 600; font-size: 13px; white-space: nowrap; }
.nn-label { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--ink); margin-right: 8px; white-space: nowrap; font-size: 12px; }
.nn-link { cursor: pointer; text-decoration: underline; text-decoration-color: var(--axis); font-size: 12px; color: var(--ink-2); }

/* location methods, cross-cable */
.loc-table td, .loc-table th { padding: 7px 8px; vertical-align: middle; }
.loc-table td b { font-weight: 600; }
.loc-table tr:not(.main) td { color: var(--ink-2); }
.loc-table tr:not(.main) td b { font-weight: 500; }
.loc-table .sens { font-weight: 600; white-space: nowrap; }
.loc-table .res, .xref-table .res { text-align: right; white-space: nowrap; }
#locm-foot { margin-top: 6px; }
.xref-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.xref-table td, .xref-table th { padding: 6px 8px; vertical-align: middle; }
.xref-table td:nth-child(2), .xref-table td:nth-child(3) { font-weight: 600; }
.xref-table td .dot { margin-right: 6px; vertical-align: -1px; }
#xref-sim { margin-top: 4px; }

/* ---------- tables ---------- */
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); font-size: 12px; background: var(--surface); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow: auto; max-height: 420px; }
#event-table td:nth-child(2) { white-space: nowrap; }

/* ---------- performance ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.tile .t-label { font-size: 13px; color: var(--ink-2); }
.tile .t-value { font-size: 30px; font-weight: 600; line-height: 1.15; margin-top: 4px; }
.tile .t-ci { font-size: 12px; color: var(--ink-2); }
.tile .t-cap { font-size: 12px; color: var(--muted); margin-top: auto; padding-top: 8px; }
.perf-table th[title] { cursor: help; }
.perf-table td { vertical-align: middle; }
.perf-table .ci { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 4px; }
.perf-table tr.ref td { color: var(--muted); }
.perf-table tr.ref td .ci { color: var(--axis); }
.perf-table td .dot { vertical-align: -1px; }
.wrong-table td { vertical-align: top; }
.wrong-table td:first-child { width: 220px; white-space: nowrap; }
.rlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.rlink { color: var(--ink); text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 2px; }
.rlink:hover { text-decoration-color: var(--ink); }

/* ---------- picker dialog ---------- */
dialog#picker {
  width: min(720px, calc(100vw - 32px)); max-height: min(760px, calc(100vh - 64px)); padding: 0; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .18); display: none; flex-direction: column; background: var(--surface);
}
dialog#picker[open] { display: flex; }
dialog#picker::backdrop { background: rgba(20, 20, 18, .35); }
.picker-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 8px; }
.picker-filters { display: flex; flex-direction: column; gap: 8px; padding: 0 18px 12px; border-bottom: 1px solid var(--grid); }
.chip-row { display: flex; gap: 8px 20px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
#wrong-chip.on { background: var(--critical); border-color: var(--critical); color: #fff; }
.search { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); }
.slice-list { overflow-y: auto; padding: 6px 12px 14px; }
.group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 6px 4px; }
.slice-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 7px 8px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; }
.slice-item:hover { background: var(--surface-2); }
.slice-item.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.slice-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slice-item .dur { font-size: 12px; color: var(--muted); width: 36px; text-align: right; }
.wrong-mark { color: var(--critical); font-weight: 700; font-size: 13px; }
.fold-note { margin: 10px 6px 2px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--ink-2); }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--axis); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .adv-grid, .loc-grid, .xref-grid, .result-grid { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
  .page { padding: 12px 16px 32px; }
}
.consensus .big .or { font-size: 15px; font-weight: 500; color: var(--muted); margin: 0 4px; }
