:root {
  --bg: #111111;
  --surface: color-mix(in oklch, #ffffff 5%, #111111);
  --fg: #f7f8fa;
  --muted: color-mix(in oklch, #d9dee7 58%, #111111);
  --border: color-mix(in oklch, #d9dee7 17%, #111111);
  --accent: #1677ff;
  --radius: 8px;
  --grid: 8px;
  --font-display: Inter, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-body: Inter, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.006em;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; color: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  background: var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg);
  color: var(--fg);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 48px;
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 8px;
  font-weight: 620;
  letter-spacing: -0.035em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border: 1px solid var(--fg);
  border-radius: 0;
  display: grid;
  place-items: center;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 11px;
}

.nav-list { display: grid; gap: 4px; }

.nav-link {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  transition: color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.nav-link:hover { color: var(--fg); transform: translateX(2px); }
.nav-link.active { color: var(--fg); border-left-color: var(--accent); }

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.sidebar-meta {
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.sidebar-meta strong {
  display: block;
  color: var(--fg);
  font-family: var(--font-mono);
  font-weight: 500;
  margin-bottom: 4px;
}

.main-shell { min-width: 0; }

.topbar {
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(20px, 4vw, 48px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
}
.breadcrumb strong { color: var(--fg); font-weight: 600; }

.top-actions { display: flex; align-items: center; gap: 8px; }

.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
}

.mobile-menu { display: none; }

.page {
  width: min(100%, 1320px);
  margin: 0 auto;
  padding: clamp(28px, 4vw, 56px);
}

.page-heading {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 40px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}

.page-heading::before {
  content: attr(data-index);
  padding-top: 7px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
}

.page-heading::after {
  content: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: -0.04em;
  text-wrap: balance;
}

h1 { margin: 0; font-size: clamp(32px, 4.2vw, 52px); line-height: 1; font-weight: 480; }
h2 { margin: 0; font-size: clamp(20px, 2vw, 26px); line-height: 1.12; font-weight: 520; }
h3 { margin: 0; font-size: 15px; line-height: 1.35; }

.lede {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-weight: 620;
  letter-spacing: -0.012em;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:hover { border-color: var(--muted); background: var(--surface); }
.button:active { transform: translateY(1px); }
.button:disabled { cursor: wait; opacity: .72; transform: none; }
.button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.button.primary:hover { background: #ffffff; border-color: #ffffff; }
.button.dark { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.button.ghost { border-color: transparent; background: transparent; }
.button.small { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.button svg { width: 16px; height: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.card-body { padding: 20px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.metric {
  min-height: 148px;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
}
.metric:last-child { border-right: 0; }

.metric-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.metric-value { font-family: var(--font-mono); font-size: clamp(30px, 4vw, 44px); font-weight: 420; letter-spacing: -0.07em; }
.metric-foot { color: var(--muted); font-size: 12px; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 40px 0 14px;
}

.section-head p { margin: 4px 0 0; color: var(--muted); }

.set-list {
  display: grid;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}
.set-list { counter-reset: saved-set; }

.set-row {
  min-height: 76px;
  display: grid;
  grid-template-columns: 42px minmax(220px, 1.5fr) minmax(130px, .7fr) minmax(120px, .55fr) 120px;
  gap: 16px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 120ms ease;
  counter-increment: saved-set;
}

.set-row::before {
  content: "0" counter(saved-set);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .04em;
}

.set-row:last-child { border-bottom: 0; }
.set-row:hover { background: color-mix(in oklch, var(--fg) 4%, transparent); }
.set-name { font-weight: 650; letter-spacing: -0.018em; }
.set-query { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.subtle { color: var(--muted); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.status.live { color: var(--fg); }
.status.live::before { background: var(--accent); box-shadow: none; }

.search-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, .55fr);
  gap: 24px;
  align-items: start;
}

.form-stack { display: grid; gap: 20px; }
.field { display: grid; gap: 8px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field label, .label { font-size: 12px; font-weight: 650; }
.field-help { color: var(--muted); font-size: 12px; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in oklch, var(--fg) 3%, var(--bg));
  padding: 10px 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input, select { min-height: 40px; }
textarea { min-height: 132px; resize: vertical; line-height: 1.5; }
input:hover, textarea:hover, select:hover { border-color: var(--muted); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 12%, transparent); outline: none; }

.range-line { display: grid; grid-template-columns: minmax(0, 1fr) 76px; align-items: center; gap: 12px; }
input[type="range"] { appearance: none; height: 4px; min-height: 4px; padding: 0; border: 0; background: var(--border); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent); }

.threshold-readout {
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
}

.quality-note {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.quality-note strong { color: var(--fg); }

.advanced {
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.advanced summary { cursor: pointer; font-weight: 650; }
.advanced-grid { margin-top: 16px; }

.job-card { position: sticky; top: 80px; overflow: hidden; }
.job-hero { padding: 22px; background: transparent; color: var(--fg); border-bottom: 1px solid var(--border); }
.job-hero .eyebrow { color: var(--muted); }
.job-time { margin-top: 20px; font-family: var(--font-mono); font-size: 28px; letter-spacing: -0.04em; }
.progress-track { height: 6px; overflow: hidden; border-radius: 1px; background: var(--border); }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 500ms cubic-bezier(.2,.8,.2,1); }
.progress-meta { margin-top: 8px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }

.job-steps { list-style: none; margin: 0; padding: 8px 20px 16px; }
.job-step {
  min-height: 46px;
  position: relative;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.job-step:last-child { border-bottom: 0; }
.job-step .step-dot { width: 8px; height: 8px; border-radius: 1px; border: 1px solid var(--muted); }
.job-step.active { color: var(--fg); font-weight: 600; }
.job-step.active .step-dot { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklch, var(--accent) 14%, transparent); }
.job-step.done .step-dot { border-color: var(--fg); background: var(--fg); }
.job-step small { font-family: var(--font-mono); font-size: 10px; font-weight: 400; }

.job-idle { padding: 24px 20px; color: var(--muted); }
.job-idle strong { display: block; margin-bottom: 4px; color: var(--fg); }
.job-result { display: none; padding: 16px 20px 20px; border-top: 1px solid var(--border); }
.job-result.show { display: grid; gap: 12px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-inline { min-width: min(380px, 100%); position: relative; }
.search-inline input { padding-left: 36px; }
.search-inline svg { position: absolute; left: 12px; top: 11px; width: 16px; height: 16px; color: var(--muted); }

.filter-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  font-size: 12px;
}
.filter-chip strong { font-family: var(--font-mono); font-weight: 600; }

.results-card {
  overflow: hidden;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}
.results-summary {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.results-summary h2 { font-size: 18px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
tbody tr { cursor: pointer; transition: background 100ms ease; }
tbody tr:hover { background: color-mix(in oklch, var(--fg) 4%, transparent); }
tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tbody tr:last-child td { border-bottom: 0; }
.title-cell { max-width: 560px; font-weight: 600; }
.abstract-line { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sim { text-align: right; font-family: var(--font-mono); font-weight: 650; }

.tier-bar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: transparent;
  color: var(--fg);
  border-top: 1px solid var(--border);
  font-size: 11px;
}
.tier-bar span { color: var(--muted); }
.tier-bar strong { color: var(--fg); font-family: var(--font-mono); font-weight: 600; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  background: color-mix(in oklch, var(--bg) 78%, transparent);
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(620px, 94vw);
  height: 100vh;
  overflow: auto;
  transform: translateX(102%);
  transition: transform 240ms cubic-bezier(.2,.8,.2,1);
  background: var(--surface);
  border-left: 1px solid var(--border);
}
.drawer.open { transform: translateX(0); }
.drawer-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-body { padding: 24px 20px 56px; }
.drawer-title { margin: 10px 0 20px; font-size: 26px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); }
.detail-item { min-height: 78px; padding: 12px; background: var(--surface); }
.detail-item span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.abstract { margin-top: 24px; font-size: 15px; line-height: 1.7; }

.analysis-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); gap: 20px; }
.chart-card { min-height: 420px; }
.chart-toolbar { display: flex; gap: 8px; align-items: center; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.segmented button { min-height: 30px; padding: 4px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.segmented button.active { color: var(--fg); background: color-mix(in oklch, var(--fg) 6%, transparent); border: 1px solid var(--border); }

.bar-chart {
  height: 300px;
  display: grid;
  grid-template-columns: repeat(10, minmax(20px, 1fr));
  align-items: end;
  gap: clamp(5px, 1vw, 12px);
  padding: 28px 8px 0;
  border-bottom: 1px solid var(--border);
}
.bar-column { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 8px; }
.bar {
  width: min(38px, 80%);
  height: var(--value);
  min-height: 4px;
  background: var(--fg);
  border-radius: 0;
  transition: height 500ms cubic-bezier(.2,.8,.2,1), background 120ms ease;
}
.bar-column:hover .bar { background: var(--accent); }
.bar-label { font-family: var(--font-mono); color: var(--muted); font-size: 10px; }
.bar-value { font-family: var(--font-mono); font-size: 10px; }
.bar.estimated { background: repeating-linear-gradient(135deg, var(--border), var(--border) 4px, var(--surface) 4px, var(--surface) 8px); border: 1px solid var(--muted); }

.area-list { display: grid; gap: 16px; }
.area-row { display: grid; gap: 7px; }
.area-meta { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.area-track { height: 7px; border-radius: 999px; background: var(--border); overflow: hidden; }
.area-fill { height: 100%; background: var(--fg); border-radius: inherit; }

.method-note {
  margin-top: 16px;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.method-note strong { color: var(--fg); }

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--fg); font-size: 16px; margin-bottom: 6px; }

.mobile-dock { display: none; }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 80px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand { justify-content: center; padding: 0; }
  .brand span, .nav-link span, .sidebar-meta { display: none; }
  .nav-link { justify-content: center; }
  .search-layout, .analysis-grid { grid-template-columns: 1fr; }
  .job-card { position: static; }
  .set-row { grid-template-columns: 36px minmax(220px, 1.5fr) minmax(100px, .6fr) 110px; }
  .set-row > :nth-child(4) { display: none; }
}

@media (max-width: 720px) {
  body { font-size: 13px; padding-bottom: 68px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { height: 56px; padding: 0 16px; }
  .top-actions .button { display: none; }
  .page { padding: 24px 16px 40px; }
  .page-heading { grid-template-columns: 32px minmax(0, 1fr); margin-bottom: 28px; padding-bottom: 22px; }
  .page-heading > .button { grid-column: 1 / -1; }
  .page-heading .button { width: 100%; }
  .grid-2, .grid-3, .field-row { grid-template-columns: 1fr; }
  .grid-3 { gap: 0; }
  .metric { min-height: 104px; }
  .metric { border-right: 0; border-bottom: 1px solid var(--border); }
  .metric:last-child { border-bottom: 0; }
  .set-row { grid-template-columns: 28px minmax(0, 1fr) auto; padding: 14px; gap: 10px; }
  .set-row > :nth-child(3), .set-row > :nth-child(4) { display: none; }
  .section-head { align-items: flex-start; }
  .search-inline { min-width: 100%; }
  .toolbar, .toolbar-group { align-items: stretch; }
  .toolbar-group { width: 100%; }
  .toolbar-group .button { flex: 1; }
  .results-summary { align-items: flex-start; flex-direction: column; }
  .tier-bar { align-items: flex-start; flex-direction: column; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .chart-card { min-height: 360px; }
  .bar-chart { height: 250px; gap: 4px; padding-inline: 0; overflow: hidden; }
  .bar-value { display: none; }
  .mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: 64px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--bg);
    border-top: 1px solid var(--border);
  }
  .mobile-dock a {
    display: grid;
    place-items: center;
    gap: 2px;
    color: var(--muted);
    font-size: 10px;
  }
  .mobile-dock a.active { color: var(--fg); }
  .mobile-dock svg { width: 18px; height: 18px; }
}

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

/* ---------------------------------------------------------------------------
   Additions for the live app. Kept in one marked block so the design source
   can be re-dropped over the top without hunting for edits.
   --------------------------------------------------------------------------- */

/* set-row gains a delete affordance, so the grid gains a column */
.set-list .set-row { grid-template-columns: 42px minmax(220px, 1.5fr) minmax(130px, .7fr) minmax(120px, .55fr) 110px 40px; }
.set-list .set-row .button.ghost { opacity: 0; transition: opacity 120ms ease; padding: 4px; min-height: 28px; }
.set-list .set-row:hover .button.ghost { opacity: .7; }
.set-list .set-row .button.ghost:hover { opacity: 1; color: var(--danger, #e2585a); }
.set-list .set-row .button.ghost svg { width: 15px; height: 15px; }

/* sortable headers */
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--fg); }
th[data-sort].active::after { content: " ▾"; }

/* set picker sits in the topbar next to the actions */
.top-actions select { min-height: 32px; max-width: 220px; font-size: 12px; }

/* charts are data-driven now, so the column count cannot be fixed at ten */
.bar-chart { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(12px, 1fr); }
.bar-chart .bar-label { font-size: 9px; }

/* the pager reuses tier-bar, but needs its controls grouped */
[data-pager] .toolbar-group { gap: 6px; }
[data-pager] .button[disabled] { opacity: .35; pointer-events: none; }

/* threshold consequence line, shown wherever a cut is chosen */
[data-threshold-hint] { margin: -6px 0 16px; }
[data-threshold-hint]:empty { display: none; }
