/* =========================================================
   STANDALONE CHATBOT WIDGET — STYLES
   Self-contained: no other stylesheet or theme toggle required.
   ========================================================= */

:root {
  --cb-bg-1: #0f172a;      /* widget background, top of gradient */
  --cb-bg-2: #0b1120;      /* widget background, bottom of gradient */
  --cb-accent-1: #93c5fd;  /* bright accent text (titles, user bubble text) */
  --cb-accent-2: #3b82f6;  /* main accent (borders, buttons, glow) */
  --cb-ink: #e6ebf5;       /* body text inside the widget */
  --cb-muted: #8291ab;     /* secondary/placeholder text */
}

/* --- Demo page shell (delete this block if embedding in your own site) --- */
.demo-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: 'Jost', sans-serif;
  color: #111827;
  background: #ffffff;
  padding: 24px;
}
.demo-page h1 { font-family: 'Unbounded', sans-serif; font-size: 1.6rem; margin-bottom: 8px; }
.demo-page p { color: #6b7280; }

/* --- Widget root --- */
.chatbot-widget {
  position: fixed;
  bottom: 44px;
  right: 44px;
  z-index: 1000;
  font-family: 'Jost', sans-serif;
}

/* --- Collapsed State (Floating Trigger) --- */
.chatbot-collapsed {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(160deg, var(--cb-bg-1), var(--cb-bg-2) 70%);
  border: 1px solid rgba(59,130,246,.45);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5), inset 0 0 20px rgba(59,130,246,.18);
  cursor: pointer;
  transition: all .4s cubic-bezier(.4,0,.2,1);
  min-width: 220px;
  backdrop-filter: blur(8px);
}

.chatbot-collapsed:hover {
  border-color: var(--cb-accent-2);
  box-shadow: 0 8px 32px rgba(0,0,0,.5), inset 0 0 20px rgba(59,130,246,.1), 0 0 16px rgba(59,130,246,.15);
  transform: translateY(-2px);
}

.chatbot-collapsed__icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(59,130,246,.12);
  border: 1px solid rgba(59,130,246,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cb-accent-2);
  flex-shrink: 0;
  transition: all .3s ease;
}

.chatbot-collapsed:hover .chatbot-collapsed__icon {
  background: rgba(59,130,246,.22);
  border-color: var(--cb-accent-2);
  box-shadow: 0 0 10px rgba(59,130,246,.25);
}

.chatbot-collapsed__input {
  display: block;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cb-accent-1);
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  width: 100%;
  cursor: pointer;
  pointer-events: none;
  line-height: 1.35;
  white-space: normal;
}

/* --- Expanded Chat Window --- */
.chatbot-expanded {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 80px);
  background: linear-gradient(160deg, var(--cb-bg-1), var(--cb-bg-2) 70%);
  border: 1px solid rgba(59,130,246,.45);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0,0,0,.6), inset 0 0 30px rgba(59,130,246,.18);
  overflow: hidden;
  animation: chatbotExpand .4s cubic-bezier(.4,0,.2,1) forwards;
  backdrop-filter: blur(12px);
}

@keyframes chatbotExpand {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chatbot-widget.open .chatbot-collapsed { display: none; }
.chatbot-widget.open .chatbot-expanded   { display: flex; }

/* --- Header --- */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(59,130,246,.18);
  flex-shrink: 0;
  background: rgba(59,130,246,.04);
}

.chatbot-header__title {
  font-family: 'Unbounded', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--cb-accent-1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chatbot-header__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cb-accent-2);
  box-shadow: 0 0 8px rgba(59,130,246,.6);
  animation: pulseDot 2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .6; transform: scale(.85); }
}

.chatbot-header__close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(59,130,246,.3);
  color: var(--cb-accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding-bottom: 2px;
  transition: all .25s ease;
}

.chatbot-header__close:hover {
  background: rgba(59,130,246,.12);
  border-color: var(--cb-accent-2);
  color: var(--cb-accent-1);
}

/* --- Thinking Rotator: cycling fade words. JS moves this node to the
   end of .chatbot-messages right before a new reply starts, so it
   always renders directly above the bubble about to stream in. --- */
.thinking-rotator {
  display: none;
  align-items: center;
  justify-content: center;
  align-self: center;
  position: relative;
  width: 100%;
  height: 22px;
  flex-shrink: 0;
  pointer-events: none;
}

.thinking-rotator.is-visible {
  display: flex;
}

.thinking-word {
  position: absolute;
  opacity: 0;
  transition: opacity 0.6s ease-in-out;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cb-accent-2);
  text-shadow: 0 0 8px rgba(59,130,246,.3);
  font-family: 'Jost', sans-serif;
}

.thinking-word.active {
  opacity: 1;
}

/* --- Messages Area --- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(59,130,246,.25) transparent;
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background: rgba(59,130,246,.25); border-radius: 2px; }

/* --- Message Bubbles --- */
.chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: msgPop .35s cubic-bezier(.4,0,.2,1);
}

@keyframes msgPop {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(59,130,246,.22), rgba(59,130,246,.1));
  border: 1px solid rgba(59,130,246,.4);
  color: var(--cb-accent-1);
  border-bottom-right-radius: 4px;
}

.chat-msg--ai {
  align-self: flex-start;
  background: rgba(59,130,246,.06);
  border: 1px solid rgba(59,130,246,.2);
  color: var(--cb-ink);
  border-bottom-left-radius: 4px;
}

/* --- Typing Indicator --- */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(59,130,246,.06);
  border: 1px solid rgba(59,130,246,.2);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  animation: msgPop .3s ease;
}

