:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a; --text: #e6e8ec; --muted: #8b93a3;
  --accent: #4f8cff; --ok: #3fb67a; --warn: #e0a43a; --bad: #e5534b;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #9085e9; --c6: #d55181; --c7: #2fc4b2; --c8: #8b93a3;
  /* chart series: validated categorical palette (dataviz reference, fixed order), dark steps */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #8b93a3;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace; color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --panel: #fff; --panel2: #f0f2f5; --line: #dde1e7; --text: #1b1f27; --muted: #5f6878;
    --accent: #2563eb; color-scheme: light;
    --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s-other: #8b8a85;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, system-ui, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; }
input:not([type=checkbox]):not([type=radio]), select:not([multiple]) { min-height: 36px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
button { cursor: pointer; min-height: 36px; font-weight: 500; transition: border-color .12s, background .12s; }
button:not(.primary):not(.danger):hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; } button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); } button:disabled { opacity: .5; cursor: default; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 15px; height: 15px; vertical-align: -2px; margin: 0 6px 0 0; }
textarea { width: 100%; }

/* ---- header ---- */
header.top { display: flex; align-items: center; gap: 14px 20px; padding: 10px 24px; min-height: 60px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
header.top .brand { font-weight: 800; font-size: 17px; letter-spacing: .3px; margin-right: 4px; }
header.top #site { max-width: 240px; }
header.top nav { display: flex; gap: 2px; flex-wrap: wrap; }
header.top nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
header.top nav a:hover { color: var(--text); background: var(--panel2); text-decoration: none; }
header.top nav a.active { background: color-mix(in srgb, var(--accent) 16%, var(--panel2)); color: var(--text); text-decoration: none; }
header.top #who { font-size: 13px; }

/* ---- page layout ---- */
.spacer { flex: 1; }
main { padding: 28px 32px 56px; max-width: 1600px; margin: 0 auto; }
@media (max-width: 700px) { main { padding: 18px 16px 40px; } header.top { padding: 10px 16px; } }
h2 { font-size: 20px; font-weight: 700; margin: 0 0 18px; letter-spacing: -.2px; }
h3 { font-size: 12px; font-weight: 600; margin: 34px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; }
main > h3:first-child, .panel > h3:first-child { margin-top: 0; }
.row > h2, .row > h3 { margin: 0; }
main > .row:first-child { margin-bottom: 20px; min-height: 36px; }    /* page title + actions */
main > .row + .row { margin-top: 10px; }
main > p, main > .row > p { margin: 10px 0; }
.muted { color: var(--muted); } .mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; }
.panel + .panel, .kpis + .panel, .panel + .kpis, .panel + .grid, .grid + .panel { margin-top: 16px; }
.panel h3 { margin: 18px 0 10px; } .panel > h3:first-child { margin-top: 0; }
.panel ul { margin: 6px 0; padding-left: 20px; } .panel li { margin: 3px 0; }

