:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #161a23; --muted: #5b6273; --line: #e1e4ea;
  --accent: #0f7b8a; --accent-ink: #ffffff; --accent-soft: #e2f3f5;
  --ok: #157f3b; --ok-soft: #e7f6ec; --warn: #8a4b00; --warn-soft: #fff3e0; --bad: #b42318; --bad-soft: #fdecea;
  --chip: #eef0f4; --chip-hover: #e2eef0; --stage: #e9ecf1;
  --tp: #16a34a; --fp: #dc2626; --fn: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1116; --panel: #171b22; --ink: #e7eaf0; --muted: #9aa3b5; --line: #2a303c;
  --accent: #4fc3d1; --accent-ink: #062a2f; --accent-soft: #123138;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270b; --bad: #f87171; --bad-soft: #3a1515;
  --chip: #212631; --chip-hover: #1d3539; --stage: #0b0d11;
  --tp: #22c55e; --fp: #f87171; --fn: #fbbf24;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.hidden { display: none !important; }
[hidden] { display: none !important; }
h1 { font-size: 30px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.brand strong { overflow: hidden; text-overflow: ellipsis; }
.backlink { text-decoration: none; color: var(--muted); }
.backlink:hover { color: var(--ink); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.freebadge { font-size: 12px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }

button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px;
  cursor: pointer; min-height: 38px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, .filebtn:focus-within, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
button.full { width: 100%; }
button.link { border: 0; background: none; padding: 0 4px; min-height: 0; color: var(--accent); font-size: 13px; }
button.link:hover { text-decoration: underline; }
button:disabled { opacity: .45; cursor: default; }
.iconbtn { min-width: 38px; padding: 4px 10px; font-size: 18px; line-height: 1; }
select, input[type="text"], input[type="search"], input[type="number"] {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 9px; min-height: 36px; min-width: 0;
}
input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 22px 20px 40px; }
.hero { margin-bottom: 14px; }
.lede { color: var(--muted); margin: 0; font-size: 16px; max-width: 760px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; min-width: 0; }
.phead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.spacer { flex: 1; }
.notice { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.pill { display: inline-block; font-size: 12px; padding: 0 8px; border-radius: 99px; background: var(--chip); color: var(--muted); font-weight: 600; }
.pill:empty { display: none; }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* loader */
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.slot { border: 2px dashed var(--line); border-radius: 10px; padding: 12px; transition: border-color .15s, background .15s; min-width: 0; }
.slot.drag { border-color: var(--accent); background: var(--accent-soft); }
.slot.done { border-style: solid; border-color: var(--accent); }
.slothead { display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.req, .opt { margin-left: auto; font-size: 12px; color: var(--muted); }
.req { color: var(--accent); }
.filebtn { position: relative; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; min-height: 38px; cursor: pointer; background: var(--panel); overflow: hidden; }
.filebtn:hover { border-color: var(--accent); }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.slotstate { font-size: 13px; color: var(--muted); margin: 8px 0 0; overflow-wrap: anywhere; }
.slot.done .slotstate { color: var(--ink); }
.loadfoot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.loadfoot .hint { margin: 0; }
.progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.progress .bar { flex: 0 0 220px; height: 6px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.loader.compact .slots, .loader.compact .loadfoot .hint { display: none; }
.loader.compact { padding: 10px 16px; }
.loader.compact .loadfoot { margin-top: 0; }

.summary { display: flex; gap: 8px 18px; flex-wrap: wrap; align-items: baseline; margin: -4px 0 12px; font-size: 14px; }
.summary b { font-variant-numeric: tabular-nums; }
.summary .warnline { color: var(--warn); }

/* workspace */
.workspace { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px; align-items: start; }
.filters { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; padding: 12px 14px; }
.filters summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
.filters summary::-webkit-details-marker { display: none; }
.fgroup { border-top: 1px solid var(--line); padding: 10px 0; }
.fhead { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.fgroup input[type="search"], .fgroup select { width: 100%; }
.catlist { max-height: 260px; overflow: auto; margin-top: 6px; display: grid; gap: 2px; }
.catrow { display: grid; grid-template-columns: 16px 12px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.catrow:hover { background: var(--chip); }
.catrow .sw { width: 12px; height: 12px; border-radius: 3px; }
.catrow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catrow .ct { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.checks { display: grid; gap: 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.inline input[type="range"] { width: 90px; }
.range2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.range2 label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.range2 input { width: 100%; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented .seg { border: 0; border-radius: 0; min-height: 32px; padding: 4px 12px; background: transparent; font-size: 14px; }
.segmented .seg + .seg { border-left: 1px solid var(--line); }
.segmented .seg.on { background: var(--accent); color: var(--accent-ink); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px; overflow-x: auto; scrollbar-width: thin; }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; white-space: nowrap; color: var(--muted); font-weight: 600; }
.tab:hover { color: var(--ink); border-color: transparent; border-bottom-color: var(--line); }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.viewinfo { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.viewinfo b { color: var(--ink); }

/* viewer */
.vbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.nav { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; min-width: 0; }
.nav input[type="range"] { flex: 1; min-width: 60px; }
.toggles { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; }
.cmpbar { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; margin-top: 10px; padding: 8px 10px; background: var(--chip); border-radius: 8px; font-size: 14px; }
.cmpbar output { font-variant-numeric: tabular-nums; min-width: 2.6em; }
.key::before { content: ""; display: inline-block; width: 12px; height: 3px; margin-right: 5px; vertical-align: middle; border-radius: 2px; background: currentColor; }
.key.gt { color: var(--muted); } .key.tp { color: var(--tp); } .key.fp { color: var(--fp); } .key.fn { color: var(--fn); }
.key { color: var(--ink); }
.imgmeta { font-size: 13px; color: var(--muted); margin: 10px 0 6px; overflow-wrap: anywhere; }
.imgmeta b { color: var(--ink); }
.imgmeta .warn { color: var(--warn); }
.stage { position: relative; background: var(--stage); border-radius: 8px; overflow: auto; max-height: 78vh; display: flex; justify-content: center; }
.stage.zoomed { justify-content: flex-start; }
.stage canvas { display: block; max-width: none; cursor: crosshair; }
.tip { position: absolute; z-index: 3; pointer-events: none; background: rgba(15, 18, 25, .92); color: #fff; font-size: 12px; line-height: 1.45; padding: 6px 9px; border-radius: 6px; max-width: 260px; }

.tablewrap { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 5px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--muted); z-index: 1; }
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--ink); }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tr.sel td { background: var(--accent-soft); }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { background: var(--chip); }
table.grid .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
table.grid td.empty { color: var(--muted); text-align: center; cursor: default; }
.tag { display: inline-block; padding: 0 7px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.tag.tp { background: color-mix(in srgb, var(--tp) 18%, transparent); color: var(--tp); }
.tag.fp { background: color-mix(in srgb, var(--fp) 18%, transparent); color: var(--fp); }
.tag.fn { background: color-mix(in srgb, var(--fn) 20%, transparent); color: var(--fn); }
.tag.ig { background: var(--chip); color: var(--muted); }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb { position: relative; border: 2px solid transparent; border-radius: 8px; padding: 0; background: var(--stage); overflow: hidden; min-height: 0; text-align: left; }
.thumb.on { border-color: var(--accent); }
.thumb .frame { position: relative; width: 100%; aspect-ratio: 4 / 3; }
.thumb img, .thumb svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.thumb img { object-fit: contain; }
.thumb .cap { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; padding: 4px 6px; background: var(--panel); color: var(--muted); }
.thumb .cap span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .badge { position: absolute; top: 4px; right: 4px; font-size: 11px; padding: 0 6px; border-radius: 99px; background: rgba(0, 0, 0, .6); color: #fff; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }

/* stats */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k { font-size: 12px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; }
.card { margin-bottom: 0; }
.card .note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .lbl, svg.chart .val, svg.chart .tick, svg.chart .axis { fill: var(--ink); font-size: 12px; font-family: inherit; }
svg.chart .tick, svg.chart .sub { fill: var(--muted); font-size: 11px; }
svg.chart .axis { fill: var(--muted); }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.heat { aspect-ratio: 4 / 3; background: var(--stage); border-radius: 6px; }
.chartwrap { max-height: 520px; overflow: auto; }
.seglegend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* health */
.healthlist { display: grid; gap: 8px; }
.hrow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.hrow.zero { opacity: .62; }
.hrow .n { font-size: 20px; font-weight: 700; min-width: 2.2em; text-align: right; font-variant-numeric: tabular-nums; }
.hrow.bad .n { color: var(--bad); }
.hrow.warn .n { color: var(--warn); }
.hrow.zero .n { color: var(--ok); }
.hrow .t { font-weight: 600; }
.hrow .d { font-size: 13px; color: var(--muted); }
.hrow .ex { font-size: 12px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.hrow .ex code { font-size: 12px; }

/* eval */
.evalctl { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.kpi.metric .v { font-size: 20px; }
pre.code { background: var(--chip); border-radius: 8px; padding: 10px 12px; overflow: auto; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin: 8px 0; }
details.raw summary { cursor: pointer; font-size: 14px; color: var(--accent); }
table.confusion td.num { min-width: 3em; }
table.confusion td.diag { font-weight: 700; color: var(--tp); }
table.confusion td.off { color: var(--fp); }

/* export */
.exportopts { display: flex; gap: 16px; flex-wrap: wrap; margin: 10px 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; display: grid; gap: 6px; min-width: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
#expPredsWrap { margin: 0 0 10px; }

.notes summary { cursor: pointer; font-weight: 600; }
.notes ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.notes li { margin-bottom: 6px; }
.notes li strong { color: var(--ink); }
.foot { max-width: 1400px; margin: 0 auto; padding: 0 20px 30px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
  .filters details:not([open]) { padding-bottom: 0; }
}
@media (max-width: 720px) {
  .slots { grid-template-columns: minmax(0, 1fr); }
  .loader:not(.compact) { display: flex; flex-direction: column; }
  .loader:not(.compact) .loadfoot { order: -1; margin: 0 0 12px; }
  .wrap { padding: 16px 16px 30px; }
  .topbar { padding: 8px 16px; }
  .freebadge { display: none; }
  h1 { font-size: 24px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 12px; }
  .progress .bar { flex-basis: 120px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hrow { grid-template-columns: auto minmax(0, 1fr); }
  .hrow > button { grid-column: 1 / -1; justify-self: start; }
  .foot { padding: 0 16px 24px; }
}
@media (max-width: 420px) {
  .backlink, .sep { display: none; }
}
