/* ==========================================================================
   NEXUS — Public Catalog Chat Widget (Voice + TTS enabled)
   Reuses design tokens from tokens.css
   ========================================================================== */

.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 8000;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full, 50%);
  border: none;
  cursor: pointer;
  background: var(--color-accent, #F5A623);
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg, 0 4px 12px rgba(0,0,0,0.3));
  transition: transform 0.2s ease, background 0.2s ease;
}

.chat-fab:hover {
  transform: scale(1.08);
  background: var(--color-primary-hover, #e5952f);
}

.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 8001;
  width: 400px;
  height: 520px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-elevated, #1a1a1a);
  border: 1px solid var(--color-border, #333);
  border-radius: var(--radius-xl, 16px);
  box-shadow: var(--shadow-xl, 0 8px 32px rgba(0,0,0,0.4));
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

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

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--color-accent, #F5A623);
  color: #fff;
  flex-shrink: 0;
}

.chat-header h3 {
  font-family: var(--font-heading, sans-serif);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.chat-header-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.8;
}

.chat-header-close:hover { opacity: 1; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.45;
  word-wrap: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--color-accent, #F5A623);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.ai {
  align-self: flex-start;
  background: var(--color-surface-2, rgba(255,255,255,0.06));
  color: var(--color-text-primary, #fff);
  border-bottom-left-radius: 4px;
}

.chat-typing {
  align-self: flex-start;
  display: none;
  gap: 4px;
  padding: 8px 12px;
  background: var(--color-surface-2, rgba(255,255,255,0.06));
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.chat-typing.visible { display: flex; }

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted, #888);
  animation: chatBounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.chat-parts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.chat-part-card {
  background: var(--color-bg-elevated, #1a1a1a);
  border: 1px solid var(--color-border, #333);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chat-part-card:hover {
  border-color: var(--color-accent, #F5A623);
  background: var(--color-bg-base, #111);
}

.chat-part-card .part-number {
  font-family: var(--font-mono, monospace);
  font-size: 0.75rem;
  color: var(--color-accent, #F5A623);
  font-weight: 600;
}

.chat-part-card .part-name {
  font-size: 0.875rem;
  color: var(--color-text-primary, #fff);
  margin-top: 2px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--color-border, #333);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border, #333);
  border-radius: 8px;
  background: var(--color-bg-base, #111);
  color: var(--color-text-primary, #fff);
  font-size: 0.875rem;
  font-family: var(--font-body, sans-serif);
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 80px;
}

.chat-input:focus {
  border-color: var(--color-accent, #F5A623);
}

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

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: none;
  background: var(--color-accent, #F5A623);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.chat-send-btn:hover { background: var(--color-primary-hover, #e5952f); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Header Actions (TTS toggle + close) ─── */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-tts-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.9;
  transition: opacity 0.15s ease;
}

.chat-tts-toggle:hover { opacity: 1; }
.chat-tts-toggle.off { opacity: 0.4; }

/* ─── Mic Button (Voice Input) ─── */
.chat-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #333);
  background: var(--color-bg-base, #111);
  color: var(--color-text-secondary, #aaa);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chat-mic-btn:hover {
  border-color: var(--color-accent, #F5A623);
  color: var(--color-accent, #F5A623);
}

.chat-mic-btn.listening {
  background: #f85149;
  border-color: #f85149;
  color: #fff;
  animation: micPulse 1.4s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(248, 81, 73, 0); }
}

/* ─── TTS Button ─── */
.chat-tts-btn {
  background: none;
  border: none;
  color: #8b949e;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 4px;
  margin-left: 6px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}
.chat-tts-btn:hover { color: #58a6ff; background: rgba(88,166,255,0.1); }
.chat-tts-btn.tts-active { color: #58a6ff; }

/* ─── Voice Toast ─── */
.chat-voice-toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.chat-voice-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - 16px);
    right: 8px;
    height: 60vh;
  }
}
