:root {
  /* ── Palette ── */
  --bg:              #0b0c09;
  --surface:         #141512;
  --surface-2:       #1c1d1a;
  --surface-light:   #e9e4d9;
  --surface-light-2: #ddd8cd;

  --border:          rgba(255,255,255,0.07);
  --border-hover:    rgba(100,165,120,0.35);
  --border-light:    rgba(0,0,0,0.1);

  /* Data colours */
  --green:    #4e7a5f;
  --green-b:  #6aab82;
  --cyan:     #00c8e0;
  --yellow:   #c8922a;
  --orange:   #c85f30;
  --red:      #c43838;
  --purple:   #7b68b8;

  /* Text */
  --text:         #c8c4ba;
  --text-strong:  #e8e4da;
  --text-light:   #111110;
  --muted:        #55524c;
  --dim:          #32302c;

  /* Type */
  --font-display: 'Syne', sans-serif;
  --font-mono:    'IBM Plex Mono', monospace;

  /* Shape */
  --radius:    16px;
  --radius-sm: 8px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

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


/* ─────────────────────────────────────────
   LOADING OVERLAY
───────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.65s ease, visibility 0.65s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

.loading-logo {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-strong);
  animation: loadPulse 2s ease-in-out infinite;
}

@keyframes loadPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

.loading-bar-track {
  width: 200px;
  height: 2px;
  background: var(--dim);
  border-radius: 99px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 99px;
  animation: loadBar 2s ease-in-out infinite;
}

@keyframes loadBar {
  0%   { width: 0%;   opacity: 1; }
  70%  { width: 100%; opacity: 1; }
  100% { width: 100%; opacity: 0; }
}

.loading-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  animation: blink 1.4s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}


/* ─────────────────────────────────────────
   NAVBAR
───────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 62px;
  background: rgba(11,12,9,0.92);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Left */
.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-logo-mark {
  color: var(--green);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.nav-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-strong);
  white-space: nowrap;
}

.nav-location {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  padding: 3px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  white-space: nowrap;
}

/* Right — links + divider + clock */
.nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 99px;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 0.2s, background 0.2s;
  letter-spacing: 0.01em;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 10px;
  flex-shrink: 0;
}

.nav-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green-b);
  flex-shrink: 0;
  animation: livePulse 2.8s ease-in-out infinite;
}

@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 5px var(--green-b); }
  50%       { box-shadow: 0 0 14px var(--green-b), 0 0 28px rgba(106,171,130,0.28); }
}

.nav-clock {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-strong);
  letter-spacing: 0.1em;
}

.nav-clock-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.14em;
}


/* ─────────────────────────────────────────
   ADVISORY BANNER
───────────────────────────────────────── */
.advisory-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 28px;
  font-size: 0.83rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.5s, border-color 0.5s;
  animation: slideDown 0.4s ease;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

.advisory-banner.hidden { display: none; }

.advisory-category {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 3px 12px;
  border-radius: 99px;
  white-space: nowrap;
}

.advisory-message { color: rgba(200,196,186,0.75); }


/* ─────────────────────────────────────────
   DASHBOARD LAYOUT
───────────────────────────────────────── */
.dashboard {
  max-width: 1500px;
  margin: 0 auto;
  padding: 22px 22px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}


/* ─────────────────────────────────────────
   STATS STRIP
───────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: 1.5fr repeat(5, 1fr);
  gap: 12px;
}

/* ── Base card ── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.25s, box-shadow 0.25s;
  animation: fadeUp 0.5s ease both;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 20% 0%, rgba(78,122,95,0.05) 0%, transparent 65%);
  pointer-events: none;
}

.stat-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 1px rgba(78,122,95,0.07), 0 8px 36px rgba(0,0,0,0.55);
}

/* ── Light / hero card (Current AQI) ── */
/* ── Hero AQI card: warm elevated dark ── */
.stat-card.light-card {
  background: #1e1f1a;
  border-color: rgba(255,255,255,0.11);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

.stat-card.light-card::after {
  background: radial-gradient(ellipse at 80% 110%, rgba(200,146,42,0.07) 0%, transparent 60%);
}

.stat-card.light-card:hover {
  border-color: rgba(200,146,42,0.28);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 8px 36px rgba(0,0,0,0.6);
}

/* Override nothing — let JS-injected AQI colors show on dark bg */
.stat-card.light-card .stat-label    { color: rgba(200,196,186,0.4); }
.stat-card.light-card .stat-sub-label { color: rgba(200,196,186,0.4); }
.stat-card.light-card .stat-sub-sep  { color: var(--dim); }
.stat-card.light-card .stat-sub-val  { color: var(--text-strong); }
.stat-card.light-card .stat-unit     { color: var(--muted); }

/* Stagger */
@keyframes fadeUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.10s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.20s; }
.stat-card:nth-child(5) { animation-delay: 0.25s; }
.stat-card:nth-child(6) { animation-delay: 0.30s; }

