/* ==========================================================================
   SARAH AI — ASSISTANTE VIRTUELLE & CONVERSATIONNELLE STAR ENTREPRISE
   Intégration fidèle à la capture d'écran + Animation complète de la demoiselle
   Effet de pliage après 3s vers cercle icône recherche
   Interface de saisie parfaitement dégagée (Zéro masquage par les suggestions)
   ========================================================================== */

/* --- Conteneur global du Widget (Fixe au-dessus de la page) --- */
#sarah-widget-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
}

/* --- Bouton flottant Avatar Sarah (Bas Droite) --- */
#sarah-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid #D4AF37;
  box-shadow: 0 8px 28px rgba(11, 31, 58, 0.45), 0 0 0 0 rgba(212, 175, 55, 0.6);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  background: #0B1F3A;
  pointer-events: auto;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s ease;
  opacity: 0;
  transform: translateY(40px) scale(0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Apparition animée après 4 secondes */
#sarah-btn.sarah-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  animation: sarahPopIn 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) forwards,
             sarahFloat 4s ease-in-out 0.8s infinite,
             sarahGoldPulse 3s infinite 1s;
}

#sarah-btn:hover {
  transform: translateY(-4px) scale(1.08) !important;
  box-shadow: 0 12px 34px rgba(11, 31, 58, 0.6), 0 0 20px rgba(212, 175, 55, 0.7);
}

#sarah-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transition: transform 0.4s ease;
}

#sarah-btn:hover img {
  transform: scale(1.1);
}

/* ==========================================================================
   BULLE DE SALUTATION ET CERCLE DE RECHERCHE (#sarah-bubble)
   Apparition après 4s, durée 3s, puis pliage vers petit cercle avec icône recherche
   ========================================================================== */
#sarah-bubble {
  position: absolute;
  bottom: 78px;
  right: 0;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px) scale(0.85);
  transform-origin: bottom right;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-sizing: border-box;
}

/* État 1 : Barre de salutation étendue (Pendant les 3 secondes après apparition) */
#sarah-bubble.sarah-visible.sarah-expanded {
  opacity: 1;
  transform: translateY(0) scale(1);
  width: auto;
  min-width: 280px;
  height: 46px;
  padding: 0 18px;
  border-radius: 23px;
  border-bottom-right-radius: 6px;
  background: #FFFFFF;
  color: #0B1F3A;
  border: 1.5px solid #D4AF37;
  box-shadow: 0 10px 28px rgba(11, 31, 58, 0.25), 0 0 15px rgba(212, 175, 55, 0.2);
}

#sarah-bubble.sarah-expanded:hover {
  background: #0B1F3A;
  color: #FFFFFF;
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 14px 32px rgba(11, 31, 58, 0.35), 0 0 20px rgba(212, 175, 55, 0.4);
}

/* État 2 : Se plie après 3s et devient ce petit cercle avec icône recherche */
#sarah-bubble.sarah-visible.sarah-folded {
  opacity: 1;
  transform: translateY(0) scale(1);
  width: 46px;
  height: 46px;
  min-width: 46px;
  padding: 0;
  border-radius: 50%;
  background: #0B1F3A;
  color: #D4AF37;
  border: 2px solid #D4AF37;
  box-shadow: 0 6px 20px rgba(11, 31, 58, 0.45), 0 0 14px rgba(212, 175, 55, 0.5);
  bottom: 76px;
  right: 8px;
  animation: sarahSearchPulse 2.8s infinite ease-in-out;
}

#sarah-bubble.sarah-folded:hover {
  transform: scale(1.15) rotate(8deg);
  background: #D4AF37;
  color: #0B1F3A;
  box-shadow: 0 8px 24px rgba(11, 31, 58, 0.6), 0 0 22px rgba(212, 175, 55, 0.8);
}

