/* Paras — single-page water report.
   Brand: navy #12355b, teal #1f9e9e (from the crab logo).
   Status: normal #1a9850, alert #d4a017, warning #e8590c, danger #d62828.
   Design rules: one panel, quiet surfaces, graphics carry the story. */

:root {
  --navy: #12355b;
  --teal: #1f9e9e;
  --ink: #1c2733;
  --muted: #5b6b7a;
  --line: rgba(18, 53, 91, 0.09);
  --bg-panel: rgba(255, 255, 255, 0.94);
  --normal: #1a9850;
  --alert: #d4a017;
  --warning: #e8590c;
  --danger: #d62828;
  --stale: #a8b3bd;
  --rain: #2563eb;
  --radius: 12px;
  --shadow: 0 3px 14px rgba(18, 53, 91, 0.16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink); }
#map { position: fixed; inset: 0; background: #dfe8ee; }

.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hidden { display: none !important; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; border-radius: 8px; padding: 0;
}
.icon-btn:hover { background: rgba(18, 53, 91, 0.06); color: var(--navy); }
.icon-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* ---------- brand chip ---------- */
.brand {
  position: fixed; top: 12px; left: 12px; z-index: 20;
  display: flex; align-items: center; gap: 7px; padding: 6px 12px 6px 8px;
  text-decoration: none; color: var(--navy);
  font-weight: 700; font-size: 15px; letter-spacing: 0.2px;
}

/* ---------- the panel ---------- */
.now {
  position: fixed; top: 12px; right: 12px; z-index: 20;
  width: 344px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  display: flex; flex-direction: column;
  padding: 12px 14px;
}
.now-head { display: flex; align-items: center; gap: 4px; }
.now-head h1 { font-size: 14px; margin: 0 auto 0 0; color: var(--navy); font-weight: 700; }
.updated { font-size: 10.5px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.only-mobile { display: none; }

/* tabs */
.tabs { display: flex; gap: 2px; margin: 9px 0 0; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; border: none; background: transparent; cursor: pointer;
  font: 700 11.5px var(--font); color: var(--muted); letter-spacing: 0.4px;
  padding: 6px 4px 7px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--navy); }
.tab.active { color: var(--navy); border-bottom-color: var(--teal); }
.tab:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }
.tabpane { overflow-y: auto; min-height: 0; display: flex; flex-direction: column; }

.met-strip {
  display: flex; align-items: center; gap: 7px;
  margin: 9px 0 0; padding: 7px 10px; border: none; cursor: pointer;
  background: #fff7ed; color: #9a4d0b; border-left: 3px solid #d97706;
  border-radius: 7px; font: 600 12px var(--font); text-align: left; width: 100%; flex: none;
}
.met-strip .met-n { margin-left: auto; font-weight: 800; }

/* near-you card */
.nearyou {
  margin: 9px 0 0; padding: 9px 11px; border-radius: 8px; flex: none;
  background: rgba(31, 158, 158, 0.07); border-left: 3px solid var(--teal);
  font-size: 12px; line-height: 1.5;
}
.nearyou h4 { margin: 0 0 3px; font-size: 11px; color: var(--teal); text-transform: uppercase; letter-spacing: 0.7px; }
.nearyou .ny-row { display: flex; align-items: baseline; gap: 6px; padding: 2px 0; }
.nearyou .ny-row b { font-weight: 700; }
.nearyou .ny-link { cursor: pointer; color: var(--navy); text-decoration: underline; text-underline-offset: 2px; }
.nearyou .ny-x { float: right; border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 2px; }

/* stat tiles: quiet numbers, coloured underline only */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0 2px; flex: none; }
.stat { text-align: center; padding: 5px 2px 7px; border-radius: 8px; border: none; background: transparent; font-family: var(--font); cursor: pointer; }
.stat b { display: block; font-size: 19px; line-height: 1.15; color: var(--ink); }
.stat span { font-size: 9.5px; color: var(--muted); letter-spacing: 0.2px; }
.stat::after { content: ""; display: block; height: 3px; border-radius: 2px; margin: 5px auto 0; width: 26px; }
.stat.danger::after { background: var(--danger); }
.stat.warning::after { background: var(--warning); }
.stat.alert::after { background: var(--alert); }
.stat.rain::after { background: var(--rain); }
.stat.hot b { color: var(--danger); }
.stat:hover { background: rgba(18, 53, 91, 0.05); }

