/* =========================================================================
   Kirexo — Design System
   Warm-paper editorial system. Light + dark. RGAA-oriented.
   ========================================================================= */

/* ---- Fonts -------------------------------------------------------------- */
/* Polices auto-hébergées — cf. assets/styles/fonts.css pour le pourquoi et la
   procédure de régénération. Le @import distant qui vivait ici coûtait 9,6 s de
   timeout DNS par page depuis un conteneur, le réseau de dev étant `internal`. */
@import url('./fonts.css');

/* =========================================================================
   TOKENS
   ========================================================================= */
:root {
  /* Type families */
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans:  'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;

  /* Type scale (fluid-ish, fixed here for clarity) */
  --t-display: 2.75rem;   /* 44 */
  --t-h1: 2.125rem;       /* 34 */
  --t-h2: 1.5rem;         /* 24 */
  --t-h3: 1.1875rem;      /* 19 */
  --t-lg: 1.0625rem;      /* 17 */
  --t-base: 1rem;         /* 16 */
  --t-sm: 0.875rem;       /* 14 */
  --t-xs: 0.75rem;        /* 12 */
  --reading: 1.1875rem;   /* article body */
  /* Titres du corps d'article : échelle modulaire ~tierce mineure (×1.2) sur --reading,
     pour des niveaux discernables à l'œil (un h3 à +1px du corps ne l'était pas). */
  --reading-h1: 2.0625rem; /* 33 */
  --reading-h2: 1.75rem;   /* 28 */
  --reading-h3: 1.4375rem; /* 23 */

  /* Spacing */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px; --s-9: 96px;

  /* Radius */
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-xl: 22px; --r-pill: 999px;

  /* Motion */
  --ease: cubic-bezier(.2, .6, .2, 1);
  --dur: 160ms;

  /* Layout */
  --measure: 38rem;       /* ideal reading width */

  /* Valeurs sombres — déclarées une seule fois ici, consommées par le thème
     sombre explicite ([data-theme="dark"]) ET par le repli système du site
     public (@media prefers-color-scheme). Le rendu public n'exécute aucun JS
     (CSP script-src 'none' en prod) : la bascule sombre y est purement CSS. */
  --d-paper:#101216; --d-surface:#181B21; --d-surface-2:#21252D; --d-surface-3:#2B303A;
  --d-ink:#E7E9EC; --d-ink-2:#A2A8B2; --d-ink-3:#969CA7;
  --d-field-border:#737985;
  --d-line:#262A32; --d-line-2:#373D47;
  --d-focus:#7AA2F7;
  --d-ok:#5FC18C; --d-ok-soft:#14231B; --d-warn:#D6A24C; --d-warn-soft:#272013; --d-danger:#E5827A; --d-danger-soft:#281615;
  --d-ch-web:#A2A8B2; --d-ch-rss:#E0883F; --d-ch-ap:#9B8DF0; --d-ch-api:#5FC18C;
  --d-shadow-1:0 1px 2px rgba(0,0,0,.45);
  --d-shadow-2:0 4px 16px rgba(0,0,0,.55);
  --d-shadow-3:0 20px 52px rgba(0,0,0,.65), 0 4px 12px rgba(0,0,0,.5);
}

/* ---- Light (default) ---------------------------------------------------- */
:root, [data-theme="light"] {
  color-scheme: light;
  --paper:      #FFFFFF;
  --surface:    #FFFFFF;
  --surface-2:  #F4F5F6;
  --surface-3:  #E9EBED;

  --ink:        #16181D;
  --ink-2:      #565B63;
  /* --ink-3 : texte discret, ≥ 4,5:1 (RGAA 3.2) sur --paper, --surface,
     --surface-2, --surface-3 et sur les fonds teintés (--accent-soft des 6
     accents, --ok/--warn/--danger-soft), min mesuré 4,68:1. #666B74 passait
     sous 4,5 sur --danger-soft et --surface-3. Seuils verrouillés par
     tests/Unit/Assets/ContrastTokensTest.php. */
  --ink-3:      #62666E;
  --field-border:#80868F;    /* bord des champs : ≥ 3:1 (RGAA 3.3, WCAG 1.4.11) */

  --line:       #E6E8EB;
  --line-2:     #D2D6DB;

  --accent:     #1D3D73;
  --accent-hover:#15305C;
  --accent-ink: #FFFFFF;     /* text on accent */
  --accent-soft:#E8EDF5;
  --accent-line:#C2CFE3;

  --focus:      #1D63D8;     /* high-visibility focus ring */

  --ok:         #1E6B47;  --ok-soft:#E4F1EA;
  --warn:       #8A5A0B;  --warn-soft:#F7ECD7;
  --danger:     #A52A26;  --danger-soft:#F8E3E1;

  /* channels */
  --ch-web:     #565B63;
  --ch-rss:     #B85B12;
  --ch-ap:      #4940A8;
  --ch-api:     #1E6B47;

  --shadow-1: 0 1px 2px rgba(16,18,23,.05), 0 1px 1px rgba(16,18,23,.04);
  --shadow-2: 0 4px 14px rgba(16,18,23,.07), 0 1px 3px rgba(16,18,23,.05);
  --shadow-3: 0 18px 48px rgba(16,18,23,.14), 0 4px 12px rgba(16,18,23,.07);
}

