/* ==========================================================================
   Socle visuel du site
   --------------------------------------------------------------------------
   Typographie, grille, barre de navigation, pied de page, figures
   (graphiques), infobulle, vue tableau et contrôles.

   Ce fichier ne contient AUCUNE couleur littérale. La page définit ses
   tokens, en clair et en sombre, dans styles.css :
     --bg  --surface  --ink  --ink-2  --muted  --line  --axis
     --accent  --accent-ink  --font-display
   ========================================================================== */

:root {
  /* Polices : chaque page définit les siennes (--font-body, --font-mono, --font-display) */
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-heading: var(--font-display);

  --maxw: 1180px;
  --measure: 66ch;
  --radius: 10px;
  --topbar-h: 56px;

  /* Échelle typographique (ratio ~1.25, titres fluides) */
  --step--1: 0.8125rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: clamp(1.45rem, 1.25rem + 0.9vw, 1.8rem);
  --step-3: clamp(1.85rem, 1.45rem + 1.8vw, 2.65rem);
  --step-4: clamp(2.4rem, 1.6rem + 3.6vw, 4.25rem);
  --step-5: clamp(2.9rem, 1.7rem + 5.8vw, 6.25rem);

  /* Espacements */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 72px;
  --space-9: 112px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Bande peinte sous la zone système (encoche) quand la barre est collante */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--bg);
}

img,
svg,
canvas {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-heading);
  line-height: 1.08;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in oklab, var(--accent) 70%, transparent);
}

a:hover {
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection {
  background: color-mix(in oklab, var(--accent) 30%, transparent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 60;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
}

.skip-link:focus {
  left: max(16px, env(safe-area-inset-left, 0px));
}

/* ---------- Conteneur et sections ---------- */

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.section {
  padding-block: var(--space-8);
}

.section + .section {
  border-top: 1px solid var(--line);
}

.section__head {
  display: grid;
  gap: var(--space-3);
  max-width: var(--measure);
  margin-bottom: var(--space-6);
}

.eyebrow {
  font: 600 0.8125rem/1.3 var(--font-body);
  color: var(--muted);
}

.title-xl {
  font-size: var(--step-5);
  letter-spacing: -0.02em;
}

.title-lg {
  font-size: var(--step-4);
  letter-spacing: -0.015em;
}

.title-md {
  font-size: var(--step-3);
  letter-spacing: -0.01em;
}

.title-sm {
  font-size: var(--step-2);
}

.lede {
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--ink-2);
  max-width: var(--measure);
}

.prose {
  display: grid;
  gap: 1em;
  max-width: var(--measure);
  color: var(--ink-2);
}

.prose strong {
  color: var(--ink);
  font-weight: 600;
}

.mono {
  font-family: var(--font-mono);
}

.num {
  font-variant-numeric: tabular-nums;
}

/* ---------- Barre de navigation ---------- */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-h);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9375rem;
  text-decoration: none;
  white-space: nowrap;
}

.brand__sub {
  color: var(--muted);
  font-weight: 500;
}

