/* Palette roles from the validated reference instance. Light and dark are each
   selected steps validated against their own surface, not an automatic flip. */
.viz-root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  /* Gauge slots, handed out by distance: nearest gauge gets g1. Every field
     draws a different number of these, and the checkboxes change it again, so
     the order was chosen for the property that every PREFIX of it validates —
     g1..gk followed by the three gridded hues clears the adjacent-pair gates
     in both modes for k = 0..4. Picking pretty colours and hoping would have
     broken on whichever field happened to have three gauges. */
  --series-g1: #2a78d6;      /* blue    */
  --series-g2: #e87ba4;      /* magenta */
  --series-g3: #4a3aa7;      /* violet  */
  --series-g4: #008300;      /* green   */
  --series-gauge:  #2a78d6;  /* also the UI accent: focus rings, primary buttons */
  --series-rfcqpe: #eda100;  /* yellow */
  --series-prism:  #1baf7a;  /* aqua   */
  --series-mrms:   #eb6834;  /* orange */
  --good: #0ca30c;
  --warning: #fab219;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19; --plane: #0d0d0d;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-g1: #3987e5; --series-g2: #d55181; --series-g3: #9085e9; --series-g4: #008300;
    --series-gauge: #3987e5;
    --series-rfcqpe: #c98500; --series-prism: #199e70; --series-mrms: #d95926;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19; --plane: #0d0d0d;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-g1: #3987e5; --series-g2: #d55181; --series-g3: #9085e9; --series-g4: #008300;
  --series-gauge: #3987e5;
  --series-rfcqpe: #c98500; --series-prism: #199e70; --series-mrms: #d95926;
}

* { box-sizing: border-box; }
/* Any `display` declaration outranks the user-agent [hidden] rule, so anything
   laid out with flex silently ignores .hidden = true. Said once here rather
   than per-component, because the failure is invisible until something shows
   up that should not be there. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--plane); color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 2px; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.note { margin: 0; color: var(--text-muted); font-size: 12px; max-width: 62ch; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
  justify-content: space-between; padding: 18px 24px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.ctl { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--text-muted); }
select, .btn {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  cursor: pointer;
}
.btn { text-decoration: none; display: inline-block; }
.btn:hover, select:hover { border-color: var(--axis); }

/* Checkbox popover for the multi-value filters. <details> carries the open
   state and the keyboard behaviour natively, so no JS owns "is it showing". */
.multi { position: relative; }
.multi > summary {
  font-size: 13px; padding: 6px 26px 6px 10px; border-radius: 7px; list-style: none;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  cursor: pointer; white-space: nowrap; min-width: 118px;
}
.multi > summary::-webkit-details-marker { display: none; }
.multi > summary::after {
  content: "▾"; position: absolute; right: 9px; top: 6px; color: var(--text-muted); font-size: 11px;
}
.multi[open] > summary::after { content: "▴"; }
.multi > summary:hover { border-color: var(--axis); }
.multi-panel {
  position: absolute; right: 0; z-index: 10; margin-top: 4px; padding: 8px; min-width: 190px;
  max-height: 280px; overflow-y: auto; background: var(--surface-1);
  border: 1px solid var(--axis); border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
}
.multi-panel label {
  display: flex; align-items: center; gap: 7px; padding: 4px 3px;
  font-size: 13px; color: var(--text-primary); cursor: pointer; white-space: nowrap;
}
.multi-panel label:hover { color: var(--series-gauge); }
.multi-panel .sep { border-top: 1px solid var(--border); margin: 6px 0; }
.multi-panel .none { color: var(--text-muted); font-size: 12px; padding: 2px 3px; }

main { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; max-width: 1180px; }

/* KPI row of stat tiles — headline numbers, not a one-bar chart. */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 11px; padding: 14px 16px;
}
.tile .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tile .value { font-size: 30px; line-height: 1.15; margin-top: 4px; letter-spacing: -0.02em; }
.tile .value .unit { font-size: 15px; color: var(--text-secondary); margin-left: 2px; }
/* A COOP station name runs longer than a tile is wide, and a tile that grows to
   fit one breaks the row. Clipped here; the legend under the chart has room to
   spell it out, and the title attribute covers the hover. */
