/* K2NTH Weather — dark-mode dashboard.
   Deliberately dark-only: an outdoor weather display read mostly at a glance,
   day and night, on a wall-mounted tablet or a desktop. Palette follows the
   dataviz skill's validated default (categorical slots, chart surfaces, ink). */

:root {
  color-scheme: dark;

  /* Page & chrome */
  --page-bg:        #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #212120;
  --surface-raised: #262625;
  --border:         rgba(255,255,255,0.10);
  --border-strong:  rgba(255,255,255,0.18);

  /* Ink */
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;

  /* Categorical slots (dark column, dataviz skill palette) */
  --series-1: #3987e5; /* blue */
  --series-2: #d95926; /* orange */
  --series-3: #199e70; /* aqua */
  --series-4: #c98500; /* yellow */
  --series-5: #d55181; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #9085e9; /* violet */
  --series-8: #e66767; /* red */

  --success: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius-card: 14px;
  --radius-control: 9px;
  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

body {
  min-height: 100vh;
  padding-bottom: 32px;
}

h1, h2 { margin: 0; font-weight: 600; }

/* ---------- Header ---------- */

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.brand-mark {
  font-size: 22px;
  line-height: 1;
}

.brand h1 {
  font-size: 19px;
  letter-spacing: -0.01em;
}

.clocks {
  display: flex;
  gap: 18px;
}

.clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.clock-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.clock-value {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 600;
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 0 3px rgba(12,163,12,0.18); }
.status-dot.stale { background: var(--warning); box-shadow: 0 0 0 3px rgba(250,178,25,0.18); }
.status-dot.down { background: var(--critical); box-shadow: 0 0 0 3px rgba(208,59,59,0.18); }

.dashboard-mode-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.dashboard-mode-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}
.dashboard-mode-btn[aria-pressed="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
.dashboard-mode-btn span { white-space: nowrap; }
@media (max-width: 700px) {
  .dashboard-mode-btn span { display: none; }
}

/* ---------- Nav tabs (both pages) ---------- */

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 3px;
}

.nav-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab[aria-current="page"] {
  background: var(--surface-raised);
  color: var(--text-primary);
}

.brand-conditions {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 2px;
  white-space: nowrap;
}

/* ---------- Range bar ---------- */

.rangebar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 61px;
  z-index: 19;
}

.rangebar-inner {
  max-width: 1680px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-btn {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.preset-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.preset-btn.active {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
  font-weight: 600;
}

.custom-range-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-control);
  padding: 7px 12px;
  cursor: pointer;
}
.custom-range-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.custom-range-btn.active {
  border-style: solid;
  border-color: var(--series-1);
  color: var(--text-primary);
}

.range-readout {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.custom-range-popover {
  position: absolute;
  right: 20px;
  top: 100%;
  margin-top: 6px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: flex-end;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 30;
}

.custom-range-popover[hidden] {
  display: none;
}

.custom-range-popover label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.custom-range-popover input[type="date"] {
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  padding: 7px 9px;
  color-scheme: dark;
}

.popover-actions {
  display: flex;
  gap: 8px;
}

.btn-ghost, .btn-primary {
  font-family: var(--font-sans);
  font-size: 13px;
  border-radius: var(--radius-control);
  padding: 7px 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); }
