/* =============================================================================
 *  theme.css — feuille de style commune Neoludis (TD-205, refonte visuelle 1/2)
 *
 *  Trois thèmes, choisis par chaque utilisateur (menu du bas de la barre
 *  latérale), « Plateau de jeu » par défaut :
 *    html[data-theme="plateau"]  Plateau de jeu  — clair, menu sombre, pions
 *    html[data-theme="atelier"]  Atelier sombre  — sombre, chaud
 *    html[data-theme="clair"]    Clair éditorial — clair, serif pour les titres
 *  Valeurs reprises des maquettes validées (canvas « Neoludis App — refonte
 *  visuelle (fiche client) », 05/10).
 *
 *  1. Jetons (variables) par thème : couleurs, statuts, typo, rayons, ombres.
 *  2. Compatibilité : les anciens noms (--bg, --surface, --accent, --font…)
 *     redéfinis depuis les jetons. --font est désormais la police de TEXTE ;
 *     la chasse fixe est réservée aux références (--font-mono, .neo-mono).
 *  3. Composants communs (classes neo-*).
 *  4. Notifications (NeoApp.toast) et confirmation (NeoApp.confirmer).
 *
 *  Chargée dans le <head> de chaque page (avec /shared/theme.js qui pose
 *  data-theme avant le premier affichage), et à défaut par layout.js.
 *  Les sélecteurs html[data-theme] l'emportent sur un :root de page.
 * ===========================================================================*/

/* ─── 1. Jetons ─────────────────────────────────────────────────────────────── */

/* Échelle commune */
:root {
  --esp-1: 4px; --esp-2: 8px; --esp-3: 12px; --esp-4: 16px; --esp-5: 24px; --esp-6: 32px;
  --hauteur-btn: 42px;
  --transition: 0.15s ease;
}

/* Plateau de jeu (défaut) — maquette C */
html[data-theme="plateau"], html:not([data-theme]) {
  color-scheme: light;
  --c-fond: #eef1f7;
  --c-fond-2: #e6eaf3;
  --c-surface: #ffffff;
  --c-surface-2: #f5f7fc;
  --c-surface-3: #e8edf8;
  --c-bordure: #dde2ec;
  --c-bordure-forte: #c9d0de;
  --c-texte: #1b2233;
  --c-texte-fort: #111827;
  --c-texte-2: #5a6480;
  --c-texte-3: #5f6985;
  --c-accent: #e0424f;
  --c-accent-fort: #c7323f;
  --c-accent-clair: #ec6a75;
  --c-accent-texte: #ffffff;
  --c-accent-rgb: 224, 66, 79;
  --c-lien: #2a55c4;
  --c-lien-survol: #1b3d96;
  --c-focus: #3d6fd9;
  /* Les quatre pions */
  --pion-bleu: #3d6fd9; --pion-jaune: #f2b632; --pion-vert: #2f9e6e; --pion-rouge: #e0424f;
  /* Statuts : texte / fond pâle */
  --s-info: #2a55c4;       --s-info-fond: #dbe5fb;
  --s-attention: #7a5300;  --s-attention-fond: #fdeec6;
  --s-succes: #1d6b49;     --s-succes-fond: #d8f2e6;
  --s-danger: #a11e2c;     --s-danger-fond: #fde8ea;
  /* Barre latérale */
  --menu-fond: #1b2233; --menu-bordure: #1b2233; --menu-texte: #b9c3d9; --menu-texte-fort: #ffffff;
  --menu-section: #8d98b3; --menu-survol: #263049; --menu-actif-fond: #f2b632; --menu-actif-texte: #1b2233;
  /* Typo */
  --font-titre: 'Bricolage Grotesque', 'Figtree', system-ui, sans-serif;
  --font-texte: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --poids-titre: 800;
  /* Formes */
  --r-sm: 12px; --r-md: 14px; --r-lg: 20px; --r-xl: 22px; --r-pill: 999px;
  --ombre-1: 0 1px 0 #dde2ec;
  --ombre-2: 0 8px 24px rgba(27, 34, 51, 0.12);
  --ombre-3: 0 18px 48px rgba(27, 34, 51, 0.22);
  --voile: rgba(27, 34, 51, 0.55);
  /* Compatibilité : couleurs « vives » des anciennes pages, lisibles sur fond clair */
  --compat-vert: #1f8a5c; --compat-bleu: #2f62cf; --compat-rouge: #d23542;
  --compat-jaune: #946a00; --compat-orange: #b45309; --compat-violet: #7048c4;
}

