/* ============================================================
   OleaFlow — Utilisation guidée
   ------------------------------------------------------------
   Surcouche du moteur de guides (public/js/formation-guide.js) et
   des écrans du centre de formation.

   Tout est exprimé en tokens du design system : le guide hérite donc
   automatiquement du thème sombre et de la charte de couleur configurée
   par la société, sans une seule couleur écrite en dur.

   Préfixe `olf-` : le moteur injecte ces éléments dans des pages
   quelconques de l'ERP, il ne doit entrer en collision avec aucune
   classe existante.
   ============================================================ */

/* ─── Overlay ────────────────────────────────────────────────── */

.olf-verrou { overflow: hidden; }

.olf-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;           /* au-dessus du FAB d'aide (800) et des modales Bootstrap (1055) */
}

.olf-voile {
  position: absolute;
  inset: 0;
  background: color-mix(in oklch, var(--stone-950) 62%, transparent);
  backdrop-filter: blur(1px);
}

/* Découpe : un halo autour de l'élément, obtenu par une ombre portée
   démesurée plutôt que par un masque SVG — un seul élément, aucun
   recalcul de tracé au défilement. */
.olf-decoupe {
  position: absolute;
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 0 0 9999px color-mix(in oklch, var(--stone-950) 62%, transparent),
              0 0 0 3px var(--olive-400);
  pointer-events: none;
  transition: top .18s ease, left .18s ease, width .18s ease, height .18s ease;
}

/* L'élément mis en évidence redevient cliquable : certaines étapes
   demandent explicitement d'agir dessus. */
.olf-cible {
  position: relative;
  z-index: 2001;
}

/* ─── Bulle ──────────────────────────────────────────────────── */

.olf-bulle {
  position: absolute;
  z-index: 2002;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface-card);
  color: var(--text-body);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4, 1rem);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.olf-bulle:focus { outline: none; box-shadow: var(--shadow-lg), var(--ring-focus); }

.olf-bulle--centree {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 24px));
}

/* Sous 720 px : feuille ancrée en bas, plus lisible qu'une bulle
   flottante sur un écran de terminal de pesée. */
.olf-bulle--feuille {
  top: auto !important;
  bottom: 0;
  left: 0 !important;
  right: 0;
  width: 100%;
  max-height: 72vh;
  border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
  transform: none;
}

.olf-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2, .5rem);
  margin-bottom: var(--space-2, .5rem);
}

.olf-compteur {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.olf-fermer {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 .25rem;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm, 4px);
}
.olf-fermer:hover { color: var(--text-strong); background: var(--surface-hover); }
.olf-fermer:focus-visible { outline: none; box-shadow: var(--ring-focus); }

.olf-jauge {
  height: 4px;
  border-radius: var(--radius-pill, 999px);
  background: var(--fill-track);
  overflow: hidden;
  margin-bottom: var(--space-3, .75rem);
}
.olf-jauge__barre {
  height: 100%;
  background: var(--olive-600);
  transition: width .25s ease;
}

.olf-titre {
  margin: 0 0 var(--space-2, .5rem);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-strong);
}

.olf-texte {
  margin: 0;
  line-height: var(--lh-relaxed, 1.6);
}

.olf-pourquoi {
  margin-top: var(--space-3, .75rem);
  padding: var(--space-2, .5rem) var(--space-3, .75rem);
  border-inline-start: 3px solid var(--gold-500);
  background: var(--surface-accent-soft);
  border-radius: 0 var(--radius-sm, 4px) var(--radius-sm, 4px) 0;
  font-size: var(--text-xs);
}
.olf-pourquoi__label {
  display: block;
  font-weight: 700;
  color: var(--text-accent);
  margin-bottom: 2px;
}
.olf-pourquoi__texte { color: var(--text-body); }

/* Cible momentanément indisponible (attente expirée) : un avertissement
   discret, jamais une erreur — le guide continue normalement. */
.olf-avertissement {
  margin-top: var(--space-3, .75rem);
  padding: var(--space-2, .5rem) var(--space-3, .75rem);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-sm, 4px);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

.olf-liens {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, .5rem);
  margin-top: var(--space-3, .75rem);
}
.olf-lien {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-link);
  text-decoration: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill, 999px);
  padding: 2px 10px;
}
.olf-lien:hover { background: var(--surface-hover); }

.olf-pied {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2, .5rem);
  margin-top: var(--space-4, 1rem);
}
.olf-pied__actions { display: flex; gap: var(--space-2, .5rem); }

.olf-btn {
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-sm, 6px);
  padding: .4rem .8rem;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.olf-btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.olf-btn--principal { background: var(--olive-600); color: var(--text-on-brand); }
.olf-btn--principal:hover { background: var(--olive-700); }
.olf-btn--secondaire {
  background: var(--surface-card);
  color: var(--text-body);
  border-color: var(--border-default);
}
.olf-btn--secondaire:hover { background: var(--surface-hover); }
.olf-btn--discret { background: none; color: var(--text-muted); }
.olf-btn--discret:hover { color: var(--text-strong); text-decoration: underline; }

