/* ── YEP'S Chat Widget ────────────────────────── */

#yeps-chat-wrapper {
  /* Couleurs alignées sur la charte YEP'S (cf. theme.json — bleu-yeps #2B2D6E,
   * bleu-sombre #1A1A2E). On lit les CSS custom properties exposées par
   * theme.json avec fallback hex pour rester robuste si le thème n'est pas
   * chargé (cas marginal : preview, admin). */
  --yeps-primary: var(--wp--preset--color--bleu-yeps, #2B2D6E);
  --yeps-primary-dark: var(--wp--preset--color--bleu-sombre, #1A1A2E);
  --yeps-radius: 12px;
  --yeps-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

/* ── Toggle button ────────────────────────────── */

#yeps-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--yeps-primary);
  color: #fff;
  cursor: pointer;
  /* Contour blanc (anneau via box-shadow, pas de border : aucun décalage de
   * layout ni de rétrécissement de l'icône) pour faire ressortir le bouton
   * sur les zones sombres. Empilé avant l'ombre portée du design system. */
  box-shadow: 0 0 0 2px #fff, var(--yeps-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
}

@media (hover: hover) {
  #yeps-chat-toggle:hover {
    background: var(--yeps-primary-dark);
    transform: scale(1.05);
  }
}

/* ── Panel ────────────────────────────────────── */

#yeps-chat-panel {
  display: none;
  flex-direction: column;
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: var(--yeps-radius);
  box-shadow: var(--yeps-shadow);
  overflow: hidden;
  /* Transition portée pour l'auto-agrandissement desktop (cf.
   * maybeExpandPanel dans yeps-chat.js). En mobile la media query passe le
   * panel en plein écran (inset:0, height:auto) : la transition reste
   * inerte tant que `.yeps-chat-expanded` n'est jamais posée (l'observer JS
   * s'en garde via isMobile()). */
  transition: height 320ms cubic-bezier(0.2, 0.7, 0.1, 1);
}

/* Pile à 70vh dès que la conversation déborde la hauteur de base (520px).
 * `max(520px, 70vh)` empêche le panel de RÉTRÉCIR sur viewport vertical
 * court : sous ~743 px de haut, 70vh < 520 px (la base) et l'expand
 * dégraderait l'overflow au lieu de l'absorber. `max-height: calc(100vh -
 * 120px)` du panel parent borne toujours la hauteur effective vers le haut.
 * Classe posée par maybeExpandPanel, retirée par resetConversation. */
#yeps-chat-panel.yeps-chat-expanded {
  height: max(520px, 70vh);
}

#yeps-chat-panel.yeps-chat-visible {
  display: flex;
}

/* ── Header ───────────────────────────────────── */

#yeps-chat-header {
  background: var(--yeps-primary);
  color: #fff;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  /* Au-dessus de l'overlay de consentement (z-index:1) pour garder le bouton
   * « Fermer » accessible pendant que la fenêtre est recouverte. */
  position: relative;
  z-index: 2;
}

#yeps-chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#yeps-chat-header strong {
  font-size: 17px;
}

#yeps-chat-header span {
  font-size: 13px;
  opacity: 0.85;
}

/* ── Actions header (nouvelle conversation / fermer) ─── */

#yeps-chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

#yeps-chat-new,
#yeps-chat-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

@media (hover: hover) {
  #yeps-chat-new:hover,
  #yeps-chat-close:hover {
    background: rgba(255, 255, 255, 0.15);
  }
}

#yeps-chat-new:focus-visible,
#yeps-chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ── Messages ─────────────────────────────────── */

#yeps-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  /* `scrollbar-gutter: stable` réserve en permanence la place de la barre
   * de scroll : sans ça, le reflow horizontal lors de son apparition/
   * disparition (notamment pendant le stream de la réponse et autour de
   * l'auto-agrandissement 70vh) faisait sautiller le contenu et la barre
   * elle-même. macOS Safari (overlay scrollbars) n'a pas ce problème ;
   * scrollbar-gutter y est ignoré sans dommage avant 18.2.
   * `scrollbar-width: thin` rend la gouttière plus discrète sur Firefox
   * et Chromium récent, alignée avec l'esthétique sobre du widget. */
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

/* Spacer transparent maintenu en dernier enfant : réserve l'espace sous le
 * dernier tour pour épingler la question en haut (cf. yeps-chat.js,
 * pinQuestionToTop / sizeTailSpacer). */
#yeps-chat-tail-spacer {
  flex-shrink: 0;
}

.yeps-msg {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1.5;
  word-break: break-word;
  font-size: 14px;
}