/* ---- cards ---- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  transition: border-color .12s, transform .12s; display: flex; flex-direction: column; }
a.card:hover, .card:hover { border-color: color-mix(in srgb, var(--muted) 60%, var(--line)); }
.card .media { aspect-ratio: 16/9; background: #000; display: block; width: 100%; object-fit: cover; border: 0; }
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; line-height: 1.5; }
.card .body > * { margin: 0; }
.card .title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); } .dot.error { background: var(--bad); }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line);
  font-size: 12px; margin: 3px 6px 3px 0; }
.chip.yolo { border-color: var(--c4); } .chip.gemini { border-color: var(--c2); } .chip.rule { border-color: var(--c6); }

/* ---- tables: boxed, roomy rows ---- */
table { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child > td { border-bottom: 0; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  background: color-mix(in srgb, var(--panel2) 60%, var(--panel)); white-space: nowrap; }
tbody tr:hover > td, table tr:not(:first-child):hover > td { background: color-mix(in srgb, var(--panel2) 45%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td button + button { margin-left: 6px; }
td > button { min-height: 30px; padding: 4px 10px; font-size: 13px; }
td:has(> button) { white-space: nowrap; }
.panel table { border: 0; border-radius: 0; background: transparent; }
.panel table th { background: transparent; }

.two { display: grid; grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr); gap: 24px; }
@media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.player { position: relative; background: #000; border-radius: 12px; overflow: hidden; }
.player video { width: 100%; display: block; } .player canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tl { position: relative; padding: 14px 18px; }
.tl-row { display: grid; grid-template-columns: 150px 1fr; align-items: center; height: 40px; border-bottom: 1px solid var(--line); }
.tl-row:last-child { border-bottom: 0; }
.tl-track { position: relative; height: 26px; background: var(--panel2); border-radius: 6px; }
.tl-ev { position: absolute; top: 3px; height: 20px; min-width: 3px; border-radius: 4px; background: var(--c1); cursor: pointer; opacity: .9; }
.tl-ev:hover { outline: 2px solid var(--text); }
.tl-den { position: absolute; bottom: 0; width: 2px; background: var(--c7); opacity: .6; }
.tl-note { position: absolute; top: -2px; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 7px solid var(--c6); transform: translateX(-5px); }
.tl-axis { display: grid; grid-template-columns: 150px 1fr; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.tl-axis .ticks { position: relative; height: 18px; } .tl-axis .ticks span { position: absolute; transform: translateX(-50%); }
.bar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--panel2); }
.bar > span { display: block; height: 100%; }
.legend { margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 12px 6px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.kpi b { display: block; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.kpi span { color: var(--muted); font-size: 12px; }
/* ---- dialogs (every popup: <form><h2/> fields… <div class="row">buttons</div></form>) ---- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0;
  width: min(620px, 94vw); max-width: none; box-shadow: 0 24px 64px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.25); overflow: hidden; }
dialog.wide { width: min(780px, 96vw); }
dialog[open] { animation: dlg-in .16s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(8, 10, 14, .55); backdrop-filter: blur(3px); }
dialog > form { max-height: min(88vh, 900px); overflow-y: auto; padding: 0 24px; display: block; }
/* header: the form's h2, sticky while the body scrolls */
dialog > form > h2 { position: sticky; top: 0; z-index: 2; margin: 0 -24px 6px; padding: 18px 56px 16px 24px; font-size: 17px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
dialog .dlg-x { position: absolute; top: 12px; right: 14px; z-index: 3; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
dialog .dlg-x:hover { background: var(--panel2); color: var(--text); }
/* footer: the last row of buttons, sticky at the bottom */
dialog > form > .row:last-child { position: sticky; bottom: 0; z-index: 2; margin: 18px -24px 0; padding: 14px 24px;
  background: var(--panel); border-top: 1px solid var(--line); gap: 10px; }
/* section headings */
dialog h3 { margin: 22px 0 2px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 11px; letter-spacing: .7px; }
dialog > form > h2 + h3, dialog > form > h2 + * h3:first-child { border-top: 0; padding-top: 0; }
/* fields */
dialog label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
dialog input, dialog select, dialog textarea { width: 100%; border-radius: 8px; padding: 8px 11px; background: var(--bg);
  border: 1px solid var(--line); transition: border-color .12s, box-shadow .12s; }
dialog input:not([type=checkbox]):not([type=radio]), dialog select:not([multiple]) { height: 38px; }
dialog input:focus, dialog select:focus, dialog textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
dialog textarea { font-family: var(--mono); font-size: 12px; line-height: 1.5; resize: vertical; }
dialog input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
dialog select[multiple] { padding: 4px; min-height: 120px; }
dialog select[multiple] option { padding: 6px 8px; border-radius: 6px; margin: 1px 0; }
dialog select[multiple] option:checked { background: color-mix(in srgb, var(--accent) 30%, var(--bg)); color: var(--text); }
dialog .row { gap: 12px; align-items: flex-start; }
dialog .row > div { flex: 1 1 0; min-width: 0; }
dialog p { line-height: 1.5; }
dialog p.muted { font-size: 12px; margin: 6px 0; }
dialog .err:empty { display: none; }
dialog .err { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  border-radius: 8px; padding: 8px 12px; margin: 14px 0 0; }
dialog button { height: 38px; padding: 0 16px; border-radius: 8px; font-weight: 500; }
dialog button.primary { min-width: 96px; }
dialog button:not(.primary):not(.danger):not(.dlg-x):hover { border-color: var(--muted); }
/* checkboxes as option chips (also overrides the inline layout styles some dialogs set) */
dialog label:has(> input[type=checkbox]), dialog label:has(> input[type=radio]) {
  display: inline-flex !important; align-items: center; gap: 8px !important; margin: 4px 8px 4px 0 !important; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text) !important; font-size: 13px;
  font-weight: 400; cursor: pointer; user-select: none; transition: border-color .12s, background .12s; }
dialog label:has(> input:checked) { border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg)); }
dialog label:has(> input[type=checkbox]):hover { border-color: var(--muted); }
dialog input[type=checkbox], dialog input[type=radio] { width: 16px !important; height: 16px; margin: 0; padding: 0;
  accent-color: var(--accent); flex: none; box-shadow: none; }
dialog label:has(> input[type=checkbox]) .muted { font-size: 12px; }
.err { color: var(--bad); }

/* stacked-bar charts (costs) */
.chart { position: relative; }
.chart svg { display: block; width: 100%; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--text); fill-opacity: .06; }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.25); min-width: 180px; z-index: 5; }
.tip .t-head { font-weight: 600; margin-bottom: 4px; }
.tip .t-row { display: flex; gap: 8px; align-items: center; } .tip .t-row span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip i, .legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }

/* inline playback on search results */
.playable { position: relative; cursor: pointer; }
.playable .play-btn { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 48px; height: 48px;
  padding: 0 14px; border-radius: 24px; background: rgba(0,0,0,.6); color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 18px; white-space: nowrap; }
.playable:hover .play-btn { background: var(--accent); }

/* live page: still image + play button until the stream starts */
.live-media .placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--panel2) 0 12px, var(--panel) 12px 24px); font-size: 12px; }
.live-media .placeholder span { margin-top: 70px; }
.live-media .snap-age { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 11px; padding: 2px 6px; border-radius: 4px; }

/* edge box machine usage */
.meters { max-width: 720px; margin-top: 16px; }
.meter { display: grid; grid-template-columns: 96px minmax(80px, 1fr) 46px minmax(0, 250px); gap: 12px; align-items: center; margin: 8px 0; font-variant-numeric: tabular-nums; }
.meter > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter b { text-align: right; } .meter .muted { font-size: 12px; }
.meter-bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.meter-bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); }
.meter-bar i.warn { background: var(--warn); } .meter-bar i.bad { background: var(--bad); }

/* segmented links (costs range / granularity) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg a { padding: 7px 13px; color: var(--muted); font-weight: 500; font-size: 13px; }
.seg a + a { border-left: 1px solid var(--line); }
.seg a:hover { color: var(--text); text-decoration: none; background: var(--panel2); }
.seg a.on { color: var(--text); background: color-mix(in srgb, var(--accent) 18%, var(--panel2)); }
.est { color: var(--warn); font-weight: 700; margin-right: 2px; cursor: help; }

/* search: camera chips, on-demand analysis panel */
.chipbox { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); font-size: 13px; cursor: pointer; user-select: none; }
.chipbox:has(input:checked) { border-color: color-mix(in srgb, var(--accent) 70%, transparent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.chipbox input { margin: 0; }
.panel.deep { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
