/* ============================================================
   Charte graphique ESG — version Phase 2
   Reprise et adaptation de la v2 offline pour un contexte
   serveur multi-page.
   ============================================================ */

:root {
  /* Couleurs primaires (charte ESG) */
  --c-primary:   #1D3E73;
  --c-primary-d: #14305c;
  --c-primary-l: #2d5394;

  /* Couleurs sémantiques */
  --c-success:   #0F6E56;
  --c-warning:   #BA7517;
  --c-danger:    #A32D2D;
  --c-info:      #2563EB;

  /* Neutres */
  --c-bg:        #F7F6F1;
  --c-surface:   #FFFFFF;
  --c-surface-2: #FAFAF7;
  --c-border:    #E5E2D8;
  --c-border-d:  #C9C5B6;
  --c-text:      #1A1A1A;
  --c-text-2:    #4A4A4A;
  --c-text-3:    #767470;
  --c-muted:     #A8A59B;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-8: 48px;
  --sp-10: 64px;

  /* Rayons */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Ombres */
  --sh-sm: 0 1px 2px rgba(0,0,0,.06);
  --sh-md: 0 4px 10px rgba(0,0,0,.07);
  --sh-lg: 0 12px 28px rgba(0,0,0,.10);

  /* Typo */
  --ff-base: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --ff-serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --ff-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Animation */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tr-fast: 120ms;
  --tr-med:  240ms;
}

/* Reset basique */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ff-base);
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { max-width: 100%; display: block; }
a { color: var(--c-primary); text-decoration: none; transition: color var(--tr-fast); }
a:hover { color: var(--c-primary-d); text-decoration: underline; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--ff-base);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.01em;
  margin: 0 0 var(--sp-4);
}
h1 { font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem); font-weight: 600; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.05rem; }
p { margin: 0 0 var(--sp-4); }

/* Conteneurs */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 var(--sp-5);
}
.container-sm { max-width: 640px; margin: 0 auto; padding: 0 var(--sp-5); }
.container-lg { max-width: 1280px; margin: 0 auto; padding: 0 var(--sp-5); }

/* Bandeau supérieur */
.topbar {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: var(--sp-4) 0;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(8px);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-5);
}
.brand {
  display: flex; align-items: center; gap: var(--sp-3);
  font-weight: 600; font-size: 1.1rem; letter-spacing: -.01em;
  color: var(--c-primary);
}
.brand-dot {
  width: 28px; height: 28px;
  background: var(--c-primary); color: white;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  font-size: .85rem; font-weight: 700;
}
.nav { display: flex; gap: var(--sp-5); align-items: center; }
.nav a {
  color: var(--c-text-2); font-size: .95rem;
  padding: var(--sp-2) 0;
  border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--c-primary); text-decoration: none; border-bottom-color: var(--c-primary); }

/* Sections / surfaces */
.section { padding: var(--sp-8) 0; }
.section-sm { padding: var(--sp-6) 0; }
.surface {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--sh-sm);
}
.surface-quiet { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--sp-4); }

/* Grille des cartes formations */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-5);
}
.card-formation {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  transition: transform var(--tr-med) var(--ease), box-shadow var(--tr-med) var(--ease), border-color var(--tr-med) var(--ease);
  position: relative; overflow: hidden;
}
.card-formation:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-md);
  border-color: var(--c-border-d);
  text-decoration: none;
}
.card-formation::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0;
  height: 4px; background: var(--c-color, var(--c-primary));
}
.card-formation .code {
  display: inline-block;
  font-size: .75rem; font-weight: 700; letter-spacing: .1em;
  color: var(--c-color, var(--c-primary));
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
}
.card-formation h3 { margin-bottom: var(--sp-2); color: var(--c-text); }
.card-formation p { color: var(--c-text-2); font-size: .92rem; margin: 0; }
.card-formation .rncp {
  margin-top: var(--sp-4);
  font-size: .8rem; color: var(--c-muted);
  font-family: var(--ff-mono);
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 10px 20px;
  background: var(--c-primary); color: white;
  border: 1px solid var(--c-primary);
  border-radius: var(--r-md);
  font-family: inherit; font-size: .95rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--tr-fast);
  text-decoration: none;
}
.btn:hover { background: var(--c-primary-d); border-color: var(--c-primary-d); text-decoration: none; color: white; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: white; color: var(--c-primary); }
.btn-secondary:hover { background: var(--c-surface-2); color: var(--c-primary-d); }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); }
.btn-danger:hover { background: #842323; border-color: #842323; }
.btn-warning { background: var(--c-warning); border-color: var(--c-warning); }
.btn-success { background: var(--c-success); border-color: var(--c-success); }
.btn-ghost { background: transparent; color: var(--c-text-2); border-color: var(--c-border); }
.btn-ghost:hover { background: var(--c-surface-2); color: var(--c-text); }
.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Formulaires */
.field { margin-bottom: var(--sp-4); }
.field label {
  display: block; margin-bottom: var(--sp-2);
  font-weight: 500; font-size: .9rem; color: var(--c-text);
}
.field .hint { display: block; margin-top: 4px; font-size: .8rem; color: var(--c-text-3); }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 14px;
  background: white;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-family: inherit; font-size: .95rem; color: var(--c-text);
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(29, 62, 115, 0.12);
}
.textarea { min-height: 100px; resize: vertical; }
.field.error .input { border-color: var(--c-danger); }
.field.error .hint { color: var(--c-danger); }

