/* ============================================================
   CHATBOT — Floating AI chat assistant
   Button mirrors .scroll-btn; panel mirrors .share-menu style.
   Web-only: hidden in print via @media print.
   ============================================================ */

/* ---- Floating open button ---- */
.chatbot-btn {
  position: fixed;
  right: 20px;
  bottom: 130px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--primary-glow);
  background: var(--bg-card);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.15s ease;
  box-shadow: 0 0 12px var(--primary-glow);
}

.chatbot-btn svg {
  width: 22px;
  height: 22px;
}

.chatbot-btn:hover {
  background: var(--bg-card-hover);
  box-shadow: 0 0 20px var(--primary-glow);
  border-color: var(--primary);
}

.chatbot-btn:active {
  transform: scale(0.92);
}

/* Hero TOC entry absorbs the scroll-to-top affordance — drop the chatbot
   down by one slot since .scroll-btn--top is no longer above it. */
.has-hero-toc .chatbot-btn {
  bottom: 76px;
}

/* ---- Panel ---- */
.chatbot-panel {
  position: fixed;
  right: 20px;
  bottom: 100px;
  width: 360px;
  height: 500px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--primary-glow);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    0 0 16px var(--primary-glow);
  z-index: 200;
  overflow: hidden;
  animation: chatbotSlideUp 0.2s ease;
}

.chatbot-panel[hidden] {
  display: none;
}

#chatbot-mode-chat[hidden],
#chatbot-mode-fallback[hidden] {
  display: none;
}

@keyframes chatbotSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Header ---- */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chatbot-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  font-family: var(--font-mono);
}

.chatbot-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.chatbot-close-btn svg {
  width: 14px;
  height: 14px;
}

.chatbot-close-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

/* ---- Chat mode ---- */
#chatbot-mode-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chatbot-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chatbot-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chatbot-msg--user {
  align-self: flex-end;
  background: rgba(0, 212, 255, 0.15);
  border: 1px solid rgba(0, 212, 255, 0.25);
  color: var(--text-primary);
}

.chatbot-msg--assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

/* Typing indicator */
.chatbot-msg--typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-width: 52px;
}

.chatbot-msg--typing span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatbotBounce 1.2s infinite;
}

.chatbot-msg--typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-msg--typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbotBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ---- Input row ---- */
.chatbot-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chatbot-input-row textarea {
  flex: 1;
  resize: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.82rem;
  padding: 6px 8px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
}

.chatbot-input-row textarea:focus {
  border-color: var(--primary-glow);
}

.chatbot-send-btn {
  background: var(--primary);
  color: var(--bg-dark);
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 10px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  align-self: flex-end;
  height: 36px;
  flex-shrink: 0;
}

.chatbot-send-btn:hover  { background: var(--secondary); }
.chatbot-send-btn:disabled { opacity: 0.45; cursor: default; }

.chatbot-disclaimer {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 10px 6px;
  flex-shrink: 0;
}

/* ---- Fallback form mode ---- */
#chatbot-mode-fallback {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbot-fallback-notice {
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 8px 10px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 6px;
  line-height: 1.5;
  flex-shrink: 0;
}

#chatbot-fallback-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chatbot-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatbot-form-group label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.chatbot-form-group input,
.chatbot-form-group textarea {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.8rem;
  padding: 6px 8px;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

.chatbot-form-group input:focus,
.chatbot-form-group textarea:focus {
  border-color: var(--primary-glow);
}

.chatbot-fallback-submit {
  background: var(--primary);
  color: var(--bg-dark);
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.chatbot-fallback-submit:hover    { background: var(--secondary); }
.chatbot-fallback-submit:disabled { opacity: 0.45; cursor: default; }

.chatbot-form-status {
  font-size: 0.78rem;
  text-align: center;
  padding: 4px 0;
  flex-shrink: 0;
}

.chatbot-form-status[hidden]    { display: none; }
.chatbot-form-status--success   { color: var(--secondary); }
.chatbot-form-status--error     { color: var(--error); }

/* ---- Print suppression ---- */
@media print {
  .chatbot-btn,
  .chatbot-panel {
    display: none !important;
  }
}

/* ---- Mobile near-fullscreen ---- */
@media (max-width: 600px) {
  .chatbot-btn {
    right: 14px;
    bottom: 120px;
    width: 48px;
    height: 48px;
  }

  .chatbot-btn svg {
    width: 20px;
    height: 20px;
  }

  /* TOC component (when loaded) hosts the scroll buttons inside its mobile
     panel, so the standalone .scroll-btn stack is hidden — the chatbot has
     no stack to clear and drops to the bottom-right. */
  .has-toc .chatbot-btn {
    bottom: 16px;
  }

  .chatbot-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 85vh;
    height: 85dvh;
    max-height: 100dvh;
    border-radius: 12px 12px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .chatbot-panel            { animation: none; }
  .chatbot-msg--typing span { animation: none; }
}
