/* ==========================================================================
   Widget de discussion, tout est scopé sous .fcb-root.
   Les couleurs viennent des réglages (attribut style de la racine :
   --fcb-primary, --fcb-primary-dark, --fcb-on-primary, --fcb-link,
   --fcb-launcher, --fcb-on-launcher) ; le reste est neutre. Police système.
   Panneau clair : en-tête fin coloré, accueil centré, champ en carte arrondie.
   ========================================================================== */

.fcb-root {
  --fcb-primary: #70BAFF;
  --fcb-primary-dark: #5f9ed9;
  --fcb-on-primary: #1F2937;
  --fcb-link: #2F6FAB;
  --fcb-launcher: #343431;
  --fcb-on-launcher: #FFFFFF;
  --fcb-surface: #FFFFFF;
  --fcb-canvas: #FAFAFA;
  --fcb-text: #09090B;
  --fcb-muted: #5F6470;
  --fcb-border: #E4E4E7;
  --fcb-frame: #E2E2E2;
  --fcb-error: #A51D1D;
  --fcb-error-bg: #FFF1F1;
  --fcb-error-border: #E3AFAF;
  --fcb-radius: 15px;
  --fcb-shadow: 0 4px 16px 2px rgba(0, 0, 0, .12);
  --fcb-gap: 20px;
  --fcb-z: 100000; /* au-dessus des en-têtes fixes des thèmes et de la barre d'admin (99999) */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--fcb-text);
}

/* --- Remise à zéro locale (les thèmes stylisent p, ul, li::before, form, img, button, textarea en global) --- */
.fcb-root *,
.fcb-root *::before,
.fcb-root *::after {
  box-sizing: border-box;
}

.fcb-root [hidden] {
  display: none !important;
}

.fcb-root button,
.fcb-root textarea {
  min-width: 0;
  min-height: 0;
  margin: 0;
  box-shadow: none;
  font-family: inherit;
  font-weight: 400;
  letter-spacing: normal;
  text-decoration: none;
  text-shadow: none;
  text-transform: none;
  -webkit-appearance: none;
  appearance: none;
}

.fcb-root button {
  cursor: pointer;
}

.fcb-root p,
.fcb-root ul,
.fcb-root ol,
.fcb-root li,
.fcb-root h2,
.fcb-root form {
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
  text-transform: none;
  letter-spacing: normal;
}

/* La puce vient du ul / ol, pas d'une icône ajoutée par le thème */
.fcb-root li {
  position: static;
  list-style: inherit;
}

.fcb-root li::before,
.fcb-root li::after {
  content: none;
}

.fcb-root img {
  display: block;
  max-width: none;
  margin: 0;
  border: 0;
  box-shadow: none;
}

.fcb-root :focus-visible {
  outline: 2px solid var(--fcb-link);
  outline-offset: 2px;
}

.fcb-root .fcb-sr {
  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;
}

.fcb-root .fcb-icon {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  max-width: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fcb-root .fcb-icon--fill {
  fill: currentColor;
  stroke: none;
}

/* --- Bouton flottant --- */
.fcb-root .fcb-launcher {
  position: fixed;
  bottom: var(--fcb-gap);
  z-index: var(--fcb-z);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  background: none;
}

.fcb-root--right .fcb-launcher {
  right: var(--fcb-gap);
  flex-direction: row;
}

.fcb-root--left .fcb-launcher {
  left: var(--fcb-gap);
  flex-direction: row-reverse;
}

.fcb-root .fcb-launcher__button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--fcb-launcher);
  color: var(--fcb-on-launcher);
  box-shadow: 0 2px 10px 1px rgba(0, 0, 0, .28);
  transition: transform .15s ease;
}

.fcb-root .fcb-launcher:hover .fcb-launcher__button {
  transform: scale(1.05);
}

.fcb-root .fcb-launcher .fcb-icon {
  width: 28px;
  height: 28px;
}

