/* CSS de Diseño Premium para el Chatbot webapi-brain-chat */

:host {
  --chat-primary: #FE7211;          /* Naranja Corporativo */
  --chat-primary-rgb: 254, 114, 17;
  --chat-secondary: #4899DE;        /* Celeste Secundario */
  --chat-bg: rgba(42, 51, 64, 0.95); /* Fondo oscuro #2A3340 con transparencia */
  --chat-surface: rgba(30, 37, 48, 0.75); /* Burbuja bot y fondo secundario */
  --chat-border: rgba(255, 255, 255, 0.08);
  --chat-text: #f8fafc;
  --chat-text-muted: #94a3b8;
  --chat-font: 'Outfit', sans-serif;
  --chat-shadow-premium: 0 20px 50px -12px rgba(254, 114, 17, 0.25);
  
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 99999;
  font-family: var(--chat-font);
}

/* ==========================================================================
   Boton de Apertura / Launcher
   ========================================================================== */
.chat-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.4);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  outline: none;
}

.chat-launcher:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 12px 35px rgba(139, 92, 246, 0.6), 
              0 0 0 4px rgba(139, 92, 246, 0.2);
}

.chat-launcher svg {
  width: 28px;
  height: 28px;
  fill: #ffffff;
  transition: transform 0.3s ease;
}

.chat-launcher.open svg {
  transform: rotate(90deg);
}

/* Indicador de notificaciones / Alerta */
.chat-launcher-badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 14px;
  height: 14px;
  background-color: #ef4444;
  border-radius: 50%;
  border: 2px solid #ffffff;
  animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* ==========================================================================
   Contenedor Principal de Chat (Ventana)
   ========================================================================== */
.chat-window {
  position: absolute;
  bottom: 75px;
  right: 0;
  width: 400px;
  height: 600px;
  border-radius: 20px;
  background: var(--chat-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--chat-border);
  box-shadow: var(--chat-shadow-premium);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
}

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

/* ==========================================================================
   Adaptabilidad y Responsividad Premium
   ========================================================================== */

/* Prevenir desbordamientos en resoluciones de escritorio bajas o redimensionadas */
.chat-window {
  max-height: calc(100vh - 120px);
  max-width: calc(100vw - 50px);
}

/* Pantallas Medianas (Tablets y móviles grandes) */
@media (max-width: 768px) {
  .chat-window {
    width: 380px;
  }
}

/* Pantallas Pequeñas (Móviles - Modo Full Screen) */
@media (max-width: 576px) {
  :host {
    bottom: 15px;
    right: 15px;
  }

  /* Cuando el chat está abierto, expandir el anfitrión a pantalla completa */
  :host([open]) {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    z-index: 999999;
  }

  :host([open]) .chat-window {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100dvh !important; /* Adaptación dinámica para teclado móvil */
    bottom: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    border: none !important;
  }

  :host([open]) .chat-launcher {
    display: none !important;
  }

  /* Optimización de espacios en móviles */
  .chat-header {
    padding: 12px 16px;
  }

  .chat-body {
    padding: 16px;
    gap: 12px;
  }

  .chat-input-container {
    padding: 10px 16px;
  }
  
  .chat-message {
    max-width: 85%; /* Un poco más de espacio para burbujas en pantallas angostas */
  }
}

/* ==========================================================================
   Encabezado del Chat (Header)
   ========================================================================== */
.chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(79, 70, 229, 0.15));
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-header-avatar svg {
  width: 20px;
  height: 20px;
  fill: #ffffff;
}

.chat-header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--chat-text);
  letter-spacing: -0.01em;
  display: flex;
  flex-direction: column;
}

.chat-header-status {
  font-size: 11px;
  color: #10b981; /* Verde esmeralda */
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-header-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #10b981;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--chat-text-muted);
  transition: all 0.2s ease;
}

.chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--chat-text);
}

.chat-header-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ==========================================================================
   Cuerpo del Chat (Mensajes)
   ========================================================================== */
