:root {
  /* Brand Colors */
  --color-brand: #1D9E75;
  --color-brand-dim: #12634a;
  
  /* Backgrounds (Dark First) */
  --color-bg: #161616;
  --color-bg-alt: #111111;
  --color-surface: #212121;
  --color-surface-alt: #2a2a2a;
  
  /* Text */
  --color-text: #FFFFFF;
  --color-text-muted: #888888;
  --color-text-dim: #444444;
  --color-text-tertiary: #555555;
  
  /* PM2.5 Bands (Thai Standard) */
  --pm-very-good: #378ADD; /* 0–15 µg/m³ */
  --pm-good: #4caf50;      /* 15–25 µg/m³ */
  --pm-moderate: #ef9f27;  /* 25.1–37.5 */
  --pm-sensitive: #d85a30; /* 37.6–75 */
  --pm-unhealthy: #a32d2d; /* 75.1+ */

  /* UI Constants */
  --border-radius-lg: 16px;
  --border-radius-md: 12px;
  --border-radius-sm: 8px;
  --border-color: #242424;
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
}

/* Base Reset */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 60px; /* Space for tab bar */
  min-height: 100vh;
}

@media (min-width: 768px) {
  body { padding-bottom: 0; padding-top: 64px; }
}

/* Layout Containers */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (min-width: 768px) {
  .container { max-width: 1000px; }
}

/* Shared Navigation - Tab Bar (Mobile) */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(60px + var(--safe-area-bottom));
  background: var(--color-bg-alt);
  border-top: 0.5px solid var(--border-color);
  display: flex;
  padding-bottom: var(--safe-area-bottom);
  z-index: 1000;
}

@media (min-width: 768px) {
  .tab-bar { display: none; }
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  position: relative;
  color: var(--color-text-tertiary); /* Default text color */
}

.tab svg { 
  width: 22px; height: 22px; 
  stroke: var(--color-text-dim); 
  fill: none; 
  stroke-width: 1.5;
  transition: stroke 0.2s;
}

.tab span { font-size: 12px; font-weight: 500; color: inherit; }

.tab.active { color: var(--color-brand); }
.tab.active svg { stroke: var(--color-brand); }

.tab.active::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 4px; height: 4px;
  background: var(--color-brand);
  border-radius: 50%;
}

/* Top Nav (Desktop) */
.top-nav {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 64px;
  background: var(--color-bg-alt);
  border-bottom: 0.5px solid var(--border-color);
  z-index: 1000;
  align-items: center;
  padding: 0 24px;
}

@media (min-width: 768px) {
  .top-nav { display: flex; justify-content: space-between; }
}

