/*
 * Improved Events — design tokens (socle commun : thème « base », back-office, console).
 * Mobile first · minimaliste · motion sobre (voir docs/01, partie A, et docs/03 §4 bis).
 * Les thèmes d'événement surchargent ces variables ; un thème sur mesure peut les ignorer.
 */

@layer tokens, base, motion;

@layer tokens {
  @font-face {
    font-family: "Bricolage Grotesque";
    src: url("/static/ui/fonts/bricolage-grotesque.woff2") format("woff2-variations");
    font-weight: 200 800; font-display: swap;
  }
  @font-face {
    font-family: "Inter";
    src: url("/static/ui/fonts/inter.woff2") format("woff2-variations");
    font-weight: 100 900; font-display: swap;
  }

  :root {
    color-scheme: light dark;

    /* Couleurs — OKLCH. Trois accents : principal (surchargé par l'événement), corail, soleil. */
    --c-bg: oklch(99.1% 0.002 270);
    --c-surface: oklch(100% 0 0);
    --c-surface-2: oklch(96.6% 0.006 270);
    --c-text: oklch(21% 0.03 270);
    --c-text-muted: oklch(47% 0.025 270);
    --c-border: oklch(91.8% 0.008 270);
    --c-accent: oklch(52% 0.22 268);
    --c-accent-contrast: oklch(99% 0.005 270);
    --c-accent-2: oklch(72% 0.16 35);
    --c-accent-3: oklch(87% 0.15 92);
    --c-ink: oklch(19% 0.04 270);
    --c-success: oklch(60% 0.15 155);
    --c-warning: oklch(76% 0.15 70);
    --c-danger: oklch(57% 0.21 25);
    --c-focus: color-mix(in srgb, var(--c-accent) 50%, transparent);
    --c-accent-soft: color-mix(in srgb, var(--c-accent) 11%, var(--c-surface));
    --g-accent: linear-gradient(135deg, var(--c-accent), color-mix(in srgb, var(--c-accent) 55%, var(--c-ink)));

    /* Typographie */
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-display: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
    --fs-xs: 0.78rem;
    --fs-sm: 0.9rem;
    --fs-md: 1rem;
    --fs-lg: clamp(1.1rem, 1rem + 0.5vw, 1.3rem);
    --fs-xl: clamp(1.45rem, 1.2rem + 1.2vw, 2rem);
    --fs-2xl: clamp(2.1rem, 1.5rem + 3.2vw, 3.6rem);
    --lh-tight: 1.08;
    --lh-body: 1.55;

    /* Espaces — base 4 px */
    --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
    --sp-5: 1.5rem;  --sp-6: 2rem;   --sp-7: 3rem;    --sp-8: 4rem;
    --gutter: var(--sp-4);
    --content-max: 68rem;

    /* Formes : douces, parfois irrégulières */
    --radius-sm: 0.6rem;
    --radius-md: 1rem;
    --radius-lg: 1.5rem;
    --radius-xl: 2rem;
    --radius-pill: 999px;
    --radius-blob: 58% 42% 52% 48% / 46% 54% 46% 54%;
    --radius-blob-2: 42% 58% 38% 62% / 55% 38% 62% 45%;
    --shadow-1: 0 1px 2px oklch(20% 0.03 270 / 0.06), 0 1px 1px oklch(20% 0.03 270 / 0.04);
    --shadow-2: 0 2px 4px oklch(20% 0.03 270 / 0.05), 0 12px 32px -8px oklch(20% 0.03 270 / 0.14);
    --shadow-3: 0 4px 10px oklch(20% 0.03 270 / 0.06), 0 30px 60px -20px oklch(25% 0.08 270 / 0.32);

    /* Tactile */
    --tap-min: 44px;
    --tabbar-h: 72px;

    /* Motion — courtes, transform/opacity uniquement */
    --dur-micro: 140ms;
    --dur-base: 240ms;
    --dur-page: 380ms;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in: cubic-bezier(0.55, 0, 1, 0.45);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --ease-spring: linear(0, 0.36 9%, 0.68 18%, 0.9 28%, 1.01 38%, 1.04 46%, 1.02 58%, 1 72%, 1);
    --rise: 14px;
    --stagger: 50ms;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --c-bg: oklch(17% 0.02 270);
      --c-surface: oklch(21.5% 0.022 270);
      --c-surface-2: oklch(25.5% 0.024 270);
      --c-text: oklch(96% 0.004 270);
      --c-text-muted: oklch(73% 0.015 270);
      --c-border: oklch(31% 0.022 270);
      --c-accent: oklch(68% 0.17 268);
      --c-accent-contrast: oklch(16% 0.03 270);
    }
  }
  :root[data-theme="dark"] {
    --c-bg: oklch(17% 0.02 270);
    --c-surface: oklch(21.5% 0.022 270);
    --c-surface-2: oklch(25.5% 0.024 270);
    --c-text: oklch(96% 0.004 270);
    --c-text-muted: oklch(73% 0.015 270);
    --c-border: oklch(31% 0.022 270);
    --c-accent: oklch(68% 0.17 268);
    --c-accent-contrast: oklch(16% 0.03 270);
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; interpolate-size: allow-keywords; }
  body {
    margin: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font: var(--fs-md) / var(--lh-body) var(--font-sans);
    -webkit-font-smoothing: antialiased;
  }
  /* Rien ne déborde : les textes longs (e-mails, références) se coupent proprement. */
  h1, h2, h3, p, dt, li, legend, label, a, span { overflow-wrap: break-word; }
  dd, .mono, .breakable { overflow-wrap: anywhere; }
  :focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; border-radius: var(--radius-sm); }
  button, input, select, textarea { font: inherit; color: inherit; }
  button, input, select { min-height: var(--tap-min); }
  img, video { display: block; max-width: 100%; height: auto; }
  svg { max-width: 100%; }
}

@layer motion {
  @media (prefers-reduced-motion: no-preference) {
    /* Transitions entre pages (MPA + htmx) */
    @view-transition { navigation: auto; }
    ::view-transition-old(root) { animation: var(--dur-page) var(--ease-in) both fade-out; }
    ::view-transition-new(root) { animation: var(--dur-page) var(--ease-out) both fade-rise; }

    /* Apparition d'un élément inséré (toast, sheet, ligne de liste) */
    .enter {
      transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
      @starting-style { opacity: 0; transform: translateY(var(--rise)); }
    }

    /* Révélation au scroll, une seule fois, CSS natif */
    @supports (animation-timeline: view()) {
      .reveal {
        animation: fade-rise linear both;
        animation-timeline: view();
        animation-range: entry 0% cover 25%;
      }
    }

    /* Retour tactile */
    .pressable { transition: transform var(--dur-micro) var(--ease-out); }
    .pressable:active { transform: scale(0.97); }

    /* Retours d'état : succès (scan valide, paiement reçu) / erreur (code faux) */
    .pulse-success { animation: pulse var(--dur-page) var(--ease-spring); }
    .shake { animation: shake 320ms var(--ease-in-out); }
  }

  @keyframes fade-rise { from { opacity: 0; transform: translateY(var(--rise)); } }
  @keyframes fade-out { to { opacity: 0; } }
  @keyframes pulse { 0% { transform: scale(0.96); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }
  @keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}
