/* Tableau de bord météo La Réunion — feuille autonome, intégrable en iframe.
   Couleurs par rôle (variables) : mode clair, mode sombre (système ou ?theme=dark). */
:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface-1: #fcfcfb;
  --surface-2: #efeee9;
  --land: #e7e6df;
  --land-edge: #c9c7bd;
  --border: #e2e0d9;
  --text-primary: #161614;
  --text-secondary: #52514e;
  --text-muted: #7a7973;
  --grid: #e9e8e2;
  --accent: #2f5d3a;
  --accent-soft: #e3ece4;
  --series-temp: #eb6834;
  --series-rain: #2a78d6;
  --series-wind: #1baf7a;
  --series-gust: #4a3aa7;
  --seq-0: #cde2fb; --seq-1: #9ec5f4; --seq-2: #6da7ec; --seq-3: #3987e5; --seq-4: #256abf; --seq-5: #104281;
  --critical: #d03b3b;
  --map-coast: #9a988e; --map-water: #8fb0cf; --map-road: #b39c84; --map-commune: #a3a196; --map-parc: #4f8a5b; --map-parc-fill: rgba(79, 138, 91, .10);
  --good: #0ca30c;
  --shadow: 0 1px 2px rgba(22, 22, 20, .05), 0 4px 16px rgba(22, 22, 20, .04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface-1: #1a1a19; --surface-2: #232321; --land: #262624; --land-edge: #45443f;
    --border: #2e2e2b; --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #94938a;
    --grid: #2b2b28; --accent: #8fc49a; --accent-soft: #23302550;
    --series-temp: #d95926; --series-rain: #3987e5; --series-wind: #199e70; --series-gust: #9085e9;
    --seq-0: #104281; --seq-1: #1c5cab; --seq-2: #2a78d6; --seq-3: #5598e7; --seq-4: #86b6ef; --seq-5: #cde2fb;
    --map-coast: #66655f; --map-water: #4f7396; --map-road: #8a7660; --map-commune: #5c5b55; --map-parc: #7fb58a; --map-parc-fill: rgba(127, 181, 138, .10);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface-1: #1a1a19; --surface-2: #232321; --land: #262624; --land-edge: #45443f;
  --border: #2e2e2b; --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #94938a;
  --grid: #2b2b28; --accent: #8fc49a; --accent-soft: #23302550;
  --series-temp: #d95926; --series-rain: #3987e5; --series-wind: #199e70; --series-gust: #9085e9;
  --seq-0: #104281; --seq-1: #1c5cab; --seq-2: #2a78d6; --seq-3: #5598e7; --seq-4: #86b6ef; --seq-5: #cde2fb;
  --map-coast: #66655f; --map-water: #4f7396; --map-road: #8a7660; --map-commune: #5c5b55; --map-parc: #7fb58a; --map-parc-fill: rgba(127, 181, 138, .10);
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums;
}
body.embed { background: transparent; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 16px 40px; }
body.embed .wrap { padding: 8px 16px 16px; }

/* En-tête */
.eyebrow { margin: 0 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
h1 { margin: 0; font-size: clamp(24px, 3.4vw, 34px); line-height: 1.15; letter-spacing: -.01em; font-weight: 700; }
.lede { margin: 8px 0 0; color: var(--text-secondary); max-width: 62ch; }
.fresh { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); font-size: 13px; }
.fresh::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.fresh.stale::before { background: var(--text-muted); }

/* Barre de contrôle */
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 24px 0 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: min(100%, 320px); flex: 1 1 320px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
select {
  appearance: none; font: inherit; color: var(--text-primary); background: var(--surface-1)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237a7973' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 36px 10px 12px; width: 100%;
}
select:focus-visible, button:focus-visible, .station-dot:focus-visible, th button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* Cartes */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2, .card h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card .sub { margin: 2px 0 12px; font-size: 13px; color: var(--text-muted); }
section { margin-top: 28px; }
section > h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.005em; }
section > .sub { margin: 0 0 14px; color: var(--text-secondary); font-size: 14px; }

