/* ============================================
   AI CHATBOT WIDGET — Micro Frontend
   Scoped under .ai-chat-* (zero conflict)
   Design system: dark, purple, glass morphism
   ============================================ */

/* ── Toggle Button ─────────────────────────── */

.ai-chat-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-brand-500, #7c3aed);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 32px rgba(124, 58, 237, 0.55),
    0 4px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow:
    0 0 48px rgba(124, 58, 237, 0.75),
    0 4px 20px rgba(0, 0, 0, 0.4);
}

.ai-chat-toggle:active { transform: scale(0.95); }

.ai-chat-toggle svg {
  width: 22px;
  height: 22px;
  color: #ffffff;
}

.ai-chat-toggle .icon-chat  { display: block; }
.ai-chat-toggle .icon-close { display: none; }
.ai-chat-toggle.is-open .icon-chat  { display: none; }
.ai-chat-toggle.is-open .icon-close { display: block; }

/* Pulse ring */
.ai-chat-toggle::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(124, 58, 237, 0.45);
  animation: ai-chat-pulse 2.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ai-chat-pulse {
  0%,  100% { transform: scale(1);    opacity: 0.65; }
  50%       { transform: scale(1.18); opacity: 0; }
}

/* Online badge */
.ai-chat-badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 14px;
  height: 14px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid var(--color-bg-primary, #050508);
  pointer-events: none;
}

/* ── Chat Panel ─────────────────────────────── */

.ai-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  z-index: 8999;
  width: 380px;
  height: 540px;
  max-height: calc(100dvh - 116px);
  display: flex;
  flex-direction: column;
  background: rgba(8, 8, 20, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 20px;
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  box-shadow:
    0 0 0 1px rgba(124, 58, 237, 0.12),
    0 28px 80px rgba(0, 0, 0, 0.65),
    0 0 60px rgba(124, 58, 237, 0.08);
  overflow: hidden;
  /* Collapsed state */
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.32s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.22s ease;
}

.ai-chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ─────────────────────────────────── */

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(124, 58, 237, 0.07);
  flex-shrink: 0;
}

.ai-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed 0%, #4c1d95 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: 0 0 16px rgba(124, 58, 237, 0.4);
}

.ai-chat-header-info { flex: 1; min-width: 0; }

.ai-chat-header-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-primary, #f0f0ff);
  line-height: 1.3;
}

.ai-chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--color-text-secondary, #a0a0b8);
  margin-top: 1px;
}

.ai-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.ai-chat-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary, #a0a0b8);
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-primary, #f0f0ff);
}

.ai-chat-close svg { width: 15px; height: 15px; }

/* ── Messages ───────────────────────────────── */

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.ai-chat-messages::-webkit-scrollbar { width: 3px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(124, 58, 237, 0.25);
  border-radius: 2px;
}

/* ── Message Row ────────────────────────────── */

.ai-chat-msg {
  display: flex;
  flex-direction: column;
  gap: 5px;
  animation: ai-msg-in 0.28s ease;
}

@keyframes ai-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-chat-msg--user { align-items: flex-end; }
.ai-chat-msg--bot  { align-items: flex-start; }

/* ── Bubble ─────────────────────────────────── */

.ai-chat-bubble {
  max-width: 86%;
  padding: 10px 14px;
  font-size: 0.875rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-msg--user .ai-chat-bubble {
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
}

.ai-chat-msg--bot .ai-chat-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--color-text-primary, #f0f0ff);
  border-radius: 4px 16px 16px 16px;
}

.ai-chat-msg--bot .ai-chat-bubble.is-error {
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* ── Source Tags ────────────────────────────── */

.ai-chat-sources {
  max-width: 86%;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ai-chat-source-tag {
  font-size: 0.68rem;
  color: #a78bfa;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.22);
  border-radius: 100px;
  padding: 2px 9px;
  letter-spacing: 0.01em;
}

/* ── Typing Indicator ───────────────────────── */

.ai-chat-typing {
  display: flex;
  align-items: flex-start;
  animation: ai-msg-in 0.2s ease;
}

.ai-chat-typing-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.ai-chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-brand-400, #8b5cf6);
  animation: ai-typing-bounce 1.4s ease-in-out infinite;
}

.ai-chat-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes ai-typing-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.35; }
  40%           { transform: translateY(-7px); opacity: 1; }
}

/* ── Input Area ─────────────────────────────── */

.ai-chat-footer {
  padding: 10px 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.ai-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input-row:focus-within {
  border-color: rgba(124, 58, 237, 0.45);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.07);
}

.ai-chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--color-text-primary, #f0f0ff);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  line-height: 1.55;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  overflow-y: auto;
}

.ai-chat-input::placeholder { color: var(--color-text-muted, #5a5a78); }

.ai-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--color-brand-500, #7c3aed);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}

.ai-chat-send:hover:not(:disabled) { background: var(--color-brand-400, #8b5cf6); }
.ai-chat-send:active:not(:disabled) { transform: scale(0.93); }

.ai-chat-send:disabled {
  background: rgba(255, 255, 255, 0.08);
  cursor: not-allowed;
}

.ai-chat-send svg { width: 17px; height: 17px; color: #ffffff; }

.ai-chat-powered {
  text-align: center;
  font-size: 0.63rem;
  color: rgba(90, 90, 120, 0.7);
  margin-top: 8px;
  letter-spacing: 0.03em;
}

/* ── Mobile ─────────────────────────────────── */

@media (max-width: 440px) {
  .ai-chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 84px;
    border-radius: 18px;
  }

  .ai-chat-toggle {
    right: 16px;
    bottom: 18px;
  }
}

/* ── Reduced motion ─────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .ai-chat-toggle::after,
  .ai-chat-typing-dot { animation: none; }

  .ai-chat-panel,
  .ai-chat-msg { transition: none; animation: none; }
}