:root {
  --bg: #f4f6f1;
  --panel: #ffffff;
  --text: #18201d;
  --muted: #65706a;
  --line: #d9e0dc;
  --byelaw: #d9412f;
  --policy: #d99b24;
  --pspo: #7a3fb3;
  --clear: #4f9f64;
  --note: #2f8f83;
  --awaiting: #64748b;
  --unknown: #8a9490;
  --airspace: #2563eb;
  --airspace-danger: #f97316;
  --airspace-prohibited: #be123c;
  --focus: #1f7a8c;
  --shadow: 0 18px 45px rgba(24, 32, 29, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 32px rgba(24, 32, 29, 0.06);
  z-index: 2;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand-row > div {
  flex: 1 1 100%;
}

.about-data-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #bdd1c8;
  border-radius: 8px;
  background: #f8faf7;
  color: #0d6678;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.about-data-button:hover {
  border-color: var(--focus);
  background: #eef7f5;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 31px;
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.22;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  border-color: #adc0b5;
  background: #eef4f0;
}

.search-wrap {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
}

.mobile-view-switch {
  display: none;
}

#searchInput {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fbfcfb;
  color: var(--text);
}

#searchInput:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(31, 122, 140, 0.14);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.status-tile {
  display: grid;
  grid-template-areas:
    "dot count"
    "label label";
  grid-template-columns: 14px minmax(0, 1fr);
  align-content: center;
  align-items: center;
  min-height: 58px;
  gap: 5px 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

.status-tile:hover,
.status-tile.active {
  border-color: var(--focus);
  background: #eef7f5;
}

.tile-label {
  grid-area: label;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.15;
}

.status-tile strong {
  grid-area: count;
  align-self: center;
  font-size: 20px;
  line-height: 1;
}

.status-tile-wide {
  grid-column: auto;
}

.status-tile-all {
  grid-column: 1 / -1;
  grid-template-areas: "dot label count";
  grid-template-columns: 14px 1fr auto;
  min-height: 42px;
}

.status-tile-all .tile-label {
  font-size: 13px;
  line-height: 1;
}

.status-dot,
.key-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
}

.status-tile .status-dot {
  grid-area: dot;
}

.status-dot.all {
  background: linear-gradient(135deg, var(--byelaw), var(--policy) 35%, var(--note) 65%, var(--clear));
}

.byelaw {
  background-color: var(--byelaw);
}

.policy {
  background-color: var(--policy);
}

.pspo {
  background-color: var(--pspo);
}

.clear {
  background-color: var(--clear);
}

.note {
  background-color: var(--note);
}

.awaiting {
  background-color: var(--awaiting);
}

.unknown {
  background-color: var(--unknown);
}

.airspace,
.airspace-restricted,
.airspace-restriction {
  background-color: var(--airspace);
}

.airspace-danger {
  background-color: var(--airspace-danger);
}

.airspace-prohibited {
  background-color: var(--airspace-prohibited);
}

.airspace-card {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 650;
}

.airspace-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid rgba(24, 32, 29, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 22px rgba(24, 32, 29, 0.12);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.airspace-toggle:hover,
.airspace-toggle.active {
  border-color: var(--airspace);
  background: #eef5ff;
}

.airspace-toggle:disabled {
  cursor: wait;
  opacity: 0.78;
}

.airspace-toggle-copy {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
}

.airspace-toggle-copy strong {
  display: block;
  font-size: 12px;
  line-height: 1.15;
}

.airspace-icon {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border: 2px solid var(--airspace);
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.16);
}

