/* =====================================================================
   chatbot.css — Bulle d'assistance IA (réutilisable)
   ---------------------------------------------------------------------
   S'appuie sur les variables de thème (:root) de style.css quand elles
   existent, avec des valeurs de repli pour fonctionner sur n'importe quel
   site. Thème sombre + accent jaune par défaut (Ohweed).
   ===================================================================== */
.cbw {
  --cbw-bg: var(--color-surface, #141414);
  --cbw-bg2: var(--color-surface-2, #1e1e1e);
  --cbw-border: var(--color-border, #292929);
  --cbw-accent: var(--color-accent, #ffe235);
  --cbw-ink: var(--color-accent-ink, #0a0a0a);
  --cbw-text: var(--color-text, #ededed);
  --cbw-muted: var(--color-muted, #9a9a9a);
  --cbw-heading: var(--color-heading, #fff);
  --cbw-radius: 16px;
  --cbw-font: var(--font-heading, system-ui, sans-serif);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: var(--cbw-font);
}

/* ---------- Bouton bulle ---------- */
.cbw__toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--cbw-accent);
  color: var(--cbw-ink);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cbw__toggle:hover {
  transform: translateY(-2px) scale(1.04);
}
.cbw__toggle:focus-visible {
  outline: 3px solid var(--cbw-accent);
  outline-offset: 3px;
}
.cbw__toggle svg {
  width: 28px;
  height: 28px;
}
.cbw__toggle-close {
  display: none;
}
.cbw.is-open .cbw__toggle-open {
  display: none;
}
.cbw.is-open .cbw__toggle-close {
  display: block;
}

/* ---------- Panneau ---------- */
.cbw__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--cbw-bg);
  border: 1px solid var(--cbw-border);
  border-radius: var(--cbw-radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.cbw.is-open .cbw__panel {
  display: flex;
  animation: cbw-in 0.18s ease;
}
@keyframes cbw-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- En-tête ---------- */
.cbw__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--cbw-bg2);
  border-bottom: 1px solid var(--cbw-border);
}
.cbw__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cbw-accent);
  color: var(--cbw-ink);
  flex: 0 0 auto;
}
.cbw__avatar svg {
  width: 20px;
  height: 20px;
}
.cbw__title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.cbw__title strong {
  color: var(--cbw-heading);
  font-size: 0.95rem;
}
.cbw__title span {
  color: var(--cbw-muted);
  font-size: 0.72rem;
}
.cbw__head-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--cbw-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
}
.cbw__head-close:hover {
  color: var(--cbw-heading);
  background: rgba(255, 255, 255, 0.06);
}
.cbw__head-close svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ---------- Corps / messages ---------- */
.cbw__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}
.cbw__msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--cbw-text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.cbw__msg--bot {
  align-self: flex-start;
  background: var(--cbw-bg2);
  border: 1px solid var(--cbw-border);
  border-bottom-left-radius: 4px;
}
.cbw__msg--user {
  align-self: flex-end;
  background: var(--cbw-accent);
  color: var(--cbw-ink);
  border-bottom-right-radius: 4px;
}
.cbw__msg--error {
  align-self: flex-start;
  background: rgba(255, 59, 59, 0.12);
  border: 1px solid rgba(255, 59, 59, 0.5);
  color: #ffd7d7;
  border-bottom-left-radius: 4px;
}
.cbw__msg p {
  margin: 0 0 8px;
}
.cbw__msg p:last-child {
  margin-bottom: 0;
}
.cbw__msg ul,
.cbw__msg ol {
  margin: 4px 0;
  padding-left: 20px;
}
.cbw__msg a {
  color: inherit;
  text-decoration: underline;
}
.cbw__msg--bot a {
  color: var(--cbw-accent);
}
.cbw__msg code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.85em;
}

/* Bouton « réessayer » sous un message d'erreur */
.cbw__retry {
  align-self: flex-start;
  margin-top: -6px;
  background: none;
  border: 1px solid var(--cbw-border);
  color: var(--cbw-text);
  font-size: 0.8rem;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.cbw__retry:hover {
  border-color: var(--cbw-accent);
  color: var(--cbw-accent);
}

/* Indicateur « en train d'écrire » */
.cbw__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.cbw__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cbw-muted);
  animation: cbw-bounce 1.2s infinite ease-in-out;
}
.cbw__typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.cbw__typing span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes cbw-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ---------- Pied / saisie ---------- */
.cbw__foot {
  border-top: 1px solid var(--cbw-border);
  padding: 10px 12px 12px;
  background: var(--cbw-bg);
}
.cbw__inputrow {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--cbw-bg2);
  border: 1px solid var(--cbw-border);
  border-radius: 12px;
  padding: 6px 6px 6px 12px;
}
.cbw__inputrow:focus-within {
  border-color: var(--cbw-accent);
}
.cbw__input {
  flex: 1;
  background: none;
  border: none;
  resize: none;
  color: var(--cbw-text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  max-height: 110px;
  padding: 6px 0;
  outline: none;
}
.cbw__input::placeholder {
  color: var(--cbw-muted);
}
.cbw__send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: var(--cbw-accent);
  color: var(--cbw-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cbw__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.cbw__send svg {
  width: 18px;
  height: 18px;
}
.cbw__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding: 0 4px;
}
.cbw__disclaimer {
  color: var(--cbw-muted);
  font-size: 0.68rem;
}
.cbw__count {
  color: var(--cbw-muted);
  font-size: 0.68rem;
}
.cbw__count.is-over {
  color: var(--color-sale, #ff3b3b);
}

.cbw__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .cbw {
    right: 12px;
    bottom: 12px;
  }
  .cbw__panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    bottom: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cbw.is-open .cbw__panel,
  .cbw__typing span,
  .cbw__toggle {
    animation: none;
    transition: none;
  }
}
