/* =========================================================================
   Utah Water Conditions — Next-Gen Measurement Dashboard (concept)
   Design tokens + app shell + components
   ========================================================================= */

:root {
  /* surfaces — neutrals tinted toward the navy/teal brand hue */
  --bg:            #EDF2F2;
  --surface:       #FFFFFF;
  --surface-2:     #F5F9F8;
  --topbar:        #142D3E;   /* State of Michigan navy */
  --topbar-2:      #1B394D;

  /* ink */
  --ink:           #142630;
  --ink-2:         #3D5560;
  --muted:         #5B7480;
  --ink-inverse:   #FFFFFF;
  --inverse-2:     rgba(255,255,255,.72);

  /* action — State of Michigan teal */
  --primary:       #277C78;
  --primary-hover: #1E605D;
  --primary-light: #E0EFED;
  --selected-bg:   #F9FBFB;   /* 3% brand tint: every text on the selected card stays AA */

  /* categorical — site types (fixed order: stream, dam, well, lake)
     validated with the dataviz palette checks (pairs: all, light surface):
     worst CVD pair 7.4 ΔE — legal with the secondary encodings in place
     (legend, hover/list labels, larger Great Lakes gauge radius) */
  --c-stream:      #2C6FBF;
  --primary-strong: #1B5C59;   /* teal for text on primary-light (6.6:1) */
  --c-dam:         #C05F2B;
  --c-well:        #0E8F73;
  --c-lake:        #9C4D93;

  /* status (reserved) */
  --ok:            #1A7A46;
  --ok-bg:         #DCF3E4;
  --warn:          #8A5F00;   /* 4.9:1 on the warn tint, 5.3:1 on zebra */
  --warn-bg:       #FCEFCE;
  --bad:           #B42318;
  --bad-bg:        #FDE4E1;
  --neutral:       #5B7183;
  --neutral-bg:    #E9EEF2;

  /* lines */
  --border:        rgba(20,45,62,.10);
  --border-strong: rgba(20,45,62,.18);
  --border-ui:     #7F909C;   /* ≥3:1 vs surface — WCAG 1.4.11 control boundaries */
  --divider:       #E2EAEA;

  /* depth */
  --shadow-sm: 0 1px 3px rgba(20,45,62,.06), 0 0 0 1px rgba(20,45,62,.04);
  --shadow-md: 0 4px 18px rgba(20,45,62,.10), 0 0 0 1px rgba(20,45,62,.05);
  --shadow-lg: 0 16px 48px rgba(20,45,62,.16), 0 0 0 1px rgba(20,45,62,.05);

  /* skeletons */
  --skel-1: #E4EBEB;
  --skel-2: #F2F7F6;

  /* list row separator + table zebra */
  --row-sep: #D0D0D0;
  --zebra: #F7F7F7;

  /* shape */
  --r:    12px;
  --r-sm: 8px;
  --r-xs: 6px;
  --r-pill: 100px;

  /* type */
  --font-ui:   'Montserrat', -apple-system, 'Segoe UI', sans-serif;
  --font-data: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;

  /* motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  /* layout */
  --topbar-h: 64px;
  --kpi-h: 124px;
  --sidebar-w: 340px;
  --drawer-w: 432px;
}

/* ---------- dark theme ----------
   Same token contract, night-shift surfaces: navy-tinted darks, teal action
   lightened for contrast, data-mark palette re-stepped for the dark surface
   (validated separately — see app.js PALETTES). */
:root[data-theme="dark"] {
  --bg:            #0E1A22;
  --surface:       #152631;
  --surface-2:     #1A2E3B;
  --topbar:        #0B161E;
  --topbar-2:      #12242F;

  --ink:           #E7EEF1;
  --ink-2:         #B7C7CF;
  --muted:         #8198A3;

  --primary:       #45A6A0;
  --primary-hover: #5FBFB9;
  --primary-light: rgba(69,166,160,.16);
  --selected-bg:   var(--surface);   /* a lighter tint would pull the status colors under AA */

  --c-stream:      #4E8BD9;
  --c-stream-text: #649BE0;    /* dot blue is too dim as text on dark rows */
  --primary-strong: #8FD3CC;   /* teal for text on primary-light (7.1:1) */
  --c-dam:         #D0713A;
  --c-well:        #1E9A72;
  --c-lake:        #BC62B0;

  --ok:            #6FCF97;   /* lifted: 5.4:1 on the tinted ok background */
  --ok-bg:         rgba(85,182,133,.16);
  --warn:          #D9A83E;
  --warn-bg:       rgba(217,168,62,.16);
  --bad:           #E06B5F;
  --bad-bg:        rgba(224,107,95,.16);
  --neutral:       #8198A3;
  --neutral-bg:    rgba(129,152,163,.16);

  --border:        rgba(231,238,241,.09);
  --border-strong: rgba(231,238,241,.18);
  --border-ui:     rgba(231,238,241,.42);
  --divider:       #22384470;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.35), 0 0 0 1px rgba(231,238,241,.05);
  --shadow-md: 0 4px 18px rgba(0,0,0,.42), 0 0 0 1px rgba(231,238,241,.06);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.55), 0 0 0 1px rgba(231,238,241,.06);

  --skel-1: #1C3140;
  --skel-2: #24404F;

  --row-sep: rgba(231,238,241,.16);
  --zebra: rgba(231,238,241,.05);
}
:root[data-theme="dark"] .maplibregl-popup-content { background: var(--surface-2); color: var(--ink); }
:root[data-theme="dark"] .maplibregl-popup-tip { border-top-color: var(--surface-2) !important; }
:root[data-theme="dark"] .chart-tip { background: #223A48; }
:root[data-theme="dark"] .api-block { background: #0B161E; }
:root[data-theme="dark"] .city-label { color: #7E96A2; text-shadow: none; }
:root[data-theme="dark"] .city-label::before { background: #7E96A2; }
:root[data-theme="dark"] .map-note,
:root[data-theme="dark"] .maplibregl-ctrl-attrib,
:root[data-theme="dark"] .map-legend { background: rgba(21,38,49,.92); }
:root[data-theme="dark"] .map-btn { background: rgba(21,38,49,.95); }
:root[data-theme="dark"] .toast { background: #223A48; }

/* ---------- reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
  /* halo under and around the ring, so it reads on navy (2.9:1 alone) as well as on white */
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 6px var(--surface);
  z-index: 3;
}
/* rows inside scrolling lists: an inset ring is never clipped by the container */
.qc-card:focus-visible, .menu-item:focus-visible, .d-photo-thumb:focus-visible {
  outline-offset: -3px;
  box-shadow: none;
}
.maplibregl-canvas:focus-visible { outline: 2px solid var(--primary); outline-offset: -4px; box-shadow: none; }

.u-sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num { font-family: var(--font-data); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* ---------- press feedback (every pressable element) ---------- */
.icon-btn:active, .map-btn:active, .chip:active, .btn-xs:active,
.range-btn:active, .btn-primary:active,
.drawer-close:active, .sidebar-fab:active, .clear-btn:active {
  scale: .96;
}
/* elements with their own transition shorthand get scale appended in place */
.drawer-close, .sidebar-fab, .clear-btn {
  transition: scale .16s var(--ease-out);
}

/* ---------- tooltips (CSS-only, delayed first paint) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px); left: 50%; translate: -50% 0;
  background: var(--ink); color: var(--bg);
  font-size: 0.6875rem; font-weight: 600; font-family: var(--font-ui);
  white-space: nowrap;
  padding: 4px 9px; border-radius: 6px;
  box-shadow: var(--shadow-md);
  opacity: 0; scale: .97;
  pointer-events: none;
  z-index: 400;
  transition: opacity .125s var(--ease-out), scale .125s var(--ease-out);
}
[data-tip]:focus-visible::after {
  opacity: 1; scale: 1;
  transition-delay: .35s;
}
[data-tip][data-tip-pos="bottom-end"]::after { left: auto; right: 0; translate: 0 0; }
[data-tip][data-tip-pos="left"]::after {
  top: 50%; left: auto; right: calc(100% + 8px);
  translate: 0 -50%;
}
@media (hover: none) { [data-tip]::after { display: none; } }

/* ---------- skeleton loading states ---------- */
.skel {
  position: relative;
  overflow: hidden;
  background: var(--skel-1);
  border-radius: var(--r-xs);
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}
.skel::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--skel-2), transparent);
  translate: -100% 0;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { to { translate: 100% 0; } }

.skel-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  column-gap: 11px;
  padding: 10px 12px;
}
.skel-dot { width: 9px; height: 9px; border-radius: 50%; }
.skel-line { height: 11px; }

/* =========================================================================
   TOPBAR
   ========================================================================= */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  color: var(--ink);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px 0 20px;
  position: relative;
  z-index: 60;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

/* State of Michigan pattern: square teal tile with the state outline */
.brand-mark {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  background: #0E5B85;             /* the same blue drop mark as the case study and the favicon */
  border-radius: var(--r-sm);
}
.brand-mark svg { display: block; }

.brand-name { font-size: 1rem; font-weight: 700; letter-spacing: -0.015em; white-space: nowrap; color: var(--ink); }
.brand-sub  { font-size: 0.7188rem; color: var(--muted); white-space: nowrap; margin-top: 3px; }

/* collapsible search: icon by default, the field slides open to the left */
.topbar-search { display: flex; align-items: center; gap: 6px; }
.topbar-search input {
  width: 0;
  height: 36px;
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--ink);
  opacity: 0;
  transition: opacity .15s var(--ease-out), border-color .15s, box-shadow .15s;   /* width snaps; only paint properties animate */
}
.topbar-search.open input {
  width: 320px;
  padding: 0 12px;
  border-color: var(--border-strong);
  opacity: 1;
}
.topbar-search input::placeholder { color: var(--muted); }
.topbar-search.open input:focus {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(39,124,120,.14);
  outline: none;
}
.topbar-search.open input { padding-right: 34px; }
.topbar-search input::-webkit-search-cancel-button { display: none; }

.search-field { position: relative; display: flex; align-items: center; }
.search-clear {
  position: absolute; right: 5px; top: 50%; translate: 0 -50%;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.search-clear:focus-visible { background: var(--neutral-bg); color: var(--ink); }
.search-clear[hidden] { display: none; }

/* the search trigger reads as a button: filled neutral with a visible boundary */
.search-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border-ui);
  color: var(--ink-2);
}
.topbar-search.open .search-toggle {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.topbar-spacer { flex: 1; }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--muted);
  transition: background .15s, color .15s, scale .16s var(--ease-out);
  position: relative;
}

