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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0f766e;
  --accent-dim: #0d9488;
  --rain: #0284c7;
  --warn: #d97706;
  --radius: 4px;
  --nav-h: 52px;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.07), 0 1px 2px -1px rgb(0 0 0 / 0.06);
  --chart-grid: #e2e8f0;
  --chart-tick: #94a3b8;
  --chart-tooltip-bg: #0f172a;
  --chart-tooltip-text: #f1f5f9;
  --chart-temp: #dc2626;
  --chart-dewpoint: #16a34a;
  --chart-wind: #1e40af;
  --chart-humidity: #0f766e;
  --chart-uv: #6d28d9;
  --chart-pressure: #334155;
  --chart-solar: #eab308;
  --font-sans: 'Overpass', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Overpass Mono', monospace;
  --value-weight: 600;
  --value-letter-spacing: -0.02em;
}

[data-theme="dark"] {
  --bg: #18181b;
  --surface: #27272a;
  --border: #3f3f46;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #fbbf24;
  --accent-dim: #f59e0b;
  --rain: #38bdf8;
  --warn: #f59e0b;
  --shadow: none;
  --chart-grid: #3f3f46;
  --chart-tick: #a1a1aa;
  --chart-tooltip-bg: #18181b;
  --chart-tooltip-text: #f4f4f5;
  --chart-temp: #ef4444;
  --chart-dewpoint: #22c55e;
  --chart-wind: #7dd3fc;
  --chart-humidity: #14b8a6;
  --chart-uv: #a855f7;
  --chart-pressure: #94a3b8;
  --chart-solar: #fde68a;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.4;
}

/* ── Nav ────────────────────────────────────────────────── */
nav {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}

nav .site-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  flex: 1;
}

nav .nav-buttons {
  display: flex;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px;
}

nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

nav a:hover { color: var(--text); background: var(--border); }
nav a.active { color: var(--bg); background: var(--accent); font-weight: 600; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 4px 8px;
  line-height: 1;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); background: var(--border); }

/* ── Main layout ────────────────────────────────────────── */
main {
  padding: 16px;
  max-width: 960px;
  margin: 0 auto;
}

h2 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 40px 0 10px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}


/* ── Dashboard two-panel layout ─────────────────────────── */
.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

@media (min-width: 680px) {
  .dashboard-layout {
    grid-template-columns: 175px 1fr;
  }
}

@media (min-width: 960px) {
  .dashboard-layout {
    grid-template-columns: 200px 1fr;
  }
}

/* ── Metric grid (3-col max) ────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (max-width: 479px) {
  .metric-col { display: contents; }
}

@media (min-width: 480px) {
  .metric-grid {
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }
  .metric-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
  }
}

/* ── Section badge inside temp cards ────────────────────── */
.section-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 2px;
}

/* ── Conditions card ────────────────────────────────────── */
.conditions-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
  row-gap: 12px;
  align-items: start;
  align-self: start;
}

/* Explicit grid placement on mobile */
.cond-label       { grid-column: 1 / -1; grid-row: 1; }
.cond-today       { grid-column: 1;      grid-row: 1; }
.cond-icon-group  { grid-column: 2;      grid-row: 1; }
.cond-divider     { grid-column: 1 / -1; grid-row: 2; }
.cond-weather-col  { grid-column: 1;      grid-row: 3; }
.cond-uv-aqi-col   { grid-column: 2;      grid-row: 3; display: flex; flex-direction: row; gap: 12px; align-items: flex-start; }

/* ── Revert to column stack in sidebar (≥680px) ─── */
@media (min-width: 680px) {
  .conditions-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .cond-icon-group { align-items: center; }
  .cond-icon       { text-align: center; }
  .cond-desc       { text-align: center; }
  .cond-uv-aqi-col { order: 10; flex-direction: column; gap: 6px; }
}

.cond-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 680px) {
  .cond-label { display: block; }
}

.cond-icon-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cond-weather-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cond-icon {
  font-size: 4rem;
  line-height: 1;
}

.cond-desc {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.cond-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

.cond-wind-row,
.cond-aqi-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cond-today {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cond-hilo {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
}

.cond-pop {
  font-size: 0.82rem;
  color: var(--text-muted);
}


.cond-wind-info {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  font-family: var(--font-mono);
}

.cond-uv-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 0;
}

.cond-aqi-row {
  flex: 1.4 1 0;
}

.cond-uv-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cond-row-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.uv-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.cond-uv-text {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.wind-compass {
  display: block;
  margin: 10px auto 2px;
}

.compass-label {
  font-size: 11px;
  font-weight: 700;
  fill: var(--text);
  font-family: var(--font-sans);
}

.compass-heading {
  font-size: 13px;
  font-weight: 700;
  fill: var(--text-muted);
  font-family: var(--font-mono);
}

.uv-level-value {
  display: flex;
  align-items: center;
  gap: 6px;
}

.astro-moon {
  display: flex;
  align-items: baseline;
  gap: 0.3em;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 4px;
}

.astro-divider {
  border: none;
  border-top: 1px solid var(--border);
  opacity: 0.4;
  width: 60%;
  margin: 2px auto 2px 0;
}

.astro-time-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 8px;
  row-gap: 3px;
}

.astro-time-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}

