/* -----------------------------------------------------------------------------
 * assistant-pluriel.css — Widget de l'Assistant de recherche Pluriel (adapté le 25/11/2026)
 * Remplace l'iframe Dify par un widget léger, cohérent avec le site.
 * Palette Pluriel : pétrole #165F70.
 * Préfixe .ab- pour éviter tout conflit avec la page hôte.
 * -----------------------------------------------------------------------------
 */

.assistant-pluriel-widget {
  --ab-accent: #165F70;
  --ab-accent-strong: #0F4652;
  --ab-cream: #f5f3ec;
  --ab-user-bg: #E4EEF0;
  --ab-bot-bg: #ffffff;
  --ab-text: #1e2a2b;
  --ab-text-muted: #5a6a6c;
  --ab-border: rgba(22, 95, 112, 0.15);
  --ab-shadow: 0 12px 32px -8px rgba(22, 95, 112, 0.28), 0 4px 12px -4px rgba(0, 0, 0, 0.08);
  --ab-radius: 16px;
  --ab-radius-bubble: 12px;
  --ab-fab-size: 58px;
  --ab-fab-offset: 20px;
  --ab-panel-w: 460px;
  --ab-panel-gap: 0px;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', system-ui, 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--ab-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================================
 * Bouton flottant (FAB)
 * ============================================================================
 */
.ab-fab {
  position: fixed;
  right: var(--ab-fab-offset);
  bottom: var(--ab-fab-offset);
  width: var(--ab-fab-size);
  height: var(--ab-fab-size);
  border: none;
  border-radius: 50%;
  background: var(--ab-accent);
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--ab-shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483000;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  padding: 0;
}
.ab-fab:hover,
.ab-fab:focus-visible {
  background: var(--ab-accent-strong);
  transform: translateY(-2px);
  outline: none;
  box-shadow: 0 16px 36px -8px rgba(22, 95, 112, 0.4), 0 6px 14px -4px rgba(0, 0, 0, 0.12);
}
.ab-fab:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}
.ab-fab svg {
  width: 26px;
  height: 26px;
  display: block;
}
.ab-fab .ab-fab-close { display: none; }
/* Quand le panneau est ouvert, le FAB glisse hors écran (le bouton × du header
   sert alors à fermer). Évite qu'il recouvre le bouton d'envoi sur mobile. */
.assistant-pluriel-widget[data-open='true'] .ab-fab {
  transform: translateX(140%);
  opacity: 0;
  pointer-events: none;
}

/* ============================================================================
 * Panneau
 * ============================================================================
 */
.ab-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--ab-panel-w);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--ab-cream);
  box-shadow: -12px 0 40px -12px rgba(22, 95, 112, 0.28), -4px 0 12px -4px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147482999;
  transform: translateX(100%);
  opacity: 1;
  pointer-events: none;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  border-left: 1px solid var(--ab-border);
}
.assistant-pluriel-widget[data-open='true'] .ab-panel {
  transform: translateX(0);
  pointer-events: auto;
}

/* En-tête */
.ab-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(22, 95, 112, 0.09), transparent);
  border-bottom: 1px solid var(--ab-border);
  flex-shrink: 0;
}
.ab-title {
  font-family: inherit;
  font-size: 19px;
  font-weight: 600;
  color: var(--ab-accent-strong);
  margin: 0;
  flex-grow: 1;
  letter-spacing: 0.01em;
}
.ab-header-btn {
  width: 45px;
  height: 45px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ab-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}
.ab-header-btn:hover,
.ab-header-btn:focus-visible {
  background: rgba(22, 95, 112, 0.1);
  color: var(--ab-accent-strong);
  outline: none;
}
.ab-header-btn:focus-visible {
  outline: 2px solid var(--ab-accent);
  outline-offset: 1px;
}
.ab-header-btn svg { width: 26px; height: 26px; }

/* Zone de messages */
.ab-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-anchor: none;
  scroll-behavior: auto;
}
.ab-messages::-webkit-scrollbar { width: 6px; }
.ab-messages::-webkit-scrollbar-thumb { background: rgba(22, 95, 112, 0.3); border-radius: 3px; }
.ab-messages::-webkit-scrollbar-track { background: transparent; }

.ab-msg {
  max-width: 92%;
  padding: 14px 18px;
  border-radius: var(--ab-radius-bubble);
  line-height: 1.55;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: ab-fadein 0.18s ease-out;
}
@keyframes ab-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ab-msg-bot {
  background: var(--ab-bot-bg);
  color: var(--ab-text);
  align-self: flex-start;
  border: 1px solid var(--ab-border);
  border-top-left-radius: 4px;
}

/* --- Streaming polish : gradient mask + curseur ------------------------------
 * Pendant que la réponse arrive, le bas du corps est légèrement fondu ; le
 * dernier bloc porte un curseur discret. Une fois le stream terminé, la
 * classe est retirée, tout redevient net. */
