:root {
  color-scheme: dark;
  --panel: #111318;
  --panel-soft: #181b22;
  --line: #2b303a;
  --text: #f3f6fb;
  --muted: #aab3c2;
  --accent: #ff3b30;
  --focus: #58a6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: #07090d;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.map-shell {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  min-height: 100vh;
}

.panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 28px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 20px 0 50px rgba(0, 0, 0, 0.35);
}

.panel-header {
  display: grid;
  gap: 8px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.summary {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.summary span {
  color: #ffffff;
}

.field-label {
  margin-bottom: -10px;
  color: #d7deea;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
button {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input,
select {
  width: 100%;
  padding: 0 12px;
}

button {
  padding: 0 16px;
  border-color: rgba(255, 59, 48, 0.55);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.stats strong,
.stats span {
  display: block;
}

.stats strong {
  font-size: 24px;
  line-height: 1.1;
}

.stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  min-height: 0;
  overflow: hidden;
}

.legend-title {
  margin-bottom: 10px;
  color: #d7deea;
  font-size: 13px;
  font-weight: 800;
}

#legend-list {
  display: grid;
  gap: 8px;
  max-height: 34vh;
  overflow: auto;
  padding-right: 4px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.legend-brand {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-credit {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  margin: auto 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.source-credit img {
  display: block;
  width: 58px;
  max-height: 34px;
  object-fit: contain;
}

code {
  color: #ffffff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.map-area {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  background: #07090d;
}

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

.status {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.92);
  color: #f3f6fb;
  font-size: 13px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}

.status.is-hidden {
  display: none;
}

.mapboxgl-popup-content {
  max-width: 260px;
  border-radius: 8px;
  background: #111318;
  color: #f3f6fb;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.45);
}

.popup-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 800;
}

.popup-row {
  margin: 4px 0;
  color: #aab3c2;
  font-size: 12px;
}

.mapboxgl-ctrl-geocoder {
  min-width: min(360px, calc(100vw - 32px));
  border-radius: 8px;
  background: #ffffff;
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .map-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(560px, 72vh);
  }

  .panel {
    padding: 20px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  h1 {
    font-size: 28px;
  }

  #legend-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: minmax(58px, auto);
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .legend-item {
    grid-template-columns: 12px 1fr;
    grid-template-rows: auto auto;
    gap: 4px 8px;
    align-content: start;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    font-size: 11px;
  }

  .legend-item span:last-child {
    grid-column: 2;
    font-size: 11px;
  }

  .legend-brand {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .source-credit {
    margin-top: 0;
  }

  .map-area {
    min-height: 560px;
  }
}
