:root {
  --bg: #f7f7f7;
  --fg: #14181d;
  --panel: rgba(255, 255, 255, 0.95);
  --panel-border: rgba(0, 0, 0, 0.12);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  --accent: #1f7ed8;
  --amber: #d49a00;
  --vfr: #3aa84a;
  --mvfr: #1f7ed8;
  --ifr: #d33;
  --lifr: #a64dff;
  --marker-stroke: #ffffff;
  --tile-filter: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --fg: #eef1f5;
    --panel: rgba(28, 32, 38, 0.96);
    --panel-border: rgba(255, 255, 255, 0.14);
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    --marker-stroke: #d8dce2;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ---------- Updated badge (top-left) ---------- */
.badge {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px;
  z-index: 1000;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 60vw;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--vfr);
  flex-shrink: 0;
}
.badge.badge-stale::before { background: var(--amber); }
.badge.badge-error::before { background: var(--ifr); }

/* ---------- Search (top-right) ---------- */
.search {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  z-index: 1000;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 4px 4px 12px;
  box-shadow: var(--shadow);
}
.search input {
  border: 0;
  background: transparent;
  color: var(--fg);
  outline: none;
  width: 110px;
  font-size: 14px;
  text-transform: uppercase;
}
.search input::placeholder { color: rgba(127, 127, 127, 0.8); text-transform: none; }
.search button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: 13px;
  min-height: 32px;
  cursor: pointer;
}

/* ---------- Legend (bottom) ---------- */
.legend {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  scrollbar-width: none;
}
.legend::-webkit-scrollbar { display: none; }

.chip {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  min-height: 36px;
  min-width: 44px;
  color: #fff;
  opacity: 1;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.chip:active { transform: scale(0.96); }
.chip[aria-pressed="false"] { opacity: 0.35; }
.chip-vfr    { background: var(--vfr); }
.chip-mvfr   { background: var(--mvfr); }
.chip-ifr    { background: var(--ifr); }
.chip-lifr   { background: var(--lifr); }
.chip-sigmet { background: #7a4a18; }

/* ---------- Map markers ---------- */
.airport-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--marker-stroke);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.airport-marker-vfr  { background: var(--vfr); }
.airport-marker-mvfr { background: var(--mvfr); }
.airport-marker-ifr  { background: var(--ifr); }
.airport-marker-lifr { background: var(--lifr); }
.airport-marker-unknown { background: #777; }

/* Cluster bubbles inherit marker palette */
.marker-cluster-vfr  div { background: var(--vfr) !important; color: #fff !important; }
.marker-cluster-mvfr div { background: var(--mvfr) !important; color: #fff !important; }
.marker-cluster-ifr  div { background: var(--ifr) !important; color: #fff !important; }
.marker-cluster-lifr div { background: var(--lifr) !important; color: #fff !important; }
.marker-cluster-vfr, .marker-cluster-mvfr, .marker-cluster-ifr, .marker-cluster-lifr {
  background: rgba(255, 255, 255, 0.25) !important;
}

/* ---------- Popup ---------- */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--fg);
  border-radius: 12px;
  border: 1px solid var(--panel-border);
}
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content {
  margin: 12px 14px;
  max-width: 92vw;
  max-height: 70vh;
  overflow: auto;
  font-size: 13px;
  line-height: 1.4;
}
.popup h3 {
  margin: 0 0 4px 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.popup .cat {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}
.popup .cat-VFR  { background: var(--vfr); }
.popup .cat-MVFR { background: var(--mvfr); }
.popup .cat-IFR  { background: var(--ifr); }
.popup .cat-LIFR { background: var(--lifr); }
.popup .cat-UNKNOWN { background: #777; }

.popup .meta { color: rgba(127, 127, 127, 1); font-size: 11px; margin-bottom: 8px; }
.popup .raw, .popup .taf-raw {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: rgba(127, 127, 127, 0.12);
  padding: 6px 8px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0;
}
.popup table { border-collapse: collapse; width: 100%; margin-top: 4px; }
.popup td { padding: 2px 6px 2px 0; vertical-align: top; }
.popup td:first-child { color: rgba(127, 127, 127, 1); width: 30%; }
.popup .taf-toggle {
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  min-height: 32px;
}
.popup .taf-section { margin-top: 8px; }
.popup .taf-section h4 { margin: 0 0 4px 0; font-size: 12px; color: rgba(127, 127, 127, 1); }

/* SIGMET polygon style is set in JS; styles for the legend chip only here. */

/* ---------- Leaflet attribution tweak ---------- */
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.7) !important;
  font-size: 10px !important;
}
@media (prefers-color-scheme: dark) {
  .leaflet-control-attribution {
    background: rgba(20, 20, 20, 0.75) !important;
    color: #ccc !important;
  }
  .leaflet-control-attribution a { color: #9bd1ff !important; }
}

/* ---------- Mobile breakpoint adjustments ---------- */
@media (max-width: 480px) {
  .badge { font-size: 12px; padding: 6px 10px; }
  .search input { width: 95px; }
  .chip { padding: 8px 10px; font-size: 11px; }
  .leaflet-popup-content { font-size: 13px; }
}
