/* ============================================================
   Sylvie, l'assistante du site (js/chatbot.js).

   Tout est prefixe `chatbot-` : la feuille principale a deja des `.message`,
   `.bulle` et `.lien`, et une collision de nom y a deja coute une soiree.

   Les couleurs viennent des variables de style.css (--surface, --texte,
   --bordure...) : le theme sombre et le theme clair suivent donc sans une
   regle de plus, que le visiteur l'ait choisi (data-theme) ou que son systeme
   le demande.

   z-index 900 : sous le bandeau et la fenetre des cookies (1000), qui doivent
   rester devant tant que le visiteur n'a pas repondu.
   ============================================================ */

/* Le lanceur : une pastille qui porte un mot (« Une question ? »), pas un
   pictogramme seul. Fenetre ouverte, elle se replie en bouton rond de
   fermeture. Sur telephone, elle reste ronde : la place manque. */
.chatbot-bulle {
  position: fixed;
  right: 20px; bottom: 20px;
  z-index: 900;
  height: 56px; min-width: 56px;
  margin: 0; padding: 0 1.25rem 0 1.05rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .6rem;
  border: 0; border-radius: 999px;
  background: var(--magenta-fonce);
  color: #fff;
  font-family: var(--corps);
  font-size: 1rem; font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(184, 0, 101, .38), 0 2px 6px rgba(0, 0, 0, .18);
  transition: transform .18s ease, background-color .18s ease;
}
.chatbot-bulle:hover { background: var(--magenta); transform: translateY(-2px); }
.chatbot-bulle:focus-visible { outline: 3px solid var(--texte); outline-offset: 3px; }
.chatbot-bulle svg { display: block; }
.chatbot-bulle-icone, .chatbot-bulle-replier { display: grid; place-items: center; }
.chatbot-bulle-replier { display: none; }
.chatbot-bulle-ouverte { padding: 0; width: 56px; }
.chatbot-bulle-ouverte .chatbot-bulle-icone,
.chatbot-bulle-ouverte .chatbot-bulle-libelle { display: none; }
.chatbot-bulle-ouverte .chatbot-bulle-replier { display: grid; }

.chatbot-fenetre {
  position: fixed;
  right: 20px; bottom: 90px;
  z-index: 900;
  /* style.css donne 64 px de marge interne a toute `section` et un
     positionnement a tout `header` : sans ces remises a zero, la fenetre
     s'ouvrait avec deux bandes vides, en haut et en bas (constate en ligne). */
  margin: 0; padding: 0;
  width: min(390px, calc(100vw - 40px));
  height: min(600px, calc(100vh - 120px));
  height: min(600px, calc(100dvh - 120px));
  display: flex; flex-direction: column;
  background: var(--surface);
  color: var(--texte);
  border: 1px solid var(--bordure);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22), 0 2px 8px rgba(0, 0, 0, .12);
  overflow: hidden;
  font-family: var(--corps);
  font-size: .95rem;
  line-height: 1.5;
  animation: chatbot-entre .2s ease-out;
}
.chatbot-fenetre[hidden] { display: none; }

