/* =========================================================
   AI CHATBOT
   Floating vanilla JS chatbot widget.
   ========================================================= */
.ai-chatbot-toggle {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  background: var(--accent);
  box-shadow: 0 14px 34px var(--accent-dim), 0 0 0 1px var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chatbot-toggle:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 18px 42px var(--accent-dim), 0 0 0 1px var(--accent);
}

.ai-chatbot-toggle svg {
  width: 25px;
  height: 25px;
}

.ai-chatbot-welcome {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 119;
  width: min(260px, calc(100vw - 28px));
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  background: var(--bg-card-hover);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.24), 0 0 0 1px var(--accent-dim);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1.35;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.24s ease, transform 0.24s ease, border-color 0.2s ease;
}

.ai-chatbot-welcome.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.ai-chatbot-welcome.show:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.ai-chatbot-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 121;
  width: min(380px, calc(100vw - 28px));
  height: min(560px, calc(100vh - 118px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(17, 17, 17, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32), var(--shadow-card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

[data-theme="light"] .ai-chatbot-panel {
  background: rgba(255, 255, 255, 0.96);
}

.ai-chatbot-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ai-chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 200, 150, 0.015);
}

.ai-chatbot-title-wrap {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.ai-chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  opacity: 0.7;
}

.ai-chatbot-title {
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.ai-chatbot-status {
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.2;
}

.ai-chatbot-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--bg-card-hover);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ai-chatbot-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.ai-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(0, 200, 150, 0.015);
}
.ai-chatbot-empty {
  margin: auto;
  max-width: 250px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.ai-chatbot-empty strong {
  display: block;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 6px;
}

.ai-chatbot-message {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-chatbot-message.user {
  align-self: flex-end;
  color: var(--bg);
  background: var(--accent);
  border-bottom-right-radius: 3px;
}

.ai-chatbot-message.assistant {
  align-self: flex-start;
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.ai-chatbot-message.assistant a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
  transition: opacity 0.2s ease;
}

.ai-chatbot-message.assistant a:hover {
  opacity: 0.8;
}

.ai-chatbot-message.error {
  color: #ffb4b4;
  border-color: rgba(255, 90, 90, 0.35);
}

.ai-chatbot-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  border-bottom-left-radius: 3px;
  background: var(--bg-card-hover);
}

.ai-chatbot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: ai-chatbot-bounce 0.9s infinite ease-in-out;
}

.ai-chatbot-typing span:nth-child(2) {
  animation-delay: 0.12s;
}

.ai-chatbot-typing span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes ai-chatbot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.ai-chatbot-form {
  padding: 13px;
  border-top: 1px solid var(--border);
  background: rgba(0, 200, 150, 0.015);
}

.ai-chatbot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-chatbot-input {
  flex: 1;
  min-width: 0;
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--input-bg);
  padding: 11px 12px;
  font: inherit;
  font-size: 0.88rem;
  outline: none;
}

.ai-chatbot-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.ai-chatbot-counter {
  flex: 0 0 48px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  line-height: 1;
  text-align: right;
  white-space: nowrap;
}

.ai-chatbot-counter.limit {
  color: var(--accent);
}

.ai-chatbot-icon-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-card);
}

.ai-chatbot-icon-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.ai-chatbot-send {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
  opacity: 0.7;
}

.ai-chatbot-send:hover {
  opacity: 1;
}

.ai-chatbot-icon-btn:disabled,
.ai-chatbot-input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ai-chatbot-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.ai-chatbot-tool {
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  padding: 7px 9px;
  font-size: 0.74rem;
  font-family: 'JetBrains Mono', monospace;
}

.ai-chatbot-tool:hover,
.ai-chatbot-tool.active {
  color: var(--accent);
  border-color: var(--accent);
}

.ai-chatbot-note {
  color: var(--text-muted);
  font-size: 0.72rem;
}

/* Mic Recording Animation */
@keyframes mic-pulse {
  0%, 100% {
    color: var(--accent);
    filter: drop-shadow(0 0 0 rgba(0, 255, 153, 0));
  }
  50% {
    color: #ff4444;
    filter: drop-shadow(0 0 6px rgba(255, 68, 68, 0.6));
  }
}

.ai-chatbot-mic.active {
  animation: mic-pulse 1.2s ease-in-out infinite;
}

@media (max-width: 560px) {
  .ai-chatbot-toggle {
    right: 16px;
    bottom: 16px;
  }

  .ai-chatbot-welcome {
    right: 16px;
    bottom: 84px;
    width: min(240px, calc(100vw - 32px));
  }

  .ai-chatbot-panel {
    right: 14px;
    bottom: 84px;
    height: min(560px, calc(100vh - 102px));
  }
}

/* ── Header actions wrap ── */
.ai-chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Voice toggle in header ── */
.ai-chatbot-voice-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255, 80, 80, 0.1);
  color: rgba(255, 80, 80, 0.85);
}
.ai-chatbot-voice-toggle.active {
  border: none;
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Empty state overrides ── */
.ai-chatbot-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem 1rem;
  gap: 4px;
  max-width: 100%;
}

.ai-chatbot-empty-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.ai-chatbot-empty-greeting {
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  margin: 0;
}

.ai-chatbot-empty-sub {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin: 0 0 14px;
  text-align: center;
}

/* ── Quick question buttons ── */
.ai-chatbot-quick-questions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.ai-chatbot-qq-btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  opacity: 0.7;
  transition: border-color 0.2s, color 0.2s, background 0.2s, opacity 0.2s;
}

.ai-chatbot-qq-btn:hover {
  opacity: 1;
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}