/**
 * AI CHAT WIDGET - Groq Powered
 * Modern floating chat with glassmorphism
 */

/* Chat Button - Floating */
.ai-chat-button {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: all 0.3s;
  animation: pulse-chat 2s infinite;
}

@keyframes pulse-chat {
  0%, 100% {
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 0 8px 40px rgba(102, 126, 234, 0.6);
  }
}

.ai-chat-button:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 40px rgba(102, 126, 234, 0.6);
}

/* Transición suave para ocultar */
.ai-chat-button {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-button svg {
  width: 28px;
  height: 28px;
  color: white;
}

/* Chat Widget Container - Estilo Burbuja */
.ai-chat-widget {
  position: fixed;
  bottom: 90px;
  right: 1.5rem;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: white;
  border-radius: 24px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15),
              0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 9998;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  cursor: move;
  user-select: none;
}

/* Móvil - Burbuja arrastrable */
@media (max-width: 768px) {
  .ai-chat-widget {
    width: 340px;
    max-width: calc(100vw - 2rem);
    height: 500px;
    max-height: 75vh;
    bottom: 90px;
    right: 1rem;
    border-radius: 24px !important;
  }
  
  .ai-chat-button {
    bottom: 1.5rem;
    right: 1.5rem;
  }
}

/* Pantallas muy pequeñas */
@media (max-width: 400px) {
  .ai-chat-widget {
    width: calc(100vw - 1.5rem);
    height: 480px;
    max-height: 70vh;
    border-radius: 24px !important;
  }
}

.ai-chat-widget.active {
  display: flex;
  transform: scale(1) translateY(0);
  opacity: 1;
  animation: bubbleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Animación de entrada (burbuja) */
@keyframes bubbleIn {
  0% {
    transform: scale(0.5) translateY(30px);
    opacity: 0;
  }
  50% {
    transform: scale(1.05) translateY(-5px);
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Animación de salida */
.ai-chat-widget.closing {
  animation: bubbleOut 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes bubbleOut {
  0% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  100% {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
}

/* Indicador de arrastre */
.ai-chat-widget.dragging {
  cursor: grabbing;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.2s;
}

/* Chat Header - Arrastrable */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1.25rem 1.5rem;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: grab;
  user-select: none;
}

.chat-header:active {
  cursor: grabbing;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.chat-header-text h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.chat-header-text p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.9;
}

.chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.3s;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Chat Messages Container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: #f7fafc;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 0.75rem;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: #e5e7eb;
}

.message-content {
  max-width: 75%;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.message.ai .message-bubble {
  background: white;
  color: #2d3748;
  border: 1px solid #e5e7eb;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.message-time {
  font-size: 0.7rem;
  color: #9ca3af;
  margin-top: 0.25rem;
  padding-left: 1rem;
}

.message.user .message-time {
  text-align: right;
  padding-left: 0;
  padding-right: 1rem;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0;
}

.typing-indicator .message-avatar {
  background: linear-gradient(135deg, #667eea, #764ba2);
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #667eea;
  animation: typingAnimation 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingAnimation {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-left: 2.5rem;
}

.quick-action-btn {
  padding: 0.5rem 0.75rem;
  background: rgba(102, 126, 234, 0.1);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 20px;
  font-size: 0.8rem;
  color: #667eea;
  cursor: pointer;
  transition: all 0.3s;
}

.quick-action-btn:hover {
  background: rgba(102, 126, 234, 0.2);
  border-color: #667eea;
}

/* Chat Input */
.chat-input-container {
  padding: 1rem 1.5rem;
  background: white;
  border-top: 1px solid #e5e7eb;
}

.chat-input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.3s;
}

.chat-input:focus {
  border-color: #667eea;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.chat-send-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.chat-send-btn svg {
  width: 20px;
  height: 20px;
}

/* Responsive */
@media (max-width: 768px) {
  .ai-chat-widget {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
  
  .ai-chat-button {
    bottom: 1rem;
    right: 1rem;
  }
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #764ba2, #667eea);
}

/* ============================================ */
/* PROACTIVE CHAT STYLES */
/* ============================================ */

/* Shake animation para llamar atención */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Quick action buttons */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.quick-action-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.quick-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.quick-action-btn:active {
  transform: translateY(0);
}

/* ============================================ */
/* OPTIMIZACIONES MÓVIL */
/* ============================================ */

@media (max-width: 768px) {
  /* IMPORTANTE: Ocultar botón cuando chat está activo */
  body:has(.ai-chat-widget.active) .ai-chat-button {
    display: none;
  }
  
  /* Input previene zoom en iOS */
  .chat-input {
    font-size: 16px !important;
  }
  
  /* Quick actions touch-friendly */
  .quick-action-btn {
    min-height: 48px;
  }
}

/* Pequeños móviles */
@media (max-width: 480px) {
  .chat-header {
    padding: 0.875rem;
  }
  
  .quick-action-btn {
    font-size: 0.875rem;
  }
}

/* ============================================ */
/* POPUP MÓVIL PROACTIVO */
/* ============================================ */

.mobile-chat-popup {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(100%);
}

.mobile-chat-popup.active {
  transform: translateY(0);
  pointer-events: all;
}

.mobile-popup-content {
  background: white;
  margin: 1rem;
  padding: 1.25rem 1.5rem 1.5rem;
  border-radius: 20px;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.2),
              0 0 0 1px rgba(0, 0, 0, 0.05);
  position: relative;
  text-align: center;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.mobile-popup-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.mobile-popup-close:hover {
  background: rgba(0, 0, 0, 0.1);
  transform: rotate(90deg);
}

.mobile-popup-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: bounce 2s ease-in-out infinite;
}

.mobile-popup-content h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  color: #333;
  font-weight: 700;
}

.mobile-popup-content p {
  margin: 0 0 1.25rem 0;
  color: #666;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.mobile-popup-btn {
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  transition: all 0.3s;
  min-height: 52px;
}

.mobile-popup-btn:active {
  transform: scale(0.98);
}

/* Solo mostrar en móvil */
@media (min-width: 769px) {
  .mobile-chat-popup {
    display: none;
  }
}
