/* ═══════════════════════════════════════════════════════════════
   SERAPH — Styles complets
   1. Widget Live2D fixe (haut-droite, sous le header)
   2. Bulle de dialogue
   3. État en veille (icône cliquable)
   4. Responsive (tablette + mobile)
   5. Icône SVG inline (remplace les 🤖 dans les blocs SERAPH)
═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────
   1. WIDGET LIVE2D FIXE
─────────────────────────────────────────────────────────────── */

#seraph-widget {
  /* Variables internes :
     - overflow : combien le widget déborde à droite hors viewport
     - top-shift : combien le widget chevauche vers le haut (sous le header)
     Les enfants positionnés à droite/haut doivent compenser pour rester
     visibles dans le viewport. */
  --seraph-overflow: 60px;
  --seraph-top-shift: 65px;

  position: fixed;
  top: calc(var(--header-h, 85px) - var(--seraph-top-shift));
  right: calc(-1 * var(--seraph-overflow));
  width: 280px;
  height: 340px;
  /* overflow: visible pour que les propulseurs latéraux du robot
     puissent dépasser légèrement les bornes du widget si besoin */
  overflow: visible;
  /* z-index calibré pour passer SOUS le header (99999) et l'overlay recherche (100000),
     mais au-dessus du contenu standard */
  z-index: 100;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  /* Isolation composite + promotion GPU pour ne pas être capturé par les filtres globaux */
  isolation: isolate;
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  transition:
    opacity 0.4s ease,
    transform 0.4s ease,
    width 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    right 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

#seraph-widget.seraph-hidden {
  opacity: 0;
  transform: translateX(40px);
  pointer-events: none !important;
}

#seraph-canvas {
  width: 100%;
  height: 100%;
  pointer-events: auto;
  cursor: pointer;
  display: block;
  touch-action: none; /* bloque scroll/pinch sur le canvas */
  transform: scale(1);
  filter: blur(0);
  visibility: visible;
  /* Transition holographique : scale + fade + flou qui se dissipe */
  transition:
    opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0s;
}

/* Halo / aura derrière le robot.
   Le robot est positionné à 28% de la largeur (voir fitModel dans le JS).
   Halo rond centré sur ce point : on utilise width + aspect-ratio 1 + left+top
   pour avoir un cercle parfait quelle que soit la taille du widget. */
#seraph-widget::before {
  content: '';
  position: absolute;
  width: 55%;
  aspect-ratio: 1 / 1;
  left: 28%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(
    circle at center,
    rgba(0, 170, 255, 0.45) 0%,
    rgba(0, 170, 255, 0.2) 40%,
    transparent 70%
  );
  filter: blur(20px);
  z-index: -1;
  pointer-events: none;
  animation: seraph-aura 4s ease-in-out infinite;
}

@keyframes seraph-aura {
  0%, 100% { opacity: 0.85; transform: translate(-50%, -50%) scale(1); }
  50%      { opacity: 1;    transform: translate(-50%, -50%) scale(1.05); }
}

/* ───────────────────────────────────────────────────────────────
   2. BOUTON DE MISE EN VEILLE (icône lune)
─────────────────────────────────────────────────────────────── */

#seraph-toggle {
  position: absolute;
  /* Compense le décalage vertical du widget pour rester sous le header */
  top: calc(var(--seraph-top-shift, 65px) + 12px);
  /* Compense le débordement horizontal du widget pour rester dans le viewport */
  right: calc(var(--seraph-overflow, 60px) + 12px);
  width: 30px;
  height: 30px;
  border: 1px solid rgba(138, 208, 255, 0.25);
  background: rgba(10, 15, 25, 0.55);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.25s ease, transform 0.25s ease, border-color 0.25s ease;
  z-index: 25;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue, #0af);
  pointer-events: auto;
}

#seraph-toggle svg {
  width: 15px;
  height: 15px;
}

#seraph-widget:hover #seraph-toggle,
#seraph-toggle:hover,
#seraph-toggle:focus-visible {
  opacity: 1;
  transform: scale(1.08);
  border-color: rgba(138, 208, 255, 0.7);
  outline: none;
}

/* ───────────────────────────────────────────────────────────────
   3. BULLE DE DIALOGUE
─────────────────────────────────────────────────────────────── */

