/* ==========================================================================
   Clima del Terminillo — design tokens (palette validata, vedi skill dataviz)
   ========================================================================== */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --card-border: rgba(11, 11, 11, 0.10);

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;

  --gridline: #e1e0d9;
  --baseline: #c3c2b7;

  --series-1: #2a78d6; /* blu   */
  --series-2: #eb6834; /* arancio */
  --series-3: #1baf7a; /* acqua */
  --series-4: #eda100; /* giallo */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* verde */
  --series-7: #4a3aa7; /* viola */
  --series-8: #e34948; /* rosso */

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

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 14px rgba(11, 11, 11, 0.05);
}

/* Dark mode follows meteoterminillo.it's own toggle (body.dark, set by
   belchertown.js from sessionStorage), not prefers-color-scheme/data-theme,
   so this page's theme always matches the rest of the site. */
html:has(body.dark) {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --card-border: rgba(255, 255, 255, 0.10);

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --gridline: #2c2c2a;
  --baseline: #383835;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #e66767;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   Base
   ========================================================================== */

* { box-sizing: border-box; }

/* Scoped to .climate-page (not body/a) so this stylesheet only styles the
   climate section's own content and doesn't bleed into the site's shared
   Belchertown header/nav/footer chrome around it. */
.climate-page {
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.climate-page a { color: var(--series-1); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ==========================================================================
   Header + tab navigation
   ========================================================================== */

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

.climate-header__top {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 14px;
}

.climate-header h1 {
  font-size: 24px;
  margin: 0;
}

.climate-header__subtitle {
  color: var(--text-secondary);
  font-size: 14.72px;
  margin: 2px 0 0;
}

.climate-header__back {
  font-size: 13.6px;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
}
.climate-header__back:hover { color: var(--series-1); }

.tabs {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 14.72px;
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  /* Belchertown/Bootstrap set a global button{text-transform:uppercase} */
  text-transform: none;
}

.tab-btn:hover { color: var(--text-primary); background: var(--page-plane); }

.tab-btn[aria-selected="true"] {
  color: var(--series-1);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

/* ==========================================================================
   Layout
   ========================================================================== */

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.tab-panel { display: none; }
.tab-panel[data-active="true"] { display: block; }

.section-intro {
  color: var(--text-secondary);
  max-width: 72ch;
  margin: 0 0 22px;
}

h2.section-title {
  font-size: 19.2px;
  margin: 0 0 4px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 14px;
  margin-bottom: 22px;
}

.card__title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 2px;
}

.card__subtitle {
  font-size: 13.6px;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.card__footnote {
  font-size: 12.48px;
  color: var(--text-muted);
  margin: 10px 0 0;
}

.chart-wrap {
  position: relative;
  height: 320px;
}
.chart-wrap.chart-wrap--tall { height: 380px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

/* Grid items default to min-width:auto, so a chart canvas's rendered pixel
   width acts as a hard floor on the column and blows out the layout on
   narrow screens (grid track grows to fit the canvas instead of the other
   way around). min-width:0 lets the track (and Chart.js's responsive
   resize, which reads the track's width) actually shrink to fit. */
.grid-2 > * { min-width: 0; }

@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* segmented control (toggle variabile) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}
.segmented button {
  appearance: none;
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13.12px;
  padding: 6px 14px;
  cursor: pointer;
  border-right: 1px solid var(--card-border);
  text-transform: none;
}
.segmented button:last-child { border-right: none; }
.segmented button[aria-pressed="true"] {
  background: var(--series-1);
  color: white;
  font-weight: 600;
}

/* ==========================================================================
   KPI stat tiles
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.stat-tile__label {
  font-size: 12.48px;
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.stat-tile__value {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}
.stat-tile__value small {
  font-size: 13.6px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-tile__delta {
  font-size: 12.8px;
  margin-top: 4px;
}
.stat-tile__delta--up { color: var(--critical); }
.stat-tile__delta--down { color: var(--series-1); }

.stat-tile__meta {
  font-size: 12.16px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ==========================================================================
   Callout / warning box
   ========================================================================== */

.callout {
  border-left: 3px solid var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, var(--surface-1));
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  font-size: 14.08px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.callout strong { color: var(--text-primary); }

/* ==========================================================================
   Trend delta cards (tab Trend)
   ========================================================================== */

.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.trend-card {
  background: var(--surface-1);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.trend-card__label { font-size: 13.12px; color: var(--text-secondary); margin: 0 0 6px; }
.trend-card__value { font-size: 20.8px; font-weight: 600; margin: 0; }
.trend-card__sig { font-size: 11.84px; color: var(--text-muted); margin-top: 4px; }

/* ==========================================================================
   Ranking list (anni piu' caldi/freddi)
   ========================================================================== */

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: ranking;
}
.ranking-list li {
  counter-increment: ranking;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--card-border);
  font-size: 14.72px;
}
.ranking-list li:last-child { border-bottom: none; }
.ranking-list li::before {
  content: counter(ranking) ".";
  color: var(--text-muted);
  margin-right: 10px;
  font-size: 12.8px;
  min-width: 16px;
}
.ranking-list__year { flex: 1; }
.ranking-list__value { font-weight: 600; }

/* ==========================================================================
   Headline stat (es. probabilita' neve a Natale)
   ========================================================================== */

.headline-stat { margin-bottom: 14px; }
.headline-stat__value {
  font-size: 28.8px;
  font-weight: 700;
  color: var(--series-1);
  margin-right: 8px;
}
.headline-stat__label { font-size: 13.6px; color: var(--text-secondary); }

/* ==========================================================================
   Methodology tab
   ========================================================================== */

.station-card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface-1);
}
.station-card h3 { margin: 0 0 4px; font-size: 16px; }
.station-card p { margin: 2px 0; font-size: 14.08px; color: var(--text-secondary); }

.caveat-list { padding-left: 20px; color: var(--text-secondary); font-size: 14.72px; }
.caveat-list li { margin-bottom: 8px; }

/* ==========================================================================
   Footer
   ========================================================================== */

.page-footer {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px 40px;
  color: var(--text-muted);
  font-size: 12.8px;
}

/* ==========================================================================
   Chart.js tooltip override (coerente coi token)
   ========================================================================== */

.chartjs-tooltip-key {
  display: inline-block;
  width: 10px;
  height: 2px;
  margin-right: 6px;
  vertical-align: middle;
}
