/* Town Map UI chrome. Neutral, compact controls over a vanilla Mapbox map.
   The map carries the color; the chrome stays calm and out of the way. */

:root {
  --bg: #F5F5F2;
  --surface: #FFFFFF;
  --ink: #15171A;
  --secondary: #3C4147;
  --accent: #DA4D2A;
  --accent-ink: #FFFFFF;
  --hairline: #D5D8D1;
  --hairline-strong: #BCC0B9;
  --shadow: 0 1px 6px rgba(21, 23, 26, 0.12), 0 1px 2px rgba(21, 23, 26, 0.08);
  --shadow-lg: 0 6px 22px rgba(21, 23, 26, 0.18);
  --radius: 9px;
  --radius-sm: 7px;
  --font-ui: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

/* The HTML hidden attribute must win over component display rules. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
}

#map { position: absolute; inset: 0; }

/* Numbers use the mono data face wherever they appear in chrome. */
.search-result-pop, .popfilter-input, .fav-pop, .poi-count,
.popup-pop-num, .badge { font-family: var(--font-mono); }

/* ---- Banner ---- */
.banner {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(480px, 92vw);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 13px;
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}
.banner code {
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 12px;
}

/* ---- Top bar ---- */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 8px;
  pointer-events: none; /* let map show through gaps; children re-enable */
}
.topbar-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.topbar-row > * { pointer-events: auto; }

/* Search (kept compact so the whole top bar fits one row) */
.search {
  position: relative;
  flex: 0 1 150px;
  /* Without this, the input's intrinsic width blocks shrinking and pushes the
     action buttons off-screen in narrow viewports (VS Code browser pane). */
  min-width: 0;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0 9px;
}
.search-icon { display: inline-flex; color: var(--secondary); margin-right: 6px; }
.search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  padding: 8px 0;
}
.search-input::placeholder { color: var(--secondary); opacity: 0.85; }

.search-results {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  /* Wider than the (compact) input so town names read comfortably. */
  min-width: 300px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 40;
}
.search-result {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 11px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  border-bottom: 1px solid var(--hairline);
}
.search-result:last-child { border-bottom: 0; }
.search-result:hover, .search-result.is-active { background: var(--bg); }
.search-result-name { font-weight: 600; font-size: 13.5px; }
.search-result-state {
  font-size: 11px; font-weight: 700; color: var(--secondary);
  margin-left: 6px; letter-spacing: 0.03em;
}
.search-result-pop { font-size: 12.5px; color: var(--secondary); font-weight: 600; }

/* Top-bar action buttons */
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }

.iconbtn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px 9px;
  font: inherit;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.iconbtn:hover { border-color: var(--hairline-strong); }
.iconbtn .ib-icon { display: inline-flex; color: var(--secondary); }
.iconbtn.is-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.iconbtn.is-on .ib-icon { color: var(--accent-ink); }
.iconbtn.ghost { box-shadow: none; border-color: transparent; background: transparent; padding: 5px; }
.iconbtn.ghost:hover { background: var(--bg); }
.iconbtn.round {
  border-radius: 50%;
  width: 36px; height: 36px;
  padding: 0;
  justify-content: center;
  color: var(--ink);
}
.iconbtn.round span { display: inline-flex; }

.badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border: 2px solid var(--surface);
}

/* Category toggles */
.cat-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 6px 11px 6px 8px;
  font: inherit;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.cat-toggle .cat-icon { display: inline-flex; color: var(--cat); }
