/**
 * Chatbox con Inteligencia Artificial - Estilos Spatial Pure White V3
 * Fondo Blanco Puro (#FFFFFF) + Negro Puro (#09090B)
 * @version 3.0.0
 */

:root {
  --chat-primary: #09090b;
  --chat-primary-hover: #27272a;
  --chat-primary-gradient: #09090b;
  --chat-accent-ruby: #b21435;
  --chat-bg-glass: rgba(255, 255, 255, 0.96);
  --chat-card-glass: #f4f4f5;
  --chat-border-glass: rgba(9, 9, 11, 0.12);
  --chat-border-glow: #09090b;
  --chat-text-main: #09090b;
  --chat-text-muted: #52525b;
  --chat-bubble-user: #09090b;
  --chat-bubble-bot: #f4f4f5;
  --chat-shadow: 0 24px 60px rgba(9, 9, 11, 0.16), 0 4px 16px rgba(9, 9, 11, 0.06);
  --chat-radius-window: 22px;
  --chat-radius-bubble: 16px;
  --chat-font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --chat-z-index: 999999;
}

/* ==========================================================================
   BOTÓN FLOTANTE (FAB)
   ========================================================================== */
#chatbot-fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--chat-z-index);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-fab-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 12px 28px rgba(9, 9, 11, 0.28);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  user-select: none;
}

.chatbot-fab-btn:focus-visible,
.chatbot-send-btn:focus-visible,
.chatbot-icon-btn:focus-visible {
  outline: 3px solid var(--chat-primary);
  outline-offset: 3px;
}

.chatbot-fab-btn:hover {
  transform: scale(1.06) translateY(-2px);
  background: var(--chat-primary-hover);
  box-shadow: 0 16px 34px rgba(9, 9, 11, 0.36);
}

.chatbot-fab-btn:active {
  transform: scale(0.96);
}

.chatbot-fab-pulse {
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px solid rgba(9, 9, 11, 0.25);
  animation: fabPulse 2.8s infinite;
  pointer-events: none;
}

@keyframes fabPulse {
  0% { transform: scale(0.95); opacity: 0.7; }
  50% { transform: scale(1.16); opacity: 0; }
  100% { transform: scale(0.95); opacity: 0; }
}

.chatbot-fab-icon {
  width: 26px;
  height: 26px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
  position: absolute;
}

.chatbot-fab-icon-chat { opacity: 1; transform: rotate(0deg) scale(1); }
.chatbot-fab-icon-close { opacity: 0; transform: rotate(-90deg) scale(0.5); }

#chatbot-widget.chat-open .chatbot-fab-icon-chat { opacity: 0; transform: rotate(90deg) scale(0.5); }
#chatbot-widget.chat-open .chatbot-fab-icon-close { opacity: 1; transform: rotate(0deg) scale(1); }

.chatbot-fab-badge {
  position: absolute;
  top: 0px;
  right: 0px;
  width: 14px;
  height: 14px;
  background-color: #10b981;
  border: 2.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

/* ==========================================================================
   VENTANA EMERGENTE DEL CHAT (PURE WHITE SPATIAL)
   ========================================================================== */
#chatbot-window {
  position: fixed;
  bottom: 98px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 48px);
  height: 580px;
  max-height: calc(100vh - 130px);
  background: var(--chat-bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--chat-border-glass);
  border-radius: var(--chat-radius-window);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--chat-z-index);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--chat-font-family);
  color: var(--chat-text-main);
}

#chatbot-widget.chat-open #chatbot-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chatbot-header {
  padding: 16px 20px;
  background: #fafafa;
  border-bottom: 1px solid var(--chat-border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chatbot-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--chat-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 17px;
  position: relative;
  flex-shrink: 0;
}

.chatbot-status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 11px;
  height: 11px;
  background-color: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.chatbot-header-info {
  display: flex;
  flex-direction: column;
}

.chatbot-header-title {
  font-weight: 800;
  font-size: 14.5px;
  color: var(--chat-text-main);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}

