/* ==========================================================================
   Formahub — feuille de style globale unique.
   Aucune dependance externe, aucune police telechargee (pile systeme).
   Toutes les couleurs passent par les variables ci-dessous : ne jamais
   coder une couleur en dur dans une regle de composant.
   ========================================================================== */

:root {
  --bg: #f7f8fa; --surface: #ffffff; --text: #1f2933; --text-muted: #6b7280;
  --border: #d1d5db; --accent: #2563eb; --success: #059669; --warning: #d97706;
  --danger: #dc2626; --radius: 12px; --transition-fast: 0.15s ease;

  /* Variantes destinees au TEXTE et aux FONDS DE BADGE.
     --success (#059669) et --danger (#dc2626) restent conformes a la
     specification pour les bordures et aplats decoratifs, mais leur contraste
     avec du texte blanc de 12 px est insuffisant (3,77:1 pour --success).
     Ces variantes assombries repassent au-dessus de 4,5:1 (WCAG AA). */
  --success-strong: #047857;   /* 5,48:1 sur --surface */
  --danger-strong:  #b91c1c;   /* 6,47:1 sur --surface */

  /* Jetons de badge : la couleur d'encre s'inverse selon le theme, car en
     theme sombre les fonds de badge sont des couleurs claires. */
  --badge-fg-on-color: #ffffff;
  --badge-success-bg: var(--success-strong);
  --badge-progress-bg: var(--accent);
  --badge-warning-bg: var(--warning);
  --badge-warning-fg: #1f2933;

  --focus-ring: #1d4ed8;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --bg: #14161a; --surface: #1f2229; --text: #e5e7eb; --text-muted: #9ca3af;
  --border: #374151; --accent: #60a5fa; --success: #34d399; --warning: #fbbf24;
  --danger: #f87171;

  /* En theme sombre les couleurs de la specification sont deja claires :
     elles contrastent correctement sur --surface, aucune variante n'est requise. */
  --success-strong: #34d399;   /* 8,28:1 sur --surface */
  --danger-strong:  #f87171;   /* 5,76:1 sur --surface */

  /* Encre foncee sur badge clair : 9,42:1 (succes), 7,12:1 (progression). */
  --badge-fg-on-color: #14161a;
  --badge-success-bg: var(--success);
  --badge-progress-bg: var(--accent);
  --badge-warning-bg: var(--warning);
  --badge-warning-fg: #1f2933;

  --focus-ring: #93c5fd;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, sans-serif; margin: 0;
  line-height: 1.6;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { max-width: 760px; margin: 0 auto; padding: 0 20px; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.9rem; margin: 0 0 8px; }
h2 { font-size: 1.35rem; margin: 32px 0 12px; }
h3 { font-size: 1.05rem; margin: 24px 0 8px; }
p  { margin: 0 0 14px; }

a { color: var(--accent); }
a:hover { text-decoration: none; }

/* Anneau de focus visible au clavier uniquement (accessibilite, section 15.4). */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Lien d'evitement : masque jusqu'a la prise de focus clavier. */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--text);
  padding: 10px 16px; border: 1px solid var(--border); border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------- En-tete -------------------------------- */

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none;
}
.site-header .logo svg { display: block; height: 26px; width: auto; }
.site-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.site-nav a {
  color: var(--text); text-decoration: none; font-size: 0.9rem;
  padding: 6px 12px; border-radius: 9999px;
}
.site-nav a:hover { background: var(--bg); }
.site-nav a[aria-current="page"] { background: var(--bg); font-weight: 600; }

.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: 9999px;
  padding: 6px 14px; color: var(--text); cursor: pointer; font-size: 0.85rem;
  transition: background var(--transition-fast);
}
.theme-toggle:hover { background: var(--bg); }

.site-footer {
  margin-top: 48px; padding: 24px 20px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.85rem;
}

/* -------------------------------- Badges -------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.75rem; font-weight: 600; line-height: 1;
  padding: 4px 12px; border-radius: 9999px; white-space: nowrap;
}
.badge-success  { background: var(--badge-success-bg);  color: var(--badge-fg-on-color); }
.badge-progress { background: var(--badge-progress-bg); color: var(--badge-fg-on-color); }
.badge-warning  { background: var(--badge-warning-bg);  color: var(--badge-warning-fg); }
.badge-neutral  { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* -------------------------------- Cartes -------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }
.card h3 { margin-top: 0; }
.card p { color: var(--text-muted); font-size: 0.9rem; }

/* Une carte non cliquable (module a venir) ne doit pas suggerer une interaction. */
.card.is-locked { opacity: 0.75; }
.card.is-locked:hover { transform: none; box-shadow: none; }

