/* =====================================================================
   Socle commun des démos OctyVIBE (octyvibe-demos.web.app)
   Chaque démo définit ses jetons sur :root dans son style.css :
     --bg --surface --surface-2 --ink --muted --line
     --accent --accent-ink (texte posé sur l'accent) --danger --ok
     --font-display --font-text --radius --radius-sm
   Le socle ne fixe aucune couleur de marque : il ne fait que s'en servir.
   Doctrine : R6 un bouton plein par écran, R10 rien ne saute, R11 texte
   ferré à gauche, R14 accent réservé aux actions, R15 pas de noir pur,
   R20 cibles de 44 px, R22 barre en bas sur mobile, R31 durées par rôle.
   ===================================================================== */

:root {
  --bg: #f6f4ef; --surface: #fff; --surface-2: #efece5;
  --ink: #1d1b18; --muted: #5f5a52; --line: #dcd7cc;
  --accent: #1d1b18; --accent-ink: #fff; --danger: #b3261e; --ok: #1e6b3a;
  --font-display: system-ui, sans-serif; --font-text: system-ui, sans-serif;
  --radius: 14px; --radius-sm: 8px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1200px;
  --t-in: 260ms; --t-out: 180ms; --t-press: 90ms;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --demobar-h: 40px;
  --tabbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--demobar-h) + 72px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 17px/1.55 var(--font-text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.08; font-weight: 500; text-wrap: balance; }
p { margin: 0; max-width: 64ch; text-wrap: pretty; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--accent-ink); }

.wrap { width: 100%; max-width: var(--max); margin-inline: auto; padding-inline: var(--gutter); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--surface); padding: 10px 14px; border-radius: var(--radius-sm); }
.skip:focus { top: 8px; }

