/* ═══════════════════════════════════════════════════════════
   CHAT PANEL — Slide-out chat interface
   ═══════════════════════════════════════════════════════════ */

.chat-toggle {
  position: relative;
  cursor: pointer;
}
.chat-toggle .chat-badge {
  position: absolute;
  top: -4px; right: -4px;
  width: 18px; height: 18px;
  background: var(--accent-purple);
  border-radius: 50%;
  font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  border: 2px solid var(--bg-primary);
  animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ─── Panel ─── */
.chat-panel {
  position: fixed;
  top: 0; right: -440px;
  width: 420px;
  height: 100vh;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.chat-panel.open {
  right: 0;
}

.chat-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.chat-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Chat Header ─── */
.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--bg-secondary);
}
.chat-header-avatar {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-indigo));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.chat-header-info {
  flex: 1;
}
.chat-header-info h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.chat-header-info span {
  font-size: 0.72rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-header-info span::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--accent-green);
  border-radius: 50%;
}
.chat-close {
  width: 32px; height: 32px;
  border: none;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
  font-size: 1.1rem;
}
.chat-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

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

.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: msg-in 0.3s ease;
}

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

.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg.assistant {
  align-self: flex-start;
}

.chat-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;
}
.chat-msg.user .chat-msg-avatar {
  background: rgba(99, 102, 241, 0.2);
}
.chat-msg.assistant .chat-msg-avatar {
  background: linear-gradient(135deg, rgba(168,85,247,0.3), rgba(99,102,241,0.3));
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text-primary);
}
.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(168,85,247,0.2));
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-msg-bubble {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg-time {
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

/* ─── Typing Indicator ─── */
.chat-typing {
  display: none;
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  gap: 4px;
  align-items: center;
}
.chat-typing.visible {
  display: flex;
}
.chat-typing-dot {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Chat Input ─── */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-secondary);
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s ease;
}
.chat-input:focus {
  border-color: var(--accent-purple);
}
.chat-input::placeholder {
  color: var(--text-muted);
}
.chat-send {
  width: 40px; height: 40px;
  border: none;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-indigo));
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.chat-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(168, 85, 247, 0.4);
}
.chat-send:active {
  transform: scale(0.95);
}
.chat-send svg {
  width: 18px; height: 18px;
}
.chat-context-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 0;
  font-size: 0.68rem;
  color: var(--text-muted);
}
.chat-context-dot {
  width: 6px; height: 6px;
  background: var(--accent-green);
  border-radius: 50%;
}

/* ─── Welcome State ─── */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 30px;
  gap: 16px;
}
.chat-welcome-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, rgba(168,85,247,0.2), rgba(99,102,241,0.2));
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
}
.chat-welcome h3 {
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0;
}
.chat-welcome p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 280px;
}
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}
.chat-suggestion {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}
.chat-suggestion:hover {
  border-color: var(--accent-purple);
  color: var(--accent-purple);
  background: rgba(168,85,247,0.1);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .chat-panel {
    width: 100%;
    right: -100%;
  }
}
