:root {
  --bg: #0a0e17;
  --bg-elevated: rgba(15, 23, 42, 0.75);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-w: 320px;
  --header-h: 64px;
  --footer-h: 32px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body.light-mode {
  --bg: #f1f5f9;
  --bg-elevated: rgba(255, 255, 255, 0.85);
  --glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.08);
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body.high-contrast {
  --text: #fff;
  --bg: #000;
  --accent: #0ff;
}

body.reduce-motion * {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Glass utility */
.glass {
  background: var(--bg-elevated);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

/* Header */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 1000;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon { font-size: 1.6rem; }
.logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.tagline {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 900px) {
  .tagline { display: inline; margin-left: 0.5rem; }
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 180px;
  padding: 0.5rem 2.2rem 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: width var(--transition), border-color var(--transition);
}
#search-input:focus {
  width: 260px;
  border-color: var(--accent);
}

#search-btn {
  position: absolute;
  right: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
}

.search-results {
  position: absolute;
  top: 110%;
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  border-radius: var(--radius);
  list-style: none;
  z-index: 1100;
}
.search-results li {
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--glass-border);
  font-size: 0.85rem;
}
.search-results li:hover,
.search-results li:focus {
  background: rgba(56, 189, 248, 0.15);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--transition), transform var(--transition);
}
.icon-btn:hover {
  background: rgba(56, 189, 248, 0.2);
  transform: scale(1.05);
}
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Main layout */
.main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  z-index: 500;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.sidebar-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0.5rem;
  border-bottom: 1px solid var(--glass-border);
}
.tab {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 0.4rem 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}
.tab.active, .tab:hover {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
}

.tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.3s ease; }

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

.layer-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.2rem;
}
.layer-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0;
}
.layer-group input[type="checkbox"],
.layer-group input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  margin-top: 0.5rem;
}

/* Weather card */
.weather-card, .aqi-card, .sun-moon-card {
  background: var(--glass);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--glass-border);
}
.weather-card .temp {
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1;
}
.weather-card .desc {
  text-transform: capitalize;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.weather-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.8rem;
}
.weather-details span {
  color: var(--text-muted);
}
.placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5rem 0.5rem;
}

/* Forecast */
.forecast-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}
.f-tab {
  flex: 1;
  padding: 0.4rem;
  font-size: 0.75rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
}
.f-tab.active {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  border-color: var(--accent);
}
.forecast-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
}
.forecast-item {
  min-width: 70px;
  text-align: center;
  padding: 0.5rem;
  background: var(--glass);
  border-radius: 8px;
  font-size: 0.75rem;
  border: 1px solid var(--glass-border);
}
.forecast-item .f-temp {
  font-weight: 600;
  font-size: 0.95rem;
}
.forecast-item img, .forecast-item .icon {
  font-size: 1.4rem;
  margin: 0.25rem 0;
}

/* Event list */
.event-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.event-item {
  padding: 0.6rem 0.75rem;
  background: var(--glass);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition);
}
.event-item:hover { background: rgba(56, 189, 248, 0.1); }
.event-item.mag-high { border-left-color: var(--danger); }
.event-item.mag-med { border-left-color: var(--warning); }
.event-item .event-title { font-weight: 600; }
.event-item .event-meta { color: var(--text-muted); font-size: 0.7rem; }

/* Map container */
#map-container {
  min-height: 0;
  flex: 1;
  position: relative;
  min-width: 0;
}
#map {
  width: 100%;
  height: 100%;
  background: #0a0e17;
}

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 400;
  padding: 6px;
  border-radius: var(--radius);
}

.legend {
  position: absolute;
  bottom: 40px;
  left: 12px;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  z-index: 400;
  max-width: 200px;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 23, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 600;
  transition: opacity 0.4s;
}
.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Info panel */
.info-panel {
  width: 300px;
  flex-shrink: 0;
  padding: 1rem;
  overflow-y: auto;
  position: relative;
  transition: transform var(--transition);
  z-index: 500;
}
.info-panel.collapsed {
  transform: translateX(100%);
  width: 0;
  padding: 0;
  border: none;
}
.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
}

/* Alerts bar */
.alerts-bar {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(248, 113, 113, 0.15);
  border-top: 1px solid rgba(248, 113, 113, 0.3);
  flex-shrink: 0;
}
.alerts-bar .alert-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Status bar */
.status-bar {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 2000;
}
.modal[hidden] { display: none; }
.modal-content {
  width: min(360px, 92vw);
  padding: 1.5rem;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal-content label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
}
.modal-content select,
.modal-content input[type="range"] {
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
}
.primary-btn {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: #0a0e17;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
}

/* Leaflet overrides */
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(0,0,0,0.5) !important;
  color: #aaa !important;
}
.leaflet-popup-content-wrapper {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border-radius: 10px !important;
  backdrop-filter: blur(12px);
}
.leaflet-popup-tip {
  background: var(--bg-elevated) !important;
}
.leaflet-popup-content {
  margin: 10px 12px !important;
  font-size: 0.85rem;
}

/* Custom markers */
.eq-marker {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.8);
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.6);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6); }
  70% { box-shadow: 0 0 0 16px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

.fire-marker {
  animation: flicker 1.5s ease-in-out infinite alternate;
}
@keyframes flicker {
  from { filter: brightness(1); }
  to { filter: brightness(1.4); }
}

.mobile-only { display: none; }

/* Responsive */
@media (max-width: 900px) {
  .mobile-only { display: grid; }
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 700;
  }
  .sidebar.open { transform: translateX(0); }
  .info-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    z-index: 700;
  }
  .info-panel.open { transform: translateX(0); }
  #search-input { width: 140px; }
  #search-input:focus { width: 180px; }
}

@media (max-width: 600px) {
  .logo h1 { font-size: 1rem; }
  .tagline { display: none; }
  .sidebar { width: 100%; }
}

/* AQI colors */
.aqi-good { color: #34d399; }
.aqi-moderate { color: #fbbf24; }
.aqi-unhealthy { color: #f87171; }
.aqi-hazardous { color: #c084fc; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 3px; }