/* Checkbox/radio personnalisés */
.checkbox { display: flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; }
.checkbox input { margin-top: 4px; accent-color: var(--c-primary); width: 16px; height: 16px; }
.checkbox span { font-size: .92rem; color: var(--c-text-2); }

/* Messages flash */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: .92rem;
  margin-bottom: var(--sp-4);
  border: 1px solid;
}
.alert-success { background: #E8F4F0; color: #0a5440; border-color: #B3DAC9; }
.alert-warning { background: #FBF1E0; color: #7A4D0F; border-color: #ECCC95; }
.alert-danger  { background: #F8E5E5; color: #71202C; border-color: #E6B5B5; }
.alert-info    { background: #E5EFFA; color: #134B85; border-color: #B5D1ED; }

/* Bandeau MODE TEST */
.banner-mode-test {
  background: var(--c-warning); color: white;
  padding: var(--sp-2) 0; text-align: center;
  font-weight: 600; font-size: .9rem; letter-spacing: .02em;
  border-bottom: 2px solid #8a5611;
  position: sticky; top: 0; z-index: 200;
}

/* Footer */
.footer {
  margin-top: var(--sp-10);
  padding: var(--sp-6) 0;
  border-top: 1px solid var(--c-border);
  color: var(--c-text-3); font-size: .88rem;
}
.footer-inner { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }
.footer a { color: var(--c-text-3); }
.footer a:hover { color: var(--c-primary); }

/* ============================================================
   INTERFACE DE PASSAGE DU TEST
   ============================================================ */
.test-stage {
  min-height: 100vh;
  background: var(--c-bg);
  padding: var(--sp-5) 0;
}

.test-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: var(--sp-5);
  padding: var(--sp-4) var(--sp-5);
  background: white; border: 1px solid var(--c-border); border-radius: var(--r-md);
}
.test-header .progress {
  display: flex; align-items: center; gap: var(--sp-3);
}
.test-header .progress strong { color: var(--c-primary); font-size: 1.1rem; }
.progress-bar {
  flex: 1; height: 6px; background: var(--c-border); border-radius: 999px;
  overflow: hidden; min-width: 200px;
}
.progress-bar > div { height: 100%; background: var(--c-primary); border-radius: 999px; transition: width var(--tr-med) var(--ease); }

/* Timer */
.timer-ring {
  position: relative; width: 64px; height: 64px;
}
.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-ring circle { fill: none; stroke-width: 6; }
.timer-ring .bg { stroke: var(--c-border); }
.timer-ring .fg { stroke: var(--c-primary); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.timer-ring .fg.warning { stroke: var(--c-warning); }
.timer-ring .fg.danger  { stroke: var(--c-danger); }
.timer-ring .value {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.1rem;
}

/* Carte question */
.question-card {
  background: white; border: 1px solid var(--c-border); border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-6);
  max-width: 800px; margin: 0 auto;
  box-shadow: var(--sh-md);
}
.question-meta {
  display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap;
  margin-bottom: var(--sp-4);
  font-size: .8rem;
}
.question-meta .pill {
  display: inline-block;
  background: var(--bloc-color, var(--c-primary));
  color: white;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.question-meta .meta-info {
  color: var(--c-text-3);
}
.question-text {
  font-size: 1.15rem; font-weight: 500;
  margin-bottom: var(--sp-5);
  line-height: 1.5;
}

.options { display: flex; flex-direction: column; gap: var(--sp-3); }
.option {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--c-surface-2);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--tr-fast);
  text-align: left;
  font-family: inherit; font-size: 1rem; color: var(--c-text);
  width: 100%;
}
.option:hover { border-color: var(--c-primary); background: white; }
.option.selected { border-color: var(--c-primary); background: white; }
.option .letter {
  flex-shrink: 0;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: white; border: 2px solid var(--c-border-d);
  border-radius: var(--r-sm);
  font-weight: 700; color: var(--c-text-2);
  transition: all var(--tr-fast);
}
.option:hover .letter, .option.selected .letter {
  background: var(--c-primary); color: white; border-color: var(--c-primary);
}
.option .text { flex: 1; line-height: 1.5; }

/* États de l'option après réponse */
.option.correct { border-color: var(--c-success); background: #E8F4F0; }
.option.correct .letter { background: var(--c-success); color: white; border-color: var(--c-success); }
.option.incorrect { border-color: var(--c-danger); background: #FCE8E8; }
.option.incorrect .letter { background: var(--c-danger); color: white; border-color: var(--c-danger); }
.option.locked { cursor: default; }

/* Bouton suivante */
.question-footer {
  margin-top: var(--sp-5);
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--sp-4);
}
.explication {
  margin-top: var(--sp-4);
  padding: var(--sp-4);
  background: var(--c-surface-2);
  border-left: 4px solid var(--c-primary);
  border-radius: var(--r-sm);
  font-size: .95rem; color: var(--c-text-2);
  display: none;
}
.explication.show { display: block; animation: fadeIn .3s var(--ease); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Bouton tiers temps en bas */
.tiers-temps-bar {
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface-2);
  border: 1px dashed var(--c-border-d);
  border-radius: var(--r-md);
  display: flex; justify-content: space-between; align-items: center;
  font-size: .85rem; color: var(--c-text-3);
}

/* Raccourcis clavier */
.option .kbd-hint {
  position: absolute; bottom: -22px; left: 14px;
  font-size: .7rem; color: var(--c-text-3);
  font-family: var(--ff-mono);
  opacity: 0; transition: opacity var(--tr-fast);
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tableaux */
.table {
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  background: white;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  font-size: .92rem;
}
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
.table th { background: var(--c-surface-2); font-weight: 600; color: var(--c-text-2); }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover { background: var(--c-surface-2); }

/* Badges de statut */
.badge {
  display: inline-block;
  padding: 2px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .02em;
}
.badge-success { background: #DDF1E8; color: #0a5440; }
.badge-warning { background: #FBF1E0; color: #7A4D0F; }
.badge-danger  { background: #F8E5E5; color: #71202C; }
.badge-info    { background: #DDE9F8; color: #1a4480; }
.badge-muted   { background: var(--c-border); color: var(--c-text-3); }

/* Utility */
.text-muted { color: var(--c-text-3); }
.text-small { font-size: .85rem; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--sp-1) !important; }
.mb-2 { margin-bottom: var(--sp-2) !important; }
.mb-3 { margin-bottom: var(--sp-3) !important; }
.mb-4 { margin-bottom: var(--sp-4) !important; }
.mb-5 { margin-bottom: var(--sp-5) !important; }
.mb-6 { margin-bottom: var(--sp-6) !important; }
.mt-3 { margin-top: var(--sp-3) !important; }
.mt-4 { margin-top: var(--sp-4) !important; }
.mt-5 { margin-top: var(--sp-5) !important; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap-2 { gap: var(--sp-2); }
.flex-gap-3 { gap: var(--sp-3); }
.flex-gap-4 { gap: var(--sp-4); }
.flex-wrap { flex-wrap: wrap; }

/* Responsive */
@media (max-width: 768px) {
  .container, .container-sm, .container-lg { padding: 0 var(--sp-4); }
  .surface { padding: var(--sp-4); }
  .question-card { padding: var(--sp-4); }
  .question-text { font-size: 1.05rem; }
  .test-header { flex-direction: column; align-items: stretch; gap: var(--sp-3); }
  .test-header .progress { width: 100%; }
  .progress-bar { min-width: unset; }
  .nav { gap: var(--sp-3); }
  .nav a { font-size: .9rem; }
}

/* Animations subtiles */
.fade-in { animation: fadeIn .3s var(--ease); }

/* Print styles */
@media print {
  .nav, .footer, .btn { display: none !important; }
  body { background: white; }
}
