/* Color variables live on :root so the WHOLE page (html/body, not just cards
   inside .viz-root) repaints on theme toggle — the previous version scoped
   them to .viz-root, which is a descendant of body, so body's own
   background/color never resolved them. */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1: #2a78d6; /* NWS */
  --series-2: #eb6834; /* Open-Meteo Best Match */
  --series-3: #1baf7a; /* GFS */
  --series-4: #eda100; /* ECMWF */
  --series-5: #e87ba4; /* ICON */
  --series-6: #008300; /* UKMO */
  --series-7: #4a3aa7; /* GEM */
  --seq-100: #cde2fb; --seq-300: #6da7ec; --seq-500: #256abf;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255,255,255,0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --seq-100: #184f95; --seq-300: #2a78d6; --seq-500: #86b6ef;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255,255,255,0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --seq-100: #184f95; --seq-300: #2a78d6; --seq-500: #86b6ef;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  transition: background-color 0.12s ease, color 0.12s ease;
}
.viz-root { max-width: 1000px; margin: 0 auto; padding: 28px 20px 48px; }
h1 { font-size: 20px; margin: 0 0 2px; }
.subtitle { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 18px; min-height: 1.4em; }
.theme-toggle {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; cursor: pointer; flex: none;
}
.top-links { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.link-btn {
  font: inherit; font-size: 12.5px; color: var(--text-secondary); text-decoration: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.link-btn:hover { color: var(--text-primary); }
.link-btn.primary { color: var(--series-1); border-color: var(--series-1); font-weight: 600; }

.controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px; padding: 12px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  position: relative;
}
.controls label { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.controls input[type="date"], .controls input[type="text"] {
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px;
}
.controls input[type="text"] { width: 220px; }
.controls .quick-btn {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: var(--page); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; cursor: pointer;
}
.controls .quick-btn:hover { color: var(--text-primary); }
.status-msg { font-size: 12px; color: var(--text-muted); margin-left: auto; }
.status-msg.error { color: #d03b3b; }
.status-msg.loading { opacity: 0.75; }

.location-wrap { position: relative; max-width: 100%; }
.location-results {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 10;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.16);
  width: max(260px, 100%); max-width: calc(100vw - 40px);
  max-height: 260px; overflow-y: auto; display: none;
}
.location-results.show { display: block; }
.location-result-item {
  padding: 10px 12px; font-size: 13px; color: var(--text-primary); cursor: pointer;
}
.location-result-item:hover { background: var(--page); }

.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.stat-label { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-value { font-size: 21px; font-weight: 600; }
.stat-note { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 16px 8px; margin-bottom: 16px;
  position: relative; min-height: 120px;
}
.card h2 { font-size: 14px; margin: 0 0 2px; }
.card .card-sub { font-size: 11.5px; color: var(--text-muted); margin: 0 0 10px; }
.no-data-msg { padding: 30px 4px; text-align: center; color: var(--text-muted); font-size: 13px; }

.legend {
  display: flex; flex-wrap: wrap; gap: 14px 18px;
  padding: 4px 4px 14px;
  font-size: 12px; color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-key { width: 16px; height: 2px; border-radius: 1px; flex: none; }
.legend-note { font-size: 11.5px; color: var(--text-muted); padding: 0 4px 12px; margin: 0; }

svg { display: block; width: 100%; height: auto; overflow: visible; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 10.5px; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.end-dot { stroke: var(--surface-1); stroke-width: 2; }
.band-fill { opacity: 0.1; stroke: none; }

.crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
.hit-layer { fill: transparent; cursor: crosshair; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.16);
  min-width: 190px; visibility: hidden; opacity: 0;
  transition: opacity 0.08s ease;
}
.tooltip.show { visibility: visible; opacity: 1; }
.tooltip .t-hour { font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.tooltip-row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.tooltip-key { width: 12px; height: 2px; flex: none; }
.tooltip-name { color: var(--text-secondary); flex: 1; }
.tooltip-val { font-weight: 600; color: var(--text-primary); }

.toggle-table-btn {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; cursor: pointer; margin: 4px 0 20px;
}
.table-wrap { display: none; overflow-x: auto; margin-bottom: 24px; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap.show { display: block; }
table { border-collapse: collapse; width: 100%; font-size: 12px; white-space: nowrap; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }
th { text-align: right; color: var(--text-secondary); font-weight: 600; background: var(--surface-1); position: sticky; top: 0; }
td:first-child, th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
.foot-note { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }

.period-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.period-tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.period-tile .period-name { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 4px; }
.period-tile .period-cond { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.period-tile .period-detail { font-size: 11.5px; color: var(--text-muted); }

@media (max-width: 780px) {
  .viz-root { padding: 18px 14px 36px; }
  h1 { font-size: 18px; }
  .stat-row, .period-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .card { padding: 14px 12px 6px; }
}

@media (max-width: 560px) {
  .controls { flex-direction: column; align-items: stretch; gap: 8px; }
  .controls label { width: 100%; justify-content: space-between; min-width: 0; }
  .controls input[type="text"], .controls input[type="date"] { width: 100%; flex: 1; min-width: 0; }
  .location-wrap { width: 100%; min-width: 0; }
  .controls .quick-btn, .controls #useMyLocationBtn { width: 100%; }
  .status-msg { margin-left: 0; }
  .top-links { flex-wrap: wrap; }
  .stat-row, .period-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Touch devices: enlarge tap targets beyond what pointer-fine (mouse) needs */
@media (hover: none) and (pointer: coarse) {
  .quick-btn, .link-btn, .theme-toggle, .toggle-table-btn { padding: 10px 14px; }
  .controls input[type="date"], .controls input[type="text"] { padding: 10px 12px; }
  .location-result-item { padding: 12px 14px; }
}