.ab-mot {
  animation: ab-mot 0.45s ease-out both;
}
@keyframes ab-mot {
  from { opacity: 0; filter: blur(3px); }
  to { opacity: 1; filter: blur(0); }
}
.ab-msg-bot--streaming .ab-msg-body > *:last-child::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--ab-accent);
  vertical-align: middle;
  animation: ab-pouls 1.1s ease-in-out infinite;
}
@keyframes ab-pouls {
  0%, 100% { opacity: 0.25; transform: scale(0.75); }
  50% { opacity: 0.9; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .ab-mot { animation: none; }
  .ab-msg-bot--streaming .ab-msg-body > *:last-child::after { animation: none; opacity: 0.6; }
}
.ab-msg-user {
  background: var(--ab-user-bg);
  color: var(--ab-text);
  align-self: flex-end;
  border-top-right-radius: 4px;
}
.ab-msg-error {
  background: #fbeaea;
  color: #7a1f1f;
  border: 1px solid #e5b7b7;
  align-self: flex-start;
  font-size: 14px;
}

/* Contenu markdown à l'intérieur des bulles */
.ab-msg p { margin: 0 0 0.5em 0; }
.ab-msg p:last-child { margin-bottom: 0; }
.ab-msg ul, .ab-msg ol { margin: 0.35em 0; padding-left: 1.25em; }
.ab-msg li { margin: 0.15em 0; }
.ab-msg strong { font-weight: 700; color: var(--ab-accent-strong); }
.ab-msg em { font-style: italic; }
.ab-msg a { color: var(--ab-accent); text-decoration: underline; text-underline-offset: 2px; }
.ab-msg a:hover { color: var(--ab-accent-strong); }
.ab-msg code {
  background: rgba(22, 95, 112, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.ab-msg h1, .ab-msg h2, .ab-msg h3 {
  font-family: inherit;
  color: var(--ab-accent-strong);
  margin: 0.4em 0 0.2em;
  line-height: 1.25;
}
.ab-msg h1 { font-size: 1.15em; }
.ab-msg h2 { font-size: 1.08em; }
.ab-msg h3 { font-size: 1em; }
.ab-msg blockquote {
  margin: 0.3em 0;
  padding-left: 0.75em;
  border-left: 3px solid var(--ab-accent);
  color: var(--ab-text-muted);
  font-style: italic;
}

/* Indicateur de typing */
.ab-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.ab-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ab-accent);
  opacity: 0.35;
  animation: ab-bounce 1.2s infinite ease-in-out;
}
.ab-typing span:nth-child(2) { animation-delay: 0.15s; }
.ab-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ab-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Sources RAG */
.ab-sources {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--ab-border);
  font-size: 0.85em;
  color: var(--ab-text-muted);
}
.ab-sources-title {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  color: var(--ab-accent);
}
.ab-source-item {
  display: block;
  margin: 2px 0;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(22, 95, 112, 0.06);
  color: var(--ab-text);
  text-decoration: none;
  border: none;
  font-size: 0.85em;
}
.ab-source-item:hover { background: rgba(22, 95, 112, 0.14); }

/* Suggestions */
.ab-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.ab-sugg {
  background: #ffffff;
  border: 1px solid var(--ab-border);
  color: var(--ab-accent-strong);
  padding: 10px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.ab-sugg:hover,
.ab-sugg:focus-visible {
  background: rgba(22, 95, 112, 0.08);
  transform: translateY(-1px);
  outline: none;
}
.ab-sugg:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 1px; }
.ab-sugg:active { transform: translateY(0); }

