/* perf-ab history: a quiet, read-only engineering console. Light by default, dark via system preference. */

:root {
  color-scheme: light dark;
  --bg: oklch(98.4% 0.003 250);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(96.6% 0.005 250);
  --surface-3: oklch(93.8% 0.007 250);
  --line: oklch(90.5% 0.008 250);
  --line-strong: oklch(83% 0.01 250);
  --ink: oklch(23% 0.015 255);
  --ink-2: oklch(42% 0.015 255);
  --ink-3: oklch(54% 0.012 255);
  --accent: oklch(50% 0.16 255);
  --accent-soft: oklch(95.5% 0.025 255);
  --ok: oklch(48% 0.12 155);
  --ok-soft: oklch(95.5% 0.03 155);
  --bad: oklch(50% 0.17 25);
  --bad-soft: oklch(96% 0.025 25);
  --warn: oklch(50% 0.11 70);
  --warn-soft: oklch(96.5% 0.04 85);
  --before: oklch(55% 0.02 255);
  --after: oklch(40% 0.12 255);
  --radius: 6px;
  --radius-sm: 4px;
  --topbar: 52px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(18.5% 0.01 255);
    --surface: oklch(21.5% 0.011 255);
    --surface-2: oklch(24.5% 0.012 255);
    --surface-3: oklch(28.5% 0.013 255);
    --line: oklch(31% 0.012 255);
    --line-strong: oklch(39% 0.014 255);
    --ink: oklch(93% 0.006 255);
    --ink-2: oklch(78% 0.01 255);
    --ink-3: oklch(66% 0.012 255);
    --accent: oklch(74% 0.12 255);
    --accent-soft: oklch(30% 0.05 255);
    --ok: oklch(76% 0.13 155);
    --ok-soft: oklch(28% 0.04 155);
    --bad: oklch(74% 0.14 25);
    --bad-soft: oklch(29% 0.05 25);
    --warn: oklch(80% 0.12 80);
    --warn-soft: oklch(30% 0.045 80);
    --before: oklch(68% 0.02 255);
    --after: oklch(78% 0.11 255);
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, dl, dd, ul, figure { margin: 0; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in oklch, currentColor 40%, transparent);
}

a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.num { text-align: right; white-space: nowrap; }
.sub { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.4; }
.sub-line { margin-top: 2px; }
.break { overflow-wrap: anywhere; }
.unlinked { color: var(--ink-2); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 20;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { display: block; flex: none; }
.brand h1 { font-size: 16px; font-weight: 620; letter-spacing: -0.01em; white-space: nowrap; }
.brand-repo { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.topbar-meta { margin-left: auto; color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.topbar-nav a { font-size: 13px; white-space: nowrap; }

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: minmax(520px, 44%) minmax(0, 1fr);
    align-items: start;
  }
  .history {
    position: sticky;
    top: var(--topbar);
    height: calc(100dvh - var(--topbar));
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: var(--surface);
  }
  .history-body { flex: 1; overflow: auto; overscroll-behavior: contain; }
  .back { display: none; }
}

@media (max-width: 1023.98px) {
  .layout[data-view="list"] .detail { display: none; }
  .layout[data-view="detail"] .history { display: none; }
  .history { background: var(--surface); min-height: calc(100dvh - var(--topbar)); }
}

/* ------------------------------------------------------------------ history column */

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 8px;
}
.history-head h2 { font-size: 18px; font-weight: 620; letter-spacing: -0.01em; }
.history-count { color: var(--ink-3); font-size: 13px; }

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 4px 16px 14px;
  border-bottom: 1px solid var(--line);
}

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; grid-column: span 2; }
.field-q { grid-column: span 4; }
.field-profile { grid-column: span 2; }
.field-actions { justify-content: flex-end; }
.field-label { font-size: 12px; color: var(--ink-2); }

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

input[type="search"], input[type="date"], select {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  transition: border-color 150ms var(--ease);
}
input:hover, select:hover { border-color: var(--ink-3); }
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 520;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:disabled { cursor: default; color: var(--ink-3); background: transparent; border-color: var(--line); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); }
.btn-quiet:hover { background: var(--accent-soft); border-color: transparent; }
.btn-quiet:disabled { border-color: transparent; }

.state, .empty { padding: 20px 16px; display: grid; gap: 10px; justify-items: start; }
.empty { padding: 40px 16px; max-width: 46ch; }
.empty-title { font-size: 16px; font-weight: 600; }
.empty p:not(.empty-title) { color: var(--ink-2); }

.skipped {
  margin: 10px 16px 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  font-size: 13px;
}
.skipped summary { cursor: pointer; }
.skipped ul { margin-top: 6px; padding-left: 18px; color: var(--ink-2); }

