:root {
  color-scheme: dark;
  --bg: #080a0c;
  --panel: rgba(15, 18, 21, 0.94);
  --panel-soft: rgba(18, 22, 25, 0.82);
  --text: #f5f7f8;
  --muted: #9da6ab;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #ff4c39;
  --accent-bright: #ff6c58;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-height: 100%; margin: 0; }

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  min-height: 320px;
}

.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 20px;
  min-height: 76px;
  padding: 12px clamp(16px, 3vw, 42px);
  background:
    linear-gradient(118deg, rgba(231, 18, 18, 0.27) 0%, rgba(231, 18, 18, 0.1) 24%, rgba(255, 157, 46, 0.18) 49%, rgba(0, 210, 133, 0.2) 78%, rgba(0, 210, 133, 0.09) 100%),
    linear-gradient(180deg, #120706 0%, #090a06 50%, #04100b 100%);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; height: 42px; }
.brand-logo { display: block; width: 260px; max-width: 100%; height: auto; aspect-ratio: 640 / 91; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--accent);
  background: rgba(255, 76, 57, 0.11);
  border: 1px solid rgba(255, 76, 57, 0.28);
  border-radius: 8px;
}

.brand-mark svg { width: 24px; height: 24px; fill: currentColor; }
.brand-mark circle { fill: #fff; }

.brand h1 { margin: 0; font-size: clamp(1rem, 1.6vw, 1.25rem); line-height: 1.08; letter-spacing: 0; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1; text-transform: uppercase; }

.dataset-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.84rem; white-space: nowrap; }
.dataset-status strong { color: var(--text); font-weight: 650; }
.dataset-status { flex-wrap: wrap; max-width: 210px; }
.dataset-status #snapshot-date { flex-basis: 100%; padding-left: 15px; font-size: .7rem; }
.location-search { position: relative; width: 100%; max-width: 580px; justify-self: center; min-width: 0; }
.location-search input { width: 100%; height: 44px; padding: 0 14px 0 42px; font: inherit; font-size: .9rem; color: var(--text); background: #181d21; border: 1px solid var(--line); border-radius: 8px; }
.location-search input:focus { outline: 2px solid var(--accent-bright); outline-offset: 1px; }
.location-search input:disabled { opacity: .6; }
.search-icon { position: absolute; top: 12px; left: 13px; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; pointer-events: none; }
.search-popup { position: absolute; top: calc(100% + 8px); left: 0; right: 0; max-height: min(420px, 60dvh); overflow: auto; overscroll-behavior: contain; color: var(--text); background: #11171b; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 30px #0008; }
.search-popup p { margin: 0; padding: 12px 14px; font-size: .74rem; color: var(--muted); }
.search-popup ul { padding: 0; margin: 0; list-style: none; }
.search-popup li { display: grid; gap: 4px; min-height: 54px; padding: 11px 14px; cursor: pointer; border-top: 1px solid var(--line); }
.search-popup li:hover, .search-popup li[aria-selected="true"] { background: #293138; }
.search-popup li strong { font-size: .9rem; font-weight: 600; overflow-wrap: anywhere; }
.search-popup li span { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #47d18c; box-shadow: 0 0 0 4px rgba(71, 209, 140, 0.12); }

.panel-close {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.panel-close:hover { background: rgba(255, 255, 255, 0.11); }
.panel-close:focus-visible, .map-action:focus-visible, #retry-data:focus-visible { outline: 3px solid rgba(255, 108, 88, 0.5); outline-offset: 2px; }
.panel-close svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.map-workspace { position: relative; min-height: 0; overflow: hidden; background: #111518; }
#map { position: absolute; inset: 0; }

.maplibregl-ctrl-top-left { top: 14px; left: 14px; }
.maplibregl-ctrl-group { overflow: hidden; background: rgba(10, 13, 15, 0.91); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 14px 34px rgba(0,0,0,.22); }
.maplibregl-ctrl-group button { width: 38px; height: 38px; background-color: transparent; }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1); opacity: .9; }
.maplibregl-ctrl-attrib { background: rgba(8,10,12,.82) !important; color: #c4cbce; }
.maplibregl-ctrl-attrib a { color: #fff; }
.maplibregl-ctrl-attrib-inner { color: #c4cbce; }

.location-panel {
  position: absolute;
  z-index: 10;
  top: 18px;
  right: 18px;
  width: min(380px, calc(100% - 36px));
  max-height: calc(100% - 36px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0,0,0,.36);
  backdrop-filter: blur(16px);
}

.panel-handle { display: none; }

.panel-content { padding: 18px; }
.panel-heading { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 12px; align-items: center; }
.selected-sign { display: block; width: 48px; height: 56px; }
.selected-sign svg { display: block; width: 100%; height: 100%; }
.eyebrow { margin: 0 0 3px; color: var(--accent-bright); font-size: .72rem; font-weight: 750; text-transform: uppercase; }
.panel-heading h2 { margin: 0; font-size: 1.08rem; line-height: 1.2; }
.panel-close { width: 34px; height: 34px; }

.location-facts { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin: 18px 0; }
.location-facts div { padding: 11px 12px; background: rgba(255,255,255,.045); border-radius: 6px; }
.location-facts dt { color: var(--muted); font-size: .71rem; text-transform: uppercase; }
.location-facts dd { margin: 5px 0 0; color: var(--text); font-size: .88rem; font-weight: 650; overflow-wrap: anywhere; }
.location-facts .address-fact { grid-column: 1 / -1; }
#selected-address { white-space: pre-line; line-height: 1.5; min-height: 3em; }
.location-facts .address-note { color: var(--muted); font-size: .72rem; font-weight: 400; line-height: 1.4; }
#selected-since span { display: block; }
#selected-since .recorded-time { margin-top: 2px; color: var(--muted); font-size: .76rem; font-weight: 500; }

.map-actions { display: grid; gap: 8px; }
.map-action { display: grid; grid-template-columns: 34px minmax(0,1fr) 18px; gap: 11px; align-items: center; min-height: 62px; padding: 10px 12px; color: var(--text); text-decoration: none; background: rgba(255,255,255,.055); border: 1px solid var(--line); border-radius: 7px; transition: background-color .18s ease, border-color .18s ease, transform .18s ease; }
.map-action:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); transform: translateY(-1px); }
.map-action > svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.action-logo { display: grid; place-items: center; width: 34px; height: 34px; color: #fff; font-weight: 800; background: #276ef1; border-radius: 7px; }
.action-logo { background: #253743; }
.action-logo svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.map-action strong, .map-action small { display: block; }
.map-action strong { font-size: .91rem; }
.map-action small { margin-top: 3px; color: var(--muted); font-size: .74rem; }
.coverage-note { margin: 13px 0 0; color: var(--muted); font-size: .72rem; line-height: 1.45; }

.map-legend { position: absolute; z-index: 8; left: 18px; bottom: 18px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 8px 11px; color: #e8edef; font-size: .75rem; background: rgba(10,13,15,.9); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 10px 28px rgba(0,0,0,.25); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-sign { display: block; width: 24px; height: 28px; }
.legend-sign svg { display: block; width: 100%; height: 100%; }

.loading-panel, .error-panel { position: absolute; z-index: 12; left: 50%; top: 50%; transform: translate(-50%,-50%); display: flex; align-items: center; gap: 12px; padding: 14px 17px; color: #fff; font-size: .86rem; background: rgba(10,13,15,.93); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.loading-line { width: 34px; height: 4px; overflow: hidden; background: rgba(255,255,255,.12); border-radius: 99px; }
.loading-line::after { content: ""; display: block; width: 15px; height: 100%; background: var(--accent); animation: load 1s ease-in-out infinite alternate; }
@keyframes load { from { transform: translateX(0); } to { transform: translateX(19px); } }
.error-panel { flex-direction: column; text-align: center; }
.loading-panel[hidden], .error-panel[hidden], .panel-content[hidden] { display: none; }
#retry-data { padding: 9px 13px; color: #fff; background: var(--accent); border: 0; border-radius: 6px; font-weight: 700; cursor: pointer; }

.map-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 20px; padding: 7px 16px max(7px, env(safe-area-inset-bottom)); color: #7e898e; font-size: .68rem; line-height: 1.35; background: #090c0e; border-top: 1px solid var(--line); }
.map-footer a { color: #b9c1c5; }

@media (max-width: 720px) {
  .topbar { grid-template-columns: minmax(0,1fr); gap: 10px; min-height: 66px; padding: 10px 12px; }
  .brand { height: 38px; }
  .brand-logo { width: 220px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand h1 { font-size: .98rem; }
  .dataset-status { grid-column: 1 / -1; grid-row: 3; max-width: none; justify-content: center; min-height: 19px; margin-top: -4px; font-size: .72rem; }
  .location-search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .dataset-status #snapshot-date { display: none; }
  .location-panel { position: absolute; top: auto; right: 8px; bottom: 8px; left: 8px; width: auto; max-height: min(57%, 430px); border-radius: 8px; transform: translateY(calc(100% + 16px)); transition: transform .24s ease; }
  .location-panel.is-open { transform: translateY(0); }
  .panel-handle { display: block; width: 38px; height: 4px; margin: 8px auto 0; background: rgba(255,255,255,.22); border-radius: 99px; }
  .panel-content { padding: 10px 14px 15px; }
  .location-facts { margin: 13px 0; }
  .map-action { min-height: 56px; }
  .map-legend { top: 8px; right: 8px; bottom: auto; left: auto; max-width: calc(100% - 76px); padding: 7px 9px; }
  .map-footer { display: none; }
  .maplibregl-ctrl-top-left { top: 8px; left: 8px; }
}

@media (max-width: 420px) {
  .brand p { display: none; }
  .location-facts { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 721px) and (max-width: 1050px) {
  .topbar { gap: 12px; padding: 12px 16px; grid-template-columns: auto minmax(180px, 1fr); }
  .dataset-status { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