/* Texte de salutation (visible dans l'état étendu, masqué en plié) */
.sarah-bubble-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#sarah-bubble.sarah-folded .sarah-bubble-text {
  display: none;
  opacity: 0;
  transform: scale(0);
}

/* Icône de recherche (masquée en étendu, visible en cercle recherche) */
.sarah-bubble-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#sarah-bubble.sarah-folded .sarah-bubble-icon {
  display: flex;
  opacity: 1;
  transform: scale(1);
}

#sarah-bubble.sarah-folded .sarah-bubble-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform 0.2s ease;
}

/* --- Fenêtre Modale de Chat Sarah (Capture d'écran exacte) --- */
#sarah-modal {
  position: fixed;
  bottom: 104px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 130px);
  height: 640px;
  background: #0B1F3A;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(11, 31, 58, 0.55), 0 0 1px 1px rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000000;
  opacity: 0;
  pointer-events: none;
  transform: translateY(28px) scale(0.94);
  transform-origin: bottom right;
  transition: opacity 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#sarah-modal.sarah-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* --- En-tête avec portrait animé de Sarah --- */
#sarah-header {
  position: relative;
  height: 225px;
  background: #0B1F3A;
  overflow: hidden;
  flex-shrink: 0;
}

#sarah-header-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  /* Animation de respiration/vie de la demoiselle */
  animation: sarahBreathe 5s ease-in-out infinite;
}

/* Halo doré subtil derrière Sarah */
#sarah-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(212, 175, 55, 0.25) 0%, transparent 70%);
  animation: sarahGoldenAura 4s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 1;
}

/* Badge identité gauche (★ Sarah + Assistante 🟢) */
#sarah-header-badge {
  position: absolute;
  top: 16px;
  left: 18px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(11, 31, 58, 0.75);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.sarah-name {
  font-size: 15px;
  font-weight: 800;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sarah-star {
  color: #D4AF37;
  font-size: 14px;
}

.sarah-role {
  font-size: 12px;
  color: #E2E8F0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.sarah-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22C55E;
  display: inline-block;
  box-shadow: 0 0 8px #22C55E;
  animation: sarahPulseGreen 2s infinite;
}

/* Bouton Fermer (X) Haut Droite */
#sarah-close-btn {
  position: absolute;
  top: 16px;
  right: 18px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(11, 31, 58, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

#sarah-close-btn:hover {
  background: #D4AF37;
  color: #0B1F3A;
  transform: rotate(90deg);
}

/* --- Corps de discussion Blanc --- */
#sarah-body {
  background: #FFFFFF;
  border-radius: 24px 24px 0 0;
  margin-top: -24px;
  position: relative;
  z-index: 4;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 24px rgba(11, 31, 58, 0.15);
}

/* Zone de défilement des messages (Les chips de suggestions sont placés ici, sous l'accueil, pour ne JAMAIS masquer la barre de saisie en bas !) */
#sarah-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Style des Bulles de messages */
.sarah-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: sarahMsgSlideIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sarah-msg.sarah-bot {
  align-self: flex-start;
}

.sarah-msg.sarah-user {
  align-self: flex-end;
}

.sarah-msg-content {
  padding: 14px 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

/* Message Bot Sarah */
.sarah-msg.sarah-bot .sarah-msg-content {
  background: #F3F5F8;
  color: #0B1F3A;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid #E6EAEF;
}

/* Message Utilisateur */
.sarah-msg.sarah-user .sarah-msg-content {
  background: #0B1F3A;
  color: #FFFFFF;
  border-radius: 18px 18px 4px 18px;
}

.sarah-msg-content b, .sarah-msg-content strong {
  font-weight: 800;
  color: #0B1F3A;
}

.sarah-msg.sarah-user .sarah-msg-content b,
.sarah-msg.sarah-user .sarah-msg-content strong {
  color: #D4AF37;
}

/* Boutons de redirection dans les réponses Sarah */
.sarah-link-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #D4AF37, #C59B27);
  color: #0B1F3A !important;
  font-weight: 700;
  font-size: 13px;
  border-radius: 20px;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.sarah-link-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(212, 175, 55, 0.45);
}