.airspace-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.selected-panel {
  display: grid;
  gap: 10px;
  flex: 0 0 auto;
  max-height: 340px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.panel-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.rule-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef4f0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

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

.selected-details {
  display: grid;
  gap: 8px;
  margin: 0;
}

.selected-details div {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 8px;
  align-items: start;
}

.selected-details dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.selected-details dd {
  margin: 0;
  color: #34403a;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.inline-source-link {
  color: #0d6678;
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.inline-source-link:hover {
  color: var(--focus);
}

.selected-explainer {
  display: grid;
  gap: 6px;
}

.still-check {
  padding: 9px 10px;
  border-left: 3px solid var(--focus);
  background: #eef7f5;
  color: #41514a;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.selected-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.text-action {
  display: inline;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #0d6678;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 900;
  line-height: 1.35;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-action:hover {
  color: var(--focus);
}

.results-list {
  display: grid;
  align-content: start;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 90px;
  overflow: auto;
  padding-right: 2px;
}

.result-button {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  align-items: start;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.result-button:hover {
  border-color: var(--focus);
  background: #eef7f5;
}

.result-button.selected {
  border-color: var(--policy);
  box-shadow: inset 0 0 0 1px var(--policy);
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfb;
  font-size: 14px;
  line-height: 1.4;
}

.result-title {
  display: block;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.result-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

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

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

.map-key {
  position: absolute;
  right: 72px;
  bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  max-width: min(640px, calc(100% - 96px));
  padding: 10px 12px;
  border: 1px solid rgba(24, 32, 29, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  z-index: 500;
}

.map-key span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.loading {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-weight: 800;
  z-index: 600;
}

.loading.hidden {
  display: none;
}

.leaflet-popup {
  max-width: calc(100vw - 32px);
}

.leaflet-popup-content-wrapper {
  max-height: calc(100vh - 56px);
  max-height: calc(100svh - 56px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.leaflet-popup-content {
  width: min(340px, calc(100vw - 84px));
  min-width: 0;
  margin: 14px;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.25;
}

.popup-source {
  margin: -4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.popup-summary {
  margin: 8px 0 10px;
  color: #4c5752;
  font-size: 13px;
  line-height: 1.42;
}

.popup-link {
  color: #0d6678;
  font-weight: 800;
}

.popup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
}

.airspace-details {
  display: grid;
  gap: 6px;
  margin: 10px 0;
}

.airspace-details div {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
}

.airspace-details dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.airspace-details dd {
  margin: 0;
  color: #34403a;
  font-size: 12px;
  line-height: 1.35;
}

.popup-footnote {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.popup-stack-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.popup-stack-label {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.popup-stack-section h4 {
  margin: 0 0 7px;
  font-size: 14px;
  line-height: 1.25;
}

.popup-stack-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.popup-stack-list li {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: start;
}

.popup-stack-list strong,
.popup-stack-list small {
  display: block;
}

.popup-stack-list strong {
  font-size: 12px;
  line-height: 1.25;
}

.popup-stack-list small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 32, 29, 0.36);
  z-index: 2000;
}

.about-modal {
  position: relative;
  width: min(760px, 100%);
  max-height: min(720px, calc(100svh - 48px));
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover {
  border-color: var(--focus);
  background: #eef7f5;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.about-grid section {
  display: grid;
  gap: 7px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.about-grid h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.about-grid p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "search"
      "view"
      "map"
      "filters"
      "selected"
      "results";
    grid-template-rows: auto auto auto minmax(460px, 72svh) auto auto auto;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    background: var(--panel);
  }

  .sidebar {
    display: contents;
  }

  .brand-row {
    grid-area: brand;
    padding: 14px 14px 0;
    background: var(--panel);
  }

  .about-data-button {
    min-height: 32px;
    padding: 0 9px;
  }

  .search-wrap {
    grid-area: search;
    padding: 10px 14px 8px;
    background: var(--panel);
  }

  .mobile-view-switch {
    display: grid;
    grid-area: view;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 0 14px 12px;
    background: var(--panel);
  }

  .mobile-view-switch button {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
  }

  .mobile-view-switch button.active {
    border-color: var(--focus);
    background: #eef7f5;
    color: var(--text);
  }

  h1 {
    font-size: 27px;
  }

  .status-grid {
    grid-area: filters;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 5px;
    margin: 14px 14px 0;
  }

  .status-tile {
    min-height: 54px;
    padding: 7px;
  }

  .tile-label {
    font-size: 10.5px;
  }

  .airspace-card {
    top: 10px;
    right: 10px;
  }

  .selected-panel {
    max-height: none;
    grid-area: selected;
    margin: 12px 14px 0;
  }

  .results-list {
    grid-area: results;
    max-height: none;
    overflow: visible;
    margin: 12px 14px 18px;
    padding-right: 0;
  }

  .map-area {
    grid-area: map;
    height: 72svh;
    min-height: 460px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .map-key {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
    max-height: 96px;
    overflow: auto;
    gap: 7px 10px;
    padding: 8px 10px;
  }

  .map-key span {
    font-size: 11px;
  }

  .leaflet-popup-content-wrapper {
    max-height: min(68svh, 430px);
  }

  .leaflet-popup-content {
    width: min(280px, calc(100vw - 64px));
    margin: 12px;
  }

  .app-shell[data-mobile-view="map"] {
    grid-template-areas:
      "brand"
      "search"
      "view"
      "map";
    grid-template-rows: auto auto auto minmax(460px, 72svh);
  }

  .app-shell[data-mobile-view="map"] .status-grid,
  .app-shell[data-mobile-view="map"] .selected-panel,
  .app-shell[data-mobile-view="map"] .results-list {
    display: none;
  }

  .app-shell[data-mobile-view="list"] {
    grid-template-areas:
      "brand"
      "search"
      "view"
      "filters"
      "selected"
      "results";
    grid-template-rows: auto auto auto auto auto auto;
  }

  .app-shell[data-mobile-view="list"] .map-area {
    display: none;
  }

  .about-modal {
    padding: 20px;
  }

  .about-grid {
    grid-template-columns: 1fr;
  }
}