.nav-brand { font-size: 18px; font-weight: 700; color: var(--color-brand); text-decoration: none; }
.nav-links-container { display: flex; align-items: center; gap: 12px; } /* Ensures right-aligned container */
.nav-links { display: flex; gap: 8px; align-items: center; }
.nav-links a { 
  color: var(--color-text-muted); 
  text-decoration: none; 
  font-size: 14px; font-weight: 500; 
  padding: 8px 16px; border-radius: 20px;
  transition: all 0.2s;
}
.nav-links a.active { background: rgba(255,255,255,0.1); color: #fff; }

/* Dropdown Logic - Improved with pseudo-element bridge to prevent closing on gap */
.dropdown { position: relative; display: inline-block; padding-bottom: 12px; margin-bottom: -12px; } /* Bridge padding */
.dropdown-trigger { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.dropdown-content {
  display: none;
  position: absolute;
  top: 100%; right: 0; /* Align sub-menu to right edge of parent */
  background-color: var(--color-bg-alt);
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-color);
  padding: 8px 0;
  z-index: 1001;
  margin-top: 0; /* No gap! */
}
.dropdown:hover .dropdown-content { display: block; }

.dropdown-content a {
  display: block;
  padding: 12px 20px;
  border-radius: 0;
  font-size: 14px;
  color: var(--color-text-muted) !important;
  background: transparent !important;
  text-align: left;
}
.dropdown-content a:hover { color: #fff !important; background: rgba(255,255,255,0.05) !important; }
.nav-status { font-size: 12px; color: var(--color-text-dim); text-align: right; margin-left: 12px; }

/* Breadcrumbs (Desktop Only) */
.breadcrumbs {
  display: none;
  font-size: 12px;
  color: var(--color-text-dim);
  padding: 8px 0;
  margin-top: 8px;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

@media (min-width: 768px) {
  .breadcrumbs { display: flex; }
}

.breadcrumbs a { 
  color: var(--color-text-muted); 
  text-decoration: none; 
  transition: color 0.2s; 
}
.breadcrumbs a:hover { color: var(--color-brand); }
.breadcrumbs .sep { color: var(--color-text-dim); opacity: 0.5; }
.breadcrumbs .current { color: var(--color-text-dim); }

/* Mobile Header Helpers */
.mobile-header-primary {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(12px + var(--safe-area-top)) 16px 12px;
  height: auto;
}
.mobile-header-inner {
  display: flex; align-items: center;
  padding: var(--safe-area-top) 14px 0;
  height: calc(56px + var(--safe-area-top));
  gap: 12px;
  background: var(--color-bg);
  border-bottom: 0.5px solid var(--border-color);
}
@media (min-width: 768px) {
  .mobile-only-header, .mobile-header-primary, .mobile-header-inner { display: none !important; }
}

.back-btn {
  width: 28px; height: 28px;
  background: var(--color-surface-alt);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: none;
}

.pg-title { font-size: 16px; font-weight: 700; color: #fff; flex: 1; line-height: 1.2; }
.pg-sub { font-size: 12px; color: var(--color-text-tertiary); margin-top: 1px; }

/* Home Hero Card */
.hero-card {
  background: var(--pm-moderate); /* Fallback */
  border-radius: var(--border-radius-lg);
  padding: 20px;
  margin: 16px 0;
  text-decoration: none;
  display: block;
  transition: transform 0.2s;
}

.hero-card[data-band="very-good"] { background-color: #0f2035; border: 1px solid #1e3a5a; }
.hero-card[data-band="good"] { background-color: #1a2e1a; border: 1px solid #2e4a2e; }
.hero-card[data-band="moderate"] { background-color: #EF9F27; }
.hero-card[data-band="sensitive"] { background-color: #d85a30; }
.hero-card[data-band="unhealthy"] { background-color: #a32d2d; }

.hero-tag { font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.65); letter-spacing: 0.05em; margin-bottom: 4px; text-transform: uppercase; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; }
.hero-num { font-size: 36px; font-weight: 700; color: #fff; line-height: 1; }
.hero-unit { font-size: 12px; color: rgba(255,255,255,0.65); margin-top: 2px; }
.hero-badge { background: rgba(0,0,0,0.25); color: #fff; font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 20px; }
.hero-cta { color: rgba(255,255,255,0.8); font-size: 12px; margin-top: 12px; font-weight: 500; }
.data-source { font-size: 10px; color: var(--color-text-dim); text-align: center; margin-top: 32px; padding-bottom: 24px; }
.data-source a { color: var(--color-text-dim); text-decoration: underline; text-underline-offset: 2px; }

/* Nearest Park Row */
.nearest {
  background: var(--color-surface);
  border-radius: var(--border-radius-md);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 24px;
}
.nearest-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-brand); flex-shrink: 0; box-shadow: 0 0 8px var(--color-brand); }
.nearest-text { flex: 1; font-size: 14px; color: rgba(255,255,255,0.7); line-height: 1.4; }
.nearest-text b { color: var(--color-brand); font-weight: 600; }
.nearest-time { font-size: 12px; color: var(--color-text-dim); }

/* Quick Tool Grid */
.section-label { padding: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--color-text-dim); letter-spacing: 0.05em; text-transform: uppercase; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 24px; }
.tool-card {
  background: var(--color-surface);
  border-radius: var(--border-radius-md);
  padding: 14px;
  text-decoration: none;
  transition: transform 0.2s;
}
.tool-icon { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.tool-name { font-size: 14px; font-weight: 600; color: #fff; }
.tool-desc { font-size: 12px; color: var(--color-text-tertiary); margin-top: 2px; line-height: 1.3; }

/* Tool Hub Cards */
.hub-card {
  background: var(--color-surface);
  border-radius: var(--border-radius-md);
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  text-decoration: none;
  margin-bottom: 10px;
}
.hub-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.hub-info { flex: 1; }
.hub-name { font-size: 15px; font-weight: 600; color: #fff; }
.hub-desc { font-size: 12px; color: var(--color-text-tertiary); margin-top: 1px; }
.hub-chevron { color: var(--color-text-dim); font-size: 16px; }

/* Chip / Filter Button */
.chip {
  white-space: nowrap;
  padding: 8px 16px;
  background: var(--color-surface);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.chip.active {
  background: var(--color-brand);
  color: #fff;
  border-color: var(--color-brand);
}

/* Area / Section Header */
.area-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 16px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.area-header span { font-weight: 500; opacity: 0.7; }

/* Park Card */
.park-card {
  background: var(--color-surface);
  border-radius: var(--border-radius-md);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border-color);
}
.park-info { flex: 1; }
.park-name { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 2px; }
.park-district { font-size: 12px; color: var(--color-text-tertiary); }
.park-pm { text-align: right; margin-left: 12px; }
.pm-val { font-size: 20px; font-weight: 800; line-height: 1; }
.pm-unit { font-size: 9px; color: var(--color-text-dim); margin-top: 2px; font-weight: 700; }
.pm-time { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.aqi-chip { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; color: #fff; white-space: nowrap; }
.pm-time-label { font-size: 11px; color: var(--color-text-muted); font-weight: 500; white-space: nowrap; }

/* Location Prompt Card */
.location-prompt-card {
  background: var(--color-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.location-prompt-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(29, 158, 117, 0.12);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.location-prompt-body { flex: 1; }
.location-prompt-title { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.location-prompt-sub { font-size: 12px; color: var(--color-text-muted); line-height: 1.5; margin-bottom: 14px; }
.location-prompt-actions { display: flex; gap: 8px; }
.location-prompt-allow {
  background: var(--color-brand); color: #fff; border: none;
  border-radius: 20px; padding: 8px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: opacity 0.2s;
}
.location-prompt-allow:active { opacity: 0.85; }
.location-prompt-dismiss {
  background: transparent; color: var(--color-text-muted);
  border: 1px solid var(--border-color);
  border-radius: 20px; padding: 8px 16px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: color 0.2s;
}
.location-prompt-dismiss:active { color: #fff; }

/* Interactive States */
.hero-card:active, .tool-card:active, .hub-card:active, .back-btn:active { transform: scale(0.97); }

/* Hide desktop nav on mobile */
@media (max-width: 767px) {
  .top-nav { display: none; }
}