.chat-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cb-accent-2);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* --- Input Area --- */
.chatbot-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(59,130,246,.12);
  flex-shrink: 0;
  background: rgba(59,130,246,.02);
}

.chatbot-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(59,130,246,.06);
  border: 1px solid rgba(59,130,246,.25);
  border-radius: 12px;
  padding: 8px 10px;
  transition: border-color .25s ease, box-shadow .25s ease;
}

.chatbot-input-wrap:focus-within {
  border-color: var(--cb-accent-2);
  box-shadow: 0 0 0 2px rgba(59,130,246,.12), inset 0 0 8px rgba(59,130,246,.06);
}

.chatbot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cb-ink);
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  line-height: 1.4;
  resize: none;
  max-height: 90px;
  min-height: 20px;
  padding: 4px 2px;
}

.chatbot-input::placeholder { color: var(--cb-muted); opacity: .7; }

.chatbot-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--cb-accent-2);
  border: none;
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .25s ease;
  padding: 0;
}

.chatbot-send:hover {
  background: #60a5fa;
  box-shadow: 0 0 12px rgba(59,130,246,.45);
  transform: scale(1.05);
}

.chatbot-send:active { transform: scale(.95); }

.chatbot-send svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ---- Send / Stop toggle state ---- */
.chatbot-send .icon-stop { display: none; }

.chatbot-send.is-stop {
  background: linear-gradient(135deg, #1e3a8a, #3b82f6 60%, #1e3a8a);
  box-shadow: 0 0 14px rgba(59,130,246,.55), 0 0 0 1px rgba(59,130,246,.4) inset;
  animation: stopPulse 1.6s ease-in-out infinite;
}

.chatbot-send.is-stop:hover {
  background: linear-gradient(135deg, #1d4ed8, #60a5fa 60%, #1d4ed8);
  transform: none;
}

.chatbot-send.is-stop .icon-send { display: none; }
.chatbot-send.is-stop .icon-stop { display: block; }

@keyframes stopPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(59,130,246,.4), 0 0 0 1px rgba(59,130,246,.35) inset; }
  50%      { box-shadow: 0 0 18px rgba(59,130,246,.7), 0 0 0 1px rgba(59,130,246,.55) inset; }
}

/* ---- Disabled input while AI is generating ---- */
.chatbot-input:disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Aborted AI message ---- */
.chat-msg--ai.is-aborted {
  opacity: .6;
  font-style: italic;
}

/* ---- Thinking toggle button ---- */
.thinking-toggle {
  display: none;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(59,130,246,.4);
  background: rgba(59,130,246,.06);
  color: var(--cb-accent-2);
  font-family: 'Jost', sans-serif;
  font-size: 10.5px;
  letter-spacing: .03em;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}

.thinking-toggle:hover {
  background: rgba(59,130,246,.12);
  border-color: rgba(59,130,246,.6);
}

.thinking-toggle.is-visible { display: inline-flex; }

.thinking-toggle .chevron {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 1.4px solid currentColor;
  border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg);
  transition: transform .2s ease;
}

.thinking-toggle.is-open .chevron { transform: rotate(-135deg); }

/* ---- Thinking reasoning panel ---- */
.bot-thinking {
  display: none;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-left: 2px solid var(--cb-accent-2);
  background: rgba(0,0,0,.22);
  color: var(--cb-muted);
  font-size: 11.5px;
  line-height: 1.55;
  font-style: italic;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.bot-thinking.is-open { display: block; }

.bot-thinking::-webkit-scrollbar { width: 4px; }
.bot-thinking::-webkit-scrollbar-track { background: transparent; }
.bot-thinking::-webkit-scrollbar-thumb { background: rgba(59,130,246,.25); border-radius: 2px; }
.bot-thinking::-webkit-scrollbar-thumb:hover { background: rgba(59,130,246,.45); }
.bot-thinking { scrollbar-width: thin; scrollbar-color: rgba(59,130,246,.25) transparent; }

.bot-content { white-space: pre-wrap; }

.chatbot-counter {
  text-align: right;
  font-size: 10px;
  letter-spacing: .05em;
  color: var(--cb-muted);
  margin-top: 6px;
  padding-right: 2px;
  transition: color .2s ease;
}

.chatbot-counter.at-limit { color: #f87171; }

/* Mobile adjustments */
@media(max-width:640px){
  .chatbot-widget { bottom: max(72px, calc(env(safe-area-inset-bottom) + 56px)); right: 24px; z-index: 1000; }
  .chatbot-collapsed { min-width: 140px; max-width: 170px; padding: 8px 10px; gap: 8px; }
  .chatbot-collapsed__input { font-size: 11px; line-height: 1.35; white-space: normal; }
  .chatbot-collapsed__icon { width: 28px; height: 28px; }
  .chatbot-collapsed__icon svg { width: 16px; height: 16px; }
  .chatbot-expanded { width: calc(100vw - 32px); height: 300px; max-height: min(48vh, calc(100vh - 140px)); border-radius: 14px; }
  .chatbot-header { padding: 10px 14px; }
  .chatbot-header__title { font-size: 12px; }
  .thinking-word { font-size: 10px; }
  .chatbot-messages { padding: 12px; gap: 10px; }
  .chat-msg { padding: 8px 12px; font-size: 12px; line-height: 1.5; max-width: 85%; }
  .chat-typing { padding: 10px 12px; }
  .chatbot-footer { padding: 10px 12px 12px; }
  .chatbot-input-wrap { padding: 6px 8px; }
}
