/* ==========================================================================
   Ardoise — Thèmes visuels
   --------------------------------------------------------------------------
   Un seul fichier pilote l'apparence des 21 pages de la plateforme.
   Chaque page conserve son bloc <style> d'origine (qui définit les valeurs
   par défaut) ; ce fichier les remplace grâce à une spécificité supérieure
   (html[data-theme="…"] l'emporte sur :root).

   AJOUTER UN NOUVEAU THÈME = ajouter un bloc ici, et une entrée dans la
   liste THEMES de theme.js. Aucune autre page n'est à modifier.

   VALEUR PARTICULIÈRE data-theme="public" : utilisée par index.html et
   connexion.html. Elle ne correspond à AUCUN bloc de couleurs ci-dessous,
   volontairement — ces deux pages définissent leur propre palette et ne
   doivent jamais être repeintes par un thème utilisateur. Seuls les jetons
   communs (polices, rayons) leur sont appliqués.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Jetons communs à tous les thèmes
   -------------------------------------------------------------------------- */
:root {
  --police-titre: 'Fraunces', Georgia, serif;
  --police-corps: 'Inter', system-ui, sans-serif;
  --police-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --r-carte: 10px;
  --r-bouton: 7px;
  --r-petit: 6px;
  --r-pilule: 20px;

  --ombre-carte: none;
  --ombre-flottante: 0 10px 30px rgba(31, 43, 36, 0.14);

  --bordure-epaisseur: 1px;
  --transition-base: 0.18s ease;

  /* Barre latérale — découplée des couleurs de contenu pour qu'un thème
     clair puisse avoir une barre claire sans rendre le texte illisible. */
  --nav-fond: #1F2B24;
  --nav-texte-fort: #F6F2E7;
  --nav-texte: rgba(246, 242, 231, 0.55);
  --nav-texte-faible: rgba(246, 242, 231, 0.35);
  --nav-actif-fond: rgba(246, 242, 231, 0.08);
  --nav-separateur: rgba(246, 242, 231, 0.12);
}

