/* Palette : instance de référence du skill dataviz (slots catégoriels 1 à 4).
   Les valeurs sombres sont choisies pour la surface sombre, pas inversées. */
:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 8px 24px rgba(11, 11, 11, 0.06);
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  /* Rampe séquentielle : une seule teinte, du clair au foncé. Jamais d'arc-en-ciel :
     la couleur doit se lire comme « plus » ou « moins », pas comme une catégorie. */
  --carte-1: #cde2fb;
  --carte-2: #9ec5f4;
  --carte-3: #5598e7;
  --carte-4: #256abf;
  --carte-5: #104281;
  --carte-vide: #e9e8e3;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: none;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    /* Sur fond sombre la rampe est inversée : le pas le plus faible doit rester
       proche de la surface, donc sombre, et l'intensité croît vers le clair. */
    --carte-1: #184f95;
    --carte-2: #1c5cab;
    --carte-3: #2a78d6;
    --carte-4: #5598e7;
    --carte-5: #9ec5f4;
    --carte-vide: #2c2c2a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1rem 4rem;
  background: var(--plane);
  color: var(--text-primary);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main, .page-header, .page-footer { max-width: 60rem; margin: 0 auto; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden;
}

/* ------------------------------------------------------------------ en-tête */

.page-header { padding: 2.5rem 0 1.5rem; }
h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -0.02em; }
.lede { margin: 0.4rem 0 0; color: var(--text-secondary); }

/* ---------------------------------------------------------------- recherche */

.search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: center;
}
.search label {
  grid-column: 1 / -1;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.combobox { position: relative; }

input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
}
input[type="text"]:focus-visible,
button:focus-visible,
summary:focus-visible,
svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.search button[type="submit"] {
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: var(--surface);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.hint { grid-column: 1 / -1; margin: 0; font-size: 0.85rem; color: var(--text-muted); }

#suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 20rem;
  overflow-y: auto;
}
#suggestions li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}
#suggestions li.is-highlighted { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.suggestion-total { font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.message {
  margin: 1rem 0 0;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--series-2);
  border-radius: 6px;
  color: var(--text-secondary);
}

/* -------------------------------------------------------------------- puces */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}
.chip {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip.is-active { border-color: var(--axis); box-shadow: inset 0 0 0 1px var(--axis); }
.chip-select {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.25rem 0.35rem 0.75rem;
  font: inherit;
  color: var(--text-primary);
  background: none;
  border: 0;
  cursor: pointer;
}
/* Clé de légende d'une courbe : un trait, pas un pavé. */
.chip-key { width: 14px; height: 3px; border-radius: 2px; }
.chip-remove {
  padding: 0.35rem 0.7rem 0.35rem 0.4rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.chip-remove:hover { color: var(--text-primary); }

/* ------------------------------------------------------------- chiffres clés */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.stats-heading {
  grid-column: 1 / -1;
  margin: 0.5rem 0 -0.25rem;
  font-size: 1.25rem;
}
.stat {
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stat-label { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stat-value { margin: 0.25rem 0 0; font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; }
.stat-detail { margin: 0.2rem 0 0; font-size: 0.82rem; color: var(--text-secondary); }

.variants { margin: 0.9rem 0 0; font-size: 0.9rem; color: var(--text-secondary); }
.link-button {
  padding: 0;
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------------------------------------------------------------- graphique */

.chart-card {
  margin-top: 1.5rem;
  padding: 1.1rem 1.1rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.chart-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.chart-head h2 { margin: 0; font-size: 1.05rem; }

.unit-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.unit-toggle button {
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: none;
  border: 0;
  cursor: pointer;
}
.unit-toggle button.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text-primary); font-weight: 600; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }

.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cursor-dot { stroke: var(--surface); stroke-width: 2; }
.label-key { stroke-width: 3; stroke-linecap: round; }
.tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.series-label { fill: var(--text-primary); font-size: 12px; font-weight: 600; }

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 8rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.tooltip-year { margin: 0 0 0.35rem; font-size: 0.78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tooltip-row { display: flex; align-items: baseline; gap: 0.45rem; margin: 0.15rem 0; }
.tooltip-key { width: 12px; height: 3px; border-radius: 2px; }
.tooltip-row strong { font-variant-numeric: tabular-nums; }
.tooltip-name { font-size: 0.85rem; color: var(--text-secondary); }

.chart-note { margin: 0.6rem 0 0; font-size: 0.8rem; color: var(--text-muted); }

.table-view { margin-top: 0.75rem; border-top: 1px solid var(--border); padding-top: 0.5rem; }
.table-view summary { font-size: 0.9rem; color: var(--text-secondary); cursor: pointer; }
.table-scroll { max-height: 22rem; overflow: auto; margin-top: 0.6rem; }
.table-scroll table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table-scroll caption { text-align: left; padding-bottom: 0.5rem; color: var(--text-muted); font-size: 0.8rem; }
.table-scroll th, .table-scroll td { padding: 0.3rem 0.6rem; text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll thead th { position: sticky; top: 0; background: var(--surface); text-align: right; border-bottom: 1px solid var(--border); }
.table-scroll tbody th { text-align: left; font-weight: 500; color: var(--text-secondary); }
.table-scroll tbody tr:nth-child(even) { background: color-mix(in srgb, var(--text-primary) 3%, transparent); }

/* -------------------------------------------------------------------- carte */

.map-figure { position: relative; }
.map-figure svg { display: block; width: 100%; height: auto; max-height: 70vh; }
.map-figure svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Trait de séparation dans la couleur de la surface : les départements se
   distinguent sans qu'un liseré sombre ne vienne peser sur les aplats clairs. */
.departement { stroke: var(--surface); stroke-width: 0.6; stroke-linejoin: round; }
.departement.est-survole { stroke: var(--text-primary); stroke-width: 1.4; }
.cartouche { fill: none; stroke: var(--axis); stroke-width: 0.7; }
.cartouche-label { fill: var(--text-muted); font-size: 8px; }

.legende { margin-top: 0.6rem; }
.legende-titre { margin: 0 0 0.35rem; font-size: 0.8rem; color: var(--text-muted); }
.legende-echelle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.legende-echelle li { display: flex; align-items: center; gap: 0.35rem; }
.legende-pastille {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.periode {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.periode label { font-weight: 600; }
.periode input[type="range"] { flex: 1; min-width: 8rem; accent-color: var(--accent); }
.periode output { min-width: 7rem; font-variant-numeric: tabular-nums; }

.suggestion-note {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: default;
}

/* ------------------------------------------------------------- état initial */

.empty {
  margin-top: 2rem;
  padding: 2rem 1.25rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--axis);
  border-radius: 12px;
  color: var(--text-secondary);
}
.examples { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin-bottom: 0; }
.examples button {
  padding: 0.4rem 0.9rem;
  font: inherit;
  color: var(--text-primary);
  background: var(--plane);
  border: 1px solid var(--axis);
  border-radius: 999px;
  cursor: pointer;
}

.page-footer { margin-top: 2.5rem; font-size: 0.82rem; color: var(--text-muted); }
.page-footer p { margin: 0.35rem 0; }
.page-footer a { color: inherit; }

@media (max-width: 34rem) {
  .search { grid-template-columns: 1fr; }
  .search button[type="submit"] { width: 100%; }
  .chart-card { padding: 0.9rem 0.7rem; }
}