/* ---- Dark --------------------------------------------------------------- */
[data-theme="dark"] {
  color-scheme: dark;
  --paper: var(--d-paper);
  --surface: var(--d-surface);
  --surface-2: var(--d-surface-2);
  --surface-3: var(--d-surface-3);

  --ink: var(--d-ink);
  --ink-2: var(--d-ink-2);
  --ink-3: var(--d-ink-3);
  --field-border: var(--d-field-border);

  --line: var(--d-line);
  --line-2: var(--d-line-2);

  /* Accent par défaut (encre sombre) — repli si data-accent absent ; les 6
     accents redéfinissent la famille plus bas. */
  --accent:     #7FA8E8;
  --accent-hover:#9ABDF0;
  --accent-ink: #0C1422;
  --accent-soft:#1A2333;
  --accent-line:#2E3C56;

  --focus: var(--d-focus);

  --ok: var(--d-ok);  --ok-soft: var(--d-ok-soft);
  --warn: var(--d-warn);  --warn-soft: var(--d-warn-soft);
  --danger: var(--d-danger);  --danger-soft: var(--d-danger-soft);

  --ch-web: var(--d-ch-web);
  --ch-rss: var(--d-ch-rss);
  --ch-ap: var(--d-ch-ap);
  --ch-api: var(--d-ch-api);

  --shadow-1: var(--d-shadow-1);
  --shadow-2: var(--d-shadow-2);
  --shadow-3: var(--d-shadow-3);
}

/* Repli système pour les pages SANS sélecteur de thème (site public) : pas une
   ligne de JS (CSP script-src 'none' en prod), on suit prefers-color-scheme.
   L'attribut data-theme, quand il est présent (back-office, espace user),
   l'emporte : ces sélecteurs ne matchent que :root:not([data-theme]). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --paper: var(--d-paper);
    --surface: var(--d-surface);
    --surface-2: var(--d-surface-2);
    --surface-3: var(--d-surface-3);

    --ink: var(--d-ink);
    --ink-2: var(--d-ink-2);
    --ink-3: var(--d-ink-3);
    --field-border: var(--d-field-border);

    --line: var(--d-line);
    --line-2: var(--d-line-2);

    --focus: var(--d-focus);

    --ok: var(--d-ok);  --ok-soft: var(--d-ok-soft);
    --warn: var(--d-warn);  --warn-soft: var(--d-warn-soft);
    --danger: var(--d-danger);  --danger-soft: var(--d-danger-soft);

    --ch-web: var(--d-ch-web);
    --ch-rss: var(--d-ch-rss);
    --ch-ap: var(--d-ch-ap);
    --ch-api: var(--d-ch-api);

    --shadow-1: var(--d-shadow-1);
    --shadow-2: var(--d-shadow-2);
    --shadow-3: var(--d-shadow-3);
  }
}

/* =========================================================================
   BASE / RESET
   ========================================================================= */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: .08em; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }

/* ---- Accessibility: focus, reduced motion, skip link ------------------- */
:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
.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: var(--s-3); top: -3rem; z-index: 100;
  background: var(--surface); color: var(--ink); border: 1px solid var(--field-border);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md); box-shadow: var(--shadow-2);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--s-3); }

/* =========================================================================
   TYPOGRAPHY HELPERS
   ========================================================================= */
.serif { font-family: var(--font-serif); }
.mono  { font-family: var(--font-mono); }
.t-display { font-family: var(--font-serif); font-size: var(--t-display); line-height: 1.08; letter-spacing: -.02em; }
.t-h1 { font-family: var(--font-serif); font-size: var(--t-h1); line-height: 1.14; }
.t-h2 { font-size: var(--t-h2); }
.t-h3 { font-size: var(--t-h3); }
.eyebrow {
  font-family: var(--font-mono); font-size: var(--t-xs); letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 500;
}
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }

/* =========================================================================
   BUTTONS
   ========================================================================= */