.btn-primary {
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: #2a78d6; }

/* ---------- Live conditions strip ---------- */

.live-strip {
  max-width: 1680px;
  margin: 18px auto 0;
  padding: 0 20px;
}

.live-strip-inner {
  background: linear-gradient(180deg, var(--surface-raised) 0%, var(--surface-1) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 1px 0 rgba(255,255,255,0.05) inset, 0 8px 24px rgba(0,0,0,0.25);
  padding: 18px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 26px;
}

.live-hero-slot {
  padding-right: 26px;
  border-right: 1px solid var(--border);
}

.live-hero-slot .live-label {
  font-size: 11.5px;
}

.live-hero-slot .live-value {
  font-size: 40px;
  letter-spacing: -0.01em;
}

.live-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 18px;
}

.live-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.live-label {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.live-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 23px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}

.trend-arrow {
  flex: none;
  align-self: center;
}
/* Temperature-style fields (temp, dewpoint): rising reads hotter (red),
   falling reads cooler (blue) - the opposite of a generic good/bad mapping. */
.trend-temp-up { color: var(--series-8); }
.trend-temp-down { color: var(--series-1); }
.trend-temp-flat { color: var(--text-muted); }
/* Neutral fields (humidity, pressure): direction only, no value judgment. */
.trend-neutral-up,
.trend-neutral-down,
.trend-neutral-flat { color: var(--text-secondary); }

.live-asof-slot {
  text-align: right;
}

.live-asof-slot .live-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  justify-content: flex-end;
}

.live-value.flash {
  animation: live-flash 0.6s ease-out;
}

@keyframes live-flash {
  0% { color: var(--series-1); }
  100% { color: var(--text-primary); }
}

/* ---------- Dashboard grid ---------- */

.dash {
  max-width: 1680px;
  margin: 24px auto 0;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.chart-card-full {
  grid-column: 1 / -1;
}

.dash-grid-rest {
  display: contents;
}

.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.22);
  display: flex;
  gap: 0;
  overflow: hidden;
  transition: border-color 0.15s;
}

.chart-card:hover {
  border-color: var(--border-strong);
}

.chart-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 18px 20px 14px;
  display: flex;
  flex-direction: column;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.chart-head h2 {
  font-size: 15.5px;
  color: var(--text-primary);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  flex: none;
}

.chart-canvas-wrap {
  position: relative;
  height: 240px;
  width: 100%;
}

.chart-card-full .chart-canvas-wrap {
  height: 320px;
}

.chart-canvas-wrap-mini {
  height: 64px;
  margin-bottom: 10px;
  flex: none;
}

.chart-canvas-wrap-mini + .chart-canvas-wrap {
  height: 176px;
}

/* Matches the Radar vs. Rain Gauge card's total height (legend bar + three stacked
   canvases) so the Daylight/Radar row pairs evenly in the 2-column grid. */
.chart-canvas-wrap-daylight {
  height: 448px;
}

.chart-canvas-wrap-small {
  height: 90px;
  margin-bottom: 10px;
  flex: none;
}

.chart-canvas-wrap-mini + .chart-canvas-wrap-small + .chart-canvas-wrap {
  height: 150px;
}