/* Contour de la couleur du bouton : l'étincelle se détache de la bulle */
.fcb-root .fcb-launcher__spark {
  stroke: var(--fcb-launcher);
  stroke-width: 2;
  paint-order: stroke;
}

.fcb-root .fcb-launcher .fcb-launcher__close {
  width: 24px;
  height: 24px;
}

.fcb-root .fcb-launcher__close,
.fcb-root.fcb-root--open .fcb-launcher__open {
  display: none;
}

.fcb-root.fcb-root--open .fcb-launcher__close {
  display: block;
}

.fcb-root .fcb-launcher__bubble {
  max-width: 220px;
  padding: 10px 14px;
  border: 1px solid var(--fcb-frame);
  border-radius: var(--fcb-radius);
  background: var(--fcb-surface);
  color: var(--fcb-text);
  box-shadow: var(--fcb-shadow);
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
  animation: fcb-in .3s ease-out .8s both;
}

.fcb-root.fcb-root--seen .fcb-launcher__bubble,
.fcb-root.fcb-root--open .fcb-launcher__bubble {
  display: none;
}

/* --- Panneau --- */
.fcb-root .fcb-panel {
  position: fixed;
  bottom: calc(var(--fcb-gap) + 76px);
  z-index: var(--fcb-z);
  display: flex;
  flex-direction: column;
  width: min(550px, calc(100vw - 2 * var(--fcb-gap)));
  height: min(560px, calc(100vh - var(--fcb-gap) - 100px));
  height: min(560px, calc(100dvh - var(--fcb-gap) - 100px));
  overflow: hidden;
  border: 1px solid var(--fcb-frame);
  border-radius: var(--fcb-radius);
  background: var(--fcb-canvas);
  box-shadow: var(--fcb-shadow);
  animation: fcb-in .2s ease-out;
}

.fcb-root--right .fcb-panel {
  right: var(--fcb-gap);
}

.fcb-root--left .fcb-panel {
  left: var(--fcb-gap);
}

/* Bouton flottant masqué : le panneau prend sa place */
.fcb-root .fcb-launcher[hidden] ~ .fcb-panel {
  bottom: var(--fcb-gap);
}

.fcb-root .fcb-panel:focus {
  outline: none;
}

@keyframes fcb-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* --- En-tête : bandeau fin, icône ronde et nom de l'assistant --- */
.fcb-root .fcb-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 6px 6px 12px;
  background: var(--fcb-primary);
  color: var(--fcb-on-primary);
}

.fcb-root .fcb-header__avatar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
}

.fcb-root .fcb-header__avatar .fcb-icon {
  width: 24px;
  height: 24px;
}

.fcb-root .fcb-header__img {
  width: 28px;
  height: 28px;
  object-fit: cover;
}

.fcb-root .fcb-header__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fcb-root .fcb-corner {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}

.fcb-root .fcb-corner .fcb-icon {
  width: 18px;
  height: 18px;
}

.fcb-root .fcb-corner:hover {
  background: rgba(255, 255, 255, .25);
}

.fcb-root .fcb-header :focus-visible {
  outline-color: var(--fcb-on-primary);
  outline-offset: -2px;
}

/* --- Fil --- */
.fcb-root .fcb-scroller {
  flex: 1;
  min-height: 0;
  padding: 16px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Fil vide : le champ suit l'accueil, l'espace libre reste en bas du panneau */
.fcb-root.fcb-root--empty .fcb-scroller {
  flex: 0 1 auto;
}

/* --- Accueil, tant que la discussion est vide --- */
.fcb-root .fcb-intro {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 0 4px;
  text-align: center;
}

.fcb-root.fcb-root--empty .fcb-intro {
  display: flex;
}

.fcb-root .fcb-intro__logo {
  width: auto;
  max-width: 160px;
  height: 40px;
  object-fit: contain;
}

.fcb-root .fcb-intro__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}