.chatbot-header-subtitle {
  font-size: 11.5px;
  color: #047857;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-weight: 600;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chatbot-icon-btn {
  background: transparent;
  border: none;
  color: var(--chat-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.chatbot-icon-btn:hover {
  background: rgba(9, 9, 11, 0.08);
  color: var(--chat-text-main);
}

/* Aviso de Transparencia IA (EU AI Act Art. 50 / Ley 21.719) */
.chatbot-ai-notice {
  background: #f4f4f5;
  border-bottom: 1px solid rgba(9, 9, 11, 0.08);
  padding: 7px 14px;
  font-size: 11px;
  line-height: 1.4;
  color: #3f3f46;
  text-align: center;
}

.chatbot-ai-notice a {
  color: #b21435;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot-ai-notice a:hover,
.chatbot-ai-notice a:focus-visible {
  color: #09090b;
}

.chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background-color: #ffffff;
}

.chatbot-messages::-webkit-scrollbar { width: 5px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb { background: rgba(9, 9, 11, 0.14); border-radius: 10px; }
.chatbot-messages::-webkit-scrollbar-thumb:hover { background: rgba(9, 9, 11, 0.25); }

.chatbot-msg-row {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: msgFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chatbot-msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.chatbot-msg-row.bot { align-self: flex-start; }

.chatbot-msg-bubble {
  padding: 12px 15px;
  border-radius: var(--chat-radius-bubble);
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}

.chatbot-msg-row.user .chatbot-msg-bubble {
  background: var(--chat-bubble-user);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chatbot-msg-row.bot .chatbot-msg-bubble {
  background: var(--chat-bubble-bot);
  color: var(--chat-text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(9, 9, 11, 0.08);
}

.chatbot-msg-bubble p {
  margin: 0;
  color: inherit;
}

/* Opción 1: Lista Escaneable para respuestas ordenadas */
.chatbot-reply-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbot-reply-lead {
  font-weight: 600;
  color: #09090b;
}

.chatbot-reply-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-list-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: #27272a;
}

.chatbot-item-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 6px;
  margin-top: 2px;
  border-radius: 6px;
  color: #b21435;
  background: #fdf2f4;
  border: 1px solid rgba(178, 20, 53, 0.16);
}

.chatbot-reply-close {
  font-size: 12.5px;
  color: #52525b;
  padding-top: 7px;
  border-top: 1px solid rgba(9, 9, 11, 0.08);
}

/* Botones de acción interactiva al pie del mensaje */
.chatbot-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chat-action-btn {
  background: #ffffff;
  border: 1px solid rgba(9, 9, 11, 0.2);
  color: #09090b;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 99px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(9, 9, 11, 0.05);
}

.chat-action-btn:hover {
  background: #09090b;
  border-color: #09090b;
  color: #ffffff;
  transform: translateY(-1px);
}

.chat-action-btn:active { transform: scale(0.97); }

/* Typing indicator */
.chatbot-typing-row {
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--chat-bubble-bot);
  border: 1px solid rgba(9, 9, 11, 0.08);
  border-radius: var(--chat-radius-bubble);
  border-bottom-left-radius: 4px;
}

.chatbot-typing-dot {
  width: 6px;
  height: 6px;
  background: #52525b;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.chatbot-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chatbot-typing-dot:nth-child(2) { animation-delay: -0.16s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Input area */
.chatbot-input-container {
  padding: 14px 16px;
  background: #fafafa;
  border-top: 1px solid var(--chat-border-glass);
}

.chatbot-input-wrapper {
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 1px solid rgba(9, 9, 11, 0.16);
  border-radius: 28px;
  padding: 4px 6px 4px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-input-wrapper:focus-within {
  border-color: #09090b;
  box-shadow: 0 0 0 3px rgba(9, 9, 11, 0.08);
}

.chatbot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #09090b;
  font-size: 14px;
  font-family: inherit;
  padding: 8px 4px;
}

.chatbot-input::placeholder { color: #71717a; }

.chatbot-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #09090b;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .chatbot-icon-btn,
  .chatbot-send-btn,
  .chat-action-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

.chatbot-send-btn:hover:not(:disabled) {
  background: #27272a;
  transform: scale(1.05);
}

.chatbot-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chatbot-send-btn svg { width: 17px; height: 17px; transform: translateX(1px); }

.chatbot-footer-brand {
  text-align: center;
  font-size: 11px;
  color: #71717a;
  margin-top: 8px;
}

@keyframes chatTargetGlowPulse {
  0% { box-shadow: 0 0 0 0 rgba(9, 9, 11, 0.45); outline: 2px solid #09090b; }
  30% { box-shadow: 0 0 28px 8px rgba(9, 9, 11, 0.18); outline: 3px solid #09090b; }
  100% { box-shadow: 0 0 0 0 rgba(9, 9, 11, 0); outline: 2px solid transparent; }
}

.chat-target-highlight {
  animation: chatTargetGlowPulse 2.4s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
  transition: outline 0.3s ease;
  position: relative;
  z-index: 10;
}

@media (max-width: 600px) {
  #chatbot-fab-container { bottom: 18px; right: 18px; }
  .chatbot-fab-btn { width: 54px; height: 54px; }
  #chatbot-window {
    right: 0; left: 0; bottom: 0;
    width: 100vw; max-width: 100vw;
    height: 85vh; max-height: 85vh;
    border-radius: 24px 24px 0 0;
    border-bottom: none;
  }
  .chatbot-input { font-size: 16px; }
  .chatbot-messages { padding: 16px; }
}
