/* Operations console: neutral surfaces, one institutional blue, status colour only where state lives. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e1e4e9;
  --line-strong: #cbd1d9;
  --text: #151a21;
  --muted: #5a6472;
  --faint: #8a939f;
  --accent: #1d4f91;
  --accent-soft: #e8eef7;
  --focus: #2c6bd1;

  --ok: #1e7f52;
  --info: #2a64ad;
  --neutral: #5b6a80;
  --warn: #b86e00;
  --danger: #bf2f2a;
  --earth: #876628;
  --off: #7b8593;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1115; --surface: #15191f; --surface-2: #1a1f26; --line: #262c35; --line-strong: #343c47;
    --text: #e6e9ed; --muted: #9aa3ae; --faint: #6d7682; --accent: #6b9de0; --accent-soft: #1b2738; --focus: #6b9de0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1115; --surface: #15191f; --surface-2: #1a1f26; --line: #262c35; --line-strong: #343c47;
  --text: #e6e9ed; --muted: #9aa3ae; --faint: #6d7682; --accent: #6b9de0; --accent-soft: #1b2738; --focus: #6b9de0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 14px; font-weight: 600; letter-spacing: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden, [hidden] { display: none !important; }
.spacer { flex: 1; }

/* Header */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 16px; min-height: 56px; padding-block: 8px;
  padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand .logo { width: 22px; height: 22px; border-radius: 4px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 12px; }
.brand small { font-weight: 500; font-size: 14px; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--line-strong); }
.site { font-size: 13px; color: var(--muted); white-space: nowrap; }
.site b { color: var(--text); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip.live { color: var(--text); font-weight: 600; }
.chip.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: pulse 2s infinite; }
@media (prefers-reduced-motion: reduce) { .chip.live::before { animation: none; } }
@keyframes pulse { 50% { opacity: .35; } }
.chip.ok::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.clock { font: 500 14px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.divider { width: 1px; height: 20px; background: var(--line); }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; padding-block: 20px;
  padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
}
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head .meta { font-size: 12px; color: var(--muted); }
.panel-body { padding: 16px; }

/* Key figures: one strip, separated by rules */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat { padding: 14px 16px; border-left: 1px solid var(--line); min-width: 0; }
.stat:first-child { border-left: 0; }
.stat .k { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.stat .k i { width: 8px; height: 8px; border-radius: 2px; background: var(--c, var(--line-strong)); flex: none; }
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.15; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.stat .v.alert { color: var(--danger); }
.stat .s { font-size: 12px; color: var(--faint); margin-top: 2px; }
.panel .stat-row { border: 0; border-radius: 0; }
.panel .stat { padding: 4px 16px 8px 0; border-left: 0; }

/* Controls */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.tab { border: 0; background: transparent; padding: 5px 10px; border-radius: 4px; font-size: 13px; color: var(--muted); display: inline-flex; gap: 7px; align-items: center; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--line-strong); }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.tab .dot.off { background: var(--off); }
.btn { font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 4px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); background: none; border: 0; padding: 0; white-space: nowrap; }
.switch i { width: 30px; height: 18px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch.on { color: var(--text); }
.switch.on i { background: var(--accent); }
.switch.on i::after { left: 14px; }

/* Status */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--c); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--c); flex: none; }
.tag { display: inline-flex; align-items: center; font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 6px; line-height: 18px; white-space: nowrap; }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.demo-note { margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; }
.demo-note b { color: var(--text); font-weight: 600; }