@keyframes chatbot-entre {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------ l'en-tete */

.chatbot-entete {
  position: static;
  margin: 0; border: 0;
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem;
  padding: .8rem .9rem .8rem 1rem;
  background: var(--magenta-fonce);
  color: #fff;
}
.chatbot-identite { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.chatbot-pastille {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #fff;
  color: var(--magenta-fonce);
  font-family: var(--titre);
  font-size: 1.2rem; font-weight: 600;
}
.chatbot-nom {
  display: block;
  font-family: var(--titre);
  font-size: 1.08rem; font-weight: 500;
  letter-spacing: .03em;
  line-height: 1.2;
}
.chatbot-role { display: block; font-size: .8rem; opacity: .92; line-height: 1.3; }
.chatbot-fermer {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.chatbot-fermer:hover { background: rgba(255, 255, 255, .18); }
.chatbot-fermer:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ----------------------------------------------------------- le journal */

.chatbot-journal {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem .9rem .6rem;
  display: flex; flex-direction: column;
  gap: .7rem;
  background: var(--fond-alt);
}
.chatbot-journal:focus-visible { outline: 2px solid var(--magenta); outline-offset: -2px; }

.chatbot-message { display: flex; flex-direction: column; gap: .45rem; max-width: 88%; }
.chatbot-sylvie { align-self: flex-start; align-items: flex-start; }
.chatbot-visiteur { align-self: flex-end; align-items: flex-end; }

.chatbot-texte {
  padding: .6rem .8rem;
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.chatbot-texte p { margin: 0; }
.chatbot-texte p + p { margin-top: .5rem; }
.chatbot-sylvie .chatbot-texte {
  background: var(--surface);
  color: var(--texte);
  border: 1px solid var(--bordure);
  border-bottom-left-radius: 4px;
}
.chatbot-visiteur .chatbot-texte {
  background: var(--magenta-fonce);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Les liens poses par le serveur sous une reponse : fiche produit d'abord. */
.chatbot-liens { display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.chatbot-lien {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .75rem;
  border: 1.5px solid var(--magenta);
  border-radius: 999px;
  background: var(--surface);
  color: var(--texte);
  font-size: .88rem; font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  transition: background-color .15s ease, color .15s ease;
}
.chatbot-lien::after { content: "→"; color: var(--magenta); transition: color .15s ease; }
.chatbot-lien:hover, .chatbot-lien:focus-visible { background: var(--magenta-fonce); border-color: var(--magenta-fonce); color: #fff; }
.chatbot-lien:hover::after, .chatbot-lien:focus-visible::after { color: #fff; }
.chatbot-lien:focus-visible { outline: 2px solid var(--texte); outline-offset: 2px; }
.chatbot-lien-devis, .chatbot-lien-contact {
  background: var(--magenta-fonce); border-color: var(--magenta-fonce); color: #fff;
}
.chatbot-lien-devis::after, .chatbot-lien-contact::after { color: #fff; }
.chatbot-lien-devis:hover, .chatbot-lien-contact:hover { background: var(--magenta); border-color: var(--magenta); }

/* Les questions frequentes : une liste, comme un centre d'aide, plutot que
   des pastilles qui passent a la ligne n'importe ou. */
.chatbot-suggestions { display: flex; flex-direction: column; gap: .4rem; margin-top: .3rem; }
.chatbot-suggestions-titre {
  margin: 0 0 .1rem;
  color: var(--texte-doux);
  font-size: .74rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
}
.chatbot-suggestion {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  width: 100%;
  margin: 0; padding: .6rem .8rem;
  border: 1px solid var(--bordure);
  border-radius: 10px;
  background: var(--surface);
  color: var(--texte);
  font: inherit; font-size: .9rem;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.chatbot-suggestion::after { content: "→"; color: var(--magenta); flex: none; }
.chatbot-suggestion:hover, .chatbot-suggestion:focus-visible { border-color: var(--magenta); color: var(--magenta); }
.chatbot-suggestion:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }

/* Les trois points pendant que Sylvie ecrit. */
.chatbot-points { display: flex; gap: 5px; align-items: center; padding: .8rem .9rem; }
.chatbot-points span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--texte-doux);
  animation: chatbot-point 1.1s infinite ease-in-out;
}
.chatbot-points span:nth-child(2) { animation-delay: .15s; }
.chatbot-points span:nth-child(3) { animation-delay: .3s; }
@keyframes chatbot-point {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ------------------------------------------------------------ la saisie */

.chatbot-saisie {
  flex: none;
  margin: 0;
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .6rem .7rem;
  border-top: 1px solid var(--bordure);
  background: var(--surface);
}
.chatbot-champ {
  flex: 1 1 auto;
  min-height: 42px; max-height: 120px;
  padding: .55rem .75rem;
  border: 1px solid var(--bordure);
  border-radius: 12px;
  background: var(--fond);
  color: var(--texte);
  /* 16 px au moins : en dessous, Safari sur iPhone zoome a la prise de focus. */
  font: inherit; font-size: 1rem;
  line-height: 1.4;
  resize: none;
}
.chatbot-champ::placeholder { color: var(--texte-leger); }
.chatbot-champ:focus { outline: 2px solid var(--magenta); outline-offset: 0; border-color: var(--magenta); }
.chatbot-envoyer {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--magenta);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease;
}
.chatbot-envoyer:hover { background: var(--magenta-fonce); }
.chatbot-envoyer:focus-visible { outline: 2px solid var(--texte); outline-offset: 2px; }
.chatbot-envoyer:disabled { opacity: .5; cursor: default; }

/* Le relais vers l'equipe, sous la saisie, toujours visible. */
.chatbot-relais {
  flex: none;
  display: flex; justify-content: center; flex-wrap: wrap; gap: .2rem 1.2rem;
  margin: 0; padding: .1rem .9rem .35rem;
  background: var(--surface);
  font-size: .82rem;
}
.chatbot-relais-lien {
  color: var(--texte);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--magenta);
  text-underline-offset: 3px;
}
.chatbot-relais-lien:hover, .chatbot-relais-lien:focus-visible { color: var(--magenta); }
.chatbot-relais-lien:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }

.chatbot-mention {
  flex: none;
  margin: 0;
  padding: 0 .9rem .55rem;
  background: var(--surface);
  color: var(--texte-doux);
  font-size: .72rem;
  line-height: 1.4;
  text-align: center;
}

/* ------------------------------------------------------------ telephone */

@media (max-width: 640px) {
  .chatbot-bulle { right: 14px; bottom: 14px; width: 54px; min-width: 54px; height: 54px; padding: 0; }
  .chatbot-bulle-libelle { display: none; }
  .chatbot-fenetre {
    inset: 0;
    width: auto; height: auto;
    border: 0; border-radius: 0;
  }
  /* Fenetre ouverte en plein ecran : la croix de l'en-tete ferme, la bulle
     ne ferait que masquer le bouton d'envoi. */
  .chatbot-bulle.chatbot-bulle-ouverte { display: none; }
  .chatbot-saisie { padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-fenetre, .chatbot-points span { animation: none; }
  .chatbot-bulle, .chatbot-lien, .chatbot-suggestion { transition: none; }
}

@media print {
  .chatbot-bulle, .chatbot-fenetre { display: none !important; }
}
