/* Tokens from the MilpaTec site (milpatec.cloud, docs/02-design.md). */
:root {
  --bg: #f6f1e6;
  --surface: #fbf7ee;
  --surface-alt: #efe7d4;
  --border: #e3d8c0;
  --text: #2b2620;
  --text-muted: #6b6356;

  --terra: #8a5a2b;
  --terra-hover: #6f4824;
  --terra-tint: #efe3cc;

  --ink: #0e2a30;
  --ink-surface: #15383f;
  --ink-border: #27505a;
  --ink-text: #f6f1e6;
  --ink-text-muted: #9fb4b9;

  --agua: #1d8296;
  --agua-2: #329655;
  --milho-2: #f6a220;
  --live: #4cae04;
  --danger-ink: #b23a22;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Courier New", monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(43, 38, 32, 0.08), 0 10px 28px rgba(43, 38, 32, 0.14);

  --topbar-h: 4rem;
  --panel-w: 23.5rem;
  --gap: 1rem;
  --peek-h: 13.5rem;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

::selection {
  background: var(--terra-tint);
  color: var(--text);
}

a {
  color: var(--terra);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--terra-hover);
}

:focus-visible {
  outline: 2px solid var(--agua);
  outline-offset: 2px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.82em;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--topbar-h);
  padding: 0 clamp(16px, 3vw, 28px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1100;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  flex: none;
}

.brand img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.wordmark span {
  color: var(--text-muted);
  font-weight: 500;
}

.project {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
  padding-left: 1.25rem;
  border-left: 1px solid var(--border);
}

.project h1 {
  font-size: 1.35rem;
  white-space: nowrap;
}

.project p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-chip {
  margin: 0 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  flex: none;
}

.source-chip .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-muted);
}

.source-chip[data-tone="live"] {
  color: #2e6b04;
}

.source-chip[data-tone="live"] .dot {
  background: var(--live);
  animation: pulse 1.8s infinite;
}

.source-chip[data-tone="demo"] {
  background: #fbefd6;
  border-color: #efd29a;
  color: #8a5a00;
}

.source-chip[data-tone="demo"] .dot {
  background: var(--milho-2);
}

.source-chip[data-tone="error"] {
  color: var(--danger-ink);
}

.source-chip[data-tone="error"] .dot {
  background: var(--danger-ink);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(76, 174, 4, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(76, 174, 4, 0); }
  100% { box-shadow: 0 0 0 0 rgba(76, 174, 4, 0); }
}

/* ---------- Stage: the map is the page ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #e9e3d4;
  font-family: var(--font-body);
}

/* Warm the neutral basemap toward the MilpaTec soil. */
#map .leaflet-tile-pane {
  filter: grayscale(0.55) sepia(0.28) saturate(0.9) brightness(1.03) contrast(0.92);
}

.leaflet-container a {
  color: var(--terra);
}

.leaflet-bar {
  border: 0 !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.leaflet-bar a {
  width: 38px !important;
  height: 38px !important;
  line-height: 38px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  border-bottom-color: var(--border) !important;
  font-family: var(--font-body);
}

.leaflet-bar a:hover {
  background: var(--terra-tint) !important;
}

.leaflet-control-attribution {
  background: rgba(251, 247, 238, 0.85) !important;
  color: var(--text-muted) !important;
  font-size: 0.68rem;
  border-top-left-radius: var(--radius-sm);
}

.leaflet-tooltip {
  background: var(--ink);
  color: var(--ink-text);
  border: 0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
}

.leaflet-tooltip-top::before {
  border-top-color: var(--ink);
}

/* IQAr marker: the number itself is the pin. */
.pin {
  background: none;
  border: 0;
}

.pin-body {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--pin);
  color: var(--pin-text, #fff);
  border: 2px solid var(--bg);
  box-shadow: 0 2px 6px rgba(14, 42, 48, 0.35);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  transition: transform 260ms var(--ease-out), box-shadow 260ms var(--ease-out);
}

.pin:hover .pin-body {
  transform: scale(1.08);
}

.pin.is-selected .pin-body {
  transform: scale(1.22);
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(246, 241, 230, 0.9), 0 6px 16px rgba(14, 42, 48, 0.4);
}

/* ---------- Layer switch + legend ---------- */

.layers {
  position: absolute;
  z-index: 900;
  right: var(--gap);
  bottom: 1.9rem;
  display: grid;
  gap: 0.6rem;
  width: 18.5rem;
  padding: 0.7rem 0.8rem 0.75rem;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.layer-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-alt);
}