/* Video */
.cam { position: relative; aspect-ratio: 16 / 9; max-width: 100%; background: #0b0d10; border-radius: 4px; overflow: hidden; }
.cam video, .cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam video { object-fit: cover; }
.cam .cam-label { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; z-index: 2; }
.cam .cam-label span, .cam .cam-stamp { background: rgba(11, 13, 16, .72); color: #e9ecf0; padding: 3px 8px; border-radius: 3px; font-size: 12px; }
.cam .cam-stamp { position: absolute; right: 10px; top: 10px; z-index: 2; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.cam .cam-stamp:empty { display: none; }
.cam .cam-wait { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa3ae; font-size: 13px; background: #0b0d10; z-index: 3; }
.cam.offline { display: grid; place-items: center; color: #9aa3ae; background: #14181d; }
.cam.offline .msg { text-align: center; font-size: 13px; padding: 16px; }
.cam.offline .msg b { display: block; color: #e6e9ed; margin-bottom: 4px; font-weight: 600; }

/* Lists */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.feed-item:first-child { border-top: 0; padding-top: 0; }
.feed-empty { color: var(--faint); font-size: 13px; }
.enter { animation: enter .3s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .enter { animation: none; } }

.toast-wrap { position: fixed; right: max(20px, env(safe-area-inset-right, 0px)); bottom: max(20px, env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { width: 320px; max-width: calc(100vw - 40px); background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent); border-radius: 4px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14); font-size: 13px; animation: enter .25s ease; }
.toast b { display: block; font-weight: 600; }

/* Data blocks */
.formula { font: 12px/1.7 var(--mono); color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; margin-top: 14px; }
.formula b { color: var(--text); font-weight: 600; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; border-bottom: 1px solid var(--line-strong); }
.bar-chart .b { flex: 1; background: var(--accent-soft); border-top: 2px solid var(--accent); min-height: 2px; }
.bar-chart .b.now { background: var(--accent); }
.bar-axis { display: flex; gap: 6px; font-size: 11px; color: var(--faint); margin-top: 4px; font-variant-numeric: tabular-nums; }
.bar-axis span { flex: 1; text-align: center; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .layout { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .divider, .site { display: none; }
  .toast:not(:first-child) { display: none; }
  .stat { border-left: 0; border-top: 1px solid var(--line); }
  .stat:first-child { border-top: 0; }
}

/* Views */
.viewnav { display: flex; gap: 2px; }
.navlink { padding: 6px 12px; border-radius: 4px; font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; }
.navlink:hover { color: var(--text); background: var(--surface-2); }
.navlink.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.view-intro { max-width: 760px; }
.view-intro h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 6px; }
.view-intro p { margin: 0; color: var(--muted); }
.single { padding-block: 20px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 20px; }

/* Feature catalogue */
.fgroup h3 { font-size: 15px; font-weight: 650; margin-bottom: 4px; }
.fgroup > .note { margin: 0 0 12px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.fcard-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.fcard-head b { font-size: 14px; font-weight: 650; }
.fcard-head .pill { font-weight: 500; font-size: 11px; text-align: right; }
.fvalue { margin: 0; font-size: 13px; color: var(--text); }
.fcard ul { margin: 0; padding-left: 18px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.fcard .btn { align-self: flex-start; margin-top: auto; }

/* Clip player */
.clip-overlay { position: fixed; inset: 0; background: rgba(8, 10, 14, .72); z-index: 60; display: grid; place-items: center; padding: 16px; }
.clip { width: min(880px, 100%); background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.clip-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.clip-head b { display: block; font-size: 15px; }
.clip-head span { font-size: 12px; color: var(--muted); }
.clip-video { aspect-ratio: 16 / 9; background: #000; border-radius: 4px; overflow: hidden; }
.clip-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.clip-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; position: relative; }
.clip-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }
.clip-bar.hit i { background: var(--danger); }
.clip .note { margin: 0; }

/* Heat maps and questions */
.heatgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.heatgrid figure { margin: 0; }
.heatgrid canvas { width: 100%; aspect-ratio: 16 / 9; border-radius: 4px; background: #0b0d10; display: block; }
.heatgrid figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; }
.qa-list { display: flex; flex-wrap: wrap; gap: 8px; }
.qa-answer { margin-top: 14px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; font-size: 13px; color: var(--text); line-height: 1.6; }
.btn.small { padding: 3px 9px; font-size: 11px; }
.feed-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }

@media print {
  .topbar, .toast-wrap, .no-print, #view-live, #view-features { display: none !important; }
  body { background: #fff; }
  #view-reports { display: flex !important; }
  .panel { break-inside: avoid; }
}

.langswitch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; }
.langbtn { border: 0; background: transparent; padding: 3px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.langbtn.active { background: var(--accent); color: #fff; }
