/* ============================================================
   FENÊTRE DE DISCUSSION
   ============================================================
   Feuille séparée de style.css : la discussion est un module
   autonome, présent sur toutes les pages mais indépendant de
   la mise en page du site. */

#chat-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#chat-lanceur {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #6366f1 0%, #3949ab 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(57, 73, 171, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .15s, opacity .15s;
}

#chat-lanceur:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 22px rgba(57, 73, 171, .45);
}

/* Le bouton reste visible quand la fenêtre est ouverte : c'est lui
   qui permet de la réduire, comme sur la plupart des messageries. */
.chat-icone { display: block; }
.chat-icone--reduire { display: none; }

.chat-widget--ouvert .chat-icone--bulle   { display: none; }
.chat-widget--ouvert .chat-icone--reduire { display: block; }

/* Ouverte, la fenêtre se place au-dessus du bouton plutôt que
   par-dessus : le bouton conserve sa place et son rôle. */
.chat-widget--ouvert #chat-fenetre { bottom: 68px; }

/* Masquée par défaut. Une classe et non l'attribut hidden : celui-ci
   serait sans effet face au display défini ici, et la fenêtre
   s'ouvrirait dès le chargement de la page. */
#chat-fenetre {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 100px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(30, 27, 75, .22);
  flex-direction: column;
  overflow: hidden;
}

#chat-fenetre.chat-fenetre--ouverte { display: flex; }

#chat-entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #3730a3 0%, #3949ab 100%);
  color: #fff;
  flex-shrink: 0;
}

/* Même line-height que le bouton : les deux boîtes de texte se
   centrent alors sur la même ligne, ce que align-items seul ne
   garantit pas quand les hauteurs de ligne diffèrent.
   Le titre cède la place en premier (min-width: 0 + ellipse) : c'est
   lui le texte redondant sur petit écran, pas le bouton d'accès aux
   conversations. */
#chat-titre {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-fermer {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  opacity: .8;
  padding: 0 4px;
}

#chat-fermer:hover { opacity: 1; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9fafb;
}

.chat-bulle {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bulle--visiteur {
  align-self: flex-end;
  background: #3949ab;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bulle--assistant {
  align-self: flex-start;
  background: #fff;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

/* Réponse humaine : distinguée visuellement de l'assistant, pour
   que le visiteur sache qu'une personne lui répond. */
.chat-bulle--admin {
  align-self: flex-start;
  background: #eef2ff;
  color: #312e81;
  border: 1px solid #c7d2fe;
  border-bottom-left-radius: 4px;
}

.chat-bulle--attente { opacity: .5; font-style: italic; }

#chat-saisie {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

#chat-texte {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 90px;
}

#chat-texte:focus { border-color: #3949ab; }

#chat-envoyer {
  width: 38px;
  border: none;
  border-radius: 8px;
  background: #3949ab;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

#chat-envoyer:hover { background: #312e81; }

#chat-demander-humain {
  border: none;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  color: #3730a3;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

#chat-demander-humain:hover { background: #eef2ff; }

/* Masquage générique, sans dépendre de l'attribut hidden. */
.chat-masque { display: none !important; }

/* Révélée seulement après clic sur « Parler à quelqu'un ». */
#chat-escalade { display: none; }

#chat-escalade.chat-escalade--visible {
  display: block;
}

#chat-escalade {
  padding: 12px;
  background: #eef2ff;
  border-top: 1px solid #c7d2fe;
  flex-shrink: 0;
}

/* La croix est alignée en haut du texte, pas centrée : sur deux
   lignes, un centrage la ferait flotter au milieu du paragraphe. */
#chat-escalade-entete {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

#chat-escalade p {
  font-size: 13px;
  color: #312e81;
  margin: 0;
  flex: 1;
}

#chat-escalade-annuler {
  border: none;
  background: transparent;
  color: #4338ca;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: .7;
  flex-shrink: 0;
}

#chat-escalade-annuler:hover { opacity: 1; }