#seraph-bubble {
  position: absolute;
  top: 50%;
  right: 100%;
  width: max-content;
  max-width: 280px;
  min-width: 140px;
  padding: 0.55rem 0.75rem;
  background: rgba(4, 8, 16, 0.96);
  border: 1px solid var(--blue, #0af);
  border-radius: 4px;
  color: var(--text, #c8dff5);
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateY(-50%) translateX(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  box-shadow: 0 0 18px var(--blue-glow, rgba(0,170,255,0.18));
  white-space: normal;
  z-index: 2;
  box-sizing: border-box;
}

#seraph-bubble::before {
  content: '';
  position: absolute;
  top: 50%;
  right: -5px;
  transform: translateY(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: rgba(4, 8, 16, 0.96);
  border-right: 1px solid var(--blue, #0af);
  border-top: 1px solid var(--blue, #0af);
}

#seraph-bubble.seraph-bubble-visible {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Zone label — masquée par défaut (le JS gère son affichage) */
#seraph-bubble .seraph-bubble-label {
  display: none;
}

/* ───────────────────────────────────────────────────────────────
   4. ÉTAT EN VEILLE (icône endormie cliquable)
─────────────────────────────────────────────────────────────── */

#seraph-asleep {
  display: flex; /* toujours flex pour permettre l'animation (opacity au lieu de display) */
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.6);
  filter: blur(6px);
  z-index: 30;
  pointer-events: none; /* pas cliquable quand invisible */
  transition:
    opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

#seraph-asleep:focus-visible {
  outline: none;
}

#seraph-asleep img,
#seraph-asleep svg {
  width: 55%;
  height: 55%;
  max-width: 110px;
  max-height: 110px;
  min-width: 56px;
  min-height: 56px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 0 10px rgba(138, 208, 255, 0.45));
  animation: seraph-breathe 3s ease-in-out infinite;
  transition: transform 0.25s ease, filter 0.25s ease;
}

@keyframes seraph-breathe {
  0%, 100% { opacity: 1; transform: scale(0.97); }
  50%      { opacity: 1; transform: scale(1.03); }
}

/* ── ÉTAT MINIMISÉ : transitions douces (pas de display:none brutal) ── */
/* Le widget lui-même rétrécit à la taille exacte de l'image de veille,
   avec une transition fluide sur width/height/position. */
#seraph-widget.seraph-minimized {
  /* Plus de débordement / décalage quand minimisé : l'icône doit être entièrement visible */
  --seraph-overflow: 0px;
  --seraph-top-shift: -10px;
  width: 80px;
  height: 80px;
  top: calc(var(--header-h, 85px) - var(--seraph-top-shift));
  right: 8px;
  transition:
    width 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    right 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.4s ease,
    transform 0.4s ease;
}

/* Canvas, bulle, toggle et halo : fade+scale+blur au lieu de display:none.
   Plus fluide à l'œil, et ça évite la rupture brute.
   `visibility: hidden` après la fin de la transition pour vraiment le retirer
   (évite les fantômes GPU du canvas toujours rendu). */
#seraph-widget.seraph-minimized #seraph-canvas {
  opacity: 0;
  transform: scale(0.75);
  filter: blur(8px);
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.35s ease,
    transform 0.35s ease,
    filter 0.35s ease,
    visibility 0s linear 0.35s;
}

#seraph-widget.seraph-minimized #seraph-bubble,
#seraph-widget.seraph-minimized #seraph-toggle {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

#seraph-widget.seraph-minimized::before {
  opacity: 0;
  animation: none;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

#seraph-widget.seraph-minimized #seraph-asleep {
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  pointer-events: auto;
  visibility: visible;
}

/* L'icône prend toute la place dispo quand minimisée */
#seraph-widget.seraph-minimized #seraph-asleep img,
#seraph-widget.seraph-minimized #seraph-asleep svg {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

#seraph-widget.seraph-minimized #seraph-asleep:hover img,
#seraph-widget.seraph-minimized #seraph-asleep:focus-visible img,
#seraph-widget.seraph-minimized #seraph-asleep:hover svg,
#seraph-widget.seraph-minimized #seraph-asleep:focus-visible svg {
  filter: drop-shadow(0 0 16px rgba(138, 208, 255, 0.8));
  transform: scale(1.05);
}

/* Apparition progressive du canvas au chargement —
   effet "matérialisation holographique" : scale up + fade + flou qui se dissipe */
#seraph-widget[data-ready="false"] #seraph-canvas {
  opacity: 0;
  transform: scale(0.88);
  filter: blur(8px);
}

#seraph-widget[data-ready="true"] #seraph-canvas {
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  transition:
    opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.8s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ───────────────────────────────────────────────────────────────
   5. RESPONSIVE
   Note : top suit automatiquement --header-h qui est défini dans
   header.css et s'adapte à chaque breakpoint. Pas besoin de
   redéfinir top/right ici, sauf pour des ajustements fins.