.yeps-msg a {
  color: var(--yeps-primary);
  text-decoration: underline;
}

.yeps-msg ul {
  margin: 4px 0;
  padding-left: 18px;
}

.yeps-msg li {
  margin-bottom: 2px;
}

.yeps-msg hr {
  border: none;
  border-top: 1px solid #e0e0e0;
  margin: 8px 0;
}

/* Sous-titre (### markdown) rendu en <h4> sémantique : on neutralise le style
   navigateur par défaut (gros titre) pour garder l'allure d'un message. */
.yeps-msg h4 {
  font-size: 1em;
  font-weight: 700;
  line-height: 1.3;
  margin: 10px 0 4px;
}

/* Région live masquée (annonces lecteur d'écran) + tout texte réservé AT
   dans le widget de chat. Masque visuellement sans retirer de l'arbre a11y. */
.yeps-chat-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.yeps-msg-user {
  align-self: flex-end;
  background: var(--yeps-primary);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.yeps-msg-assistant {
  align-self: flex-start;
  background: #f0f2f5;
  color: #1a1a1a;
  border-bottom-left-radius: 2px;
}

/* Consentement RGPD « données sensibles » : prise COMPLÈTE de la fenêtre du
 * chat (fond blanc opaque) affichée à l'ouverture, volontairement distincte
 * d'un message régulier pour exposer solennellement l'usage des données. Posée
 * SOUS le header (z-index) afin que le bouton « Fermer » reste accessible. */
.yeps-chat-consent {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
}

.yeps-chat-consent__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 18px;
  max-width: 300px;
}

.yeps-chat-consent__icon {
  color: var(--yeps-primary);
  line-height: 0;
}

.yeps-chat-consent__text {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #1a1a1a;
}