#chat-escalade-ligne { display: flex; gap: 8px; }

#chat-email {
  flex: 1;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

#chat-email:focus { border-color: #3949ab; }

#chat-escalade-valider {
  border: none;
  border-radius: 8px;
  background: #3949ab;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Sur petit écran, la fenêtre occupe tout l'espace : une bulle
   flottante y serait trop à l'étroit pour lire confortablement. */
@media (max-width: 480px) {
  #chat-widget { right: 14px; bottom: 14px; }

  /* Presque plein écran, mais pas tout à fait : une bande reste
     visible en haut, qui rappelle qu'il y a une page derrière et
     évite l'impression d'être enfermé dans la fenêtre. */
  .chat-widget--ouvert #chat-fenetre {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: 56px;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
    border-radius: 14px 14px 0 0;
  }

  /* Le bouton rond passerait sous la fenêtre : sur mobile, c'est la
     croix de l'en-tête qui referme, et elle est agrandie pour être
     confortable au pouce. */
  .chat-widget--ouvert #chat-lanceur { display: none; }

  #chat-fermer { font-size: 20px; padding: 4px 8px; }
}

/* Avertissement technique : ni une réponse de l'assistant, ni un
   message humain. Le ton visuel doit dire « quelque chose n'a pas
   fonctionné » sans alarmer - le visiteur n'y est pour rien. */
.chat-bulle--systeme {
  align-self: center;
  max-width: 92%;
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

/* ------------------------------------------------------------
   BANDEAU D'ÉTAT
   ------------------------------------------------------------
   Indique que le fil est passé en traitement humain. Un bandeau
   plutôt qu'une bulle : il ne se répète pas à chaque envoi et ne
   remonte pas dans l'historique. */

#chat-bandeau { display: none; }

.chat-bandeau--visible {
  display: block !important;
  padding: 8px 12px;
  background: #fffbeb;
  border-top: 1px solid #fde68a;
  color: #92400e;
  font-size: 12.5px;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
}

/* Une fois l'échange engagé avec une personne, le ton passe du
   rappel d'attente à la simple information. */
.chat-bandeau--suivi {
  background: #eef2ff;
  border-top-color: #c7d2fe;
  color: #3730a3;
}

/* ------------------------------------------------------------
   ACCUEIL
   ------------------------------------------------------------
   Occupe l'espace vide avant le premier échange. Ce n'est pas une
   bulle de conversation : rien n'a encore été dit, et ce texte
   n'est jamais enregistré. */

.chat-accueil {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 28px 20px;
  text-align: center;
  margin: auto 0;
}

.chat-accueil-salut {
  font-size: 20px;
  font-weight: 700;
  color: #1e1b4b;
}

/* Un léger salut de la main, discret : trois allers-retours puis
   l'animation s'arrête, pour ne pas capter l'attention en continu. */
.chat-accueil-main {
  display: inline-block;
  animation: chat-coucou 1.6s ease-in-out 3;
  transform-origin: 70% 80%;
}

@keyframes chat-coucou {
  0%, 60%, 100% { transform: rotate(0deg); }
  20%           { transform: rotate(16deg); }
  40%           { transform: rotate(-8deg); }
}

/* Respect du réglage système : certaines personnes désactivent les
   animations, il n'y a aucune raison de passer outre. */
@media (prefers-reduced-motion: reduce) {
  .chat-accueil-main { animation: none; }
}

.chat-accueil-question {
  font-size: 15px;
  font-weight: 600;
  color: #374151;
}

.chat-accueil-precision {
  font-size: 12.5px;
  color: #9ca3af;
  line-height: 1.5;
  max-width: 240px;
  margin: 4px auto 0;
}

/* Conversation archivée : ton neutre, l'échange est terminé sans
   qu'il y ait rien à signaler. */
.chat-bandeau--clos {
  background: #f3f4f6;
  border-top-color: #e5e7eb;
  color: #6b7280;
}

/* Le gras produit par le modèle. */
.chat-bulle strong { font-weight: 700; }

/* ============================================================
   Historique des conversations et notation
   ============================================================ */

/* Bouton d'historique dans l'en-tête, à côté de la croix.
   Une icône seule n'était pas comprise : le libellé « Conversations »
   dit ce que le bouton fait, et la forme de pastille le distingue du
   titre sans l'imiter. */
#chat-historique-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: inherit;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

#chat-historique-btn:hover {
  background: rgba(255, 255, 255, .24);
  border-color: rgba(255, 255, 255, .55);
}