.cat-toggle:hover { border-color: var(--hairline-strong); }
.cat-toggle.is-on { background: var(--cat); color: #fff; border-color: var(--cat); }
.cat-toggle.is-on .cat-icon { color: #fff; }

/* Population filter */
.popfilter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 5px 10px;
}
.popfilter.inset { box-shadow: none; border-radius: var(--radius-sm); padding: 7px 8px; }
.popfilter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.popfilter-toggle input {
  width: 14px; height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
/* Filter off: dim the bounds but keep them typable (typing re-enables). */
.popfilter.is-off .popfilter-input,
.popfilter.is-off .popfilter-dash { opacity: 0.45; }
.popfilter-label {
  font-size: 11px; font-weight: 700; color: var(--secondary);
  letter-spacing: 0.02em; text-transform: uppercase;
}
.popfilter-input {
  width: 72px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  padding: 5px 7px;
  outline: 0;
}
/* Remove number-input spinner arrows (they cropped 6-digit values). */
.popfilter-input::-webkit-outer-spin-button,
.popfilter-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.popfilter-input { -moz-appearance: textfield; appearance: textfield; }
.popfilter-input:focus { border-color: var(--accent); }
.popfilter-dash { color: var(--secondary); font-weight: 700; }

/* ---- Bottom-right map controls ---- */
.mapctrls {
  position: absolute;
  right: 11px; bottom: 22px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- Side panels ---- */
.sidepanel {
  position: absolute;
  top: 0; right: 0;
  z-index: 35;
  width: min(300px, 92vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 9px;
  border-bottom: 1px solid var(--hairline);
}
.panel-title { font-weight: 800; font-size: 15px; }
.panel-body { flex: 1; overflow-y: auto; padding: 11px 12px; }

/* POI list */
.poi-panel { width: min(300px, 92vw); }
.poi-empty, .fav-empty, .poi-empty-row {
  color: var(--secondary);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 8px 2px;
}
.poi-group { margin-bottom: 13px; }
.poi-group-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 6px;
  padding-bottom: 5px;
  border-bottom: 2px solid currentColor;
}
.poi-group-head span:first-of-type { color: var(--ink); }
.poi-count {
  margin-left: auto;
  color: var(--ink);
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 1px 8px;
}
.poi-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 7px 8px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.poi-row:hover, .poi-row.is-active {
  background: var(--bg);
  border-color: var(--hairline);
}
.poi-row-name { font-weight: 600; font-size: 13px; }
.poi-row-addr { font-size: 11.5px; color: var(--secondary); }

/* POI map pins */
.poi-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: currentColor;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.poi-pin svg { transform: rotate(45deg); color: #fff; }
.poi-pin.is-active { outline: 3px solid var(--ink); outline-offset: 1px; z-index: 5; }

/* Favorites */
.fav-row {
  display: flex;
  align-items: stretch;
  gap: 5px;
  margin-bottom: 6px;
}
.fav-go {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 10px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.fav-go:hover { background: var(--bg); border-color: var(--hairline-strong); }
.fav-name { font-weight: 700; font-size: 14px; }
.fav-state { font-size: 11px; font-weight: 700; color: var(--secondary); margin-left: 6px; letter-spacing: 0.03em; }
.fav-pop { font-size: 12.5px; font-weight: 600; color: var(--secondary); }
.fav-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--secondary);
  cursor: pointer;
}
.fav-remove:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Settings ---- */
.settings-body { display: flex; flex-direction: column; gap: 16px; }
.setting { border: 0; margin: 0; padding: 0; }
.setting legend {
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 7px;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}
.tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--bg);
  border: 1px solid var(--hairline);
  color: var(--secondary);
  border-radius: 4px;
  padding: 1px 5px;
}
.setting-hint { font-size: 11.5px; color: var(--secondary); line-height: 1.45; margin: 6px 0 0; }

.segmented {
  display: flex;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg { flex: 1; position: relative; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  padding: 8px 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--secondary);
  cursor: pointer;
  border-right: 1px solid var(--hairline-strong);
}
.seg:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -2px; }

/* Switch */
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch-track {
  position: relative;
  flex: none;
  width: 38px; height: 22px;
  background: var(--hairline-strong);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--ink); outline-offset: 2px; }
.switch-text { font-size: 13px; font-weight: 600; }

/* Theme picker: one swatch per theme; the chip previews the base map, the dot
   previews the town dot/label color. */
.theme-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
}
.theme-chip {
  position: relative;
  display: block;
  width: 54px; height: 40px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--hairline);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.theme-swatch.is-on .theme-chip { border-color: var(--accent); }
