/* ============================================================
   style.css — all the visual styling for the app
   ============================================================
   CSS is read top to bottom. Each rule says:
       selector { property: value; }
   e.g.  header { background: #fff; }  paints the header white.

   The look follows the UW–Madison design system (brand.wisc.edu):
   Badger Red + white, charcoal and light grays, the Red Hat Display
   font for headings and Red Hat Text for everything else.

   All the colors live in ONE place, the ":root" block just below,
   as named "variables" like --uw-red. The rest of the file uses them
   as  var(--uw-red). To change a color everywhere, change it there.
   ============================================================ */

/* ---------- fonts ----------
   The Red Hat font files are stored in brand/fonts/ (copied from the
   UW–Madison design system), so the app needs no internet font service.
   Each @font-face says: "the font named X lives in file Y".
   "font-weight: 300 900" means one file covers light through black.   */
@font-face {
  font-family: "Red Hat Display";
  src: url("brand/fonts/redhat-display-latin.woff2") format("woff2");
  font-weight: 300 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Red Hat Display";
  src: url("brand/fonts/redhat-display-latin-ext.woff2") format("woff2");
  font-weight: 300 900; font-style: normal; font-display: swap;
  unicode-range: U+0100-024F, U+1E00-1EFF;  /* accented letters only */
}
@font-face {
  font-family: "Red Hat Text";
  src: url("brand/fonts/redhat-text-latin.woff2") format("woff2");
  font-weight: 300 625; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Red Hat Text";
  src: url("brand/fonts/redhat-text-latin-ext.woff2") format("woff2");
  font-weight: 300 625; font-style: normal; font-display: swap;
  unicode-range: U+0100-024F, U+1E00-1EFF;
}
@font-face {
  font-family: "Red Hat Text";
  src: url("brand/fonts/redhat-text-italic-latin.woff2") format("woff2");
  font-weight: 300 625; font-style: italic; font-display: swap;
}

/* ---------- UW–Madison colors (official values) ---------- */
:root {
  --uw-red:            #c5050c;  /* Badger Red — never change this one */
  --uw-red-dark:       #9b0000;  /* hover color for red things */
  --uw-black:          #121212;  /* text (the brand uses this, not pure black) */
  --uw-gray-dark:      #282728;  /* charcoal: footer, headings */
  --uw-gray-light:     #e1e5e7;
  --uw-gray-lightest:  #f3f3f3;  /* page background, caption strip */
  --uw-border:         #cfcfcf;  /* thin lines between areas */
  --uw-muted:          #5a5a5a;  /* small gray text (dark enough to read) */
  --uw-link:           #036796;  /* links */
  --uw-link-hover:     #023d54;
  --uw-footer-text:    #adadad;

  --font-display: "Red Hat Display", Arial, sans-serif;  /* headings */
  --font-text:    "Red Hat Text", Arial, sans-serif;     /* everything else */
}

/* Apply to every element: include borders in size math, no default margins */
* { box-sizing: border-box; margin: 0; }

/* The whole page: a vertical stack (header on top, main below) */
body {
  font-family: var(--font-text);
  background: var(--uw-gray-lightest);
  color: var(--uw-black);
}

/* buttons and dropdowns don't copy the page font on their own; tell them to */
button, select, input { font-family: inherit; }

/* a blue ring around whatever the keyboard is on (Tab key), so keyboard
   users can always see where they are */
:focus-visible { outline: 2px solid var(--uw-link); outline-offset: 2px; }

/* The app itself (header + map + chart): a vertical stack that fills the
   window, minus 44px at the bottom where the "Citations" heading of the
   citations section (below) peeks out. Scroll down to read the citations. */
#app {
  height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
}

