/* ============================================================
   WAYTEC — chatbot.css : apparence de l'assistant (bouton rond + fenêtre de conversation)
   Téléphone : la fenêtre prend tout l'écran. Ordinateur : panneau en bas à droite.
   Les couleurs viennent de site.css (--rouge, --surface…).
   ============================================================ */

/* --- Bouton rond --- */
.chat-bouton {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 42;
  width: 58px; height: 58px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--rouge-vif, #ff4136), var(--rouge, #e3262f) 55%, var(--rouge-fonce, #b3141c));
  box-shadow: 0 14px 34px -10px rgba(227,38,47,.8), inset 0 1px 0 rgba(255,255,255,.3);
  transition: bottom .35s cubic-bezier(.2,.7,.2,1), transform .2s, opacity .2s;
}
.chat-bouton svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.chat-bouton svg circle { fill: currentColor; stroke: none; }
.chat-bouton::after {        /* onde qui pulse doucement */
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  animation: chatOnde 2.6s infinite;
}
@keyframes chatOnde {
  0%   { box-shadow: 0 0 0 0 rgba(227,38,47,.5); }
  70%  { box-shadow: 0 0 0 16px rgba(227,38,47,0); }
  100% { box-shadow: 0 0 0 0 rgba(227,38,47,0); }
}
.chat-bouton:active { transform: scale(.94); }
.chat-bouton.actif::after { animation: none; }

/* Sur téléphone, il monte au-dessus de la barre d'achat ou du total du configurateur */
@media (max-width: 1023px) {
  body.chat-haut .chat-bouton { bottom: calc(92px + env(safe-area-inset-bottom)); }
}
@media (max-width: 999px) {
  body.chat-haut-config .chat-bouton { bottom: calc(104px + env(safe-area-inset-bottom)); }
}
/* Caché pendant le menu du téléphone et pendant une partie du simulateur */
body.menu-ouvert .chat-bouton, body.menu-ouvert .chat-info,
body:has(.simu.en-jeu) .chat-bouton, body:has(.simu.en-jeu) .chat-info { opacity: 0; pointer-events: none; }

/* --- Petite bulle d'invitation --- */
.chat-info {
  position: fixed; right: 84px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 42;
  max-width: 220px; padding: 10px 14px; border-radius: 16px 16px 4px 16px;
  font-size: .85rem; font-weight: 600; line-height: 1.35; color: #111;
  background: #fff; box-shadow: 0 12px 30px -8px rgba(0,0,0,.6);
  cursor: pointer;
  opacity: 0; transform: translateY(10px) scale(.95); pointer-events: none;
  transition: opacity .3s, transform .3s, bottom .35s;
}
.chat-info.visible { opacity: 1; transform: none; pointer-events: auto; }
@media (max-width: 1023px) {
  body.chat-haut .chat-info { bottom: calc(100px + env(safe-area-inset-bottom)); }
}

/* --- Fenêtre --- */
.chat-fenetre {
  position: fixed; inset: 0; z-index: 80;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--fond, #0a0b0d); color: var(--texte, #eef1f5);
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.2,.7,.2,1);
}
.chat-fenetre[hidden] { display: none; }
.chat-fenetre.ouverte { transform: none; }

