/* Simulator page. Builds on app.css tokens. */
:root {
  --c-elev: #0f6e80;
  --c-avg: #8d969a;
  --c-inflow: #2a7fc1;
  --c-river: #0f8a6a;
  --c-upstream: #b9772a;
  --c-spill: #c2453b;
  --c-swe: #4a68c9;
  --band-flood: rgba(194, 69, 59, .09);
  --band-joint: rgba(15, 110, 128, .07);
  --band-active: rgba(141, 150, 154, .06);
  --future: rgba(29, 42, 47, .035);
  --grid: #ebe6dc;
  --asof: #1d2a2f;
  --faint: .28;          /* recorded lines after the chosen date, and their hover/tooltip dots */
}
:root[data-theme="dark"] {
    --c-elev: #5cc8d6;
    --c-avg: #7c8b90;
    --c-inflow: #6fb3ea;
    --c-river: #4fd1a5;
    --c-upstream: #e3a55a;
    --c-spill: #ef7a70;
    --c-swe: #93a8f5;
    --band-flood: rgba(239, 122, 112, .12);
    --band-joint: rgba(92, 200, 214, .08);
    --band-active: rgba(147, 166, 171, .06);
    --future: rgba(231, 238, 240, .035);
    --grid: #223236;
    --asof: #e7eef0;
    --faint: .5;         /* on a dark background .28 turns colours to grey */
}

.page--wide { max-width: 1320px; }
.h-display--sm { font-size: clamp(26px, 3.2vw, 36px); margin-bottom: 10px; }
.lede--wide { max-width: 62ch; font-size: 16px; margin-bottom: 0; }

.sim-top { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 32px; align-items: end; }
@media (max-width: 1000px) { .sim-top { grid-template-columns: 1fr; gap: 20px; } }

/* ------------------------------------------------------------ toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 16px 20px; padding: 16px 18px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--grow { flex: 1 1 260px; }
.field--end { margin-left: auto; }
.field label, .field__label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.field label[for="asOf"], #actual-l { color: var(--c-rules); }
.field input[type="date"] {
  font: inherit; font-size: 15px; font-variant-numeric: tabular-nums;
  padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.field input[type="date"]:focus-visible, .seg input:focus-visible + span, .chips button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 5px 12px; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  font: inherit; font-size: 13px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.button { display: inline-flex; align-items: center; gap: 8px; border: 0; cursor: pointer; font: inherit; font-weight: 600; }

.notice { margin: 16px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.notice.is-error { background: rgba(194, 69, 59, .12); }

/* ------------------------------------------------------------ stats */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-top: 24px; }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; }
.stat__label { font-size: 12px; color: var(--muted); }
.stat__value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; margin: 2px 0; }
.stat__value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat__note { font-size: 12px; color: var(--muted); }
.stat--corps { border-color: var(--c-spill); }
.stat--corps .stat__value { color: var(--c-spill); }
.up { color: var(--ok); } .down { color: var(--c-spill); }

/* ------------------------------------------------------------ charts */
.chart-card { margin-top: 16px; padding: 16px 18px 10px; }
.chart-card__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 20px; }
.chart-card__head .h-section { margin: 0; }
.h-note { margin: 2px 0 0; font-size: 13px; color: var(--muted); flex-basis: 100%; }
.chart-row { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; }
@media (max-width: 1000px) { .chart-row { grid-template-columns: 1fr; } }
.chart { position: relative; width: 100%; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; }
.legend__item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend__swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend__swatch--dash { background: none !important; border-top: 2px dashed; height: 0; }
.legend__value { font-variant-numeric: tabular-nums; font-weight: 600; }
.legend__date { color: var(--muted); font-variant-numeric: tabular-nums; }

.axis text, .label { font: 11px Inter, system-ui, sans-serif; fill: var(--muted); }
.axis line, .gridline { stroke: var(--grid); stroke-width: 1; }
.band-label { font: 600 10.5px Inter, system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; }
.band-label--flood { fill: var(--c-spill); }
.band-label--joint { fill: var(--c-elev); }
.band-label--active { fill: var(--muted); }
.ref-line { stroke-width: 1; stroke-dasharray: 3 3; }
.ref-line--flood { stroke: var(--c-spill); opacity: .6; }
.ref-line--joint { stroke: var(--c-elev); opacity: .5; }
.future { fill: var(--future); }
.asof-line { stroke: var(--asof); stroke-width: 1.25; }
.asof-label { font: 600 11px Inter, system-ui, sans-serif; fill: var(--asof); }
.future-label { font: italic 11px Inter, system-ui, sans-serif; fill: var(--muted); }
.target { fill: var(--surface); stroke: var(--asof); stroke-width: 1.5; }
.target-label { font: 10.5px Inter, system-ui, sans-serif; fill: var(--asof); }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series--thin { stroke-width: 1.5; }
.series--dash { stroke-dasharray: 5 4; stroke-width: 1.5; }
.series-area { stroke: none; opacity: .12; }
/* Actual history after the chosen date */
.after.mode-faint { opacity: var(--faint); }
.after.mode-show { opacity: 1; }
.after.mode-hide { display: none; }
.hover-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.hover-dot { stroke: var(--surface); stroke-width: 1.5; }
.overlay { fill: transparent; cursor: crosshair; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); font-size: 12px; line-height: 1.45; font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 16px rgba(0,0,0,.28); max-width: 260px;
}
.tooltip b { font-weight: 600; }
/* Same background as the charts, so each dot reads as the same colour as its line and hover point. */
.tooltip .t-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.tooltip .t-after { opacity: .7; font-style: italic; }