.bell-dot {
  position: absolute; top: 7px; right: 8px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #D64541;
  box-shadow: 0 0 0 2px var(--surface);
}

/* visible only in Internal mode, now that the audience switch lives in the menu */
.mode-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: .03em;
  min-height: 24px;
  color: var(--primary-strong);
  background: var(--primary-light);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  margin-right: 4px;
  white-space: nowrap;
}
.mode-chip[hidden] { display: none; }
.mode-chip { cursor: pointer; transition: background .15s, scale .16s var(--ease-out); }
.mode-chip:active { scale: .97; }
.mode-chip .mode-chip-sep { opacity: .5; }
.mode-chip .mode-chip-flag { color: var(--warn); font-size: 0.6875rem; line-height: 1; }
.mode-chip .num { font-size: 0.7188rem; letter-spacing: 0; }

.topbar-divider {
  width: 1px; height: 26px;
  background: var(--divider);
  margin: 0 4px;
  flex: none;
}

/* theme toggle shows the icon of the theme you'd switch TO */
#theme-btn .ic-sun { display: none; }
:root[data-theme="dark"] #theme-btn .ic-sun { display: block; }
:root[data-theme="dark"] #theme-btn .ic-moon { display: none; }

.avatar {
  width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  background: linear-gradient(140deg, #C05F2B, #96431A);
  display: grid; place-items: center;
  font-size: 0.6875rem; font-weight: 700; color: #fff;
}

/* account button: avatar + chevron (8px apart) that opens a small menu */
.user-menu { position: relative; margin-left: 2px; }
.user-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--r-pill);
  color: var(--muted);
  transition: background .15s, color .15s, scale .16s var(--ease-out);
}
.user-btn:active { scale: .97; }
.user-chev { flex: none; transition: rotate .18s var(--ease-out); }
.user-btn[aria-expanded="true"] .user-chev { rotate: 180deg; }

.menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 232px;
  background: var(--surface);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 90;
  transform-origin: top right;
  animation: menuIn .15s var(--ease-out) both;
}
@keyframes menuIn { from { opacity: 0; scale: .96; } }
.menu-head {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 4px;
  display: flex; flex-direction: column; gap: 3px;
}
.menu-name { font-size: 0.8125rem; font-weight: 700; color: var(--ink); }
.menu-sub  { font-size: 0.6875rem; color: var(--muted); }
.menu-item {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--r-xs);
  font-size: 0.7812rem; font-weight: 500;
  color: var(--ink-2);
  text-align: left;
  transition: background .12s, color .12s;
}
.menu-item:focus-visible { background: var(--surface-2); color: var(--ink); }
.menu-item svg { color: var(--muted); flex: none; }

.menu-label {
  display: block;
  font-size: 0.625rem; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px 4px;
}
.menu-check { margin-left: auto; opacity: 0; color: var(--primary) !important; }
/* the state in words beside the check, so it never depends on color alone */
.menu-state { margin-left: auto; font-size: 0.6875rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.menu-state + .menu-check { margin-left: 0; }
.menu-item[aria-checked="true"] .menu-state { color: var(--primary-strong); }
.menu-item[aria-checked="true"] { color: var(--ink); font-weight: 600; }
.menu-item[aria-checked="true"] .menu-check { opacity: 1; }
.menu-divider { display: block; height: 1px; background: var(--divider); margin: 6px 4px; }

a.menu-item { text-decoration: none; color: inherit; }
.menu-item.danger { color: var(--bad); }
.menu-item.danger svg { color: var(--bad); }
.menu-item.danger:focus-visible { background: var(--bad-bg); color: var(--bad); }

/* =========================================================================
   KPI STRIP
   ========================================================================= */
/* KPI band: a navy "eyebrow" under the white header — indicators live ON
   the band (no cards), separated by hairlines. Gives the brand navy a job. */
.kpis {
  min-height: var(--kpi-h);
  display: grid;
  grid-template-columns: repeat(5, 1fr) auto;
  align-items: stretch;
  gap: 0;
  padding: 0 24px;
  background: var(--topbar);
  color: #F2F6F8;
}
:root[data-theme="dark"] .kpis { background: var(--topbar-2); }

/* density toggle: expanded cards ↔ one compact line (preference persisted) */
:root[data-kpi="compact"] { --kpi-h: 48px; }
:root[data-kpi="compact"] .kpis { display: flex; align-items: center; gap: 12px; padding: 8px 20px; }
:root[data-kpi="compact"] .kpi { display: none; }

.kpi-compact {
  display: none;
  order: -1;
  flex: 1; min-width: 0;
  font-size: 0.75rem; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: kpiIn .2s var(--ease-out) both;
}
:root[data-kpi="compact"] .kpi-compact {
  display: flex; align-items: center; flex-wrap: wrap;
  row-gap: 4px;
  white-space: normal; overflow: visible;
}
.kpi-compact .num { font-size: 0.7812rem; font-weight: 600; color: var(--ink); }
.kpi-compact .kpi-item { display: inline-block; white-space: nowrap; }
.kpi-compact .delta { margin-left: 4px; }
.kpi-compact .arrow { margin-right: 4px; }
/* separator = 1px hairline (a middot vanishes at this size) */
.kpi-compact .sep {
  flex: none; width: 1px; height: 12px;
  margin: 0 12px;
  background: currentColor; color: var(--muted);
  font-size: 0; line-height: 0;
}
.kpi-compact .lbl { color: var(--muted); font-family: var(--font-ui); font-size: 0.75rem; font-weight: 600; }
.kpi-compact .up { color: var(--ok); } .kpi-compact .down { color: var(--bad); }

.kpi-toggle {
  order: 10;
  align-self: center;
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--muted);
  border: 1px solid var(--border-ui);
  background: var(--surface);
  transition: background .15s, color .15s, scale .16s var(--ease-out);
}
.kpi-toggle:active { scale: .96; }
.kpi-toggle svg { transition: rotate .18s var(--ease-out); }
.kpi-toggle[aria-expanded="false"] svg { rotate: 180deg; }

