/* ═══════════════════════════════════════════════════════
   RAG Chatbot Widget — chatbot.css
   Premium edition — Parcours MCE brand palette
   ═══════════════════════════════════════════════════════ */

:root {
  /* Brand: deep navy + warm gold on white */
  --rag-primary:    #1B3A6B;   /* Parcours MCE navy blue  */
  --rag-primary-dk: #122952;   /* darker navy on hover    */
  --rag-accent:     #C5973C;   /* warm gold accent        */
  --rag-bg:         #FFFFFF;
  --rag-surface:    #F7F8FA;
  --rag-border:     #DDE3EE;
  --rag-text:       #1A2333;
  --rag-muted:      #6B7A99;
  --rag-bot-bubble: #EEF1F8;
  --rag-user-bubble:#1B3A6B;
  --rag-radius:     18px;
  --rag-shadow:     0 8px 40px rgba(27,58,107,0.18), 0 2px 8px rgba(27,58,107,0.08);
  --rag-z:          999999;
}

/* ── Wrapper ─────────────────────────────── */
#rag-chat-wrapper {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--rag-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Toggle Button ───────────────────────── */
#rag-chat-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--rag-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(27,58,107,0.35), 0 1px 4px rgba(27,58,107,0.2);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}
#rag-chat-toggle:hover {
  background: var(--rag-primary-dk);
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(27,58,107,0.45);
}
#rag-chat-toggle svg {
  width: 24px;
  height: 24px;
}

/* ── Chat Box ────────────────────────────── */
#rag-chat-box {
  width: 380px;
  height: 540px;
  background: var(--rag-bg);
  border-radius: var(--rag-radius);
  box-shadow: var(--rag-shadow);
  border: 1.5px solid var(--rag-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
}
#rag-chat-box.open {
  display: flex;
}
#rag-chat-box.open.rag-animate {
  animation: ragSlideIn 0.28s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes ragSlideIn {
  from { opacity: 0; transform: scale(0.88) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

/* ── Socratic mode (amber) — course/lesson pages ─────────────────────────── */
#rag-chat-wrapper.rag-socratic {
  --rag-primary:    #B45309;   /* amber-700 */
  --rag-primary-dk: #92400E;   /* amber-800 */
}
#rag-chat-wrapper.rag-socratic #rag-chat-toggle {
  box-shadow: 0 4px 20px rgba(180,83,9,0.40);
}
#rag-chat-wrapper.rag-socratic #rag-chat-toggle:hover {
  box-shadow: 0 6px 28px rgba(180,83,9,0.50);
}
#rag-chat-wrapper.rag-socratic .rag-status-dot {
  background: #FCD34D;
  box-shadow: 0 0 6px #FCD34D;
}

/* ── Header ──────────────────────────────── */
#rag-chat-header {
  background: var(--rag-primary);
  color: #fff;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  /* Subtle top gradient for depth */
  background-image: linear-gradient(135deg, var(--rag-primary) 0%, var(--rag-primary-dk) 100%);
}
#rag-chat-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
/* Gold accent bar on title */
#rag-chat-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 18px;
  border-radius: 2px;
  background: var(--rag-accent);
  flex-shrink: 0;
}
.rag-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #86efac;
  box-shadow: 0 0 6px #86efac;
  animation: ragPulse 2s infinite;
}
@keyframes ragPulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
#rag-chat-clear {
  background: none;
  border: none;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  font-size: 16px;
  padding: 3px 7px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
#rag-chat-clear:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* ── Messages Area ───────────────────────── */
#rag-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--rag-surface);
}
#rag-chat-messages::-webkit-scrollbar { width: 4px; }
#rag-chat-messages::-webkit-scrollbar-thumb {
  background: var(--rag-border);
  border-radius: 4px;
}

/* ── Message Rows ────────────────────────── */
.rag-msg {
  display: flex;
  max-width: 86%;
  animation: ragMsgIn 0.22s ease;
}
@keyframes ragMsgIn {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.rag-msg.user  { margin-left: auto; flex-direction: row-reverse; }
.rag-msg.bot   { margin-right: auto; }

/* ── Bubbles ─────────────────────────────── */
.rag-bubble {
  padding: 11px 15px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  letter-spacing: 0.005em;
}
.rag-msg.bot  .rag-bubble {
  background: var(--rag-bot-bubble);
  color: var(--rag-text);
  border-bottom-left-radius: 4px;
  border: 1px solid #DDE3EE;
}
.rag-msg.user .rag-bubble {
  background: var(--rag-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.rag-bubble a {
  color: var(--rag-accent);
  text-decoration: underline;
  word-break: break-all;
}
.rag-msg.user .rag-bubble a {
  color: #fff;
  opacity: 0.9;
}

/* ── Typing indicator ────────────────────── */
.rag-typing .rag-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 13px 17px;
}
.rag-typing .rag-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--rag-muted);
  animation: ragBounce 1.2s infinite;
}
.rag-typing .rag-dot:nth-child(2) { animation-delay: 0.2s; }
.rag-typing .rag-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ragBounce {
  0%,80%,100% { transform: translateY(0); }
  40%         { transform: translateY(-6px); }
}