.chat-tete {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: var(--surface, #15181e);
  border-bottom: 1px solid var(--trait, rgba(255,255,255,.08));
}
.chat-avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--police-titre, sans-serif); font-weight: 900; color: #fff;
  background: linear-gradient(135deg, var(--rouge-vif, #ff4136), var(--rouge-fonce, #b3141c));
}
.chat-tete > div { flex: 1; min-width: 0; }
.chat-nom { font-family: var(--police-titre, sans-serif); font-weight: 800; font-size: 1rem; line-height: 1.2; }
.chat-statut { display: flex; align-items: center; gap: 7px; font-size: .75rem; color: var(--texte-3, #8a93a0); }
.chat-fermer {
  flex: none; width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.07); color: var(--texte, #eef1f5);
}

.chat-messages {
  position: relative;                        /* repère pour faire défiler jusqu'au début d'une réponse */
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 14px;
}
.chat-msg {
  max-width: 88%; padding: 11px 14px;
  font-size: .95rem; line-height: 1.5;
  border-radius: 18px;
  animation: chatArrive .28s cubic-bezier(.2,.7,.2,1) both;
  overflow-wrap: anywhere;
}
@keyframes chatArrive { from { opacity: 0; transform: translateY(8px); } }
.chat-msg.bot { align-self: flex-start; background: var(--surface-2, #1b1f27); border-bottom-left-radius: 6px; }
.chat-msg.moi {
  align-self: flex-end; color: #fff; border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, var(--rouge-vif, #ff4136), var(--rouge, #e3262f));
}
.chat-msg strong { color: #fff; }
.chat-secours { margin-top: 8px; font-size: .72rem; font-style: italic; color: var(--texte-3, #8a93a0); }
.chat-source { font-size: .78rem; font-weight: 700; color: var(--ambre, #ffb02e); margin-bottom: 4px; }
.chat-citation { padding-left: 10px; border-left: 3px solid rgba(255,176,46,.45); color: var(--texte-2, #b6bdc8); }

/* Indicateur « en train d'écrire » */
.chat-msg.ecrit { display: flex; gap: 5px; padding: 14px 16px; }
.chat-msg.ecrit span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--texte-3, #8a93a0);
  animation: chatPoint 1s infinite;
}
.chat-msg.ecrit span:nth-child(2) { animation-delay: .15s; }
.chat-msg.ecrit span:nth-child(3) { animation-delay: .3s; }
@keyframes chatPoint { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Boutons sous une réponse */
.chat-liens { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chat-lien {
  display: inline-flex; align-items: center;
  padding: 7px 11px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; line-height: 1.2;
  color: #fff; background: rgba(255,255,255,.07); border: 1px solid var(--trait-fort, rgba(255,255,255,.15));
}
.chat-lien:hover { border-color: var(--rouge, #e3262f); }
.chat-lien-wa { color: #05210e; background: #25d366; border-color: #25d366; }

/* Questions proposées */
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; animation: chatArrive .3s .1s both; }
.chat-suggestions button {
  padding: 8px 12px; border-radius: 999px;
  font-size: .82rem; font-weight: 600; color: var(--texte, #eef1f5);
  background: transparent; border: 1px solid rgba(227,38,47,.55);
}
.chat-suggestions button:active { background: rgba(227,38,47,.15); }

/* Zone de saisie */
.chat-saisie {
  flex: none;
  display: flex; gap: 8px;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--trait, rgba(255,255,255,.08));
  background: var(--surface, #15181e);
}
.chat-saisie input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 16px;            /* 16 px : l'iPhone ne zoome pas */
  color: var(--texte, #eef1f5); background: #0f1115;
  border: 1.5px solid var(--trait-fort, rgba(255,255,255,.15)); border-radius: 14px;
  padding: 12px 14px;
}
.chat-saisie input:focus { outline: none; border-color: var(--rouge, #e3262f); }
.chat-envoyer {
  flex: none; width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--rouge-vif, #ff4136), var(--rouge, #e3262f));
}
.chat-note {
  flex: none;
  padding: 2px 14px calc(10px + env(safe-area-inset-bottom));
  font-size: .7rem; color: var(--texte-3, #8a93a0); text-align: center;
  background: var(--surface, #15181e);
}

/* Téléphone : on bloque le défilement de la page derrière la fenêtre */
@media (max-width: 699px) {
  body.chat-ouvert { overflow: hidden; }
}

/* Ordinateur et tablette : panneau en bas à droite */
@media (min-width: 700px) {
  .chat-bouton { right: 24px; bottom: 24px; }
  .chat-info { right: 94px; bottom: 34px; }
  .chat-fenetre {
    inset: auto 24px 96px auto;
    width: 390px; height: min(620px, calc(100vh - 130px));
    border: 1px solid var(--trait-fort, rgba(255,255,255,.15)); border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 30px 80px -20px rgba(0,0,0,.85);
    transform: translateY(16px) scale(.96); opacity: 0;
    transform-origin: bottom right;
    transition: transform .25s cubic-bezier(.2,.7,.2,1), opacity .2s;
  }
  .chat-fenetre.ouverte { transform: none; opacity: 1; }
  .chat-tete { padding-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-bouton::after, .chat-msg, .chat-suggestions, .chat-msg.ecrit span { animation: none; }
  .chat-fenetre { transition: none; }
}
