/* ══════════════════════════════════════════════════════════════════════════
   ET-256: AI Chat Widget — Floating Panel
   Glassmorphism design matching AI MarketLens tokens.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Toggle Button (bottom-right) ─────────────────────────────────────── */
.ai-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-primary, linear-gradient(135deg, #00a8b8, #00d4aa));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 168, 184, 0.4);
  transition: all 0.3s ease;
}
.ai-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0, 168, 184, 0.5);
}
.ai-chat-toggle.active {
  background: var(--bg-tertiary, #161b22);
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  box-shadow: none;
}

/* ── Chat Panel ───────────────────────────────────────────────────────── */
.ai-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9989;
  width: 400px;
  height: 520px;
  background: var(--glass-bg, rgba(13, 17, 23, 0.92));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border, rgba(255,255,255,0.06));
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.ai-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-chat-header-icon {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: var(--gradient-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.ai-chat-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-heading, #fff);
  margin: 0;
}
.ai-chat-header small {
  font-size: 0.65rem;
  color: var(--text-secondary, #8b949e);
}
.ai-chat-close {
  background: none; border: none;
  color: var(--text-secondary); cursor: pointer;
  font-size: 1.1rem; padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
}
.ai-chat-close:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

/* ── Messages Area ────────────────────────────────────────────────────── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1); border-radius: 4px;
}

/* ── Message Bubbles ──────────────────────────────────────────────────── */
.ai-msg {
  display: flex;
  gap: 10px;
  animation: fadeInUp 0.3s ease;
}
.ai-msg.user { flex-direction: row-reverse; }

.ai-msg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.ai-msg.bot .ai-msg-avatar {
  background: rgba(0, 168, 184, 0.15);
}
.ai-msg.user .ai-msg-avatar {
  background: rgba(99, 102, 241, 0.15);
}

.ai-msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-primary, #e6edf3);
  word-wrap: break-word;
}
.ai-msg.bot .ai-msg-bubble {
  background: var(--bg-tertiary, #161b22);
  border: 1px solid var(--border-color, rgba(255,255,255,0.06));
  border-top-left-radius: 4px;
}
.ai-msg.user .ai-msg-bubble {
  background: rgba(0, 168, 184, 0.12);
  border: 1px solid rgba(0, 168, 184, 0.2);
  border-top-right-radius: 4px;
}

/* Bold and bullet points inside messages */
.ai-msg-bubble strong { color: var(--accent-primary, #00a8b8); }
.ai-msg-bubble ul { margin: 6px 0 0 16px; padding: 0; }
.ai-msg-bubble li { margin-bottom: 3px; }

/* ── Typing Indicator ─────────────────────────────────────────────────── */
.ai-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
}
.ai-typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-secondary, #8b949e);
  animation: typingBounce 1.2s infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Suggested Prompts ────────────────────────────────────────────────── */
.ai-chat-suggestions {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ai-suggest-btn {
  padding: 5px 12px;
  background: rgba(0, 168, 184, 0.08);
  border: 1px solid rgba(0, 168, 184, 0.15);
  border-radius: 20px;
  color: var(--accent-primary, #00a8b8);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.ai-suggest-btn:hover {
  background: rgba(0, 168, 184, 0.18);
  border-color: rgba(0, 168, 184, 0.3);
}

/* ── Input Area ───────────────────────────────────────────────────────── */
.ai-chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color, rgba(255,255,255,0.08));
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.ai-chat-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-tertiary, #161b22);
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 10px;
  color: var(--text-primary, #e6edf3);
  font-size: 0.82rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}
.ai-chat-input:focus {
  border-color: var(--accent-primary, #00a8b8);
}
.ai-chat-input::placeholder {
  color: var(--text-secondary, #8b949e);
}
.ai-chat-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--gradient-primary);
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.ai-chat-send:hover { transform: scale(1.06); }
.ai-chat-send:disabled {
  opacity: 0.4; cursor: not-allowed; transform: none;
}

/* ── Rate limit badge ─────────────────────────────────────────────────── */
.ai-rate-badge {
  font-size: 0.6rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 2px 0;
}

/* ── Mobile Responsive ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .ai-chat-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 140px);
    right: 8px;
    bottom: 84px;
    border-radius: 12px;
  }
  .ai-chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }
}

/* ── Fade-in Animation ────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
