/* LLM Timeline — theme-aware styling.
   Palette tokens follow the dataviz reference palette (light/dark selected). */

:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --surface-2:       #f2f1ec;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --shadow:          rgba(11, 11, 11, 0.08);
  --shadow-lg:       rgba(11, 11, 11, 0.16);

  /* categorical slots 1..8 */
  --series-1: #2a78d6; /* blue   */
  --series-2: #008300; /* green  */
  --series-3: #e87ba4; /* magenta*/
  --series-4: #eda100; /* yellow */
  --series-5: #1baf7a; /* aqua   */
  --series-6: #eb6834; /* orange */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red    */

  --radius:    12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark values are declared under both scopes: the media query covers the OS
   setting, the [data-theme] scope covers the in-page toggle, which must win
   both ways. (See dataviz palette reference.) */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #1a1a19;
    --surface-2:      #232320;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --shadow:         rgba(0, 0, 0, 0.5);
    --shadow-lg:      rgba(0, 0, 0, 0.7);
    --series-1: #3987e5;
    --series-2: #008300;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #1a1a19;
  --surface-2:      #232320;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --shadow:         rgba(0, 0, 0, 0.5);
  --shadow-lg:      rgba(0, 0, 0, 0.7);
  --series-1: #3987e5;
  --series-2: #008300;
  --series-3: #d55181;
  --series-4: #c98500;
  --series-5: #199e70;
  --series-6: #d95926;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }

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

/* ============================ header ============================ */
header.app {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand { margin-right: auto; }
.brand h1 {
  font-size: 19px;
  margin: 0;
  letter-spacing: -0.015em;
  font-weight: 620;
}
.brand .subtitle {
  color: var(--text-secondary);
  font-size: 12.5px;
  margin: 1px 0 0;
}

/* ============================ controls ============================ */
button { font: inherit; cursor: pointer; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 10px;
}
.tab-btn {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 7px;
  padding: 6px 16px;
  font-weight: 500;
  transition: color 0.12s ease, background 0.12s ease;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 3px var(--shadow);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 34px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 15px;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--baseline); }

.ghost-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12.5px;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.ghost-btn:hover { color: var(--text-primary); border-color: var(--baseline); }

/* one filter row, above everything it scopes */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  padding: 11px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.filters .spacer { flex: 1 1 auto; }
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-group .label {
  color: var(--text-muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--page);
  transition: border-color 0.12s ease;
}
.field:focus-within { border-color: var(--series-1); }
.field-icon { color: var(--text-muted); font-size: 14px; }
.field input {
  font: inherit;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--text-primary);
  min-width: 190px;
}
.field input:focus { outline: none; }
.field input::-webkit-search-cancel-button { cursor: pointer; }

.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.chip:hover { color: var(--text-primary); border-color: var(--baseline); }
.chip .dot-key {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  transition: opacity 0.12s ease;
}
.chip.active {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--baseline);
}
.chip.active .dot-key { opacity: 1; }

.segmented {
  display: flex;
  padding: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.seg {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 12.5px;
  transition: color 0.12s ease, background 0.12s ease;
}
.seg:hover { color: var(--text-primary); }
.seg.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px var(--shadow);
}

.count {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ============================ layout ============================ */
main { padding: 20px 24px 48px; }
.view { display: none; }
.view.active { display: block; }

.timeline-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 980px) {
  .timeline-wrap { grid-template-columns: minmax(0, 1fr); }
}
.timeline-panel { min-width: 0; }

/* ---- legends ---- */
.legend-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin: 0 2px 10px;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.legend .item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .swatch.round { border-radius: 50%; }
.legend .swatch.line { width: 14px; height: 2.5px; border-radius: 2px; }
.legend .legend-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}
.legend .swatch.hollow { background: none !important; border: 1.5px solid var(--baseline); }

/* ---- timeline: fixed label column + horizontally scrolling plot ---- */
.tl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.tl-labels {
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  z-index: 2;
}
.tl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 0;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: default;
  transition: background 0.1s ease, color 0.1s ease;
}
.tl-row .region-bar {
  width: 3px;
  height: 60%;
  border-radius: 2px;
  margin-left: 8px;
  flex: none;
}
.tl-row .lab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 148px;
}
.tl-row .lab-count {
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  padding-left: 8px;
}
.tl-row.hot { background: var(--surface-2); color: var(--text-primary); }
.tl-row.spacer-row { pointer-events: none; }

.chart-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--baseline) transparent;
}
.chart-scroll::-webkit-scrollbar { height: 8px; }
.chart-scroll::-webkit-scrollbar-track { background: transparent; }
.chart-scroll::-webkit-scrollbar-thumb {
  background: var(--baseline);
  border-radius: 4px;
}
svg { display: block; }
svg text { font-family: var(--font); }