.yeps-chat-consent__accept {
  background: var(--yeps-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.yeps-chat-consent__accept:hover,
.yeps-chat-consent__accept:focus-visible {
  background: var(--yeps-primary-dark);
}

.yeps-msg-sources {
  align-self: flex-start;
  background: transparent;
  padding: 4px 14px;
  font-size: 12px;
  color: #666;
  max-width: 100%;
}

.yeps-msg-sources strong {
  font-size: 12px;
}

.yeps-msg-sources ul {
  margin: 4px 0 0;
  padding-left: 4px;
  list-style: none;
}

.yeps-msg-sources a {
  color: var(--yeps-primary);
  font-size: 12px;
}

/* Domaine du site source, en suffixe gris du titre. Discret pour ne pas
   surcharger l'affichage, notamment sur mobile. */
.yeps-src-host {
  color: #888;
  font-weight: 400;
  white-space: nowrap;
}

/* Numéro [n] de la liste de sources, aligné sur les marqueurs inline. */
.yeps-cite-num {
  color: #888;
  font-variant-numeric: tabular-nums;
}

/* Marqueur de citation inline : exposant cliquable [n] vers la fiche source. */
.yeps-cite {
  line-height: 0;
}

.yeps-cite a {
  text-decoration: none;
  font-size: 0.7em;
  font-weight: 600;
  color: var(--yeps-primary);
  padding: 0 1px;
}

.yeps-cite a:hover {
  text-decoration: underline;
}

/* Bulles de relance cliquables, sous la réponse. */
.yeps-msg-suggestions {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 14px 2px;
  max-width: 100%;
  background: transparent;
}

.yeps-suggestion {
  border: 1px solid var(--yeps-primary, #2d6cdf);
  color: var(--yeps-primary, #2d6cdf);
  background: transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.yeps-suggestion:hover,
.yeps-suggestion:focus-visible {
  background: var(--yeps-primary, #2d6cdf);
  color: #fff;
  outline: none;
}

/* Barre de feedback (👍 / 👎 / Signaler) sous chaque réponse. */
.yeps-msg-feedback {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 14px 6px;
  background: transparent;
}

.yeps-feedback-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: #888;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: color 0.15s ease, background 0.15s ease;
}

.yeps-feedback-btn:hover:not(:disabled),
.yeps-feedback-btn:focus-visible:not(:disabled) {
  color: var(--yeps-primary, #2d6cdf);
  background: rgba(45, 108, 223, 0.08);
  outline: none;
}

.yeps-feedback-btn.is-selected {
  color: var(--yeps-primary, #2d6cdf);
}

.yeps-feedback-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.yeps-feedback-report {
  margin-left: 2px;
}

.yeps-feedback-thanks {
  font-size: 12px;
  color: #888;
  margin-left: 4px;
}

.yeps-feedback-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Dialogue de caractérisation (type + raison préréglée). */
.yeps-fb-dialog {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid #d6d8dc;
  border-radius: 10px;
  background: #fff;
  max-width: 340px;
}

.yeps-fb-dialog-head {
  font-size: 12px;
  color: #555;
  margin-bottom: 8px;
}

.yeps-fb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.yeps-fb-type,
.yeps-fb-reason {
  border: 1px solid #c7cad0;
  background: transparent;
  color: #444;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.yeps-fb-type.is-active,
.yeps-fb-reason.is-active {
  background: var(--yeps-primary, #2d6cdf);
  border-color: var(--yeps-primary, #2d6cdf);
  color: #fff;
}

.yeps-fb-comment {
  display: block;
}

.yeps-fb-textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #c7cad0;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
}

.yeps-fb-hint {
  font-size: 11px;
  color: #999;
  margin-top: 3px;
}

.yeps-fb-actions {
  margin-bottom: 0;
}

.yeps-fb-send {
  border: none;
  background: var(--yeps-primary, #2d6cdf);
  color: #fff;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 13px;
  cursor: pointer;
}

.yeps-fb-cancel {
  border: none;
  background: transparent;
  color: #888;
  font-size: 13px;
  cursor: pointer;
}

/* ── Typing indicator ─────────────────────────── */

.yeps-typing::after {
  content: "\25CF  \25CF  \25CF";
  animation: yeps-blink 1.2s infinite;
  color: #888;
  letter-spacing: 3px;
}

@keyframes yeps-blink {
  0%, 20% { opacity: 0.2; }
  50% { opacity: 1; }
  80%, 100% { opacity: 0.2; }
}

/* ── Form ─────────────────────────────────────── */

/* Forme « pilule » alignée sur le bloc hero-search : fond blanc, rounded
 * pleins, ombre subtile, ring bleu-yeps au focus-within. Pas de border-top
 * séparateur — la pilule détachée tient lieu de séparation visuelle avec
 * les messages au-dessus. */
#yeps-chat-form {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 10px;
  padding: 4px 4px 4px 16px;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(26, 26, 46, 0.08);
  transition: box-shadow 0.24s cubic-bezier(0.2, 0.7, 0.1, 1);
}

#yeps-chat-form:focus-within {
  box-shadow:
    0 0 0 2px var(--yeps-primary),
    0 6px 16px rgba(26, 26, 46, 0.12);
}

/* Wrap relatif autour de l'input : sert de containing block pour le canvas
 * overlay de la waveform STT. Reprend le `flex: 1` qui était sur l'input
 * pour rester le seul enfant flexible de la pilule. */
#yeps-chat-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#yeps-chat-input {
  width: 100%;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--wp--custom--yeps--color--text--dark, #1A1A2E);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  outline: none;
}

#yeps-chat-input::placeholder {
  color: rgba(26, 26, 46, 0.5);
}

#yeps-chat-input:disabled {
  background: transparent;
  opacity: 0.6;
}

/* Canvas waveform STT : overlay au-dessus de l'input. Identique à celui
 * du bloc hero-search (cf. src/blocks/hero-search/style.scss). Activé via
 * la classe modifier `.yeps-chat-form--recording` posée par yeps-chat.js
 * au démarrage du micro et retirée à l'arrêt/abort. */
#yeps-chat-waveform {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease-out;
}

.yeps-chat-form--recording #yeps-chat-waveform {
  opacity: 1;
}

.yeps-chat-form--recording #yeps-chat-input {
  color: transparent;
  caret-color: transparent;
}

.yeps-chat-form--recording #yeps-chat-input::placeholder {
  color: transparent;
}

#yeps-chat-send,
#yeps-chat-mic {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s ease;
  flex-shrink: 0;
  /* position: relative pour ancrer le ::after du halo micro
   * (rendu sans DOM supplémentaire). */
  position: relative;
}

#yeps-chat-send {
  background: var(--yeps-primary);
  color: #fff;
}

@media (hover: hover) {
  #yeps-chat-send:hover:not(:disabled) {
    background: var(--yeps-primary-dark);
  }
}

#yeps-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Micro : ghost button (cohérent avec le bloc hero-search) — contour bleu
 * sombre au repos (couleur palette charte, distincte du bleu-yeps plein du
 * submit voisin) ; icône rouge + bordure rouge + ripple quand actif.
 * Identité visuelle partagée avec .yeps-hero-search__mic
 * (cf. src/blocks/hero-search/style.scss). */