.btn {
  font-family: var(--font-sans); font-size: var(--t-sm); font-weight: 600;
  line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2); min-height: 44px; padding: 0 var(--s-5);
  border-radius: var(--r-md); border: 1px solid transparent; cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); font-size: var(--t-xs); border-radius: var(--r-sm); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* =========================================================================
   FORM FIELDS
   ========================================================================= */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field label { font-size: var(--t-sm); font-weight: 600; color: var(--ink); }
.field .hint { font-size: var(--t-xs); color: var(--ink-2); }
.input, .textarea, .select {
  font-family: var(--font-sans); font-size: var(--t-base); color: var(--ink);
  background: var(--surface); border: 1px solid var(--field-border); border-radius: var(--r-md);
  padding: 11px var(--s-3); min-height: 44px; width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 28%, transparent);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field.error .input, .field.error .textarea { border-color: var(--danger); }
.field.error .msg { color: var(--danger); font-size: var(--t-xs); display: flex; gap: var(--s-1); align-items: center; }

/* =========================================================================
   TAGS / BADGES / CHANNELS
   ========================================================================= */
.tag {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-xs); font-weight: 500; line-height: 1;
  padding: 6px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.tag .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.chan {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: var(--t-xs); font-weight: 500; line-height: 1;
  padding: 6px 11px 6px 9px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
}
.chan .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chan[data-ch="web"] .dot { background: var(--ch-web); }
.chan[data-ch="rss"] .dot { background: var(--ch-rss); }
.chan[data-ch="ap"]  .dot { background: var(--ch-ap); }
.chan[data-ch="api"] .dot { background: var(--ch-api); }
.chan.solid[data-ch="web"] { color: var(--ch-web); border-color: color-mix(in oklab, var(--ch-web) 35%, transparent); }
.chan.solid[data-ch="rss"] { color: var(--ch-rss); border-color: color-mix(in oklab, var(--ch-rss) 35%, transparent); }
.chan.solid[data-ch="ap"]  { color: var(--ch-ap);  border-color: color-mix(in oklab, var(--ch-ap) 35%, transparent); }
.chan.solid[data-ch="api"] { color: var(--ch-api); border-color: color-mix(in oklab, var(--ch-api) 35%, transparent); }

.status {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-xs); font-weight: 600; line-height: 1; padding: 5px 10px; border-radius: var(--r-sm);
}
.status.published { background: var(--ok-soft); color: var(--ok); }
.status.draft { background: var(--surface-2); color: var(--ink-2); }
.status.scheduled { background: var(--warn-soft); color: var(--warn); }

/* =========================================================================
   CARDS / SURFACES
   ========================================================================= */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.notice {
  display: flex; gap: var(--s-3); padding: var(--s-4); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface-2); font-size: var(--t-sm);
}
.notice .bar { width: 3px; border-radius: 3px; flex: none; align-self: stretch; }
.notice.info .bar { background: var(--accent); }
.notice.ok .bar { background: var(--ok); }
.notice.warn .bar { background: var(--warn); }

/* =========================================================================
   SHOWCASE PAGE CHROME (not part of the product DS itself)
   ========================================================================= */
