/* ---------------------------------------------------------------------------
   Union Map — design system

   The map is full-bleed and everything else floats over it: a rounded top bar,
   a results card on the left, a detail card bottom-right. Nothing is docked, so
   the map is never boxed into a corner.

   Palette follows the reference: near-white land, soft blue water, near-black
   ink, muted blue accent. Dark mode is a first-class inversion rather than an
   afterthought, and the basemap style swaps with it.
   --------------------------------------------------------------------------- */

:root {
  --bg: #e8edf1;
  --panel: #ffffff;
  --panel-blur: rgba(255, 255, 255, 0.82);
  --sunk: #f2f5f8;
  --ink: #1e2523;
  --ink-2: #4a5560;
  --muted: #757680;
  --line: #dfe6ed;
  --line-2: #c9d5e0;
  --accent: #709cba;
  --accent-ink: #0f1a22;
  --accent-strong: #4a7d9e;
  --pill: #1e2523;
  --pill-ink: #ffffff;
  --ok: #2f7d5d;
  --warn: #9a6b1f;
  --danger: #b4453a;
  --shadow-lg: 0 4px 12px rgba(30, 37, 35, 0.06), 0 16px 48px rgba(30, 37, 35, 0.12);
  --shadow: 0 1px 3px rgba(30, 37, 35, 0.07), 0 8px 24px rgba(30, 37, 35, 0.1);
  --shadow-sm: 0 1px 2px rgba(30, 37, 35, 0.08);
  --r-lg: 16px;
  --r: 12px;
  --r-sm: 8px;
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #10161c;
  --panel: #171e26;
  --panel-blur: rgba(23, 30, 38, 0.86);
  --sunk: #1d252e;
  --ink: #e6edf3;
  --ink-2: #b3c0cc;
  --muted: #8494a3;
  --line: #28323d;
  --line-2: #3a4753;
  --accent: #9dbad0;
  --accent-ink: #0f1a22;
  --accent-strong: #b6c7da;
  --pill: #e6edf3;
  --pill-ink: #10161c;
  --ok: #5fc79b;
  --warn: #e0a851;
  --danger: #ff7a6d;
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4), 0 16px 48px rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* An explicit display (grid/flex) beats the hidden attribute's UA rule, which
   would silently leave [hidden] panels on screen. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}
a {
  color: var(--accent-strong);
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip:focus {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 99;
  width: auto;
  height: auto;
  clip: auto;
  margin: 0;
  padding: 10px 14px;
  background: var(--pill);
  color: var(--pill-ink);
  border-radius: var(--r-sm);
}

/* --- map: the whole stage ------------------------------------------------- */

#map {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

/* --- floating top bar ----------------------------------------------------- */

.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-blur);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 4px;
  flex: none;
}
.brand-mark {
  width: 20px;
  height: 20px;
  flex: none;
}
.brand strong {
  font-size: 14.5px;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

/* Segmented control — the reference's Map/Marketplace switch. */
.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--sunk);
  border-radius: 10px;
  flex: none;
}
.segmented button {
  border: 0;
  background: none;
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}
.segmented button[aria-selected='true'] {
  background: var(--panel);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.segmented .n {
  font-weight: 400;
  color: var(--muted);
  font-size: 11.5px;
}

/* Centred search, as in the reference. */
.search-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, 100%);
  background: var(--sunk);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 10px;
}
.search:focus-within {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}
.search svg {
  flex: none;
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 8px 0;
  outline: none;
}
.search input::placeholder {
  color: var(--muted);
}
.kbd {
  flex: none;
  font-size: 10.5px;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  padding: 1px 5px;
  background: var(--panel);
}

