:root {
  /* Names and values match web/tokens.json (the forestwatch design system); tests/test_web_tokens.py checks them. */
  --bg: #f7f7f4;
  --fg: #1d2420;
  --muted: #5d665f;
  --line: #d9ddd6;
  --accent: #2f6b45;
  --danger: #b3261e;
  --caution: #8a5a00;
  --on-danger: #ffffff;
  --warn: #b3861e;
  --select: #00b8d4;
  --on-select: #00222a;
  --map-boundary: #2f6f4f;
  --label-halo: rgba(15, 23, 42, 0.85);
  --label-ink: #ffffff;
  --label-facility: #ffc7bf;
  --label-landmark: #e2d3ff;
  --label-river: #9be0ff;
  --panel-w: 340px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a17;
    --fg: #e6ebe6;
    --muted: #9aa59c;
    --line: #2d342f;
    --accent: #7cc49a;
  }
}
/* High contrast: every text colour >= 7:1 on bg, borders >= 3:1. Wins over the dark scheme. */
@media (prefers-contrast: more) {
  :root {
    --bg: #ffffff;
    --fg: #0b0f0c;
    --muted: #3b423d;
    --line: #767d78;
    --accent: #1d4a2e;
    --warn: #6b4d00;
    --danger: #9e1b14;
    --caution: #6b4500;
    --on-select: #000000;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; }
#app { flex: 1; min-height: 0; display: flex; }
#panel { width: var(--panel-w); height: 100%; overflow-y: auto; padding: 14px 16px;
  border-right: 1px solid var(--line); flex: none; }
#map { flex: 1; height: 100%; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
h3 { font-size: 14px; margin: 8px 0 4px; }
.sub, .hint, footer { color: var(--muted); font-size: 12px; }
section { border-top: 1px solid var(--line); padding: 10px 0; }
header { padding-bottom: 8px; }
.row { display: flex; align-items: center; gap: 8px; margin: 4px 0; cursor: pointer; }
.row output { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.layer { margin: 4px 0; }
.layer .opacity { width: 90px; margin-left: auto; }
.layer small { color: var(--muted); display: block; margin-left: 24px; font-size: 11px; }
.legend { margin: 6px 0 10px; }
.legend .bar { height: 10px; border-radius: 2px; }
.legend .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.legend .sw { width: 12px; height: 12px; border-radius: 2px; flex: none; }
.chart { margin: 4px 0 10px; }
.chart svg { width: 100%; height: 70px; overflow: visible; }
.chart .lbl { display: flex; justify-content: space-between; font-size: 12px; }
.chart .lbl span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12px; }
.kv span:nth-child(even) { font-variant-numeric: tabular-nums; text-align: right; }
#banner { flex: none; text-align: center; background: var(--danger); color: var(--on-danger); padding: 6px 14px;
  font-weight: 600; font-size: 13px; }
.maplibregl-popup-content { color: #1d2420; font-size: 12px; }
@media (max-width: 720px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  #map { height: 55%; }
}
.credits { padding-left: 16px; margin: 4px 0 8px; }
.credits li { margin: 2px 0; }
[hidden] { display: none !important; }
#banner.preview { background: var(--caution); font-weight: 500; }

/* Place labels: light text with a dark halo reads over bright NDVI greens and dark hillshade alike */
.plabel { font-size: 11px; color: var(--label-ink); white-space: nowrap; pointer-events: none;
  text-shadow: -1px -1px 0 var(--label-halo), 1px -1px 0 var(--label-halo), -1px 1px 0 var(--label-halo),
    1px 1px 0 var(--label-halo), 0 0 3px rgba(15,23,42,.9); }
.plabel-institute, .plabel-dam, .plabel-reservoir { font-weight: 700; color: var(--label-facility); }
.plabel-landmark, .plabel-peak { color: var(--label-landmark); font-style: italic; }
.plabel-town { font-weight: 700; font-size: 12.5px; letter-spacing: .02em; }
.plabel-river_label { color: var(--label-river); font-style: italic; font-weight: 600; }

.boxlabel { font-size: 11px; font-weight: 600; color: var(--map-boundary); text-decoration: none; background: rgba(255,255,255,0.85); padding: 1px 5px; border-radius: 3px; }

/* Study-box switcher: segmented pill bar across the top */
#boxbar { flex: none; display: flex; align-items: center; gap: 12px; padding: 6px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg); min-width: 0; }
#boxbar .brand { font-weight: 700; font-size: 14px; flex: none; }
.pills { display: flex; border: 1px solid var(--accent); border-radius: 999px; overflow-x: auto;
  scrollbar-width: none; min-width: 0; }
.pills::-webkit-scrollbar { display: none; }
.pill { flex: none; font-size: 13px; padding: 4px 14px; color: var(--accent); text-decoration: none;
  white-space: nowrap; border-left: 1px solid var(--accent); }
.pill:first-child { border-left: 0; }
.pill:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pill:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 999px; }
.pill[aria-current="page"] { background: var(--accent); color: var(--bg); font-weight: 600; pointer-events: none; }
#showAll { flex: none; margin-left: auto; font-size: 12px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; }
.boxlabel { font-size: 11px; font-weight: 600; color: var(--map-boundary); text-decoration: none; background: rgba(255,255,255,0.85); padding: 1px 5px; border-radius: 3px; }
@media (max-width: 720px) { #boxbar .brand { display: none; } }

/* QA badge + modal */
#qaBadge { flex: none; display: flex; align-items: center; gap: 6px; max-width: 46%; font-size: 12px; padding: 3px 10px;
  border-radius: 999px; border: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; }
