/* ============================================================
   SkyLens — Main Stylesheet
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --surface: rgba(255,255,255,0.06);
  --surface-hover: rgba(255,255,255,0.10);
  --border: rgba(255,255,255,0.10);
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent2: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --font: 'Inter', system-ui, sans-serif;
  --font-head: 'Space Grotesk', system-ui, sans-serif;
  --nav-h: 60px;
  --mobile-tab-h: 60px;
  --transition: 0.25s ease;
}

[data-theme="light"] {
  --bg: #f0f4f8;
  --bg2: #e2e8f0;
  --surface: rgba(255,255,255,0.75);
  --surface-hover: rgba(255,255,255,0.90);
  --border: rgba(0,0,0,0.08);
  --text: #1a202c;
  --text-muted: #4a5568;
  --shadow: 0 8px 32px rgba(0,0,0,0.12);
}

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

html { scroll-behavior: smooth; }

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

/* ---------- Sky Canvas ---------- */
.sky-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.sky-layer { position: absolute; inset: 0; }

/* Gradient sky backgrounds per condition */
body[data-condition="sunny"] .sky-canvas {
  background: linear-gradient(180deg, #1a6fa8 0%, #4db8e8 60%, #f7c948 100%);
}
body[data-condition="cloudy"] .sky-canvas {
  background: linear-gradient(180deg, #2c3e50 0%, #4a5568 60%, #718096 100%);
}
body[data-condition="rainy"] .sky-canvas {
  background: linear-gradient(180deg, #1a202c 0%, #2d3748 60%, #4a5568 100%);
}
body[data-condition="night"] .sky-canvas {
  background: linear-gradient(180deg, #0a0e1a 0%, #1a2035 60%, #2d3561 100%);
}
body[data-condition="default"] .sky-canvas {
  background: linear-gradient(180deg, #0d1117 0%, #161b22 100%);
}

/* Animated clouds */
.cloud-puff {
  position: absolute;
  border-radius: 50px;
  background: rgba(255,255,255,0.15);
  animation: driftCloud linear infinite;
}

@keyframes driftCloud {
  from { transform: translateX(-200px); }
  to   { transform: translateX(calc(100vw + 200px)); }
}

/* Rain drops */
.rain-drop {
  position: absolute;
  width: 1px;
  background: linear-gradient(transparent, rgba(174,214,241,0.6));
  animation: fallRain linear infinite;
}

@keyframes fallRain {
  from { transform: translateY(-100px); opacity: 0; }
  10%  { opacity: 1; }
  to   { transform: translateY(110vh); opacity: 0; }
}

/* Sun glow */
.sun-glow {
  background: radial-gradient(circle at 70% 20%, rgba(255,200,50,0.15) 0%, transparent 60%);
  transition: opacity 1s ease;
}

/* Stars */
.star {
  position: absolute;
  border-radius: 50%;
  background: white;
  animation: twinkle ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(1); }
  50%       { opacity: 1;   transform: scale(1.3); }
}

/* ---------- Glass Morphism ---------- */
.glass {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ---------- Navigation ---------- */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-icon { font-size: 1.4rem; }
.brand-sg { color: var(--accent); }

.nav-center { flex: 1; display: flex; justify-content: center; }

.search-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.search-wrap input {
  width: 100%;
  padding: 8px 40px 8px 14px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88,166,255,0.15);
}

.search-btn {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
  display: none;
}

.search-dropdown.open { display: block; }

.search-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
}

.search-item:hover { background: var(--surface-hover); }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background var(--transition), border-color var(--transition);
}

.icon-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

/* ---------- App Layout — 3 columns ---------- */
.app-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 340px 1fr 300px;
  gap: 14px;
  padding: calc(var(--nav-h) + 14px) 16px 28px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 7-day vertical list */
.daily-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-row {
  display: grid;
  grid-template-columns: 72px 28px 1fr auto 80px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  cursor: pointer;
}

.day-row:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}

.day-name  { font-size: 0.82rem; font-weight: 500; }
.day-icon  { font-size: 1.2rem; text-align: center; }
.day-desc  { font-size: 0.75rem; color: var(--text-muted); }
.day-rain-chance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 50px;
}
.day-temps {
  display: flex;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  justify-content: flex-end;
}
.day-temp-lo { color: var(--text-muted); font-weight: 400; }