.radar-legend-bar {
  display: flex;
  height: 14px;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.radar-legend-bar span {
  flex: 1 1 0;
}

.radar-legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.stat-panel {
  flex: none;
  width: 172px;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  padding: 16px 15px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-card-full .stat-panel {
  width: 220px;
}

.stat-group-label {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
}

.stat-row .k {
  font-size: 12px;
  color: var(--text-secondary);
  /* Wrap to a second line rather than truncate with "..." - stat panels
     have vertical room to spare, so a readable full label beats a clipped one. */
  overflow-wrap: break-word;
  min-width: 0;
}

.stat-row .v {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: none;
}

/* Split max/min layout (e.g. pressure): each value gets its own row with
   more breathing room, since that card otherwise has empty space below. */
.stat-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row-split {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 0;
}

.stat-row-split .k {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-row-split .v {
  font-size: 22px;
  font-weight: 600;
}

.stat-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.empty-note {
  font-size: 12px;
  color: var(--text-muted);
}

.footer {
  max-width: 1680px;
  margin: 28px auto 0;
  padding: 0 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Chart.js tooltip override ---------- */
.chartjs-tooltip-hidden { opacity: 0; }

/* ---------- Responsive ----------
   >1200px: two charts per row, each with its side stat panel.
   900-1200px: one chart per row (full width), stat panel still side-by-side.
   <900px: chart card stacks internally (stats move below the chart).
   <480px: tightest mobile tuning. */

@media (max-width: 1200px) {
  .dash { grid-template-columns: 1fr; max-width: 980px; }
}

@media (max-width: 900px) {
  .chart-card { flex-direction: column; }
  .stat-panel {
    width: auto;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
  }
  .clocks { gap: 12px; }
  .rangebar-inner { flex-direction: column; align-items: stretch; }
  .range-readout { margin-left: 0; }

  .live-strip-inner {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .live-hero-slot {
    border-right: none;
    padding-right: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
  }
  .live-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px 14px;
  }
  .live-asof-slot {
    text-align: left;
    border-top: 1px solid var(--border);
    padding-top: 12px;
  }
  .live-asof-slot .live-value { justify-content: flex-start; }
}

@media (max-width: 480px) {
  .topbar-inner { padding: 12px 16px; }
  .brand h1 { font-size: 16px; }
  .clock-value { font-size: 13px; }
  .chart-main { padding: 14px 14px 10px; }
  .chart-canvas-wrap { height: 220px; }
  .custom-range-popover { left: 16px; right: 16px; flex-direction: column; align-items: stretch; }

  .live-hero-slot .live-value { font-size: 32px; }
  .live-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .live-value { font-size: 19px; }
}

/* ---------- Dashboard mode: fit everything to one screen, no scrolling ----------
   A kiosk/wall-display view. Fixed-height sections (header/rangebar/live-strip)
   keep their natural height; the chart grid fills whatever's left via flex,
   with the full-width temp row given less height than the 2x2 grid row below it. */

body.dashboard-mode {
  height: 100vh;
  overflow: hidden;
  padding-bottom: 0;
  display: flex;
  flex-direction: column;
}

body.dashboard-mode .topbar-inner,
body.dashboard-mode .rangebar-inner,
body.dashboard-mode .live-strip,
body.dashboard-mode .dash,
body.dashboard-mode .footer {
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

body.dashboard-mode .topbar,
body.dashboard-mode .rangebar {
  position: static;
  flex: none;
}

body.dashboard-mode .live-strip {
  flex: none;
  margin-top: 10px;
}

body.dashboard-mode .live-strip-inner {
  padding: 10px 20px;
}

body.dashboard-mode .live-hero-slot .live-value {
  font-size: 28px;
}

body.dashboard-mode .live-value {
  font-size: 18px;
}

body.dashboard-mode .dash {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 10px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

body.dashboard-mode .chart-card-full {
  flex: 0 0 34%;
  min-height: 0;
}

body.dashboard-mode .dash-grid-rest {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

body.dashboard-mode .chart-card {
  min-height: 0;
}

body.dashboard-mode .chart-main {
  min-height: 0;
  padding: 10px 14px 8px;
}

body.dashboard-mode .chart-head {
  margin-bottom: 4px;
}

body.dashboard-mode .chart-head h2 {
  font-size: 13px;
}

body.dashboard-mode .chart-canvas-wrap,
body.dashboard-mode .chart-card-full .chart-canvas-wrap {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

body.dashboard-mode .chart-canvas-wrap-mini {
  flex: 0 0 48px;
  height: 48px;
  margin-bottom: 6px;
}

body.dashboard-mode .chart-canvas-wrap-small {
  flex: 0 0 60px;
  height: 60px;
  margin-bottom: 6px;
}

body.dashboard-mode .stat-panel {
  width: 185px;
  padding: 10px 12px;
  gap: 8px;
  overflow-y: auto;
}

body.dashboard-mode .chart-card-full .stat-panel {
  width: 230px;
}

body.dashboard-mode .stat-group-label {
  margin-bottom: 2px;
}

body.dashboard-mode .stat-row {
  padding: 1px 0;
}

body.dashboard-mode .stat-row .k {
  font-size: 11.5px;
}

body.dashboard-mode .stat-row .v {
  font-size: 13px;
}

body.dashboard-mode .footer {
  display: none;
}
