/* Closed-Loop Semantic Safety Filter Explorer — same tokens as the VLA explorers. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.10);
  --good-text: #006300;
  --critical: #d03b3b;
  --warning-bg: #fff6df;
  --warning-border: #f0d48a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --good-text: #0ca30c;
    --critical: #e66767;
    --warning-bg: #2a2412;
    --warning-border: #5c4a17;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --good-text: #0ca30c;
  --critical: #e66767;
  --warning-bg: #2a2412;
  --warning-border: #5c4a17;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); }
body { font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text-primary); }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); }
.data-source { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); min-width: 0; }
.data-source select { max-width: min(460px, 60vw); }

select, .btn {
  font: inherit; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.btn.ghost { background: transparent; }
.btn:hover, select:hover { border-color: var(--axis); }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 64px; }
.loading, .empty { color: var(--text-muted); padding: 40px 0; text-align: center; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 14px; border: none; background: none; font: inherit; color: var(--text-secondary); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }

.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 20px; margin: 0 0 4px; }
.page-head .sub { color: var(--text-secondary); }
.crumb { display: inline-block; margin-bottom: 8px; color: var(--text-secondary); }

.warning {
  background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 14px; color: var(--text-primary);
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 2px; }
.card .caption { color: var(--text-secondary); font-size: 12.5px; margin: 0 0 10px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

.controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--text-secondary); font-size: 13px; }
.chip {
  font: inherit; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text-primary); }

.chart { width: 100%; }
.chart-scroll { overflow-x: auto; }
.chart-scroll .chart { min-width: 760px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.panel { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px 4px; background: var(--surface); }
.panel h3 { font-size: 13px; margin: 0; }
.panel .caption { margin: 0; font-size: 12px; color: var(--text-muted); }
.panel .na { color: var(--text-muted); padding: 50px 0; text-align: center; font-size: 13px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 6px; font-size: 12.5px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th:first-child, td:first-child, td.left, th.left { text-align: left; }
tbody tr:hover { background: var(--accent-soft); }
tr.clickable { cursor: pointer; }
.pm { color: var(--text-muted); }
.ok { color: var(--good-text); font-weight: 600; }
.bad { color: var(--critical); font-weight: 600; }
.muted { color: var(--text-muted); }

.episodes { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(560px, 100%), 1fr)); }
.episode { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.episode.flash { outline: 2px solid var(--accent); }
.episode-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--surface-2); font-size: 13px;
}
.episode-head .title { font-weight: 600; }
.episode-body { background: #fff; }
.episode-body img, .episode-body video { display: block; width: 100%; height: auto; }
.episode-body video { background: #000; max-height: 560px; }
.episode-foot { padding: 8px 12px; font-size: 12.5px; color: var(--text-secondary); }
.queries { max-height: 260px; overflow: auto; margin-top: 8px; }
.queries td { white-space: normal; text-align: left; }

@media (max-width: 640px) {
  main { padding: 14px 16px 48px; }
  .topbar { padding: 10px 16px; }
  .grid { grid-template-columns: 1fr; }
}