/* ─── Scène de démonstration ─────────────────────────────────── */

.olf-scene {
  margin-top: var(--space-3, .75rem);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, .75rem);
  background: var(--surface-sunken);
}
.olf-scene__ecran {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  margin-bottom: var(--space-2, .5rem);
}
.olf-scene__encarts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-2, .5rem);
}
.olf-encart {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm, 6px);
  padding: var(--space-2, .5rem);
}
.olf-encart__libelle {
  font-size: var(--text-xs);
  color: var(--text-muted);
}
.olf-encart__valeur {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.olf-scene__table {
  margin-top: var(--space-2, .5rem);
  overflow-x: auto;
}
.olf-scene__table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}
.olf-scene__table th,
.olf-scene__table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: start;
  white-space: nowrap;
}
.olf-scene__table th { color: var(--text-muted); font-weight: 600; }
.olf-scene__table td { color: var(--text-body); font-variant-numeric: tabular-nums; }
.olf-scene__mention {
  margin-top: var(--space-2, .5rem);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* ─── Invitation de première utilisation ─────────────────────── */

.olf-invitation {
  position: fixed;
  bottom: var(--space-5, 1.25rem);
  inset-inline-end: calc(var(--space-5, 1.25rem) + 56px);
  z-index: 900;
  width: min(320px, calc(100vw - 24px));
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4, 1rem);
  font-family: var(--font-sans);
}
.olf-invitation__titre {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 4px;
}
.olf-invitation__texte {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-3, .75rem);
}
.olf-invitation__actions { display: flex; gap: var(--space-2, .5rem); }

@media (max-width: 720px) {
  .olf-invitation {
    inset-inline: var(--space-3, .75rem);
    bottom: calc(var(--space-3, .75rem) + 56px);
    width: auto;
  }
}

/* ─── Écrans du centre de formation ──────────────────────────── */

.olf-carte {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-4, 1rem);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.olf-carte:hover { border-color: var(--border-brand); box-shadow: var(--shadow-sm); }
.olf-carte__emoji { font-size: 1.6rem; line-height: 1; }
.olf-carte__titre {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-strong);
  margin: var(--space-2, .5rem) 0 4px;
}
.olf-carte__desc {
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex: 1;
  line-height: var(--lh-relaxed, 1.6);
}
.olf-carte__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, .5rem);
  align-items: center;
  margin-top: var(--space-3, .75rem);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.olf-progress {
  height: 8px;
  border-radius: var(--radius-pill, 999px);
  background: var(--fill-track);
  overflow: hidden;
}
.olf-progress__barre { height: 100%; background: var(--olive-600); transition: width .3s ease; }
.olf-progress__barre--termine { background: var(--green-500, var(--olive-600)); }

.olf-pastille {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.olf-pastille--success { background: var(--status-success-fg); }
.olf-pastille--warning { background: var(--status-warning-fg); }
.olf-pastille--neutral { background: var(--status-neutral-bd); }

.olf-astuce {
  display: flex;
  gap: var(--space-3, .75rem);
  align-items: flex-start;
  background: var(--surface-accent-soft);
  border: 1px solid var(--gold-200);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, .75rem);
  font-size: var(--text-sm);
  color: var(--text-body);
}
.olf-astuce__icone { font-size: 1.1rem; line-height: 1.2; }

/* Bouton contextuel « Utilisation guidée » posé dans l'en-tête d'écran. */
.olf-btn-guide {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-brand);
  background: var(--surface-brand-soft);
  border: 1px solid var(--olive-200);
  border-radius: var(--radius-pill, 999px);
  padding: .35rem .75rem;
  cursor: pointer;
  white-space: nowrap;
}
.olf-btn-guide:hover { background: var(--olive-100); }
.olf-btn-guide:focus-visible { outline: none; box-shadow: var(--ring-focus); }

/* ─── Panneau de debug (admin/dev) ───────────────────────────── */

.olf-debug {
  position: fixed;
  z-index: 2100;             /* au-dessus de la bulle (2002) */
  bottom: var(--space-3, .75rem);
  inset-inline-start: var(--space-3, .75rem);
  width: min(320px, calc(100vw - 24px));
  max-height: 40vh;
  overflow-y: auto;
  background: var(--stone-950, #1a1713);
  color: #e7e5e4;
  border: 1px solid var(--olive-500, #8a7a52);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, .75rem);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  line-height: 1.5;
  pointer-events: none;
}
.olf-debug__titre {
  font-weight: 700;
  color: var(--olive-300, #cfc2a3);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.olf-debug__ligne { display: flex; justify-content: space-between; gap: 8px; }
.olf-debug__cle { color: #a8a29e; white-space: nowrap; }
.olf-debug__valeur { text-align: end; word-break: break-all; }

/* ─── Confort de lecture et préférences système ──────────────── */

@media (prefers-reduced-motion: reduce) {
  .olf-decoupe,
  .olf-jauge__barre,
  .olf-progress__barre { transition: none; }
}

@media print {
  .olf-overlay,
  .olf-invitation,
  .olf-debug,
  .olf-btn-guide { display: none !important; }
}
