/* =====================================================================
   Mer de nuages · design system « Grelou » — composants
   Ne consomme que les tokens de tokens.css. Préfixe : .ds-
   Catalogue et règles d'usage : docs/design-system/README.md
   ===================================================================== */

/* ---------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: var(--text-md); line-height: var(--leading-snug);
  color: var(--text-primary); background: var(--surface-0);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
:where(a) { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: from-font; }
:where(a:hover) { color: var(--accent-hover); }
:where(button, input, select, textarea) { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
::selection { background: var(--marque); color: var(--marque-texte); }
[hidden] { display: none !important; }
.ds-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; }
.ds-num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------- typographie */
.ds-display {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-display);
  line-height: var(--leading-tight); letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums;
}
.ds-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-2xl); line-height: 1.1; margin: 0; }
.ds-eyebrow {
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow); color: var(--text-secondary); margin: 0 0 var(--space-2);
}
.ds-note { font-size: var(--text-xs); line-height: var(--leading-normal); color: var(--text-muted); margin: var(--space-1) 0 0; }
.ds-prose p { font-size: var(--text-sm); line-height: var(--leading-normal); color: var(--text-secondary); margin: 0 0 var(--space-3); }

/* ---------------------------------------------------------- carte */
.ds-card { background: var(--surface-2); border-radius: var(--radius-lg); padding: var(--space-4); }
.ds-card--outline { background: transparent; border: 1px solid var(--border); }

/* ---------------------------------------------------------- boutons */
.ds-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h); padding: 0 var(--space-4); border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--text-primary);
  font-size: var(--text-sm); font-weight: 500; line-height: 1; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.ds-btn:hover { background: var(--surface-3); }
.ds-btn:active { transform: translateY(1px); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] { opacity: .45; cursor: default; transform: none; }
.ds-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); font-weight: 600; }
.ds-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.ds-btn--sm { min-height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.ds-btn--text { border-color: transparent; background: none; color: var(--accent); padding: 0 var(--space-1); min-height: 28px; }
.ds-btn--text:hover { background: var(--accent-soft); }
.ds-btn svg { width: 16px; height: 16px; flex: none; }

/* bouton rond à pictogramme (contrôles de carte, thème) */
.ds-icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface-raised);
  color: var(--text-primary); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.ds-icon-btn:hover { background: var(--surface-3); }
.ds-icon-btn:active { transform: scale(.95); }
.ds-icon-btn svg { width: 20px; height: 20px; }
.ds-icon-btn--map { border: 0; box-shadow: var(--shadow-map); }

/* ---------------------------------------------------------- pastille (chip) */
.ds-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: var(--text-2xs); font-weight: 600; line-height: 1.5; white-space: nowrap;
  color: var(--text-secondary); background: var(--surface-3);
}
.ds-chip[data-tone="good"] { color: var(--good); background: var(--good-bg); }
.ds-chip[data-tone="warn"] { color: var(--warn); background: var(--warn-bg); }
.ds-chip[data-tone="info"] { color: var(--info); background: var(--info-bg); }
.ds-chip[data-tone="danger"] { color: var(--danger); background: var(--danger-bg); }
.ds-chip[data-tone="accent"] { color: var(--accent); background: var(--accent-soft); }
/* position par rapport à la nappe : couleurs des étiquettes de la carte */
.ds-chip[data-pos="dessus"] { color: var(--pos-dessus); background: var(--pos-dessus-bg); box-shadow: inset 0 0 0 1px var(--pos-dessus-contour); }
.ds-chip[data-pos="bord"] { color: var(--pos-bord); background: var(--pos-bord-bg); box-shadow: inset 0 0 0 1px var(--soleil-300); }
.ds-chip[data-pos="dessous"] { color: var(--pos-dessous); background: var(--pos-dessous-bg); }
.ds-chip--md { font-size: var(--text-xs); padding: 3px 10px; }

/* point d'état, qui « respire » quand la donnée est en direct */
.ds-dot { position: relative; width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; }
.ds-dot--live::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; opacity: 0;
  animation: ds-pouls 2.4s var(--ease-out) infinite;
}
@keyframes ds-pouls { 0% { transform: scale(.5); opacity: .7; } 100% { transform: scale(1.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ds-dot--live::after { animation: none; } }

/* ---------------------------------------------------------- interrupteur (case à cocher stylée) */
.ds-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: 36px; height: 22px; border-radius: var(--radius-pill);
  background: transparent; border: 2px solid var(--control-off);
  transition: background var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.ds-switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--control-off); transition: transform var(--dur-base) var(--ease-out), background var(--dur-base) var(--ease-out);
}
.ds-switch:checked { background: var(--accent); border-color: var(--accent); }
.ds-switch:checked::before { transform: translateX(14px); background: var(--text-on-accent); }
.ds-switch:disabled { opacity: .4; cursor: not-allowed; }
.ds-switch:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ligne de réglage : libellé à gauche, interrupteur à droite, cible tactile pleine largeur */
.ds-toggle {
  display: flex; align-items: center; gap: var(--space-3); min-height: var(--tap-min);
  padding: var(--space-1) 0; cursor: pointer; font-size: var(--text-md);
}
.ds-toggle + .ds-toggle { border-top: 1px solid var(--border); }
.ds-toggle .ds-toggle-ico { width: 20px; height: 20px; flex: none; color: var(--text-secondary); }
.ds-toggle .ds-toggle-txt { flex: 1; min-width: 0; }
.ds-toggle .ds-toggle-txt small { display: block; font-size: var(--text-xs); color: var(--text-muted); }
.ds-toggle.is-disabled { color: var(--text-muted); cursor: not-allowed; }