/* ── Card elements ── */
.stat-label {
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.stat-number {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text-strong);
  transition: color 0.4s;
}

/* Hero: big AQI number */
.hero-number {
  font-size: 3.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat-unit {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.stat-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.stat-sub-label { font-size: 0.67rem; color: var(--muted); }
.stat-sub-sep   { font-size: 0.67rem; color: var(--dim); }
.stat-sub-val   { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text); }

.stat-footnote {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  color: var(--muted);
  margin-top: auto;
}

/* AQI badge */
.aqi-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: rgba(255,255,255,0.07);
  color: var(--text-strong);
  transition: background 0.4s, color 0.4s;
  white-space: nowrap;
  align-self: center;
}

.trend-icon {
  font-size: 2.2rem;
  line-height: 1;
  transition: color 0.4s;
}

.trend-label {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* Stale freshness card */
#freshnessCard.stale {
  border-color: rgba(196,56,56,0.32);
  background: rgba(196,56,56,0.04);
}


/* ─────────────────────────────────────────
   CHART ROWS
───────────────────────────────────────── */
.charts-row {
  display: grid;
  gap: 12px;
}

.main-charts-row   { grid-template-columns: 2fr 1fr 1fr; }
.analysis-row      { grid-template-columns: 1fr 1fr; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: border-color 0.25s, box-shadow 0.25s;
  animation: fadeUp 0.5s ease both;
  animation-delay: 0.35s;
}

.chart-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 8px 36px rgba(0,0,0,0.45);
}

/* ── Chart header ── */
.chart-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.chart-header h3 {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
  flex: 1;
}

.chart-sub {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--dim);
  letter-spacing: 0.06em;
}

.chart-legend {
  display: flex;
  gap: 8px;
  align-items: center;
}

.legend-pill {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.legend-pill.red   { background: rgba(196,56,56,0.14); color: #d05555; }
.legend-pill.green { background: rgba(78,122,95,0.18);  color: var(--green-b); }
.legend-pill.dashed { border: 1px dashed; }

/* ··· card menu button */
.card-menu {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  font-size: 0.9rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.08em;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  line-height: 1;
  margin-left: auto;
  flex-shrink: 0;
}

.card-menu:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface-2);
}

/* Canvas constraints — same heights as before */
canvas {
  display: block;
  width: 100% !important;
}

#aqiChart        { height: 240px !important; max-height: 240px; }
#pm25Chart       { height: 180px !important; max-height: 180px; }
#pm10Chart       { height: 180px !important; max-height: 180px; }
#dailyChart      { height: 220px !important; max-height: 220px; }
#worstHoursChart { height: 220px !important; max-height: 220px; }

.chart-wrap { position: relative; width: 100%; }


/* ─────────────────────────────────────────
   FOOTER
───────────────────────────────────────── */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 22px;
  margin-top: 20px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  letter-spacing: 0.04em;
}

.footer-sep { color: var(--dim); }


/* ─────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────── */
@media (max-width: 1280px) {
  .stats-strip { grid-template-columns: 1fr 1fr 1fr; }
  .main-charts-row { grid-template-columns: 1fr 1fr; }
  .chart-card.span-2 { grid-column: span 2; }
}

@media (max-width: 900px) {
  .main-charts-row { grid-template-columns: 1fr; }
  .chart-card.span-2 { grid-column: span 1; }
  .analysis-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .dashboard { padding: 14px 14px 0; gap: 12px; }
  .stats-strip { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-number { font-size: 1.8rem; }
  .hero-number { font-size: 2.5rem; }
  .navbar { padding: 0 14px; height: 52px; }
  .nav-location { display: none; }
  .nav-link { font-size: 0.72rem; padding: 5px 10px; gap: 5px; }
  .nav-link svg { width: 12px; height: 12px; }
  .nav-clock { font-size: 0.85rem; }
  .nav-clock-label { font-size: 0.55rem; }
  .nav-live-dot { width: 6px; height: 6px; }
  .nav-divider { margin: 0 6px; }
  .advisory-banner { padding: 10px 16px; font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .stats-strip { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-number { font-size: 1.6rem; }
  .hero-number { font-size: 2.1rem; }
  .stat-card { padding: 16px; }
  .nav-brand { font-size: 0.92rem; }
  .nav-link { font-size: 0.68rem; padding: 4px 8px; }
  .nav-clock { font-size: 0.78rem; letter-spacing: 0.06em; }
  .nav-divider { margin: 0 4px; }
}