/* Respecte le réglage système « réduire les animations ». */
@media (prefers-reduced-motion: reduce) {
  :root { --transition-base: 0s; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   1. ARDOISE — thème par défaut (craie et ocre, chaleureux)
   ========================================================================== */
html[data-theme="ardoise"] {
  --ardoise: #1F2B24;
  --ardoise-2: #2A3830;
  --craie: #F6F2E7;
  --craie-2: #FBF9F3;
  --ocre: #C98A3E;
  --ocre-dark: #A96F2E;
  --ocre-clair: #E0AE6B;
  --encre: #3C5A62;
  --rouge: #B23A2E;
  --vert-ok: #4C7A5A;
  --texte-sombre: #1F2B24;
  --texte-att: #6B7269;
  --bordure: #E4DFCF;
  --ligne: #E4DFCF;
}

/* ==========================================================================
   2. PURE — fond blanc, angles nets, aucune ombre, un seul accent sobre.
      Densité administrative : la donnée avant la décoration.
   ========================================================================== */
html[data-theme="pure"] {
  --ardoise: #14171A;
  --ardoise-2: #22262B;
  --craie: #FFFFFF;
  --craie-2: #FFFFFF;
  --ocre: #2563A8;
  --ocre-dark: #1B4C84;
  --ocre-clair: #6BA3DC;
  --encre: #2563A8;
  --rouge: #C0392B;
  --vert-ok: #1E7A4D;
  --texte-sombre: #14171A;
  --texte-att: #6A7078;
  --bordure: #E6E7E9;
  --ligne: #EFEFF1;

  --police-titre: 'Inter', system-ui, sans-serif;
  --police-corps: 'Inter', system-ui, sans-serif;

  --r-carte: 3px;
  --r-bouton: 3px;
  --r-petit: 2px;
  --r-pilule: 3px;

  --ombre-carte: none;
  --ombre-flottante: 0 4px 20px rgba(20, 23, 26, 0.10);

  /* Barre latérale claire : c'est ce qui donne au thème son côté « page blanche ». */
  --nav-fond: #FAFAFA;
  --nav-texte-fort: #14171A;
  --nav-texte: #6A7078;
  --nav-texte-faible: #A3A8AE;
  --nav-actif-fond: #ECEFF3;
  --nav-separateur: #E6E7E9;
}

/* La barre latérale de Pure étant claire, elle a besoin d'un filet de séparation. */
html[data-theme="pure"] .barre-laterale {
  border-right: 1px solid var(--nav-separateur);
}
html[data-theme="pure"] .nav-item.actif {
  box-shadow: inset 2px 0 0 var(--ocre);
}
/* Titres en sans-serif : on rétablit une graisse lisible sans le serif. */
html[data-theme="pure"] h1,
html[data-theme="pure"] h2,
html[data-theme="pure"] h3 {
  letter-spacing: -0.015em;
  font-weight: 600;
}

/* ==========================================================================
   3. NUIT — thème sombre. Utile en fin de journée et sur écran OLED.
   ========================================================================== */
html[data-theme="nuit"] {
  --ardoise: #0C1013;
  --ardoise-2: #1B2226;
  --craie: #12171A;
  --craie-2: #1B2226;
  --ocre: #5FB08C;
  --ocre-dark: #4A9273;
  --ocre-clair: #86C9AB;
  --encre: #7FB4C4;
  --rouge: #E07A6E;
  --vert-ok: #5FB08C;
  --texte-sombre: #E8EDE9;
  --texte-att: #94A29C;
  --bordure: #2A3439;
  --ligne: #2A3439;

  --r-carte: 8px;
  --r-bouton: 8px;
  --r-petit: 6px;
  --r-pilule: 20px;

  --ombre-carte: none;
  --ombre-flottante: 0 12px 36px rgba(0, 0, 0, 0.55);

  --nav-fond: #0C1013;
  --nav-texte-fort: #E8EDE9;
  --nav-texte: #7C8A85;
  --nav-texte-faible: #5A6863;
  --nav-actif-fond: rgba(95, 176, 140, 0.14);
  --nav-separateur: #222B30;
}

/* En thème sombre, un texte blanc pur sur fond noir fatigue : on adoucit. */
html[data-theme="nuit"] body {
  -webkit-font-smoothing: antialiased;
}
html[data-theme="nuit"] .nav-item.actif {
  box-shadow: inset 2px 0 0 var(--ocre);
}
/* Les champs de formulaire natifs doivent suivre le thème sombre,
   sinon le navigateur les affiche en blanc éclatant. */
html[data-theme="nuit"] input,
html[data-theme="nuit"] select,
html[data-theme="nuit"] textarea {
  background: #0F1417;
  color: var(--texte-sombre);
  border-color: var(--bordure);
}
html[data-theme="nuit"] input::placeholder,
html[data-theme="nuit"] textarea::placeholder {
  color: var(--texte-att);
}
/* Indique au navigateur que la page est sombre (barres de défilement, etc.). */
html[data-theme="nuit"] { color-scheme: dark; }

/* ==========================================================================
   4. KIVU — expressif. Terracotta et vert profond, grands rayons,
      typographie généreuse. Le thème qui accueille les illustrations.
   ========================================================================== */
html[data-theme="kivu"] {
  --ardoise: #1E5B4F;
  --ardoise-2: #17483F;
  --craie: #FDF6EE;
  --craie-2: #FFFFFF;
  --ocre: #C2542F;
  --ocre-dark: #A34324;
  --ocre-clair: #E08B66;
  --encre: #1E5B4F;
  --rouge: #B3392C;
  --vert-ok: #1E5B4F;
  --texte-sombre: #26201B;
  --texte-att: #8A7A6B;
  --bordure: #EFE1D3;
  --ligne: #EFE1D3;

  --police-titre: 'Fraunces', Georgia, serif;

  --r-carte: 16px;
  --r-bouton: 14px;
  --r-petit: 10px;
  --r-pilule: 24px;

  --ombre-carte: 0 2px 10px rgba(38, 32, 27, 0.05);
  --ombre-flottante: 0 16px 44px rgba(38, 32, 27, 0.16);

  --nav-fond: #1E5B4F;
  --nav-texte-fort: #FDF6EE;
  --nav-texte: rgba(253, 246, 238, 0.62);
  --nav-texte-faible: rgba(253, 246, 238, 0.38);
  --nav-actif-fond: rgba(253, 246, 238, 0.13);
  --nav-separateur: rgba(253, 246, 238, 0.16);
}

/* Kivu respire davantage : barre latérale détachée du bord, coins arrondis. */
html[data-theme="kivu"] .barre-laterale {
  border-radius: 0 var(--r-carte) var(--r-carte) 0;
}
html[data-theme="kivu"] .carte-cours,
html[data-theme="kivu"] .carte-recap,
html[data-theme="kivu"] .carte-evenements,
html[data-theme="kivu"] .conteneur-tableau {
  box-shadow: var(--ombre-carte);
}
html[data-theme="kivu"] h1 {
  letter-spacing: -0.01em;
}

/* ==========================================================================
   Micro-animations communes (désactivées si le système le demande)
   ========================================================================== */
.nav-item { transition: background var(--transition-base), color var(--transition-base); }
.bouton { transition: background var(--transition-base), border-color var(--transition-base), transform var(--transition-base); }
.bouton:active { transform: scale(0.985); }

/* Apparition douce du contenu principal au chargement de chaque page.
   Exclut les pages publiques, qui ont leur propre mise en scene. */
@keyframes ardoise-apparition {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
html:not([data-theme="public"]) .contenu { animation: ardoise-apparition 0.3s ease both; }

/* Aucun masquage de secours ici : le thème est posé par un script synchrone
   dans le <head> de chaque page, donc avant le premier affichage. Masquer le
   corps rendrait la plateforme invisible si ce fichier se chargeait seul. */

/* ==========================================================================
   THÈME « STUDIO »
   Inspiration : les produits SaaS de bureau contemporains — fond très clair,
   rail d'icônes sombre, accent indigo, cartes largement arrondies et ombres
   diffuses plutôt que des bordures.
   Particularité : le rail est déplaçable sur les quatre côtés de l'écran.
   ========================================================================== */
html[data-theme="studio"] {
  --craie: #F4F6FB;
  --craie-2: #FFFFFF;
  --ardoise: #1B2559;
  --ocre: #4C5FD5;
  --ocre-dark: #3A4BB8;
  --encre: #4C5FD5;
  --vert-ok: #12B76A;
  --rouge: #F04438;
  --texte-sombre: #101828;
  --texte-att: #667085;
  --bordure: #EAECF0;

  --police-titre: 'Inter', system-ui, -apple-system, sans-serif;
  --police-corps: 'Inter', system-ui, -apple-system, sans-serif;

  --r-carte: 16px;
  --r-bouton: 10px;
  --r-petit: 8px;
  --r-pilule: 999px;

  --nav-fond: #1B2559;
  --nav-texte: rgba(255, 255, 255, 0.62);
  --nav-texte-fort: #FFFFFF;
  --nav-actif-fond: rgba(255, 255, 255, 0.12);
  --nav-actif-texte: #FFFFFF;

  --ombre-carte: 0 1px 3px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}

html[data-theme="studio"] h1,
html[data-theme="studio"] h2,
html[data-theme="studio"] h3 { letter-spacing: -0.02em; font-weight: 600; }

/* Cartes sans bordure : la profondeur vient de l'ombre, pas du trait. */
html[data-theme="studio"] .carte-stat,
html[data-theme="studio"] .widget,
html[data-theme="studio"] .carte-config,
html[data-theme="studio"] .conteneur-tableau,
html[data-theme="studio"] .tuile,
html[data-theme="studio"] .fiche {
  border-color: transparent;
  box-shadow: var(--ombre-carte);
}

html[data-theme="studio"] .barre-laterale { border: none; }
html[data-theme="studio"] .nav-item { border-radius: 10px; }
html[data-theme="studio"] .bouton-principal { box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08); }
html[data-theme="studio"] th {
  background: #F9FAFB;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------------
   Rail déplaçable — disponible sur TOUS les thèmes, réglé depuis Mon profil.
   La règle prime sur la mise en page définie dans chaque page grâce au
   sélecteur html[data-nav-*], plus spécifique qu'une simple classe.
   -------------------------------------------------------------------------- */
html[data-nav-position="droite"] .mise-en-page {
  grid-template-columns: 1fr 240px;
}
html[data-nav-position="droite"] .barre-laterale { order: 2; }
html[data-nav-position="droite"] .contenu { order: 1; }

/* Haut et bas : le rail devient une barre horizontale pleine largeur. */
html[data-nav-position="haut"] .mise-en-page,
html[data-nav-position="bas"] .mise-en-page {
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
}
html[data-nav-position="bas"] .mise-en-page {
  grid-template-rows: 1fr auto;
}
html[data-nav-position="bas"] .barre-laterale { order: 2; }
html[data-nav-position="bas"] .contenu { order: 1; }

html[data-nav-position="haut"] .barre-laterale,
html[data-nav-position="bas"] .barre-laterale {
  height: auto;
  min-height: 0;
  position: sticky;
  top: 0;
  /* Sans z-index, le contenu de la page défile PAR-DESSUS la barre : les
     cartes et les tableaux ont leur propre contexte d'empilement. */
  z-index: 60;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  overflow: visible;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}
html[data-nav-position="bas"] .barre-laterale {
  box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.08);
}
html[data-nav-position="haut"] .nav-item,
html[data-nav-position="bas"] .nav-item { padding: 7px 12px; font-size: 0.9rem; }
html[data-nav-position="bas"] .barre-laterale { top: auto; bottom: 0; }

html[data-nav-position="haut"] .barre-laterale .marque,
html[data-nav-position="bas"] .barre-laterale .marque {
  margin: 0;
  font-size: 1.15rem;
  white-space: nowrap;
  flex: none;
}

/* Le contenu de la barre est enveloppé dans un <div> : sans cette règle, la
   marque et les liens resteraient empilés au lieu de s'aligner. */
html[data-nav-position="haut"] .barre-laterale > div,
html[data-nav-position="bas"] .barre-laterale > div {
  display: flex;
  align-items: center;
  gap: 20px;
  flex: 1;
  min-width: 0;
}
html[data-nav-position="haut"] .nav-liste,
html[data-nav-position="bas"] .nav-liste {
  overflow-x: auto;
  scrollbar-width: none;
}
html[data-nav-position="haut"] .nav-liste::-webkit-scrollbar,
html[data-nav-position="bas"] .nav-liste::-webkit-scrollbar { display: none; }

/* La déconnexion part à droite, en bout de barre. */
html[data-nav-position="haut"] .nav-deconnexion,
html[data-nav-position="bas"] .nav-deconnexion {
  margin: 0 0 0 auto;
  flex: none;
  white-space: nowrap;
  padding: 7px 13px;
}
html[data-nav-position="haut"] .nav-liste,
html[data-nav-position="bas"] .nav-liste {
  flex-direction: row;
  gap: 4px;
  flex-wrap: nowrap;
}
html[data-nav-position="haut"] .nav-item,
html[data-nav-position="bas"] .nav-item { white-space: nowrap; }


/* --------------------------------------------------------------------------
   Rail compact : icônes seules, le libellé apparaît au survol.
   C'est le comportement du rail sombre de la maquette. Réservé aux positions
   latérales : en barre horizontale, un élargissement au survol ferait sauter
   toute la ligne.
   -------------------------------------------------------------------------- */
html[data-nav-compact="oui"][data-nav-position="gauche"] .mise-en-page,
html[data-nav-compact="oui"]:not([data-nav-position]) .mise-en-page {
  grid-template-columns: 72px 1fr;
}
html[data-nav-compact="oui"][data-nav-position="droite"] .mise-en-page {
  grid-template-columns: 1fr 72px;
}

html[data-nav-compact="oui"][data-nav-position="gauche"] .barre-laterale,
html[data-nav-compact="oui"][data-nav-position="droite"] .barre-laterale,
html[data-nav-compact="oui"]:not([data-nav-position]) .barre-laterale {
  width: 72px;
  padding: 24px 12px;
  z-index: 40;
  transition: width 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
}
html[data-nav-compact="oui"][data-nav-position="gauche"] .barre-laterale:hover,
html[data-nav-compact="oui"][data-nav-position="gauche"] .barre-laterale:focus-within,
html[data-nav-compact="oui"]:not([data-nav-position]) .barre-laterale:hover,
html[data-nav-compact="oui"]:not([data-nav-position]) .barre-laterale:focus-within {
  width: 240px;
  box-shadow: 8px 0 32px rgba(16, 24, 40, 0.14);
}
html[data-nav-compact="oui"][data-nav-position="droite"] .barre-laterale:hover,
html[data-nav-compact="oui"][data-nav-position="droite"] .barre-laterale:focus-within {
  width: 240px;
  margin-left: -168px;
  box-shadow: -8px 0 32px rgba(16, 24, 40, 0.14);
}

/* Le libellé s'efface mais reste dans le flux : sans cela, chaque survol
   provoquerait un recalcul de largeur et un tremblement du texte. */
html[data-nav-compact="oui"] .nav-libelle {
  opacity: 0;
  transition: opacity 0.16s ease;
  white-space: nowrap;
}
html[data-nav-compact="oui"] .barre-laterale:hover .nav-libelle,
html[data-nav-compact="oui"] .barre-laterale:focus-within .nav-libelle { opacity: 1; }

html[data-nav-compact="oui"] .nav-item { overflow: hidden; }

/* La marque ne disparaît pas : elle rétrécit juste assez pour tenir sur une
   seule ligne dans le rail étroit. Un mot coupé en deux serait illisible. */
html[data-nav-compact="oui"][data-nav-position="gauche"] .barre-laterale .marque,
html[data-nav-compact="oui"][data-nav-position="droite"] .barre-laterale .marque,
html[data-nav-compact="oui"]:not([data-nav-position]) .barre-laterale .marque {
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  margin-bottom: 26px;
  text-align: center;
  /* La taille anime le texte ET le point, ce dernier étant exprimé en em. */
  transition: font-size 0.22s cubic-bezier(0.22, 0.61, 0.36, 1),
              margin-bottom 0.22s cubic-bezier(0.22, 0.61, 0.36, 1);
}
html[data-nav-compact="oui"] .barre-laterale:hover .marque,
html[data-nav-compact="oui"] .barre-laterale:focus-within .marque {
  font-size: 1.5rem;
  text-align: left;
}
/* Aucune règle sur le point du « i » : il est dimensionné en « em » et
   centré par translateX(-50%). Il suit donc déjà la taille du texte, et
   toute transform ajoutée ici écraserait ce centrage. */

/* Déconnexion : réduite à une porte de sortie, sans texte. */
html[data-nav-compact="oui"][data-nav-position="gauche"] .nav-deconnexion,
html[data-nav-compact="oui"][data-nav-position="droite"] .nav-deconnexion,
html[data-nav-compact="oui"]:not([data-nav-position]) .nav-deconnexion {
  font-size: 0;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}
html[data-nav-compact="oui"] .nav-deconnexion::before {
  content: '';
  width: 20px; height: 20px; flex: none;
  background: currentColor;
  -webkit-mask: var(--icone-sortie) center / contain no-repeat;
  mask: var(--icone-sortie) center / contain no-repeat;
}
html[data-nav-compact="oui"] .barre-laterale:hover .nav-deconnexion,
html[data-nav-compact="oui"] .barre-laterale:focus-within .nav-deconnexion {
  font-size: 0.88rem;
  padding: 10px 12px;
  justify-content: flex-start;
  gap: 10px;
}
html[data-nav-compact="oui"] .barre-laterale:hover .nav-deconnexion::before,
html[data-nav-compact="oui"] .barre-laterale:focus-within .nav-deconnexion::before {
  width: 17px; height: 17px;
}

:root {
  --icone-sortie: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3Cpath d='m16 17 5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3C/svg%3E");
}

@media (prefers-reduced-motion: reduce) {
  html[data-nav-compact="oui"] .barre-laterale,
  html[data-nav-compact="oui"] .nav-libelle { transition: none; }
}

/* Sous 780 px, la barre repasse en bandeau supérieur quelle que soit la
   position choisie : un rail latéral n'a pas de sens sur un téléphone. */
@media (max-width: 780px) {
  html[data-nav-position] .mise-en-page,
  html[data-nav-compact] .mise-en-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  html[data-nav-position] .barre-laterale,
  html[data-nav-compact="oui"] .barre-laterale {
    width: auto;
    height: auto;
    order: 0;
    margin-left: 0;
    padding: 18px 22px;
  }
  html[data-nav-position] .contenu { order: 1; }
  html[data-nav-compact="oui"] .nav-libelle { opacity: 1; }
  html[data-nav-compact="oui"] .barre-laterale .marque { font-size: 1.25rem; margin-bottom: 0; text-align: left; }
  html[data-nav-compact="oui"] .nav-deconnexion { font-size: 0.88rem; padding: 8px 12px; }
  html[data-nav-compact="oui"] .nav-deconnexion::before { display: none; }
}