.fcb-root .fcb-intro__subtitle {
  margin-top: -6px;
  color: var(--fcb-muted);
  font-size: 14px;
}

.fcb-root .fcb-intro__text {
  font-size: 16px;
  line-height: 1.5;
}

.fcb-root .fcb-log {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.fcb-root .fcb-log:empty {
  display: none;
}

.fcb-root .fcb-msg {
  display: flex;
}

.fcb-root .fcb-msg--user {
  justify-content: flex-end;
}

.fcb-root .fcb-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  overflow-wrap: anywhere;
}

/* Réponse de l'agent : texte posé sur le fond du panneau, sur toute la largeur */
.fcb-root .fcb-msg--agent .fcb-bubble {
  max-width: 100%;
  padding: 2px 0;
}

.fcb-root .fcb-msg--user .fcb-bubble {
  border-bottom-right-radius: 4px;
  background: var(--fcb-primary);
  color: var(--fcb-on-primary);
}

.fcb-root .fcb-msg--error .fcb-bubble {
  max-width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--fcb-error-border);
  border-radius: 12px;
  background: var(--fcb-error-bg);
  color: var(--fcb-error);
}

.fcb-root .fcb-plain {
  white-space: pre-wrap;
}

.fcb-root .fcb-md > * + * {
  margin-top: 8px;
}

.fcb-root .fcb-md ul,
.fcb-root .fcb-md ol {
  padding-left: 20px;
}

.fcb-root .fcb-md ul {
  list-style: disc;
}

.fcb-root .fcb-md ol {
  list-style: decimal;
}

.fcb-root .fcb-md li + li {
  margin-top: 4px;
}

.fcb-root .fcb-md strong {
  font-weight: 600;
}

.fcb-root .fcb-bubble a {
  color: var(--fcb-link);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.fcb-root .fcb-bubble a:hover {
  text-decoration-thickness: 2px;
}

.fcb-root .fcb-msg--error .fcb-bubble a {
  color: inherit;
}

.fcb-root .fcb-ai-notice {
  margin-top: 8px;
  color: var(--fcb-muted);
  font-size: 12px;
  line-height: 1.4;
}

/* --- Indicateur d'écriture --- */
.fcb-root .fcb-typing .fcb-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fcb-muted);
  font-size: 14px;
}

.fcb-root .fcb-dots {
  display: inline-flex;
  gap: 4px;
}

.fcb-root .fcb-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: fcb-dot 1.2s infinite ease-in-out;
}

.fcb-root .fcb-dots span:nth-child(2) {
  animation-delay: .15s;
}

.fcb-root .fcb-dots span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes fcb-dot {
  0%, 80%, 100% { opacity: .3; transform: scale(.8); }
  40% { opacity: 1; transform: none; }
}

/* --- Questions suggérées et boutons secondaires --- */
.fcb-root .fcb-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.fcb-root .fcb-choices:empty {
  display: none;
}

.fcb-root .fcb-pill {
  max-width: 100%;
  padding: 7px 14px;
  border: 1px solid var(--fcb-border);
  border-radius: 18px;
  background: var(--fcb-surface);
  color: var(--fcb-text);
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
}

.fcb-root .fcb-pill:hover {
  border-color: var(--fcb-primary);
  background: var(--fcb-primary);
  color: var(--fcb-on-primary);
}

.fcb-root .fcb-retry {
  display: block;
  margin-top: 8px;
  border-color: currentColor;
  background: transparent;
  color: inherit;
}

.fcb-root .fcb-retry:hover {
  border-color: var(--fcb-error);
  background: var(--fcb-error);
  color: #FFFFFF;
}

/* --- Vérification anti-robot --- */
.fcb-root .fcb-gate {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--fcb-border);
  border-radius: 12px;
  background: var(--fcb-surface);
}

.fcb-root .fcb-gate__text {
  margin-bottom: 8px;
  font-size: 14px;
}

