/* =============================================================================
   Air Pollution Dashboard Pro — Styles
   ============================================================================= */

/* ---------- CSS Variables / Theming ---------- */
:root {
  --bg-primary: #0f1923;
  --bg-secondary: #1a2736;
  --bg-card: #1e2d3d;
  --bg-card-hover: #243447;
  --text-primary: #e8edf2;
  --text-secondary: #8a9bb0;
  --text-muted: #5a6d82;
  --border-color: #2a3a4a;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: .25s cubic-bezier(.4,0,.2,1);

  /* AQI Colors */
  --aqi-good: #4caf50;
  --aqi-fair: #ffeb3b;
  --aqi-moderate: #ff9800;
  --aqi-poor: #f44336;
  --aqi-very-poor: #9c27b0;
  --aqi-hazardous: #7e0023;
}

[data-theme="light"] {
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Header ---------- */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

.logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--aqi-good), var(--accent));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-weight: 700;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.demo-badge {
  font-size: .7rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,152,0,.15);
  color: #ff9800;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  display: none;
}

.demo-badge.visible { display: inline-block; }

/* Theme toggle */
.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

/* ---------- Main Layout ---------- */
.main-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---------- Search Bar ---------- */
.search-section {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.search-wrapper {
  flex: 1;
  position: relative;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: .95rem;
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }

.search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  max-height: 260px;
  overflow-y: auto;
  display: none;
}

.search-suggestions.active { display: block; }

.suggestion-item {
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .9rem;
}

.suggestion-item:hover, .suggestion-item.active {
  background: var(--bg-card-hover);
}

.suggestion-item .country {
  color: var(--text-muted);
  font-size: .8rem;
}

.btn-search {
  padding: 0 24px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-search:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ---------- Top Stats Row ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card .label {
  font-size: .78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 600;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-card .unit {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.stat-card .sub {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Color accents for cards */
.stat-card[data-pollutant="aqi"]::before   { background: var(--accent); }
.stat-card[data-pollutant="pm25"]::before  { background: var(--aqi-poor); }
.stat-card[data-pollutant="pm10"]::before  { background: var(--aqi-moderate); }
.stat-card[data-pollutant="o3"]::before    { background: #00bcd4; }
.stat-card[data-pollutant="no2"]::before   { background: #ff5722; }
.stat-card[data-pollutant="so2"]::before   { background: #9c27b0; }
.stat-card[data-pollutant="co"]::before    { background: #607d8b; }

/* ---------- AQI Hero Card ---------- */
.aqi-hero {
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.aqi-hero::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 300px;
  height: 300px;
  background: rgba(255,255,255,.06);
  border-radius: 50%;
}

.aqi-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 3px solid rgba(255,255,255,.3);
}

.aqi-circle .number {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
}

.aqi-circle .label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .85;
}

.aqi-info h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .25rem;
}

.aqi-info .city-name {
  font-size: 1rem;
  opacity: .85;
  margin-bottom: .5rem;
}

.aqi-info .description {
  font-size: .9rem;
  opacity: .75;
  line-height: 1.5;
  max-width: 400px;
}

/* ---------- Two-Column Layout (Map + Chart) ---------- */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition);
}

.panel:hover { box-shadow: var(--shadow-md); }

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header h3 .icon {
  font-size: 1.1rem;
}

.panel-body {
  padding: 1.25rem;
}

/* Map */
#map {
  height: 420px;
  width: 100%;
  border-radius: 0;
}

.map-panel .panel-body {
  padding: 0;
}

/* Chart container */
.chart-container {
  position: relative;
  height: 380px;
}

.chart-controls {
  display: flex;
  gap: 6px;
}

.chart-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  font-size: .78rem;
  cursor: pointer;
  transition: all var(--transition);
}

.chart-btn.active, .chart-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- AQI Scale Legend ---------- */
.aqi-legend {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .75rem;
}

.legend-item {
  text-align: center;
  border-radius: var(--radius-sm);
  padding: .75rem .5rem;
  transition: transform var(--transition);
}

.legend-item:hover { transform: translateY(-2px); }

.legend-color {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  margin-bottom: 8px;
}

.legend-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-primary);
}

.legend-range {
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Top Polluted Cities ---------- */
.cities-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.city-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  transition: all var(--transition);
  cursor: pointer;
}

.city-row:hover {
  background: var(--bg-card-hover);
  transform: translateX(4px);
}

.city-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.city-row .city-info {
  flex: 1;
  min-width: 0;
}

.city-row .city-info .name {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.city-row .city-info .country-tag {
  font-size: .72rem;
  color: var(--text-muted);
}

.city-row .aqi-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.city-row .aqi-value {
  font-size: .9rem;
  font-weight: 800;
  flex-shrink: 0;
  width: 40px;
  text-align: right;
}

/* ---------- Pollutant Detail Cards ---------- */
.pollutant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.pollutant-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.pollutant-card:hover {
  border-color: var(--border-color);
  transform: translateY(-2px);
}

.pollutant-card .p-name {
  font-size: .78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.pollutant-card .p-value {
  font-size: 1.5rem;
  font-weight: 800;
}

.pollutant-card .p-unit {
  font-size: .72rem;
  color: var(--text-muted);
}

.pollutant-card .p-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border-color);
  margin-top: 10px;
  overflow: hidden;
}

.pollutant-card .p-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .6s ease;
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: .8rem;
  border-top: 1px solid var(--border-color);
  margin-top: 1rem;
}

.footer a { color: var(--accent); }

/* ---------- Loading Spinner ---------- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.loading-overlay.active { opacity: 1; pointer-events: auto; }

/* ---------- Animations ---------- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
  animation: fadeInUp .5s ease forwards;
}

/* Staggered children */
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .1s; }
.stagger > *:nth-child(3) { animation-delay: .15s; }
.stagger > *:nth-child(4) { animation-delay: .2s; }
.stagger > *:nth-child(5) { animation-delay: .25s; }
.stagger > *:nth-child(6) { animation-delay: .3s; }
.stagger > *:nth-child(7) { animation-delay: .35s; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-2col {
    grid-template-columns: 1fr;
  }
  .aqi-legend {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .header {
    padding: 0 1rem;
  }
  .header h1 { font-size: 1rem; }
  .main-content { padding: 1rem; gap: 1rem; }

  .aqi-hero {
    flex-direction: column;
    text-align: center;
    padding: 1.5rem;
    gap: 1rem;
  }

  .aqi-circle { width: 100px; height: 100px; }
  .aqi-circle .number { font-size: 2rem; }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .search-section {
    flex-direction: column;
  }

  #map { height: 300px; }

  .chart-container { height: 280px; }

  .aqi-legend {
    grid-template-columns: repeat(2, 1fr);
  }

  .pollutant-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr;
  }
  .aqi-legend {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---------- Leaflet Custom Overrides ---------- */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-lg) !important;
  border: 1px solid var(--border-color) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-color) !important;
}

.leaflet-popup-content {
  margin: 10px 14px !important;
  font-family: 'Inter', sans-serif !important;
  font-size: .85rem !important;
  line-height: 1.5 !important;
}

.popup-city { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.popup-aqi { font-size: .8rem; padding: 2px 8px; border-radius: 10px; color: #fff; display: inline-block; margin-bottom: 4px; }
.popup-detail { font-size: .78rem; color: var(--text-secondary); }

.custom-marker {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.6);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 11px;
  color: #fff;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: transform .2s ease;
}

.custom-marker:hover { transform: scale(1.2); }

/* Tile layer dark mode */
[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(.8) contrast(1.1) saturate(.8);
}
