/* ========================================
   Chat FAB + Panel
   ======================================== */

/* Floating action button */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--track-accent, #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 1000;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.chat-fab:hover { transform: scale(1.08); }
.chat-fab.hidden { opacity: 0; pointer-events: none; transform: scale(0.8); }

/* Chat panel */
.chat-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: 480px;
  max-height: calc(100vh - 6rem);
  background: #0a0a0a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.75rem;
  display: flex;
  flex-direction: column;
  z-index: 1001;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.chat-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.chat-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text, #e2e8f0);
}
.chat-close {
  background: none;
  border: none;
  color: var(--color-text-muted, #94a3b8);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}
.chat-close:hover { color: var(--color-text, #e2e8f0); }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* Message bubbles */
.chat-msg {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.625rem;
  font-size: 0.8125rem;
  line-height: 1.6;
  word-wrap: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--track-accent, #8b5cf6);
  color: #fff;
  border-bottom-right-radius: 0.2rem;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.06);
  color: var(--color-text, #e2e8f0);
  border-bottom-left-radius: 0.2rem;
}
.chat-msg.error {
  align-self: center;
  background: rgba(239,68,68,0.15);
  color: #fca5a5;
  font-size: 0.75rem;
  text-align: center;
}

/* Typing indicator */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 0.5rem 0.75rem;
  align-self: flex-start;
}
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  animation: chatBounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Input form */
.chat-input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--color-text, #e2e8f0);
  outline: none;
  font-family: inherit;
}
.chat-input::placeholder { color: var(--color-text-dim, #64748b); }
.chat-input:focus { border-color: var(--track-accent, #8b5cf6); }
.chat-send {
  background: var(--track-accent, #8b5cf6);
  border: none;
  border-radius: 0.5rem;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}
.chat-send:hover { opacity: 0.85; }
.chat-send:disabled { opacity: 0.4; cursor: default; }

/* Mobile */
@media (max-width: 640px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 60vh;
    max-width: 100vw;
    border-radius: 0.75rem 0.75rem 0 0;
  }
  .chat-fab {
    bottom: 1rem;
    right: 1rem;
  }
}
