/* ===========================
   DESIGN SYSTEM: VARIABLES
   =========================== */
:root {
  --bg-deep:     #0e1210;
  --bg-mid:      #141a15;
  --bg-card:     #1a2218;
  --bg-card2:    #1f2b1e;
  --border:      #2e4030;
  --border-glow: #3d6b42;

  --text-primary: #e8ead4;
  --text-muted:   #8a9e82;
  --text-dim:     #526655;

  --good:    #6bcf7f;
  --moderate:#e8b84b;
  --poor:    #e8604b;
  --neutral: #7dbfcf;

  --accent:  #a8d98e;
  --accent2: #d4a85a;

  --font-mono:  'Space Mono', monospace;
  --font-serif: 'Libre Baskerville', Georgia, serif;

  --radius:    6px;
  --radius-lg: 10px;
}

/* ===========================
   RESET & BASE
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-mono);
  min-height: 100vh;
  overflow-x: hidden;
}

.noise-overlay {
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 1000; opacity: 0.5;
}

/* ===========================
   HEADER
   =========================== */
header {
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  background: var(--bg-mid);
  position: sticky;
  top: 0; z-index: 900;
}

.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center;
  justify-content: space-between;
  height: 64px;
}

.header-left  { display: flex; align-items: center; gap: 16px; }

.logo-mark {
  background: var(--accent); color: var(--bg-deep);
  font-family: var(--font-mono); font-weight: 700;
  font-size: 11px; letter-spacing: 1px;
  padding: 6px 10px; border-radius: var(--radius);
}

.header-text h1 {
  font-family: var(--font-serif);
  font-size: 1.15rem; font-weight: 700;
  color: var(--text-primary); line-height: 1.2;
}

.subtitle {
  font-size: 0.72rem; color: var(--text-dim);
  letter-spacing: 0.02em; margin-top: 2px;
}

.status-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 100px;
  font-size: 0.72rem; color: var(--text-muted);
}

.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
  animation: pulseAnim 2s infinite;
}

@keyframes pulseAnim {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

/* ===========================
   MAIN LAYOUT
   =========================== */
main {
  max-width: 1400px; margin: 0 auto;
  padding: 20px 24px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  align-items: start;
}

/* ===========================
   MAP
   =========================== */
.map-section { position: relative; }

.section-label {
  font-size: 0.62rem; letter-spacing: 0.12em;
  color: var(--text-dim); margin-bottom: 8px;
}

#map {
  height: 580px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.map-legend {
  margin-top: 10px; padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 16px;
}

.legend-title {
  font-size: 0.65rem; letter-spacing: 0.1em;
  color: var(--text-dim); flex-shrink: 0;
}

.legend-items {
  display: flex; align-items: center;
  gap: 8px; font-size: 0.7rem;
  color: var(--text-muted); flex-wrap: wrap;
}

.legend-dot {
  display: inline-block;
  width: 10px; height: 10px; border-radius: 50%;
}
.legend-dot.good     { background: var(--good); }
.legend-dot.moderate { background: var(--moderate); }
.legend-dot.poor     { background: var(--poor); }

/* ===========================
   PANEL CARDS
   =========================== */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Welcome */
.welcome { text-align: center; }
.welcome-icon { font-size: 2.2rem; margin-bottom: 14px; opacity: 0.7; }
.welcome h2 {
  font-family: var(--font-serif);
  font-size: 1.2rem; color: var(--text-primary);
  margin-bottom: 10px;
}
.welcome p {
  color: var(--text-muted); font-size: 0.78rem;
  line-height: 1.6; margin-bottom: 20px;
}

.welcome-metrics {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 20px;
}

.wm-item {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}

.wm-num {
  font-size: 1.4rem; font-weight: 700;
  color: var(--accent);
}

.wm-label {
  font-size: 0.62rem; color: var(--text-dim);
  letter-spacing: 0.08em;
}

/* Data sources legend in welcome panel */
.data-sources {
  text-align: left;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.ds-title {
  font-size: 0.6rem; letter-spacing: 0.15em;
  color: var(--text-dim); margin-bottom: 8px;
}

.ds-row {
  display: flex; align-items: flex-start;
  gap: 8px; margin-bottom: 5px;
  font-size: 0.68rem; color: var(--text-muted);
  line-height: 1.4;
}

.ds-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0; margin-top: 3px;
}
.ds-dot.live   { background: var(--good); }
.ds-dot.static { background: var(--neutral); }

/* Region panel header */
.region-header {
  display: flex; justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.region-tag {
  font-size: 0.6rem; letter-spacing: 0.15em;
  color: var(--text-dim); margin-bottom: 4px;
}

.region-header h2 {
  font-family: var(--font-serif);
  font-size: 1.3rem; color: var(--text-primary);
}

.close-btn {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px; height: 28px;
  border-radius: var(--radius);
  cursor: pointer; font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.close-btn:hover { background: var(--border); color: var(--text-primary); }

/* Metric tiles — now full width stacked, not 2×2 grid */
.metric-tile {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}
.metric-tile:hover { border-color: var(--border-glow); }
.metric-tile:last-of-type { margin-bottom: 0; }

.metric-header {
  display: flex; align-items: center;
  gap: 8px; margin-bottom: 6px;
}

.metric-icon  { font-size: 1rem; }

.metric-label {
  font-size: 0.58rem; letter-spacing: 0.12em;
  color: var(--text-dim);
}

.metric-value {
  font-size: 1.15rem; font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.metric-value.good     { color: var(--good); }
.metric-value.moderate { color: var(--moderate); }
.metric-value.poor     { color: var(--poor); }
.metric-value.neutral  { color: var(--neutral); }

.metric-status {
  font-size: 0.65rem; color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-chart {
  display: block; width: 100%; height: 55px;
  margin: 6px 0;
  border-radius: 3px;
}

.metric-desc {
  font-size: 0.66rem; color: var(--text-dim);
  line-height: 1.5;
}

.data-note {
  font-size: 0.63rem; color: var(--text-dim);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  line-height: 1.5;
  margin-top: 10px;
}

/* ===========================
   FOOTER
   =========================== */
footer {
  border-top: 1px solid var(--border);
  margin-top: 20px;
  padding: 14px 24px;
  background: var(--bg-mid);
}

.footer-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; justify-content: space-between;
  font-size: 0.65rem; color: var(--text-dim);
  gap: 16px; flex-wrap: wrap;
}

/* ===========================
   LEAFLET OVERRIDES
   =========================== */
.leaflet-container {
  background: #1a2218 !important;
  font-family: var(--font-mono);
}

.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  padding: 0;
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-size: 0.75rem;
}

.leaflet-popup-tip       { background: var(--bg-card); }
.leaflet-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 16px !important; padding: 6px 8px !important;
}

.popup-name {
  font-family: var(--font-serif);
  font-size: 0.9rem; color: var(--text-primary);
  margin-bottom: 4px;
}
.popup-aqi { color: var(--text-muted); font-size: 0.7rem; }

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  #map { height: 380px; }
  .header-right { display: none; }
}