.theme-chip-water { position: absolute; left: 0; bottom: 0; width: 40%; height: 100%; }
.theme-chip-forest { position: absolute; right: 0; top: 0; width: 55%; height: 55%; border-bottom-left-radius: 8px; }
.theme-chip-road { position: absolute; left: 30%; top: 0; width: 4px; height: 100%; transform: rotate(12deg); }
.theme-chip-dot {
  position: absolute;
  right: 9px; bottom: 7px;
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid;
}
.theme-name { font-size: 12px; font-weight: 700; color: var(--secondary); }
.theme-swatch.is-on .theme-name { color: var(--ink); }
.theme-swatch:focus-visible .theme-chip { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: flex-start;
  margin-top: 2px;
}

/* ---- Buttons (shared, used in popups too) ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 11px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink); }
.btn-ghost { background: var(--surface); }
.btn-fav { color: var(--ink); }
.btn-fav .fav-icon { display: inline-flex; color: var(--accent); }
.btn-fav.is-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-fav.is-on .fav-icon { color: var(--accent-ink); }

/* ---- Mapbox popup overrides ---- */
.mapboxgl-popup-content {
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lg);
  padding: 11px 13px;
  font-family: var(--font-ui);
}
.popup-title {
  font-weight: 800;
  font-size: 15px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1.2;
}
.popup-state { font-size: 11px; font-weight: 700; color: var(--secondary); letter-spacing: 0.04em; }
.popup-pop { margin-top: 5px; color: var(--secondary); font-size: 12.5px; }
.popup-pop-num { font-size: 15px; font-weight: 700; color: var(--ink); }
.popup-pop-label { text-transform: uppercase; letter-spacing: 0.04em; font-size: 10.5px; font-weight: 700; }
.popup-addr { margin-top: 4px; color: var(--secondary); font-size: 12.5px; line-height: 1.4; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.poi-popup-icon { display: inline-flex; }

/* ---- Debug panel (owner tuning tool) ---- */
.debug-panel {
  position: fixed;
  left: 12px;
  bottom: 44px; /* clears the Mapbox logo */
  z-index: 30;
  width: 228px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px 12px 12px;
}
.debug-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.debug-title { font-weight: 800; font-size: 13px; }
.debug-close { font-size: 17px; line-height: 1; color: var(--secondary); }
.debug-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 0 0 10px;
}
.debug-stats dt { font-size: 12px; font-weight: 700; color: var(--secondary); }
.debug-stats dd { margin: 0; font-family: var(--font-mono); font-size: 13px; font-weight: 700; color: var(--ink); text-align: right; }
.debug-floors-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--secondary);
  margin-bottom: 5px;
}
.debug-floors { display: flex; flex-direction: column; gap: 4px; }
.debug-rung {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 1px 5px;
  border-radius: 5px;
}
.debug-rung.is-active { background: var(--bg); box-shadow: inset 0 0 0 1.5px var(--accent); }
.debug-rung-zoom { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--ink); width: 52px; }
.debug-rung-floor {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 3px 7px;
  text-align: right;
}
.debug-rung-floor:focus { border-color: var(--accent); outline: none; }
.debug-reset { margin-top: 10px; }

/* ---- Focus visibility ---- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.iconbtn:focus-visible, .cat-toggle:focus-visible, .btn:focus-visible { outline-offset: 2px; }

/* ---- Progressive top-bar collapse: shed labels before wrapping ---- */
@media (max-width: 1180px) {
  .ib-label { display: none; }
  .iconbtn { padding: 7px; }
}
@media (max-width: 980px) {
  .cat-label { display: none; }
  .cat-toggle { padding: 6px 8px; }
  .popfilter-label { display: none; }
}

/* ---- Mobile: side panels become bottom sheets ---- */
@media (max-width: 680px) {
  .sidepanel {
    top: auto; bottom: 0;
    width: 100%;
    height: min(62vh, 520px);
    border-left: 0;
    border-top: 1px solid var(--hairline);
    border-radius: 14px 14px 0 0;
  }
  .mapctrls { bottom: 16px; right: 10px; }
}

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