─────────────────────────────────────────────────────────────── */

/* Tablette */
@media (max-width: 1024px) {
  #seraph-widget {
    --seraph-overflow: 45px;
    --seraph-top-shift: 50px;
    width: 240px;
    height: 290px;
  }
  #seraph-widget.seraph-minimized {
    --seraph-overflow: 0px;
    --seraph-top-shift: -10px;
    width: 72px;
    height: 72px;
    right: 6px;
  }
  #seraph-bubble {
    max-width: 200px;
    font-size: 0.68rem;
  }
}

/* Mobile — SERAPH visible, en coin haut-droite (sous le header, au-dessus du widget phone) */
@media (max-width: 768px) {
  #seraph-widget {
    --seraph-overflow: 30px;
    --seraph-top-shift: 35px;
    /* Élargi de 150 → 180 pour donner plus d'espace au robot et éviter la coupe à gauche */
    width: 180px;
    height: 200px;
  }
  #seraph-widget.seraph-minimized {
    --seraph-overflow: 0px;
    --seraph-top-shift: -10px;
    width: 60px;
    height: 60px;
    right: 4px;
  }
  #seraph-toggle {
    width: 26px;
    height: 26px;
    top: calc(var(--seraph-top-shift, 35px) + 6px);
    right: calc(var(--seraph-overflow, 30px) + 6px);
  }
  #seraph-toggle svg {
    width: 13px;
    height: 13px;
  }
  /* Bulle : à gauche du robot, au niveau de ses yeux, étroite */
  #seraph-bubble {
    top: 50%;
    right: 100%;
    bottom: auto;
    left: auto;
    transform: translateY(-50%) translateX(10px);
    max-width: 140px;
    min-width: 100px;
    font-size: 0.68rem;
    padding: 0.45rem 0.6rem;
  }
  #seraph-bubble::before {
    top: 50%;
    right: -5px;
    bottom: auto;
    transform: translateY(-50%) rotate(45deg);
  }
  #seraph-bubble.seraph-bubble-visible {
    transform: translateY(-50%) translateX(0);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #seraph-widget::before { animation: none; }
  #seraph-asleep img,
  #seraph-asleep svg { animation: none; }
  #seraph-widget #seraph-canvas,
  #seraph-widget #seraph-bubble,
  #seraph-widget #seraph-toggle,
  #seraph-widget #seraph-asleep { transition: none; }
}


/* ───────────────────────────────────────────────────────────────
   6. ICÔNE IMAGE INLINE (remplace les 🤖)
   Source : /images/SeraphIA.png
─────────────────────────────────────────────────────────────── */

.seraph-icon-img {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  object-fit: contain;
  /* Léger halo bleu pour matcher la charte cyberpunk */
  filter: drop-shadow(0 0 4px var(--blue-glow, rgba(0,170,255,0.18)));
  transition: filter 0.3s ease, transform 0.3s ease;
  /* Ratio natif : 345×392 (préservé via width/height en attributs HTML) */
  height: auto;
  max-width: none;
  animation: seraph-icon-pulse 3s ease-in-out infinite;
}

/* Classes utilitaires — hauteur uniquement, largeur automatique via ratio */
.seraph-icon-img.seraph-icon-sm { height: 22px; width: auto; }
.seraph-icon-img.seraph-icon-md { height: 32px; width: auto; }
.seraph-icon-img.seraph-icon-lg { height: 44px; width: auto; }
.seraph-icon-img.seraph-icon-xl { height: 60px; width: auto; }

/* Pulsation subtile du halo (effet "IA active") */
@keyframes seraph-icon-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px var(--blue-glow, rgba(0,170,255,0.18))); }
  50%      { filter: drop-shadow(0 0 8px rgba(0,170,255,0.35)); }
}

/* Hover plus prononcé quand l'icône est dans un lien/bouton */
a:hover > .seraph-icon-img,
button:hover > .seraph-icon-img {
  transform: scale(1.08);
  filter: drop-shadow(0 0 10px rgba(0,170,255,0.5));
}

/* Conteneurs existants : s'assurer que l'image se place proprement */
.seraph-icon,
.seraph-bloc-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* On neutralise le font-size de l'emoji 🤖 précédent */
  font-size: 0;
  line-height: 0;
}

@media (prefers-reduced-motion: reduce) {
  .seraph-icon-img {
    animation: none;
  }
}
