/* ═══════════════════════════════════════════════════════════════
   chatbot.css — Styles du widget ChatPrepa
   ═══════════════════════════════════════════════════════════════
   Utilise les variables CSS du design system PrépInfo (main.css)
   Fallback inclus si les variables n'existent pas.
   ═══════════════════════════════════════════════════════════════ */

/* ── Variables locales (fallbacks) ───────────────────────────── */
:root {
  --chatbot-primary:    var(--blue-800, #1e40af);
  --chatbot-primary-h:  var(--blue-700, #1d4ed8);
  --chatbot-bg:         var(--gray-50, #f8fafc);
  --chatbot-surface:    #ffffff;
  --chatbot-text:       var(--gray-900, #0f172a);
  --chatbot-text-muted: var(--gray-500, #64748b);
  --chatbot-border:     var(--gray-200, #e2e8f0);
  --chatbot-radius:     var(--radius-lg, 12px);
  --chatbot-radius-sm:  var(--radius-md, 8px);
  --chatbot-shadow:     var(--shadow-xl, 0 20px 60px rgba(0,0,0,.15));
  --chatbot-bot-bg:     var(--gray-100, #f1f5f9);
  --chatbot-user-bg:    var(--blue-800, #1e40af);
  --chatbot-user-text:  #ffffff;
  --chatbot-width:      380px;
  --chatbot-height:     540px;
}

/* ── Bouton flottant ─────────────────────────────────────────── */
.chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--chatbot-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(30, 64, 175, .35);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.chatbot-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(30, 64, 175, .45);
  background: var(--chatbot-primary-h);
}
.chatbot-toggle:active {
  transform: scale(.95);
}
.chatbot-toggle__icon {
  width: 26px;
  height: 26px;
}
.chatbot-toggle__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Fenêtre de chat ─────────────────────────────────────────── */
.chatbot-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9999;
  width: var(--chatbot-width);
  height: var(--chatbot-height);
  background: var(--chatbot-surface);
  border-radius: var(--chatbot-radius);
  box-shadow: var(--chatbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chatbot-border);
  animation: chatbot-slideUp .25s ease-out;
}
@keyframes chatbot-slideUp {
  from { opacity: 0; transform: translateY(16px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ──────────────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--chatbot-primary);
  color: #fff;
  flex-shrink: 0;
}
.chatbot-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chatbot-header__name {
  font-weight: 700;
  font-size: 15px;
  display: block;
  line-height: 1.2;
}
.chatbot-header__status {
  font-size: 11px;
  opacity: .8;
  display: block;
}
.chatbot-header__actions {
  display: flex;
  gap: 4px;
}
.chatbot-header__btn {
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.chatbot-header__btn:hover {
  background: rgba(255,255,255,.25);
}

/* ── Zone de messages ────────────────────────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--chatbot-bg);
  scroll-behavior: smooth;
}
.chatbot-messages::-webkit-scrollbar {
  width: 5px;
}
.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-border);
  border-radius: 3px;
}

/* ── Messages ────────────────────────────────────────────────── */
.chatbot-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: chatbot-fadeIn .2s ease-out;
}
@keyframes chatbot-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chatbot-msg--bot {
  align-self: flex-start;
}
.chatbot-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chatbot-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chatbot-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.chatbot-msg__avatar--sm {
  width: 22px;
  height: 22px;
}
.chatbot-msg--user .chatbot-msg__avatar {
  background: var(--chatbot-text-muted);
}
.chatbot-msg__bubble {
  padding: 10px 14px;
  border-radius: var(--chatbot-radius-sm);
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.chatbot-msg--bot .chatbot-msg__bubble {
  background: var(--chatbot-surface);
  color: var(--chatbot-text);
  border: 1px solid var(--chatbot-border);
  border-top-left-radius: 2px;
}
.chatbot-msg--user .chatbot-msg__bubble {
  background: var(--chatbot-user-bg);
  color: var(--chatbot-user-text);
  border-top-right-radius: 2px;
}

/* Formatage Markdown dans les réponses du bot */
.chatbot-msg--bot .chatbot-msg__bubble code {
  background: var(--chatbot-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: 'Fira Code', 'Consolas', monospace;
}
.chatbot-msg--bot .chatbot-msg__bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.5;
}
.chatbot-msg--bot .chatbot-msg__bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.chatbot-msg--bot .chatbot-msg__bubble strong {
  font-weight: 600;
}
.chatbot-msg--bot .chatbot-msg__bubble ul,
.chatbot-msg--bot .chatbot-msg__bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}
.chatbot-msg--bot .chatbot-msg__bubble li {
  margin: 3px 0;
}

/* ── Indicateur de frappe ────────────────────────────────────── */
.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
  background: var(--chatbot-bg);
}
.chatbot-typing__dots {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--chatbot-surface);
  border-radius: var(--chatbot-radius-sm);
  border: 1px solid var(--chatbot-border);
}
.chatbot-typing__dots span {
  width: 7px;
  height: 7px;
  background: var(--chatbot-text-muted);
  border-radius: 50%;
  animation: chatbot-bounce .6s infinite alternate;
}
.chatbot-typing__dots span:nth-child(2) { animation-delay: .15s; }
.chatbot-typing__dots span:nth-child(3) { animation-delay: .3s; }
@keyframes chatbot-bounce {
  from { opacity: .3; transform: translateY(0); }
  to   { opacity: 1;  transform: translateY(-4px); }
}

/* ── Compteur restant ────────────────────────────────────────── */
.chatbot-remaining {
  text-align: center;
  font-size: 11px;
  color: var(--chatbot-text-muted);
  padding: 4px 16px;
  background: var(--chatbot-bg);
  border-top: 1px solid var(--chatbot-border);
  flex-shrink: 0;
}

/* ── Zone de saisie ──────────────────────────────────────────── */
.chatbot-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: var(--chatbot-surface);
  border-top: 1px solid var(--chatbot-border);
  flex-shrink: 0;
}
.chatbot-input {
  flex: 1;
  border: 1px solid var(--chatbot-border);
  border-radius: var(--chatbot-radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color .15s;
  background: var(--chatbot-bg);
  color: var(--chatbot-text);
}
.chatbot-input:focus {
  border-color: var(--chatbot-primary);
}
.chatbot-input::placeholder {
  color: var(--chatbot-text-muted);
}
.chatbot-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--chatbot-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, opacity .15s;
}
.chatbot-send:hover:not(:disabled) {
  background: var(--chatbot-primary-h);
}
.chatbot-send:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ── RESPONSIVE — Mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
  .chatbot-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .chatbot-toggle {
    bottom: 16px;
    right: 16px;
  }
}
/* ── Bouton verrouillé ── */
.chatbot-toggle--locked {
  background: var(--gray-400, #94a3b8);
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}
.chatbot-toggle--locked:hover {
  background: var(--gray-500, #64748b);
}

/* ── Modal upgrade ── */
.chatbot-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.chatbot-modal {
  background: var(--chatbot-surface, #fff);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: chatbot-slideUp .25s ease-out;
}
.chatbot-modal__icon {
  font-size: 40px;
  margin-bottom: 12px;
}
.chatbot-modal__title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--chatbot-text, #0f172a);
}
.chatbot-modal__text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--chatbot-text-muted, #64748b);
  margin: 0 0 24px;
}
.chatbot-modal__btn {
  display: block;
  background: var(--chatbot-primary, #1e40af);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 12px;
  transition: background .15s;
}
.chatbot-modal__btn:hover {
  background: var(--chatbot-primary-h, #1d4ed8);
}
.chatbot-modal__close {
  background: none;
  border: none;
  color: var(--chatbot-text-muted, #64748b);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}
.chatbot-modal__close:hover {
  color: var(--chatbot-text, #0f172a);
}
/* ── Fix positionnement sidebar ── */
.chatbot-toggle {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  left: auto !important;
  z-index: 99999 !important;
}
.chatbot-window {
  position: fixed !important;
  bottom: 96px !important;
  right: 24px !important;
  left: auto !important;
  z-index: 99999 !important;
}

/* ── Bulle de message animée ── */
.chatbot-bubble {
  position: fixed;
  bottom: 90px;
  right: 90px;
  background: #fff;
  border: 1px solid var(--chatbot-border, #e2e8f0);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px 10px 14px;
  font-size: 13.5px;
  color: var(--chatbot-text, #0f172a);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 9997;
  animation: bubble-in .4s cubic-bezier(.34,1.56,.64,1) forwards,
             bubble-float 3s ease-in-out 0.4s infinite;
  white-space: nowrap;
}
.chatbot-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 16px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1px solid var(--chatbot-border, #e2e8f0);
  border-bottom: 1px solid var(--chatbot-border, #e2e8f0);
  transform: rotate(45deg);
}
.chatbot-bubble__close {
  background: none;
  border: none;
  color: var(--chatbot-text-muted, #64748b);
  font-size: 16px;
  cursor: pointer;
  padding: 0 0 0 4px;
  line-height: 1;
}
.chatbot-bubble__close:hover { color: #0f172a; }
@keyframes bubble-in {
  from { opacity: 0; transform: scale(.7) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes bubble-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-5px); }
}
