/*
 * Chatbot flottant IA (RAG T4, 22/09/2026 ; généralisé le 23/09/2026 pour
 * remplacer le tutoriel en bulles — Planner qqsFdrh-3Ei2Oipec8B5wpgACSTI).
 * Rendu pour tout utilisateur connecté (mode général), ou avec un écran de
 * conversation direct sur une page de notice quand isIaAdaptationActive()
 * y est vrai (mode notice, inchangé) — voir
 * templates/components/_ia_chatbot.html.twig. Comportement dans
 * public/js/ia-chatbot.js.
 */

.ia-chatbot {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  font-family: inherit;
}

.ia-chatbot__bouton {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
  padding: 0;
}

.ia-chatbot__bouton:hover,
.ia-chatbot__bouton:focus-visible {
  background: #1d4ed8;
}

.ia-chatbot__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
}

.ia-chatbot__badge[hidden] {
  display: none;
}

.ia-chatbot__menu {
  position: absolute;
  right: 0;
  bottom: 68px;
  min-width: 260px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  padding: 6px;
  display: flex;
  flex-direction: column;
}

.ia-chatbot__menu[hidden],
.ia-chatbot__menu-item[hidden] {
  display: none;
}

.ia-chatbot__menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: #1e293b;
  text-align: left;
  cursor: pointer;
}

.ia-chatbot__menu-item .material-symbols-outlined {
  font-size: 20px;
  color: #2563eb;
}

.ia-chatbot__menu-item:hover,
.ia-chatbot__menu-item:focus-visible {
  background: #eff6ff;
}

