/* =============================================================================
   AI Loader — famille unifiée de loaders de génération IA
   Variantes : orbital · nebula · radar · aurora · spark
   Grammaire commune : stage word animé, progress, subtitle, meta (flows · elapsed)
   Palette : suit var(--accent) — s'adapte au thème utilisateur (light/dark + accent)
   ============================================================================= */

:root,
.ail {
  --ail-accent: var(--accent, #FF7B54);
  --ail-accent-2: var(--accent-hover, #8b5cf6);
  --ail-surface: var(--bg-surface, #fff);
  --ail-surface-alt: var(--bg-primary, #fafafa);
  --ail-border: var(--border-default, rgba(0,0,0,0.08));
  --ail-text: var(--text-primary, #0f172a);
  --ail-text-dim: var(--text-secondary, #64748b);
  --ail-text-faint: var(--text-tertiary, #94a3b8);
  --ail-speed: 1;
}

/* ─── Coque commune ──────────────────────────────────────────────────── */
.ail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 4px 4px;
  text-align: center;
  color: var(--ail-text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  position: relative;
}

.ail-stage {
  position: relative;
  width: 180px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ail-text {
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ail-text);
  position: relative;
  overflow: hidden;
}

.ail-word {
  display: inline-block;
  background: linear-gradient(90deg, var(--ail-text) 0%, var(--ail-accent) 50%, var(--ail-text) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
          background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: ailShimmer 3s linear infinite;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.ail-word.is-leaving { opacity: 0; transform: translateY(-8px); }
.ail-word.is-entering { opacity: 0; transform: translateY(8px); }

.ail-dots {
  display: inline-flex;
  gap: 3px;
  vertical-align: middle;
}
.ail-dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ail-accent);
  animation: ailDot 1.2s ease-in-out infinite;
}
.ail-dots i:nth-child(2) { animation-delay: 0.15s; }
.ail-dots i:nth-child(3) { animation-delay: 0.3s; }

.ail-subtitle {
  font-size: 12px;
  color: var(--ail-text-dim);
  margin: -6px 0 0;
  line-height: 1.5;
  max-width: 420px;
}

.ail-progress {
  width: min(320px, 100%);
  height: 4px;
  background: var(--ail-border);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.ail-progress-bar {
  position: absolute;
  height: 100%;
  width: 40%;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--ail-accent), var(--ail-accent-2), transparent);
  animation: ailProgress 1.8s ease-in-out infinite;
}

.ail-meta {
  font-size: 11px;
  color: var(--ail-text-faint);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.ail-meta-sep { opacity: 0.4; }

/* ─── Modifiers tailles ──────────────────────────────────────────────── */
.ail--compact { gap: 10px; }
.ail--compact .ail-stage { width: 120px; height: 120px; }
.ail--compact .ail-text { font-size: 13px; }
.ail--compact .ail-progress { width: min(240px, 100%); }

.ail--fullscreen {
  gap: 22px;
  padding: 40px 20px;
}
.ail--fullscreen .ail-stage { width: 220px; height: 220px; }
.ail--fullscreen .ail-text { font-size: 18px; }

.ail--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 0;
}
.ail--inline .ail-stage { width: auto; height: 24px; }
.ail--inline .ail-text { font-size: 13px; min-height: 0; }
.ail--inline .ail-progress,
.ail--inline .ail-subtitle,
.ail--inline .ail-meta { display: none; }

/* =============================================================================
   Variante ORBITAL — GrapesJS (référence)
   Une idée qui se cristallise : orbe + halos + 8 sparkles orbitant
   ============================================================================= */
.ail--orbital .ail-orbital {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ail--fullscreen.ail--orbital .ail-orbital { width: 140px; height: 140px; }
.ail--compact.ail--orbital .ail-orbital { width: 80px; height: 80px; }

.ail-orbital-core {
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #ffffff 0%, var(--ail-accent) 45%, transparent 75%),
    conic-gradient(from 0deg,
      var(--ail-accent),
      var(--ail-accent-2),
      #60a5fa,
      #34d399,
      var(--ail-accent));
  filter: blur(0.5px);
  box-shadow:
    0 0 30px 4px var(--ail-accent),
    0 0 60px 8px color-mix(in srgb, var(--ail-accent-2) 35%, transparent),
    inset 0 0 20px rgba(255, 255, 255, 0.4);
  animation: ailOrbSpin 6s linear infinite, ailOrbPulse 2.2s ease-in-out infinite;
}
.ail-orbital-halo {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--ail-accent) 0%, transparent 70%);
  opacity: 0.35;
  filter: blur(14px);
  animation: ailHaloPulse 2.4s ease-in-out infinite;
}
.ail-orbital-halo--2 {
  inset: -10px;
  background: radial-gradient(circle, var(--ail-accent-2) 0%, transparent 65%);
  opacity: 0.22;
  filter: blur(22px);
  animation-duration: 3.2s;
  animation-delay: -1s;
}
.ail-orbital-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  background:
    linear-gradient(var(--ail-surface), var(--ail-surface)) padding-box,
    conic-gradient(from 0deg, transparent 0deg, var(--ail-accent) 90deg, transparent 180deg) border-box;
  animation: ailRingSpin 3.2s linear infinite;
  opacity: 0.9;
}
.ail-orbital-ring--2 {
  inset: -18px;
  background:
    linear-gradient(var(--ail-surface), var(--ail-surface)) padding-box,
    conic-gradient(from 180deg, transparent 0deg, var(--ail-accent-2) 90deg, transparent 180deg) border-box;
  animation: ailRingSpin 5s linear infinite reverse;
  opacity: 0.55;
}
.ail-orbital-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ail-orbital-sparkles span {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--ail-accent) 60%, transparent 100%);
  box-shadow: 0 0 8px 2px var(--ail-accent);
  opacity: 0;
  animation: ailSparkle 2.8s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.35s);
  --angle: 0deg;
}
.ail-orbital-sparkles span:nth-child(1) { --angle: 0deg; }
.ail-orbital-sparkles span:nth-child(2) { --angle: 45deg; }
.ail-orbital-sparkles span:nth-child(3) { --angle: 90deg; }
.ail-orbital-sparkles span:nth-child(4) { --angle: 135deg; }
.ail-orbital-sparkles span:nth-child(5) { --angle: 180deg; }
.ail-orbital-sparkles span:nth-child(6) { --angle: 225deg; }
.ail-orbital-sparkles span:nth-child(7) { --angle: 270deg; }
.ail-orbital-sparkles span:nth-child(8) { --angle: 315deg; }

/* =============================================================================
   Variante NEBULA — Spec (cahier des charges)
   Structuration lente : mesh de gradients qui respirent + étoiles scintillantes
   ============================================================================= */
.ail--nebula .ail-nebula {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  isolation: isolate;
}
.ail-nebula-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(24px);
  mix-blend-mode: screen;
  will-change: transform, opacity;
}
.ail-nebula-blob--1 {
  top: 10%; left: 8%;
  width: 70%; height: 70%;
  background: radial-gradient(circle, var(--ail-accent) 0%, transparent 65%);
  opacity: 0.65;
  animation: ailNebulaDrift1 11s ease-in-out infinite;
}
.ail-nebula-blob--2 {
  top: 22%; right: 4%;
  width: 55%; height: 55%;
  background: radial-gradient(circle, var(--ail-accent-2) 0%, transparent 70%);
  opacity: 0.55;
  animation: ailNebulaDrift2 13s ease-in-out infinite;
}
.ail-nebula-blob--3 {
  bottom: 8%; left: 20%;
  width: 60%; height: 60%;
  background: radial-gradient(circle, #60a5fa 0%, transparent 70%);
  opacity: 0.45;
  animation: ailNebulaDrift3 15s ease-in-out infinite;
}
.ail-nebula-core {
  position: absolute;
  top: 50%; left: 50%;
  width: 44px; height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--ail-accent) 40%, transparent 80%);
  box-shadow: 0 0 30px 8px color-mix(in srgb, var(--ail-accent) 40%, transparent);
  animation: ailNebulaCore 3.4s ease-in-out infinite;
}
.ail-nebula-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ail-nebula-stars i {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 4px 1px #fff;
  opacity: 0;
  animation: ailNebulaStar 3.6s ease-in-out infinite;
}
.ail-nebula-stars i:nth-child(1) { top: 18%; left: 28%; animation-delay: 0s; }
.ail-nebula-stars i:nth-child(2) { top: 32%; left: 72%; animation-delay: 0.8s; }
.ail-nebula-stars i:nth-child(3) { top: 58%; left: 18%; animation-delay: 1.6s; }
.ail-nebula-stars i:nth-child(4) { top: 72%; left: 62%; animation-delay: 2.4s; }
.ail-nebula-stars i:nth-child(5) { top: 26%; left: 52%; animation-delay: 1.2s; }

