/**
 * Turismo MT - Chat Widget Component
 * FAB button and expanded widget
 * Based on Stitch CHAT-002 IA Visitante Desktop
 * Version: 2.0 - Sprint 5
 */

/* Chat Tokens from Stitch CHAT-002 */
:root {
    --chat-widget-bg: #283028;
    --chat-header-bg: #1e241e;
    --chat-bubble-ai: #353f35;
    --chat-bubble-user: #76b63e;
    --chat-input-bg: #1d241d;
    --chat-border: #3d4a3d;
    --chat-link: #58a6ff;
    --chat-online: #4ade80;
}

/* ==========================================
   CHAT FAB (Floating Action Button)
   ========================================== */

.chat-fab {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-fixed);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-full);
  color: var(--color-bg-primary);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(118, 182, 62, 0.3);
  transition: all var(--transition-base);
}

.chat-fab:hover {
  background: var(--color-primary-hover);
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(118, 182, 62, 0.4);
}

.chat-fab .material-symbols-outlined {
  font-size: 28px;
}

/* Pulse animation for attention */
.chat-fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  opacity: 0;
  animation: chat-pulse 2s ease-out infinite;
}

@keyframes chat-pulse {
  0% {
    opacity: 0.4;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

/* ==========================================
   CHAT WIDGET (Expanded)
   ========================================== */

.chat-widget {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-modal);
  width: 380px;
  max-height: 600px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-slow);
}

.chat-widget.open,
.chat-widget.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* FAB open state */
.chat-fab.is-open .icon-open { display: none; }
.chat-fab.is-open .icon-close { display: block; }
.chat-fab:not(.is-open) .icon-close { display: none; }

/* ==========================================
   CHAT HEADER
   ========================================== */

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-bg-tertiary);
  border-bottom: 1px solid var(--color-border);
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-bg-primary);
}

.chat-avatar .material-symbols-outlined {
  font-size: 24px;
}

.chat-info {
  flex: 1;
}

.chat-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text-primary);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

.chat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-primary);
}

/* ==========================================
   CHAT MESSAGES
   ========================================== */

.chat-messages {
  flex: 1;
  padding: var(--space-4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 300px;
  max-height: 400px;
}

/* Message bubbles */
.chat-message {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.chat-message-bot {
  align-self: flex-start;
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-message-user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-bg-primary);
  border-bottom-right-radius: var(--radius-sm);
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-lg);
  width: fit-content;
}

.chat-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-text-muted);
  animation: typing 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ==========================================
   CHAT INPUT
   ========================================== */

.chat-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--color-bg-tertiary);
  border-top: 1px solid var(--color-border);
}

.chat-input input {
  flex: 1;
  height: 40px;
  padding: 0 var(--space-4);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition-base);
}

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

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

.chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-lg);
  color: var(--color-bg-primary);
  cursor: pointer;
  transition: all var(--transition-base);
}

.chat-send:hover {
  background: var(--color-primary-hover);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================
   CHAT USAGE COUNTER (Visitors)
   ========================================== */

.chat-usage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.chat-usage a {
  color: var(--chat-link);
  text-decoration: none;
}

.chat-usage a:hover {
  text-decoration: underline;
}

/* ==========================================
   CHAT DISCLAIMER
   ========================================== */

.chat-disclaimer {
  text-align: center;
  font-size: 10px;
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-4);
  margin: 0;
}

/* ==========================================
   CHAT SOURCES (Expandable)
   ========================================== */

.chat-sources {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--chat-border);
}

.chat-sources summary {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
}

.chat-sources a {
  display: block;
  font-size: var(--text-xs);
  color: var(--chat-link);
  margin-top: var(--space-1);
}

/* ==========================================
   CHAT MESSAGE VARIANTS
   ========================================== */

.chat-message.is-ai {
  align-self: flex-start;
}

.chat-message.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.is-ai .chat-bubble {
  background: var(--chat-bubble-ai);
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-message.is-user .chat-bubble {
  background: var(--chat-bubble-user);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

/* Online indicator animation */
.chat-online-dot {
  width: 10px;
  height: 10px;
  background: var(--chat-online);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Date divider */
.chat-date-divider {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-2) 0;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 767px) {
  .chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  }

  .chat-messages {
    max-height: calc(100vh - 200px);
  }

  .chat-fab {
    bottom: var(--space-4);
    right: var(--space-4);
  }
}