/* ── Input Area ──────────────────────────── */
#rag-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1.5px solid var(--rag-border);
  background: var(--rag-bg);
  flex-shrink: 0;
}
#rag-chat-input {
  flex: 1;
  border: 1.5px solid var(--rag-border);
  border-radius: 13px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  color: var(--rag-text);
  background: var(--rag-surface);
  transition: border-color 0.2s, background 0.2s;
  line-height: 1.5;
}
#rag-chat-input:focus {
  border-color: var(--rag-primary);
  background: #fff;
}
#rag-chat-input::placeholder { color: var(--rag-muted); }

#rag-chat-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--rag-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(27,58,107,0.25);
}
#rag-chat-send:hover {
  background: var(--rag-primary-dk);
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(27,58,107,0.35);
}
#rag-chat-send:disabled {
  background: var(--rag-border);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
#rag-chat-send svg { width: 18px; height: 18px; }

/* ── Mic wrapper + button ────────────────── */
#rag-mic-wrapper {
  position: relative;
  flex-shrink: 0;
}
#rag-chat-mic {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: none;
  border: 1.5px solid var(--rag-border);
  color: var(--rag-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
#rag-chat-mic:hover {
  background: var(--rag-surface);
  color: var(--rag-primary);
  border-color: var(--rag-primary);
}
#rag-chat-mic svg { width: 16px; height: 16px; }

/* Recording state — pulsing red */
#rag-chat-mic.rag-mic-recording {
  background: #FEE2E2;
  border-color: #EF4444;
  color: #EF4444;
  animation: ragMicPulse 1s ease-in-out infinite;
}
@keyframes ragMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* Hidden when browser has no speech support */
#rag-chat-mic.rag-mic-unsupported { display: none; }
#rag-chat-mic.rag-mic-unsupported ~ #rag-mic-menu { display: none; }

/* Language picker popup — horizontal pill row */
#rag-mic-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  transform: scale(0.9);
  transform-origin: bottom left;
  background: #fff;
  border: 1.5px solid var(--rag-border);
  border-radius: 50px;          /* fully rounded pill container */
  box-shadow: 0 6px 24px rgba(27,58,107,0.16);
  display: flex;
  flex-direction: row;          /* side-by-side */
  gap: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
  z-index: 10;
  padding: 3px;
}
#rag-mic-menu.rag-mic-menu-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
.rag-mic-lang-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  color: var(--rag-muted);
  cursor: pointer;
  border-radius: 50px;
  letter-spacing: 0.06em;
  transition: background 0.15s, color 0.15s;
}
.rag-mic-lang-btn:hover {
  background: var(--rag-surface);
  color: var(--rag-primary);
}
/* Active / selected language pill */
.rag-mic-lang-btn.rag-lang-active {
  background: var(--rag-primary);
  color: #fff;
}

/* ── Error bubble ────────────────────────── */
.rag-error .rag-bubble {
  background: #FEE2E2;
  color: #991B1B;
  border-color: #FECACA;
}

/* ── Proactive bubble ────────────────────── */
#rag-proactive {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 248px;
  background: #fff;
  border: 1.5px solid var(--rag-border);
  border-radius: 16px 16px 4px 16px;
  padding: 11px 13px 11px 15px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--rag-text);
  box-shadow: 0 6px 28px rgba(27,58,107,0.13);
  /* hidden by default */
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
#rag-proactive.rag-proactive-show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
#rag-proactive-text {
  flex: 1;
}
#rag-proactive-close {
  background: none;
  border: none;
  color: var(--rag-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin-top: -2px;
  flex-shrink: 0;
  transition: color 0.2s;
}
#rag-proactive-close:hover { color: var(--rag-text); }

/* Socratic (amber) tint on lesson pages */
#rag-chat-wrapper.rag-socratic #rag-proactive {
  border-color: #FCD34D;
  box-shadow: 0 6px 24px rgba(180,83,9,0.12);
}

/* ── Mobile responsive ───────────────────── */
@media (max-width: 480px) {
  #rag-chat-box  { width: calc(100vw - 32px); height: 70vh; }
  #rag-chat-wrapper { right: 16px; bottom: 16px; }
  #rag-proactive { max-width: calc(100vw - 96px); }
}
