:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --sidebar: #fafafa;
  --surface: #ffffff;
  --surface-soft: #f6f7f8;
  --surface-hover: #eef1f4;
  --text: #17191c;
  --text-soft: #62676f;
  --text-faint: #8b9098;
  --border: #dfe2e6;
  --border-strong: #cfd3d8;
  --blue: #347fd9;
  --blue-soft: #e7f1fd;
  --green: #1f9d72;
  --green-soft: #e4f4ed;
  --red: #d85858;
  --red-soft: #fbeaea;
  --amber: #b77a20;
  --amber-soft: #fff4dc;
  --code-bg: #17191d;
  --code-text: #e5e8ed;
  --shadow: 0 1px 2px rgba(20, 24, 28, 0.04);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e0f;
  --sidebar: #171819;
  --surface: #191a1b;
  --surface-soft: #1e2022;
  --surface-hover: #25272a;
  --text: #f1f2f3;
  --text-soft: #a4a7ab;
  --text-faint: #74787e;
  --border: #2c2e31;
  --border-strong: #3a3d41;
  --blue: #4a97ec;
  --blue-soft: #172b43;
  --green: #31b487;
  --green-soft: #15352b;
  --red: #ec6b6b;
  --red-soft: #3b2224;
  --amber: #e0a447;
  --amber-soft: #382d1b;
  --code-bg: #0e0f11;
  --code-text: #e7e9ec;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--text); background: var(--bg); font-family: var(--sans); font-size: 14px; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.icon-button svg, .search svg, .quiet-button svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 330px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid var(--border); overflow: hidden; }
