:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --text: #101820;
  --muted: #68737e;
  --line: #dde2e6;
  --line-dark: #cbd2d8;
  --accent: #205e91;
  --positive: #17714a;
  --negative: #9b3937;
  --shadow: 0 7px 22px rgba(16, 24, 32, .045);
  --c1: #205e91;
  --c2: #7f8f9d;
  --c3: #9a594a;
  --c4: #6f668f;
  --c5: #5f8065;
  --c6: #ad7c43;
  --c7: #4f7780;
  --c8: #8c6e78;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 64px; }
.site-nav { display: flex; gap: 18px; margin-bottom: 30px; border-bottom: 1px solid var(--line); }
.site-nav a { position: relative; padding: 0 1px 10px; color: var(--muted); font-size: .86rem; font-weight: 650; }
.site-nav a[aria-current="page"] { color: var(--text); }
.site-nav a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }
.masthead, .analysis-head, .chart-head, .card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.masthead { align-items: flex-start; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2.15rem, 5vw, 3.55rem); line-height: 1; letter-spacing: -.045em; }
h2 { margin-bottom: 4px; font-size: clamp(1.55rem, 3.5vw, 2.15rem); letter-spacing: -.035em; }
h3 { margin: 0; font-size: 1.04rem; letter-spacing: -.015em; }
.subtitle { max-width: 760px; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; }
.kicker, .metric-label, .control-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .69rem; font-weight: 760; letter-spacing: .12em; text-transform: uppercase; }
.button { border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 9px 13px; cursor: pointer; box-shadow: var(--shadow); color: var(--text); }
.button:hover { border-color: var(--line-dark); }
.button:disabled { opacity: .55; cursor: wait; }
.button-small { padding: 7px 11px; font-size: .8rem; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 10px; margin: 22px 0 25px; color: var(--muted); font-size: .86rem; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #c08b26; box-shadow: 0 0 0 4px rgba(192,139,38,.11); }
.status-dot.ok { background: #24805a; box-shadow: 0 0 0 4px rgba(36,128,90,.11); }
.status-dot.error { background: #b44843; box-shadow: 0 0 0 4px rgba(180,72,67,.11); }
.muted { color: var(--muted); }

.control-card, .headline-card, .chart-card, .table-card { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.control-card { display: grid; grid-template-columns: auto auto 1fr; gap: 18px 26px; align-items: end; padding: 14px 16px; }
.control-block { min-width: 0; }
.range-block { justify-self: end; }
.segmented { display: inline-flex; gap: 2px; border: 1px solid var(--line); border-radius: 9px; padding: 3px; background: #f8f9fa; }
.segmented button { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 6px 9px; font-size: .76rem; font-weight: 720; cursor: pointer; white-space: nowrap; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(16,24,32,.12); }

#dashboard { display: grid; gap: 14px; margin-top: 30px; }
.analysis-head { align-items: flex-end; padding: 2px 1px 0; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 5px; min-height: 22px; margin-bottom: 3px; color: var(--muted); font-size: .78rem; }
.breadcrumbs button { border: 0; padding: 0; background: transparent; color: var(--accent); cursor: pointer; }
.breadcrumbs button:hover { text-decoration: underline; }
.breadcrumb-sep { color: #a4adb4; }
#seriesMeta { font-size: .79rem; }
.headline-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.headline-card { position: relative; overflow: hidden; padding: 16px 17px; }
.headline-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.headline-card > strong { display: block; font-size: 1.9rem; letter-spacing: -.04em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.card-sub { display: block; margin-top: 4px; color: var(--muted); font-size: .74rem; }

.chart-card { padding: 16px 18px 12px; }
.chart-head { margin-bottom: 8px; }
.pill { display: inline-block; border: 1px solid var(--line); border-radius: 99px; padding: 5px 9px; color: var(--muted); background: #fafbfb; font-size: .72rem; white-space: nowrap; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 7px 14px; min-height: 22px; margin: 4px 0 2px; color: var(--muted); font-size: .74rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; border: 0; padding: 0; background: transparent; color: inherit; cursor: pointer; }
.legend-item:hover { color: var(--text); }
.legend-swatch { width: 13px; height: 7px; border-radius: 2px; opacity: .8; }
.driver-chart { width: 100%; min-height: 310px; touch-action: pan-y; }
.driver-chart svg { display: block; width: 100%; height: auto; min-height: 280px; overflow: visible; }
.grid-line { stroke: #e7ebee; stroke-width: 1; vector-effect: non-scaling-stroke; }
.zero-line { stroke: #aeb6bd; stroke-width: 1; vector-effect: non-scaling-stroke; }
.axis-label { fill: #68737e; font-size: 12px; font-weight: 500; }
.stack-area { opacity: .72; }
.parent-line { fill: none; stroke: #101820; stroke-width: 2.1; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.crosshair { stroke: #7c8790; stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.chart-dot { fill: #101820; stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.chart-tooltip-bg { fill: #101820; opacity: .94; }
.chart-tooltip-text { fill: #fff; font-size: 12px; font-weight: 600; pointer-events: none; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-empty { display: grid; place-items: center; min-height: 285px; color: var(--muted); font-size: .88rem; text-align: center; padding: 20px; }
.chart-meta { min-height: 20px; padding: 3px 2px 0; font-size: .73rem; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.table-card { min-width: 0; overflow: hidden; }
.card-title-row { padding: 15px 16px 9px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: var(--panel); color: var(--muted); font-size: .68rem; font-weight: 720; letter-spacing: .075em; text-transform: uppercase; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
.breakdown-table { min-width: 475px; }
.breakdown-row.drillable { cursor: pointer; }
.breakdown-row.drillable:hover { background: #f8fafb; }
.category-cell { display: flex; align-items: center; gap: 7px; }
.category-marker { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 2px; }
.category-name { font-weight: 650; }
.drill-cue { color: #9aa4ac; font-size: .9rem; }
.effect-positive { color: var(--positive); }
.effect-negative { color: var(--negative); }
.empty-state { border-top: 1px solid var(--line); padding: 18px 16px; color: var(--muted); font-size: .84rem; }
.history-scroll { max-height: 550px; overflow: auto; }
.history-table { min-width: 610px; }
.history-row-selected { background: #f2f7fa; }
.error-panel { margin-top: 16px; border: 1px solid #dfb7b4; border-radius: 12px; background: #fff8f7; padding: 17px; color: #7b302d; }
.error-panel p { margin: 5px 0 0; }
footer { margin-top: 42px; padding-top: 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: .84rem; }
footer h2 { color: var(--text); font-size: .98rem; }
footer p { max-width: 1020px; }

@media (max-width: 940px) {
  .control-card { grid-template-columns: 1fr 1fr; }
  .range-block { grid-column: 1 / -1; justify-self: start; }
  .headline-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1180px); padding-top: 20px; }
  .site-nav { margin-bottom: 24px; }
  .masthead { flex-direction: column; align-items: flex-start; }
  .masthead .button { align-self: stretch; }
  .status { align-items: flex-start; }
  .control-card { grid-template-columns: 1fr; gap: 13px; padding: 12px; }
  .range-block { grid-column: auto; justify-self: stretch; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; min-width: 0; padding: 7px 4px; font-size: .7rem; }
  .segmented-measure button { font-size: .73rem; }
  .analysis-head { align-items: flex-start; flex-direction: column; gap: 9px; }
  .button-small { align-self: flex-start; }
  .headline-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .headline-card { padding: 14px 12px; }
  .headline-card > strong { font-size: 1.62rem; }
  .headline-card .metric-label { font-size: .61rem; }
  .chart-card { padding: 14px 10px 10px; }
  .chart-head { align-items: flex-start; }
  .chart-legend { font-size: .69rem; gap: 6px 10px; }
  .driver-chart { min-height: 245px; }
  .driver-chart svg { min-height: 235px; }
  .axis-label { font-size: 16px; }
  .card-title-row { padding-left: 12px; padding-right: 12px; }
  th, td { padding: 11px 10px; }
  .breakdown-table th:nth-child(2), .breakdown-table td:nth-child(2) { display: none; }
  .breakdown-table { min-width: 365px; }
}

@media (max-width: 430px) {
  .segmented-range button { font-size: .66rem; }
  .headline-card > strong { font-size: 1.45rem; }
  .chart-head .pill { display: none; }
}
