/* AV Diagnostics Suite. Bold, tight, built for the modern web. */

:root {
  --bg: #08090b;
  --surface: #0f1114;
  --surface-2: #16191e;
  --line: #24282f;
  --line-soft: #1a1d22;
  --text: #f4f6f8;
  --muted: #8b939e;
  --accent: #c8ff2e;
  --accent-ink: #0a0c05;
  --good: #2ee08a;
  --warn: #ffbe2e;
  --bad: #ff4f5a;
  --info: #56b8ff;

  --r-sm: 3px;
  --r: 6px;
  --r-lg: 10px;

  --pad: 14px;
  --gap: 10px;

  --sans: "Inter Tight", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --line: #d6dae0;
  --line-soft: #e6e9ed;
  --text: #0d1014;
  --muted: #5c6673;
  --accent: #5b8c00;
  --accent-ink: #ffffff;
  --good: #00875a;
  --warn: #a86400;
  --bad: #c62828;
  --info: #0b62c4;
  color-scheme: light;
}

* { box-sizing: border-box; min-width: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  overflow-wrap: break-word;
}

h1, h2, h3, h4 { margin: 0; font-weight: 760; letter-spacing: -0.03em; line-height: 1.05; }
p { margin: 0 0 .5rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }

:where(button, input, select, textarea, a, [tabindex], summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip { position: fixed; left: -9999px; z-index: 200; }
.skip:focus { left: 12px; top: 12px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; font-weight: 700; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---------------------------------------------------------------- header */

header.top {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 16px;
  height: 54px; padding: 0 var(--pad);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: baseline; gap: 8px; font-weight: 800; letter-spacing: -0.04em; font-size: 1.05rem;
  color: inherit; text-decoration: none;
}
.brand:hover, .brand:focus-visible { opacity: 0.82; }
.brand b { color: var(--accent); }
.brand small { color: var(--muted); font-weight: 500; font-size: .72rem; letter-spacing: 0; }

.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.confidence-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 4px 10px; background: var(--surface);
}
.confidence-chip .label { font-size: .64rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.confidence-chip strong { font-family: var(--mono); font-size: .92rem; }
.confidence-chip .track { width: 56px; height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.confidence-chip .track i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ---------------------------------------------------------------- shell */

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); align-items: start; }

nav.side {
  position: sticky; top: 54px;
  height: calc(100vh - 54px); overflow: auto;
  border-right: 1px solid var(--line);
  padding: 10px;
  scrollbar-width: thin;
}

.nav-search {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 8px 10px; margin-bottom: 8px;
}
.nav-section { margin-bottom: 10px; }
.nav-group {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); font-weight: 700; padding: 6px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; background: none; border: 0; cursor: pointer;
  padding: 6px 8px; border-radius: var(--r); color: var(--text);
  font-size: .855rem; line-height: 1.25;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.nav-item-title { flex: 1; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: transparent; flex: none; }
.nav-dot[data-state="pass"] { background: var(--good); }
.nav-dot[data-state="warn"] { background: var(--warn); }
.nav-dot[data-state="fail"] { background: var(--bad); }
.nav-dot[data-state="info"] { background: var(--info); }
.nav-empty { color: var(--muted); font-size: .82rem; padding: 8px; }

main { padding: var(--pad); max-width: 1560px; }

@media (min-width: 1920px) {
  main { max-width: clamp(1560px, calc(1560px + (100vw - 1920px) * 0.8125), 2080px); }
}

/* ---------------------------------------------------------------- hero */

.hero { margin-bottom: 14px; }
.hero .eyebrow {
  font-size: .64rem; text-transform: uppercase; letter-spacing: .16em;
  color: var(--accent); font-weight: 800; margin-bottom: 6px;
}
.hero h1 { font-size: clamp(1.85rem, 4.2vw, 3.1rem); max-width: 22ch; }
.hero .blurb { color: var(--muted); max-width: 72ch; margin-top: 8px; font-size: 1rem; }

.safety {
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  background: var(--surface); padding: 10px 12px; border-radius: var(--r);
  margin-bottom: 14px; font-size: .88rem;
}
.safety strong { margin-right: 4px; }

/* ---------------------------------------------------------------- cards */

#workspace { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--gap); align-items: start; }

.card {
  grid-column: span 6;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--pad);
}
.card.full { grid-column: 1 / -1; }
.card.third { grid-column: span 4; }
.card.two-thirds { grid-column: span 8; }
.card-title { font-size: 1.02rem; margin-bottom: 10px; letter-spacing: -0.02em; }

/* ---------------------------------------------------------------- metrics */