#qaBadge #qaText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#qaBadge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: none; }
#qaBadge.ready .dot { background: var(--accent); }
#showAll { margin-left: auto; }
#qaModal { width: min(860px, 94vw); max-height: 86vh; padding: 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--fg); }
#qaModal::backdrop { background: rgba(0, 0, 0, .45); }
#qaModal header { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
#qaModal h2 { margin: 0; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--fg); }
#qaClose { font-size: 22px; line-height: 1; border: 0; background: transparent; color: inherit; cursor: pointer; }
#qaBody { padding: 4px 16px 16px; overflow-y: auto; max-height: calc(86vh - 50px); }
#qaBody h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#qaBody table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
#qaBody th, #qaBody td { text-align: right; padding: 3px 6px; border-bottom: 1px solid var(--line); }
#qaBody th:first-child, #qaBody td:first-child, #qaBody td.l, #qaBody th.l { text-align: left; }
#qaBody .scroll { overflow-x: auto; }
#qaBody code { font-size: 11px; word-break: break-all; }
#qaBody dl { margin: 0; font-size: 12px; }
#qaBody dt { font-weight: 600; margin-top: 8px; }
#qaBody dd { margin: 2px 0 0; color: var(--muted); }
#qaBody .warn { color: var(--warn); font-weight: 600; }
#qaBody .na { color: var(--muted); font-size: 12px; margin: 4px 0; }
.ovsw { display: inline-block; width: 10px; height: 10px; border-radius: var(--radius-xs, 2px); vertical-align: -1px; }
.limit { border-left: 3px solid var(--warn); padding-left: 8px; margin: 8px 0; }
#qaBody .limit { color: var(--fg); font-size: 12px; }

/* candidate table */
.chips, .sorts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; font-size: 12px; }
.chip, .sortbtn { font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: inherit; cursor: pointer; }
.chip.on, .sortbtn.on { background: var(--accent); border-color: var(--accent); color: var(--bg); }
#candList { list-style: none; margin: 4px 0; padding: 0; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 6px; }
.candrow { display: grid; grid-template-columns: 34px 1fr 1fr auto; gap: 6px; width: 100%; text-align: left;
  padding: 4px 8px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: inherit;
  font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; }
.candrow:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.candrow.sel { background: var(--select); color: var(--on-select); font-weight: 600; }
.candrow .rk { font-weight: 600; }
.candrow .z { color: var(--muted); }
.candrow.sel .z { color: inherit; }
@media (max-width: 720px) { #qaBadge { max-width: 40%; } }

kbd { font: inherit; font-size: 11px; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; }
#peekRow button { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: inherit; cursor: pointer; touch-action: none; }
#peekHint { position: fixed; left: calc(var(--panel-w) + 16px); bottom: 34px; z-index: 5; background: rgba(15,23,42,.88);
  color: #fff; font-size: 12px; padding: 5px 10px; border-radius: 6px; pointer-events: none; }
@media (max-width: 720px) { #peekHint { left: 12px; bottom: auto; top: 110px; } }
