/* Scout — brand tokens from the Scout brand book */
:root {
  --bg: oklch(0.985 0.008 80);
  --card-bg: oklch(0.97 0.012 75);
  --ink: oklch(0.24 0.02 60);
  --muted: oklch(0.48 0.02 65);
  --border: oklch(0.87 0.015 70);
  --accent: oklch(0.6 0.16 38);
  --accent-dark: oklch(0.46 0.15 35);
  --accent-light: oklch(0.72 0.13 40);
  --accent-tint: oklch(0.94 0.03 40);
  --ramp-1: oklch(0.94 0.03 70);
  --ramp-2: oklch(0.85 0.07 55);
  --ramp-3: oklch(0.74 0.12 45);
  --ramp-4: oklch(0.63 0.16 38);
  --ramp-5: oklch(0.48 0.15 33);
  --shadow: 0 4px 24px rgb(40 30 20 / 0.18);
  --radius: 14px;
  --font-ui: 'Manrope', system-ui, sans-serif;
  --font-display: 'Newsreader', Georgia, serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
}
button { font-family: var(--font-ui); cursor: pointer; }
input, select { font-family: var(--font-ui); }

#map { position: fixed; inset: 0; background: #1a1e18; }
#map:focus { outline: none; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 1000;
}
.searchwrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0 6px 0 14px;
  min-width: 0;
}
.searchwrap svg { flex-shrink: 0; color: var(--muted); }
#search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
  padding: 12px 8px;
  color: var(--ink);
}
#search-input::placeholder { color: var(--muted); }
#search-clear {
  display: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px;
  border-radius: 50%;
}
.searchwrap.has-text #search-clear { display: block; }
.iconbtn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  position: relative;
}
.iconbtn:active { transform: scale(0.94); }
.iconbtn .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}
.iconbtn .badge.on { display: flex; }

/* ---------- legend ---------- */
.legend {
  position: fixed;
  left: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 900;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  max-width: 240px;
  transition: transform 0.25s ease;
}
.legend .legend-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
}
.legend .swatches { display: flex; border-radius: 6px; overflow: hidden; height: 12px; }
.legend .swatches div { flex: 1; }
.legend .labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}
.legend .legend-note { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ---------- generic sheet/panel ---------- */
.sheet {
  position: fixed;
  z-index: 1100;
  background: var(--bg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.22, 1);
}
.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 10px auto 2px;
  flex-shrink: 0;
}
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 18px 24px; }

