/* ===========================================================================
 * QZR vNext — AI generation flow (IA-2 params, IA-3 loading, IA-4 review)
 * Scoped to .qzr-ai-flow. Mono-tone teal; aligned with docs/vnext/mockups (IA-*).
 * ======================================================================== */

.qzr-ai-flow {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.qzr-ai-flow[hidden] { display: none; }

body.qzr-ai-flow-open { overflow: hidden; }

.qzr-ai-flow__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 52, 42, 0.42);
  backdrop-filter: blur(2px);
}

.qzr-ai-flow__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  max-height: 94vh;
  background: var(--qz-surface);
  border-radius: var(--qz-r-screen) var(--qz-r-screen) 0 0;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(6, 52, 42, 0.2);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--qz-text);
  animation: qzrAiRise var(--qz-dur-pop) var(--qz-ease);
}

@media (min-width: 600px) {
  .qzr-ai-flow { align-items: center; }
  .qzr-ai-flow__panel { border-radius: var(--qz-r-screen); max-height: 88vh; }
}

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

/* ── Head ───────────────────────────────────────────────────────────────── */
.qzr-ai-flow__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--qz-line);
}

.qzr-ai-flow__icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: 1px solid var(--qz-line);
  background: var(--qz-surface);
  border-radius: var(--qz-r-control);
  color: var(--qz-muted);
  cursor: pointer;
  transition: background var(--qz-dur-press) var(--qz-ease), color var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-flow__icon-btn:hover { background: var(--qz-accent-soft); color: var(--qz-accent); border-color: var(--qz-accent); }

.qzr-ai-flow__head-title {
  font-size: var(--qz-fs-h3);
  font-weight: var(--qz-fw-strong);
  color: var(--qz-text);
}

.qzr-ai-flow__head-title .fas { color: var(--qz-accent); margin-right: 4px; }

.qzr-ai-flow__head-count {
  margin-left: auto;
  font-size: var(--qz-fs-xs);
  color: var(--qz-muted);
  font-weight: var(--qz-fw-strong);
}

.qzr-ai-flow__subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: var(--qz-fs-sm);
  color: var(--qz-muted);
}

.qzr-ai-flow__selall {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--qz-accent);
  font-size: var(--qz-fs-sm);
  font-weight: var(--qz-fw-strong);
  cursor: pointer;
}

/* ── Body / foot ────────────────────────────────────────────────────────── */
.qzr-ai-flow__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.qzr-ai-flow__foot {
  padding: 14px 16px;
  border-top: 1px solid var(--qz-line);
}

.qzr-ai-flow__foot--split {
  display: flex;
  gap: 10px;
}

.qzr-ai-flow__foot--split .qzr-ai-btn { flex: 1; }

/* ── Fields ─────────────────────────────────────────────────────────────── */
.qzr-ai-field { margin-bottom: 18px; }

.qzr-ai-field > label {
  display: block;
  margin-bottom: 8px;
  font-size: var(--qz-fs-sm);
  font-weight: var(--qz-fw-strong);
  color: var(--qz-muted);
}

.qzr-ai-input,
.qzr-ai-textarea {
  width: 100%;
  color: var(--qz-text);
  background: var(--qz-surface);
  border: 1px solid var(--qz-line);
  border-radius: var(--qz-r-field);
  font-size: var(--qz-fs-body);
  font-family: inherit;
  outline: none;
}

.qzr-ai-input { min-height: 50px; padding: 0 14px; }
.qzr-ai-textarea { min-height: 120px; padding: 12px 14px; resize: vertical; }

.qzr-ai-input:focus,
.qzr-ai-textarea:focus { border-color: var(--qz-accent); box-shadow: var(--qz-focus-ring); }

.qzr-ai-hint {
  display: block;
  margin-top: 6px;
  font-size: var(--qz-fs-xs);
  color: var(--qz-muted);
}

/* ── Segmented control (count / difficulty) ─────────────────────────────── */
.qzr-ai-seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--qz-accent-soft);
  border-radius: var(--qz-r-control);
}