/* Atelier sombre — maquette A */
html[data-theme="atelier"] {
  color-scheme: dark;
  --c-fond: #15130f;
  --c-fond-2: #1a1813;
  --c-surface: #1e1b16;
  --c-surface-2: #221e18;
  --c-surface-3: #2a251d;
  --c-bordure: #2c2820;
  --c-bordure-forte: #3a342a;
  --c-texte: #ece6dc;
  --c-texte-fort: #fbf6ee;
  --c-texte-2: #a89f91;
  --c-texte-3: #8f877a;
  --c-accent: #e0424f;
  --c-accent-fort: #c7323f;
  --c-accent-clair: #ec6a75;
  --c-accent-texte: #ffffff;
  --c-accent-rgb: 224, 66, 79;
  --c-lien: #f2b6a0;
  --c-lien-survol: #ffd3c2;
  --c-focus: #9cc3f5;
  --pion-bleu: #6a9cf0; --pion-jaune: #e8c58a; --pion-vert: #4cb88a; --pion-rouge: #ec5f69;
  --s-info: #9cc3f5;       --s-info-fond: #1b2a3d;
  --s-attention: #e8c58a;  --s-attention-fond: #3a2e18;
  --s-succes: #8fd3b4;     --s-succes-fond: #16332a;
  --s-danger: #f2a6a0;     --s-danger-fond: #3a1d1d;
  --menu-fond: #1c1914; --menu-bordure: #2c2820; --menu-texte: #c9c1b4; --menu-texte-fort: #ffffff;
  --menu-section: #8f877a; --menu-survol: #26221b; --menu-actif-fond: #2e2820; --menu-actif-texte: #ffffff;
  --font-titre: 'IBM Plex Sans', system-ui, sans-serif;
  --font-texte: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --poids-titre: 700;
  --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-xl: 14px; --r-pill: 999px;
  --ombre-1: none;
  --ombre-2: 0 8px 24px rgba(0, 0, 0, 0.35);
  --ombre-3: 0 18px 48px rgba(0, 0, 0, 0.55);
  --voile: rgba(0, 0, 0, 0.6);
  --compat-vert: #4cb88a; --compat-bleu: #6a9cf0; --compat-rouge: #ec5f69;
  --compat-jaune: #e8c58a; --compat-orange: #e8a35a; --compat-violet: #b39ddb;
}

/* Clair éditorial — maquette B */
html[data-theme="clair"] {
  color-scheme: light;
  --c-fond: #f6f4f0;
  --c-fond-2: #efece6;
  --c-surface: #ffffff;
  --c-surface-2: #faf8f5;
  --c-surface-3: #eeeae3;
  --c-bordure: #e6e1d8;
  --c-bordure-forte: #d9d2c6;
  --c-texte: #22201c;
  --c-texte-fort: #14120f;
  --c-texte-2: #5d574d;
  --c-texte-3: #6f685d;
  --c-accent: #b42a37;
  --c-accent-fort: #8c1f2a;
  --c-accent-clair: #c94a56;
  --c-accent-texte: #ffffff;
  --c-accent-rgb: 180, 42, 55;
  --c-lien: #b42a37;
  --c-lien-survol: #8c1f2a;
  --c-focus: #2f6fd1;
  --pion-bleu: #2f6fd1; --pion-jaune: #c98a0b; --pion-vert: #2a8a5e; --pion-rouge: #b42a37;
  --s-info: #1d4f9c;       --s-info-fond: #e3ecfa;
  --s-attention: #6b4e12;  --s-attention-fond: #f8ecd2;
  --s-succes: #1f6b4a;     --s-succes-fond: #e3f2ea;
  --s-danger: #8c1f2a;     --s-danger-fond: #f8e3e5;
  --menu-fond: #ffffff; --menu-bordure: #e6e1d8; --menu-texte: #5d574d; --menu-texte-fort: #22201c;
  --menu-section: #6f685d; --menu-survol: #f6f4f0; --menu-actif-fond: #f3ece4; --menu-actif-texte: #22201c;
  --font-titre: 'Source Serif 4', Georgia, serif;
  --font-texte: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Source Code Pro', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --poids-titre: 700;
  --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-xl: 14px; --r-pill: 999px;
  --ombre-1: none;
  --ombre-2: 0 8px 24px rgba(34, 32, 28, 0.10);
  --ombre-3: 0 18px 48px rgba(34, 32, 28, 0.20);
  --voile: rgba(34, 32, 28, 0.45);
  --compat-vert: #1f7a52; --compat-bleu: #2f6fd1; --compat-rouge: #b42a37;
  --compat-jaune: #8a5a00; --compat-orange: #a4500e; --compat-violet: #6b4bb8;
}