/* --- band skin: everything inside the KPI strip reads on navy --- */
/* all band text ≥ 7:1 on navy (AAA); numbers brighter than labels */
.kpis .kpi-label { color: rgba(255,255,255,.80); }
.kpis .kpi-value { color: #F2F6F8; }
.kpis .kpi-value small { color: rgba(255,255,255,.74); }
.kpis .kpi-delta.up   { color: #7BD9A2; }
.kpis .kpi-delta.down { color: #F7A39A; }
.kpis .kpi-delta.flat { color: rgba(255,255,255,.74); }
.kpis .kpi-spark { color: #8DBDF2; }
.kpis .kpi-compact { color: rgba(255,255,255,.80); }
.kpis .kpi-compact .num { color: #F2F6F8; }
.kpis .kpi-compact .lbl { color: rgba(255,255,255,.80); }
.kpis .kpi-compact .sep { color: rgba(255,255,255,.5); }
.kpis .kpi-compact .up   { color: #7BD9A2; }
.kpis .kpi-compact .down { color: #F7A39A; }
.kpis .kpi-toggle {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.38);
  color: rgba(255,255,255,.85);
  margin-left: 16px;
}
.kpis .skel { --skel-2: rgba(255,255,255,.28); background: rgba(255,255,255,.14); }

/* the five cards share one wrapper so phones can turn them into a scroll strip;
   on wider screens it dissolves and the band stays a single grid */
.kpi-strip { display: contents; }
:root[data-kpi="compact"] .kpi-strip { display: none; }

.kpi {
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  position: relative;
  overflow: hidden;
  animation: kpiIn .3s var(--ease-out) both;
}
.kpi:first-of-type { padding-left: 0; }
.kpi + .kpi { border-left: 1px solid rgba(255,255,255,.12); }
.kpi[hidden] { display: none; }   /* a provider without that indicator */
.kpi:nth-child(2) { animation-delay: .04s; }
.kpi:nth-child(3) { animation-delay: .08s; }
.kpi:nth-child(4) { animation-delay: .12s; }
.kpi:nth-child(5) { animation-delay: .16s; }
@keyframes kpiIn { from { opacity: 0; translate: 0 6px; } }


.kpi-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

/* KPI titles: sentence case, same family/weight in expanded and compact */
.kpi-label {
  font-family: var(--font-ui);
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0; text-transform: none;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.kpi-value {
  font-family: var(--font-data);
  font-size: 1.375rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: var(--ink);
  line-height: 1.1;
  display: flex; align-items: baseline; gap: 6px;
}
.kpi-value small { font-size: 0.75rem; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi-delta {
  font-family: var(--font-data);
  font-size: 0.6562rem; font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.4;
  text-wrap: pretty;
}
.kpi-delta.up   { color: var(--ok); }
.kpi-delta.down { color: var(--bad); }
.kpi-delta.flat { color: var(--muted); }

/* the sparkline sits beside the value/delta rows (bottom-right); those two
   rows reserve its width, the label keeps the full width */
.kpi-spark {
  position: absolute; right: 22px; bottom: 22px; top: auto;
  opacity: .9;
}
.kpi:has(.kpi-spark) .kpi-value,
.kpi:has(.kpi-spark) .kpi-delta { padding-right: 104px; }

.kpi.kpi-alert { cursor: pointer; transition: box-shadow .15s, translate .15s; }
.kpi-alert .kpi-value { color: var(--warn); }

/* =========================================================================
   APP LAYOUT
   ========================================================================= */
.app {
  height: calc(100vh - var(--topbar-h) - var(--kpi-h));
  display: flex;
  padding: 0 20px 0 0;   /* sidebar is docked: no left gutter */
  gap: 14px;
  position: relative;
}
/* the floating panels keep a 20px gutter above and below (matching the right
   gutter) so they breathe off the KPI band; the docked sidebar runs full height */
.app > .map-wrap, .app > .drawer { margin: 20px 0; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
/* scroll affordance: a fade at the bottom while there is more list below;
   gone when the list ends (or doesn't overflow at all) */
.sidebar::after {
  content: '';
  position: absolute; left: 0; right: 1px; bottom: 0;
  height: 72px;
  /* reaches full surface color early so the last row is clearly veiled */
  background: linear-gradient(to bottom, transparent 0%, var(--surface) 65%, var(--surface) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s var(--ease-out);
}
.sidebar.has-more::after { opacity: 1; }

.sidebar-tabs {
  display: flex;
  align-items: center;
  padding: 10px 12px 0;
  gap: 2px;
  border-bottom: 1px solid var(--divider);
}
.sidebar-toggle {
  margin-left: auto; margin-bottom: 6px;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-ui);
  color: var(--muted);
  transition: background .15s, color .15s, scale .16s var(--ease-out);
}
.sidebar-toggle:active { scale: .96; }

/* ---- collapsed rail (desktop only; mobile keeps the overlay) ---- */
.sidebar-rail { display: none; }
.rail-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--muted);
  position: relative;
  transition: background .15s, color .15s, scale .16s var(--ease-out);
}
body.internal .rail-btn.internal-only { display: grid; }
.rail-btn:active { scale: .96; }
.rail-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--warn-bg); color: var(--warn);
  font-family: var(--font-data); font-size: 0.5938rem; font-weight: 600;
  display: grid; place-items: center;
}
[data-tip][data-tip-pos="right"]::after {
  top: 50%; left: calc(100% + 8px); right: auto;
  translate: 0 -50%;
}
@media (min-width: 901px) {
  :root[data-sidebar="collapsed"] .sidebar { width: 52px; }
  :root[data-sidebar="collapsed"] .sidebar-tabs,
  :root[data-sidebar="collapsed"] .filters,
  :root[data-sidebar="collapsed"] .site-list,
  :root[data-sidebar="collapsed"] .qc-list { display: none !important; }
  :root[data-sidebar="collapsed"] .sidebar-rail {
    display: flex; flex-direction: column; align-items: center;
    gap: 6px; padding: 10px 0;
    animation: kpiIn .2s var(--ease-out) both;
  }
}
.sidebar-tab {
  font-size: 0.8125rem; font-weight: 600;
  color: var(--muted);
  padding: 8px 12px 10px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex; align-items: center; gap: 7px;
  transition: color .15s;
}
.sidebar-tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.sidebar-tab .count {
  font-family: var(--font-data); font-size: 0.625rem; font-weight: 600;
  background: var(--neutral-bg); color: var(--ink-2);
  border-radius: var(--r-pill); padding: 1px 7px;
}
.sidebar-tab .count.warn { background: var(--warn-bg); color: var(--warn); }

.sidebar-tab.internal-only { display: none; }
body.internal .sidebar-tab.internal-only { display: flex; }

/* filters */
.filters { padding: 12px 16px 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--divider); }

/* disclosure bar: one line that summarizes the selection; controls unfold on demand */
/* two rows: [Filters ▾ ........ count] / [selection summary ........ Reset] */
.filters-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px; row-gap: 7px;
  min-width: 0;
}
.filters-toggle { grid-area: 1 / 1; justify-self: start; }
.filters-summary { grid-area: 2 / 1; }
.filters-bar .clear-btn { grid-area: 2 / 2; }
.filters-count {
  grid-area: 1 / 1 / 2 / 3;   /* spans both columns so the long count never widens column 2 */
  justify-self: end;
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--font-data); font-size: 0.6875rem; font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  white-space: nowrap;
}
.filters-bar .clear-btn {
  justify-self: end;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7188rem; font-weight: 600; color: var(--primary);
}
.filters-bar .clear-btn[hidden] { display: none; }
.filters-toggle {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 0.75rem; font-weight: 600;
  color: var(--ink-2);
  border: 1px solid var(--border-ui);
  border-radius: var(--r-pill);
  padding: 4px 9px 4px 8px;
  transition: background .15s, color .15s, scale .16s var(--ease-out);
}
.filters-toggle:active { scale: .97; }
.filters-toggle .count { margin-left: 2px; }
.filters-toggle .count[hidden] { display: none; }
.filters-chev { transition: rotate .18s var(--ease-out); }
.filters-toggle[aria-expanded="true"] .filters-chev { rotate: 180deg; }
.filters-toggle[aria-expanded="true"] { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.filters-summary {
  flex: 1; min-width: 0;
  grid-area: 2 / 1 / 3 / 3;            /* full width; Reset sits inside, at the right */
  font-size: 0.625rem; font-weight: 500; color: var(--ink-2);
  background: var(--summary-bg, #EAF1F4);
  border-radius: 2px;
  padding: 2px 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.filters-bar:has(.clear-btn:not([hidden])) .filters-summary { padding-right: 60px; }
.filters-bar .clear-btn { margin-right: 4px; }
:root[data-theme="dark"] .filters-summary { --summary-bg: rgba(231,238,241,.08); }
.filters-summary b { color: var(--ink-2); font-weight: 600; }
.filters-body { display: flex; flex-direction: column; gap: 11px; padding-top: 2px; animation: kpiIn .18s var(--ease-out) both; }
.filters-body[hidden] { display: none; }

.filter-row { display: flex; gap: 8px; }

/* control labels: sentence case, same voice as the KPI titles */
.f-label {
  display: block;
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0; text-transform: none;
  color: var(--muted);
  margin-bottom: 6px;
}

.select {
  flex: 1; min-width: 0;
  position: relative;
}
.select select {
  width: 100%;
  height: 32px;
  padding: 0 26px 0 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-ui);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.7812rem;
  font-weight: 500;
  appearance: none;
  cursor: pointer;
}
.select::after {
  content: '';
  position: absolute; right: 10px; bottom: 15px;
  width: 8px; height: 8px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  pointer-events: none;
}

/* type chips (legend = filter) */
/* type chips: an aligned 2×2 grid (never 3+1) */
.type-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  width: 100%; min-width: 0;
  white-space: normal; text-align: left; line-height: 1.2;   /* long provider labels wrap; the check stays visible */
  font-size: 0.75rem; font-weight: 600;
  color: var(--ink-2);
  border: 1px solid var(--border-ui);
  border-radius: var(--r-pill);
  padding: 5px 9px 5px 8px;
  transition: border-color .15s, background .15s, color .15s, scale .16s var(--ease-out);
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; transition: background .15s; }
.chip [data-type-chip] { flex: 1 1 auto; min-width: 0; }
/* explicit selected state (WCAG 1.4.1): a check, not just color/border */
.chip-check { margin-left: auto; flex: none; color: var(--primary); opacity: 0; transition: opacity .12s; }
.chip[aria-pressed="true"] .chip-check { opacity: 1; }
.chip[aria-pressed="true"] { background: var(--surface); }
/* off = dashed boundary + neutral dot; no opacity tricks (contrast holds in dark) */
.chip[aria-pressed="false"] { border-style: dashed; color: var(--muted); background: transparent; }
.chip[aria-pressed="false"] .dot { background: var(--border-ui); }

.dot-stream { background: var(--c-stream); }
.dot-dam    { background: var(--c-dam); }
.dot-well   { background: var(--c-well); }
.dot-lake   { background: var(--c-lake); }

.filter-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.7188rem; color: var(--muted);
}
#filter-summary {
  font-family: var(--font-data);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}
.filter-meta .clear-btn {
  font-size: 0.7188rem; font-weight: 600; color: var(--primary);
}

/* site list: one card per site */
.site-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 12px 16px;   /* room for the focus ring on every side */
  scroll-padding: 8px 0;
}
.site-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.site-card {
  width: 100%;
  text-align: left;
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color .12s, background-color .12s;
}
.site-card:focus-visible { box-shadow: none; }        /* cards sit in a gap: no halo needed */
.site-card.selected {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);         /* reads as a 2 px ring without moving the layout */
  background: var(--selected-bg);
}
.site-card.selected:focus-visible { box-shadow: inset 0 0 0 1px var(--primary); }
.site-card.selected .site-name { color: var(--primary-strong); }

