:root {
  color-scheme: light;
  --bg: #f1f3f2;
  --surface: #ffffff;
  --surface-muted: #f7f8f7;
  --ink: #18201d;
  --muted: #65716c;
  --line: #d5dbd8;
  --line-strong: #abb6b1;
  --teal: #087263;
  --teal-soft: #dcefe9;
  --blue: #2c6590;
  --blue-soft: #dce9f3;
  --amber: #a9650b;
  --amber-soft: #f6e7c7;
  --red: #a44840;
  --red-soft: #f3deda;
  --violet: #6f5a8d;
  --focus: #2c6590;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-header {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 13px 40px;
  background: #1c2521;
  color: #f6f8f7;
  border-bottom: 3px solid var(--amber);
}

.brand-lockup { min-width: 0; display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border: 1px solid #5c6a64;
  background: #29342f;
  color: #f4c26c;
  font: 800 1.3rem/1 Georgia, serif;
}

.eyebrow, .section-label {
  margin: 0 0 4px;
  color: #5d6964;
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.app-header .eyebrow { color: #aeb9b4; }
h1 { margin: 0; font-size: 1.48rem; line-height: 1.15; letter-spacing: 0; }
h2 { margin: 0; font-size: 1.04rem; line-height: 1.42; letter-spacing: 0; }

.dataset-state {
  max-width: 48%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  color: #d6ddda;
  font-size: 0.8rem;
  text-align: right;
}
.status-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #72b39d; }
.status-dot.pending { background: #e0a64f; }
.status-dot.error { background: #df756d; }

.icon-button {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #53615b;
  border-radius: 5px;
  background: #2c3833;
  color: #fff;
  font-size: 1.05rem;
  line-height: 1;
}
.icon-button:hover { background: #3a4741; }
.icon-button.light { border-color: var(--line-strong); background: var(--surface); color: #31403a; }
.icon-button.light:hover { background: #e9eeeb; }
.icon-button:disabled { cursor: default; opacity: 0.42; }

main { width: min(1560px, 100%); margin: 0 auto; padding: 18px 36px 48px; }

.control-band {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(360px, 1.5fr) auto;
  align-items: end;
  gap: 13px;
  padding: 12px 14px;
  background: #e5eae7;
  border: 1px solid var(--line);
  border-radius: 4px;
}

label > span {
  display: block;
  margin-bottom: 6px;
  color: #47534e;
  font-size: 0.74rem;
  font-weight: 750;
}

input[type="search"], select {
  width: 100%;
  min-height: 39px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}

.nav-controls { display: flex; align-items: center; gap: 7px; }
.text-button {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: #33423c;
  font-weight: 700;
}
.text-button:hover { background: #e9eeeb; }

.trend-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 14px 0 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.trend-filter {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: #45514c;
  font-size: 0.79rem;
  font-weight: 750;
}
.trend-filter:last-child { border-right: 0; }
.trend-filter:hover { background: #f1f4f2; color: var(--ink); }
.trend-filter.active { box-shadow: inset 0 -3px currentColor; background: #edf2ef; color: var(--teal); }
.trend-filter[data-trend="mostly_increasing"].active { color: var(--teal); background: var(--teal-soft); }
.trend-filter[data-trend="flat"].active { color: var(--blue); background: var(--blue-soft); }
.trend-filter[data-trend="mostly_decreasing"].active { color: var(--red); background: var(--red-soft); }
.trend-filter[data-trend="mixed"].active { color: var(--violet); background: #ebe5f2; }
.trend-count { font-variant-numeric: tabular-nums; color: inherit; }
.trend-label { min-width: 0; overflow-wrap: anywhere; }

.message-state {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: var(--muted);
  text-align: center;
}
.message-state[hidden] { display: none; }
.message-state.error { color: var(--red); }
.loader { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.trajectory-heading {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--line-strong);
}
.heading-copy { min-width: 0; }
.heading-copy h2 { max-width: 1050px; font-size: 1.12rem; overflow-wrap: anywhere; }

.segmented-control { flex: 0 0 auto; display: flex; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; background: var(--surface); }
.segment {
  min-height: 38px;
  padding: 7px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: #4b5752;
  font-size: 0.78rem;
  font-weight: 750;
}
.segment:last-child { border-right: 0; }
.segment:hover { background: #f0f3f1; }
.segment.active { background: #26342e; color: #fff; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 15px 0;
  border: 1px solid var(--line);
  background: var(--surface);
}
.summary-item { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.69rem; font-weight: 750; text-transform: uppercase; }
.summary-item strong { display: block; min-height: 24px; font-size: 1.08rem; line-height: 1.35; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.trend-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 0.84rem !important; }
.trend-badge::before { content: ""; width: 9px; height: 9px; background: currentColor; }
.trend-badge.mostly-increasing { color: var(--teal); }
.trend-badge.flat { color: var(--blue); }
.trend-badge.mostly-decreasing { color: var(--red); }
.trend-badge.mixed { color: var(--violet); }

.distribution-section, .chart-section, .detail-section {
  margin-top: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.section-heading {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 15px;
  border-bottom: 1px solid var(--line);
}
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 13px; color: var(--muted); font-size: 0.72rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-swatch { width: 12px; height: 3px; display: inline-block; background: var(--teal); }
.legend-swatch.interval { height: 10px; border-left: 2px solid var(--blue); border-right: 2px solid var(--blue); background: var(--blue-soft); }
.legend-swatch.final { width: 9px; height: 9px; transform: rotate(45deg); background: var(--amber); }

.distribution-stats { display: flex; align-items: stretch; border: 1px solid var(--line); background: var(--surface-muted); }
.distribution-stat { min-width: 105px; padding: 7px 11px; border-right: 1px solid var(--line); }
.distribution-stat:last-child { border-right: 0; }
.distribution-stat span { display: block; color: var(--muted); font-size: 0.62rem; font-weight: 750; text-transform: uppercase; }
.distribution-stat strong { display: block; margin-top: 2px; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.distribution-chart { position: relative; width: 100%; height: 270px; padding: 8px 10px 0; overflow: hidden; }
.distribution-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.distribution-bar { fill: var(--teal); stroke: #056154; stroke-width: 1; vector-effect: non-scaling-stroke; }
.distribution-bar:hover { fill: #0a8d79; }
.distribution-bar:focus { outline: none; }
.distribution-bar:focus-visible { fill: #0a8d79; stroke: #18201d; stroke-width: 3; }
.distribution-mean { stroke: var(--amber); stroke-width: 2; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.distribution-mean-label { fill: #85500a; font-size: 11px; font-family: inherit; font-weight: 750; }

.value-chart { position: relative; width: 100%; height: 390px; padding: 8px 10px 0; overflow: hidden; }
.value-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-grid-line { stroke: #dfe4e1; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axis { stroke: #8f9a95; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke: #31443d; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.ci-line, .ci-cap { stroke: var(--blue); stroke-width: 1.5; vector-effect: non-scaling-stroke; opacity: 0.8; }
.mc-point { fill: var(--teal); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; }
.final-point { fill: var(--amber); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; }
.point-hit-area { fill: transparent; pointer-events: all; }
.chart-point-target:focus { outline: none; }
.chart-point-target:focus-visible .mc-point,
.chart-point-target:focus-visible .final-point { stroke: #18201d; stroke-width: 4; }
.selected-point { fill: none; stroke: #1f2925; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.chart-label { fill: #65716c; font-size: 12px; font-family: inherit; }
.chart-label.strong { fill: #34413c; font-weight: 750; }
.chart-tooltip {
  position: absolute;
  z-index: 4;
  width: max-content;
  max-width: 245px;
  padding: 8px 10px;
  border: 1px solid #85928c;
  border-radius: 4px;
  background: #1f2925;
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 4px 14px rgb(24 32 29 / 18%);
}

.chart-footer { display: grid; grid-template-columns: minmax(280px, 0.75fr) minmax(380px, 1.25fr); border-top: 1px solid var(--line); }
.point-summary { min-height: 126px; padding: 14px 16px; border-right: 1px solid var(--line); }
.point-title { margin-bottom: 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.point-title strong { font-size: 0.95rem; }
.point-value { color: var(--teal); font-size: 1.25rem !important; font-variant-numeric: tabular-nums; }
.point-summary.final .point-value { color: var(--amber); }
.point-detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.point-detail-grid span { display: block; color: var(--muted); font-size: 0.66rem; font-weight: 700; text-transform: uppercase; }
.point-detail-grid strong { display: block; margin-top: 3px; font-size: 0.8rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.score-histogram { min-height: 126px; display: grid; grid-template-columns: repeat(10, minmax(16px, 1fr)); align-items: end; gap: 5px; padding: 18px 18px 12px; }
.hist-bin { min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 92px; }
.hist-bar { width: 100%; min-height: 2px; background: var(--teal); border: 1px solid #056154; }
.hist-bin.final .hist-bar { background: var(--amber); border-color: #8a5108; }
.hist-label { color: var(--muted); font-size: 0.62rem; font-variant-numeric: tabular-nums; }

.detail-tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.detail-tab {
  position: relative;
  min-width: 116px;
  padding: 11px 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}
.detail-tab:hover { background: #f2f5f3; color: var(--ink); }
.detail-tab.active { color: var(--teal); }
.detail-tab.active::after { content: ""; position: absolute; right: 12px; bottom: 0; left: 12px; height: 3px; background: var(--teal); }

.detail-toolbar { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 7px 13px; border-bottom: 1px solid var(--line); background: var(--surface-muted); color: var(--muted); font-size: 0.74rem; }
.point-stepper { display: flex; align-items: center; gap: 9px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.detail-content { min-height: 330px; max-height: 650px; overflow: auto; padding: 18px 20px 28px; font: 0.86rem/1.62 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-content .reasoning-past { color: #34413c; }
.detail-content .reasoning-current { background: var(--amber-soft); color: #33260f; box-shadow: 0 0 0 2px var(--amber-soft); }
.detail-content .reasoning-future { color: #626f6a; }
.terminal-answer-label { display: block; margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--amber); font-family: inherit; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; }
.terminal-answer { display: block; margin-top: 8px; color: var(--ink); }

.methodology { margin-top: 15px; border: 1px solid var(--line); background: #e7ece9; }
.methodology summary { padding: 11px 14px; cursor: pointer; color: #3d4944; font-size: 0.76rem; font-weight: 750; }
.methodology > div { padding: 0 14px 14px; color: var(--muted); font-size: 0.78rem; line-height: 1.6; }
.methodology p { margin: 8px 0 0; }

@media (max-width: 980px) {
  .app-header { padding-right: 22px; padding-left: 22px; }
  main { padding-right: 18px; padding-left: 18px; }
  .control-band { grid-template-columns: 1fr 1.45fr; }
  .nav-controls { grid-column: 1 / -1; justify-content: flex-end; }
  .trend-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trend-filter { border-bottom: 1px solid var(--line); }
  .trend-filter:first-child { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .summary-item:nth-child(3) { border-right: 0; }
  .summary-item:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .chart-footer { grid-template-columns: 1fr; }
  .point-summary { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .app-header { min-height: 70px; padding: 11px 14px; }
  .brand-mark { width: 36px; height: 36px; flex-basis: 36px; }
  h1 { font-size: 1.18rem; }
  .app-header .eyebrow { display: none; }
  .dataset-state { max-width: 42%; }
  #dataset-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  main { padding: 12px 10px 36px; }
  .control-band { grid-template-columns: 1fr; }
  .nav-controls { grid-column: auto; justify-content: space-between; }
  .text-button { flex: 1; }
  .trend-strip { margin-top: 10px; }
  .trend-filter { min-height: 48px; padding: 7px 9px; }
  .trajectory-heading { align-items: stretch; flex-direction: column; }
  .segmented-control { align-self: stretch; }
  .segment { flex: 1; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item, .summary-item:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .summary-item:nth-child(even) { border-right: 0; }
  .summary-item:last-child { grid-column: 1 / -1; border-right: 0; border-bottom: 0; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .distribution-stats { width: 100%; }
  .distribution-stat { min-width: 0; flex: 1; padding-right: 7px; padding-left: 7px; }
  .distribution-chart { height: 240px; padding-right: 2px; padding-left: 2px; }
  .chart-legend { justify-content: flex-start; }
  .value-chart { height: 330px; padding-right: 2px; padding-left: 2px; }
  .point-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .score-histogram { gap: 2px; padding-right: 8px; padding-left: 8px; }
  .hist-label { font-size: 0.56rem; }
  .detail-tab { min-width: 96px; }
  .detail-toolbar { align-items: flex-start; flex-direction: column; }
  .detail-content { min-height: 280px; padding: 14px 12px 24px; }
}