/* Formulaire */
.ab-form {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--ab-border);
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}
.ab-input {
  flex-grow: 1;
  border: 1px solid var(--ab-border);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.45;
  resize: none;
  background: #ffffff;
  color: var(--ab-text);
  min-height: 54px;
  max-height: 160px;
  overflow-y: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
/* La scrollbar n'apparaît que si le contenu dépasse la max-height (posée par JS). */
.ab-input.ab-scrollable { overflow-y: auto; }
.ab-input:focus-visible {
  outline: none;
  border-color: var(--ab-accent);
  box-shadow: 0 0 0 3px rgba(22, 95, 112, 0.14);
}
.ab-send {
  align-self: stretch;
  width: 52px;
  border: none;
  border-radius: 12px;
  background: var(--ab-accent);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
  flex-shrink: 0;
}
.ab-send:hover:not(:disabled),
.ab-send:focus-visible {
  background: var(--ab-accent-strong);
  outline: none;
}
.ab-send:focus-visible { outline: 2px solid var(--ab-accent); outline-offset: 2px; }
.ab-send:disabled {
  background: var(--ab-border);
  color: var(--ab-text-muted);
  cursor: not-allowed;
}
.ab-send svg { width: 32px; height: 32px; }

/* ============================================================================
 * Encart de la page d'accueil, en tête de la colonne de l'agenda (même gabarit que la carte épinglée
 * des événements : coins de 12 px, ombre légère, titre en Garamond), aux couleurs de Pluriel.
 * ============================================================================
 */
.ab-encart {
  position: relative;
  margin: 0 0 22px;
  padding: 18px 18px 16px;
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(127, 193, 210, 0.22) 0%, rgba(127, 193, 210, 0) 60%),
    linear-gradient(140deg, #165F70 0%, #0F4652 100%);
  color: #E4EEF0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
  font-family: Raleway, system-ui, sans-serif;
  text-align: left;
}
.ab-encart * { box-sizing: border-box; }
.ab-encart__tete { display: flex; align-items: center; gap: 8px; }
.ab-encart__icone { display: inline-flex; color: #9FD3DF; }
.ab-encart__icone svg { width: 18px; height: 18px; display: block; }
.ab-encart__surtitre {
  margin: 0 !important; font-size: 11px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: #9FD3DF !important;
}
.ab-encart__titre {
  margin: 8px 0 8px !important; padding: 0 !important; background: none !important;
  font-family: "EB Garamond", Georgia, serif !important; font-weight: 500 !important;
  font-size: 24px !important; line-height: 1.2 !important; color: #fff !important;
  text-transform: none !important; letter-spacing: 0 !important;
}
.ab-encart__titre em { font-style: italic; color: #fff; }
.ab-encart__texte { margin: 0 0 12px !important; font-size: 14px; line-height: 1.55; color: #E4EEF0 !important; }
.ab-encart__questions { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.ab-encart .ab-encart__question {
  position: relative; display: block; width: 100%; margin: 0; padding: 8px 32px 8px 11px;
  font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1.35; text-align: left;
  color: #fff; background: rgba(255, 255, 255, 0.08); background-image: none;
  border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 8px; box-shadow: none; text-shadow: none;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
/* Flèche qui glisse à droite au survol : la question se lance d'un clic. */
.ab-encart__question::after {
  content: '→';
  position: absolute; right: 12px; top: 50%;
  font-size: 15px; line-height: 1; color: #fff;
  opacity: 0; transform: translate(-6px, -50%);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
/* Le thème donne à tout button:hover une ombre intérieure brillante : on la remplace par une ombre portée douce. */
.ab-encart .ab-encart__question:hover,
.ab-encart .ab-encart__question:focus-visible {
  background-color: rgba(255, 255, 255, 0.18); background-image: none;
  border-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.35);
  transform: translateY(-1px);
  outline: none;
}
.ab-encart .ab-encart__question:hover::after,
.ab-encart .ab-encart__question:focus-visible::after { opacity: 1; transform: translate(0, -50%); }
.ab-encart .ab-encart__question:focus-visible { outline: 2px solid #9FD3DF; outline-offset: 2px; }
.ab-encart .ab-encart__question:active { transform: translateY(0); box-shadow: 0 2px 8px -4px rgba(0, 0, 0, 0.35); }
.ab-encart__cta {
  display: inline-flex; align-items: center; margin: 0; padding: 9px 16px;
  font-family: inherit; font-size: 14px; font-weight: 700; line-height: 1.2;
  color: #0F4652; background: #fff; border: 0; border-radius: 6px; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ab-encart__cta:hover,
.ab-encart__cta:focus-visible { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); outline: none; }
@media (prefers-reduced-motion: reduce) {
  .ab-encart__cta, .ab-encart .ab-encart__question, .ab-encart__question::after { transition: none; }
  .ab-encart__cta:hover, .ab-encart .ab-encart__question:hover { transform: none; }
}

/* Le thème donne à tout button:hover un reflet (ombre intérieure brillante) et une bordure grise : annulés dans
   la fenêtre de l'assistant ; le bouton flottant garde son ombre portée. */
.assistant-pluriel-widget button:hover { box-shadow: none; }
.assistant-pluriel-widget .ab-sugg:hover,
.assistant-pluriel-widget .ab-sugg:focus-visible { border-color: var(--ab-accent); background-image: none; }
.assistant-pluriel-widget .ab-fab:hover,
.assistant-pluriel-widget .ab-fab:focus-visible {
  box-shadow: 0 16px 36px -8px rgba(22, 95, 112, 0.4), 0 6px 14px -4px rgba(0, 0, 0, 0.12);
}

/* Barre du bas des pages refondues : le bouton « IA » y remplace « Recherche » et tient lieu de bouton flottant
   (≤ 900 px) ; la recherche du site passe en tête du menu (.ab-recherche-menu, injecté par le script). */
@media (max-width: 900px) {
  .assistant-pluriel-widget.ab-dans-barre .ab-fab { display: none; }
}
.ab-recherche-menu { display: none; }
@media (max-width: 900px) {
  #test-rg-page .ab-recherche-menu { display: flex; gap: 6px; margin: 0 0 18px; }
  #test-rg-page .ab-recherche-menu input {
    flex: 1; min-width: 0; font-family: inherit; font-size: 16px; color: #1a1a1a;
    padding: 10px 12px; border: 1px solid rgba(22, 95, 112, 0.25); border-radius: 8px; background: #fff;
  }
  #test-rg-page .ab-recherche-menu button {
    display: inline-flex; align-items: center; padding: 0 12px; border: 0; border-radius: 8px;
    background: #165F70; color: #fff; cursor: pointer;
  }
  #test-rg-page .ab-recherche-menu svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
}

/* Pages du site refondu : sur téléphone et tablette (≤ 900 px), une barre de navigation fixe de 60 px
   occupe le bas de l'écran (mu-plugin pluriel-mobile-bottombar) ; le bouton se place au-dessus. */
@media (max-width: 900px) {
  body.test-rg-page-body .assistant-pluriel-widget:not(.assistant-pluriel-widget--integre) .ab-fab {
    bottom: calc(var(--ab-fab-offset) + 60px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================================
 * Mode intégré — l'assistant dans le corps de la page (élément #assistant-pluriel).
 * Ordinateur : carte de hauteur fixe, les messages défilent à l'intérieur.
 * Téléphone (≤ 760 px) : carte compacte dans la page, puis plein écran dès
 * qu'on s'en sert (classe .ab-plein-ecran posée par le script).
 * ============================================================================
 */
.assistant-pluriel-widget--integre {
  position: relative;
  text-align: left;
}
.assistant-pluriel-widget--integre .ab-panel {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  width: 100%;
  max-width: none;
  height: min(78vh, 820px);
  min-height: 540px;
  transform: none;
  pointer-events: auto;
  z-index: auto;
  border: 1px solid var(--ab-border);
  border-radius: var(--ab-radius);
  box-shadow: var(--ab-shadow);
  transition: none;
}
.assistant-pluriel-widget--integre .ab-fermer { display: none; }
html.ab-verrou,
html.ab-verrou body { overflow: hidden; }

@media (max-width: 760px) {
  .assistant-pluriel-widget--integre .ab-panel {
    height: auto;
    min-height: 0;
    max-height: 78vh;
    box-shadow: none;
  }
  .assistant-pluriel-widget--integre .ab-messages { min-height: 0; padding: 14px 14px 6px; }
  .assistant-pluriel-widget--integre.ab-plein-ecran .ab-panel {
    position: fixed;
    top: var(--ab-vv-top, 0px);
    left: 0;
    right: 0;
    width: auto;
    height: 100vh;
    height: var(--ab-vv-h, 100dvh);
    max-height: none;
    border: 0;
    border-radius: 0;
    z-index: 2147482999;
  }
  .assistant-pluriel-widget--integre.ab-plein-ecran .ab-fermer { display: inline-flex; }
  .assistant-pluriel-widget--integre.ab-plein-ecran .ab-form {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

/* ============================================================================
 * Responsive — pleine largeur / plein écran ≤ 600 px (téléphones).
 * Au-delà (tablettes, ordinateurs) : colonne de largeur fixe ancrée à droite.
 * On utilise left:0 + right:0 (et non 100vw) pour couvrir exactement la zone
 * de contenu, quelle que soit la largeur de la barre de défilement.
 * ============================================================================
 */
@media (max-width: 600px) {
  .assistant-pluriel-widget {
    --ab-fab-size: 54px;
    --ab-fab-offset: 14px;
  }
  .ab-panel {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    border-left: none;
    box-shadow: none;
  }
  .ab-messages { padding: 14px 14px 6px; }
  .ab-form { padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0)); }
}

/* Texte réservé aux lecteurs d'écran (typing indicator, annonce SR finale) */
.ab-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Réduit les animations si l'utilisateur préfère */
@media (prefers-reduced-motion: reduce) {
  .assistant-pluriel-widget *,
  .assistant-pluriel-widget *::before,
  .assistant-pluriel-widget *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
  .assistant-pluriel-widget .ab-messages {
    scroll-behavior: auto !important;
  }
}

/* Arabe : chaque paragraphe prend le sens de sa première lettre (ajout Pluriel, 25/11/2026). */
.assistant-pluriel-widget .ab-msg,
.assistant-pluriel-widget .ab-msg-body p,
.assistant-pluriel-widget .ab-msg-body li,
.assistant-pluriel-widget textarea {
  unicode-bidi: plaintext;
  text-align: start;
}
/* Les réponses citent déjà leurs liens : la liste technique des documents Dify est masquée. */
.assistant-pluriel-widget .ab-sources { display: none; }