/* =============================================================================
   Variante RADAR — Devis
   Balayage/détection : sweep conique + blips glow
   ============================================================================= */
.ail--radar .ail-radar {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
}
.ail-radar-ring {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--ail-accent) 22%, transparent);
}
.ail-radar-ring--1 { width: 40%;  height: 40%; }
.ail-radar-ring--2 { width: 68%;  height: 68%; border-color: color-mix(in srgb, var(--ail-accent) 18%, transparent); }
.ail-radar-ring--3 { width: 96%;  height: 96%; border-color: color-mix(in srgb, var(--ail-accent) 12%, transparent); }

.ail-radar-core {
  position: absolute;
  top: 50%; left: 50%;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--ail-accent);
  box-shadow: 0 0 12px 3px color-mix(in srgb, var(--ail-accent) 55%, transparent);
  animation: ailRadarPulse 2s ease-in-out infinite;
}

.ail-radar-sweep {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    color-mix(in srgb, var(--ail-accent) 60%, transparent) 30deg,
    color-mix(in srgb, var(--ail-accent) 30%, transparent) 60deg,
    transparent 90deg,
    transparent 360deg
  );
  animation: ailRadarSweep 3.2s linear infinite;
  mix-blend-mode: screen;
}

.ail-radar-blips {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ail-radar-blips i {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ail-accent);
  box-shadow: 0 0 8px 2px var(--ail-accent);
  opacity: 0;
  animation: ailRadarBlip 3.2s linear infinite;
}
.ail-radar-blips i:nth-child(1) { top: 26%; left: 62%; animation-delay: 0.2s; }
.ail-radar-blips i:nth-child(2) { top: 48%; left: 78%; animation-delay: 0.9s; }
.ail-radar-blips i:nth-child(3) { top: 72%; left: 54%; animation-delay: 1.6s; }
.ail-radar-blips i:nth-child(4) { top: 60%; left: 24%; animation-delay: 2.3s; }
.ail-radar-blips i:nth-child(5) { top: 30%; left: 32%; animation-delay: 2.8s; }