/* Sous 380 px, le libellé cède la place : l'icône seule reste, avec
   son infobulle et son libellé accessible. Le seuil a été relevé de
   340 à 380 px en même temps que la police passait de 12 à 15 px -
   le bouton occupe désormais assez de largeur pour que le titre soit
   tronqué sur un téléphone étroit. */
@media (max-width: 380px) {
  #chat-historique-btn span { display: none; }
  #chat-historique-btn { padding: 5px 8px; }
}

/* Sortie d'un fil archivé. Placé sous le bandeau « conversation
   terminée », là où se trouve la zone de saisie sur un fil actif. */
#chat-nouvelle-question {
  border: none;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  color: #3730a3;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  flex-shrink: 0;
  width: 100%;
}

#chat-nouvelle-question:hover { background: #eef2ff; }

/* --- Liste des conversations -------------------------------- */
/* Masquée par défaut ; la classe posée sur la fenêtre l'échange
   avec le fil de messages. */
#chat-liste { display: none; }

.chat-fenetre--liste #chat-liste {
  display: block;
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f8fafc;
}

/* #chat-liste-pied est volontairement ABSENT de cette liste : il fait
   partie de la vue liste, pas de la vue conversation. */
.chat-fenetre--liste #chat-messages,
.chat-fenetre--liste #chat-bandeau,
.chat-fenetre--liste #chat-avis,
.chat-fenetre--liste #chat-saisie,
.chat-fenetre--liste #chat-escalade,
.chat-fenetre--liste #chat-nouvelle-question,
.chat-fenetre--liste #chat-demander-humain { display: none !important; }

#chat-liste-titre {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #312e81;
}

.chat-liste-entree {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: inherit;
}

.chat-liste-entree:hover { border-color: #a5b4fc; background: #eef2ff; }

.chat-liste-entree--courante { border-color: #6366f1; }

.chat-liste-entree-titre {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-liste-entree-meta {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: #6b7280;
}

.chat-liste-entree--courante .chat-liste-entree-meta { color: #4338ca; }

/* Ferme visuellement la liste par le bas, là où une conversation a sa
   barre de saisie. Sans ce repère, la zone vide sous les entrées
   n'avait pas de fin lisible. */
#chat-liste-pied {
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  flex-shrink: 0;
}

/* --- Lecture seule d'un fil passé ---------------------------- */
/* Le fil se relit mais ne se poursuit pas : ni saisie, ni demande
   de contact, ni encart d'adresse email. */
.chat-fenetre--lecture #chat-saisie,
.chat-fenetre--lecture #chat-escalade,
.chat-fenetre--lecture #chat-demander-humain { display: none !important; }

/* --- Encadré de notation (cinq smileys) ---------------------- */
#chat-avis { display: none; }

#chat-avis.chat-avis--visible {
  display: block;
  padding: 12px;
  background: #fefce8;
  border-top: 1px solid #fde68a;
  flex-shrink: 0;
  text-align: center;
}

#chat-avis-titre {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: #92400e;
}

#chat-avis-smileys {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.chat-avis-smiley {
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
  transition: transform .12s, background .12s, border-color .12s;
}

.chat-avis-smiley:hover {
  transform: scale(1.2);
  background: #fff;
  border-color: #fcd34d;
}

/* Bulle d'avertissement système, différenciée des réponses. */
.chat-bulle--systeme {
  align-self: center;
  background: #fffbeb;
  border: 1px dashed #fcd34d;
  color: #92400e;
  font-size: 12.5px;
}