.ia-chatbot__panneau {
  position: absolute;
  right: 0;
  bottom: 68px;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: 480px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ia-chatbot__panneau[hidden] {
  display: none;
}

.ia-chatbot__entete {
  padding: 12px 16px;
  background: #2563eb;
  color: #fff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ia-chatbot__entete-titre {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Avatar de l'assistant (rond, couleurs de la marque) — décision du
   24/09/2026 : un simple SVG inline dans un cercle blanc suffit, pas d'image
   externe ni de génération d'image. En tête du panneau ET, depuis les
   visites pas à pas du Guide (décision du pilote du 24/09/2026), en tête de
   chaque bulle hors du chat (.ia-chatbot-cible-bulle__entete plus bas). */
.ia-chatbot__avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  color: #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ia-chatbot__entete-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ia-chatbot__relancer {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0;
}

.ia-chatbot__relancer .material-symbols-outlined {
  font-size: 20px;
}

.ia-chatbot__fermer {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.ia-chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 160px;
}

.ia-chatbot__message {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.ia-chatbot__message--assistant {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1e293b;
}

.ia-chatbot__message--utilisateur {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
}

.ia-chatbot__message--systeme {
  align-self: center;
  background: transparent;
  color: #64748b;
  font-style: italic;
  font-size: 12px;
  text-align: center;
  max-width: 100%;
}

/* Bouton d'action sous une réponse fixe (28/09/2026) : « Demander le rôle
   Testeur ». Mêmes couleurs que le bouton « Envoyer » du panneau. */
.ia-chatbot__actions {
  margin-top: 8px;
  white-space: normal;
}

.ia-chatbot__action {
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}

.ia-chatbot__action:hover,
.ia-chatbot__action:focus-visible {
  background: #1d4ed8;
}

.ia-chatbot__action:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ia-chatbot__action-resultat {
  margin: 6px 0 0;
  font-size: 13px;
  color: #334155;
}

/* Panneau encore vide : une indication discrète, pas un message de la
   conversation (le panneau ne sert qu'aux questions précises). */
.ia-chatbot__messages:empty::before {
  content: attr(data-vide);
  margin: auto;
  color: #94a3b8;
  font-size: 13px;
  text-align: center;
}

.ia-chatbot__statut {
  padding: 0 12px 4px;
  font-size: 12px;
  color: #64748b;
  min-height: 16px;
  margin: 0;
}

.ia-chatbot__saisie {
  display: flex;
  border-top: 1px solid #e2e8f0;
  padding: 8px;
  gap: 8px;
}

.ia-chatbot__champ {
  flex: 1;
  resize: none;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
  max-height: 80px;
}

.ia-chatbot__envoyer {
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
}

.ia-chatbot__envoyer:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/*
 * Bulle qui désigne un élément de l'écran, HORS du chat (ST2, RAG T5,
 * 24/09/2026 — remplace visuellement l'ancien tutoriel en bulles,
 * public/css/tutorial.css, supprimé le 23/09/2026 avec ce même chantier).
 * Repris de `.tutorial__bulle`, RECOLORÉ aux couleurs du chatbot (fond bleu
 * #2563eb, texte blanc, cf. .ia-chatbot__bouton et .ia-chatbot__entete
 * ci-dessus) plutôt que fond blanc/texte sombre comme l'ancien tutoriel :
 * un fond de marque pleine couleur reste lisible identiquement en thème
 * clair et sombre, donc AUCUN override `html[data-theme="dark"]` n'est
 * nécessaire ici (à la différence de tutorial.css, qui en avait besoin pour
 * son fond blanc).
 */
.ia-chatbot-cible-bulle {
  position: absolute;
  top: 0;
  left: 0;
  /* Au-dessus du panneau du chatbot (z-index: 1000 sur .ia-chatbot) ET,
     depuis le 24/09/2026, des fenêtres de la page (z-index: 20000 sur
     .modal, public/css/components/_modal.css) : les suites de visite du
     Guide présentent aussi le contenu de ces fenêtres. */
  z-index: 20001;
  /* 320px (au lieu de 280px avant le 24/09/2026) : le texte de la bulle
     porte désormais jusqu'à 100 caractères (ChatbotService::
     LONGUEUR_MAX_TEXTE_MONTRER), un peu de marge en plus reste confortable
     à lire. */
  /* 200 caractères au plus pour une bulle de visite du Guide
     (VisitesGuide::LONGUEUR_MAX_TEXTE). Jamais plus large que l'écran d'un
     téléphone, marge de 16px de chaque côté. */
  max-width: min(320px, calc(100vw - 32px));
  padding: 0.85rem 1rem;
  background: #2563eb;
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
}

.ia-chatbot-cible-bulle[hidden] {
  display: none;
}

/* En-tête de chaque bulle : avatar, nom de l'assistant, et pendant une
   visite pas à pas du Guide, « Étape i / n » et la croix pour quitter. */
.ia-chatbot-cible-bulle__entete {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 0.5rem;
}

.ia-chatbot-cible-bulle__titre {
  font-size: 12px;
  font-weight: 600;
}

.ia-chatbot-cible-bulle__etape {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.85;
  white-space: nowrap;
}

.ia-chatbot-cible-bulle__etape[hidden],
.ia-chatbot-cible-bulle__fermer[hidden],
.ia-chatbot-cible-bulle__nav[hidden] {
  display: none;
}

.ia-chatbot-cible-bulle__fermer {
  background: none;
  border: none;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.85;
}

/* Sans compteur d'étape, la croix se range quand même à droite. */
.ia-chatbot-cible-bulle__etape[hidden] + .ia-chatbot-cible-bulle__fermer {
  margin-left: auto;
}

.ia-chatbot-cible-bulle__fermer:hover,
.ia-chatbot-cible-bulle__fermer:focus-visible {
  opacity: 1;
}

.ia-chatbot-cible-bulle__actions {
  display: flex;
  flex-wrap: wrap; /* « Ne plus afficher le guide » + navigation, sur 320px */
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* Boutons « Précédent » / « Suivant » / « Terminer » d'une visite : même
   dessin que « Compris », « Précédent » en version discrète. */
.ia-chatbot-cible-bulle__nav {
  background: #fff;
  color: #2563eb;
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* Lien d'étape (« Voir les tarifs ») : même dessin qu'un bouton. */
a.ia-chatbot-cible-bulle__nav {
  display: inline-block;
  text-decoration: none;
}

.ia-chatbot-cible-bulle__nav--secondaire {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.ia-chatbot-cible-bulle__nav:hover,
.ia-chatbot-cible-bulle__nav:focus-visible {
  background: #dbeafe;
  color: #2563eb;
}

.ia-chatbot-cible-bulle__texte {
  margin: 0 0 0.7rem;
  font-size: 13px;
  line-height: 1.4;
  /* Les retours à la ligne d'un texte Markdown restent des \n bruts
     (cf. rendreMarkdownEnHtml() dans ia-chatbot.js), comme dans le panneau. */
  white-space: pre-wrap;
}

/* Explication d'un article (« En savoir plus sur cet article ») : une
   réponse réglementaire est plus longue qu'une bulle du Guide. La bulle
   s'élargit et son texte défile au-delà d'une demi-hauteur d'écran. */
.ia-chatbot-cible-bulle--article {
  max-width: min(420px, calc(100vw - 32px));
}

.ia-chatbot-cible-bulle--article .ia-chatbot-cible-bulle__texte {
  /* 260px : l'en-tête, les boutons et l'écart au bouton du chatbot. Sans
     cette borne, sur un écran bas (téléphone en paysage), l'en-tête de la
     bulle sortait par le haut (vu à l'écran le 28/09/2026). */
  max-height: max(60px, min(50vh, calc(100vh - 260px)));
  overflow-y: auto;
  /* Une adresse écrite en clair (lien Légifrance) se coupe au lieu de
     déborder à droite de la bulle. */
  overflow-wrap: anywhere;
}

.ia-chatbot-cible-bulle__texte ul,
.ia-chatbot-cible-bulle__texte ol {
  margin: 0.3rem 0;
  padding-left: 1.1rem;
  white-space: normal;
}

.ia-chatbot-cible-bulle__texte a {
  color: #fff;
  text-decoration: underline;
}

.ia-chatbot-cible-bulle__choix {
  display: flex;
  gap: 8px;
  margin: 0 0 0.6rem;
}

.ia-chatbot-cible-bulle__choix[hidden] {
  display: none;
}

.ia-chatbot-cible-bulle__choix-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fff;
  color: #2563eb;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ia-chatbot-cible-bulle__choix-btn .material-symbols-outlined {
  font-size: 18px;
}

.ia-chatbot-cible-bulle__choix-btn:hover,
.ia-chatbot-cible-bulle__choix-btn:focus-visible {
  background: #dbeafe;
}

.ia-chatbot-cible-bulle__compris[hidden] {
  display: none;
}

.ia-chatbot-cible-bulle__compris {
  background: #fff;
  color: #2563eb;
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ia-chatbot-cible-bulle__fleche {
  position: absolute;
  width: 10px;
  height: 10px;
  background: inherit;
  transform: rotate(45deg);
}

@media (max-width: 480px) {
  .ia-chatbot {
    right: 16px;
    bottom: 16px;
  }

  .ia-chatbot__panneau {
    width: calc(100vw - 32px);
  }
}

/* « Ne plus afficher le guide » (24/09/2026) : lien discret sur sa propre
   ligne, sous « Précédent » / « Suivant » (sinon, sur un téléphone, il
   repousse « Suivant » à la ligne). */
.ia-chatbot-cible-bulle__arreter {
  order: 1;
  flex-basis: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.1rem 0 0;
  color: #fff;
  font-size: 11px;
  text-decoration: underline;
  opacity: 0.85;
  cursor: pointer;
}

.ia-chatbot-cible-bulle__arreter:hover,
.ia-chatbot-cible-bulle__arreter:focus-visible {
  opacity: 1;
}

.ia-chatbot-cible-bulle__arreter[hidden] {
  display: none;
}