/* --- Chips / Boutons de questions rapides (Intégrés dans la zone de message, sous l'accueil) --- */
#sarah-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 8px;
  margin-top: -4px;
}

.sarah-chip {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  color: #0B1F3A;
  padding: 8px 15px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  white-space: nowrap;
}

.sarah-chip:hover {
  background: #FFFDF5;
  border-color: #D4AF37;
  color: #0B1F3A;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(212, 175, 55, 0.15);
}

/* --- Animation indicateur d'écriture (Sarah écrit...) --- */
.sarah-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  background: #F3F5F8;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid #E6EAEF;
  width: fit-content;
}

.sarah-dot-anim {
  width: 7px;
  height: 7px;
  background: #0B1F3A;
  border-radius: 50%;
  animation: sarahDots 1.4s infinite ease-in-out both;
}

.sarah-dot-anim:nth-child(1) { animation-delay: -0.32s; }
.sarah-dot-anim:nth-child(2) { animation-delay: -0.16s; }

/* --- Footer Barre de Saisie (En bas, totalement dégagé et accessible) --- */
#sarah-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: #FFFFFF;
  border-top: 1px solid #E7ECEF;
  box-shadow: 0 -4px 16px rgba(11, 31, 58, 0.05);
  flex-shrink: 0;
  z-index: 10;
}

#sarah-input {
  flex: 1;
  border: 1.5px solid #CBD5E1;
  border-radius: 26px;
  padding: 12px 18px;
  font-size: 16px; /* 16px minimum : empêche le zoom automatique iOS qui cachait l'interface */
  color: #0B1F3A;
  background: #F8FAFC;
  outline: none;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  font-family: 'Manrope', sans-serif;
}

#sarah-input:focus {
  border-color: #D4AF37;
  background: #FFFFFF;
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
}

#sarah-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #D4AF37;
  color: #0B1F3A;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.35);
  flex-shrink: 0;
}

#sarah-send-btn:hover {
  background: #E5C354;
  transform: scale(1.06);
  box-shadow: 0 6px 16px rgba(212, 175, 55, 0.5);
}

#sarah-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  transform: translateX(1px);
}

/* --- RESPONSIVE MOBILE & TV --- */
@media (max-width: 600px) {
  #sarah-modal {
    width: calc(100vw - 20px);
    right: 10px;
    bottom: 90px;
    height: 560px;
    max-height: calc(100vh - 100px);
    /* Correctif mobile : s'adapte quand le clavier du téléphone s'ouvre */
    max-height: calc(100dvh - 100px);
  }
  #sarah-btn {
    width: 60px;
    height: 60px;
    bottom: 18px;
    right: 18px;
  }
  #sarah-bubble.sarah-folded {
    bottom: 68px;
    right: 6px;
  }
}

@media (min-width: 1600px) {
  #sarah-modal {
    width: 420px;
    height: 680px;
  }
}

/* ==========================================================================
   KEYFRAME ANIMATIONS — LA DEMOISELLE ANIMÉE & PLIAGE CERCLE RECHERCHE
   ========================================================================== */