/* ---------------------------------------------------------- choix segmenté (radios) */
.ds-segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-pill); background: var(--surface-3);
}
.ds-segmented label { position: relative; cursor: pointer; }
.ds-segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.ds-segmented span {
  display: block; padding: 5px 12px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500;
  color: var(--text-secondary); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.ds-segmented input:checked + span { background: var(--surface-raised); color: var(--text-primary); box-shadow: var(--shadow-1); font-weight: 600; }
.ds-segmented input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

/* ---------------------------------------------------------- curseur */
.ds-range {
  --pct: 50%;
  appearance: none; -webkit-appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer;
}
.ds-range::-webkit-slider-runnable-track {
  height: 6px; border-radius: var(--radius-pill);
  background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-3) var(--pct));
}
.ds-range::-moz-range-track { height: 6px; border-radius: var(--radius-pill); background: var(--surface-3); }
.ds-range::-moz-range-progress { height: 6px; border-radius: var(--radius-pill); background: var(--accent); }
.ds-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: var(--surface-raised); border: 3px solid var(--accent); box-shadow: var(--shadow-1);
}
.ds-range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--surface-raised); border: 3px solid var(--accent); box-shadow: var(--shadow-1);
}
.ds-range:focus-visible { outline: none; }
.ds-range:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.ds-range:focus-visible::-moz-range-thumb { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.ds-range:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------- liste */
.ds-list { list-style: none; margin: 0; padding: 0; font-size: var(--text-sm); }
.ds-list > li { display: flex; align-items: center; gap: var(--space-2); min-height: 38px; padding: var(--space-1) 0; border-bottom: 1px solid var(--border); }
.ds-list > li:last-child { border-bottom: 0; }
.ds-list .ds-list-fin { margin-left: auto; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------- tableau */
.ds-table { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
.ds-table th { text-align: left; font-weight: 600; color: var(--text-secondary); padding: var(--space-2) var(--space-1);
  border-bottom: 1px solid var(--border-strong); position: sticky; top: 0; background: var(--surface-1); }
.ds-table td { padding: var(--space-2) var(--space-1); border-bottom: 1px solid var(--border); }
.ds-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ds-table tbody tr[tabindex] { cursor: pointer; }
.ds-table tbody tr[tabindex]:hover td { background: var(--surface-2); }
.ds-table tbody tr[tabindex]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.ds-table tbody tr[aria-current="true"] td { background: var(--accent-soft); font-weight: 600; }
.ds-table tbody tr[aria-current="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

/* ---------------------------------------------------------- dépliant */
.ds-disclosure { border-top: 1px solid var(--border); }
.ds-disclosure > summary {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap-min); cursor: pointer; list-style: none;
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow); color: var(--text-secondary);
}
.ds-disclosure > summary::-webkit-details-marker { display: none; }
.ds-disclosure > summary::after {
  content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px); transition: transform var(--dur-base) var(--ease-out);
}
.ds-disclosure[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
.ds-disclosure > summary:hover { color: var(--text-primary); }
.ds-disclosure > :not(summary) { margin-bottom: var(--space-4); }

/* ---------------------------------------------------------- fenêtre (dialog) */
.ds-dialog {
  width: min(780px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: var(--space-4); border: 0;
  border-radius: var(--radius-xl); background: var(--surface-raised); color: var(--text-primary); box-shadow: var(--shadow-3);
}
.ds-dialog::backdrop { background: rgb(8 14 24 / .55); backdrop-filter: blur(3px); }
.ds-dialog[open] { animation: ds-entree var(--dur-slow) var(--ease-out); }
@keyframes ds-entree { from { opacity: 0; transform: translateY(12px) scale(.98); } }

/* ---------------------------------------------------------- infobulle */
.ds-tooltip {
  position: fixed; z-index: var(--z-tooltip); pointer-events: none; min-width: 130px; max-width: 270px;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface-raised); color: var(--text-primary); box-shadow: var(--shadow-2);
  font-size: var(--text-xs); line-height: 1.45;
}

/* ---------------------------------------------------------- légende */
.ds-legend { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--text-xs); color: var(--text-secondary); margin-top: var(--space-2); }
.ds-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.ds-swatch { display: inline-block; flex: none; }
.ds-swatch--line { width: 18px; height: 3px; border-radius: 2px; background: var(--c, var(--series-arome)); }
.ds-swatch--dash { width: 18px; height: 3px; background: radial-gradient(circle, var(--c, var(--series-arome)) 1.4px, transparent 1.6px) 0 50% / 6px 3px repeat-x; }
.ds-swatch--dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--series-satellite)); }
.ds-swatch--ring { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--c, var(--text-muted)); }
.ds-swatch--band { width: 14px; height: 11px; border-radius: 2px; background: var(--c, var(--chart-air-defav)); }

/* ---------------------------------------------------------- message (erreur, info) */
.ds-callout { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md); background: var(--info-bg); color: var(--info); font-size: var(--text-sm); }
.ds-callout[data-tone="danger"] { background: var(--danger-bg); color: var(--danger); }

/* ---------------------------------------------------------- logo */
.ds-logo { width: 36px; height: 36px; flex: none; border-radius: 10px; }
