/* ==========================================================================
   NEXUS POS — AI Chat Widget
   Uses design system tokens from tokens.css
   ========================================================================== */

/* ─── Floating Button ─── */

.chat-fab {
  position: fixed;
  bottom: 140px;           /* above cart FAB and F-keys footer */
  right: var(--space-5);
  z-index: 8000;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  background: var(--color-accent);
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-fast) var(--ease-in-out),
              background var(--duration-fast) var(--ease-in-out);
}

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

.chat-fab.has-unread::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-error);
}

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

.chat-panel {
  position: fixed;
  bottom: 200px;
  right: var(--space-5);
  z-index: 8001;
  width: 400px;
  height: 520px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--duration-normal) var(--ease-in-out),
              opacity var(--duration-normal) var(--ease-in-out);
}

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

/* ─── Header ─── */

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

.chat-header h3 {
  font-family: var(--font-heading);
  font-size: var(--text-body);
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

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

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

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chat-tts-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
  opacity: 0.9;
  transition: opacity var(--duration-fast) var(--ease-in-out);
}

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

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ─── Message Bubbles ─── */

.chat-msg {
  max-width: 85%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm, 0.875rem);
  line-height: 1.45;
  word-wrap: break-word;
}

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

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

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

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

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

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted);
  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); }
}

/* ─── Part Result Cards ─── */

.chat-parts {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.chat-part-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-in-out),
              background var(--duration-fast) var(--ease-in-out);
}

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

.chat-part-card .part-number {
  font-family: var(--font-mono);
  font-size: var(--text-caption, 0.75rem);
  color: var(--color-accent);
  font-weight: var(--font-weight-semibold);
}

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

.chat-part-card .part-stock {
  font-size: var(--text-caption, 0.75rem);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.chat-part-card .part-stock.in-stock {
  color: var(--color-success);
}

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

.chat-input-area {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-base);
  color: var(--color-text-primary);
  font-size: var(--text-body-sm, 0.875rem);
  font-family: var(--font-body);
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 80px;
}

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

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

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

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

/* ─── Camera Button (Photo identification) ─── */

.chat-cam-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-base);
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-in-out),
              color var(--duration-fast) var(--ease-in-out),
              border-color var(--duration-fast) var(--ease-in-out);
}

.chat-cam-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.chat-msg-image img {
  border: 1px solid var(--color-border);
}

/* ─── Mic Button (Voice Input) ─── */

.chat-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-bg-base);
  color: var(--color-text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-in-out),
              color var(--duration-fast) var(--ease-in-out),
              border-color var(--duration-fast) var(--ease-in-out);
}

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

.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); }
}

/* ─── 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: var(--radius-md, 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);
}

/* ─── Vehicle Info Banner ─── */

.chat-vehicle-banner {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-base);
  border: 1px solid var(--color-accent);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  font-size: var(--text-caption, 0.75rem);
  color: var(--color-text-secondary);
}

.chat-vehicle-banner strong {
  color: var(--color-text-primary);
}

/* ─── Responsive ─── */

@media (max-width: 480px) {
  .chat-panel {
    width: calc(100vw - var(--space-4));
    right: var(--space-2);
    height: 60vh;
  }
}