/* Carte des stations */
.map svg { display: block; width: 100%; height: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.chip { font: inherit; font-size: 12px; color: var(--text-secondary); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text-primary); }
.chip[aria-pressed="true"]::before { content: "✓ "; color: var(--accent); }
.chips[hidden], .timebar[hidden] { display: none; }
.tiles-title { margin: 16px 0 8px; font-size: 14px; font-weight: 650; }
#clim-records { margin-bottom: 16px; }
.fiche { margin: 14px 0 0; }
.fiche[hidden] { display: none; }
.fiche .cols { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); margin-top: 10px; }
.facts { margin: 0; display: grid; gap: 9px; align-content: start; }
.facts > div { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 10px; font-size: 13px; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; }
.fiche table { font-size: 12.5px; }
.fiche th, .fiche td { text-align: left; white-space: normal; padding: 7px 8px; }
.fiche .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
.fiche .callout { margin: 12px 0 0; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--series-temp); font-size: 13px; color: var(--text-secondary); }
@media (max-width: 860px) { .fiche .cols { grid-template-columns: minmax(0, 1fr); } .facts > div { grid-template-columns: 8.5em minmax(0, 1fr); } }
.chart .normal { fill: none; stroke: var(--text-secondary); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .band { fill: var(--series-temp); opacity: .14; }
.tile .t { line-height: 1.35; }
.timebar { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.timebar .play { font: inherit; width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); cursor: pointer; line-height: 1; }
.timebar .play[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.timebar input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.timebar output { flex: none; min-width: 9.5em; font-size: 12px; color: var(--text-secondary); text-align: right; }
.map svg.fc .station-dot .core { fill: var(--surface-1); stroke: var(--text-secondary); stroke-width: 1.5; }
.chart .nowline { stroke: var(--text-secondary); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .nowlabel { font-size: 11px; fill: var(--text-secondary); }
.legend i.line.dash { background: repeating-linear-gradient(90deg, var(--lg, currentColor) 0 5px, transparent 5px 8px) !important; }
.legend i.bar { width: 10px; height: 10px; border-radius: 2px; box-shadow: none; }
.map .land-edge { fill: none; stroke: var(--map-coast); stroke-width: 1.2; }
.map .parc { fill: var(--map-parc-fill); stroke: var(--map-parc); stroke-width: 1.2; stroke-dasharray: 4 3; }
.map .water { fill: none; stroke: var(--map-water); stroke-width: 1; stroke-linecap: round; }
.map .road { fill: none; stroke: var(--map-road); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.map .commune { fill: none; stroke: var(--map-commune); stroke-width: .8; stroke-dasharray: 2 3; }
.map .place { font-size: 11px; fill: var(--text-secondary); paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.map .town { fill: var(--text-secondary); }
.map .peak { fill: var(--text-secondary); }
.station-dot { cursor: pointer; }
.station-dot .ring { fill: var(--surface-1); }
.station-dot .hit { fill: transparent; }
.station-dot.nodata .core { fill: var(--surface-1); stroke: var(--text-muted); stroke-width: 1.5; }
.station-dot .sel { fill: none; stroke: var(--text-primary); stroke-width: 2; opacity: 0; }
.station-dot.selected .sel { opacity: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(127,127,127,.35); }
.legend i.line { width: 16px; height: 2px; border-radius: 1px; box-shadow: none; }

/* Station sélectionnée */
.station-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.station-head h2 { font-size: 20px; }
.station-meta { color: var(--text-muted); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 10px; margin-top: 14px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font-size: 24px; font-weight: 650; line-height: 1.2; margin-top: 2px; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile .t { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.tile.empty .v { color: var(--text-muted); font-weight: 500; font-size: 16px; }
.note { margin: 12px 0 0; font-size: 12px; color: var(--text-muted); }

/* Graphiques */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--land-edge); stroke-width: 1; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .label { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.chart .empty { fill: var(--text-muted); font-size: 13px; }
.chart-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.charts { display: grid; gap: 16px; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; opacity: 0; transition: opacity .08s;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.45; box-shadow: 0 6px 24px rgba(0,0,0,.12);
  max-width: 260px;
}
.tooltip.on { opacity: 1; }
.tooltip b { font-weight: 650; }
.tooltip .row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .row i { width: 10px; height: 2px; border-radius: 1px; display: inline-block; }
.tooltip .row strong { color: var(--text-primary); font-weight: 600; margin-left: auto; padding-left: 10px; }

/* Classement et événements */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank button { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr) 4.2rem;
  gap: 10px; align-items: center; cursor: pointer; padding: 3px 4px; border-radius: 8px; font-size: 13px; }
.rank button:hover, .rank button[aria-current="true"] { background: var(--surface-2); }
.rank .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.rank .bar { height: 10px; border-radius: 0 4px 4px 0; background: var(--series-rain); min-width: 2px; }
.rank .val { text-align: right; font-weight: 600; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.events li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.status.critical { color: var(--critical); }
.status.good { color: var(--text-secondary); }
.status svg { flex: none; }

/* Tableau (vue accessible de toutes les données) */
details.table { margin-top: 16px; }
details.table summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); padding: 4px 0; }
.table-scroll { overflow-x: auto; margin-top: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--text-secondary); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th button { all: unset; cursor: pointer; }
th button[data-dir="asc"]::after { content: " ↑"; }
th button[data-dir="desc"]::after { content: " ↓"; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr[aria-selected="true"] { background: var(--accent-soft); }
td.muted { color: var(--text-muted); }

/* Pied de page */
footer { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); display: grid; gap: 6px; }
footer a { color: var(--text-secondary); }
.page-credit { margin-top: 8px; font-size: 12px; letter-spacing: .02em; color: #D4AF37; opacity: 1; }
.error { padding: 16px; border-radius: 12px; background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); }

@media (max-width: 860px) {
  .grid, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .rank button { grid-template-columns: minmax(0, 8rem) minmax(0, 1fr) 3.6rem; }
  .tile .v { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { .tooltip { transition: none; } }
