/*
 * Charlie — styles du widget de la KB v2.
 *
 * Porté depuis les sites v1 (`docs-doc/stylesheets/sensaas-bot.css`). La
 * structure est la même ; seules les couleurs changent, rebranchées sur les
 * jetons de la charte v2 (`extra.css`) pour que le widget ne jure pas avec le
 * reste du site et suive les deux schémas sans réglage propre.
 */

#sensaas-bot-root {
  /* Encre de l'en-tête du site : le widget en est le prolongement. */
  --bot-primary: var(--sen-encre, #0c1524);
  --bot-bg: var(--sen-card, #fff);
  --bot-fg: var(--md-default-fg-color, #0c1524);
  --bot-muted: var(--md-default-fg-color--light, #5a6b7f);
  --bot-border: var(--sen-bordure, rgb(148 163 184 / 0.38));
  /* Bleu de marque, déjà décliné par schéma pour les liens du site. */
  --bot-link: var(--md-typeset-a-color, #0693e3);
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 2000;
  font-size: .8rem;
}

/* Bouton flottant */
.sensaas-bot-toggle {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  border: none;
  background: var(--bot-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--sen-ombre);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.sensaas-bot-toggle:hover { transform: translateY(-2px); box-shadow: var(--sen-ombre-survol); }
#sensaas-bot-root.open .sensaas-bot-toggle { display: none; }

/* Panneau */
.sensaas-bot-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(25rem, calc(100vw - 2rem));
  height: min(80vh, 44rem);
  max-height: calc(100vh - 5rem);
  background: var(--bot-bg);
  color: var(--bot-fg);
  border: 1px solid var(--bot-border);
  border-radius: .7rem;
  box-shadow: var(--sen-ombre);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sensaas-bot-panel[hidden] { display: none; }

.sensaas-bot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .7rem .9rem;
  background: var(--bot-primary);
  color: #fff;
}
.sensaas-bot-title { font-weight: 700; }
.sensaas-bot-close {
  background: none; border: none; color: #fff;
  font-size: 1rem; cursor: pointer; line-height: 1; padding: .2rem;
}

.sensaas-bot-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: .8rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.sensaas-bot-msg {
  max-width: 88%;
  padding: .5rem .7rem;
  border-radius: .6rem;
  line-height: 1.45;
  word-wrap: break-word;
}
.sensaas-bot-msg.user {
  align-self: flex-end;
  background: var(--bot-primary);
  color: #fff;
  border-bottom-right-radius: .15rem;
  white-space: pre-wrap;
}
.sensaas-bot-msg.assistant {
  align-self: flex-start;
  background: var(--md-code-bg-color, rgba(0, 0, 0, .05));
  color: var(--bot-fg);
  border-bottom-left-radius: .15rem;
}
.sensaas-bot-msg.error {
  background: color-mix(in srgb, var(--sen-danger) 12%, transparent);
  color: var(--sen-danger);
}
.sensaas-bot-msg p { margin: 0 0 .4rem; }
.sensaas-bot-msg p:last-child { margin-bottom: 0; }
.sensaas-bot-msg h4, .sensaas-bot-msg h5 { margin: .55rem 0 .25rem; line-height: 1.3; font-weight: 700; }
.sensaas-bot-msg h4 { font-size: 1em; }
.sensaas-bot-msg h5 { font-size: .95em; }
.sensaas-bot-msg > :first-child { margin-top: 0; }
.sensaas-bot-msg ul, .sensaas-bot-msg ol { margin: .2rem 0; padding-left: 1.1rem; }
.sensaas-bot-msg code {
  background: var(--md-code-bg-color, rgba(0, 0, 0, .07));
  padding: .05rem .3rem; border-radius: .25rem; font-size: .92em;
}
.sensaas-bot-msg a { color: var(--bot-link); text-decoration: underline; }

/* Sources */
.sensaas-bot-sources {
  align-self: flex-start;
  max-width: 88%;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  font-size: .74rem;
  padding: .1rem .2rem .3rem;
}
.sensaas-bot-sources-label { color: var(--bot-muted); font-weight: 700; }
.sensaas-bot-sources a { color: var(--bot-link); text-decoration: underline; }
.sensaas-bot-sources a:hover { opacity: .85; }

/* Indicateur de saisie */
.sensaas-bot-typing { display: flex; gap: .25rem; }
.sensaas-bot-typing span {
  width: .45rem; height: .45rem; border-radius: 50%;
  background: var(--bot-muted); opacity: .5;
  animation: sensaas-bot-blink 1.2s infinite;
}
.sensaas-bot-typing span:nth-child(2) { animation-delay: .2s; }
.sensaas-bot-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes sensaas-bot-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: .9; } }

/* Formulaire */
.sensaas-bot-form {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  padding: .6rem;
  border-top: 1px solid var(--bot-border);
}
.sensaas-bot-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--bot-border);
  border-radius: .5rem;
  padding: .45rem .6rem;
  font: inherit;
  color: var(--bot-fg);
  background: var(--bot-bg);
  max-height: 7.5rem;
}
.sensaas-bot-input:focus { outline: 2px solid var(--bot-primary); outline-offset: -1px; }
.sensaas-bot-send {
  border: none;
  background: var(--bot-primary);
  color: #fff;
  width: 2.2rem; height: 2.2rem;
  border-radius: .5rem;
  cursor: pointer;
  flex: none;
}
.sensaas-bot-send:hover { filter: brightness(1.08); }

@media (max-width: 480px) {
  #sensaas-bot-root { right: .6rem; bottom: .6rem; }
  .sensaas-bot-panel { width: calc(100vw - 1.2rem); max-height: 78vh; }
}
@media (prefers-reduced-motion: reduce) {
  .sensaas-bot-toggle, .sensaas-bot-typing span { transition: none; animation: none; }
}