/* ─── #744 : tableau long qui défile DANS sa carte ───────────────────────────────
   À poser sur le conteneur du tableau (pas sur toute la carte) : les barres de
   défilement verticale ET horizontale restent à l'écran, l'en-tête reste figé en
   haut. --neo-defile-marge : la hauteur laissée au-dessus (barre de titre, filtres),
   réglable par page. Fond de l'en-tête : la surface du thème (clair et sombre). */
.neo-defile { overflow: auto; max-height: calc(100vh - var(--neo-defile-marge, 160px)); }
/* Spécificité nulle (:where) : la couleur d'en-tête propre à une page l'emporte. */
:where(.neo-defile > table > thead th) { position: sticky; top: calc(-1 * var(--neo-defile-pad, 0px)); z-index: 1; background: var(--c-surface); }
/* Une carte (.neo-carte, 20 px de marge intérieure) : l'en-tête remonte jusqu'au bord, sinon les lignes
   défileraient visibles au-dessus de lui, dans la marge. */
.neo-carte.neo-defile { --neo-defile-pad: 20px; }
@media print { .neo-defile { overflow: visible; max-height: none; } }

/* ─── 2. Compatibilité avec les anciennes pages ─────────────────────────────── */
/* Les pages lisaient ces noms dans leur propre :root (retiré par
   migrer_theme_pages.mjs) : ils pointent désormais sur les jetons du thème. */
html[data-theme], html:not([data-theme]) {
  --bg: var(--c-fond);
  --bg2: var(--c-fond-2);
  --bg3: var(--c-surface-3);
  --surface: var(--c-surface);
  --surface2: var(--c-surface-2);
  --surface3: var(--c-surface-3);
  --border: var(--c-bordure);
  --text: var(--c-texte);
  --muted: var(--c-texte-2);
  --soft: var(--c-texte-3);
  --grey: var(--c-texte-3);
  --accent: var(--c-accent);
  --accent-dark: var(--c-accent-fort);
  --accent-light: var(--c-accent-clair);
  --accent-rgb: var(--c-accent-rgb);
  --green: var(--compat-vert);
  --blue: var(--compat-bleu);
  --red: var(--compat-rouge);
  --yellow: var(--compat-jaune);
  --amber: var(--compat-jaune);
  --orange: var(--compat-orange);
  --purple: var(--compat-violet);
  --violet: var(--compat-violet);
  --font: var(--font-texte);
  --font-ui: var(--font-texte);
  --mono: var(--font-mono);
  --radius: var(--r-md);
  /* Alias de l'accueil, de la fiche article, de la fiche client et du document */
  --dark: var(--c-fond);
  --dark2: var(--c-surface);
  --red2: var(--c-accent-fort);
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--c-fond);
  color: var(--c-texte);
  font-family: var(--font-texte);
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--c-lien); }
a:hover { color: var(--c-lien-survol); }
:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.neo-mono, code, kbd, samp { font-family: var(--font-mono); }
.neo-titre { font-family: var(--font-titre); font-weight: var(--poids-titre); letter-spacing: -0.01em; }
.neo-chiffre { font-variant-numeric: tabular-nums; }

/* ─── 3. Composants communs ─────────────────────────────────────────────────── */

/* Boutons */
.neo-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--esp-2);
  min-height: var(--hauteur-btn); padding: 0 var(--esp-4);
  border-radius: var(--r-md); border: 1px solid var(--c-bordure-forte);
  background: var(--c-surface-2); color: var(--c-texte);
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer;
  text-decoration: none; transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.neo-btn:hover:not(:disabled) { border-color: var(--c-texte-3); }
.neo-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.neo-btn--principal { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-accent-texte); }
.neo-btn--principal:hover:not(:disabled) { background: var(--c-accent-fort); border-color: var(--c-accent-fort); color: var(--c-accent-texte); }
/* #562 : « --primaire », employé par plusieurs écrans, n'existait pas (boutons pâles). Alias du bouton plein,
   en accent foncé : le texte blanc garde le contraste AA (sur l'accent clair, 4,1:1 seulement). */
