/* DW5071v2 - Bento Dashboard */

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

:root {
  --bg: #f0f2f5;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --card-bg: #ffffff;
  --card-border: #e5e7eb;
  --card-radius: 1rem;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.06);
  --accent: #3b82f6;

  /* Weather palette */
  --wx-cold: #3b82f6;
  --wx-cool: #06b6d4;
  --wx-mild: #22c55e;
  --wx-warm: #f59e0b;
  --wx-hot: #ef4444;
  --wx-rain: #6366f1;
  --wx-wind: #22c55e;
  --wx-aq-good: #22c55e;
  --wx-aq-moderate: #f59e0b;
  --wx-aq-unhealthy: #ef4444;

  color-scheme: light dark;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --card-bg: #1a1d2e;
  --card-border: #2d3148;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* --- Top Bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.topbar-time {
  color: var(--text-muted);
  font-size: 0.875rem;
}

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

.theme-toggle {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  padding: 0.375rem 0.625rem;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
}

/* --- Dashboard Grid --- */
.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-areas:
    "hero     wind     rain     aq"
    "tchart   tchart   baro     fcbars"
    "wchart   wchart   wrose    cond"
    "sun      sun      hist     hist"
    "hmap     hmap     hmap     hmap";
  gap: 0.75rem;
  padding: 0.75rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* Tablet: 2 columns */
@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "hero     hero"
      "wind     rain"
      "forecast forecast"
      "fcbars   fcbars"
      "tchart   tchart"
      "baro     cond"
      "aq       aq"
      "wchart   wchart"
      "wrose    sun"
      "hist     hist"
      "hmap     hmap";
  }
}

/* Mobile: single column with select 2-up */
@media (max-width: 640px) {
  .dashboard {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "hero     hero"
      "wind     rain"
      "forecast forecast"
      "fcbars   fcbars"
      "tchart   tchart"
      "cond     baro"
      "aq       aq"
      "wchart   wchart"
      "wrose    sun"
      "hist     hist"
      "hmap     hmap";
    gap: 0.5rem;
    padding: 0.5rem;
  }
}

/* --- Cards --- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  padding: 1rem;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  container-type: inline-size;
}

.card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Grid area assignments */
.card-hero     { grid-area: hero; }
.card-wind     { grid-area: wind; }
.card-rain     { grid-area: rain; }
.card-aq       { grid-area: aq; }
.card-tchart   { grid-area: tchart; }
.card-baro     { grid-area: baro; }
.card-cond     { grid-area: cond; }
.card-wchart   { grid-area: wchart; }
.card-wrose    { grid-area: wrose; }
.card-sun      { grid-area: sun; }
.card-hist     { grid-area: hist; }
.card-hmap     { grid-area: hmap; }
.card-forecast { grid-area: forecast; }
.card-fcbars   { grid-area: fcbars; }

/* --- Forecast Strip --- */
.forecast-strip {
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.forecast-day {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  padding: 0.375rem 0.25rem;
  border-right: 1px solid var(--card-border);
}

.forecast-day:last-child { border-right: none; }
.forecast-day-name { font-size: 0.6875rem; font-weight: 600; color: var(--text-muted); }
.forecast-icon { font-size: 1.375rem; margin: 0.125rem 0; line-height: 1; }
.forecast-temps { display: flex; justify-content: center; gap: 0.375rem; font-size: 0.8125rem; font-weight: 600; }
.forecast-hi { color: var(--wx-hot); }
.forecast-lo { color: var(--wx-cold); }
.forecast-desc { font-size: 0.625rem; color: var(--text-muted); margin-top: 0.125rem; line-height: 1.2; }

/* --- Forecast Bars (iOS-style) --- */
.fc-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.8125rem;
}
.fc-bar-row:last-child { border-bottom: none; }
.fc-bar-day { width: 3rem; font-weight: 600; }
.fc-bar-icon { width: 1.5rem; text-align: center; font-size: 1.125rem; line-height: 1; }
.fc-bar-lo, .fc-bar-hi { width: 2.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fc-bar-lo { text-align: right; color: var(--text-muted); }
.fc-bar-hi { text-align: left; }
.fc-bar-track {
  flex: 1;
  height: 6px;
  background: var(--card-border);
  border-radius: 3px;
  position: relative;
}
.fc-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 3px;
}