/* NEA compact list in right column */
.nea-compact {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 260px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nea-compact .nea-region-item {
  padding: 5px 8px;
  font-size: 0.78rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .app-layout { grid-template-columns: 300px 1fr 280px; }
}

@media (max-width: 960px) {
  .app-layout { grid-template-columns: 1fr 1fr; }
  .col-center { grid-column: 1 / -1; order: -1; }
}

@media (max-width: 640px) {
  .app-layout { grid-template-columns: 1fr; }
  .col-center { grid-column: auto; order: 0; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
}


/* ---------- Cards ---------- */
.card {
  border-radius: var(--radius);
  padding: 20px;
  transition: transform var(--transition), box-shadow var(--transition);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-header h2 {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(88,166,255,0.15);
  color: var(--accent);
  border: 1px solid rgba(88,166,255,0.3);
  font-weight: 500;
}

/* ---------- Hero Card ---------- */
.hero-card { padding: 28px; }

.hero-location {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.hero-time {
  margin-left: auto;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.hero-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.hero-temp-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hero-icon { font-size: 3.5rem; line-height: 1; }

.hero-temp {
  font-family: var(--font-head);
  font-size: 5rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -3px;
}

.hero-unit {
  font-size: 2rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-top: 8px;
}

.hero-desc {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
  text-transform: capitalize;
}

.hero-feels {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-icon { font-size: 1.1rem; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-val { font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Hourly Forecast ---------- */
.hourly-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  margin-bottom: 12px;
}

.hourly-scroll::-webkit-scrollbar { height: 4px; }
.hourly-scroll::-webkit-scrollbar-track { background: transparent; }
.hourly-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.hour-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  min-width: 64px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.hour-item:hover, .hour-item.active {
  background: rgba(88,166,255,0.12);
  border-color: var(--accent);
}

.hour-time { font-size: 0.72rem; color: var(--text-muted); }
.hour-icon { font-size: 1.4rem; }
.hour-temp { font-size: 0.9rem; font-weight: 600; }
.hour-rain { font-size: 0.7rem; color: #58a6ff; }

.hourly-chart-wrap { height: 80px; }

/* ---------- Daily Forecast ---------- */
.daily-list { display: flex; flex-direction: column; gap: 6px; }

.day-row {
  display: grid;
  grid-template-columns: 80px 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  cursor: pointer;
}

.day-row:hover {
  background: rgba(255,255,255,0.04);
  border-color: var(--border);
}

.day-name { font-size: 0.85rem; font-weight: 500; }
.day-icon { font-size: 1.3rem; text-align: center; }
.day-desc { font-size: 0.78rem; color: var(--text-muted); }
.day-rain-chance { font-size: 0.78rem; color: #58a6ff; min-width: 36px; text-align: right; }
.day-temps { display: flex; gap: 6px; font-size: 0.85rem; font-weight: 600; min-width: 70px; justify-content: flex-end; }
.day-temp-lo { color: var(--text-muted); font-weight: 400; }

/* ---------- Station Map ---------- */
.map-card { padding: 20px; }

.station-map {
  height: 340px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.map-layer-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.layer-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--transition);
}

.layer-btn.active, .layer-btn:hover {
  background: rgba(88,166,255,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.map-legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* Leaflet overrides */
.leaflet-container { background: #1a2035 !important; }
.leaflet-tile { filter: brightness(0.7) saturate(0.8); }
[data-theme="light"] .leaflet-tile { filter: none; }

.station-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid white;
  font-size: 0.65rem;
  font-weight: 700;
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

/* ---------- Activity Suitability ---------- */
.activity-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.activity-item {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255,255,255,0.03);
}

.activity-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
}

.activity-icon { font-size: 1.2rem; }

.activity-score-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.activity-score-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s ease;
}

.score-great  { background: linear-gradient(90deg, #3fb950, #56d364); }
.score-good   { background: linear-gradient(90deg, #d29922, #e3b341); }
.score-poor   { background: linear-gradient(90deg, #f85149, #ff7b72); }

.activity-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.label-great { color: #3fb950; }
.label-good  { color: #d29922; }
.label-poor  { color: #f85149; }

/* ---------- Sun & Moon ---------- */
.sun-moon-card {}

.sun-arc-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.sun-moon-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}

.sm-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
}

.sm-stat span:first-child { font-size: 1.2rem; }
.sm-stat span:last-child { font-weight: 600; }

/* ---------- Consensus Card ---------- */
.consensus-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}

.source-logo {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(88,166,255,0.15);
  color: var(--accent);
  min-width: 60px;
  text-align: center;
  flex-shrink: 0;
}

.source-temp {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 50px;
}

.source-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
}

.source-icon { font-size: 1.3rem; }

.confidence-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conf-label { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

.confidence-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 1s ease;
}

.conf-pct { font-size: 0.8rem; font-weight: 600; color: var(--accent); min-width: 32px; }

/* ---------- NEA Regions ---------- */
.nea-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(63,185,80,0.15);
  color: var(--accent2);
  border: 1px solid rgba(63,185,80,0.3);
  font-weight: 600;
}

.nea-regions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.nea-region-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  font-size: 0.82rem;
}

.nea-region-icon { font-size: 1.1rem; }
.nea-region-name { font-weight: 500; }
.nea-region-desc { font-size: 0.72rem; color: var(--text-muted); }

/* ---------- Air Quality ---------- */
.aq-body { display: flex; flex-direction: column; gap: 10px; }

.aqi-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.aqi-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid;
  flex-shrink: 0;
}

.aqi-number { font-size: 1.4rem; font-weight: 700; line-height: 1; }
.aqi-label-sm { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.05em; }

.aqi-info { flex: 1; }
.aqi-category { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.aqi-advice { font-size: 0.78rem; color: var(--text-muted); }

.aqi-good     { border-color: #3fb950; color: #3fb950; }
.aqi-moderate { border-color: #d29922; color: #d29922; }
.aqi-unhealthy{ border-color: #f85149; color: #f85149; }

.pollutant-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.pollutant-item {
  text-align: center;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.pollutant-name { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }
.pollutant-val  { font-size: 0.85rem; font-weight: 600; }

/* ---------- Alerts ---------- */
.alerts-card { border-color: rgba(248,81,73,0.3); }

.alert-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
  background: rgba(248,81,73,0.08);
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.alert-title { font-weight: 600; margin-bottom: 4px; }
.alert-desc  { color: var(--text-muted); font-size: 0.78rem; }

/* ---------- Historical Comparison ---------- */
.history-body { display: flex; flex-direction: column; gap: 10px; }

.hist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.hist-label { width: 80px; color: var(--text-muted); font-size: 0.78rem; }

.hist-bar-wrap {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  position: relative;
  overflow: visible;
}

.hist-bar-avg {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 12px;
  background: var(--text-muted);
  border-radius: 1px;
}

.hist-bar-now {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.8s ease;
}

.hist-val { font-weight: 600; min-width: 50px; text-align: right; font-size: 0.82rem; }
.hist-diff { font-size: 0.72rem; min-width: 40px; text-align: right; }
.hist-diff.above { color: var(--danger); }
.hist-diff.below { color: var(--accent); }

/* ---------- Loading Shimmer ---------- */
.loading-shimmer {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    rgba(255,255,255,0.04) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  max-width: 320px;
  animation: slideInToast 0.3s ease;
}

.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--accent2); }

@keyframes slideInToast {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  border-radius: var(--radius);
  padding: 32px;
  max-width: 480px;
  width: 90%;
}

.modal h2 {
  font-family: var(--font-head);
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.modal p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.api-key-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.api-key-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.api-key-form input {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  outline: none;
}

.api-key-form input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 10px; }

.btn-primary {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #0d1117;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  font-size: 0.88rem;
  transition: opacity var(--transition);
}

.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  cursor: pointer;
  font-size: 0.88rem;
  transition: background var(--transition);
}

.btn-ghost:hover { background: var(--surface-hover); }

/* ---------- Tooltip ---------- */
.tooltip-trigger { cursor: help; position: relative; }

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

/* ---------- Responsive tweaks ---------- */
@media (max-width: 480px) {
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .sun-moon-stats { grid-template-columns: repeat(2, 1fr); }
  .pollutant-grid { grid-template-columns: repeat(2, 1fr); }
  .nea-regions { grid-template-columns: 1fr; }
  .activity-grid { grid-template-columns: 1fr; }
  .topnav { padding: 0 12px; gap: 8px; }
  .nav-brand .brand-name { display: none; }
}

/* ---------- Live pulse dot ---------- */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

/* ---------- Rain Forecast Card ---------- */
.rain-next-banner {
  margin-bottom: 14px;
}

.rain-banner-clear,
.rain-banner-rain,
.rain-banner-soon {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.rain-banner-clear { background: rgba(63,185,80,0.08);  border-color: rgba(63,185,80,0.25); }
.rain-banner-rain  { background: rgba(88,166,255,0.10); border-color: rgba(88,166,255,0.3); }
.rain-banner-soon  { background: rgba(210,153,34,0.08); border-color: rgba(210,153,34,0.25); }

.rain-banner-icon  { font-size: 1.8rem; flex-shrink: 0; }
.rain-banner-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 3px; }
.rain-banner-sub   { font-size: 0.78rem; color: var(--text-muted); }

.rain-accumulation-wrap {
  height: 110px;
  margin-bottom: 14px;
}

/* Chart legend row */
.rain-chart-legend {
  display: flex;
  gap: 14px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.rain-chart-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Daily rain totals */
.rain-daily-totals {
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.rain-total-row {
  display: grid;
  grid-template-columns: 72px 24px 1fr 46px 34px;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.rain-total-day  { color: var(--text-muted); font-size: 0.75rem; }
.rain-total-icon { text-align: center; font-size: 1rem; }

.rain-total-bar-wrap {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.rain-total-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
  min-width: 2px;
}

.rain-total-mm   { font-weight: 600; text-align: right; color: #58a6ff; font-size: 0.78rem; }
.rain-total-prob { font-size: 0.72rem; color: var(--text-muted); text-align: right; }

/* Hourly scroll — mm label style */
.rain-mm-label { color: #58a6ff !important; font-weight: 600; }

/* Daily list — rain prob + mm stacked */
.day-rain-chance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.rain-prob { font-size: 0.75rem; color: #58a6ff; }
.rain-mm   { font-size: 0.72rem; color: #3fb950; font-weight: 600; }

/* ---------- Global search result items ---------- */
.search-item > div { line-height: 1.3; }

/* ---------- Modal hidden state ---------- */
.modal-overlay.hidden { display: none; }

/* ---------- Singapore quick-switch button ---------- */
.sg-btn {
  font-size: 1.1rem;
  padding: 4px 8px;
  border-color: rgba(63,185,80,0.3);
}
.sg-btn:hover {
  border-color: #3fb950;
  background: rgba(63,185,80,0.12);
}

/* ---------- NEA compact (right column) ---------- */
.nea-regions-compact {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nea-regions-compact .nea-region-item {
  padding: 6px 8px;
  font-size: 0.78rem;
}

/* ---------- PWA / Mobile optimisations ---------- */

/* Safe area insets for notched phones */
.topnav {
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

.app-layout {
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

/* Standalone mode (installed PWA) — hide browser chrome hints */
@media (display-mode: standalone) {
  .topnav {
    padding-top: max(0px, env(safe-area-inset-top));
    height: calc(var(--nav-h) + env(safe-area-inset-top));
  }
  .app-layout {
    padding-top: calc(var(--nav-h) + env(safe-area-inset-top) + 14px);
  }
}

/* Touch-friendly tap targets */
@media (pointer: coarse) {
  .icon-btn    { min-width: 40px; min-height: 40px; }
  .layer-btn   { min-height: 36px; padding: 6px 12px; }
  .hour-item   { min-width: 72px; }
  .search-wrap input { font-size: 16px; } /* prevent iOS zoom on focus */
}

/* Mobile single-column layout */
@media (max-width: 640px) {
  .app-layout {
    grid-template-columns: 1fr;
    padding: calc(var(--nav-h) + env(safe-area-inset-top) + 12px) 12px max(24px, env(safe-area-inset-bottom));
    gap: 12px;
  }
  .hero-temp  { font-size: 4rem; }
  .hero-icon  { font-size: 2.8rem; }
  .hero-stats { grid-template-columns: repeat(3, 1fr); }
  .map-card .station-map { height: 260px; }
  .nav-brand .brand-name { font-size: 1rem; }
  .nav-actions { gap: 4px; }
}

/* ============================================================
   MOBILE LAYOUT — single column + bottom tab bar
   Applies at ≤ 768px
   ============================================================ */

@media (max-width: 768px) {

  /* Hide desktop 3-col grid, use single column */
  .app-layout {
    display: block;
    padding: calc(var(--nav-h) + 10px) 12px calc(var(--mobile-tab-h) + 16px);
  }

  /* All columns stack, hidden by default — shown by tab JS */
  .col-left, .col-center, .col-right {
    display: none;
    flex-direction: column;
    gap: 12px;
  }

  /* Active tab panel is shown */
  .col-left.tab-active,
  .col-center.tab-active,
  .col-right.tab-active {
    display: flex;
  }

  /* Compact nav — hide search on mobile, keep buttons */
  .nav-center { display: none; }
  .nav-brand .brand-name { font-size: 1rem; }
  .topnav { padding: 0 12px; gap: 8px; }

  /* Hero card — more compact */
  .hero-card { padding: 18px; }
  .hero-temp { font-size: 4.5rem; letter-spacing: -2px; }
  .hero-icon { font-size: 3rem; }
  .hero-stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-pill { padding: 8px 10px; }
  .stat-label { font-size: 0.65rem; }
  .stat-val { font-size: 0.85rem; }

  /* Hourly scroll — bigger touch targets */
  .hour-item { min-width: 68px; padding: 10px 8px; }

  /* Map full width */
  .map-card .station-map { height: 280px; }

  /* Cards full width */
  .card { border-radius: 14px; }

  /* Day rows more compact */
  .day-row { grid-template-columns: 60px 24px 1fr auto 70px; gap: 8px; padding: 8px; }

  /* Activity grid 2 cols */
  .activity-grid { grid-template-columns: 1fr 1fr; }

  /* NEA regions 1 col */
  .nea-compact { max-height: none; }

  /* Sun moon stats 2x2 */
  .sun-moon-stats { grid-template-columns: repeat(2, 1fr); }

  /* AQ pollutants 3 col */
  .pollutant-grid { grid-template-columns: repeat(3, 1fr); }

  /* ── Bottom Tab Bar ── */
  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 200;
    height: var(--mobile-tab-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 500;
    padding: 6px 4px;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
  }

  .tab-btn.active { color: var(--accent); }

  .tab-btn svg, .tab-btn .tab-icon {
    font-size: 1.3rem;
    line-height: 1;
  }

  /* Mobile search bar — shown inside tab panels */
  .mobile-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
  }

  .mobile-search-bar input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 16px; /* prevent iOS zoom */
    font-family: var(--font);
    outline: none;
  }

  .mobile-search-bar input:focus { border-color: var(--accent); }

  .mobile-search-bar button {
    padding: 10px 16px;
    border-radius: 24px;
    border: none;
    background: var(--accent);
    color: #0d1117;
    font-weight: 600;
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
  }
}

/* Desktop: hide mobile tabs */
@media (min-width: 769px) {
  .mobile-tabs { display: none; }
  .mobile-search-bar { display: none; }
  /* Ensure all cols visible on desktop */
  .col-left, .col-center, .col-right { display: flex !important; }
}