.qzr-ai-seg__btn {
  flex: 1;
  min-width: 0;
  padding: 9px 6px;
  border: none;
  background: transparent;
  border-radius: calc(var(--qz-r-control) - 4px);
  color: var(--qz-muted);
  font-size: var(--qz-fs-sm);
  font-weight: var(--qz-fw-strong);
  cursor: pointer;
  transition: background var(--qz-dur-press) var(--qz-ease), color var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-seg__btn.is-active {
  background: var(--qz-surface);
  color: var(--qz-accent-ink);
  box-shadow: 0 1px 3px rgba(6, 52, 42, 0.12);
}

/* ── Type pills (multi-select) ──────────────────────────────────────────── */
.qzr-ai-pills { display: flex; flex-wrap: wrap; gap: 8px; }

.qzr-ai-pill {
  padding: 8px 16px;
  border-radius: var(--qz-r-pill);
  border: 1px solid var(--qz-line);
  background: var(--qz-surface);
  color: var(--qz-muted);
  font-size: var(--qz-fs-sm);
  font-weight: var(--qz-fw-strong);
  cursor: pointer;
  transition: all var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-pill.is-active {
  background: var(--qz-accent);
  border-color: var(--qz-accent);
  color: var(--qz-on-accent);
}

/* ── Dropzone (file source) ─────────────────────────────────────────────── */
.qzr-ai-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 28px 16px;
  border: 1.5px dashed var(--qz-accent-mid);
  border-radius: var(--qz-r-card);
  background: var(--qz-accent-soft);
  cursor: pointer;
  transition: border-color var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-dropzone:hover { border-color: var(--qz-accent); }

.qzr-ai-dropzone__icon { font-size: 1.6rem; color: var(--qz-accent); margin-bottom: 4px; }
.qzr-ai-dropzone strong { font-size: var(--qz-fs-body); color: var(--qz-text); font-weight: var(--qz-fw-strong); }
.qzr-ai-dropzone small { font-size: var(--qz-fs-xs); color: var(--qz-muted); }

.qzr-ai-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--qz-surface);
  border: 1px solid var(--qz-line);
  border-radius: var(--qz-r-control);
}

.qzr-ai-file-row .fas { color: var(--qz-accent); }
.qzr-ai-file-row__name { flex: 1; min-width: 0; font-size: var(--qz-fs-sm); color: var(--qz-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qzr-ai-file-row__status { font-size: var(--qz-fs-xs); color: var(--qz-success-ink); font-weight: var(--qz-fw-strong); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.qzr-ai-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 0 18px;
  border: none;
  border-radius: var(--qz-r-control);
  font-size: var(--qz-fs-body);
  font-weight: var(--qz-fw-strong);
  cursor: pointer;
  transition: filter var(--qz-dur-press) var(--qz-ease), transform var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-btn--primary {
  background: var(--qz-accent);
  color: var(--qz-on-accent);
  border-bottom: 3px solid var(--qz-accent-deep);
}

.qzr-ai-btn--primary:hover { filter: brightness(1.05); }
.qzr-ai-btn--primary:active { transform: scale(var(--qz-press-scale)); border-bottom-width: 2px; }
.qzr-ai-btn--primary[disabled] { opacity: 0.5; cursor: not-allowed; filter: none; }

.qzr-ai-btn--ghost {
  background: var(--qz-surface);
  color: var(--qz-text);
  border: 1px solid var(--qz-line);
  border-bottom: 3px solid var(--qz-line-strong);
}

.qzr-ai-btn--ghost:hover { background: var(--qz-accent-soft); color: var(--qz-accent); border-color: var(--qz-accent); }

/* ── Loading (IA-3) ─────────────────────────────────────────────────────── */
.qzr-ai-flow__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px 48px;
}

.qzr-ai-flow__mascot {
  width: 132px;
  height: 158px;
  margin-bottom: 16px;
  animation: qzrAiBob 2.4s var(--qz-ease) infinite;
}

.qzr-ai-flow__mascot svg { width: 100%; height: 100%; }

.qzr-ai-flow__mascot--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 110px;
  font-size: 3rem;
  color: var(--qz-accent);
}

@keyframes qzrAiBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.qzr-ai-flow__loading-title {
  font-size: var(--qz-fs-h2);
  font-weight: var(--qz-fw-strong);
  color: var(--qz-text);
  margin: 0 0 8px;
}

.qzr-ai-flow__loading-text {
  font-size: var(--qz-fs-sm);
  color: var(--qz-muted);
  max-width: 320px;
  margin: 0 0 24px;
  line-height: 1.5;
}

.qzr-ai-skeleton { width: 100%; max-width: 280px; display: flex; flex-direction: column; gap: 10px; }
.qzr-ai-skeleton span {
  height: 12px;
  border-radius: var(--qz-r-pill);
  background: linear-gradient(90deg, var(--qz-accent-soft) 25%, var(--qz-line) 37%, var(--qz-accent-soft) 63%);
  background-size: 400% 100%;
  animation: qzrAiShimmer 1.4s ease infinite;
}
.qzr-ai-skeleton span:nth-child(2) { width: 80%; }
.qzr-ai-skeleton span:nth-child(3) { width: 60%; }

@keyframes qzrAiShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ── Review (IA-4) ──────────────────────────────────────────────────────── */
.qzr-ai-review-list { display: flex; flex-direction: column; gap: 10px; }

.qzr-ai-review-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px;
  background: var(--qz-surface);
  border: 1px solid var(--qz-line);
  border-radius: var(--qz-r-card);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--qz-dur-press) var(--qz-ease), background var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-review-card.is-selected {
  border-color: var(--qz-accent);
  background: var(--qz-accent-soft);
}