/* --- Hero Temperature --- */
.hero-temp {
  font-size: clamp(3rem, 8vw, 5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.hero-feels {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.hero-feels-val {
  font-weight: 600;
  color: var(--text);
}

.hero-highlow {
  display: flex;
  gap: 1rem;
  margin-top: 0.375rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.hero-highlow .hi { color: var(--wx-hot); }
.hero-highlow .lo { color: var(--wx-cold); }

.hero-trend {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.hero-sparkline {
  margin-top: 0.5rem;
  height: 32px;
  width: 100%;
}

/* --- Wind Card --- */
.wind-layout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.wind-data { flex: 1; min-width: 0; }
.wind-compass {
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

/* --- Data Pairs (key: value) --- */
.data-pair {
  display: flex;
  justify-content: space-between;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 0.875rem;
}

.data-pair:last-child { border-bottom: none; }

.rain-last-line { display: flex; gap: 0.5rem; align-items: baseline; justify-content: flex-end; flex-wrap: wrap; }
.rain-days-ago { color: var(--text-muted); font-weight: 500; font-size: 0.8125rem; white-space: nowrap; }
.rain-group-start { border-bottom: none; padding-bottom: 0.125rem; }
.rain-group-end { padding-top: 0.125rem; padding-left: 0.75rem; font-size: 0.8125rem; }

.data-key {
  color: var(--text-muted);
  font-weight: 500;
}

.data-val {
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- AQ Bars --- */
.aq-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.aq-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.aq-label { width: 3rem; color: var(--text-muted); font-weight: 500; }
.aq-val { width: 4rem; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.aq-track {
  flex: 1;
  height: 6px;
  background: var(--card-border);
  border-radius: 3px;
  overflow: hidden;
}

.aq-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* --- uPlot Legend --- */
.u-legend {
  text-align: center;
  font-size: 0.8125rem;
}
.u-legend tbody {
  display: inline-flex;
  flex-direction: column;
}
.u-legend .u-series {
  display: flex !important;
  align-items: center;
  gap: 0.25rem;
}
.u-legend th {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}
.u-legend .u-value {
  font-variant-numeric: tabular-nums;
  width: 5.5rem;
  text-align: right;
}

/* uPlot drag-to-zoom selection highlight (override uPlot default) */
.u-select { background: var(--accent) !important; opacity: 0.2; }

/* --- Chart Containers --- */
.chart-wrap {
  width: 100%;
  min-height: 200px;
  position: relative;
}

.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 200px;
  color: var(--text-muted);
  font-size: 0.8125rem;
  border: 1px dashed var(--card-border);
  border-radius: 0.5rem;
}

/* --- Time Scale Selector --- */
.time-scale {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.time-scale button {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.time-scale button.active,
.time-scale button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Sun/Moon Card --- */
.sun-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
}

.sun-times > div { min-width: 0; }
.sun-arc-wrap { width: 100%; margin-bottom: 0.25rem; }
.sun-arc-wrap svg { width: 100%; height: auto; display: block; }

@container (max-width: 380px) {
  .sun-times {
    grid-template-columns: 1fr;
  }
  .sun-times > div {
    grid-column: 1 !important;
  }
}

/* --- History Grid --- */
.hist-grid {
  display: grid;
  grid-template-columns: auto repeat(4, 1fr);
  gap: 0 0.75rem;
  font-size: 0.8125rem;
}
.hist-hdr {
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  padding-bottom: 0.375rem;
  text-align: right;
}
.hist-hdr:first-child { text-align: left; }
.hist-label {
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.3rem 0;
  border-top: 1px solid var(--card-border);
  white-space: nowrap;
}
.hist-val {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0.3rem 0;
  border-top: 1px solid var(--card-border);
  white-space: nowrap;
}

/* --- Heatmap --- */
.hmap-nav {
  background: none;
  border: 1px solid var(--card-border);
  border-radius: 0.375rem;
  padding: 0.125rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.625rem;
  line-height: 1;
}
.hmap-nav:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.heatmap-wrap {
  width: 100%;
  overflow-x: auto;
  min-height: 120px;
}

/* --- Moisture Gauge --- */
.moisture-gauge { margin-bottom: 0.5rem; }

.moisture-level {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}

.moisture-dp {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
}

.moisture-label {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  line-height: 1.4;
}

.moisture-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.moisture-seg { flex: 1; }

.moisture-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 12px;
  background: var(--text);
  border-radius: 1px;
  transition: left 0.5s ease;
}

/* --- Utilities --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