/* =============================================================================
   Variante AURORA — Canvas + générique
   Flux créatif : ruban aurora boréale ondulant + particules qui remontent
   ============================================================================= */
.ail--aurora .ail-aurora {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--ail-accent) 6%, transparent) 0%, transparent 70%);
}
.ail-aurora-ribbon {
  position: absolute;
  inset: -20% -10%;
  background:
    conic-gradient(from 180deg at 50% 50%,
      transparent 0deg,
      color-mix(in srgb, var(--ail-accent) 60%, transparent) 40deg,
      color-mix(in srgb, var(--ail-accent-2) 50%, transparent) 90deg,
      color-mix(in srgb, #60a5fa 45%, transparent) 130deg,
      transparent 200deg,
      transparent 360deg);
  filter: blur(22px);
  mix-blend-mode: screen;
  animation: ailAuroraFlow 9s ease-in-out infinite;
  opacity: 0.85;
}
.ail-aurora-ribbon--2 {
  animation-duration: 13s;
  animation-direction: reverse;
  opacity: 0.55;
  background:
    conic-gradient(from 0deg at 50% 50%,
      transparent 0deg,
      color-mix(in srgb, var(--ail-accent-2) 50%, transparent) 60deg,
      color-mix(in srgb, var(--ail-accent) 55%, transparent) 120deg,
      transparent 200deg,
      transparent 360deg);
}
.ail-aurora-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.ail-aurora-particles i {
  position: absolute;
  bottom: -8px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 6px 2px var(--ail-accent);
  opacity: 0;
  animation: ailAuroraParticle 5s ease-in infinite;
}
.ail-aurora-particles i:nth-child(1) { left: 14%; animation-delay: 0s;   }
.ail-aurora-particles i:nth-child(2) { left: 32%; animation-delay: 0.9s; }
.ail-aurora-particles i:nth-child(3) { left: 48%; animation-delay: 1.8s; }
.ail-aurora-particles i:nth-child(4) { left: 66%; animation-delay: 2.7s; }
.ail-aurora-particles i:nth-child(5) { left: 82%; animation-delay: 3.6s; }
.ail-aurora-particles i:nth-child(6) { left: 54%; animation-delay: 4.5s; }

/* =============================================================================
   Variante SPARK — Coach IA (inline / chat bubble)
   Présence attentive : 5 mini-sparkles scintillant en vague
   ============================================================================= */
.ail--spark .ail-spark {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
}
.ail-spark i {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--ail-accent) 60%, transparent 100%);
  box-shadow: 0 0 6px 1px var(--ail-accent);
  opacity: 0.25;
  animation: ailSparkPulse 1.4s ease-in-out infinite;
}
.ail-spark i:nth-child(1) { animation-delay: 0s; }
.ail-spark i:nth-child(2) { animation-delay: 0.12s; }
.ail-spark i:nth-child(3) { animation-delay: 0.24s; }
.ail-spark i:nth-child(4) { animation-delay: 0.36s; }
.ail-spark i:nth-child(5) { animation-delay: 0.48s; }