.site-visual {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
}

/* type dot; on the selected card it becomes a check on the brand color, so the
   state has a shape as well as a color */
.site-mark { position: relative; width: 14px; height: 14px; display: grid; place-items: center; }
.site-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); transition: width .12s, height .12s, background-color .12s; }
.site-check { position: absolute; inset: 0; width: 14px; height: 14px; display: none; color: var(--surface); }
.site-card.selected .site-dot { width: 14px; height: 14px; background: var(--primary); }
.site-card.selected .site-check { display: block; }

/* QC pending marker: a flag before the name (internal mode only) */
.site-flag {
  display: none;
  color: var(--warn);
  font-size: 0.75rem; line-height: 1;
  margin-right: 5px;
  vertical-align: -1px;
}
body.internal .site-flag { display: inline-block; }

.site-main { min-width: 0; }
.site-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 0.85rem; font-weight: 600; line-height: 1.3; color: var(--ink);
}
.site-sub {
  display: block;
  font-size: 0.72rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 3px;
}

.site-val { text-align: right; }
.site-val .v { font-family: var(--font-data); font-size: 0.8125rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.site-val .u { font-size: 0.72rem; color: var(--muted); margin-left: 3px; }
.site-val .pct {
  font-family: var(--font-data);
  font-size: 0.72rem; font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: block; margin-top: 3px;
}
.pct.hi  { color: var(--c-stream-text, var(--c-stream)); }
.pct.ok  { color: var(--ok); }
.pct.lo  { color: var(--warn); }
.pct.vlo { color: var(--bad); }

.list-sentinel { text-align: center; padding: 10px 0 6px; margin: 0; font-size: 0.72rem; color: var(--muted); }
.btn-more {
  display: block; width: 100%;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--muted); border-radius: var(--r-sm);   /* 3:1+ boundary in both themes */
  font-size: 0.8rem; font-weight: 600; color: var(--primary-strong);
  background: var(--surface);
  transition: border-color .12s, background-color .12s;
}

/* the list when the data provider failed */
.list-error { padding: 8px 4px; font-size: 0.8rem; color: var(--ink-2); }
.list-error-title { font-weight: 600; color: var(--ink); margin: 0 0 6px; }
.list-error p { margin: 0 0 10px; }
.list-error-actions { display: grid; gap: 8px; margin: 12px 0; }
a.btn-more { text-decoration: none; display: flex; align-items: center; justify-content: center; }
.list-error details { font-size: 0.72rem; color: var(--muted); }
.list-error summary { cursor: pointer; }
.seed-note { font-size: 0.72rem; color: var(--muted); margin-top: 8px; }
.seed-note code { display: block; margin-top: 6px; overflow-wrap: anywhere; font-family: var(--font-data); color: var(--bad); }
.list-error code { display: block; margin-top: 6px; overflow-wrap: anywhere; font-family: var(--font-data); }

/* inline correction form on a QC card (live provider) */
.qc-form { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; margin-top: 10px; }
.qc-form-label { grid-column: 1 / -1; font-size: 0.6875rem; font-weight: 600; color: var(--muted); }
.qc-form input {
  min-width: 0; width: 100%; font: inherit; font-family: var(--font-data); font-size: 0.8125rem;
  padding: 5px 8px; border: 1px solid var(--border-ui); border-radius: var(--r-xs);
  background: var(--surface); color: var(--ink);
}
.qc-card.busy { opacity: .6; }
.btn-xs[disabled], .btn-more[disabled] { opacity: .55; cursor: default; }

/* demo token inside the account menu */
.menu-field { display: flex; gap: 6px; padding: 2px 12px 4px; }
.menu-field input {
  flex: 1; min-width: 0; font: inherit; font-size: 0.8125rem;
  padding: 6px 8px; border: 1px solid var(--border-ui); border-radius: var(--r-xs);
  background: var(--surface); color: var(--ink);
}
.menu-note { display: block; font-size: 0.6875rem; color: var(--muted); padding: 0 12px 8px; min-height: 1em; }

/* live providers publish no photos: say so instead of drawing one */
.d-photo-empty {
  aspect-ratio: 16 / 9; border-radius: var(--r-sm);
  border: 1px dashed var(--border-strong);
  display: grid; place-items: center;
  padding: 16px; text-align: center;
  font-size: 0.75rem; color: var(--ink-2);
}

/* Windows High Contrast and other forced palettes: keep the state and the type
   readable without our colors */
@media (forced-colors: active) {
  .site-card { border-color: CanvasText; }
  .site-card.selected { border: 2px solid Highlight; box-shadow: none; }
  .site-card.selected .site-name { color: Highlight; }
  .site-dot { forced-color-adjust: none; outline: 1px solid CanvasText; }
  .site-card.selected .site-dot { background: Highlight; }
  .site-check { forced-color-adjust: none; color: Canvas; }
  .btn-more { border-color: ButtonText; }
}

/* QC queue panel */
.qc-list { flex: 1; overflow-y: auto; padding: 8px; display: none; }
.qc-intro { font-size: 0.7188rem; color: var(--muted); padding: 4px 8px 10px; }