.brandbar { height: 62px; padding: 0 16px 0 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.wordmark { color: var(--text); text-decoration: none; font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; background: transparent; }
.icon-button:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.icon-button svg { width: 15px; height: 15px; }
.sun-icon { display: none; }
:root[data-theme="dark"] .sun-icon { display: block; }
:root[data-theme="dark"] .moon-icon { display: none; }

.rail { min-height: 0; display: flex; flex: 1; flex-direction: column; }
.rail-head { padding: 15px 14px 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rail-head h2 { margin: 0 0 2px; font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.muted { color: var(--text-faint); font-size: 11px; }
.filter-chip, .quiet-button { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); }
.filter-chip { padding: 5px 9px; color: var(--text-soft); font-size: 11px; }
.filter-chip:hover, .quiet-button:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.filter-chip.active { border-color: var(--blue); background: var(--blue); color: #fff; }
.search { margin: 0 14px 11px; height: 34px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 18%, transparent); }
.search svg { width: 14px; color: var(--text-faint); }
.search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-size: 12px; }
.search input::placeholder { color: var(--text-faint); }
.candidate-list { min-height: 0; flex: 1; overflow-y: auto; padding: 0 8px 14px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.candidate-row { width: 100%; padding: 10px 10px 9px; display: grid; grid-template-columns: 1fr auto; gap: 4px 9px; border: 0; border-left: 2px solid transparent; border-radius: 7px; background: transparent; text-align: left; }
.candidate-row:hover { background: var(--surface-hover); }
.candidate-row.active { border-left-color: var(--blue); background: var(--blue-soft); }
.candidate-name { min-width: 0; overflow: hidden; font-size: 12px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.baseline-tag { margin-right: 6px; padding: 2px 4px; border-radius: 3px; background: color-mix(in srgb, #d99a3d 18%, transparent); color: #d99a3d; font-size: 8px; font-weight: 600; letter-spacing: .04em; vertical-align: 1px; }
.candidate-id, .score { color: var(--text-faint); font: 10px var(--mono); }
.candidate-row.active .candidate-name { color: var(--blue); }
.best-mark { color: var(--blue); font-size: 11px; }

.workspace { min-width: 0; padding: 26px 34px 56px; }
.topbar { min-height: 55px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.archive-label { display: flex; align-items: center; gap: 7px; color: var(--text-soft); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.live-dot.ok { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 15%, transparent); }
.live-dot.error { background: var(--red); }
h1 { margin: 5px 0 2px; font-size: 20px; line-height: 1.25; letter-spacing: -.025em; }
.workspace-heading code { display: block; max-width: min(70vw, 850px); overflow: hidden; color: var(--text-soft); font: 10px var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.quiet-button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; color: var(--text-soft); font-size: 11px; }
.quiet-button svg { width: 13px; }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tab { padding: 7px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text-soft); font-size: 12px; font-weight: 500; }
.tab:hover { background: var(--surface-hover); }
.tab.active { background: var(--blue); color: #fff; }
.content-card { min-height: calc(100vh - 140px); border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.panel { padding: 22px; }
.hidden { display: none !important; }

.eyebrow { margin: 0 0 6px; color: var(--text-faint); font: 9px var(--mono); text-transform: uppercase; letter-spacing: .08em; overflow-wrap: anywhere; }
.candidate-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.candidate-title h2 { margin: 0; font-size: 22px; font-weight: 600; line-height: 1.25; letter-spacing: -.025em; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.badge { padding: 3px 7px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-soft); background: var(--surface-soft); font-size: 10px; }
.badge.verified { border-color: transparent; background: var(--green-soft); color: var(--green); }
.badge.best { border-color: transparent; background: var(--blue-soft); color: var(--blue); }
.badge.baseline { border-color: transparent; background: color-mix(in srgb, #d99a3d 18%, transparent); color: #c88725; }
.metric-grid { margin: 20px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.metric { min-height: 73px; padding: 13px; background: var(--surface-soft); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.metric:nth-child(4n) { border-right: 0; }
.metric:nth-last-child(-n + 4) { border-bottom: 0; }
.metric strong { display: block; overflow-wrap: anywhere; font: 500 13px var(--mono); font-variant-numeric: tabular-nums; }
.metric span { display: block; margin-top: 6px; color: var(--text-faint); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.section-title { margin: 22px 0 8px; color: var(--text-soft); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.prose { max-width: 78ch; color: var(--text-soft); font-size: 12px; line-height: 1.65; }
pre { margin: 0; max-height: 460px; overflow: auto; padding: 14px; border: 1px solid var(--border); border-radius: 7px; background: var(--code-bg); color: var(--code-text); font: 11px/1.65 var(--mono); tab-size: 4; }
.code-wrap { position: relative; }
.copy { position: absolute; z-index: 1; top: 8px; right: 8px; border-color: #383b40; background: #24272b; color: #c8ccd2; }
.copy:hover { background: #30343a; }
.empty { padding: 55px 10px; color: var(--text-faint); font-size: 12px; text-align: center; }

.verification-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; }
.verification-head h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.verification-head > div > p:last-child { max-width: 620px; margin: 7px 0 0; color: var(--text-soft); font-size: 11px; line-height: 1.55; }
.assurance-result { min-width: 150px; padding: 10px 12px; border: 1px solid var(--border); border-left-width: 3px; border-radius: 7px; background: var(--surface-soft); }
.assurance-result.accepted { border-left-color: var(--green); }
.assurance-result.rejected { border-left-color: var(--red); }
.assurance-result span { display: block; color: var(--text-faint); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.assurance-result strong { display: block; margin-top: 4px; font: 500 12px var(--mono); }
.assurance-ladder { position: relative; margin: 24px 0 18px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); list-style: none; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.assurance-ladder li { position: relative; min-height: 88px; padding: 13px; border-right: 1px solid var(--border); background: var(--surface-soft); }
.assurance-ladder li:last-child { border-right: 0; }
.assurance-ladder li.complete { background: color-mix(in srgb, var(--green-soft) 66%, var(--surface)); }
.assurance-ladder li.current { box-shadow: inset 0 -2px var(--green); }
.tier-index { display: block; margin-bottom: 11px; color: var(--text-faint); font: 9px var(--mono); }
.assurance-ladder li.complete .tier-index { color: var(--green); }
.assurance-ladder strong { display: block; font-size: 11px; font-weight: 600; }
.assurance-ladder small { display: block; margin-top: 4px; color: var(--text-faint); font-size: 9px; line-height: 1.4; }
.archive-notice { display: flex; align-items: baseline; gap: 9px; margin-bottom: 16px; padding: 9px 11px; border: 1px solid color-mix(in srgb, var(--amber) 32%, var(--border)); border-radius: 7px; background: var(--amber-soft); color: var(--amber); font-size: 10px; }
.archive-notice span { color: var(--text-soft); }
.evidence-summary { min-height: 34px; display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); color: var(--text-faint); font-size: 10px; }
.evidence-summary b { color: var(--text); font: 500 11px var(--mono); }
.template-ref { margin-left: auto; font: 9px var(--mono); }
.evidence-groups { display: grid; gap: 22px; margin-top: 20px; }
.evidence-group-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; color: var(--text-soft); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.evidence-group-title small { color: var(--text-faint); font-size: 9px; text-transform: none; letter-spacing: 0; }
.evidence-list { border-top: 1px solid var(--border); }
.evidence-row { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 6px; padding: 13px 4px; border-bottom: 1px solid var(--border); }
.evidence-mark { width: 16px; height: 16px; display: grid; place-items: center; margin-top: 1px; border-radius: 50%; background: var(--surface-soft); color: var(--text-faint); font: 600 10px var(--sans); }
.evidence-row.pass .evidence-mark { background: var(--green-soft); color: var(--green); }
.evidence-row.fail .evidence-mark { background: var(--red-soft); color: var(--red); }
.evidence-row.pending .evidence-mark { background: var(--amber-soft); color: var(--amber); }
.evidence-name { color: var(--text); font-size: 11px; font-weight: 600; text-transform: capitalize; }
.evidence-copy p { margin: 3px 0 0; color: var(--text-soft); font-size: 10px; line-height: 1.5; }
.evidence-metrics { margin: 9px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.evidence-metrics div { min-width: 128px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-soft); }
.evidence-metrics dt { color: var(--text-faint); font-size: 8px; text-transform: uppercase; letter-spacing: .05em; }
.evidence-metrics dd { margin: 3px 0 0; color: var(--text-soft); font: 9px var(--mono); overflow-wrap: anywhere; }
.verification-footnote { margin-top: 24px; padding: 12px 14px; border-left: 2px solid var(--blue); background: var(--surface-soft); }
.verification-footnote strong { font-size: 10px; }
.verification-footnote p { max-width: 850px; margin: 4px 0 0; color: var(--text-soft); font-size: 10px; line-height: 1.55; }
.verification-empty { min-height: 420px; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; }
.verification-empty span { margin-bottom: 9px; color: var(--text-faint); font: 9px var(--mono); letter-spacing: .08em; }
.verification-empty strong { font-size: 14px; }
.verification-empty p { color: var(--text-faint); font-size: 11px; }

.plot-heading { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; }
.plot-heading strong { font-size: 12px; font-weight: 600; }
.plot-heading span { color: var(--text-faint); font-size: 11px; }
.plot-card { padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); }
#pareto-plot { width: 100%; height: auto; display: block; color: var(--text); }
.plot-grid { stroke: var(--border); stroke-width: 1; }
.plot-axis { stroke: var(--text-soft); stroke-width: 1; }
.baseline-reference { stroke: #d99a3d; stroke-width: 1; stroke-dasharray: 5 4; opacity: .8; }
.baseline-label { fill: #d99a3d; stroke: none; font-family: var(--sans); font-size: 10px; font-weight: 500; }
.axis-label { fill: var(--text-faint); stroke: none; font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace; font-size: 11px; font-weight: 400; }
.axis-title { fill: var(--text-soft); stroke: none; font-family: var(--sans); font-size: 11px; font-weight: 400; }
.plot-label { fill: var(--text); stroke: none; font-family: var(--sans); font-size: 11px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .12s ease; }
g[data-plot-id]:hover .plot-label { opacity: 1; }
.point { stroke: var(--surface); stroke-width: 2; cursor: pointer; transition: r .15s ease, opacity .15s ease; }
.point:hover { r: 8; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 9px; color: var(--text-faint); font-size: 10px; }
.legend i { width: 7px; height: 7px; display: inline-block; margin-right: 4px; border-radius: 50%; }
.legend i.baseline-key { border-radius: 2px; background: #d99a3d; }
.legend b { margin-right: 3px; color: var(--blue); font-size: 11px; font-weight: 400; }
#progress-plot { width: 100%; height: auto; display: block; color: var(--text); }
.progress-best { stroke: #31b487; stroke-width: 2; opacity: .9; }
.progress-annotation { fill: #31b487; stroke: none; font-family: var(--sans); font-size: 10px; font-weight: 500; pointer-events: none; }
.discarded-point { opacity: .45; cursor: pointer; }
.kept-point { cursor: pointer; }
.run-select { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; }
.trace-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.trace-heading strong { display: block; font-size: 13px; font-weight: 600; }
.trace-heading span { display: block; margin-top: 3px; color: var(--text-faint); font-size: 10px; }
.trace-empty { min-height: 340px; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; }
.trace-empty-icon { margin-bottom: 12px; padding: 4px 7px; border-radius: 4px; background: color-mix(in srgb, #d99a3d 18%, transparent); color: #d99a3d; font-size: 9px; font-weight: 600; letter-spacing: .06em; }
.trace-empty-icon.backend { background: var(--red-soft, #3b2224); color: var(--red); }
.trace-empty strong { font-size: 13px; font-weight: 600; }
.trace-empty p { max-width: 430px; margin: 7px 0 0; color: var(--text-faint); font-size: 11px; line-height: 1.6; }
.trace-empty code { font-family: var(--mono); color: var(--text-soft); }
.run-select select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-soft); font: 10px var(--mono); }
.timeline { margin-left: 4px; border-left: 1px solid var(--border); }
.event { position: relative; padding: 0 0 18px 18px; }
.event::before { content: ""; position: absolute; top: 3px; left: -4px; width: 7px; height: 7px; border: 1px solid var(--text-soft); border-radius: 50%; background: var(--surface); }
.event.tool::before { border-color: var(--blue); background: var(--blue); }
.event-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px; font-size: 10px; }
.event-role { font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.event-sequence { color: var(--text-faint); font-family: var(--mono); }
.event.candidate-linked::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 14%, transparent); }
.event-body { margin-top: 5px; color: var(--text-soft); font: 10px/1.6 var(--mono); white-space: pre-wrap; word-break: break-word; }
#toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--text); color: var(--surface); font-size: 11px; opacity: 0; transform: translateY(6px); transition: .18s ease; }
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; max-height: 470px; border-right: 0; border-bottom: 1px solid var(--border); }
  .candidate-list { max-height: 260px; }
  .workspace { padding: 20px 16px 40px; }
  .content-card { min-height: 500px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-last-child(-n + 4) { border-bottom: 1px solid var(--border); }
  .metric:nth-last-child(-n + 2) { border-bottom: 0; }
  .assurance-ladder { grid-template-columns: 1fr; }
  .assurance-ladder li { min-height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .assurance-ladder li:last-child { border-bottom: 0; }
  .assurance-ladder li.current { box-shadow: inset 2px 0 var(--green); }
}

@media (max-width: 560px) {
  .topbar { align-items: center; }
  .workspace-heading code { max-width: 68vw; }
  .panel { padding: 16px; }
  .verification-head { flex-direction: column; gap: 14px; }
  .assurance-result { width: 100%; }
  .evidence-summary { flex-wrap: wrap; gap: 9px 14px; padding: 7px 0; }
  .template-ref { width: 100%; margin-left: 0; }
}

g[data-plot-id]:focus-visible { outline: none; }
g[data-plot-id]:focus-visible .point { stroke: var(--text); stroke-width: 3; }
g[data-plot-id]:focus-visible .plot-label { opacity: 1; }
