/* ─── Custom Properties ─────────────────────────────────── */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent: #0369a1;
  --wait-low: #15803d;
  --wait-med: #b45309;
  --wait-high: #b91c1c;
  --wait-text: white;
  --nav-height: 56px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e2d42;
  --border: #3d5068;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #38bdf8;
  --wait-low: #22c55e;
  --wait-med: #f59e0b;
  --wait-high: #ef4444;
  --wait-text: white;
}

/* Lift dark map tiles out of jet-black for better geographic contrast */
[data-theme="dark"] .leaflet-tile-pane {
  filter: grayscale(1) brightness(1.9) contrast(1.2);
}

/* ─── Reset & Base ───────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  transition: background 0.2s, color 0.2s;
}

/* ─── Nav ────────────────────────────────────────────────── */

#nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 1000;
}

#nav-brand {
  font-weight: 800;
  font-size: 15px;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

#nav-search-wrap {
  flex: 1;
  position: relative;
  max-width: 400px;
}

#search {
  width: 100%;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  z-index: 1001;
  display: none;
}

#search-results.visible { display: block; }

#search-results li {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
}

#search-results li:hover,
#search-results li[aria-selected="true"] {
  background: var(--bg);
  color: var(--accent);
}

#theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  flex-shrink: 0;
  line-height: 1;
}

/* ─── Main Layout ────────────────────────────────────────── */

#main {
  position: fixed;
  top: var(--nav-height);
  bottom: 0; left: 0; right: 0;
  display: flex;
  overflow: hidden;
}

/* ─── Airport Labels ─────────────────────────────────────── */

.airport-label {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 3px var(--bg), 0 0 6px var(--bg);
  white-space: nowrap;
  pointer-events: none;
}

.airport-label::before { display: none !important; }

/* ─── Map ────────────────────────────────────────────────── */

#map-container {
  flex: 1;
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

#map-legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
  pointer-events: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-low { color: var(--wait-low); font-weight: 600; }
.legend-med { color: var(--wait-med); font-weight: 600; }
.legend-high { color: var(--wait-high); font-weight: 600; }

/* ─── Detail Panel (desktop) ─────────────────────────────── */

#detail-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  position: relative;
}

#detail-panel[hidden] {
  display: none;
}

#detail-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

#detail-close:hover { color: var(--text-primary); }

/* Detail panel content pieces — populated by JS */
.detail-code {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.detail-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.detail-location {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.wait-badge {
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  margin-bottom: 14px;
}

.wait-badge .wait-number {
  font-size: 36px;
  font-weight: 800;
  color: var(--wait-text);
  line-height: 1;
}

.wait-badge .wait-label {
  font-size: 11px;
  color: var(--wait-text);
  opacity: 0.85;
  margin-top: 2px;
}

.wait-badge.low  { background: var(--wait-low); }
.wait-badge.med  { background: var(--wait-med); }
.wait-badge.high { background: var(--wait-high); }

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* 24-hour bar chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 48px;
  margin-bottom: 4px;
}

.bar-chart .bar {
  flex: 1;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}

.bar-chart .bar.current {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.bar-chart .bar.low  { background: var(--wait-low); }
.bar-chart .bar.med  { background: var(--wait-med); }
.bar-chart .bar.high { background: var(--wait-high); }

.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.precheck-row {
  font-size: 12px;
  color: var(--wait-low);
  font-weight: 600;
  margin-bottom: 4px;
}

.precheck-row.none {
  color: var(--text-secondary);
  font-weight: 400;
}

.peak-hours {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ─── Airport List (mobile) ──────────────────────────────── */

#airport-list {
  display: none; /* shown via media query */
  overflow-y: auto;
  width: 100%;
}

.airport-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.airport-row-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.airport-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.airport-dot.low  { background: var(--wait-low); }
.airport-dot.med  { background: var(--wait-med); }
.airport-dot.high { background: var(--wait-high); }

.airport-row-name {
  flex: 1;
}

.airport-row-name strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
}

.airport-row-name span {
  font-size: 12px;
  color: var(--text-secondary);
}

.airport-row-wait {
  font-size: 15px;
  font-weight: 700;
}

.airport-row-wait.low  { color: var(--wait-low); }
.airport-row-wait.med  { color: var(--wait-med); }
.airport-row-wait.high { color: var(--wait-high); }

.airport-row-detail {
  padding: 0 16px 14px 36px;
  display: none;
}

.airport-row.expanded .airport-row-detail {
  display: block;
}

/* ─── FAA Status Alerts ──────────────────────────────────── */

.faa-alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.4;
}

.faa-alert-icon {
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1.2;
}

.faa-alert strong {
  color: var(--text-primary);
  font-size: 12px;
}

.faa-alert-reason {
  color: var(--text-secondary);
  font-size: 11px;
}

.faa-closure {
  background: rgba(185, 28, 28, 0.12);
  border: 1px solid rgba(185, 28, 28, 0.3);
}

.faa-ground-delay {
  background: rgba(180, 83, 9, 0.12);
  border: 1px solid rgba(180, 83, 9, 0.3);
}

.faa-delays {
  margin-bottom: 8px;
}

.faa-delay-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.faa-delay-row:last-child {
  border-bottom: none;
}

.faa-delay-label {
  flex: 1;
  color: var(--text-secondary);
}

.faa-delay-range {
  color: var(--text-primary);
  font-weight: 600;
}

.faa-trend {
  font-size: 11px;
  font-weight: 600;
  min-width: 80px;
  text-align: right;
}

.trend-up     { color: var(--wait-high); }
.trend-down   { color: var(--wait-low);  }
.trend-steady { color: var(--text-secondary); }

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 768px) {
  :root { --nav-height: 96px; } /* two rows on mobile */

  #nav {
    flex-wrap: wrap;
    height: var(--nav-height);
    padding: 8px 16px;
    gap: 8px;
  }

  #nav-brand { flex: 1; }
  #theme-toggle { flex-shrink: 0; }

  #nav-search-wrap {
    order: 3;
    max-width: 100%;
    width: 100%;
    flex-basis: 100%;
  }

  #main {
    flex-direction: column;
    overflow: hidden;
  }

  #map-container {
    height: 180px;
    flex: none;
  }

  #detail-panel { display: none !important; }

  #airport-list {
    display: block;
    flex: 1;
    min-height: 0;
  }
}

/* ─── Weather ────────────────────────────────────────────── */

.weather-condition {
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.weather-row {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.weather-loading {
  font-size: 12px;
  color: var(--text-secondary);
}