/* ---------- UW global bar (thin red strip at the very top) ---------- */
.uw-global-bar {
  background: var(--uw-red);
  padding: 4px 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;  /* the one place the brand allows ALL CAPS */
}
.uw-global-bar a { color: #fff; text-decoration: none; }
.uw-global-bar a:hover { text-decoration: underline; }

/* ---------- header (white, crest on the left) ---------- */
header {
  padding: 8px 16px;
  background: #fff;
  color: var(--uw-black);
  border-bottom: 1px solid var(--uw-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
header .crest img { height: 40px; display: block; }  /* the UW crest */
/* flex: 1 lets the title shrink and wrap its words, so on a phone it stays
   beside the crest instead of dropping onto a line of its own */
header .site-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
header h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--uw-gray-dark);
  line-height: 1.2;
}
header .subtitle { font-size: 12.5px; color: var(--uw-muted); }

/* the Units / View dropdowns, pushed to the right end of the header */
.header-controls {
  margin-left: auto;          /* "auto" soaks up the free space on the left */
  display: flex;
  gap: 14px;
  font-size: 13px;
}
.header-controls label { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.header-controls select { font-size: 13px; padding: 2px 4px; }

/* all the dropdowns in the app: thin gray border, slightly rounded */
select {
  border: 1px solid var(--uw-border);
  border-radius: 4px;
  background: #fff;
  color: var(--uw-black);
}

/* ---------- the two-panel layout ---------- */
/* "grid-template-columns: 55% 45%" = map panel gets 55% of the width */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 55% 45%;
  min-height: 0;              /* allows panels to shrink properly */
}

section { display: flex; flex-direction: column; min-height: 0; }
#map-panel { border-right: 1px solid var(--uw-border); }

/* ---------- toolbars above map and chart ---------- */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--uw-border);
  font-size: 13px;
  flex-wrap: wrap;            /* wrap onto a second line if too narrow */
}
.controls label { display: flex; align-items: center; gap: 5px; font-weight: 600; }
.controls select { font-size: 13px; padding: 3px 4px; max-width: 170px; }
#metric-select { max-width: 260px; } /* its labels include units, so they're longer */

#year-slider { flex: 1; min-width: 120px; accent-color: var(--uw-red); } /* accent-color = the slider's red */
#year-input {
  width: 66px;                /* room for 4 digits plus the up/down arrows */
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums; /* digits all the same width */
  padding: 2px 4px;
  border: 1px solid var(--uw-border);
  border-radius: 4px;
}
#year-note { font-size: 12px; color: var(--uw-red-dark); }

/* The Play button: a solid Badger Red button, like the UW "red button".
   On hover it turns the darker red (the brand's only hover effect). */
#play-btn {
  width: 32px; height: 26px;
  border: 2px solid var(--uw-red); border-radius: 4px;
  background: var(--uw-red); color: #fff;
  cursor: pointer; font-size: 12px;
  transition: all 0.25s ease-out;
}
#play-btn:hover { background: var(--uw-red-dark); border-color: var(--uw-red-dark); }

/* The other buttons (Flip, + Compare, Clear, Compare my farm, and Cancel
   in its pop-up): the UW "outlined" button — red border and red text on
   white, filling with red on hover. */
#flip-btn, #compare-add, #compare-clear, #farm-open, #farm-cancel {
  border: 2px solid var(--uw-red);
  border-radius: 4px;
  background: #fff;
  color: var(--uw-red);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  cursor: pointer;
  transition: all 0.25s ease-out;
}
#flip-btn:hover, #compare-add:hover, #compare-clear:hover, #farm-open:hover, #farm-cancel:hover {
  background: var(--uw-red);
  color: #fff;
}
#map-status, #chart-status { font-size: 12px; color: var(--uw-muted); }
.diff-ctl { font-weight: 600; white-space: nowrap; }

/* ---------- the "Ask" box above the chart (js/ask.js) ---------- */
.ask-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 4px;
  background: #fff;
  font-size: 13px;
}
.ask-bar label { font-weight: 600; }
#ask-input {
  flex: 1;                    /* take all the width that's left */
  min-width: 0;
  font-size: 14px;
  padding: 5px 8px;
  border: 1px solid var(--uw-border);
  border-radius: 4px;
}
/* "Show": the same solid red as the Play button */
.ask-bar button {
  border: 2px solid var(--uw-red);
  border-radius: 4px;
  background: var(--uw-red);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 12px;
  cursor: pointer;
  transition: all 0.25s ease-out;
}
.ask-bar button:hover { background: var(--uw-red-dark); border-color: var(--uw-red-dark); }

/* the grey "Beta" notice under the box. #5a5a5a (--uw-muted) is the
   lightest grey that is still easy to read on white (4.5:1 contrast). */
#ask-beta {
  padding: 0 12px 4px;
  background: #fff;
  font-size: 11.5px;
  font-style: italic;
  color: var(--uw-muted);
}
#ask-beta b { font-style: normal; }

/* the reply line under the box */
#ask-reply {
  padding: 2px 12px 8px;
  background: #fff;
  border-bottom: 1px solid var(--uw-border);
  font-size: 12.5px;
  color: var(--uw-gray-dark);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}