.tile .meta {
  font-size: 11.5px; color: var(--text-secondary); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .meta .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: baseline; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 11px; padding: 16px 18px 10px; }
.card-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }

/* The card's own explanation, folded away and remembered (`rm-notes` in
   app.js). Borderless like the legend's buttons, because it switches a view
   rather than doing anything: beside "Re-map gauges" a bordered glyph would
   read as a third action. 24px minimum — it is the smallest target on the
   page, and WCAG 2.5.8 is the floor rather than the aim. */
.notetoggle {
  font: inherit; font-size: 13px; line-height: 1; color: var(--text-muted);
  background: none; border: none; border-radius: 6px; cursor: pointer;
  padding: 4px 7px; min-width: 24px; min-height: 24px;
}
.notetoggle:hover { background: var(--plane); color: var(--text-primary); }
.notetoggle:focus-visible { outline: 2px solid var(--series-gauge); outline-offset: 0; }
/* Only when it is the head's own child. Appended into a .jobactions group it is
   already at that group's right-hand end, and an auto margin there would push
   it away from the buttons it just joined. The auto margin is for the wrapped
   case: .card-head wraps, and .note's 62ch base width drops the toggle onto its
   own line on a phone. */
.card-head > .notetoggle { margin-left: auto; flex: none; }