.chat-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Personalizar barra de scroll */
.chat-body::-webkit-scrollbar {
  width: 6px;
}
.chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Estilo de Mensaje Base */
.chat-message {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: message-in 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mensaje del Usuario */
.chat-message.user {
  align-self: flex-end;
}

.chat-message.user .message-bubble {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
  color: #ffffff;
  border-radius: 18px 18px 2px 18px;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mensaje del Asistente (Bot) */
.chat-message.bot {
  align-self: flex-start;
}

.chat-message.bot .message-bubble {
  background: var(--chat-surface);
  color: var(--chat-text);
  border-radius: 18px 18px 18px 2px;
  border: 1px solid var(--chat-border);
}

.message-bubble {
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-time {
  font-size: 10px;
  color: var(--chat-text-muted);
  margin-top: 4px;
  align-self: flex-end;
}

.chat-message.bot .message-time {
  align-self: flex-start;
}

/* Links dentro de burbujas */
.message-bubble a {
  color: #60a5fa; /* Azul claro */
  text-decoration: underline;
  font-weight: 600;
}
.message-bubble a:hover {
  color: #93c5fd;
}

/* ==========================================================================
   UI de Feedback (Me gusta / No me gusta)
   ========================================================================== */
.message-feedback {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
  position: absolute;
  right: -50px;
  bottom: 0;
}

.chat-message.bot:hover .message-feedback,
.chat-message.bot.has-feedback .message-feedback {
  opacity: 1;
}

/* Adaptación para pantallas táctiles (siempre visible feedback en móvil) */
@media (max-width: 768px) {
  .message-feedback {
    position: relative;
    right: 0;
    justify-content: flex-start;
    margin-left: 4px;
    opacity: 0.8;
  }
}

.feedback-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--chat-text-muted);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
}

.feedback-btn:hover {
  color: var(--chat-text);
  transform: scale(1.15);
}

.feedback-btn.active {
  color: #10b981; /* Verde */
}

.feedback-btn.dislike.active {
  color: #ef4444; /* Rojo */
}

.feedback-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ==========================================================================
   Tarjetas de Recomendación (Maketito / GolesIA / Servicios)
   ========================================================================== */
.recommendation-card {
  margin-top: 8px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(139, 92, 246, 0.3); /* Contorno brillante */
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 25px -5px rgba(139, 92, 246, 0.15);
  animation: card-in 0.4s cubic-bezier(0.19, 1, 0.22, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.rec-badge {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--chat-primary);
  background: rgba(139, 92, 246, 0.12);
  padding: 3px 8px;
  border-radius: 100px;
  align-self: flex-start;
}

.rec-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
}

.rec-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--chat-text-muted);
  line-height: 1.4;
}

.rec-button {
  margin-top: 4px;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.rec-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.35);
}

.rec-reason {
  font-size: 11px;
  font-style: italic;
  color: rgba(139, 92, 246, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 8px;
  margin-top: 4px;
}

/* ==========================================================================
   Burbuja de Escritura (Typing Indicator)
   ========================================================================== */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  background: var(--chat-surface);
  border-radius: 18px 18px 18px 2px;
  border: 1px solid var(--chat-border);
  align-self: flex-start;
  max-width: 60px;
}

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

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ==========================================================================
   Área de Entrada del Chat (Input)
   ========================================================================== */
.chat-input-container {
  padding: 14px 20px;
  background: rgba(15, 23, 42, 0.4);
  border-top: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--chat-text);
  font-family: var(--chat-font);
  font-size: 14.5px;
  outline: none;
  transition: all 0.2s ease;
  resize: none;
  max-height: 80px;
  min-height: 22px;
}

.chat-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}

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

.chat-send-btn {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-secondary));
  border: none;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(139, 92, 246, 0.4);
}

.chat-send-btn:active:not(:disabled) {
  transform: translateY(0);
}

.chat-send-btn:disabled {
  background: var(--chat-surface);
  color: var(--chat-text-muted);
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ==========================================================================
   Modal Elegante de Confirmación (Reiniciar Chat)
   ========================================================================== */
.chat-modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.chat-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.chat-modal-content {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  width: 85%;
  max-width: 320px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
  transform: scale(0.9) translateY(10px);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-modal-overlay.active .chat-modal-content {
  transform: scale(1) translateY(0);
}

.chat-modal-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 16px auto;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.chat-modal-icon svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.chat-modal-content h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  color: #ffffff;
  font-weight: 700;
}

.chat-modal-content p {
  margin: 0 0 20px 0;
  font-size: 13.5px;
  color: var(--chat-text-muted);
  line-height: 1.5;
}

.chat-modal-actions {
  display: flex;
  gap: 12px;
}

.chat-modal-btn {
  flex: 1;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-modal-btn.cancel {
  background: rgba(255, 255, 255, 0.08);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
}

.chat-modal-btn.cancel:hover {
  background: rgba(255, 255, 255, 0.12);
}

.chat-modal-btn.confirm {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.chat-modal-btn.confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(239, 68, 68, 0.35);
}