.metric-list { border-top: 1px solid var(--line-soft); }
.metric {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
  gap: 4px 12px;
  padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: .875rem;
}
.metric-key { color: var(--muted); flex: 1 1 40%; }
.metric-val {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 7px;
  text-align: right; justify-content: flex-end; flex: 1 1 auto; max-width: 100%;
}
.metric-val strong { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric > span:not(.metric-key):not(.metric-val) { flex: 1 1 55%; text-align: right; }

.tag {
  font-size: .6rem; text-transform: uppercase; letter-spacing: .07em;
  padding: 2px 5px; border-radius: var(--r-sm); white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.tag-measured { color: var(--good); border-color: color-mix(in oklab, var(--good) 40%, var(--line)); }
.tag-calculated { color: var(--info); border-color: color-mix(in oklab, var(--info) 40%, var(--line)); }
.tag-observed { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 40%, var(--line)); }
.tag-instrument, .tag-unavailable { color: var(--bad); border-color: color-mix(in oklab, var(--bad) 35%, var(--line)); }

/* ---------------------------------------------------------------- verdict */

.verdict {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; margin: 10px 0; background: var(--surface-2);
}
.verdict-mark {
  width: 30px; height: 30px; flex: none; display: grid; place-items: center;
  border-radius: 50%; font-weight: 800; font-size: 1rem;
  background: var(--muted); color: var(--bg);
}
.verdict-good  { border-left: 3px solid var(--good); }
.verdict-good .verdict-mark { background: var(--good); }
.verdict-warn  { border-left: 3px solid var(--warn); }
.verdict-warn .verdict-mark { background: var(--warn); }
.verdict-bad   { border-left: 3px solid var(--bad); }
.verdict-bad .verdict-mark { background: var(--bad); }
.verdict-info  { border-left: 3px solid var(--info); }
.verdict-info .verdict-mark { background: var(--info); }

.verdict-label { display: block; font-size: 1.15rem; letter-spacing: -0.03em; }
.verdict-headline { margin: 2px 0 0; font-size: .92rem; }
.verdict-detail { margin: 4px 0 0; color: var(--muted); font-size: .84rem; }

/* ---------------------------------------------------------------- howto */

.howto {
  border: 1px dashed var(--line); border-radius: var(--r);
  padding: 10px 12px; margin-bottom: 10px; background: var(--surface-2);
}
.howto-tag {
  display: inline-block; font-size: .6rem; text-transform: uppercase;
  letter-spacing: .12em; font-weight: 800; color: var(--accent); margin-bottom: 4px;
}
.howto ol, .steps { margin: 0; padding-left: 18px; }
.howto li, .steps li { margin: 3px 0; font-size: .88rem; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
.checklist label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: .88rem; }
.checklist input { margin-top: 3px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- controls */

.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }

.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 7px 12px; border-radius: var(--r); cursor: pointer; font-weight: 600;
  font-size: .855rem; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-good { border-color: color-mix(in oklab, var(--good) 55%, var(--line)); }
.btn-bad  { border-color: color-mix(in oklab, var(--bad) 55%, var(--line)); }
.btn-ghost { background: transparent; }
.btn-danger { background: color-mix(in oklab, var(--bad) 22%, var(--surface)); border-color: var(--bad); }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.field { display: grid; gap: 3px; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 700; }
.field > :not(span) { text-transform: none; letter-spacing: 0; font-weight: 400; }

input[type="text"], input[type="number"], input[type="search"], select, textarea {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r); padding: 7px 9px; width: 100%;
}
textarea { resize: vertical; font-size: .875rem; line-height: 1.45; }
input[type="range"] { accent-color: var(--accent); width: 150px; padding: 0; background: none; border: 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.range { display: flex; align-items: center; gap: 8px; }
.range-out { font-family: var(--mono); font-size: .8rem; color: var(--muted); min-width: 6ch; }

.judge { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.judge-tag { font-size: .6rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; color: var(--muted); }
.judge-status { font-size: .78rem; color: var(--muted); margin-top: 6px; }

.tech { margin-top: 10px; border-top: 1px solid var(--line-soft); padding-top: 8px; }
.tech summary {
  cursor: pointer; font-size: .76rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; list-style: none;
}
.tech summary::-webkit-details-marker { display: none; }
.tech summary::before { content: "+ "; color: var(--accent); }
.tech[open] summary::before { content: "- "; }
.tech > :not(summary) { margin-top: 8px; }

.inline-note { font-size: .82rem; color: var(--muted); margin-top: 6px; }
.note-warn { color: var(--warn); }
.note-bad { color: var(--bad); }
.note-good { color: var(--good); }

.limitation {
  font-size: .8rem; color: var(--muted); margin-top: 10px;
  border-left: 2px solid var(--line); padding-left: 9px;
}
.limitation strong { color: var(--text); }

.pill {
  display: inline-block; font-size: .68rem; font-weight: 700; padding: 2px 7px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); } .pill.info { color: var(--info); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.kpi { border: 1px solid var(--line); border-radius: var(--r); padding: 9px 11px; background: var(--surface-2); }
.kpi-value { display: block; font-family: var(--mono); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.kpi-label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.kpi.good .kpi-value { color: var(--good); }
.kpi.warn .kpi-value { color: var(--warn); }
.kpi.bad .kpi-value { color: var(--bad); }

.meter { height: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), var(--warn) 78%, var(--bad)); transition: width .06s linear; }
.meter-fill.flat { background: var(--accent); }

canvas.chart {
  width: 100%; height: 190px; display: block;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r);
}
canvas.chart.tall { height: 260px; }

