/* =============================================================================
   Base : remise à zéro, typographie, boutons, champs, utilitaires communs
   au site public, à l'espace client et aux mini-pages.
   ============================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;               /* ancres : ne pas passer sous la barre fixe */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;
  letter-spacing: var(--tracking-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: clip;
}

/* Grain : bruit fractal très léger posé sur toute la page (SVG inline, feTurbulence) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

img, svg, video { display: block; max-width: 100%; }
h1, h2, h3, h4, p, figure, dl, dd, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-fg); }
[hidden] { display: none !important; }

/* Focus : anneau accent de 2 px, décalé de 2 px, sur tout élément interactif */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-color: transparent; }

.skip {
  position: fixed; left: 16px; top: -100px; z-index: 200;
  background: var(--accent); color: var(--accent-fg);
  padding: 12px 16px; font-weight: 600; text-decoration: none;
}
.skip:focus { top: 16px; }

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

/* Mise en page ---------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Typographie ----------------------------------------------------------------- */
.display, h1, h2 { font-weight: 700; line-height: 1.05; letter-spacing: var(--tracking-tight); text-wrap: balance; }
h3 { font-weight: 600; line-height: 1.25; letter-spacing: var(--tracking-normal); }

.label {                                   /* étiquettes : mono, capitales, très espacées */
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--muted-fg);
}
.label--accent { color: var(--accent-text); }

.lead { font-size: var(--fs-lg); line-height: 1.6; color: var(--muted-fg); max-width: 40rem; text-wrap: pretty; }
@media (min-width: 768px) { .lead { font-size: var(--fs-xl); } }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-accent { color: var(--accent-text); }
.text-muted { color: var(--muted-fg); }
.bar { display: block; width: 4rem; height: 4px; background: var(--accent); }   /* barre d'ancrage */

a.link {                                   /* lien : l'underline est l'affordance principale */
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
  text-decoration-color: var(--accent);
  transition: color var(--t-fast) var(--ease);
}
a.link:hover { color: var(--accent-text); }

/* Icônes (sprite assets/img/icons.svg, tracé fin 1,5 px, arêtes vives) ------------ */
.icon {
  width: 1.25rem; height: 1.25rem; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: square; stroke-linejoin: miter;
}
.icon--sm { width: 1rem; height: 1rem; }
.icon--lg { width: 1.75rem; height: 1.75rem; }

/* Boutons ---------------------------------------------------------------------- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.625rem;
  min-height: 44px;                        /* cible tactile minimale */
  padding: 0.75rem 0;
  font-size: var(--fs-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: var(--tracking-wider);
  white-space: nowrap; text-decoration: none;
  color: var(--accent-text);
  background: none; border: 0; border-radius: var(--radius);
  transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { pointer-events: none; opacity: 0.5; }

/* Principal : texte seul + soulignement accent animé */
.btn::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: var(--accent);
  transform-origin: left; transform: scaleX(1);
  transition: height var(--t-fast) var(--ease);
}
.btn:hover::after { height: 3px; }   /* pas de scaleX > 1 : le trait ne doit jamais dépasser du bouton */

/* Secondaire : filet fin, inversion complète au survol */
.btn--outline {
  padding-inline: 1.5rem; min-height: 48px;
  color: var(--fg); border: 1px solid var(--fg);
}
.btn--outline::after { display: none; }
.btn--outline:hover { background: var(--fg); color: var(--bg); }

/* Discret : gris, soulignement fin qui apparaît */
.btn--ghost { padding-inline: 1rem; color: var(--muted-fg); }
.btn--ghost::after { height: 1px; left: 1rem; right: 1rem; background: currentColor; transform: scaleX(0); transform-origin: left; }
.btn--ghost:hover { color: var(--fg); }
.btn--ghost:hover::after { transform: scaleX(1); }

/* Dangereux (déconnexion, suppression) */
.btn--danger { color: var(--danger); }
.btn--danger::after { background: currentColor; }

.btn--sm { min-height: 40px; font-size: var(--fs-xs); }
.btn--outline.btn--sm { padding-inline: 1rem; min-height: 40px; }
.btn--block { width: 100%; }

/* Bouton-icône carré (thème, menu, fermer…) */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px;
  color: var(--fg); border: 1px solid transparent; border-radius: var(--radius);
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { border-color: var(--border-hover); background: var(--muted); }
.icon-btn:active { transform: translateY(1px); }

/* Bascule de thème : lune en clair, soleil en sombre */
.theme-toggle .i-sun { display: none; }
:root[data-scheme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-scheme="dark"] .theme-toggle .i-moon { display: none; }

/* Champs ------------------------------------------------------------------------ */
.field { display: grid; gap: 0.5rem; }
.field > .label { color: var(--muted-fg); }

.input, .textarea, .select {
  width: 100%;
  min-height: 48px;
  padding: 0 1rem;
  font-size: var(--fs-base);                   /* 16 px : évite le zoom automatique sur iOS */
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--t-fast) var(--ease);
  appearance: none;
}
@media (min-width: 768px) { .input, .select { min-height: 56px; } }
.textarea { padding-block: 0.875rem; min-height: 9rem; resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--muted-fg); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-hover); }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); outline: none; }
.input:disabled, .textarea:disabled { cursor: not-allowed; opacity: 0.5; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[type="date"] { color-scheme: inherit; }

.field__hint { font-size: var(--fs-sm); color: var(--muted-fg); }

/* Message d'état (formulaires) */
.status { min-height: 1.6em; font-size: var(--fs-sm); }
.status[data-tone="ok"] { color: var(--ok); }
.status[data-tone="error"] { color: var(--danger); }

/* Pastille de statut : un point + le libellé (jamais la couleur seule) */
.badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 500;
  text-transform: uppercase; letter-spacing: var(--tracking-wider);
  white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; background: currentColor; flex: none; }
.badge--success { color: var(--ok); }
.badge--warning { color: var(--warn); }
.badge--danger  { color: var(--danger); }
.badge--neutral { color: var(--fg); }
.badge--muted   { color: var(--muted-fg); }

/* Révélation à l'apparition (site public) : fondu + glissement de 20 px, 500 ms */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity var(--t-slow) var(--ease), transform var(--t-slow) var(--ease); transition-delay: calc(var(--i, 0) * 80ms); }
.reveal.is-in { opacity: 1; transform: none; }
html:not(.js) .reveal { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .reveal { opacity: 1; transform: none; }
}
@media (forced-colors: active) { .btn::after { background: LinkText; } }

/* Décalages d'animation (remplacent style="--i:N", interdit par une CSP stricte) */
.d-1 { --i: 1; } .d-2 { --i: 2; } .d-3 { --i: 3; } .d-4 { --i: 4; } .d-5 { --i: 5; }