.layer-toggle button {
  padding: 0.4rem 0.75rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}

.layer-toggle button:hover {
  color: var(--text);
}

.layer-toggle button[aria-checked="true"] {
  background: var(--terra);
  color: var(--terra-on, #f6f1e6);
  box-shadow: 0 1px 2px rgba(43, 38, 32, 0.2);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.8rem;
  margin: 0;
  padding: 0 0.15rem;
  list-style: none;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.legend i {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
}

.legend-places {
  display: grid;
  gap: 0.3rem;
  margin: 0;
  padding: 0.5rem 0.15rem 0;
  border-top: 1px solid var(--border);
  list-style: none;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
}

.legend-places li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.school-dot {
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  margin: 0 0.12rem;
  border-radius: 50%;
  background: #efe3cc;
  box-shadow: inset 0 0 0 1px var(--terra);
}

/* Nave do Conhecimento: a small authored building mark in terra. */
.nave-glyph {
  display: inline-block;
  flex: none;
  width: 0.85rem;
  height: 0.85rem;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.5 1.5 6v1.2h1.3V14h10.4V7.2h1.3V6L8 1.5Zm-2.2 11V9.3h4.4v3.2H5.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1.5 1.5 6v1.2h1.3V14h10.4V7.2h1.3V6L8 1.5Zm-2.2 11V9.3h4.4v3.2H5.8Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.legend-places .nave-glyph {
  color: var(--terra);
}

.nave-pin {
  background: none;
  border: 0;
}

.nave-body {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--surface);
  color: var(--terra);
  border: 1.5px solid var(--terra);
  box-shadow: 0 2px 5px rgba(43, 38, 32, 0.25);
}

.nave-body .nave-glyph {
  width: 0.95rem;
  height: 0.95rem;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.leaflet-popup-tip {
  background: var(--surface);
}

.nave-popup {
  display: grid;
  gap: 0.3rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  line-height: 1.4;
}

.nave-popup strong {
  font-family: var(--font-display);
  font-size: 0.98rem;
}

.nave-popup span {
  color: var(--text-muted);
}

.nave-popup em {
  font-style: normal;
  font-weight: 600;
  color: var(--terra);
}

.nave-popup button {
  justify-self: start;
  margin-top: 0.2rem;
  padding: 0.35rem 0.8rem;
  border: 1.5px solid var(--terra);
  border-radius: 999px;
  background: transparent;
  color: var(--terra);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.nave-popup button:hover {
  background: var(--terra-tint);
}

/* ---------- Panel (floating column on desktop) ---------- */

.panel {
  position: absolute;
  z-index: 1000;
  top: var(--gap);
  left: var(--gap);
  bottom: var(--gap);
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-right: 2px;
}

.sheet-handle {
  display: none;
}

.detail,
.streams,
.about {
  flex: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* Detail: the dark "dados" card from the MilpaTec dashboard. */
.detail {
  background: var(--ink);
  color: var(--ink-text);
  padding: 1.15rem 1.15rem 1rem;
}

.detail:has(#detail:empty) {
  display: none;
}

.detail-head h3 {
  font-size: 1.3rem;
  line-height: 1.2;
}

.detail-head p {
  margin: 0;
  color: var(--ink-text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.detail-notice {
  margin: 0.75rem 0 0;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  background: rgba(246, 162, 32, 0.12);
  color: #f6cf8a;
  font-size: 0.8rem;
}

.reading {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "value band"
    "meta meta";
  align-items: center;
  gap: 0.7rem 0.9rem;
  margin-top: 1rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--ink-surface);
}

.reading-value {
  grid-area: value;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 2.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.reading-band {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  background: var(--tone);
  color: var(--tone-text, #fff);
  font-size: 0.78rem;
  font-weight: 600;
}

.reading-meta {
  grid-area: meta;
  padding-top: 0.6rem;
  border-top: 1px solid var(--ink-border);
  color: var(--ink-text-muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.reading-meta code {
  font-size: 0.95em;
  overflow-wrap: anywhere;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.6rem 0 0;
}

.metrics div {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--ink-border);
}

.metrics dt {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-text-muted);
}

.metrics dd {
  margin: 0.15rem 0 0;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.metrics dd small {
  margin-left: 0.2rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-text-muted);
}

.observed {
  margin: 0.7rem 0 0;
  font-size: 0.76rem;
  color: var(--ink-text-muted);
}

.observed strong {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-text);
}

#sparkline:not(:empty) {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--ink-border);
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.chart-head h4 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-text-muted);
}

.chart-head span,
.chart-axis {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-text-muted);
}

#sparkline svg {
  display: block;
  width: 100%;
  height: 4.2rem;
  margin-top: 0.4rem;
  overflow: visible;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 0.25rem;
}

.chart-empty {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-text-muted);
}

/* Stream list */
.streams {
  background: var(--surface);
  padding: 1rem 0.65rem 0.65rem;
}

.streams-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0 0.45rem 0.5rem;
}

.streams-head h2 {
  font-size: 1.1rem;
}

.status {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.status[data-tone="error"] {
  color: var(--danger-ink);
  white-space: normal;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0.35rem 0 0.15rem;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stream-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  margin: 0 0 2px;
  padding: 0.6rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.stream-item:hover {
  background: var(--surface-alt);
}

.stream-item[aria-current="true"] {
  background: var(--terra-tint);
  border-color: #dcc39a;
}

.swatch {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(43, 38, 32, 0.15);
}

.stream-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stream-copy strong {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-copy small {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.stream-index {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.stream-index.missing {
  color: var(--text-muted);
  font-weight: 500;
}

.empty {
  padding: 0.25rem 0.45rem 0.5rem;
}

.empty p {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.button-secondary {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border: 1.5px solid var(--terra);
  border-radius: 999px;
  color: var(--terra);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 160ms ease;
}

.button-secondary:hover {
  background: var(--terra-tint);
}

.about {
  background: var(--surface);
  padding: 0.85rem 1rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.about p {
  margin: 0;
}

.about p + p {
  margin-top: 0.45rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Additions: nav, progress, state, thermal reading ---------- */

.topnav {
  flex: none;
  margin-left: auto;
}

.topnav a {
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
}

.topnav a:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.topnav + .source-chip {
  margin-left: 0;
}

.status[data-tone="warn"] {
  color: var(--danger-ink);
  font-weight: 600;
}

.progress {
  padding: 0 0.45rem 0.6rem;
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--terra);
  transform: scaleX(var(--fill, 0));
  transform-origin: left;
  transition: transform 600ms var(--ease-out);
}

.progress p {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  margin: 0.45rem 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.progress-count strong {
  margin-right: 0.15rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
  color: var(--terra);
  font-variant-numeric: tabular-nums;
}

.progress-live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.progress-live i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 1.8s infinite;
}

.stream-item[data-offline="true"] .swatch {
  opacity: 0.45;
}

.stream-item[data-offline="true"] small {
  color: var(--danger-ink);
}

.detail-head {
  display: grid;
  justify-items: start;
  gap: 0.35rem;
}

.detail-head .state-pill {
  margin: 0 0 0.3rem;
}

.detail-nave {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin-top: 0.2rem !important;
  color: #e9c79c !important;
  font-weight: 500;
}

.detail-nave .nave-glyph {
  margin-top: 0.22rem;
}

.state-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.2rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--ink-border);
  color: #f3b2a3;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.state-pill i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
}

.state-pill.is-live {
  color: #8fe0a8;
}

.state-pill.is-live i {
  background: var(--live);
  animation: pulse 1.8s infinite;
}

.reading-value small {
  margin-left: 0.15rem;
  font-size: 0.45em;
  font-weight: 500;
  color: var(--ink-text-muted);
}

.reading-band {
  grid-area: band;
  justify-self: start;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: var(--tone);
  color: var(--tone-text, #fff);
  font-size: 0.78rem;
  font-weight: 600;
}

.metrics dd.sub {
  margin-top: 0.1rem;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-text-muted);
}

.metrics .is-alert {
  border-color: rgba(201, 162, 39, 0.55);
}

.metrics .is-alert dd:not(.sub) {
  color: #f2d06b;
}

.metrics .is-risk {
  border-color: rgba(240, 138, 116, 0.6);
}

.metrics .is-risk dd:not(.sub) {
  color: #f6a493;
}

.day-chart {
  position: relative;
  margin: 0.45rem 2.4rem 0 0;
}

.day-chart svg {
  display: block;
  width: 100%;
  height: 6rem;
  overflow: visible;
  border-bottom: 1px solid var(--ink-border);
}

.day-tick {
  position: absolute;
  left: calc(100% + 0.5rem);
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  white-space: nowrap;
}

.day-tick.legal {
  color: #8fd6a0;
}

.day-tick.risk {
  color: #f6a493;
}

.day-dot {
  position: absolute;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
  transform: translate(-50%, -50%);
}

.day-chart + .chart-axis {
  margin-right: 2.4rem;
}

.group-title:hover {
  background: var(--surface-alt);
}

.group-title small {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.group-title svg {
  flex: none;
  width: 0.8rem;
  height: 0.8rem;
  transition: transform 200ms var(--ease-out);
}

.group-title[aria-expanded="false"] svg {
  transform: rotate(-90deg);
}

/* ---------- Zone filter & live ticks ---------- */

.zone-filter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
}

.zone-filter button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.zone-filter button::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  border: 1.5px solid currentColor;
}

.zone-filter button[aria-pressed="true"] {
  border-color: #dcc39a;
  background: var(--terra-tint);
  color: var(--text);
}

.zone-filter button[aria-pressed="true"]::before {
  border-color: var(--terra);
  background: var(--terra);
}

.zone-filter button:hover {
  border-color: var(--terra);
}

.is-tick {
  animation: tick 1.1s var(--ease-out);
}

@keyframes tick {
  0% { color: #f2d06b; }
  100% { color: inherit; }
}

.stream-index.is-tick {
  animation-name: tick-light;
}

@keyframes tick-light {
  0% { color: var(--terra); }
  100% { color: inherit; }
}

/* ---------- School search & monitoring request ---------- */

.request {
  flex: none;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.request h2 {
  font-size: 1.1rem;
}

.request > p {
  margin: 0.3rem 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.request input[type="search"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.request input[type="search"]::placeholder {
  color: #8a8172;
}

.request input[type="search"]:focus-visible {
  outline: 2px solid var(--agua);
  outline-offset: 1px;
}

.school-results {
  display: grid;
  gap: 2px;
  margin-top: 0.5rem;
}

.school-result {
  display: grid;
  gap: 0.05rem;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.school-result:hover {
  background: var(--surface-alt);
}

.school-result strong {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.3;
}

.school-result small,
.no-results {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.no-results {
  margin: 0.25rem 0.1rem 0;
}

.state-pill.is-none {
  color: #e9c79c;
}

.school-copy {
  margin: 0.8rem 0 0;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--ink-text);
}

.request-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.request-form fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.request-form legend,
.request-form .field > span {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-text-muted);
}

.request-form .field em {
  font-style: normal;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.role-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.role-options label {
  position: relative;
}

.role-options input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.role-options span {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--ink-border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-text);
  transition: background-color 160ms ease, border-color 160ms ease;
}

.role-options input:checked + span {
  background: var(--ink-text);
  border-color: var(--ink-text);
  color: var(--ink);
}

.role-options input:focus-visible + span {
  outline: 2px solid #6fc3d3;
  outline-offset: 2px;
}

.request-form textarea,
.request-form input[type="email"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--ink-border);
  border-radius: var(--radius-md);
  background: var(--ink-surface);
  color: var(--ink-text);
  font: inherit;
  font-size: 0.88rem;
  resize: vertical;
}

.request-form textarea::placeholder {
  color: #7f9aa0;
}

.request-form textarea:focus-visible,
.request-form input[type="email"]:focus-visible {
  outline: 2px solid #6fc3d3;
  outline-offset: 1px;
}

.form-hint {
  margin: -0.35rem 0 0;
  font-size: 0.74rem;
  color: var(--ink-text-muted);
}

.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
}

.button-primary {
  justify-self: start;
  padding: 0.6rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: #f6f1e6;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.button-primary:hover {
  background: #e7dcc4;
}

.button-primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.form-status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--ink-text-muted);
}

.form-status[data-tone="error"] {
  color: #f6a493;
}

.form-status a {
  color: #e8c48f;
}

.request-done {
  margin-top: 0.9rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--ink-surface);
}

.request-done strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.request-done p {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-text-muted);
}

/* ---------- Tablet: narrower panel ---------- */

@media (max-width: 1100px) {
  :root {
    --panel-w: 20.5rem;
  }

  .project p {
    display: none;
  }

  .layers {
    width: 17.5rem;
  }

  .zone-filter button {
    padding: 0.3rem 0.2rem;
    font-size: 0.72rem;
  }

  .topnav {
    margin-left: auto;
  }
}

/* ---------- Phone & small tablet: bottom sheet ---------- */

@media (max-width: 760px) {
  :root {
    --topbar-h: 3.5rem;
    --gap: 0.6rem;
  }

  .topbar {
    gap: 0.75rem;
  }

  .wordmark {
    display: none;
  }

  .project {
    padding-left: 0.75rem;
  }

  .project h1 {
    font-size: 1.15rem;
  }

  .source-chip {
    padding: 0.3rem 0.65rem;
    font-size: 0.72rem;
  }

  .source-detail {
    display: none;
  }

  .topnav a {
    padding: 0.3rem 0.4rem;
    font-size: 0.8rem;
  }

  .layers {
    top: var(--gap);
    left: var(--gap);
    right: auto;
    bottom: auto;
    width: auto;
    max-width: calc(100% - 4.4rem);
    gap: 0.45rem;
    padding: 0.4rem;
  }

  .layer-toggle {
    width: 11rem;
  }

  .layer-toggle button {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }

  .legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 0 0.3rem 0.1rem;
    font-size: 0.7rem;
  }

  .legend-places {
    display: none;
  }

  .leaflet-control-attribution {
    display: none;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: calc(100% - 3.25rem);
    gap: 0.6rem;
    padding: 0 0.6rem calc(0.6rem + env(safe-area-inset-bottom));
    background: var(--bg);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 28px rgba(43, 38, 32, 0.18);
    overflow-y: hidden;
    transform: translateY(calc(100% - var(--peek-h)));
    transition: transform 380ms var(--ease-out);
  }

  .panel[data-sheet="peek"] {
    cursor: pointer;
  }

  .panel[data-sheet="open"] {
    transform: none;
    overflow-y: auto;
  }

  .sheet-handle {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    place-items: center;
    flex: none;
    width: 100%;
    height: 2.25rem;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--bg);
    cursor: pointer;
  }

  .grip {
    width: 2.6rem;
    height: 0.3rem;
    border-radius: 999px;
    background: #cdbf9f;
  }

  .detail,
  .streams,
  .about {
    box-shadow: none;
  }

  .panel[data-sheet="peek"] .metrics,
  .panel[data-sheet="peek"] .observed,
  .panel[data-sheet="peek"] #sparkline,
  .panel[data-sheet="peek"] .detail-notice {
    display: none;
  }

  .detail {
    padding: 0.9rem 0.95rem;
  }

  .detail-head h3 {
    font-size: 1.1rem;
  }

  .reading {
    margin-top: 0.7rem;
    padding: 0.65rem 0.8rem;
  }

  .reading-value {
    font-size: 2.1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .is-tick {
    animation: none;
  }

  .source-chip[data-tone="live"] .dot {
    animation: none;
  }

  .panel,
  .pin-body {
    transition: none;
  }
}