pre.err { font-family: var(--mono); font-size: .78rem; color: var(--bad); white-space: pre-wrap; }
.scroll-x { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.data th, table.data td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line-soft); }
table.data th { color: var(--muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
table.data td.num { font-family: var(--mono); text-align: right; }

/* ---------------------------------------------------------------- stage */

.stage {
  position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r);
  width: 100%;
}
.stage:fullscreen { border: 0; border-radius: 0; height: 100vh !important; width: 100vw; }
.stage-surface { position: absolute; inset: 0; }
.stage-label {
  position: absolute; left: 10px; top: 10px; z-index: 3;
  background: #000000cc; color: #fff; padding: 4px 9px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: .74rem; pointer-events: none;
}
.stage-bar {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 4;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
  max-width: calc(100% - 20px); padding: 5px;
  background: #000000b8; border-radius: var(--r); backdrop-filter: blur(6px);
  opacity: .28; transition: opacity .18s;
}
.stage:hover .stage-bar, .stage:focus-within .stage-bar { opacity: 1; }
.stage-bar .btn { background: #ffffff14; border-color: #ffffff33; color: #fff; padding: 5px 9px; font-size: .78rem; }
.stage-bar .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.stage-hint {
  position: absolute; right: 10px; top: 10px; z-index: 3;
  font-size: .68rem; color: #ffffffaa; background: #00000099;
  padding: 3px 7px; border-radius: var(--r-sm); pointer-events: none;
}
.stage:fullscreen .stage-hint { opacity: 0; }

.swatch { width: 30px; height: 26px; padding: 0; border-radius: var(--r-sm); border: 1px solid #ffffff44; cursor: pointer; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

.mapper { position: relative; cursor: crosshair; touch-action: none; }
.pin {
  position: absolute; width: 15px; height: 15px; padding: 0;
  border: 2px solid #fff; border-radius: 50%; transform: translate(-50%, -50%);
  cursor: pointer; box-shadow: 0 1px 5px #000a; background: var(--bad);
}
.pin:hover { transform: translate(-50%, -50%) scale(1.25); }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed; left: 50%; bottom: 18px; z-index: 150;
  transform: translate(-50%, 130%); opacity: 0;
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-weight: 650; font-size: .875rem;
  transition: transform .2s ease, opacity .2s ease; pointer-events: none;
  max-width: min(92vw, 520px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }
#toast.good { background: var(--good); color: #06251a; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .card, .card.third, .card.two-thirds { grid-column: 1 / -1; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  nav.side {
    position: static; height: auto; border-right: 0;
    border-bottom: 1px solid var(--line); max-height: 42vh;
  }
  header.top { height: auto; flex-wrap: wrap; padding: 8px var(--pad); gap: 8px; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1 1 auto; }   /* nothing is hidden on small screens now */
  .confidence-chip { flex: 1 0 100%; order: -1; justify-content: space-between; }
  .confidence-chip .track { flex: 1; width: auto; }
  .hero h1 { font-size: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------- print */

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --muted: #444; --line: #bbb; --line-soft: #ddd; }
  body { background: #fff; color: #000; font-size: 11pt; }
  header.top, nav.side, #toast, .stage-bar, .stage-hint, .top-actions,
  .btn, .judge, .nav-search, .skip, canvas.chart { display: none !important; }
  .shell { display: block; }
  main { padding: 0; max-width: none; }
  #workspace { display: block; }
  .card {
    grid-column: auto !important; break-inside: avoid; page-break-inside: avoid;
    border: 1px solid #bbb; margin-bottom: 10pt; padding: 10pt;
  }
  .tech { display: block; }
  .tech[open] > :not(summary), .tech > :not(summary) { display: block !important; }
  details:not([open]) > :not(summary) { display: block !important; }
  .hero h1 { font-size: 20pt; }
  .verdict { border: 1px solid #999; }
  a[href]::after { content: ""; }
  .print-only { display: block !important; }
}

.print-only { display: none; }