#yeps-chat-mic {
  background: transparent;
  /* Aligné avec .yeps-hero-search__mic (cf. src/blocks/hero-search/style.scss) :
   * `text--dark` au lieu de l'ancien `text--muted` pour la même force visuelle
   * sur les deux composants. Le user remarquait la différence — c'était la
   * couleur de repos, pas le stroke-width SVG. */
  color: var(--wp--custom--yeps--color--text--dark, #1A1A2E);
  box-shadow: 0 0 0 1.5px var(--wp--preset--color--bleu-sombre, #1A1A2E);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s ease;
}

/* Hover : on darken juste le fond, pas la couleur (sinon la spécificité
 * `:hover:not(:disabled)` écraserait l'état actif var(--wp--custom--yeps--color--recording, #D62B20) quand l'utilisateur
 * survole le bouton pendant l'enregistrement). Wrap @media (hover: hover)
 * pour ne pas déclencher le sticky hover sur tactile après un tap. */
@media (hover: hover) {
  #yeps-chat-mic:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.06);
  }
}

#yeps-chat-mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#yeps-chat-mic[aria-pressed="true"] {
  color: var(--wp--custom--yeps--color--recording, #D62B20);
  /* Bordure rouge constante pendant l'enregistrement (sans impact layout
   * grâce à box-shadow). Le ripple s'émet depuis ce bord stable. */
  box-shadow: 0 0 0 2px var(--wp--custom--yeps--color--recording, #D62B20);
}

/* Onde unique « ripple » — pattern aligné sur .yeps-hero-video__wave et
 * sur .yeps-hero-search__mic pour cohérence d'identité visuelle. */
#yeps-chat-mic[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 2px solid var(--wp--custom--yeps--color--recording, #D62B20);
  opacity: 0.45;
  pointer-events: none;
  animation: yeps-chat-mic-ripple 1.6s cubic-bezier(0.2, 0.7, 0.1, 1) infinite;
}

@keyframes yeps-chat-mic-ripple {
  0%   { transform: scale(1); opacity: 0.45; }
  80%  { transform: scale(2); opacity: 0;    }
  100% { transform: scale(2); opacity: 0;    }
}

/* État transcription, miroir des règles du hero-search (cf.
 * src/blocks/hero-search/style.scss). Posé par yepsBindMic dès le clic stop
 * user, retiré quand la Promise `done` du STT résout. L'icône mic reste
 * visible ; la bordure du bouton devient un anneau rouge rotatif. Le keyframe
 * `yeps-mic-spin` est défini en double dans hero-search/style.scss et ici —
 * les browsers fusionnent les keyframes nommées identiquement, pas de conflit. */
#yeps-chat-mic[aria-busy="true"] {
  color: var(--wp--custom--yeps--color--recording, #D62B20);
  /* Retire la bordure bleu-sombre du repos pour ne pas doubler avec le
   * spinner. */
  box-shadow: none;
}
#yeps-chat-mic[aria-busy="true"]::before {
  content: '';
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: yeps-mic-spin 0.8s linear infinite;
  pointer-events: none;
}

@keyframes yeps-mic-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  #yeps-chat-mic[aria-pressed="true"]::after {
    animation: none;
    transform: scale(1.15);
    opacity: 0.5;
  }
  /* Spinner transcription : pas de rotation, anneau plein rouge statique. */
  #yeps-chat-mic[aria-busy="true"]::before {
    animation: none;
    border-top-color: currentColor;
  }
  /* Couverture globale des animations / transitions du widget chat pour
   * respecter WCAG 2.3.3 : toggle scale au hover, blink des trois points
   * « typing », transition box-shadow du focus-within sur la pilule. */
  .yeps-typing::after {
    animation: none;
    opacity: 0.7;
  }
  /* Épinglage de la question instantané (pas d'animation de scroll). */
  #yeps-chat-messages {
    scroll-behavior: auto;
  }
  #yeps-chat-toggle,
  #yeps-chat-toggle:hover {
    transition: none;
    transform: none;
  }
  #yeps-chat-form,
  #yeps-chat-mic,
  #yeps-chat-send {
    transition: none;
  }
  /* Auto-agrandissement : on conserve la bascule de taille (la classe est
   * encore posée), mais sans interpolation animée — WCAG 2.3.3. */
  #yeps-chat-panel {
    transition: none;
  }
}

/* ── Mobile ───────────────────────────────────── */

/* Les overrides mobile du chat widget vivent désormais dans le CSS inline
 * généré par Yeps_DS_Responsive_CSS (cf. design-system/class-responsive-css.php),
 * pour suivre le breakpoint admin. */