@keyframes sarahPopIn {
  0% {
    opacity: 0;
    transform: translateY(40px) scale(0.6);
  }
  65% {
    transform: translateY(-8px) scale(1.08);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes sarahBreathe {
  0%, 100% {
    transform: scale(1) translateY(0);
  }
  50% {
    transform: scale(1.035) translateY(-4px);
  }
}

@keyframes sarahGoldenAura {
  0% {
    opacity: 0.5;
    transform: scale(0.95);
  }
  100% {
    opacity: 0.95;
    transform: scale(1.05);
  }
}

@keyframes sarahPulseGreen {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

@keyframes sarahGoldPulse {
  0% {
    box-shadow: 0 8px 28px rgba(11, 31, 58, 0.45), 0 0 0 0 rgba(212, 175, 55, 0.6);
  }
  70% {
    box-shadow: 0 8px 28px rgba(11, 31, 58, 0.45), 0 0 0 16px rgba(212, 175, 55, 0);
  }
  100% {
    box-shadow: 0 8px 28px rgba(11, 31, 58, 0.45), 0 0 0 0 rgba(212, 175, 55, 0);
  }
}

@keyframes sarahSearchPulse {
  0%, 100% {
    box-shadow: 0 6px 20px rgba(11, 31, 58, 0.45), 0 0 12px rgba(212, 175, 55, 0.5);
  }
  50% {
    box-shadow: 0 6px 24px rgba(11, 31, 58, 0.6), 0 0 22px rgba(212, 175, 55, 0.85);
  }
}

@keyframes sarahMsgSlideIn {
  0% {
    opacity: 0;
    transform: translateY(12px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sarahDots {
  0%, 80%, 100% {
    transform: scale(0.4);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

#sarah-mic-btn {
  background: transparent;
  color: #0B1F3A;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
}
#sarah-mic-btn:hover {
  background: rgba(212, 175, 55, 0.15);
  color: #D4AF37;
}
#sarah-mic-btn.is-recording {
  background: #EF4444 !important;
  color: #fff !important;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.7);
  animation: sarahMicPulse 1s infinite;
}
@keyframes sarahMicPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(239, 68, 68, 0.7); }
  50% { transform: scale(1.12); box-shadow: 0 0 18px rgba(239, 68, 68, 1); }
}

#sarah-header-img.is-speaking {
  box-shadow: 0 0 16px #D4AF37, 0 0 24px rgba(212, 175, 55, 0.8) !important;
  border-color: #D4AF37 !important;
  animation: sarahSpeakingPulse 1.2s infinite;
}
@keyframes sarahSpeakingPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 12px #D4AF37; }
  50% { transform: scale(1.08); box-shadow: 0 0 24px #E5C354; }
}

@keyframes sarahCallPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 10px rgba(212, 175, 55, 0.6); }
  50% { transform: scale(1.1); box-shadow: 0 0 20px rgba(212, 175, 55, 1); }
}

/* ==========================================================================
   100% MOBILE RESPONSIVE INPUT BAR (#sarah-footer)
   - Garantie d'affichage parfait sur n'importe quel téléphone (iPhone, Android, petit écran)
   - Champ de saisie dégagé et boutons micro/envoi/haut-parleur parfaitement ajustés
   ========================================================================== */
#sarah-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #fff;
  border-top: 1px solid #E2E8F0;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}
#sarah-input {
  flex: 1;
  min-width: 0;
  border: 1px solid #CBD5E1;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 16px; /* 16px minimum : empêche le zoom automatique iOS qui cachait l'interface */
  color: #0B1F3A;
  outline: none;
  background: #F8FAFC;
  transition: border-color 0.2s, background 0.2s;
}
#sarah-input:focus {
  border-color: #D4AF37;
  background: #fff;
}
#sarah-mic-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sarah-send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #0B1F3A;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
}
#sarah-send-btn:hover {
  background: #D4AF37;
  color: #0B1F3A;
  transform: scale(1.05);
}
#sarah-send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

@media (max-width: 480px) {
  #sarah-footer {
    padding: 8px 10px;
    gap: 4px;
  }
  #sarah-input {
    font-size: 16px; /* 16px minimum : empêche le zoom iOS qui cachait l'interface */
    padding: 9px 12px;
  }
  #sarah-mic-btn {
    width: 32px;
    height: 32px;
  }
  #sarah-mic-btn svg {
    width: 16px;
    height: 16px;
  }
  #sarah-send-btn {
    width: 34px;
    height: 34px;
  }
}