.page { max-width: 1080px; margin: 0 auto; padding: 0 var(--s-5); }
.topbar {
  position: sticky; top: 0; z-index: 30; backdrop-filter: blur(10px);
  background: color-mix(in oklab, var(--paper) 86%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar .row { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.wordmark { display: flex; align-items: center; gap: var(--s-3); font-weight: 700; letter-spacing: -.01em; font-size: var(--t-lg); }
.wordmark .glyph {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
}
/* Logomark — SVG K, géométriquement centré (remplace le glyphe texte) */
.glyph svg, .kx-mark svg { width: 58%; height: 58%; display: block; }
.kx-mark {
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
  border-radius: 22%; aspect-ratio: 1;
}
.theme-toggle {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: 40px; padding: 0 var(--s-3);
  background: var(--surface); border: 1px solid var(--field-border); border-radius: var(--r-pill);
  color: var(--ink); font-size: var(--t-sm); font-weight: 500; cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); }

.section { padding: var(--s-8) 0; border-top: 1px solid var(--line); }
.section:first-of-type { border-top: 0; }
.section-head { margin-bottom: var(--s-6); }
.section-head .eyebrow { margin-bottom: var(--s-2); display: block; }

.grid { display: grid; gap: var(--s-5); }
.swatch { border-radius: var(--r-md); border: 1px solid var(--line); overflow: hidden; box-shadow: var(--shadow-1); }
.swatch .chip { height: 72px; }
.swatch .meta { padding: 10px var(--s-3); background: var(--surface); font-size: var(--t-xs); display: flex; justify-content: space-between; align-items: center; }
.swatch .meta .hex { font-family: var(--font-mono); color: var(--ink-2); }

.spec-row { display: grid; grid-template-columns: 130px 1fr; gap: var(--s-5); align-items: baseline; padding: var(--s-4) 0; border-top: 1px dashed var(--line-2); }
.spec-row:first-child { border-top: 0; }
.spec-row .label { font-family: var(--font-mono); font-size: var(--t-xs); color: var(--ink-3); }

.demo-row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.demo-grid { display: grid; gap: var(--s-5); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* =========================================================================
   ACCENT — palette sélectionnable (data-accent sur <html>)
   Chaque accent redéfinit la famille --accent pour les thèmes clair & sombre.
   Le focus reste un bleu dédié (RGAA) indépendant de l'accent.
   ========================================================================= */
[data-accent="encre"]    { --accent:#1D3D73; --accent-hover:#15305C; --accent-ink:#fff; --accent-soft:#E8EDF5; --accent-line:#C2CFE3;
                           --da-accent:#7FA8E8; --da-accent-hover:#9ABDF0; --da-accent-ink:#0C1422; --da-accent-soft:#1A2333; --da-accent-line:#2E3C56; }
[data-accent="bordeaux"] { --accent:#9A2D2D; --accent-hover:#7E2222; --accent-ink:#fff; --accent-soft:#F6E5E5; --accent-line:#E4C2C2;
                           --da-accent:#E58B86; --da-accent-hover:#EDA39E; --da-accent-ink:#2A0E0C; --da-accent-soft:#2A1614; --da-accent-line:#4A2521; }
[data-accent="foret"]    { --accent:#1F6A4A; --accent-hover:#18553B; --accent-ink:#fff; --accent-soft:#E3F0EA; --accent-line:#BCD8CB;
                           --da-accent:#5FC191; --da-accent-hover:#7CCFA6; --da-accent-ink:#08160F; --da-accent-soft:#14241B; --da-accent-line:#244534; }
[data-accent="prune"]    { --accent:#6A3A86; --accent-hover:#552E6C; --accent-ink:#fff; --accent-soft:#F0E8F5; --accent-line:#D6C2E2;
                           --da-accent:#C89BE0; --da-accent-hover:#D4B0E8; --da-accent-ink:#1A0E22; --da-accent-soft:#221630; --da-accent-line:#3C2A4E; }
[data-accent="rouille"]  { --accent:#A8482A; --accent-hover:#8C3A21; --accent-ink:#fff; --accent-soft:#F6E7DF; --accent-line:#E6C8B9;
                           --da-accent:#E0916A; --da-accent-hover:#E9A684; --da-accent-ink:#220F07; --da-accent-soft:#2A1A12; --da-accent-line:#4A3122; }
[data-accent="graphite"] { --accent:#2A2E35; --accent-hover:#16181D; --accent-ink:#fff; --accent-soft:#ECEDEF; --accent-line:#D2D6DB;
                           --da-accent:#D6DAE0; --da-accent-hover:#E7E9EC; --da-accent-ink:#14161A; --da-accent-soft:#21252D; --da-accent-line:#373D47; }

/* Bascule des accents en contexte sombre — une seule règle au lieu de six :
   chaque accent a défini sa variante sombre --da-* ci-dessus. Spécificité (0,2,0)
   pour l'attribut / (0,3,0) pour la media : l'emporte sur la famille claire
   [data-accent] (0,1,0), quel que soit l'ordre. S'applique au thème sombre
   explicite ET au repli système public. */
[data-theme="dark"][data-accent] {
  --accent: var(--da-accent); --accent-hover: var(--da-accent-hover); --accent-ink: var(--da-accent-ink);
  --accent-soft: var(--da-accent-soft); --accent-line: var(--da-accent-line);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme])[data-accent] {
    --accent: var(--da-accent); --accent-hover: var(--da-accent-hover); --accent-ink: var(--da-accent-ink);
    --accent-soft: var(--da-accent-soft); --accent-line: var(--da-accent-line);
  }
}

/* Picker d'accent (chrome de revue) */
.accent-picker { display: inline-flex; align-items: center; gap: 6px; }
.accent-picker .sw {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; padding: 0; position: relative;
  transition: transform var(--dur) var(--ease);
}
.accent-picker .sw:hover { transform: scale(1.12); }
.accent-picker .sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px currentColor; }
.accent-picker .sw[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 7px; height: 7px;
  border-radius: 50%; background: #fff; mix-blend-mode: difference;
}