.fcb-root .fcb-turnstile {
  min-height: 65px;
}

.fcb-root .fcb-gate__error {
  margin-top: 8px;
  color: var(--fcb-error);
  font-size: 14px;
}

/* --- Saisie : carte arrondie, bouton d'envoi rond --- */
/* Certains thèmes centrent les formulaires (margin: 0 auto), ce qui rétrécit la saisie */
.fcb-root .fcb-composer {
  flex-shrink: 0;
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0 10px 12px;
}

.fcb-root .fcb-restart {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px 6px;
  padding: 4px 10px;
  border: 1px solid var(--fcb-border);
  border-radius: 14px;
  background: var(--fcb-surface);
  color: var(--fcb-muted);
  font-size: 13px;
}

.fcb-root .fcb-restart .fcb-icon {
  width: 14px;
  height: 14px;
}

.fcb-root .fcb-restart:hover {
  color: var(--fcb-text);
}

.fcb-root .fcb-composer__box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 12px 12px 10px 16px;
  border: 1px solid var(--fcb-border);
  border-radius: 16px;
  background: var(--fcb-surface);
  transition: border-color .15s ease;
}

.fcb-root .fcb-composer__box:focus-within {
  border-color: var(--fcb-link);
}

.fcb-root .fcb-input {
  flex: 1 0 100%;
  width: 100%;
  min-height: 50px;
  max-height: 160px;
  padding: 2px 8px 2px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fcb-text);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
}

.fcb-root .fcb-input::placeholder {
  color: var(--fcb-muted);
  opacity: 1;
}

/* Le contour de la carte signale le focus du champ */
.fcb-root .fcb-input:focus,
.fcb-root .fcb-input:focus-visible {
  border: 0;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: var(--fcb-text);
}

.fcb-root .fcb-input:disabled {
  cursor: not-allowed;
}

.fcb-root .fcb-send {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--fcb-border);
  border-radius: 50%;
  background: transparent;
  color: rgba(0, 0, 0, .3);
  transition: background-color .15s ease, color .15s ease;
}

.fcb-root .fcb-send .fcb-icon {
  width: 18px;
  height: 18px;
}

/* Champ rempli (classe posée par le script) : bouton d'envoi en couleur */
.fcb-root .fcb-composer--filled .fcb-send:not(:disabled) {
  border-color: var(--fcb-primary);
  background: var(--fcb-primary);
  color: var(--fcb-on-primary);
}

.fcb-root .fcb-composer--filled .fcb-send:hover:not(:disabled) {
  border-color: var(--fcb-primary-dark);
  background: var(--fcb-primary-dark);
}

.fcb-root .fcb-send:disabled {
  cursor: not-allowed;
}

.fcb-root .fcb-counter {
  color: var(--fcb-muted);
  font-size: 12px;
}

.fcb-root .fcb-counter--max {
  color: var(--fcb-error);
}

/* --- Petit écran : panneau en plein écran, la page ne défile plus dessous --- */
@media (max-width: 575.98px) {
  html.fcb-lock {
    overflow: hidden;
  }

  .fcb-root {
    --fcb-gap: 16px;
  }

  .fcb-root .fcb-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .fcb-root.fcb-root--open .fcb-launcher {
    display: none;
  }

  .fcb-root .fcb-launcher__bubble {
    max-width: 180px;
  }

  /* 16 px au moins : iOS ne zoome pas sur le champ */
  .fcb-root .fcb-input {
    font-size: 16px;
  }
}

@media (forced-colors: active) {
  .fcb-root .fcb-bubble,
  .fcb-root .fcb-panel,
  .fcb-root .fcb-launcher__button,
  .fcb-root .fcb-send {
    border: 1px solid CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fcb-root *,
  .fcb-root *::before,
  .fcb-root *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  .fcb-root {
    display: none !important;
  }
}