/* a note like "showing winter wheat" (same yellow as the map caption note) */
#ask-reply .ask-note {
  background: #fff4d6;
  border: 1px solid #f0d58a;
  border-radius: 10px;
  padding: 0 8px;
  color: #6b4d00;
}
/* the clickable example questions */
#ask-reply .ask-example {
  border: 1px solid var(--uw-border);
  border-radius: 12px;
  background: var(--uw-gray-lightest);
  color: var(--uw-link);
  font-size: 12px;
  padding: 1px 8px;
  cursor: pointer;
}
#ask-reply .ask-example:hover { border-color: var(--uw-link); }

/* ---------- caption strip above the map ---------- */
#map-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;              /* 4px between rows, 16px between items */
  padding: 5px 12px;
  background: var(--uw-gray-lightest);
  border-bottom: 1px solid var(--uw-border);
  font-size: 12.5px;
  color: var(--uw-gray-dark);
}
/* the little red square that means "outlined in red on the map" */
#map-caption .swatch {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid var(--uw-red);  /* same red as HIGHLIGHT_STYLE in map.js */
  margin-right: 5px;
  vertical-align: -1px;
}
/* the yellow note shown when the chart's Crop/Metric differ from the map */
#map-caption .caption-note {
  background: #fff4d6;
  border: 1px solid #f0d58a;
  border-radius: 10px;
  padding: 0 8px;
  color: #6b4d00;
}

/* ---------- the map area ---------- */
/* map-wrap holds the map (and the second map in Dual mode) side by side */
#map-wrap { flex: 1; min-height: 0; display: flex; position: relative; }
#map  { flex: 1; min-height: 0; }
#map2 { flex: 1; min-height: 0; border-left: 2px solid #fff; }
#chart { flex: 1; min-height: 0; }

/* ---------- swipe divider (Swipe mode only) ---------- */
/* a thin white vertical bar you can drag left/right */
#swipe-divider {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 4px;
  margin-left: -2px;
  background: #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
  cursor: ew-resize;
  z-index: 900;               /* draw on top of the map */
  touch-action: none;         /* let us handle touch dragging ourselves */
}
/* the round handle in the middle of the divider */
#swipe-divider .handle {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px;
  border-radius: 50%;         /* 50% radius = a circle */
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #333;
  user-select: none;
}

/* ---------- year badges shown over the map ---------- */
.year-badge {
  position: absolute;
  top: 10px;
  padding: 3px 10px;
  background: rgba(40,39,40,0.88);  /* charcoal, slightly see-through */
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border-radius: 5px;
  z-index: 900;
  pointer-events: none;       /* clicks pass through to the map */
}
#badge-a { left: 52px; }      /* left badge sits right of the zoom buttons */
#badge-b { right: 10px; }

/* ---------- map legend (bottom-left color bar) ---------- */
.legend {
  background: rgba(255,255,255,0.92);
  padding: 8px 10px;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  font-size: 11.5px;
  line-height: 1.3;
}
.legend .bar {
  width: 160px; height: 12px;
  border-radius: 2px;
  margin: 4px 0 2px;
}
.legend .ticks { display: flex; justify-content: space-between; }

/* ---------- "+ Compare" chips ---------- */
/* (the + Compare and Clear buttons are styled with the Flip button above) */
#compare-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--uw-gray-lightest);
  border: 1px solid var(--uw-border);
  border-radius: 12px;        /* rounded pill shape */
  padding: 1px 8px;
  font-size: 12px;
}
.chip button {
  border: none; background: none; cursor: pointer;
  font-size: 13px; padding: 0; color: var(--uw-muted); line-height: 1;
}
.chip button:hover { color: var(--uw-red); }

/* ---------- "Compare my farm" (js/farm.js) ---------- */
/* (the button in the toolbar is styled with the Flip button above, and
   the chips beside it reuse .chip) */
#farm-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* The pop-up: a white card in the middle of the window, with the UW red
   bar across its top. Never wider than the screen (16px gap each side). */
#farm-dialog {
  width: min(400px, calc(100vw - 32px));
  margin: auto;               /* centered (the "* { margin: 0 }" rule above removes the browser's own centering) */
  padding: 20px 22px;
  border: none;
  border-top: 4px solid var(--uw-red);
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  color: var(--uw-black);
  font-size: 14px;
}
/* the dimmed page behind the pop-up */
#farm-dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
#farm-dialog h2 {
  font-family: "Red Hat Display", Arial, sans-serif;
  font-size: 20px;
  color: var(--uw-gray-dark);
  margin-bottom: 4px;
}
.farm-intro { font-size: 12.5px; color: var(--uw-muted); margin-bottom: 16px; }