.qc-card {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.qc-card.done { opacity: .55; }

.qc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.qc-rule {
  font-size: 0.6875rem; font-weight: 700;
  color: var(--warn);
  background: var(--warn-bg);
  padding: 2px 8px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 5px;
}
.qc-card.done .qc-rule { color: var(--ok); background: var(--ok-bg); }
.qc-when { font-size: 0.6562rem; color: var(--muted); margin-left: auto; white-space: nowrap; }

.qc-site { font-size: 0.7812rem; font-weight: 600; color: var(--ink); cursor: pointer; }
.qc-detail { font-size: 0.7188rem; color: var(--ink-2); margin-top: 4px; }

.qc-actions { display: flex; gap: 6px; margin-top: 11px; }
.btn-xs {
  font-size: 0.7188rem; font-weight: 600;
  padding: 4px 11px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-strong);
  color: var(--ink-2);
  transition: background .12s, color .12s, border-color .12s, scale .16s var(--ease-out);
}
/* primary action of the card: filled, unmistakable next to the outlines */
.btn-xs.approve { color: #fff; background: var(--ok); border-color: var(--ok); }
:root[data-theme="dark"] .btn-xs.approve { color: #0E1A22; }

/* =========================================================================
   MAP
   ========================================================================= */
.map-wrap {
  flex: 1;
  position: relative;
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: var(--surface-2);
  min-width: 0;
}
#map { position: absolute; inset: 0; }

.map-offline-msg {
  position: absolute; inset: 0;
  display: none;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
  padding: 40px;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(44,111,191,.08), transparent 60%),
    var(--surface-2);
}
.map-wrap.offline .map-offline-msg { display: grid; }

/* overlay cards on the map */
.map-title {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 8px 13px;
  pointer-events: none;
}
.map-title h1 { font-size: 0.8125rem; font-weight: 700; letter-spacing: -0.01em; }
.map-title p  { font-size: 0.6875rem; color: var(--muted); margin-top: 3px; }

.map-actions {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: flex; flex-direction: column; gap: 6px;
}
.map-btn {
  width: 34px; height: 34px;
  background: rgba(255,255,255,.95);
  border: 1px solid var(--border-ui);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  display: grid; place-items: center;
  color: var(--ink-2);
  transition: color .15s, box-shadow .15s, scale .16s var(--ease-out);
}

.map-legend {
  position: absolute; left: 14px; top: 14px; z-index: 5;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 9px 12px;
  display: flex; flex-direction: column; gap: 5px;
  pointer-events: none;
}
.map-legend .lg-title {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0;
  text-transform: none; color: var(--muted);
  margin-bottom: 3px;
}
.lg-row { display: flex; align-items: center; gap: 7px; font-size: 0.7188rem; color: var(--ink-2); }
.lg-rows { display: flex; flex-direction: column; gap: 5px; }
/* data freshness lives with the map notes, where a cartographer expects it */
/* data freshness: its own card, bottom-left of the map */
.map-note {
  position: absolute; left: 14px; bottom: 10px; z-index: 5;   /* same baseline as the attribution */
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 6px 10px;
  pointer-events: none;
}
.lg-note {
  display: flex; align-items: center; gap: 4px;
  margin: 0; padding: 0; border: 0;
  font-family: var(--font-data); font-size: 0.6562rem;
  color: var(--ink-2);
  white-space: nowrap;
}
.lg-row .dot { width: 8px; height: 8px; border-radius: 50%; }

/* maplibre chrome */
.maplibregl-popup-content {
  font-family: var(--font-ui);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  padding: 10px 12px;
}
.maplibregl-popup-close-button { display: none; }
.mpop-name { font-size: 0.7812rem; font-weight: 700; }
.mpop-sub  { font-size: 0.6875rem; color: var(--muted); margin-top: 3px; }
.mpop-val  { font-family: var(--font-data); font-size: 0.8125rem; font-weight: 600; margin-top: 7px; }
.mpop-val small { font-size: 0.625rem; color: var(--muted); font-family: var(--font-ui); }
/* attribution styled as the twin of the data note: one row along the bottom */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 0 14px 10px 0; }
.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib.maplibregl-compact {
  font-family: var(--font-data); font-size: 0.6562rem; line-height: 14px;
  color: var(--ink-2);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 6px 10px;
  margin: 0 14px 10px 0;
  min-height: 14px;          /* MapLibre's 20px min-height would push it to 32px */
  white-space: nowrap;
}
.maplibregl-ctrl-attrib-inner { line-height: 14px; }
/* narrow map (drawer open on smaller screens): stack the attribution above the note */
@media (max-width: 1280px) {
  .app:has(.drawer.open) .maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin-bottom: 44px; }
}
.maplibregl-ctrl-attrib a { color: inherit; }
.maplibregl-ctrl-attrib.maplibregl-compact.maplibregl-compact-show { padding-right: 30px; }
.maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button { top: 1px; right: 3px; }

.city-label {
  font-family: var(--font-ui);
  font-size: 0.625rem; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  color: #8296A3;
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
  pointer-events: none;
}
.city-label::before {
  content: '';
  display: inline-block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #8296A3;
  margin-right: 5px;
  vertical-align: 1px;
}

/* =========================================================================
   DETAIL DRAWER
   ========================================================================= */
.drawer {
  width: 0;
  flex: none;
  /* the width change is a single reflow, never a per-frame animation: it
     snaps open at once (the content slides in), and on close it waits for
     the content to fade before collapsing */
  transition: width 0s linear .15s;
  overflow: hidden;
  border-radius: var(--r);
}
.drawer.open { width: var(--drawer-w); transition: width 0s; }
/* the panel's content is what the eye tracks: it slides/fades with
   transform + opacity while the width reflow happens underneath */
.drawer .drawer-inner {
  translate: 16px 0;
  opacity: 0;
  transition: translate .15s var(--ease-out), opacity .12s var(--ease-out);
}
.drawer.open .drawer-inner {
  translate: 0 0;
  opacity: 1;
  transition: translate .24s var(--ease-out) .06s, opacity .2s var(--ease-out) .06s;
}

.drawer-inner {
  width: var(--drawer-w);
  height: 100%;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
/* fade at the bottom while there is more detail below (same cue as the sidebar) */
.drawer-inner::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 72px;
  border-radius: 0 0 var(--r) var(--r);
  background: linear-gradient(to bottom, transparent 0%, var(--surface) 65%, var(--surface) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s var(--ease-out);
}
.drawer-inner.has-more::after { opacity: 1; }

.drawer-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.drawer-head {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--divider);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 2;
}
.drawer-close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--muted);
}

.d-id { font-family: var(--font-data); font-size: 0.6875rem; color: var(--muted); letter-spacing: .02em; }
.d-name { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.015em; margin: 5px 34px 10px 0; line-height: 1.25; }

.d-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.6875rem; font-weight: 600;
  border-radius: var(--r-pill);
  padding: 3px 10px;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge-type { background: var(--neutral-bg); color: var(--ink-2); }
.badge-ok      { background: var(--ok-bg); color: var(--ok); }
.badge-warn    { background: var(--warn-bg); color: var(--warn); }
.badge-bad     { background: var(--bad-bg); color: var(--bad); }
.badge-neutral { background: var(--neutral-bg); color: var(--ink-2); }

/* current value hero */
.d-hero {
  padding: 18px 20px 6px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.d-hero-label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--muted); }
.d-hero-value {
  font-family: var(--font-data);
  font-size: 2.125rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin-top: 6px;
  color: var(--ink);
}
.d-hero-value small { font-size: 0.875rem; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.d-hero-meta { font-size: 0.7188rem; color: var(--muted); margin-top: 7px; }
.d-hero-pct { text-align: right; padding-top: 18px; }
.d-hero-pct .n { font-family: var(--font-data); font-size: 1.0625rem; font-weight: 600; }
.d-hero-pct .t { display: block; font-size: 0.6562rem; color: var(--muted); margin-top: 4px; }

/* chart */
.d-chart-card { padding: 8px 6px 0 0; }
.d-chart-tools {
  display: flex; align-items: center;
  padding: 8px 20px 2px;
  gap: 4px;
}
.range-label {
  display: inline-flex; align-items: center; gap: 5px;
  margin: 0;
}
.range-label svg { flex: none; opacity: .8; }
.range-group {
  display: flex; gap: 4px;
  margin-left: auto;
}
.range-btn {
  font-size: 0.7188rem; font-weight: 600;
  color: var(--muted);
  min-height: 28px; padding: 6px 12px;
  border-radius: var(--r-pill);
  transition: background .12s, color .12s, scale .16s var(--ease-out);
}
.range-btn[aria-pressed="true"] { background: var(--primary-light); color: var(--primary-strong); }

.chart-host { position: relative; }
.chart-host svg { display: block; width: 100%; height: auto; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 0.6875rem;
  border-radius: var(--r-xs);
  padding: 5px 9px;
  translate: -50% 0;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s;
  z-index: 3;
}
.chart-tip .tv { font-family: var(--font-data); font-weight: 600; font-size: 0.75rem; }
.chart-tip .td { color: rgba(255,255,255,.7); }

/* stats row */
.d-stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  margin: 12px 20px 0;
}
.d-stat { padding: 11px 4px 12px; text-align: center; }
.d-stat + .d-stat { border-left: 1px solid var(--divider); }
.d-stat .l { display: block; font-size: 0.7188rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--muted); }
.d-stat .v { display: block; font-family: var(--font-data); font-size: 0.9062rem; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }

/* sections */
.d-section { padding: 16px 20px; }
.d-section + .d-section { border-top: 1px solid var(--divider); }
.d-section h3 {
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0; text-transform: none;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.d-section h3 .spacer { flex: 1; }

/* station views (drawer): one main illustration, three selectable views */
.d-photos { padding: 12px 20px 0; }
.d-photo-main { position: relative; aspect-ratio: 16 / 9; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); }
.d-photo-main svg, .d-photo-thumb svg { display: block; width: 100%; height: 100%; }
.d-photo-tag {
  position: absolute; right: 8px; top: 8px;
  font-size: 0.625rem; font-weight: 600; letter-spacing: 0;
  color: #FFFFFF; background: rgba(20,45,62,.76);
  padding: 2px 7px; border-radius: var(--r-pill);
  backdrop-filter: blur(4px);
}
.d-photo-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.d-photo-thumb {
  position: relative; aspect-ratio: 16 / 9;
  border-radius: var(--r-xs); overflow: hidden;
  border: 2px solid transparent;
  padding: 0;
  transition: border-color .15s, scale .16s var(--ease-out);
}
.d-photo-thumb:active { scale: .97; }
.d-photo-thumb[aria-selected="true"] { border-color: var(--primary); }
.d-photo-thumb span {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 0.5938rem; font-weight: 600; color: #FFFFFF;
  background: linear-gradient(to top, rgba(20,45,62,.72), transparent);
  padding: 10px 6px 3px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.d-photo-cap { font-size: 0.6875rem; color: var(--muted); margin-top: 6px; }
.d-photo-cap .num { font-size: 0.6875rem; color: var(--ink-2); }

/* calendar heatmap (drawer) */
.d-section h3 .h3-sub { font-weight: 500; color: var(--muted); }
.hm-host { position: relative; }
.hm-host svg { display: block; width: 100%; height: auto; }
.hm-legend {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 3px;
  margin-top: 10px;
  font-size: 0.6562rem; color: var(--muted);
}
.hm-legend .hm-end { font-weight: 600; margin: 0 3px; }
.hm-legend .hm-swatch { display: inline-flex; }
.hm-legend .hm-swatch i { display: block; width: 14px; height: 10px; border-radius: 2px; }
.hm-legend .spacer { flex: 1; }
.hm-caption { font-size: 0.6562rem; color: var(--ink-2); white-space: nowrap; }
.hm-caption .num { font-size: 0.6562rem; font-weight: 600; }
.hm-host .chart-tip { top: 0; }

/* provisional notice (public mode) */
.provisional {
  margin: 14px 20px 0;
  font-size: 0.7188rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  display: flex; gap: 8px; align-items: flex-start;
}
.provisional svg { flex: none; margin-top: 1px; color: var(--muted); }
body.internal .provisional { display: none; }

/* observations table (internal) */
.obs-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.obs-table th {
  text-align: left; font-size: 0.7188rem; font-weight: 600;
  letter-spacing: 0; text-transform: none;
  color: var(--muted);
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--divider);
}
.obs-table td { padding: 7px 8px; border-bottom: 1px solid var(--divider); }
.obs-table tbody tr:nth-child(even) td { background: var(--zebra); }
.obs-table tr:last-child td { border-bottom: none; }
.obs-table .num { font-size: 0.75rem; }
.obs-flag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.625rem; font-weight: 700;
  padding: 2px 7px; border-radius: var(--r-pill);
}
.obs-flag svg { flex: none; }
.obs-flag.ok   { background: var(--ok-bg); color: var(--ok); }
.obs-flag.warn { background: var(--warn-bg); color: var(--warn); }

.internal-only { display: none; }
body.internal .internal-only { display: block; }

/* metadata / API block */
.meta-grid {
  display: grid; grid-template-columns: auto 1fr;
  gap: 0; font-size: 0.75rem;
  margin: 0 -8px;             /* bands run a little past the text, like list rows */
}
.meta-grid dt, .meta-grid dd { padding: 7px 8px; }
.meta-grid dt { color: var(--muted); white-space: nowrap; }
.meta-grid dd { color: var(--ink); font-weight: 500; text-align: right; overflow-wrap: anywhere; }
.meta-grid dd.num { font-size: 0.75rem; }
.meta-grid dt:nth-of-type(even), .meta-grid dd:nth-of-type(even) { background: var(--zebra); }
.meta-grid dt:not(:first-of-type), .meta-grid dd:not(:first-of-type) { border-top: 1px dotted var(--row-sep); }

