:root, [data-theme="dark"] {
  --bg: #0b1220; --bg2: #0f1829; --panel: #121d31; --panel2: #17243b; --line: #22324d;
  --text: #e4ecf7; --muted: #8fa3bf; --accent: #2dd4bf; --accent2: #38bdf8;
  --good: #34d399; --warn: #fbbf24; --bad: #f87171; --info: #93c5fd;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f7fb; --bg2: #eaf0f7; --panel: #ffffff; --panel2: #f2f6fb; --line: #d5dfeb;
  --text: #0e1a2b; --muted: #50637c; --accent: #0d9488; --accent2: #0369a1;
  --good: #047857; --warn: #a16207; --bad: #b91c1c; --info: #1d4ed8;
  --shadow: 0 6px 20px rgba(15,30,60,.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { background: radial-gradient(1200px 600px at 80% -10%, color-mix(in srgb, var(--accent2) 10%, transparent), transparent), var(--bg); min-height: 100vh; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; gap: 16px; align-items: center; padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 8px; align-items: center; color: var(--accent); font-weight: 650; letter-spacing: .02em; white-space: nowrap; }
.brand span { color: var(--text); }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--panel2); text-decoration: none; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; }
.health { font-size: 12px; color: var(--muted); white-space: nowrap; }
.health::before { content: "●"; margin-right: 5px; color: var(--muted); }
.health.ok::before { color: var(--good); } .health.warn::before { color: var(--warn); } .health.bad::before { color: var(--bad); }
main { padding: 20px; max-width: 1500px; margin: 0 auto; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
h1 { font-size: 22px; margin: 4px 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: 15px; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.cols2 { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.kpi .n { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi a { color: inherit; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 70px; }
button.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button.btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #04211d; border-color: transparent; font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.tabs button.on { background: var(--panel2); color: var(--text); border-color: var(--accent); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel2); color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td.proj { min-width: 180px; font-weight: 600; }
td small, .muted { color: var(--muted); }
.unk { color: var(--muted); font-style: italic; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--line); white-space: nowrap; }
.pill.High, .pill.primary_confirmed, .pill.published, .pill.ok, .pill.success { color: var(--good); border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.pill.Medium, .pill.corroborated, .pill.approved { color: var(--info); border-color: color-mix(in srgb, var(--info) 50%, transparent); }
.pill.Low, .pill.review_needed, .pill.review, .pill.partial, .pill.degraded, .pill.untested, .pill.not_modified { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.pill.conflicting, .pill.failed, .pill.blocked, .pill.failing, .pill.rejected { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.pill.inference { color: var(--accent2); border-style: dashed; }
.pill.manual { color: var(--accent); border-style: dashed; }
#reviewCount { margin-left: 4px; }
.cards { display: none; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.pcard .t { font-weight: 650; margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.evidence { border-left: 3px solid var(--line); padding: 8px 12px; margin: 10px 0; background: var(--bg2); border-radius: 0 8px 8px 0; }
.evidence blockquote { margin: 6px 0; color: var(--text); font-style: italic; }
.evidence .meta { font-size: 12px; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.inference-box { border: 1px dashed var(--accent2); border-radius: 10px; padding: 10px 12px; background: color-mix(in srgb, var(--accent2) 6%, transparent); }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.err { color: var(--bad); }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid; }
.banner.warn { border-color: var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.banner.bad { border-color: var(--bad); color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.banner.info { border-color: var(--info); color: var(--info); background: color-mix(in srgb, var(--info) 8%, transparent); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--accent);
  padding: 8px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }
.login { max-width: 400px; margin: 10vh auto; }
.login input { width: 100%; margin: 8px 0; }
.scan { position: relative; overflow: hidden; }
.scan::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--accent) 10%, transparent) 50%, transparent 70%);
  transform: translateX(-100%); animation: scan 4s ease-in-out infinite; pointer-events: none; }
@keyframes scan { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { *, *::after { animation: none !important; transition: none !important; } }
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .health { display: none; }
  main { padding: 12px; }
  .table-wrap.responsive { display: none; }
  .cards { display: block; }
  .kv { grid-template-columns: 110px 1fr; }
  .cols2 { grid-template-columns: 1fr; }
}
.card table select { max-width: 110px; }
.pill.historical, .pill.reference { color: var(--muted); border-style: dashed; }