/* Legend is always present for >= 2 series; identity is never color-alone. */
.legend { display: flex; flex-wrap: wrap; gap: 12px 8px; font-size: 12px; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* The legend is also the chart's controls: a series is clicked off the two
   charts and clicked back on. Only the buttons take these — the year key beside
   them is a `.item` too and describes form, not something you can switch. */
.legend button.item {
  font: inherit; font-size: 12px; color: inherit; background: none;
  border: none; padding: 3px 5px; margin: -3px 0; border-radius: 6px; cursor: pointer;
}
.legend button.item:hover { background: var(--plane); }
.legend button.item:focus-visible { outline: 2px solid var(--series-gauge); outline-offset: 0; }
/* Struck through rather than removed: a series put away for a minute must stay
   distinguishable from one that has nothing to draw, and it has to stay
   clickable to come back. Line-through survives forced-colors, where opacity
   alone would not. */
.legend button.item.off { color: var(--text-muted); text-decoration: line-through; }
.legend button.item.off .swatch { opacity: 0.3; }
.legend button.item.back { text-decoration: underline; color: var(--series-gauge); }
/* The year key: which half / which stroke is which year. It describes form, not
   identity, so its glyphs inherit the legend's ink rather than a series colour. */
.legend .ykey { width: 24px; height: 14px; flex: none; }

.chart-wrap { width: 100%; overflow: hidden; }
svg { display: block; width: 100%; height: auto; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.dlabel { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.hit { fill: transparent; cursor: pointer; }
.hit:hover ~ .hl, .band.on { fill: var(--grid); opacity: 0.45; }

.table-wrap { overflow-x: auto; max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
th:first-child, td:first-child { text-align: left; }
/* The station table leads with a checkbox, so the name is the second column. */
#stationTable th:nth-child(2), #stationTable td:nth-child(2) { text-align: left; }
#stationTable th:first-child, #stationTable td:first-child { width: 1%; }
td.none { color: var(--text-muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 20; padding: 8px 10px;
  background: var(--surface-1); border: 1px solid var(--axis); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14); font-size: 12px; color: var(--text-primary);
  max-width: 260px; font-variant-numeric: tabular-nums;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tt-row .k { color: var(--text-secondary); }
/* The comparison year, wherever it sits beside this year's figure: recessive,
   because this year is the number being read and last year is the reference. */
.prev { color: var(--text-muted); }
.tooltip .tt-row .prev { margin-left: 8px; }
.tooltip .tt-note { color: var(--text-muted); margin-top: 5px; font-size: 11px; }

.fieldform { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px; }
.fieldform label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--text-muted); }
.fieldform label em { font-style: normal; opacity: 0.75; }
.fieldform input {
  font: inherit; font-size: 13px; padding: 6px 9px; border-radius: 7px; width: 140px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
}
.fieldform input:focus { outline: 2px solid var(--series-gauge); outline-offset: -1px; }
.fieldform input[type="file"] { width: 260px; padding: 5px 6px; }
/* A report URL is unreadable at the default width, and getting it wrong is the
   one setup mistake that only shows up months later. */
.fieldform input.wide { width: 300px; }
.fieldform label.check { flex-direction: row; align-items: center; gap: 7px; padding-bottom: 6px; }
.fieldform label.check input { width: auto; }
.fieldform label.check span { color: var(--text-primary); font-size: 12.5px; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 2px 0 12px; }
.toggles label {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer;
  color: var(--text-primary);
}
.toggles label.off { color: var(--text-muted); }
.toggles .swatch { width: 10px; height: 10px; border-radius: 3px; }
td .tick { display: flex; justify-content: flex-start; }

/* Editable table cell: reads as text until focused, so the table still scans as
   a table rather than a form. */
.cell {
  font: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums;
  padding: 3px 6px; width: 108px; border-radius: 5px;
  border: 1px solid transparent; background: transparent; color: var(--text-primary);
}
.cell.num { text-align: right; width: 74px; }
.cell:hover { border-color: var(--border); }
.cell:focus { outline: none; border-color: var(--series-gauge); background: var(--plane); }
.cell.saving { border-color: var(--warning); }

.linkbtn {
  font: inherit; font-size: 12px; background: none; border: none; padding: 2px 4px;
  color: var(--series-gauge); cursor: pointer; text-decoration: underline;
}
.linkbtn.danger { color: var(--critical, #d03b3b); }
code { font-size: 11.5px; background: var(--grid); padding: 1px 4px; border-radius: 4px; }

/* Update notice. Colored border rather than a colored fill: it has to read as
   "something is waiting for you" without competing with the rainfall numbers,
   which are the reason anyone opened the page. */
.banner {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-radius: 11px;
  background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--series-gauge);
}
.banner strong { font-size: 14px; }
.banner .note { margin-top: 2px; }
.btn.primary { border-color: var(--series-gauge); color: var(--series-gauge); font-weight: 600; }
.btn.primary:hover { background: var(--plane); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: default; }
/* Outlined rather than filled: a destructive button should be identifiable
   before it is clicked without shouting over the rainfall numbers. */
.btn.danger { border-color: var(--critical, #d03b3b); color: var(--critical, #d03b3b); }
.btn.danger:hover { background: var(--plane); border-color: var(--critical, #d03b3b); }

.jobactions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jobstatus { margin: 4px 0 8px; font-size: 13px; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.jobstatus .none { color: var(--text-muted); }
/* Spinner doubles as the "is it working" signal; text alone reads as stalled. */
.spinner {
  width: 12px; height: 12px; flex: none; border-radius: 50%;
  border: 2px solid var(--grid); border-top-color: var(--series-gauge);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.joblog {
  margin: 0 0 10px; padding: 10px 12px; max-height: 190px; overflow: auto;
  background: var(--plane); border: 1px solid var(--border); border-radius: 8px;
  font: 11.5px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text-secondary); white-space: pre-wrap;
}

.footer { color: var(--text-muted); font-size: 11.5px; margin: 4px 0 0; }
.warn { color: var(--warning); }

/* Hosted mode. Signed out, the page is the sign-in card and nothing else: the
   charts and controls would only be empty boxes that look broken. */
.acct { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-secondary); }
.signin { max-width: 560px; margin: 24px auto; }
.signin .gsi { margin: 14px 0 6px; min-height: 44px; }
body.signed-out main > :not(#signinCard),
body.signed-out .controls > :not(#themeBtn) { display: none !important; }
.multi-panel .farmlink { display: block; padding: 3px 3px; color: var(--text-primary); text-decoration: none; }
.multi-panel .farmlink:hover { color: var(--series-gauge); }
.multi-panel .farmlink.here { font-weight: 600; }
.sharebox { margin: 6px 0 10px; display: grid; gap: 6px; font-size: 13px; }
.sharebox .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sharebox code { user-select: all; }
.banner.pastdue {
  border: 2px solid var(--critical, #d03b3b); border-left-width: 8px;
  background: color-mix(in srgb, var(--critical, #d03b3b) 10%, var(--surface-1));
}
.banner.pastdue strong { color: var(--critical, #d03b3b); font-size: 16px; }
#historyTable input { width: 6em; }