.neo-btn--primaire { background: var(--c-accent-fort); border-color: var(--c-accent-fort); color: var(--c-accent-texte); }
.neo-btn--primaire:hover:not(:disabled) { filter: brightness(0.9); color: var(--c-accent-texte); }
.neo-btn--secondaire { background: var(--c-surface-3); border-color: transparent; }
html[data-theme="atelier"] .neo-btn--secondaire, html[data-theme="clair"] .neo-btn--secondaire { background: var(--c-surface); border-color: var(--c-bordure-forte); }
.neo-btn--discret { background: transparent; border-color: transparent; color: var(--c-lien); }
.neo-btn--discret:hover:not(:disabled) { background: var(--c-surface-3); border-color: transparent; }
.neo-btn--danger { background: var(--s-danger); border-color: var(--s-danger); color: #fff; }
html[data-theme="atelier"] .neo-btn--danger { background: #c7323f; border-color: #c7323f; }
.neo-btn--danger:hover:not(:disabled) { filter: brightness(0.92); }
.neo-btn--icone { width: var(--hauteur-btn); padding: 0; }

/* Carte */
.neo-carte {
  background: var(--c-surface); border: 1px solid var(--c-bordure);
  border-radius: var(--r-xl); padding: 20px 22px; box-shadow: var(--ombre-1);
}
html[data-theme="plateau"] .neo-carte, html:not([data-theme]) .neo-carte { border-color: transparent; }
.neo-carte > h2, .neo-carte__titre { margin: 0 0 var(--esp-3); font-family: var(--font-titre); font-weight: var(--poids-titre); font-size: 18px; }

/* Badges de statut */
.neo-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 600; line-height: 1.4; white-space: nowrap;
  background: var(--c-surface-3); color: var(--c-texte-2);
}
.neo-badge--info      { background: var(--s-info-fond);      color: var(--s-info); }
.neo-badge--attention { background: var(--s-attention-fond); color: var(--s-attention); }
.neo-badge--succes    { background: var(--s-succes-fond);    color: var(--s-succes); }
.neo-badge--danger    { background: var(--s-danger-fond);    color: var(--s-danger); }

/* Tableau */
.neo-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.neo-table th {
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--c-texte-2);
  padding: 9px 12px; border-bottom: 1px solid var(--c-bordure); white-space: nowrap;
}
.neo-table td { padding: 11px 12px; border-bottom: 1px solid var(--c-bordure); vertical-align: middle; }
.neo-table tbody tr:last-child td { border-bottom: none; }
.neo-table tbody tr:hover td { background: var(--c-surface-2); }
.neo-table .num, .neo-table td.num, .neo-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.neo-table-boite { overflow-x: auto; }

/* Onglets */
.neo-onglets { display: flex; flex-wrap: wrap; gap: var(--esp-1); border-bottom: 1px solid var(--c-bordure); }
.neo-onglet {
  min-height: 42px; padding: 0 14px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--c-texte-2); font: inherit; cursor: pointer;
}
.neo-onglet[aria-selected="true"], .neo-onglet.actif { color: var(--c-texte-fort); font-weight: 700; border-bottom-color: var(--c-accent); }
html[data-theme="plateau"] .neo-onglets, html:not([data-theme]) .neo-onglets { border-bottom: none; gap: var(--esp-2); }
html[data-theme="plateau"] .neo-onglet, html:not([data-theme]) .neo-onglet { border: none; border-radius: var(--r-pill); background: var(--c-surface); color: var(--c-texte); padding: 0 16px; }
html[data-theme="plateau"] .neo-onglet[aria-selected="true"], html[data-theme="plateau"] .neo-onglet.actif,
html:not([data-theme]) .neo-onglet[aria-selected="true"], html:not([data-theme]) .neo-onglet.actif { background: var(--menu-fond); color: #fff; }

/* Champs */
.neo-label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--c-texte-2); }
.neo-champ {
  min-height: var(--hauteur-btn); padding: 0 12px; box-sizing: border-box;
  background: var(--c-surface); color: var(--c-texte);
  border: 1px solid var(--c-bordure-forte); border-radius: var(--r-sm);
  font: inherit; font-size: 15px;
}
textarea.neo-champ { padding: 10px 12px; min-height: 90px; }
.neo-champ:focus { outline: none; border-color: var(--c-focus); box-shadow: 0 0 0 3px rgba(61, 111, 217, 0.18); }