/* bottom sheet (mobile) */
@media (max-width: 767px) {
  .sheet {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 72vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet.open { transform: translateY(0); }
}
/* side panel (desktop) */
@media (min-width: 768px) {
  .sheet {
    top: 74px;
    right: 12px;
    bottom: 12px;
    width: 400px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transform: translateX(120%);
  }
  .sheet.open { transform: translateX(0); }
  .sheet-grip { display: none; }
  .sheet-body { padding-top: 16px; }
}

/* ---------- detail panel ---------- */
.block-title-row { display: flex; align-items: baseline; gap: 8px; }
.block-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  line-height: 1.1;
  margin: 4px 0 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.rename-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  flex-shrink: 0;
}
.rename-btn:hover { background: var(--card-bg); }
.block-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.chip {
  display: inline-block;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  margin-top: 8px;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.stat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat .v { font-size: 20px; font-weight: 700; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin: 20px 0 10px;
}
.agebars { display: flex; flex-direction: column; gap: 6px; }
.agebar { display: grid; grid-template-columns: 64px 1fr 40px; align-items: center; gap: 8px; font-size: 12px; }
.agebar .lbl { color: var(--muted); }
.agebar .track { height: 8px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.agebar .fill { height: 100%; background: var(--accent-light); border-radius: 4px; }
.agebar .val { text-align: right; font-weight: 600; }

.school-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.school-info { flex: 1; min-width: 0; }
.school-level { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.school-name { font-size: 15px; font-weight: 600; line-height: 1.25; }
.school-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.score-ring {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--ink);
  background: var(--card-bg);
}
.score-na { font-size: 12px; color: var(--muted); font-weight: 600; }
.score-detail { margin-top: 4px; line-height: 1.45; }
.score-detail strong { color: var(--accent-dark); font-weight: 700; }
.section-note { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 4px; }

.btn-row { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.btn {
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; color: var(--ink); border: 1.5px solid var(--border); font-weight: 600; }
.btn-secondary.saved-state { border-color: var(--accent); color: var(--accent-dark); }
.btn-half-row { display: flex; gap: 10px; }
.btn-half-row .btn { flex: 1; }

.note-area {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  padding: 12px;
  font-size: 14px;
  resize: vertical;
  min-height: 70px;
  color: var(--ink);
  outline: none;
  margin-top: 8px;
}
.note-area:focus { border-color: var(--accent-light); }

/* ---------- filter panel ---------- */
.filter-group { margin-bottom: 22px; }
.filter-label { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.select {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  font-size: 15px;
  color: var(--ink);
}
.bandgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.bandchip {
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
}
.bandchip.on { background: var(--accent-tint); border-color: var(--accent-light); color: var(--accent-dark); }
.resolved-range { font-size: 12px; color: var(--muted); margin-top: 8px; }
.countylist { display: flex; flex-wrap: wrap; gap: 6px; max-height: 180px; overflow-y: auto; }
.threshold-row { margin-bottom: 14px; }
.threshold-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.threshold-head .t-name { font-weight: 600; }
.threshold-head .t-val { color: var(--accent-dark); font-weight: 700; }
.threshold-inputs { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.threshold-inputs input {
  flex: 1;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.threshold-inputs input:focus { border-color: var(--accent-light); }
.threshold-inputs span { color: var(--muted); font-size: 13px; }
.filter-footer { display: flex; gap: 10px; margin-top: 4px; }
.filter-footer .btn { flex: 1; }
.match-count { font-size: 13px; color: var(--muted); text-align: center; margin-top: 12px; }

/* ---------- saved panel ---------- */
.saved-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.saved-tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
}
.saved-tab.on { background: var(--accent-tint); border-color: var(--accent-light); color: var(--accent-dark); }
.saved-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.saved-item .si-name { font-family: var(--font-display); font-size: 19px; font-weight: 500; }
.saved-item .si-sub { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.saved-item .si-note { font-size: 13px; margin-top: 6px; font-style: italic; color: var(--muted); }
.saved-item .si-actions { display: flex; gap: 12px; margin-top: 8px; }
.saved-item .si-actions button {
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-dark);
  padding: 4px 0;
}
.saved-item .si-actions .danger { color: var(--muted); }
.empty-msg { text-align: center; color: var(--muted); font-size: 14px; padding: 30px 10px; line-height: 1.5; }

/* ---------- panel header w/ close ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; }
.panel-head h2 { font-family: var(--font-display); font-weight: 500; font-size: 26px; margin: 6px 0 4px; }
.close-btn {
  border: 0;
  background: var(--card-bg);
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 66px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 2000;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- loading ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  transition: opacity 0.4s;
}
.loader.hide { opacity: 0; pointer-events: none; }
.loader .mark { position: relative; width: 56px; height: 56px; }
.loader .mark .r1, .loader .mark .r2, .loader .mark .dot { position: absolute; border-radius: 50%; }
.loader .mark .r1 { inset: 0; border: 3px solid var(--accent); animation: ping 1.6s ease-out infinite; }
.loader .mark .r2 { inset: 12px; border: 3px solid var(--accent); }
.loader .mark .dot { inset: 22px; background: var(--accent); }
@keyframes ping {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(1.25); opacity: 0.15; }
}
.loader .word { font-weight: 800; font-size: 20px; letter-spacing: 0.02em; }
.loader .sub { font-size: 13px; color: var(--muted); }

/* leaflet tweaks */
.leaflet-container { font-family: var(--font-ui); }
.leaflet-control-attribution { font-size: 10px; background: rgb(255 253 248 / 0.75) !important; }
.leaflet-control-zoom { display: none; }
@media (min-width: 768px) {
  .leaflet-control-zoom { display: block; margin-top: 74px !important; }
  .leaflet-control-zoom a { border-radius: 8px !important; }
}
.pin-marker { filter: drop-shadow(0 2px 4px rgb(0 0 0 / 0.4)); }