/* ---------- Bandeau démo : dit honnêtement ce qu'est la page ---------- */
.demobar {
  position: sticky; top: 0; z-index: 60; height: var(--demobar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-inline: var(--gutter);
  background: #17171a; color: #e9e7e2; font: 500 13px/1 Inter, system-ui, sans-serif; letter-spacing: .01em;
}
.demobar__what { opacity: .78; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demobar__what b { font-weight: 600; opacity: 1; }
.demobar a {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding-inline: 4px;
  color: #fff; text-decoration: none; white-space: nowrap;
}
.demobar a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Boutons ---------- */
.btn {
  --_bg: var(--accent); --_fg: var(--accent-ink); --_bd: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 22px; border-radius: var(--radius-sm);
  background: var(--_bg); color: var(--_fg); border: 1.5px solid var(--_bd);
  font-weight: 600; font-size: 16px; line-height: 1; text-decoration: none; cursor: pointer;
  transition: transform var(--t-press) var(--ease-out), background-color var(--t-out) var(--ease-out), border-color var(--t-out) var(--ease-out), opacity var(--t-out);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn--ghost { --_bg: transparent; --_fg: var(--ink); --_bd: var(--line); }
.btn--ghost:hover { --_bd: var(--ink); }
.btn--quiet { --_bg: transparent; --_fg: var(--ink); --_bd: transparent; padding-inline: 12px; text-decoration: underline; text-underline-offset: 4px; }
.btn--block { width: 100%; }
.btn .i { width: 18px; height: 18px; flex: none; }
.btn.is-busy { pointer-events: none; }
.btn.is-busy .btn__label { opacity: .6; }

/* Icônes : un seul jeu, trait de 1.75, en currentColor (R19) */
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Formulaires (R29 : libellé au-dessus, validation à la sortie) ---------- */
.form { display: grid; gap: 4px 20px; }
.form--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form--2 > .field--full, .form--2 > .form__foot, .form--2 > fieldset { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .field > legend, .legend { font-size: 14px; font-weight: 600; color: var(--ink); padding: 0; }
.field__opt { font-weight: 400; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color var(--t-out) var(--ease-out), box-shadow var(--t-out) var(--ease-out);
}
.textarea { min-height: 112px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 40px; }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--ink) 40%, var(--line)); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.field__help { font-size: 13px; color: var(--muted); }
/* La place de l'erreur est réservée : rien ne saute quand elle apparaît (R10) */
.field__err { min-height: 20px; font-size: 13px; line-height: 20px; color: var(--danger); display: flex; gap: 6px; align-items: center; }
.field__err:empty::before { content: "\00a0"; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--danger); }
.field.is-valid .input, .field.is-valid .select { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* Choix en pastilles (radio/checkbox) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1.5px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 15px; font-weight: 500; transition: background-color var(--t-out), border-color var(--t-out), color var(--t-out);
}
.chip input:hover + span { border-color: var(--ink); }
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.chip input:disabled + span { opacity: .4; }
.chip input:disabled[data-out] + span, .chip--out input:disabled + span { text-decoration: line-through; }

/* Compteur − n + */
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.stepper button { width: 44px; height: 44px; border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1; }
.stepper button:disabled { opacity: .3; cursor: not-allowed; }
.stepper output { min-width: 32px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Étapes d'un parcours */
.steps { display: flex; gap: 6px; list-style: none; margin: 0 0 20px; padding: 0; counter-reset: s; }
.steps li { flex: 1; display: grid; gap: 8px; font-size: 13px; color: var(--muted); counter-increment: s; }
.steps li::before { content: ""; height: 3px; border-radius: 3px; background: var(--line); transition: background-color var(--t-in) var(--ease-out); }
.steps li[aria-current="step"], .steps li.is-done { color: var(--ink); }
.steps li[aria-current="step"]::before, .steps li.is-done::before { background: var(--ink); }

/* Panneau de succès / d'erreur à la place du formulaire */
.result { display: grid; gap: 14px; align-content: start; padding: 28px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.result[hidden] { display: none; }
.result__title { font-family: var(--font-display); font-size: 28px; line-height: 1.15; }
.result__recap { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: 15px; }
.result__recap dt { color: var(--muted); }
.result__recap dd { margin: 0; font-weight: 500; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 14px; color: var(--muted); }
.notice .i { margin-top: 1px; }
.notice--err { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--ink); }

/* ---------- Toast avec « Annuler » (R28) ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 6px 6px 16px;
  background: #1c1c1f; color: #f2f1ee; border-radius: 12px; box-shadow: 0 10px 30px rgba(20, 18, 16, .25);
  font: 500 15px/1.35 Inter, system-ui, sans-serif;
  animation: toast-in var(--t-in) var(--ease-out) both;
}
.toast.is-leaving { animation: toast-out var(--t-out) var(--ease-in) both; }
.toast__msg { flex: 1; }
.toast__undo { min-height: 44px; padding: 0 14px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .28); background: transparent; color: #fff; font-weight: 600; cursor: pointer; }
.toast__undo:hover { background: rgba(255, 255, 255, .1); }
.toast__bar { position: absolute; left: 12px; right: 12px; bottom: 4px; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, .5); transform-origin: left; }
.toast { position: relative; overflow: hidden; }
@keyframes toast-in { from { opacity: 0; translate: 0 12px; } }
@keyframes toast-out { to { opacity: 0; translate: 0 8px; } }
@keyframes bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Squelettes (R27) ---------- */
.skel { background: linear-gradient(90deg, var(--surface-2) 0%, color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: skel 1.4s ease-in-out infinite; border-radius: var(--radius-sm); }
@keyframes skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Apparitions au défilement (R31 : 260 ms, courbe naturelle) ---------- */
.js [data-rev] { opacity: 0; }
/* « backwards » et non « both » : une fois arrivé, l'élément retrouve son propre translate */
.js [data-rev].is-in { opacity: 1; animation: rev-in var(--t-in) var(--ease-out) backwards; animation-delay: var(--rev-d, 0ms); }
@keyframes rev-in { from { opacity: 0; translate: 0 var(--rev-y, 14px); } to { opacity: 1; translate: 0 0; } }

/* ---------- Séquence d'images liée au défilement ---------- */
.seq { position: absolute; inset: 0; width: 100%; height: 100%; }
.seq-stage { position: relative; overflow: hidden; background: var(--surface-2); }

/* ---------- Barre d'onglets mobile (R22) ---------- */
.tabbar { display: none; }
@media (max-width: 760px) {
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 44px;
    font-size: 11.5px; font-weight: 600; text-decoration: none; color: var(--muted);
  }
  .tabbar a[aria-current="true"] { color: var(--ink); }
  .tabbar a.tabbar__main { color: var(--tab-main, var(--accent)); }
  .toasts { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); }
  .form--2 { grid-template-columns: 1fr; }
  .desk-only { display: none !important; }
}
@media (min-width: 761px) { .mob-only { display: none !important; } }

/* ---------- Pied de page démo commun ---------- */
.democredit { padding: 28px var(--gutter); font: 400 13px/1.5 Inter, system-ui, sans-serif; color: var(--muted); border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; }
.democredit a { display: inline-flex; align-items: center; min-height: 44px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
  .js [data-rev] { opacity: 1; }
}