/* ------------------------------------------------------------------ tables */

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding-top: 7px;
  padding-bottom: 7px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 560;
  white-space: nowrap;
  border-bottom-color: var(--line-strong);
}
table.data th.num, table.data td.num { text-align: right; }
table.data tbody th { font-weight: 560; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table-scroll table.data tbody tr:last-child > * { border-bottom: 0; }
table.compact th, table.compact td { padding: 6px 10px; }

.runs th:first-child, .runs td:first-child { padding-left: 16px; }
.runs th:last-child, .runs td:last-child { padding-right: 16px; }
.run-row { cursor: pointer; transition: background-color 150ms var(--ease); }
.run-row:hover { background: var(--surface-2); }
.run-row.is-selected { background: var(--accent-soft); }
.run-row.is-selected .run-link { font-weight: 600; }
.run-row.is-selected .sub, .run-row.is-selected .weak { color: var(--ink-2); }
.run-link { color: var(--ink); text-decoration: none; white-space: nowrap; }
.run-link:hover { color: var(--accent); text-decoration: underline; }
/* max-width: 0 lets the page column take the leftover width and truncate instead of widening the table. */
.runs .cell-page { width: 100%; max-width: 0; }
.page, .runs .cell-page .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weak { color: var(--ink-3); }

.badges { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 520;
  white-space: nowrap;
}
.badge[data-tone="ok"] { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in oklch, var(--ok) 35%, transparent); }
.badge[data-tone="bad"] { color: var(--bad); background: var(--bad-soft); border-color: color-mix(in oklch, var(--bad) 35%, transparent); }
.badge[data-tone="warn"] { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in oklch, var(--warn) 40%, transparent); }

/* ------------------------------------------------------------------ skeletons */

.history-skeleton { padding: 8px 16px; }
.skeleton-row { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.skeleton-block { display: grid; gap: 8px; padding: 6px 0 18px; }
.skeleton-line {
  display: block;
  height: 10px;
  border-radius: 3px;
  background: var(--surface-3);
  animation: pulse 1.4s ease-in-out infinite;
}
.skeleton-line.w1 { width: 72%; }
.skeleton-line.w2 { width: 46%; }
.skeleton-line.w3 { width: 60%; }
.skeleton-block.head .skeleton-line { height: 16px; }

@keyframes pulse { 50% { opacity: 0.45; } }

@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; }
  *, *::before, *::after { transition-duration: 0s !important; }
}

/* ------------------------------------------------------------------ detail */

.detail { min-width: 0; outline: none; }
.detail-inner { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1040px; padding: 20px 24px 64px; }
.detail-inner > * { min-width: 0; }
.detail-empty { padding: 48px 24px; color: var(--ink-3); }
.back { justify-self: start; margin-left: -8px; }

.detail-head { display: grid; gap: 8px; }
.detail-head h2 { font-size: 22px; font-weight: 640; letter-spacing: -0.015em; line-height: 1.25; overflow-wrap: anywhere; outline: none; }
.detail-sub { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); font-size: 13px; }

.callout {
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.callout + .callout { margin-top: -10px; }
.callout-title { font-weight: 620; }
.callout-body { display: grid; gap: 6px; margin-top: 3px; color: var(--ink-2); }
.callout-body .btn { justify-self: start; margin-top: 4px; }
.callout[data-tone="warn"] { background: var(--warn-soft); border-color: color-mix(in oklch, var(--warn) 45%, transparent); }
.callout[data-tone="warn"] .callout-title { color: var(--warn); }
.callout[data-tone="bad"] { background: var(--bad-soft); border-color: color-mix(in oklch, var(--bad) 40%, transparent); }
.callout[data-tone="bad"] .callout-title { color: var(--bad); }
.error-text { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; color: var(--ink); }
.disclosure { font-size: 12px; color: var(--ink-2); }
.disclosure summary { width: fit-content; cursor: pointer; }
.disclosure-content { display: grid; gap: 4px; margin-top: 4px; }
.disclosure:not([open]) > .disclosure-content { display: none; }
.disclosure-content p { overflow-wrap: anywhere; }

.block { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; }
.block h3 { font-size: 16px; font-weight: 620; letter-spacing: -0.01em; }
.block h4 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.note { color: var(--ink-3); font-size: 12px; max-width: 90ch; }

.medians-content { min-width: 0; max-width: 100%; }
.medians-scroll { width: 100%; min-width: 0; max-width: 100%; }
.medians { min-width: 720px; }
.medians tbody th { white-space: nowrap; }
.metric-short { display: inline-block; min-width: 3.4em; }
.metric-long { color: var(--ink-3); font-weight: 400; font-size: 12px; margin-left: 6px; }
.medians td.delta { font-weight: 600; }
.medians tr[data-verdict="better"] td.delta { color: var(--ok); }
.medians tr[data-verdict="worse"] td.delta { color: var(--bad); }
.verdict { min-width: 150px; }
.verdict-label { font-weight: 560; }
.verdict[data-verdict="better"] .verdict-label { color: var(--ok); }
.verdict[data-verdict="worse"] .verdict-label { color: var(--bad); }
.verdict[data-verdict="inconclusive"] .verdict-label,
.verdict[data-verdict="noise"] .verdict-label { color: var(--ink-2); }

/* ------------------------------------------------------------------ plots */

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--ink-2); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-glyph { display: block; overflow: visible; }

.plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.plot { padding: 10px 12px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.plot figcaption { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.plot-title { font-weight: 600; }
.plot-unit { color: var(--ink-3); font-size: 12px; }
.plot-svg { display: block; width: 100%; height: auto; overflow: visible; }

.gridline { stroke: var(--line); stroke-width: 1; }
.tick, .row-label { fill: var(--ink-3); font-size: 10px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.med-before, .med-after { stroke-width: 1.25; stroke-dasharray: 3 3; }
.med-before { stroke: var(--before); }
.med-after { stroke: var(--after); }
.link { stroke-width: 2; stroke-linecap: round; }
.link.dir-flat { stroke: var(--line-strong); }
.link.dir-better { stroke: color-mix(in oklch, var(--ok) 70%, transparent); }
.link.dir-worse { stroke: color-mix(in oklch, var(--bad) 70%, transparent); }
.dot-before { fill: var(--surface); stroke: var(--before); stroke-width: 1.5; }
.dot-after { fill: var(--after); stroke: var(--surface); stroke-width: 1; }
.pair:hover .dot-before { stroke-width: 2.5; }
.pair:hover .dot-after { stroke: var(--ink); }

/* ------------------------------------------------------------------ per-pair table */

.pairs { min-width: 640px; }
.pairs th.num .th-unit { display: block; color: var(--ink-3); font-weight: 400; font-size: 12px; }
.pairs tbody th, .pairs tbody td { border-bottom: 0; padding-top: 4px; padding-bottom: 4px; }
.pairs tr.pair-start > * { border-top: 1px solid var(--line); padding-top: 8px; }
.pairs tbody tr:first-child > * { border-top: 0; }
.pairs .pair-id { vertical-align: top; white-space: nowrap; }
.pairs .variant { color: var(--ink-2); font-weight: 400; white-space: nowrap; }
.pairs .pair-delta > * { color: var(--ink-2); padding-bottom: 8px; }
.pairs .pair-incomplete td.num { color: var(--ink-3); }
.pairs .missing { font-style: italic; color: var(--ink-3); }
.pairs .job { color: var(--ink-3); font-size: 12px; min-width: 140px; }

/* ------------------------------------------------------------------ changes, provenance */

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.kv-block { min-width: 0; }
.paths { list-style: none; padding: 0; display: grid; gap: 2px; }
.paths li { overflow-wrap: anywhere; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, auto)); gap: 4px 20px; justify-content: start; }
.stats dt { color: var(--ink-3); font-size: 12px; }
.stats dd { text-align: left; font-size: 16px; font-weight: 600; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.kv > div { display: contents; }
.kv dt, .kv dd { padding: 7px 12px; border-bottom: 1px solid var(--line); }
.kv > div:last-child dt, .kv > div:last-child dd { border-bottom: 0; }
.kv dt { color: var(--ink-2); font-size: 13px; background: var(--surface-2); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

tr.is-self > * { background: var(--accent-soft); }
tr.is-self .weak, tr.is-self .sub { color: var(--ink-2); }

.noscript { padding: 24px; }

/* ------------------------------------------------------------------ small screens */

@media (max-width: 1279.98px) and (min-width: 1024px) {
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .field-q { grid-column: span 4; }
  .field { grid-column: span 2; }
  .field-actions { grid-column: span 4; align-items: flex-end; }
}

@media (max-width: 1023.98px) {
  .detail-inner { padding: 12px 16px 48px; }
}

/* Inline padding grows the touch target without changing line layout. */
@media (pointer: coarse) {
  .topbar-nav a, .history a, .detail a:not(.btn), .skipped summary { padding-block: 4px; }
}

@media (max-width: 639.98px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .brand-repo, .topbar-meta { display: none; }
  .topbar-nav { margin-left: auto; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 4px 12px 12px; }
  .field, .field-profile { grid-column: span 1; }
  .field-q, .field-profile, .field-actions { grid-column: span 2; }
  .field-actions { align-items: flex-start; }
  .field-actions .btn { margin-left: -12px; }
  .history-head { padding: 12px 12px 6px; }

  .runs thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .runs, .runs tbody { display: block; }
  .runs tr.run-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px 14px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
  }
  .runs tr.run-row > td { display: block; padding: 0; border: 0; text-align: left; max-width: none; }
  .runs .cell-run, .runs .cell-page, .runs .cell-status { grid-column: 1 / -1; }
  .runs .cell-run { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
  .runs .cell-run .sub { display: inline; }
  .runs td.num { text-align: left; }
  .runs td.num::before {
    content: attr(data-label);
    display: block;
    color: var(--ink-3);
    font-size: 12px;
  }
  .runs td.cell-pairs { grid-column: 1; }
  .runs th:first-child, .runs td:first-child { padding-left: 0; }
  .runs th:last-child, .runs td:last-child { padding-right: 0; }

  .detail-inner { gap: 16px; padding: 8px 12px 40px; }
  .detail-head h2 { font-size: 18px; }
  .metric-long { display: none; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { border-bottom: 0; padding-bottom: 0; background: transparent; font-size: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, auto)); }
}