/* ------------------------------------------------------------ forecasts */
.forecast-card { margin-top: 16px; padding: 16px 18px; }
.forecast-table { overflow-x: auto; margin-top: 10px; }
.forecast-table table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.forecast-table th, .forecast-table td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.forecast-table th:first-child { text-align: left; }
.forecast-table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.forecast-table tbody th { text-align: left; font-size: 13px; text-transform: none; letter-spacing: 0; }
.forecast-table .is-future.mode-faint { opacity: .35; }
.forecast-table .is-future.mode-hide { visibility: hidden; }
.forecast-table .is-current { background: var(--accent-soft); }
.forecast-table .is-actual { font-weight: 600; }
.forecast-table .muted { color: var(--muted); }

.print-head, .print-foot { display: none; }

/* ------------------------------------------------------------ print: one landscape letter page */
@media print {
  @page { size: letter landscape; margin: .35in; }
  :root, :root[data-theme] { --surface: #fff; --bg: #fff; --text: #111; --muted: #555; --border: #ccc; --grid: #e6e6e6; --asof: #111; --shadow: none; }
  html, body { background: #fff; }
  body { display: block; min-height: 0; font-size: 11px; }
  .site-header, .site-footer, .sim-top, #notice, .tooltip, .forecast-card .h-note, .sc-swe { display: none !important; }
  .page { max-width: none; padding: 0; }
  .page > section, .chart-row { margin-top: 6px !important; }
  .chart { margin-top: 2px; }
  .card { box-shadow: none; border-color: #ccc; border-radius: 6px; break-inside: avoid; }
  .print-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 6px; }
  .print-head__eyebrow { font-size: 9px; text-transform: uppercase; letter-spacing: .06em; color: #555; }
  .print-head__title { font: 600 17px "Source Serif 4", Georgia, serif; margin: 2px 0 0; }
  .print-params { display: grid; grid-template-columns: repeat(3, auto); gap: 1px 14px; margin: 0; font-size: 9px; }
  .print-params dt { color: #555; }
  .print-params dd { margin: 0 0 0 4px; font-weight: 600; display: inline; }
  .print-params div { white-space: nowrap; }
  .stats { grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 4px; }
  .stat { padding: 5px 8px; }
  .stat__value { font-size: 14px; }
  .stat__label, .stat__note { font-size: 8.5px; }
  .chart-card { margin-top: 6px; padding: 6px 8px 2px; }
  .chart-card .h-section { font-size: 11px; }
  .h-sub { font-size: 9px; }
  .legend { font-size: 9px; }
  .chart-row { grid-template-columns: 3fr 2fr; gap: 6px; }
  .forecast-card { margin-top: 6px; padding: 4px 8px; }
  .forecast-card .h-section { font-size: 11px; }
  .forecast-table { margin-top: 2px; }
  .forecast-table table { font-size: 8.5px; }
  .forecast-table th, .forecast-table td { padding: 1px 6px; }
  .forecast-table th, .forecast-table tbody th { font-size: 8px; }
  .source-note { margin-top: 3px; font-size: 7px; line-height: 1.3; }
  .after.mode-faint { opacity: .35; }
}

/* ------------------------------------------------------------ step 2: scenario + simulation */
:root { --c-sim: #c2551f; }
:root[data-theme="dark"] { --c-sim: #ff9a5c; }
.series--sim { stroke-width: 2.25; stroke-dasharray: 7 3; }
.series--simthin { stroke-width: 1.5; stroke-dasharray: 4 3; }
.series--rule { stroke-width: 1.25; stroke-dasharray: 1 3; opacity: .8; }
.overlay--pick { cursor: copy; }
.pick-dot { fill: var(--c-sim); stroke: var(--surface); stroke-width: 2; }
.pick-label { font: 600 11px Inter, system-ui, sans-serif; fill: var(--c-sim); }

.scenario { margin-top: 16px; padding: 16px 18px; }
.scenario__grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr) minmax(0, 1.3fr); gap: 14px 22px; margin-top: 10px; }
@media (min-width: 1001px) {
  /* Afterbay runs the full height on the right; Flood pool tucks under Inflow + Boysen */
  #afterbayGroup { grid-column: 3; grid-row: 1 / span 2; }
  #corpsGroup { grid-column: 1 / span 2; grid-row: 2; border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }
}
@media (max-width: 1000px) { .scenario__grid { grid-template-columns: 1fr 1fr; } .sc-group--wide { grid-column: 1 / -1; } }
@media (max-width: 640px) { .scenario__grid { grid-template-columns: 1fr; } }
.sc-group { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.sc-group legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--c-rules); }
.sc-swe { margin-top: 4px; }
.sc-swe__head { font-size: 12px; font-weight: 600; color: var(--text); }
.sc-swe__head .h-sub { font-weight: 400; }
.sc-swe .chart { margin-top: 4px; }
.sc-group legend .h-sub { text-transform: none; letter-spacing: 0; font-weight: 400; }
.seg--sm span { padding: 4px 10px; font-size: 13px; }
.seg input:disabled + span { opacity: .4; cursor: not-allowed; }
.sc-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.sc-row > label, .step__label { font-size: 13px; color: var(--muted); }
.sc-row input[type="range"] { flex: 1 1 140px; accent-color: var(--c-sim); }
.sc-row output { min-width: 7ch; font-weight: 600; font-variant-numeric: tabular-nums; }
.sc-push { margin-left: auto; }
.sc-unit { font-size: 13px; color: var(--muted); }
.scenario select, .scenario input[type="number"], .scenario input[type="date"] {
  font: inherit; font-size: 14px; font-variant-numeric: tabular-nums; padding: 5px 8px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.scenario input[type="number"] { width: 10ch; }
.scenario input:disabled, .scenario select:disabled { opacity: .5; }
.sc-summary { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.schedule { display: flex; flex-direction: column; gap: 6px; }
.schedule:empty { display: none; }
.step { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.link-button { font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 4px 0; cursor: pointer; }
.link-button:disabled { opacity: .4; cursor: default; }
.icon-button { font: inherit; font-size: 18px; line-height: 1; width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--c-spill); border-color: var(--c-spill); }
.link-button:focus-visible, .icon-button:focus-visible, .scenario select:focus-visible, .scenario input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sc-notes { margin: 12px 0 0; padding: 8px 12px 8px 28px; border-radius: 10px; background: rgba(194, 85, 31, .1); font-size: 13px; line-height: 1.5; }

.results { overflow-x: auto; margin-top: 6px; }
.results table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.results th, .results td { padding: 5px 10px; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; }
.results th:first-child { text-align: left; }
.results thead th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-top: 0; }
.results tbody th { text-align: left; font-weight: 500; color: var(--muted); }
.results tr.is-sim th { color: var(--c-sim); font-weight: 600; }
.results tr.is-sim td { font-weight: 600; }
.results .is-warn { color: var(--c-spill); }
.results .muted { color: var(--muted); font-weight: 400; }
.results .is-future.mode-faint { opacity: .45; }
.results .is-future.mode-hide { display: none; }
.fc-story { margin: 8px 0 0; font-size: 14px; font-style: italic; }

@media print {
  .scenario { display: none !important; }
  .results { margin-top: 2px; }
  .results table { font-size: 8.5px; }
  .results th, .results td { padding: 1px 6px; }
  .results thead th { font-size: 8px; }
  .fc-story { font-size: 9px; margin-top: 2px; }
  .print-params { grid-template-columns: repeat(4, auto); }
}

/* ------------------------------------------------------------ step 4: coach + scorecard */
:root { --c-rules: #6b55c9; }
:root[data-theme="dark"] { --c-rules: #ab9cf5; }
/* Reclamation's operating plan (Operations Outlook): median line, minimum-maximum band. */
:root { --c-plan: #b0377f; }
:root[data-theme="dark"] { --c-plan: #f28cc8; }
.series--plan { stroke-width: 1.75; stroke-dasharray: 2 2; }
.plan-band { fill: var(--c-plan); opacity: .1; }
.series--ref { stroke-width: 1.75; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text) !important; cursor: pointer; }
.check input { accent-color: var(--c-rules); width: 15px; height: 15px; }

.coach-card { margin-top: 16px; padding: 16px 18px; }
.tips { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px 18px; }
.tip { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.5; }
.tip p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.tip .muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.tip__icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font: 700 12px Inter, system-ui, sans-serif; color: #fff; margin-top: 1px; }
.tip--warn .tip__icon { background: var(--c-spill); }
.tip--info .tip__icon { background: var(--c-rules); }
.tip--good .tip__icon { background: var(--ok); }

.scorecard-card { margin-top: 16px; padding: 10px 18px 12px; }
.scorecard-card .results { margin-top: 0; }
.scorecard thead th { text-align: right; }
.scorecard .sc-groups th { text-align: center; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.scorecard .sc-groups th:first-child { text-align: left; vertical-align: bottom; text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); }
.scorecard .sc-groups th + th { border-left: 1px solid var(--border); }
.results tr.is-ref th { color: var(--c-rules); font-weight: 600; }

@media print {
  .coach-card { display: none !important; }
  .source-note { display: none; }
  .print-foot { display: block; margin: 3px 0 0; font-size: 7px; color: #555; }
  .stat__note { display: none; }
  .stat { padding: 3px 8px; }
  #swe-h .h-sub, .chart-card__head .h-note { display: none; }
  .scorecard-card { margin-top: 6px; padding: 4px 8px; }
  .scorecard .sc-groups th:first-child { font-size: 10px; }
}

/* Corps mode: strip along the bottom of the lake chart on days the Corps is in control. */
.corps-strip { fill: var(--c-spill); opacity: .75; }
.corps-strip-label { fill: var(--c-spill); }

/* Estimated mid-month forecasts */
.forecast-table .is-est { font-style: italic; }
.est { font-size: 11px; font-style: normal; font-weight: 600; letter-spacing: .03em; color: var(--muted); text-transform: uppercase; cursor: help; }
.fc-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* Backward solver: the aim marker on the lake chart and its message. */
.aim { fill: none; stroke: var(--c-sim); stroke-width: 2.5; }
.aim-label { fill: var(--c-sim); font-weight: 600; }
.sc-summary.is-error { color: var(--c-spill); }
#aimRow input[type="number"] { width: 9ch; }

/* River release by month (the 2009 simulator's monthly boxes). */
.monthgrid__head { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.monthgrid__cells { display: flex; flex-wrap: wrap; gap: 6px; }
.monthcell { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.monthcell input { width: 8ch; }
#upWinterRow input { width: 8ch; }
#upGrid { display: flex; flex-direction: column; gap: 4px; }
#upGrid .link-button { align-self: flex-start; }
.monthcell.is-solved input { font-style: italic; border-color: var(--c-sim); }

/* ---- ensemble card ("What are the odds?") ---- */
.ens-card { margin-top: 16px; padding: 16px 18px 12px; }
.ens-card.is-busy { opacity: .6; }
.ens-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.ens-lede { margin: 4px 0 10px; color: var(--text); max-width: 80ch; }
.ens-band { stroke: none; }
.ens-band--outer { fill: var(--c-sim, #b9772a); opacity: .16; }
.ens-band--inner { fill: var(--c-sim, #b9772a); opacity: .26; }
.ens-median { stroke: var(--c-sim, #b9772a); stroke-width: 2; fill: none; }
.ens-recorded { stroke: var(--c-elev); stroke-width: 2; fill: none; }
.ens-actual { stroke: var(--c-elev); stroke-width: 1.5; fill: none; stroke-dasharray: 4 3; }
.ens-actual.mode-faint { opacity: .45; }
.ens-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.ens-sw { opacity: .5; }
.ens-table table { width: 100%; max-width: 760px; border-collapse: collapse; font-size: 14px; }
.ens-table th, .ens-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); font-weight: 400; }
.ens-table thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.ens-table td { text-align: right; font-variant-numeric: tabular-nums; }
.ens-table thead th:not(:first-child) { text-align: right; }
.ens-other { color: var(--muted); }
.ens-sub { color: var(--muted); font-size: 12px; }
.ens-note { font-size: 12.5px; color: var(--muted); max-width: 90ch; margin: 12px 0 0; }
@media print { .ens-controls { display: none; } }
@media print {
  .ens-card { margin-top: 6px; padding: 4px 8px; break-inside: avoid; }
  .ens-card .h-section { font-size: 11px; }
  .ens-lede { font-size: 9px; margin: 2px 0 4px; }
  .ens-legend { font-size: 8.5px; margin: 2px 0 4px; gap: 10px; }
  .ens-table table { font-size: 8.5px; max-width: none; }
  .ens-table th, .ens-table td { padding: 1px 6px; }
  .ens-note { font-size: 7.5px; margin-top: 3px; }
  .ens-card.is-busy { opacity: 1; }
}

.field--buttons { flex-direction: row; gap: 10px; }
@media print { #clearBtn { display: none !important; } }
#coachRow .check { color: var(--c-sim) !important; font-weight: 600; }

/* Top card: As of, Actual history and the buttons on one row, Jump to underneath */
.toolbar > .field--grow { order: 2; flex: 1 1 100%; }
.toolbar > .field--end { order: 1; }
