/*
 * Assistant documentaire SenSaaS — styles du widget.
 * Utilise les variables Material (--md-*) pour suivre le thème clair/sombre.
 * Source unique : garder docs-doc/ et docs-kb/ synchronisés à l'identique.
 */

#sensaas-bot-root {
  --bot-primary: var(--md-primary-fg-color, #1976d2);
  --bot-bg: var(--md-default-bg-color, #fff);
  --bot-fg: var(--md-default-fg-color, #1a1a1a);
  --bot-muted: var(--md-default-fg-color--light, #666);
  --bot-border: var(--md-default-fg-color--lightest, rgba(0, 0, 0, .12));
  --bot-link: #2e7d32;
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 2000;
  font-size: .8rem;
}

/* Liens en vert (bien identifiables) — variante plus claire pour le mode sombre */
[data-md-color-scheme="slate"] #sensaas-bot-root { --bot-link: #81c784; }

/* 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: 0 4px 14px rgba(0, 0, 0, .28);
  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: 0 6px 18px rgba(0, 0, 0, .34); }
#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: 0 10px 40px rgba(0, 0, 0, .3);
  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: #ffe4e4; color: #b71c1c; }
.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; }
}
