/* Widget chatbot Qualibat — styles encapsulés sous #qualibat-chatbot.
   Charte : primary #007bca, primary-dark #0d1b41, primary-light #6AC7F4, secondary #f8ce39. */

#qualibat-chatbot {
  --qb-primary: #007bca;
  --qb-primary-dark: #0d1b41;
  --qb-primary-light: #6ac7f4;
  --qb-accent: #f8ce39;
  --qb-text: #1f2a37;
  --qb-muted: #5b6b7b;
  --qb-bg: #ffffff;
  --qb-surface: #f4f7fa;
  --qb-bot-bubble: #eef3f8;
  --qb-border: #e2e8f0;
  --qb-shadow: 0 18px 48px rgba(13, 27, 65, .22);
  --qb-radius: 16px;

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2147483000;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--qb-text);
}

#qualibat-chatbot *,
#qualibat-chatbot *::before,
#qualibat-chatbot *::after {
  box-sizing: border-box;
}

/* ---- Lanceur ---- */
.qb-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--qb-primary-dark);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--qb-shadow);
  transition: transform .18s ease, background-color .18s ease;
}

.qb-launcher:hover { background: var(--qb-primary); transform: translateY(-2px); }
.qb-launcher:focus-visible { outline: 3px solid var(--qb-primary-light); outline-offset: 3px; }
.qb-launcher svg { width: 28px; height: 28px; }
.qb-launcher .qb-icon-close { display: none; }

#qualibat-chatbot.qb-open .qb-launcher .qb-icon-open { display: none; }
#qualibat-chatbot.qb-open .qb-launcher .qb-icon-close { display: block; }

/* ---- Panneau ---- */
.qb-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 116px);
  display: flex;
  flex-direction: column;
  background: var(--qb-bg);
  border: 1px solid var(--qb-border);
  border-radius: var(--qb-radius);
  box-shadow: var(--qb-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

#qualibat-chatbot.qb-open .qb-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---- En-tête ---- */
.qb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--qb-primary-dark), var(--qb-primary));
  color: #fff;
}

.qb-header__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .16);
  flex: 0 0 auto;
}
.qb-header__avatar svg { width: 22px; height: 22px; }

.qb-header__titles { display: flex; flex-direction: column; min-width: 0; }
.qb-header__title { font-size: 15px; font-weight: 600; }
.qb-header__status { font-size: 12px; opacity: .85; }

.qb-header__close {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease;
}
.qb-header__close:hover { background: rgba(255, 255, 255, .18); }
.qb-header__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.qb-header__close svg { width: 18px; height: 18px; }

/* ---- Fil de conversation ---- */
.qb-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--qb-surface);
  scroll-behavior: smooth;
}

.qb-msg { display: flex; max-width: 84%; }
.qb-msg__bubble {
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.qb-msg--user { align-self: flex-end; }
.qb-msg--user .qb-msg__bubble {
  background: var(--qb-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.qb-msg--bot { align-self: flex-start; }
.qb-msg--bot .qb-msg__bubble {
  background: var(--qb-bot-bubble);
  color: var(--qb-text);
  border-bottom-left-radius: 4px;
}
.qb-msg__bubble a { color: var(--qb-primary); font-weight: 600; text-decoration: underline; }
.qb-msg--user .qb-msg__bubble a { color: #fff; }
.qb-msg__bubble strong { font-weight: 700; }

/* Feedback (pouce haut / bas) sous les réponses du bot */
.qb-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding-left: 2px;
}
.qb-feedback__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--qb-muted);
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.qb-feedback__btn:hover { background: var(--qb-bot-bubble); color: var(--qb-primary); }
.qb-feedback__btn:focus-visible { outline: 2px solid var(--qb-primary-light); outline-offset: 1px; }
.qb-feedback__btn--active { color: var(--qb-primary); background: var(--qb-bot-bubble); }
.qb-feedback__btn svg { width: 15px; height: 15px; }

/* Indicateur de saisie */
.qb-typing { align-self: flex-start; }
.qb-typing .qb-msg__bubble { display: inline-flex; align-items: center; gap: 8px; color: var(--qb-muted); }
.qb-typing__dots { display: inline-flex; gap: 4px; }
.qb-typing__dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--qb-muted);
  animation: qb-bounce 1.2s infinite ease-in-out both;
}
.qb-typing__dots span:nth-child(2) { animation-delay: .15s; }
.qb-typing__dots span:nth-child(3) { animation-delay: .3s; }

@keyframes qb-bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- Zone de saisie ---- */
.qb-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--qb-border);
  background: var(--qb-bg);
}

.qb-composer__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  padding: 8px 10px;
  border: 1px solid var(--qb-border);
  border-radius: 12px;
  font: inherit;
  color: var(--qb-text);
  background: #fff;
}
.qb-composer__input:focus { outline: none; border-color: var(--qb-primary); box-shadow: 0 0 0 3px rgba(0, 124, 202, .15); }
.qb-composer__input::placeholder { color: var(--qb-muted); }

.qb-composer__send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--qb-primary);
  color: #fff;
  cursor: pointer;
  transition: background-color .15s ease;
}
.qb-composer__send:hover:not(:disabled) { background: var(--qb-primary-dark); }
.qb-composer__send:focus-visible { outline: 2px solid var(--qb-primary-dark); outline-offset: 2px; }
.qb-composer__send:disabled { opacity: .5; cursor: not-allowed; }
.qb-composer__send svg { width: 18px; height: 18px; }

.qb-footnote {
  padding: 0 12px 10px;
  font-size: 11px;
  color: var(--qb-muted);
  text-align: center;
  background: var(--qb-bg);
}

/* ---- Tablette ---- */
@media (max-width: 1024px) {
  .qb-panel { width: 340px; }
}

/* ---- Mobile : plein écran ---- */
@media (max-width: 767px) {
  #qualibat-chatbot { right: 24px; bottom: 24px; }
  .qb-launcher { width: 52px; height: 52px; }
  #qualibat-chatbot.qb-open .qb-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qb-launcher,
  .qb-panel,
  .qb-typing__dots span { transition: none; animation: none; }
  .qb-thread { scroll-behavior: auto; }
}