.api-block {
  margin-top: 10px;
  background: #0F2937;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-family: var(--font-data);
  font-size: 0.6562rem;
  line-height: 1.6;
  color: #B7D3E2;
  overflow-x: auto;
  white-space: nowrap;
}
.api-block .method { color: #7BD88F; font-weight: 600; }
.api-block .path   { color: #E8F1F6; }
.api-block .qs     { color: #8FB8CE; }
.api-copy {
  float: right;
  font-size: 0.6875rem; font-weight: 600; font-family: var(--font-ui);
  min-height: 26px; padding: 4px 8px; margin: -4px -6px 2px 8px;
  border-radius: var(--r-xs);
  color: #7FC4BE;                    /* 7.6:1 on the block's ink, both themes */
}

/* drawer empty state */
.drawer-empty {
  height: 100%;
  display: grid; place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.7812rem;
  padding: 40px 30px;
}
.drawer-empty svg { margin: 0 auto 12px; display: block; color: var(--border-strong); }

/* =========================================================================
   OVERLAY SCRIM + MOBILE SIDEBAR
   ========================================================================= */
.scrim {
  position: fixed; inset: 0;
  background: rgba(13, 27, 36, .45);
  backdrop-filter: blur(2px);
  z-index: 34;
  opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease-out);
}
body.sidebar-open .scrim { opacity: 1; pointer-events: auto; z-index: 78; }
@media (max-width: 1080px) {
  body.has-drawer .scrim { opacity: 1; pointer-events: auto; }
}

.action-bar { display: none; }
.sidebar-fab {
  display: none;
  position: fixed; left: 16px; bottom: 18px;
  z-index: 70;
  align-items: center; gap: 8px;
  background: var(--topbar); color: #fff;
  font-size: 0.8125rem; font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-lg);
}
:root[data-theme="dark"] .sidebar-fab { background: var(--primary); color: #0E1A22; }
.sidebar-fab .fab-count {
  font-family: var(--font-data); font-size: 0.6875rem;
  font-variant-numeric: tabular-nums; opacity: .8;
}

/* =========================================================================
   TOAST + MODAL
   ========================================================================= */
.toast-host {
  position: fixed; bottom: 22px; left: 50%; translate: -50% 0;
  z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
/* transitions (not keyframes) so rapid successive toasts retarget smoothly;
   enter 200ms, exit 150ms */
.toast {
  background: var(--ink);
  color: #fff;
  font-size: 0.7812rem; font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 8px;
  opacity: 1; translate: 0 0;
  transition: opacity .2s var(--ease-out), translate .2s var(--ease-out);
  @starting-style { opacity: 0; translate: 0 8px; }
}
.toast svg { color: #6FCF97; }
.toast.leaving { opacity: 0; translate: 0 6px; transition-duration: .15s; }
@keyframes toastOut { to { opacity: 0; translate: 0 6px; } }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(13,43,59,.45);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  z-index: 300;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
/* exits faster than entries: users are done deciding */
.modal-overlay:not(.open), .modal-overlay:not(.open) .modal { transition-duration: .15s; }
.modal {
  width: min(560px, calc(100vw - 40px));
  max-height: min(640px, calc(100dvh - 60px));
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 26px 28px;
  transform: translateY(12px) scale(.98);
  transition: transform .25s cubic-bezier(.22,1,.36,1);
}
.modal-overlay.open .modal { transform: none; }
.modal h2 { font-size: 1.125rem; letter-spacing: -0.015em; margin-bottom: 4px; }
.modal .m-sub { font-size: 0.7812rem; color: var(--muted); margin-bottom: 16px; }
.modal p { font-size: 0.8125rem; color: var(--ink-2); line-height: 1.6; margin-bottom: 12px; }
.modal strong { color: var(--ink); }
.modal ul { margin: 0 0 12px 18px; }
.modal li { font-size: 0.8125rem; color: var(--ink-2); line-height: 1.6; margin-bottom: 4px; }
.modal-close {
  position: absolute;
  margin: 0;
}
.modal .modal-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.modal-link { margin-right: auto; align-self: center; display: inline-flex; align-items: center; min-height: 24px; font-size: 0.8125rem; font-weight: 600; color: var(--primary-strong); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  font-size: 0.8125rem; font-weight: 600;
  padding: 9px 20px;
  border-radius: var(--r-sm);
  transition: background .15s, scale .16s var(--ease-out);
}

/* =========================================================================
   RESPONSIVE
   The desktop layout (mouse, >=1280px) is the source design. Each tier below
   rethinks the arrangement for its viewport and input instead of shrinking it:
   - <=1280  tighter panels
   - <=1080  the detail drawer floats over the map
   - <=900   portrait tablets: body becomes a flex column, indicators 3 + 2
   - <=640   phones: app-like shell, map fills the viewport, panels overlay it
   ========================================================================= */
@media (max-width: 1280px) {
  :root { --drawer-w: 396px; --sidebar-w: 304px; }
  .kpis { grid-template-columns: repeat(5, 1fr) auto; }
  .kpi-value { font-size: 1.25rem; }
}

@media (max-width: 1080px) {
  .app > .drawer { position: absolute; right: 16px; top: 20px; bottom: 20px; margin: 0; z-index: 40; width: auto; }
  .drawer.open { width: min(var(--drawer-w), calc(100vw - 48px)); }
  .drawer-inner { box-shadow: var(--shadow-lg); }
}

@media (max-width: 900px) {
  /* the band is no longer a fixed height, so the shell stacks with flex
     instead of the desktop 100vh subtraction */
  body { display: flex; flex-direction: column; }
  .topbar, .kpis { flex: none; }
  .app { flex: 1; min-height: 0; height: auto; }
  .brand { min-width: 0; flex: 1; }
  .brand > div { min-width: 0; }
  .brand-name { overflow: hidden; text-overflow: ellipsis; }
  .topbar { gap: 10px; padding: 0 12px 0 14px; }
  .topbar-spacer { flex: 0; }        /* the title, not the gap, gets the spare width */
  .sidebar-toggle { display: none; }   /* docked panel, no rail below 901px */
}

/* portrait tablets: five indicators on one row would truncate every label */
@media (min-width: 641px) and (max-width: 900px) and (min-height: 501px) {
  .kpis { height: auto; grid-template-columns: repeat(6, 1fr) auto; padding: 8px 20px 10px; }
  .kpi { grid-column: span 2; padding: 10px 18px; }
  .kpi:nth-of-type(n+4) { grid-column: span 3; border-top: 1px solid rgba(255,255,255,.12); }
  .kpi:nth-of-type(4) { border-left: 0; padding-left: 0; }
  .kpis .kpi-toggle { grid-column: 7; grid-row: 1 / span 2; align-self: center; }
}

/* phones, portrait or landscape (a landscape phone is 900px wide but 375px tall) */
@media (max-width: 640px), (max-width: 900px) and (max-height: 500px) {
  :root { --topbar-h: 56px; }

  /* ---- topbar: two-line title, avatar only, search takes the whole bar ---- */
  .topbar { gap: 10px; padding: 0 10px 0 12px; }
  .topbar-spacer { flex: 0; }        /* the title gets every spare pixel */
  .brand { gap: 10px; }
  .brand > div:not(.brand-mark) { flex: 1; min-width: 0; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-mark svg { width: 22px; height: 22px; }
  .brand-name {
    font-size: 0.8125rem; line-height: 1.25; white-space: normal;
    max-height: 2.5em; overflow: hidden;   /* two lines, then clipped */
    text-overflow: clip;
  }
  .brand-sub { display: none; }
  .topbar-divider { display: none; }
  .topbar-actions { gap: 4px; }
  .user-menu { margin-left: 0; }
  .user-btn { padding: 4px; }
  .user-btn .user-chev { display: none; }
  /* the QC queue is one tap away in the panel; the chip would cost the title */
  .mode-chip { display: none; }
  .topbar-search.open {
    position: absolute; inset: 0; z-index: 5;
    padding: 0 10px 0 12px; gap: 8px;
    background: var(--surface);
  }
  .topbar-search.open .search-field { flex: 1; }
  .topbar-search.open input { width: 100%; font-size: 1rem; }   /* 16px: iOS keeps the page zoom */

  /* ---- indicators: a horizontal snap strip, two cards in view ---- */
  .kpis { height: auto; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 16px; }
  .kpi-strip {
    display: flex; flex: 1; min-width: 0;
    overflow-x: auto; scroll-snap-type: x mandatory;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    padding: 12px 0;
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .kpi-strip::-webkit-scrollbar { display: none; }
  .kpi { flex: 0 0 168px; padding: 2px 14px 2px 0; scroll-snap-align: start; animation: none; }
  .kpi + .kpi { padding-left: 14px; }
  .kpi-value { font-size: 1.25rem; }
  .kpi-spark { display: none; }
  .kpi:has(.kpi-spark) .kpi-value,
  .kpi:has(.kpi-spark) .kpi-delta { padding-right: 0; }
  .kpis .kpi-toggle { margin-left: 0; width: 36px; height: 36px; }
  :root[data-kpi="compact"] .kpis { padding: 8px 10px 8px 16px; gap: 8px; }
  :root[data-kpi="compact"] .kpi-compact {
    flex-wrap: nowrap; white-space: nowrap;
    overflow-x: auto; scrollbar-width: none;
    padding: 4px 0;
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  :root[data-kpi="compact"] .kpi-compact::-webkit-scrollbar { display: none; }

  /* ---- map fills the rest of the screen, edge to edge ---- */
  body { overflow: hidden; }
  .app { padding: 0; gap: 0; }
  .app > .map-wrap { margin: 0; border-radius: 0; box-shadow: none; }
  .map-wrap { flex: 1; min-height: 0; }
  .map-actions { top: 10px; right: 10px; gap: 8px; }
  .map-btn { width: 40px; height: 40px; }
  /* legend as a 2x2 block, the freshness note tucked under it, both clear of the zoom stack */
  .map-legend { left: 10px; top: 10px; padding: 8px 10px; }
  .map-legend .lg-rows { display: grid; grid-template-columns: auto auto; column-gap: 12px; row-gap: 4px; }
  .map-legend .lg-title { display: none; }
  .lg-row { white-space: nowrap; font-size: 0.6875rem; line-height: 14px; }
  .map-note { left: 10px; top: 66px; bottom: auto; padding: 5px 9px; }
  .lg-note { font-size: 0.625rem; }
  .map-note .ms-count { display: none; }   /* the Sites button already carries the count */
  /* the credit lives in the action bar; when an overlay hides that bar, the
     map's own compact control comes back so attribution is never absent */
  .maplibregl-ctrl-bottom-right { display: none; }
  body.has-drawer .maplibregl-ctrl-bottom-right,
  body.sidebar-open .maplibregl-ctrl-bottom-right { display: block; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl { margin: 0 10px 10px 0; }
  .maplibregl-ctrl-attrib.maplibregl-compact { padding: 0; width: 26px; height: 26px; min-height: 26px; }
  .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button { top: 1px; right: 1px; }
  .maplibregl-ctrl-attrib.maplibregl-compact.maplibregl-compact-show {
    width: auto; height: 26px;
    padding: 6px 30px 6px 10px;
  }

  /* ---- sites panel: left overlay, summoned by the bottom pill ---- */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: min(340px, 88vw);
    max-height: none;
    z-index: 80;
    border-right: 0;
    border-radius: 0 var(--r) var(--r) 0;
    padding-bottom: env(safe-area-inset-bottom);
    translate: -105% 0;
    transition: translate .32s var(--ease-drawer);
  }
  body.sidebar-open .sidebar { translate: 0 0; box-shadow: var(--shadow-lg); }
  .sidebar-toggle { display: grid; width: 36px; height: 36px; }   /* closes the overlay here */
  .sidebar-tabs { padding: 12px 12px 0; }
  .sidebar-tab { padding: 10px 12px 12px; font-size: 0.875rem; }
  .filters { padding: 12px 16px; }
  .filters-toggle { padding: 7px 11px 7px 10px; font-size: 0.8125rem; }
  .select select { height: 40px; font-size: 1rem; }
  .select::after { bottom: 19px; }
  .chip { padding: 9px 12px 9px 10px; font-size: 0.8125rem; }
  .site-card { padding: 12px 14px; min-height: 44px; }
  .btn-more { min-height: 44px; }
  .site-list { padding-bottom: 24px; }

  /* ---- bottom action bar: the primary CTA sits on its own surface ---- */
  .action-bar {
    display: block;
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 70;
    background: var(--surface);
    border-top: 1px solid var(--divider);
    box-shadow: 0 -2px 12px rgba(13, 27, 36, .07);
    padding: 10px 16px calc(8px + env(safe-area-inset-bottom));
    transition: translate .25s var(--ease-out);
  }
  body.has-drawer .action-bar, body.sidebar-open .action-bar { translate: 0 100%; }
  .sidebar-fab {
    display: flex; justify-content: center;
    position: static; translate: none;
    width: 100%;
    min-height: 48px; padding: 13px 20px;
    font-size: 0.875rem;
    border-radius: 8px;
    background: var(--primary); color: #FFFFFF;          /* brand teal on phones (4.6:1, AA) */
    box-shadow: none;
  }
  .attrib-note {
    margin-top: 7px;
    text-align: center;
    font-size: 0.6875rem; line-height: 1.3;
    color: var(--muted);
  }
  .toast-host { bottom: calc(104px + env(safe-area-inset-bottom)); width: calc(100vw - 32px); }
  .toast { text-align: center; }

  /* ---- site detail: a bottom sheet with a grab handle ---- */
  /* the sheet is laid out at its full stop (8vh) and rests at the half stop via
     translate (32vh), so both stops animate on transform only */
  .app > .drawer {
    position: fixed; inset: auto 0 0 0; top: 8vh;
    z-index: 85; width: auto;
    border-radius: var(--r) var(--r) 0 0;
    background: var(--surface);
    translate: 0 105%;
    transition: translate .3s var(--ease-drawer);
    pointer-events: none;
  }
  .app > .drawer.open { width: auto; translate: 0 32vh; pointer-events: auto; }   /* half: top edge at 40vh, see focusOffset() */
  .app > .drawer.open.full { translate: 0 0; }
  .drawer .drawer-inner { translate: 0 0; }
  .drawer-inner { height: calc(100% - 32vh); }
  .drawer.full .drawer-inner { height: 100%; }
  .drawer-inner {
    width: 100%; position: relative;
    border-radius: var(--r) var(--r) 0 0;
    box-shadow: var(--shadow-lg);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .drawer-inner::before {
    content: '';
    position: absolute; top: 8px; left: 50%; translate: -50% 0;
    width: 36px; height: 4px; border-radius: 2px;
    background: var(--border-ui);
    z-index: 3;
  }
  .drawer-head { padding: 22px 20px 14px; }
  .drawer-close { top: 14px; right: 12px; width: 36px; height: 36px; }

  /* ---- touch targets: 44px on icon controls and row-level actions ---- */
  .icon-btn, .kpis .kpi-toggle, .sidebar-toggle, .drawer-close, .map-btn { width: 44px; height: 44px; }
  .user-btn { min-width: 44px; min-height: 44px; justify-content: center; }
  .search-clear { width: 36px; height: 36px; right: 4px; }
  .sidebar-tab { min-height: 44px; }
  .filters-toggle { min-height: 44px; padding: 8px 12px 8px 10px; }
  .chip { min-height: 44px; }
  .range-group { gap: 8px; }
  .range-btn { min-height: 44px; min-width: 44px; padding: 10px 14px; font-size: 0.7812rem; }
  .api-copy { min-height: 44px; padding: 10px 14px; font-size: 0.7188rem; margin: -8px -8px 4px 8px; }
  /* the SensorThings request wraps instead of clipping */
  .api-block { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.7188rem; }
  /* type floor: nothing under 11.5px on a phone */
  .lg-row { font-size: 0.7188rem; line-height: 15px; }
  .map-note { top: 70px; }
  .lg-note, .d-photo-cap, .d-photo-cap .num, .hm-legend, .hm-caption, .hm-caption .num, .d-photo-thumb span,
  .kpi-delta, .kpi-value small, .filters-summary, .filters-count, .site-sub, .site-card .u, .site-card .pct,
  .d-hero-pct .t, .d-id, .d-photo-tag, .fab-count { font-size: 0.7188rem; }
  .attrib-note, .avatar, .site-val .u, .site-pct { font-size: 0.7188rem; }
  .modal .btn-primary { min-height: 44px; height: 44px; padding: 0 22px; }
  .modal-link { min-height: 44px; }
  .menu-item { min-height: 44px; padding: 10px 12px; }
  .btn-primary { min-height: 44px; }
  .select select { height: 44px; }
  .select::after { bottom: 21px; }
  /* no blur layers over the WebGL map on phones */
  .map-legend, .map-note, .maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib.maplibregl-compact, .d-photo-tag, .scrim { backdrop-filter: none; }
  .map-legend, .map-note, .maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib.maplibregl-compact { background: var(--surface); }
  .d-photo-tag { background: rgba(20,45,62,.78); }
  /* sheet drag */
  .drawer.dragging { transition: none; }
  .drawer-head { touch-action: none; cursor: grab; }

  .modal { padding: 22px 20px; }
}

/* landscape phones: the detail becomes a side panel so the map keeps its height,
   and the indicator strip gets shorter */
@media (max-width: 900px) and (max-height: 500px) {
  .kpi-strip { padding: 6px 0; }
  .kpi { flex-basis: 150px; }
  .kpi-value { font-size: 1.125rem; }
  .app > .drawer, .app > .drawer.open {
    inset: 0 0 0 auto; top: 0;
    width: min(46vw, 420px);
    border-radius: var(--r) 0 0 var(--r);
  }
  .app > .drawer { translate: 105% 0; }
  .drawer.open { translate: 0 0; }
  .app > .drawer.open, .app > .drawer.open.full { translate: 0 0; }
  .drawer-inner, .drawer.full .drawer-inner { height: 100%; border-radius: var(--r) 0 0 var(--r); }
  .drawer-inner::before { display: none; }
  .kpi-delta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .drawer-head { touch-action: auto; cursor: default; padding-top: 16px; }
  /* a 375px-tall screen cannot spare 88px of chrome: one short row instead */
  .action-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  }
  .sidebar-fab { width: auto; min-height: 40px; padding: 10px 18px; flex: none; }
  .attrib-note { margin-top: 0; text-align: left; flex: 1; min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* =========================================================================
   HOVER STATES: only where a pointer can hover; touch keeps its tap feedback
   ========================================================================= */
@media (hover: hover) {
  .api-copy:hover { background: rgba(255,255,255,.08); color: #A9D9D4; }
  [data-tip]:hover::after { opacity: 1; scale: 1; transition-delay: .35s; }
  .search-clear:hover { background: var(--neutral-bg); color: var(--ink); }
  .search-toggle:hover { background: var(--neutral-bg); color: var(--ink); }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
  .mode-chip:hover { background: rgba(39,124,120,.22); }
  .user-btn:hover { background: var(--surface-2); color: var(--ink); }
  .menu-item:hover { background: var(--surface-2); color: var(--ink); }
  .menu-item.danger:hover { background: var(--bad-bg); color: var(--bad); }
  .kpi-toggle:hover { background: var(--surface-2); color: var(--ink); }
  .kpis .kpi-toggle:hover { background: rgba(255,255,255,.16); color: #F2F6F8; }
  .kpi.kpi-alert:hover { box-shadow: var(--shadow-md); translate: 0 -1px; }
  .sidebar-toggle:hover { background: var(--surface-2); color: var(--ink); }
  .rail-btn:hover { background: var(--surface-2); color: var(--ink); }
  .sidebar-tab:hover { color: var(--ink-2); }
  .filters-bar .clear-btn:hover { text-decoration: underline; }
  .filters-toggle:hover { background: var(--surface-2); color: var(--ink); }
  .chip[aria-pressed="false"]:hover { color: var(--ink-2); border-color: var(--muted); }
  .chip:hover { border-color: var(--muted); }
  .filter-meta .clear-btn:hover { text-decoration: underline; }
  .site-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
  .btn-more:hover { border-color: var(--muted); background: var(--surface-2); }
  .qc-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
  .qc-site:hover { color: var(--primary); text-decoration: underline; }
  .btn-xs:hover { border-color: var(--muted); background: var(--surface-2); }
  .btn-xs.approve:hover { background: #14663A; border-color: #14663A; }
  :root[data-theme="dark"] .btn-xs.approve:hover { background: #6AC697; border-color: #6AC697; }
  .map-btn:hover { color: var(--primary); box-shadow: var(--shadow-md); }
  .drawer-close:hover { background: var(--surface-2); color: var(--ink); }
  .range-btn:hover { color: var(--ink); }
  .d-photo-thumb:hover { border-color: var(--border-ui); }
  .hm-host svg rect[data-i]:hover { stroke: var(--ink); stroke-width: 1.2; }
  .api-copy:hover { text-decoration: underline; }
  .btn-primary:hover { background: var(--primary-hover); }
/* in dark the brand teal lightens, so white text drops to 2.9:1; ink reads 6.1:1 */
:root[data-theme="dark"] .btn-primary { color: #0E1A22; }
  /* selected / pressed states keep their color under the pointer (these rules
     now sit after the state rules in the cascade) */
  .site-card.selected:hover { border-color: var(--primary); background: var(--selected-bg); }
  .d-photo-thumb[aria-selected="true"]:hover { border-color: var(--primary); }
  .range-btn[aria-pressed="true"]:hover { color: var(--primary); }
  .sidebar-tab[aria-selected="true"]:hover { color: var(--primary); }
  .filters-toggle[aria-expanded="true"]:hover { background: var(--primary-light); color: var(--primary); }
}