.card-link { text-decoration: none; color: inherit; display: block; }
.card-link:hover .card { transform: translateY(-2px); box-shadow: var(--shadow-card); }

.catalogue-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px;
}

.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

/* ---------------------------- Barre de progression ---------------------- */

.progress-bar {
  height: 8px; border-radius: 9999px; background: var(--border); overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--accent); border-radius: 9999px;
  transition: width 0.4s ease;
}
.progress-label { font-size: 0.8rem; color: var(--text-muted); margin: 6px 0 0; }

.progress-global {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 24px 0 32px;
}
.progress-global h2 { margin: 0 0 10px; font-size: 1rem; }
.streak { font-size: 0.85rem; color: var(--text-muted); margin: 10px 0 0; }

/* ------------------------- Timeline (liste modules) --------------------- */

.timeline { list-style: none; margin: 24px 0; padding: 0 0 0 28px; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-item::before {
  content: ""; position: absolute; left: -28px; top: 18px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
}
.timeline-item.is-done::before { background: var(--success-strong); border-color: var(--success-strong); }
.timeline-item.is-current::before { border-color: var(--accent); }
.timeline-meta { font-size: 0.8rem; color: var(--text-muted); }

/* ----------------------------- Page de module --------------------------- */

.module-layout { display: block; }
.module-header { margin: 28px 0 8px; }
.module-kicker { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.objectifs {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 16px 20px; margin: 24px 0;
}
.objectifs h2 { margin-top: 0; }
.objectifs ul { margin: 0; padding-left: 20px; }
.objectifs li { margin-bottom: 6px; }

.encart {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin: 24px 0;
}
.encart-exercice { border-left: 4px solid var(--warning); }
.encart-verif    { border-left: 4px solid var(--danger); }
.encart-suivant  { border-left: 4px solid var(--success); }
.encart h2, .encart h3 { margin-top: 0; }

/* Marqueur inline pour les informations non verifiees (regle anti-hallucination).
   Le texte peut etre long : il doit pouvoir se couper, sinon il deborde de la
   page sur mobile. */
.a-verifier {
  background: var(--badge-warning-bg); color: var(--badge-warning-fg);
  font-size: 0.78rem; font-weight: 600;
  padding: 1px 7px; border-radius: 4px;
  overflow-wrap: break-word;
}

.exemple {
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin: 14px 0;
  font-size: 0.92rem;
}
.exemple p:last-child { margin-bottom: 0; }

/* Sommaire sticky sur desktop uniquement (section 15.5). */
.sommaire {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; margin: 24px 0;
}
.sommaire h2 { margin: 0 0 8px; font-size: 0.95rem; }
.sommaire ol { margin: 0; padding-left: 20px; font-size: 0.9rem; }
.sommaire li { margin-bottom: 4px; }
.sommaire a { color: var(--text); text-decoration: none; }
.sommaire a:hover { text-decoration: underline; }
.sommaire a.is-active { color: var(--accent); font-weight: 600; }

/* Barre de lecture : progression de defilement dans le module. */
.reading-progress {
  position: sticky; top: 0; z-index: 20;
  height: 3px; background: transparent;
}
.reading-progress-fill { height: 100%; width: 0; background: var(--accent); }

/* --------------------------------- Quiz --------------------------------- */

.quiz-question {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; margin: 0 0 16px;
  transition: border-color var(--transition-fast);
}
.quiz-question legend { font-weight: 600; padding: 0 4px; }

.quiz-choice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin: 8px 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.quiz-choice:hover { border-color: var(--accent); }
.quiz-choice input { margin: 3px 0 0; flex-shrink: 0; }
.quiz-choice:has(input:checked) { border-color: var(--accent); background: var(--bg); }
.quiz-question.is-answered .quiz-choice { cursor: default; }
.quiz-question.is-answered .quiz-choice:hover { border-color: var(--border); }
.quiz-question.is-answered .quiz-choice:has(input:checked) { border-color: currentColor; }

/* Correction : couleur + icone (section 18), jamais la couleur seule. */
.quiz-question.correct   { border-color: var(--success-strong); }
.quiz-question.incorrect { border-color: var(--danger-strong); }

.quiz-feedback {
  margin: 12px 0 0; padding: 10px 12px;
  border-radius: var(--radius); background: var(--bg);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.quiz-feedback::before { font-weight: 700; margin-right: 6px; }
.quiz-question.correct   .quiz-feedback { color: var(--success-strong); }
.quiz-question.correct   .quiz-feedback::before { content: "\2713"; }
.quiz-question.incorrect .quiz-feedback { color: var(--danger-strong); }
.quiz-question.incorrect .quiz-feedback::before { content: "\2717"; }

.quiz-placeholder { color: var(--text-muted); font-size: 0.9rem; }
.quiz-score {
  margin-top: 16px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-weight: 600;
}
.quiz-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }

/* -------------------------------- Boutons ------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.95rem; font-weight: 600; font-family: inherit;
  padding: 10px 20px; border-radius: 9999px;
  border: 1px solid transparent; cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition-fast), background var(--transition-fast);
}
.btn-primary { background: var(--accent); color: var(--badge-fg-on-color); }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn[disabled] { opacity: 0.6; cursor: default; }
.btn-done { background: var(--success-strong); color: #ffffff; }

.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 24px 0; }
.action-status { font-size: 0.85rem; color: var(--text-muted); }

.module-nav {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 32px 0; padding-top: 20px; border-top: 1px solid var(--border);
}

/* --------------------------- Formulaire de retour ----------------------- */

.feedback-form { margin-top: 12px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 0.92rem;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.field textarea { min-height: 96px; resize: vertical; }
.field-hint { font-size: 0.8rem; color: var(--text-muted); margin: 4px 0 0; }
.form-status { font-size: 0.88rem; margin: 10px 0 0; }
.form-status.is-ok    { color: var(--success-strong); }
.form-status.is-error { color: var(--danger-strong); }

/* --------------------------- Ressources externes ------------------------ */

.filters {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 24px 0;
}
.filters .field { margin-bottom: 0; min-width: 200px; }

.cpf-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 16px 20px; margin: 24px 0;
}
.cpf-panel h2 { margin-top: 0; }
/* Contrairement aux badges courts, celui-ci porte un libelle complet :
   .badge impose white-space: nowrap, qu'il faut lever ici. */
.cpf-solde {
  font-size: 1.1rem; font-weight: 700;
  white-space: normal; text-align: left; max-width: 100%;
}

/* Le tableau defile horizontalement dans son conteneur, jamais la page. */
.table-scroll { overflow-x: auto; margin: 16px 0; }
/* table-layout: fixed est necessaire : en mode auto, les largeurs ci-dessous ne
   sont que des suggestions et le contenu le plus long les ecrase. */
.table-ressources {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
  min-width: 860px; table-layout: fixed;
}

/* Sans largeurs explicites, la colonne "reste a charge" (qui porte une phrase
   d'explication) s'approprie l'espace et ecrase la colonne "ressource" au point
   de couper les titres mot par mot. */
.table-ressources th:nth-child(1), .table-ressources td:nth-child(1) { width: 28%; }
.table-ressources th:nth-child(2), .table-ressources td:nth-child(2) { width: 12%; }
.table-ressources th:nth-child(3), .table-ressources td:nth-child(3) { width: 13%; }
.table-ressources th:nth-child(4), .table-ressources td:nth-child(4) { width: 13%; }
.table-ressources th:nth-child(5), .table-ressources td:nth-child(5) { width: 24%; }
.table-ressources th:nth-child(6), .table-ressources td:nth-child(6) { width: 10%; }
.table-ressources th, .table-ressources td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table-ressources th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.table-ressources tbody tr:hover { background: var(--surface); }
/* Les montants formates par Intl contiennent deja des espaces insecables : ils
   ne se coupent pas d'eux-memes. Imposer nowrap sur toute la cellule faisait en
   revanche deborder les libelles longs sur la colonne voisine. */
.table-ressources .num { overflow-wrap: break-word; }
.empty-state { color: var(--text-muted); padding: 20px 0; }

dl.def-list { margin: 12px 0; }
dl.def-list dt { font-weight: 600; margin-top: 10px; }
dl.def-list dd { margin: 2px 0 0; color: var(--text-muted); }

/* ------------------------------ Responsive ------------------------------ */

@media (min-width: 900px) {
  .module-layout {
    display: grid; grid-template-columns: 240px 1fr; gap: 40px; align-items: start;
  }
  .sommaire { position: sticky; top: 20px; margin-top: 28px; }
}

@media (max-width: 560px) {
  h1 { font-size: 1.5rem; }
  .site-header { padding: 10px 16px; }
  .actions { flex-direction: column; align-items: stretch; }
  .btn { justify-content: center; }
}

/* Respect de la preference systeme de mouvement reduit (section 15.4). */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .quiz-feedback { opacity: 1; }
}