/* sections */
.sections { overflow: visible; min-height: 0; }
.sections section, .tabpane section { margin-top: 12px; }
.sections h3, .tabpane h3 {
  font-size: 11px; margin: 0 0 6px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.8px; font-weight: 700;
}
.sections h3 .est, .tabpane h3 .est { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; opacity: 0.8; }
.calm { font-size: 12.5px; color: var(--normal); margin: 2px 0 6px; }

/* river rows: dot · name · gauge · trend */
.river-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; border-radius: 8px; cursor: pointer;
}
.river-row:hover, .river-row:focus-visible { background: rgba(18, 53, 91, 0.05); outline: none; }
.rdot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.rwho { flex: 1; min-width: 0; }
.rnm { display: block; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rwh { display: block; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtrend { display: inline-flex; align-items: center; gap: 3px; flex: none; width: 52px; justify-content: flex-end; font-size: 10px; }
.rtrend.up { color: var(--danger); }
.rtrend.down { color: var(--normal); }
.rtrend i { font-style: normal; color: var(--muted); }

/* level gauge: track from normal to danger, marker = current level */
.lgauge {
  position: relative; flex: none; width: 86px; height: 6px;
  background: linear-gradient(to right,
    rgba(26,152,80,.25), rgba(212,160,23,.25) 50%, rgba(232,89,12,.3) 75%, rgba(214,40,40,.35));
  border-radius: 4px;
}
.lgauge.wide { width: 100%; height: 8px; }
.lgauge.mini { width: 64px; }
.lgauge .tick { position: absolute; top: -2px; width: 1px; height: 10px; background: rgba(18,53,91,.25); }
.lgauge .lvl {
  position: absolute; top: 50%; width: 11px; height: 11px;
  background: var(--navy); border: 2px solid #fff; border-radius: 50%;
  transform: translate(-50%, -50%); box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.gauge-scale {
  display: flex; justify-content: space-between; width: 86px;
  margin-left: auto; margin-right: 60px; margin-bottom: 2px;
  font-size: 9px; color: var(--muted);
}
.gauge-scale.wide { width: 100%; margin: 2px 0 0; }
.nogauge { flex: none; width: 86px; font-size: 10px; color: var(--muted); text-align: center; font-weight: 600; }

/* quiet bars */
.bar-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px; font-size: 12px; }
.bar-label { flex: none; width: 96px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.bar-place { cursor: pointer; }
.bar-place:hover { color: var(--navy); text-decoration: underline; }
.bar-track { flex: 1; height: 7px; background: rgba(18,53,91,.07); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-val { flex: none; min-width: 44px; text-align: right; font-weight: 700; font-size: 11.5px; }

/* ---------- basins tab ---------- */
.basin-card {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line);
  background: rgba(255,255,255,0.6); border-radius: 9px; padding: 8px 10px;
  margin-top: 8px; cursor: pointer; font-family: var(--font);
}
.basin-card:hover { border-color: rgba(31,158,158,0.5); background: #fff; }
.basin-card .bc-top { display: flex; align-items: baseline; gap: 8px; }
.basin-card .bc-name { font-size: 12.5px; font-weight: 700; color: var(--navy); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.basin-card .bc-states { font-size: 10px; color: var(--muted); flex: none; }
.basin-card .bc-dots { display: flex; gap: 3px; margin-top: 6px; align-items: center; }
.basin-card .bc-dots i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.basin-card .bc-sum { font-size: 10.5px; color: var(--muted); margin-top: 5px; line-height: 1.4; }
.basin-intro { font-size: 11.5px; color: var(--muted); line-height: 1.5; margin: 10px 0 0; }

/* basin detail header */
.bd-head { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex: none; }
.bd-head h2 { font-size: 14px; color: var(--navy); margin: 0; flex: 1; min-width: 0; }
.bd-back {
  border: none; background: rgba(18,53,91,0.06); color: var(--navy); cursor: pointer;
  font: 600 11px var(--font); padding: 4px 9px; border-radius: 6px; flex: none;
}
.bd-back:hover { background: rgba(18,53,91,0.12); }
.bd-summary { font-size: 12px; line-height: 1.55; margin: 8px 0 0; flex: none; }
.bd-summary b.bad { color: var(--danger); }
.bd-caption { font-size: 10px; color: var(--muted); margin: 8px 0 2px; flex: none; }

/* flow strip: vertical chain, headwaters at top */
.flow { position: relative; margin: 4px 0 8px; padding-left: 18px; }
.flow::before {
  content: ""; position: absolute; left: 7px; top: 10px; bottom: 10px; width: 3px;
  background: linear-gradient(to bottom, rgba(31,158,158,0.35), rgba(18,53,91,0.45));
  border-radius: 2px;
}
.fstop {
  position: relative; display: flex; align-items: center; gap: 7px;
  padding: 5px 4px 5px 6px; border-radius: 8px; cursor: pointer;
}
.fstop:hover { background: rgba(18, 53, 91, 0.05); }
.fstop .fdot {
  position: absolute; left: -16.5px; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(18,53,91,0.15);
}
.fstop .fname { flex: 1; min-width: 0; font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fstop .flvl { flex: none; font-size: 10px; color: var(--muted); font-weight: 600; }
.fjoin {
  position: relative; display: flex; align-items: center; gap: 6px;
  margin: 1px 0 1px 4px; padding: 3px 6px; border-radius: 7px; cursor: pointer;
  font-size: 10.5px; color: var(--muted); background: rgba(18,53,91,0.03);
}
.fjoin:hover { background: rgba(18,53,91,0.08); color: var(--ink); }
.fjoin svg { flex: none; color: var(--teal); }
.fjoin .fj-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.fjoin b { color: var(--ink); font-weight: 600; }
.finsight {
  margin: 2px 0 2px 4px; padding: 5px 9px; border-radius: 7px;
  font-size: 11px; line-height: 1.45; color: #9a4d0b;
  background: #fff7ed; border-left: 3px solid #d97706;
}
.fsea { position: relative; display: flex; align-items: center; gap: 7px; padding: 4px 4px 2px 6px; font-size: 10.5px; color: var(--muted); font-weight: 600; }
.fsea svg { position: absolute; left: -17px; background: #fff; border-radius: 50%; color: var(--rain); }

/* dam rows / cylinders */
.fdam {
  position: relative; display: flex; align-items: center; gap: 8px;
  margin: 1px 0 1px 4px; padding: 4px 6px; border-radius: 7px; cursor: pointer;
  font-size: 11px;
}
.fdam:hover { background: rgba(18,53,91,0.05); }
.fdam .fname { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fdam .fpct { flex: none; font-weight: 700; font-size: 10.5px; }
.cyl {
  position: relative; flex: none; width: 15px; height: 22px;
  border: 1.5px solid var(--muted); border-radius: 3px 3px 4px 4px;
  background: #fff; overflow: hidden;
}
.cyl::before { content: ""; position: absolute; left: 1px; right: 1px; top: -1px; height: 3px; border-radius: 50%; border: 1px solid rgba(18,53,91,0.2); }
.cyl .cfill { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(31,158,158,0.55); }
.cyl.low { border-color: var(--warning); } .cyl.low .cfill { background: rgba(232,89,12,0.5); }
.cyl.full { border-color: var(--navy); } .cyl.full .cfill { background: rgba(18,53,91,0.55); }
.cyl.big { width: 34px; height: 48px; border-width: 2px; }

/* dam map marker */
.dam-marker { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.dam-marker .cyl { box-shadow: 0 1px 4px rgba(18,53,91,0.35); }
.dam-marker .dm-pct {
  font: 700 9px var(--font); color: var(--navy); background: rgba(255,255,255,0.85);
  padding: 0 3px; border-radius: 4px; line-height: 1.3;
}

/* warning map marker */
.warn-marker {
  cursor: pointer; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: #fff7ed; color: #b45309; border: 2px solid #d97706; border-radius: 50%;
  box-shadow: 0 1px 5px rgba(18,53,91,0.3);
}

/* ---------- more tab ---------- */
.lead-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px; border-radius: 7px; cursor: pointer; font-size: 11.5px; }
.lead-row:hover { background: rgba(18, 53, 91, 0.05); }
.lead-row .lr-rank { flex: none; width: 14px; font-size: 10px; color: var(--muted); text-align: right; }
.lead-row .lr-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.lead-row .lr-where { flex: none; max-width: 88px; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-row .lr-val { flex: none; font-weight: 700; font-size: 11px; }
.more-note { font-size: 11px; color: var(--muted); line-height: 1.55; margin: 8px 0 0; }
.more-note a { color: var(--navy); }

/* ---------- mobile summary strip ---------- */
.now-open {
  position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 12px; right: 64px; z-index: 19;
  display: flex; align-items: center; gap: 10px;
  border: none; cursor: pointer; padding: 10px 14px;
  font: 600 12.5px var(--font); color: var(--ink);
}
.now-open .mini { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 700; }
.now-open .phrase { margin-left: auto; }
.now-open svg { color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- legend ---------- */
.legend {
  position: fixed; bottom: 26px; left: 12px; z-index: 18;
  padding: 9px 12px; font-size: 12px; max-width: 210px;
}
.legend .row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.legend .toggle-row { cursor: pointer; user-select: none; }
.legend input { accent-color: var(--navy); margin: 0 2px 0 0; }
.legend .keyrow { flex-wrap: wrap; gap: 4px 6px; margin-top: 7px; }
.legend .key { color: var(--muted); font-size: 10.5px; margin-right: 4px; }
.legend .keyhead { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-top: 7px; }
.legend summary { cursor: pointer; font-weight: 700; color: var(--navy); font-size: 12px; }
.legend .raindot { border-radius: 50%; flex: none; }

/* ---------- locate ---------- */
.locate {
  position: fixed; bottom: 110px; right: 12px; z-index: 18;
  border: none; width: 40px; height: 40px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--navy);
}

/* ---------- popup card ---------- */
.maplibregl-popup { z-index: 25; }
.maplibregl-popup-content {
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 15px 11px; font-family: var(--font); min-width: 264px;
}
.maplibregl-popup-close-button { font-size: 17px; padding: 4px 8px; color: var(--muted); }
.ttag {
  display: inline-block; font: 700 9px var(--font); letter-spacing: 0.8px;
  color: var(--teal); border: 1px solid rgba(31,158,158,0.45); border-radius: 4px;
  padding: 1px 5px; margin-bottom: 4px; text-transform: uppercase;
}
.ttag.rain { color: var(--rain); border-color: rgba(37,99,235,0.4); }
.ttag.dam { color: var(--navy); border-color: rgba(18,53,91,0.35); }
.ttag.warn { color: #b45309; border-color: rgba(217,119,6,0.45); }
.card h3 { margin: 0 0 2px; font-size: 14px; color: var(--navy); padding-right: 14px; }
.card .where { font-size: 11px; color: var(--muted); margin: 0 0 8px; }
.statusline { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.pill {
  font: 700 10.5px var(--font); color: #fff; padding: 3px 9px; border-radius: 5px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.pill.Normal { background: var(--normal); } .pill.Alert { background: var(--alert); }
.pill.Warning { background: var(--warning); } .pill.Danger { background: var(--danger); }
.pill.Stale { background: var(--stale); }
.big { font-size: 20px; font-weight: 800; color: var(--ink); }
.big small { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.gaugeline { margin: 2px 0 0; }
.sentence { font-size: 12px; line-height: 1.5; margin: 7px 0 0; }
.sentence b { color: var(--danger); }
.spark-wrap { margin-top: 8px; }
.spark-wrap .cap { display: block; font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.card .meta { font-size: 10px; color: var(--muted); margin: 7px 0 0; }
.card .source { font-size: 9.5px; color: var(--muted); margin: 6px 0 0; padding-top: 5px; border-top: 1px solid var(--line); }
.card .basin-link {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 7px;
  border: none; background: rgba(31,158,158,0.1); color: var(--teal); cursor: pointer;
  font: 600 11px var(--font); padding: 4px 9px; border-radius: 6px;
}
.card .basin-link:hover { background: rgba(31,158,158,0.2); }
.dam-pop { display: flex; gap: 12px; align-items: center; margin: 4px 0 6px; }
.dam-pop .dp-nums { flex: 1; font-size: 11px; line-height: 1.6; color: var(--muted); }
.dam-pop .dp-nums b { color: var(--ink); font-size: 13px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(18, 53, 91, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card { position: relative; max-width: 540px; width: 100%; max-height: 84vh; overflow-y: auto; padding: 20px 22px; }
.modal-x { position: absolute; top: 10px; right: 10px; }
.modal-card h2 { color: var(--navy); margin: 0 0 10px; font-size: 17px; }
.modal-card h3 { color: var(--navy); font-size: 13.5px; margin: 15px 0 5px; }
.modal-card p, .modal-card li { font-size: 13px; line-height: 1.6; }
.warn-item { border-left: 3px solid #d97706; padding: 6px 10px; margin: 10px 0; background: #fff7ed; border-radius: 6px; font-size: 12.5px; line-height: 1.55; }
.warn-item .wt { font-size: 10.5px; color: var(--muted); }

.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .only-mobile { display: inline-flex; }
  .now {
    top: auto; bottom: 0; left: 0; right: 0; width: 100%;
    border-radius: var(--radius) var(--radius) 0 0; max-height: 68vh;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .legend { bottom: auto; top: 56px; }
  .locate { bottom: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