/* Fenêtre modale (générique) */
.neo-modale-fond {
  position: fixed; inset: 0; z-index: 100002; background: var(--voile);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.neo-modale {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--c-surface); color: var(--c-texte);
  border: 1px solid var(--c-bordure); border-radius: var(--r-xl); box-shadow: var(--ombre-3);
  padding: 22px 24px; display: flex; flex-direction: column; gap: 14px;
  font-family: var(--font-texte);
}
.neo-modale__titre { margin: 0; font-family: var(--font-titre); font-weight: var(--poids-titre); font-size: 19px; color: var(--c-texte-fort); }
.neo-modale__message { margin: 0; font-size: 15px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.neo-modale__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--esp-2); margin-top: 4px; }

/* État vide, chargement */
.neo-vide { padding: 32px 16px; text-align: center; color: var(--c-texte-2); }
.neo-vide strong { display: block; color: var(--c-texte); font-size: 16px; margin-bottom: 4px; }
.neo-chargement { display: inline-flex; align-items: center; gap: 10px; color: var(--c-texte-2); }
.neo-chargement::before {
  content: ''; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--c-bordure-forte); border-top-color: var(--c-accent);
  animation: neo-tourne 0.8s linear infinite;
}
@keyframes neo-tourne { to { transform: rotate(360deg); } }

/* Chiffre clé (KPI) */
.neo-kpi {
  background: var(--c-surface); border: 1px solid var(--c-bordure); border-radius: var(--r-lg);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--ombre-1);
}
html[data-theme="plateau"] .neo-kpi, html:not([data-theme]) .neo-kpi { border-color: transparent; }
.neo-kpi__libelle { font-size: 13px; color: var(--c-texte-2); }
.neo-kpi__valeur { font-family: var(--font-titre); font-weight: var(--poids-titre); font-size: 28px; font-variant-numeric: tabular-nums; color: var(--c-texte-fort); }
.neo-kpi__detail { font-size: 13px; color: var(--c-texte-2); }

/* ─── 4. Notifications (NeoApp.toast) ──────────────────────────────────────── */
/* En bas à GAUCHE de la zone de contenu (TD-212) : les tiroirs et leurs boutons
   (Annuler / Enregistrer…) sont à droite dans toute l'app, une notification en
   bas à droite les recouvrait au moment de cliquer. À droite de la barre
   latérale (232 px) quand elle est là, sinon au bord gauche de l'écran. */
.neo-toasts {
  position: fixed; left: 16px; bottom: 16px; z-index: 100001;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  max-width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
body.neo-shell-active .neo-toasts { left: calc(232px + 16px); max-width: min(440px, calc(100vw - 232px - 32px)); }
@media (max-width: 899px) { body.neo-shell-active .neo-toasts { left: 16px; max-width: calc(100vw - 32px); } }   /* #562 : menu en tiroir */
.neo-toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 12px 12px 16px; border-radius: var(--r-lg);
  background: var(--menu-fond); color: #fff; box-shadow: var(--ombre-2);
  font-family: var(--font-texte); font-size: 14.5px; line-height: 1.45;
  border: 1px solid transparent; animation: neo-toast-entree 0.18s ease-out;
}
html[data-theme="clair"] .neo-toast { background: var(--c-texte); }
.neo-toast__pion { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; margin-top: 1px;
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; color: #fff; }
.neo-toast--info      .neo-toast__pion { background: var(--pion-bleu); }
.neo-toast--succes    .neo-toast__pion { background: var(--pion-vert); }
.neo-toast--attention .neo-toast__pion { background: var(--pion-jaune); color: #1b2233; }
.neo-toast--erreur    .neo-toast__pion { background: var(--pion-rouge); }
.neo-toast__texte { flex: 1 1 auto; white-space: pre-line; overflow-wrap: anywhere; padding-top: 1px; }
.neo-toast__fermer {
  flex: 0 0 auto; width: 30px; height: 30px; margin: -4px -2px -4px 0; border-radius: 8px;
  border: none; background: transparent; color: inherit; opacity: 0.75; cursor: pointer; font-size: 16px; line-height: 1;
}
.neo-toast__fermer:hover { opacity: 1; background: rgba(255, 255, 255, 0.12); }
@keyframes neo-toast-entree { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .neo-toast, .neo-chargement::before { animation: none; } }
@media print { .neo-toasts, .neo-modale-fond { display: none !important; } }