.qzr-ai-review-card__check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 7px;
  border: 1.5px solid var(--qz-line-strong);
  background: var(--qz-surface);
  color: transparent;
  font-size: 12px;
  margin-top: 1px;
  transition: all var(--qz-dur-press) var(--qz-ease);
}

.qzr-ai-review-card.is-selected .qzr-ai-review-card__check {
  background: var(--qz-accent);
  border-color: var(--qz-accent);
  color: var(--qz-on-accent);
}

.qzr-ai-review-card__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.qzr-ai-review-card__q { font-size: var(--qz-fs-body); font-weight: var(--qz-fw-strong); color: var(--qz-text); line-height: 1.35; }
.qzr-ai-review-card__meta { font-size: var(--qz-fs-xs); color: var(--qz-muted); }

/* ── Empty / error ──────────────────────────────────────────────────────── */
.qzr-ai-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--qz-muted);
}

.qzr-ai-empty .fas { font-size: 1.8rem; color: var(--qz-accent); }
.qzr-ai-empty p { font-size: var(--qz-fs-sm); margin: 0; max-width: 300px; }

/* ── Shake (validation) ─────────────────────────────────────────────────── */
.qzr-ai-shake { animation: qzrAiShake 0.4s ease; }
@keyframes qzrAiShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* An independent verification pass disagreed about the correct option. Warning
   colour, not error: the second opinion is the same model and is sometimes the
   one that is wrong — this asks the author to look, it does not assert a fault. */
.qzr-ai-review-card__warn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 3px 9px;
  border-radius: var(--qz-r-pill);
  background: var(--qz-warning-bg);
  color: var(--qz-warning-ink);
  font-size: var(--qz-fs-xs);
  font-weight: 700;
}

/* ===========================================================================
 * MODE AUTONOME — écran de résultat et modale de création de compte
 *
 * La modale vit DANS `.qzr-ai-flow`, au-dessus du panneau, et non à sa place :
 * le quiz généré doit rester visible derrière elle. C'est lui qui justifie
 * l'inscription — la demander sur un écran vide serait la même demande, privée
 * de sa raison.
 * ======================================================================== */

.qzr-ia-modale {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.qzr-ia-modale[hidden] { display: none; }

.qzr-ia-modale__voile {
  position: absolute;
  inset: 0;
  background: rgba(6, 52, 42, 0.55);
  backdrop-filter: blur(2px);
}

.qzr-ia-modale__boite {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  border-radius: var(--qz-r-card);
  background: var(--qz-surface);
  box-shadow: 0 12px 44px rgba(6, 52, 42, 0.28);
  animation: qzrAiRise var(--qz-dur-pop) var(--qz-ease);
}

.qzr-ia-modale__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.qzr-ia-modale__head h3 {
  margin: 0;
  font-size: var(--qz-fs-h3);
  font-weight: 900;
  color: var(--qz-text);
}

.qzr-ia-modale__sub {
  margin: 0 0 16px;
  font-size: var(--qz-fs-sm);
  line-height: 1.45;
  color: var(--qz-muted);
}

/* Sous-titre porteur d’action (modale « garde ton quiz ») : plus present
   que le sous-titre discret par defaut — c’est l’appel a s’inscrire, il
   doit se lire sans effort sous le titre. */
.qzr-ia-modale__sub--cta {
  font-size: var(--qz-fs-body);
  color: var(--qz-text);
}

.qzr-ia-modale__err {
  margin-bottom: 14px;
  padding: 9px 12px;
  border-radius: var(--qz-r-control);
  background: var(--qz-error-bg);
  color: var(--qz-error-ink);
  font-size: var(--qz-fs-sm);
  font-weight: var(--qz-fw-strong);
}

.qzr-ia-modale__cta { width: 100%; }

.qzr-ia-modale__lien {
  width: 100%;
  margin-top: 8px;
  background: none;
  border: 0;
}

/* Un code se lit caractère par caractère : espacer les lettres et fixer la
   chasse évite de confondre O et 0 au moment de le recopier. */
.qzr-ia-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: var(--qz-fs-h3);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-align: center;
  text-transform: uppercase;
}

/* ── L'écran « c'est prêt » ─────────────────────────────────────────────── */

.qzr-ia-fini {
  padding: 22px 4px;
  text-align: center;
}

.qzr-ia-fini__ic {
  font-size: 40px;
  line-height: 1;
  color: var(--qz-success-ink);
}

.qzr-ia-fini__t {
  margin: 14px 0 4px;
  font-size: var(--qz-fs-h3);
  font-weight: 900;
  color: var(--qz-text);
  text-wrap: balance;
  overflow-wrap: break-word;
}

.qzr-ia-fini__s {
  margin: 0;
  font-size: var(--qz-fs-sm);
  color: var(--qz-muted);
}

.qzr-ia-lien { margin-top: 18px; }

/* Le lien est long : il doit être lisible d'un coup d'œil pour qu'on VOIE ce
   que l'on s'apprête à copier, sans se retrouver à faire défiler un champ. */
.qzr-ia-lien .qzr-ai-input {
  font-size: var(--qz-fs-xs);
  text-align: center;
}

/* ── Le choix du type de génération (mode autonome) ──────────────────────
   Trois portes, présentées comme la feuille IA du créateur : c'est la même
   fonctionnalité, elle ne doit pas s'annoncer de deux façons selon le chemin
   emprunté. */

.qzr-ia-sources {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

.qzr-ia-source {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--qz-line);
  border-radius: var(--qz-r-card);
  background: var(--qz-surface);
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: border-color var(--qz-dur-ui) var(--qz-ease), background var(--qz-dur-ui) var(--qz-ease);
}

.qzr-ia-source:hover { border-color: var(--qz-accent); background: var(--qz-accent-soft); }
.qzr-ia-source:active { transform: scale(var(--qz-press-scale)); }

.qzr-ia-source__ic {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--qz-r-control);
  background: var(--qz-accent-soft);
  color: var(--qz-accent-ink);
  font-size: 16px;
}

/* `min-width: 0` : sans lui, une description longue pousse la flèche dehors. */
.qzr-ia-source__txt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.qzr-ia-source__txt strong {
  font-size: var(--qz-fs-body);
  font-weight: 800;
  color: var(--qz-text);
}

.qzr-ia-source__txt small {
  font-size: var(--qz-fs-sm);
  color: var(--qz-muted);
  overflow-wrap: break-word;
}

.qzr-ia-source__go { flex: 0 0 auto; color: var(--qz-muted); }

@media (prefers-reduced-motion: reduce) {
  .qzr-ia-source { transition: none; }
  .qzr-ia-source:active { transform: none; }
}

/* Note d'information en tete de la revue : affichee quand on RE-affiche une
   generation non enregistree (un invite n'en tient qu'une a la fois). Tokens
   pour rester lisible en clair comme en sombre. */
.qzr-ai-flow__note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 10px 16px 0;
  padding: 10px 12px;
  background: var(--qz-accent-soft);
  color: var(--qz-accent-ink, var(--qz-accent));
  border-radius: var(--qz-r-control, 12px);
  font-size: .85rem;
  line-height: 1.4;
}
.qzr-ai-flow__note .fas { margin-top: 2px; opacity: .9; }