.tile .label {
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.tile .value {
  font-size: 1.8rem;
  font-weight: var(--value-weight);
  color: var(--text);
  line-height: 1.1;
  font-family: var(--font-mono);
  letter-spacing: var(--value-letter-spacing);
}

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

.temp-trend {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.1;
}


.tile .secondaries {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.tile .secondary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.tile .secondary-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

.tile .secondary-value {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  font-family: var(--font-mono);
  white-space: nowrap;
}

#pressureTrend {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
}

/* ── Forecast cards ─────────────────────────────────────── */
.forecast-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

@media (max-width: 479px) { .forecast-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .forecast-grid { grid-template-columns: repeat(7, 1fr); } }

.forecast-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.forecast-card .day {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.forecast-card .icon { font-size: 2rem; line-height: 1; }

.forecast-card .hi-lo {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.forecast-card .hi-lo span { color: var(--text-muted); font-weight: 400; }

.forecast-card .precip {
  font-size: 0.9rem;
  color: var(--rain);
}

.forecast-card .wind {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ── Status bar ─────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.live { background: #22c55e; }

.status-dot.error { background: #ef4444; }

/* ── Offline banner ─────────────────────────────────────── */
.offline-banner {
  display: none;
  background: var(--warn);
  color: #0f172a;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px;
}

.offline-banner.visible { display: block; }

/* ── Loading / skeleton ─────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
  color: transparent !important;
  user-select: none;
}

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

/* ── History charts ─────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.chart-card canvas { width: 100% !important; height: 200px !important; }


/* ── Forecast card click affordance ─────────────────────── */
.forecast-card {
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.forecast-card:hover {
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.1);
  transform: translateY(-1px);
}

/* ── Bottom sheet ───────────────────────────────────────── */
.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
.sheet-backdrop.open { display: block; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 680px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  z-index: 101;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 80vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-overflow-scrolling: touch;
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
  cursor: pointer;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sheet-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.sheet-close:hover { color: var(--text); }

.sheet-icon { font-size: 3rem; line-height: 1; }

.sheet-day {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.sheet-cond {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sheet-blurb {
  padding: 14px 20px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.sheet-hourly {
  display: flex;
  overflow-x: auto;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 4px;
}
.sheet-hourly::-webkit-scrollbar { display: none; }

.hourly-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 52px;
  flex-shrink: 0;
}

.hourly-time {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  position: relative;
}

.hourly-col.now .hourly-time {
  color: var(--text);
  font-weight: 700;
}

.hourly-col.now .hourly-time::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #0ea5e9;
}

.hourly-icon { font-size: 1.4rem; line-height: 1; }

.hourly-temp {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
}

.hourly-pop {
  font-size: 0.85rem;
  color: var(--rain);
  font-weight: 500;
  min-height: 1em;
}

.sheet-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1rem auto auto;
  column-gap: 16px;
  row-gap: 4px;
  padding: 20px;
}

/* Flatten each stat so its label and value join the grid directly */
.sheet-stat { display: contents; }

.sheet-stat:nth-child(1) .sheet-stat-label { grid-column: 1; grid-row: 1; }
.sheet-stat:nth-child(2) .sheet-stat-label { grid-column: 2; grid-row: 1; }
.sheet-stat:nth-child(1) .sheet-stat-value { grid-column: 1; grid-row: 2; }
.sheet-stat:nth-child(2) .sheet-stat-value { grid-column: 2; grid-row: 2; }
.sheet-stat:nth-child(3) .sheet-stat-label { grid-column: 1; grid-row: 4; }
.sheet-stat:nth-child(4) .sheet-stat-label { grid-column: 2; grid-row: 4; }
.sheet-stat:nth-child(3) .sheet-stat-value { grid-column: 1; grid-row: 5; }
.sheet-stat:nth-child(4) .sheet-stat-value { grid-column: 2; grid-row: 5; }

.sheet-stat-label {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.sheet-stat-value {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
}

.sheet-aqi {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: -8px;
}

.sheet-aqi-label {
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.sheet-aqi-value {
  font-size: 1.15rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* ── Sheet: modal mode on wide screens ──────────────────── */
@media (min-width: 768px) {
  .sheet-handle { display: none; }
  .sheet-close  { display: block; }

  .bottom-sheet {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    width: min(580px, 90vw);
    max-width: none;
    margin: 0;
    max-height: 85vh;
    border-radius: 12px;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .bottom-sheet.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
  }
}

/* ── Range picker ───────────────────────────────────────── */
.range-picker {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.range-picker button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.range-picker button:hover { color: var(--text); border-color: var(--accent-dim); }
.range-picker button.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.range-picker button.prefetching { opacity: 0.5; cursor: wait; }
.range-picker button.prefetching::after { content: ' …'; }

.range-refresh {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.range-refresh:hover { color: var(--text); border-color: var(--accent-dim); }
.range-refresh:disabled { opacity: 0.4; cursor: wait; }
.range-refresh.spinning svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tooltips ───────────────────────────────────────────── */
.tooltip-target {
  position: relative;
  cursor: help;
  border-bottom: 1px dotted var(--text-muted);
}

.tooltip-target::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--chart-tooltip-bg);
  color: var(--chart-tooltip-text);
  font-size: 0.78rem;
  font-family: var(--font-sans);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
}

.tooltip-target:hover::after,
.tooltip-target.tooltip-visible::after {
  opacity: 1;
}