.sitenav {
  display: flex;
  gap: 18px;
  margin-left: auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.sitenav::-webkit-scrollbar {
  display: none;
}

.sitenav a {
  flex: none;
  padding: 6px 2px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
  box-shadow: inset 0 -2px 0 transparent;
}

.sitenav a:hover {
  color: var(--ink);
}

.sitenav a[aria-current] {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.codelink {
  flex: none;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}

.codelink:hover {
  text-decoration: underline;
}

@media (max-width: 720px) {
  .brand__sub,
  .codelink {
    display: none;
  }

  .sitenav a {
    padding: 6px 9px;
    font-size: 0.8125rem;
  }
}

/* ---------- Chiffres clés (tuiles) ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: var(--space-5) var(--space-5);
}

.kpi {
  display: grid;
  align-content: start;
  gap: 6px;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
  min-width: 0;
}

.kpi__value {
  font: 600 clamp(1.9rem, 1.4rem + 1.8vw, 2.8rem)/1 var(--font-body);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.kpi__unit {
  font-size: 0.55em;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-2);
  margin-left: 2px;
}

.kpi__label {
  font-size: var(--step--1);
  line-height: 1.4;
  color: var(--ink-2);
}

/* ---------- Figures (graphiques) ---------- */

.fig {
  margin: 0;
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.fig__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
}

.fig__titles {
  display: grid;
  gap: 2px;
  min-width: 0;
  max-width: var(--measure);
}

.fig__title {
  font: 600 var(--step-1)/1.3 var(--font-body);
  color: var(--ink);
  text-wrap: balance;
}

.fig__sub {
  font-size: var(--step--1);
  color: var(--ink-2);
}

.fig__plot {
  position: relative;
  min-width: 0;
}

.fig__plot > svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.fig__note {
  font-size: var(--step--1);
  line-height: 1.5;
  color: var(--muted);
  max-width: var(--measure);
}

/* Habillage SVG commun */
.axis text,
.chart-label {
  fill: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.chart-label--ink {
  fill: var(--ink-2);
}

.chart-label--strong {
  fill: var(--ink);
  font-weight: 600;
}

.grid line {
  stroke: var(--line);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.baseline {
  stroke: var(--axis);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.hit {
  fill: transparent;
  stroke: none;
  cursor: crosshair;
}

[tabindex].mark:focus-visible,
.mark.is-hot {
  outline: none;
  filter: brightness(1.08) saturate(1.1);
}

/* ---------- Légende ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--step--1);
  color: var(--ink-2);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend__key {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend__key--line {
  width: 18px;
  height: 2px;
  border-radius: 1px;
}

.legend__key--dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ---------- Contrôles ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.seg button {
  font: 500 var(--step--1) / 1 var(--font-body);
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.seg button:hover {
  color: var(--ink);
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > label,
.field__label {
  font: 600 0.8125rem/1.2 var(--font-body);
  color: var(--ink-2);
}

select,
input[type="number"],
input[type="date"],
input[type="time"] {
  font: 500 0.9375rem/1.2 var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
  max-width: 100%;
}

select:hover,
input:hover {
  border-color: var(--ink-2);
}

input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 0.9375rem/1 var(--font-body);
  padding: 11px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  text-decoration: none;
}

.btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

/* ---------- Infobulle ---------- */

.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 280px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 10px 30px color-mix(in oklab, var(--ink) 16%, transparent);
  font: 500 0.8125rem/1.35 var(--font-body);
  font-variant-numeric: tabular-nums;
}

.tip__title {
  margin-bottom: 5px;
  color: var(--ink-2);
  font-weight: 600;
}

.tip__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tip__row + .tip__row {
  margin-top: 3px;
}

.tip__key {
  flex: none;
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

.tip__key--dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.tip__key--box {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.tip__value {
  font-weight: 650;
  color: var(--ink);
}

.tip__label {
  color: var(--ink-2);
}

.tip__note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}

/* ---------- Vue tableau (jumeau accessible des graphiques) ---------- */

.dataview {
  font-size: var(--step--1);
  color: var(--ink-2);
}

.dataview > summary {
  width: fit-content;
  cursor: pointer;
  font-weight: 500;
  color: var(--ink-2);
}

.dataview > summary:hover {
  color: var(--ink);
}

.dataview__scroll {
  margin-top: var(--space-2);
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dataview table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.dataview th,
.dataview td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.dataview th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
}

.dataview .num {
  text-align: right;
}

/* ---------- Pied de page ---------- */

.footer {
  border-top: 1px solid var(--line);
  padding-block: var(--space-7) var(--space-8);
  font-size: var(--step--1);
  line-height: 1.55;
  color: var(--ink-2);
}

.footer__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: var(--space-5) var(--space-6);
}

.footer__grid > * {
  min-width: 0;
}

.footer h2 {
  margin-bottom: var(--space-2);
  font: 600 0.8125rem/1.3 var(--font-body);
  color: var(--ink);
}

.footer ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}

/* ---------- Mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