/* =============================================================================
   Keyframes partagées
   ============================================================================= */
@keyframes ailShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes ailDot {
  0%, 60%, 100% { transform: translateY(0) scale(0.8); opacity: 0.35; }
  30%           { transform: translateY(-4px) scale(1); opacity: 1; }
}
@keyframes ailProgress {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* Orbital */
@keyframes ailOrbSpin   { to { transform: rotate(360deg); } }
@keyframes ailOrbPulse {
  0%, 100% { transform: scale(1);    filter: blur(0.5px) brightness(1); }
  50%      { transform: scale(1.06); filter: blur(0.5px) brightness(1.15); }
}
@keyframes ailHaloPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.95); }
  50%      { opacity: 0.5;  transform: scale(1.1); }
}
@keyframes ailRingSpin { to { transform: rotate(360deg); } }
@keyframes ailSparkle {
  0%   { transform: rotate(var(--angle)) translateX(35px) scale(0.4); opacity: 0; }
  40%  { transform: rotate(var(--angle)) translateX(70px) scale(1);   opacity: 1; }
  100% { transform: rotate(var(--angle)) translateX(95px) scale(0.2); opacity: 0; }
}

/* Nebula */
@keyframes ailNebulaDrift1 {
  0%, 100% { transform: translate(0, 0)      scale(1);    }
  50%      { transform: translate(12%, 8%)   scale(1.12); }
}
@keyframes ailNebulaDrift2 {
  0%, 100% { transform: translate(0, 0)      scale(1);    }
  50%      { transform: translate(-14%, 10%) scale(1.08); }
}
@keyframes ailNebulaDrift3 {
  0%, 100% { transform: translate(0, 0)       scale(1);    }
  50%      { transform: translate(10%, -12%)  scale(1.15); }
}
@keyframes ailNebulaCore {
  0%, 100% { transform: scale(1);    opacity: 0.85; }
  50%      { transform: scale(1.15); opacity: 1;    }
}
@keyframes ailNebulaStar {
  0%, 100% { opacity: 0; transform: scale(0.6); }
  50%      { opacity: 1; transform: scale(1.3); }
}

/* Radar */
@keyframes ailRadarSweep { to { transform: rotate(360deg); } }
@keyframes ailRadarPulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 0 12px 3px color-mix(in srgb, var(--ail-accent) 55%, transparent); }
  50%      { transform: scale(1.3); box-shadow: 0 0 20px 6px color-mix(in srgb, var(--ail-accent) 70%, transparent); }
}
@keyframes ailRadarBlip {
  0%, 40%  { opacity: 0; transform: scale(0.5); }
  45%      { opacity: 1; transform: scale(1.2); }
  60%      { opacity: 0.7; transform: scale(1); }
  100%     { opacity: 0; transform: scale(0.8); }
}

/* Aurora */
@keyframes ailAuroraFlow {
  0%, 100% { transform: rotate(0deg)  translateX(0) scale(1);    }
  33%      { transform: rotate(4deg)  translateX(3%) scale(1.06); }
  66%      { transform: rotate(-3deg) translateX(-3%) scale(0.97); }
}
@keyframes ailAuroraParticle {
  0%   { opacity: 0; transform: translateY(0)      scale(0.6); }
  15%  { opacity: 1; transform: translateY(-30%)   scale(1);   }
  100% { opacity: 0; transform: translateY(-120%)  scale(0.4); }
}

/* Spark */
@keyframes ailSparkPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

/* =============================================================================
   Reduced motion — calme tout à une pulsation lente d'opacité
   ============================================================================= */
@media (prefers-reduced-motion: reduce) {
  .ail *,
  .ail *::before,
  .ail *::after {
    animation-duration: 6s !important;
    animation-timing-function: ease-in-out !important;
    animation-iteration-count: infinite !important;
  }
  .ail-word {
    animation: none !important;
    -webkit-text-fill-color: var(--ail-text) !important;
    background: none !important;
  }
  .ail-orbital-core,
  .ail-orbital-ring,
  .ail-orbital-sparkles span,
  .ail-radar-sweep,
  .ail-aurora-ribbon {
    animation: ailReducedFade 6s ease-in-out infinite !important;
    transform: none !important;
  }
}
@keyframes ailReducedFade {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1;    }
}