/* Marks take no pointer events — the per-row nearest-point band below handles
   the mouse, so overlapping dots can never occlude one another. */
.mark { pointer-events: none; outline: none; }
.dot { transition: stroke-width 0.1s ease; }
.row-hit { fill: transparent; cursor: pointer; }
.mark.dim { opacity: 0.1; }
.mark.hot .dot { stroke: var(--text-primary); stroke-width: 2; }
.mark.selected .dot { stroke: var(--text-primary); stroke-width: 2.5; }
.mark:focus .dot { stroke: var(--text-primary); stroke-width: 2.5; }

.hint {
  color: var(--text-muted);
  font-size: 11.5px;
  margin: 10px 2px 0;
}
kbd {
  font: inherit;
  font-size: 10.5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  background: var(--surface-2);
  color: var(--text-secondary);
}

/* ---- empty state ---- */
.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ============================ detail panel ============================ */
.detail {
  position: sticky;
  top: 84px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px 20px;
  max-height: calc(100vh - 108px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--baseline) transparent;
}
.detail .placeholder { color: var(--text-muted); margin: 0; }
.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 2px;
}
.detail h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.015em;
  line-height: 1.25;
  flex: 1;
}
.close-btn {
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
  flex: none;
}
.close-btn:hover { color: var(--text-primary); background: var(--surface-2); }

.detail .lab-line { color: var(--text-secondary); font-size: 13px; }
.detail .badges { display: flex; gap: 5px; flex-wrap: wrap; margin: 12px 0 4px; }
.badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge.key { display: inline-flex; align-items: center; gap: 5px; }
.badge.key::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--key-color, var(--text-muted));
}

.kv {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 6px 12px;
  margin: 16px 0;
  font-size: 13px;
}
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.section-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 18px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--grid);
}

/* benchmark rows: label, meter, value */
.bench-list { display: grid; gap: 9px; font-size: 12.5px; }
.bench-list > .b-cat {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}
.bench-list > .b-cat:first-child { margin-top: 0; }
.bench-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; align-items: baseline; }
.bench-row .b-name { color: var(--text-secondary); }
.bench-row .b-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
}
.bench-row .b-track {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.bench-row .b-fill { height: 100%; border-radius: 3px; background: var(--series-1); }

.notes {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin: 10px 0 0;
}
.sources { display: grid; gap: 5px; }
.sources a {
  font-size: 12px;
  overflow-wrap: anywhere;
  color: var(--series-1);
  text-decoration: none;
}
.sources a:hover { text-decoration: underline; }

/* ============================ stats ============================ */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 16px;
}
.tile .num {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.tile.hero .num { font-size: 48px; }
.tile .lbl { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.tile .sub { color: var(--text-secondary); font-size: 11.5px; margin-top: 5px; }

/* Multi-column packing rather than a grid: cards vary a lot in height and a
   row-based grid leaves large holes under the short ones. */
.stats-grid {
  column-width: 340px;
  column-gap: 16px;
}
@media (min-width: 1600px) { .stats-grid { column-count: 4; } }
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px 14px;
  min-width: 0;
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 16px;
}
.card h3 { margin: 0; font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.card .card-sub { color: var(--text-muted); font-size: 11.5px; margin: 2px 0 12px; }
/* No inner scroll: a fixed height slices the last row in half, and the column
   layout already absorbs cards of very different heights. */
.card .scroll-y { overflow: visible; }

/* table-view twin — every chart's values reachable without hovering */
.card details {
  margin-top: 12px;
  border-top: 1px solid var(--grid);
  padding-top: 8px;
}
.card summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--text-muted);
  list-style: none;
}
.card summary::-webkit-details-marker { display: none; }
.card summary::before { content: "▸ "; }
.card details[open] summary::before { content: "▾ "; }
.card summary:hover { color: var(--text-primary); }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td {
  text-align: right;
  padding: 3px 6px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--text-muted); font-weight: 600; }
.table-wrap { max-height: 240px; overflow: auto; scrollbar-width: thin; }

.bar:hover, .mark-hit:hover { opacity: 0.82; }
.mark-hit { cursor: default; }

/* ============================ tooltip ============================ */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--baseline);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 12px;
  box-shadow: 0 8px 26px var(--shadow-lg);
  max-width: 280px;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.1s ease;
}
.tooltip .t-name { font-weight: 600; margin-bottom: 2px; }
.tooltip .t-sub { color: var(--text-secondary); font-size: 11.5px; }
.tooltip .t-rows { display: grid; gap: 3px; margin-top: 6px; }
.tooltip .t-row { display: flex; align-items: center; gap: 7px; }
.tooltip .t-key { width: 12px; height: 2.5px; border-radius: 2px; flex: none; }
.tooltip .t-label { color: var(--text-secondary); flex: 1; }
.tooltip .t-value { font-weight: 600; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