/* "Use my location" — a crosshair inside the search bar. */
.geo-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
}
.geo-btn:hover {
  color: var(--accent-strong);
  background: var(--panel);
}
.geo-btn[data-busy='true'] {
  color: var(--accent-strong);
  animation: geo-pulse 1s ease-in-out infinite;
}
@keyframes geo-pulse {
  50% {
    opacity: 0.4;
  }
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover {
  background: var(--sunk);
  color: var(--ink);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: var(--pill);
  color: var(--pill-ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.pill-btn:hover {
  filter: brightness(1.15);
}
.pill-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- floating results card ------------------------------------------------ */

.results {
  position: fixed;
  /* Sits below the top bar's ACTUAL rendered height (set by app.js), so it can
     never overlap it — the bar wraps to two or three rows on narrow screens. */
  top: var(--results-top, 68px);
  left: 12px;
  bottom: 12px;
  z-index: 9;
  width: 348px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel-blur);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.results-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 3px;
}
.results-head h1 {
  margin: 0;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.results-head p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.results-head p.error {
  color: var(--danger);
}

.filters {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.field {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 7px 9px;
  background: var(--panel);
  font-size: 13px;
}
.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: none;
}
.chip[aria-pressed='false'] {
  opacity: 0.42;
}
.chip:hover {
  border-color: var(--accent);
}

.scroll {
  overflow: auto;
  min-height: 0;
  flex: 1;
  overscroll-behavior: contain;
}

.group {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: var(--panel-blur);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.group .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.group .n {
  margin-left: auto;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.card {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  padding: 11px 14px;
  cursor: pointer;
  display: grid;
  gap: 4px;
}
.card:hover {
  background: var(--sunk);
}
.card[aria-current='true'] {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 3px 0 0 var(--accent-strong);
}
.card-top {
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.card h3 {
  margin: 0;
  font-size: 13.5px;
  letter-spacing: -0.01em;
}
.card .sub {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
}
.card .why {
  margin: 0;
  color: var(--ink-2);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--sunk);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
  flex: none;
  margin-left: auto;
}
.tag-strong {
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 32%, transparent);
}
.tag-soft {
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent);
}

.empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 5px;
}
.empty strong {
  color: var(--ink);
  font-size: 14px;
}

.caveat {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--sunk);
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.45;
}
.caveat b {
  color: var(--ink-2);
}

/* --- floating detail card (bottom-right, as in the reference) ------------- */

.detail {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 9;
  width: 324px;
  max-height: calc(100dvh - 92px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 14px;
  display: grid;
  gap: 10px;
}
.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.detail-head .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 5px;
  flex: none;
}
.detail h2 {
  margin: 0;
  font-size: 14.5px;
  letter-spacing: -0.01em;
}
.detail .org {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}
.detail .why {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--sunk);
  border-radius: var(--r-sm);
  padding: 8px 10px;
}
.detail dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  font-size: 12px;
}
.detail dt {
  color: var(--muted);
}
.detail dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 5px 9px;
  font-size: 12px;
  text-decoration: none;
  color: var(--ink-2);
  background: var(--panel);
}
.action:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}
.places {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.place {
  font-size: 10.5px;
  background: var(--sunk);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--ink-2);
}

/* --- map furniture -------------------------------------------------------- */

.legend {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 8;
  background: var(--panel-blur);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 8px 10px;
  font-size: 11px;
  display: grid;
  gap: 3px;
  max-height: 42vh;
  overflow: auto;
}
.legend div {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--ink-2);
}
.legend .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.map-msg {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 8;
  background: var(--panel-blur);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 11.5px;
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.maplibregl-ctrl-group {
  border-radius: var(--r) !important;
  box-shadow: var(--shadow-sm) !important;
  border: 1px solid var(--line) !important;
  overflow: hidden;
}
.maplibregl-ctrl-attrib {
  border-radius: 999px 0 0 0 !important;
  font-size: 10px;
}
.maplibregl-popup-content {
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 9px 11px;
  font: inherit;
  font-size: 12.5px;
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: var(--panel);
}
.maplibregl-popup-anchor-top .maplibregl-popup-tip {
  border-bottom-color: var(--panel);
}

/* --- mobile --------------------------------------------------------------- */

.view-toggle {
  display: none;
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .search-wrap {
    order: 3;
    flex-basis: 100%;
  }
  .search {
    width: 100%;
  }
  .kbd {
    display: none;
  }
  /* The brand wordmark goes, not the tab labels: "15 | 538" on its own says
     nothing about what is being counted. */
  .brand strong {
    display: none;
  }
  .segmented button {
    padding: 6px 9px;
  }
  .view-toggle {
    display: inline-flex;
  }

  /* One pane at a time: a floating card over a map is unusable at this width. */
  .results {
    /* top comes from --results-top (the bar's real height); no fixed guess. */
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
  }
  .detail {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 58dvh;
  }
  body[data-view='map'] .results {
    display: none;
  }
  body[data-view='list'] .legend {
    display: none;
  }
  .legend {
    bottom: 8px;
    right: 8px;
    font-size: 10px;
    max-height: 30vh;
  }
  .map-msg {
    bottom: 8px;
    font-size: 10.5px;
  }
}

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