/* The four questions: a two-column grid, the question on the left and
   its box(es) on the right. */
.farm-steps {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 12px;
  align-items: center;
}
.farm-step { font-weight: 600; white-space: nowrap; }
/* two things side by side: State + County, or the number + its unit */
.farm-pair { display: flex; align-items: center; gap: 6px; min-width: 0; }
#farm-dialog select, #farm-dialog input {
  font-size: 14px;
  padding: 5px 6px;
  border: 1px solid var(--uw-border);
  border-radius: 4px;
  min-width: 0;               /* lets the boxes shrink on a narrow phone */
}
#farm-county { flex: 1; }     /* the county names are long: take the rest of the row */
#farm-crop { width: 100%; }
#farm-year { width: 90px; }
#farm-value { width: 110px; }
/* the unit after the number box, e.g. "lb P/acre cropland" */
#farm-unit { color: var(--uw-muted); }

/* Show me (solid red, like the Ask box's "Show") and Cancel (outlined) */
.farm-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#farm-show, #farm-cancel { font-size: 13px; padding: 4px 14px; }
#farm-show {
  border: 2px solid var(--uw-red);
  border-radius: 4px;
  background: var(--uw-red);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease-out;
}
#farm-show:hover { background: var(--uw-red-dark); border-color: var(--uw-red-dark); }

/* ---------- citations section (bottom of the page) ---------- */
#citations {
  background: #fff;
  border-top: 1px solid var(--uw-border);
  padding: 8px 16px 28px;
  font-size: 13.5px;
  line-height: 1.55;
}
/* "Citations" — this line peeks out at the bottom of the window */
#citations h2 {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--uw-gray-dark);
  margin-bottom: 6px;
}
/* the short red bar above "Citations": the UW "mini-bar". ::before adds
   an empty box in front of the heading, which we paint red. */
#citations h2::before {
  content: "";
  display: block;
  width: 1.5em;
  height: 0.2em;
  background: var(--uw-red);
  margin-bottom: 3px;
}
#citations h3 {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--uw-gray-dark);
  margin: 16px 0 6px;
}
#citations ol { padding-left: 22px; max-width: 980px; }
#citations li { margin-bottom: 8px; }
#citations a { color: var(--uw-link); overflow-wrap: anywhere; } /* long DOIs may wrap */
#citations a:hover { color: var(--uw-link-hover); }
#citations .placeholder { color: var(--uw-muted); font-style: italic; }

/* ---------- UW footer (charcoal strip at the very bottom) ---------- */
#uw-footer {
  background: var(--uw-gray-dark);
  color: var(--uw-footer-text);
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
#uw-footer img { height: 44px; }
#uw-footer a { color: var(--uw-footer-text); }
#uw-footer a:hover { color: #fff; }

/* ---------- small screens: stack the panels vertically ---------- */
@media (max-width: 900px) {
  /* On a phone, squeezing both panels into one screen left the chart too
     short to read, so give each a fixed height and let the page scroll. */
  #app { height: auto; }
  main { grid-template-columns: 1fr; grid-template-rows: 460px 600px; }
  #map-panel { border-right: none; border-bottom: 1px solid var(--uw-border); }
}

/* ---------- the "Stream stations" layer (js/water.js) ---------- */
/* the checkbox in the map toolbar */
.stations-toggle { white-space: nowrap; cursor: pointer; }
.stations-toggle input { accent-color: var(--uw-red); margin: 0; }
/* the Parameter / Value box floating over the map (bottom right) */
.stations-ctl label { display: flex; align-items: center; gap: 5px; font-weight: 600; margin-top: 4px; }
.stations-ctl select { font-size: 12px; padding: 2px 3px; max-width: 210px; }
.stations-ctl .spotlight-toggle { font-weight: 500; }
.stations-ctl .spotlight-toggle input { accent-color: var(--uw-red); margin: 0; }
/* the dots' legend: the hollow "no result" dot and the small grey note */
.legend .legend-note { color: var(--uw-muted); margin-top: 3px; }
.legend .dot-empty {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid #777; background: #fff; vertical-align: -1px; margin-right: 4px;
}
/* the grey hint at the bottom of a dot's hover text */
.leaflet-tooltip .hint { color: var(--uw-muted); font-size: 11px; }
/* the "Station: ..." chip above the chart, and greyed-out dropdowns */
#station-chip { font-weight: 600; }
.controls select:disabled, .controls button:disabled { opacity: 0.45; cursor: not-allowed; }
