/* =====================================================================
   Meteo Cambodge - feuille de style
   Palette et regles de dataviz : rampes sequentielles a une seule teinte,
   encres recessives pour la grille, contraste valide en clair et en sombre.
   ===================================================================== */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --ocean: #e8eef4;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 4px 12px rgba(11, 11, 11, .04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --ocean: #16202a;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --ocean: #16202a;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px 64px; }

/* --- en-tete ------------------------------------------------------- */
header {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  margin-bottom: 28px;
}
header .wrap { padding-top: 26px; padding-bottom: 22px; }
h1 { font-size: 25px; margin: 0 0 6px; letter-spacing: -.015em; font-weight: 650; }
.sub { color: var(--text-secondary); font-size: 14px; margin: 0; }
.sub b { color: var(--text-primary); font-weight: 600; }

.theme-toggle {
  float: right; border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); border-radius: 7px; padding: 6px 12px;
  cursor: pointer; font: inherit; font-size: 13px;
}
.theme-toggle:hover { color: var(--text-primary); }

/* --- barre de filtres (une seule rangee, au-dessus de tout) --------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  padding: 14px 16px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 24px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600;
}
select {
  font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--page);
  color: var(--text-primary); min-width: 190px; cursor: pointer;
}

.switch { display: flex; align-items: center; gap: 7px; font-size: 14px;
  padding: 7px 0; color: var(--text-secondary); cursor: pointer; }
.switch input { accent-color: var(--series-1); width: 15px; height: 15px; cursor: pointer; }

.filter-note {
  margin: -14px 0 24px; font-size: 12.5px; color: var(--text-muted);
  padding-left: 2px;
}
.filter-note:empty { display: none; }

/* Pendant un recalcul, on garde le rendu precedent en retrait plutot que
   d'afficher un squelette : pas de saut de mise en page. */
.busy { opacity: .45; transition: opacity .12s; }

/* --- sections et cartes -------------------------------------------- */
section { margin-bottom: 36px; }
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); margin: 0 0 14px; font-weight: 650;
}
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; box-shadow: var(--shadow);
}
.card h3 {
  font-size: 15px; margin: 0 0 2px; font-weight: 600;
}
.card .note { font-size: 12.5px; color: var(--text-muted); margin: 0 0 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* --- tuiles de statistiques ---------------------------------------- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.kpi {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
}
.kpi .k {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 6px;
}
.kpi .v { font-size: 26px; font-weight: 640; letter-spacing: -.02em; }
.kpi .v small { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.kpi .d { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* --- carte geographique -------------------------------------------- */
.map-wrap { position: relative; }
#map {
  width: 100%; height: auto; display: block; border-radius: 8px;
  background: var(--ocean); cursor: crosshair;
  image-rendering: auto;
}
/* Les frontieres sont un calque vectoriel au-dessus du raster : le trait
   reste net quel que soit l'affichage, et les PNG restent des donnees pures. */
.borders {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; border-radius: 8px;
}
/* Les proprietes doivent porter sur les traces eux-memes : `vector-effect`
   n'est pas heritee, et posee sur le groupe elle laisserait `stroke-width`
   s'exprimer en unites du viewBox — soit plus d'un degre de longitude. */
.borders path {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* Trait double : un lisere clair pose sous la ligne la rend lisible aussi
   bien sur les teintes claires que sur les teintes foncees de la rampe. */
.borders .halo path { stroke: var(--surface-1); stroke-opacity: .7; }
.borders .halo.country path { stroke-width: 3; }
.borders .halo.province path { stroke-width: 2; }

.borders .line.country path {
  stroke: var(--text-primary); stroke-opacity: .8; stroke-width: 1.2;
}
.borders .line.province path {
  stroke: var(--text-primary); stroke-opacity: .38; stroke-width: .6;
}

.borders.off { display: none; }

.markers { position: absolute; inset: 0; pointer-events: none; }
.marker {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px;
  border-radius: 50%; background: var(--text-primary);
  box-shadow: 0 0 0 2px var(--surface-1); pointer-events: auto; cursor: pointer;
}
.marker.active { background: var(--series-2); width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; }
.marker:hover { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px var(--border); }

.legend { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.legend .bar { height: 10px; flex: 1; border-radius: 3px; }
.legend .lab { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* --- infobulle ------------------------------------------------------ */
.tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,.10), 0 8px 24px rgba(0,0,0,.10);
  opacity: 0; transition: opacity .1s; max-width: 260px;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-title {
  font-size: 11.5px; color: var(--text-muted); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
.tooltip .tt-row { display: flex; align-items: baseline; gap: 8px; margin-top: 3px; }
.tooltip .tt-key { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-val { font-weight: 640; font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--text-secondary); font-size: 12.5px; }

/* --- graphiques ----------------------------------------------------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-title { fill: var(--text-muted); font-size: 11px; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 10px; }
.chart-legend .item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.chart-legend .swatch { width: 14px; height: 2px; border-radius: 1px; }
.chart-legend .swatch.rect { height: 10px; width: 10px; border-radius: 2px; }

/* --- vues tableau ---------------------------------------------------- */
.table-toggle {
  background: none; border: none; color: var(--text-secondary);
  font: inherit; font-size: 12.5px; cursor: pointer; padding: 4px 0;
  text-decoration: underline; text-underline-offset: 3px;
}
.table-toggle:hover { color: var(--text-primary); }
.table-view { display: none; margin-top: 12px; max-height: 320px; overflow: auto; }
.table-view.on { display: block; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td {
  text-align: right; padding: 5px 9px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
th {
  position: sticky; top: 0; background: var(--surface-1);
  color: var(--text-muted); font-weight: 600; text-align: right;
}
th:first-child, td:first-child { text-align: left; }

.dl {
  display: inline-block; margin-top: 12px; font-size: 12.5px;
  color: var(--series-1); text-decoration: none; font-weight: 500;
}
.dl:hover { text-decoration: underline; }

footer {
  border-top: 1px solid var(--border); padding-top: 18px;
  color: var(--text-muted); font-size: 12.5px;
}
footer a { color: var(--text-secondary); }
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }
