/* ===========================
   Chatbot AI - DISEÑO MODERNO
   Versión 2.2.3 - Interfaz de mensajería moderna
   =========================== */

#chat-flowi-widget {
  /* Colores principales: derivan del color elegido en el admin (inyectado en chat-widget.php como --chat-primary/--chat-secondary). */
  --primary-blue: var(--chat-primary, #4A90E2);
  --primary-blue-light: var(--chat-secondary, #6B9FE8);
  --bubble-bot: #C8E0F4;
  --bubble-user: #A8E6CF;
  --background: #F5F6F8;
  --text-primary: #2C3E50;
  --text-secondary: #7F8C8D;
  --border-color: #E1E8ED;
  --white: #FFFFFF;
  --online-green: #48BB78;

  /* Sombras */
  --shadow-soft: 0 4px 20px rgba(74, 144, 226, 0.15);
  --shadow-medium: 0 8px 30px rgba(74, 144, 226, 0.2);

  /* Transiciones */
  --transition-smooth: all 0.3s ease-out;

  /* Reset de fuentes para el widget */
  line-height: 1.5;
  text-align: left;
  box-sizing: border-box;
}

#chat-flowi-widget * {
  box-sizing: border-box;
}

/* ===========================
   WIDGET CONTAINER
   El wrapper actúa como una capa transparente del tamaño del viewport.
   Cada hijo se posiciona individualmente con `position: fixed` y recupera
   sus pointer-events. Antes el wrapper era una caja 60×60 que en algunos
   navegadores móviles clippeaba a sus hijos position:fixed (la barra
   aparecía como icono + X y el chat se renderizaba con el header arriba).
   =========================== */
#chat-flowi-widget {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  z-index: 999999;
  font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  direction: ltr;
  text-align: left;
  pointer-events: none;
}

/* Cada elemento interactivo recupera pointer-events para ser clicable. */
#chat-flowi-widget #chat-bubble,
#chat-flowi-widget #chat-window,
#chat-flowi-widget #chat-intro-bar {
  pointer-events: auto;
}

/* Las clases chat-widget-right / chat-widget-left ya no necesitan posicionar
   el wrapper (es full-viewport). Las usaremos a nivel de cada hijo. */
#chat-flowi-widget.chat-widget-right,
#chat-flowi-widget.chat-widget-left {
  right: 0;
  left: 0;
}

/* ===========================
   BOTÓN FLOTANTE
   =========================== */
#chat-flowi-widget #chat-bubble {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  transition: var(--transition-smooth);
  overflow: visible;
  margin: 0;
  padding: 0;
}

#chat-flowi-widget.chat-widget-left #chat-bubble {
  left: 20px;
  right: auto;
}

#chat-flowi-widget #chat-bubble:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-medium);
}

#chat-flowi-widget #chat-bubble svg {
  width: 28px;
  height: 28px;
  display: block;
}

/* Eliminar el texto del bubble */
#chat-flowi-widget .bubble-text {
  display: none;
}

/* ===========================
   VENTANA DE CHAT
   =========================== */
#chat-flowi-widget #chat-window {
  position: fixed;
  bottom: 20px;
  /* Anchored to bottom regardless of button height */
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 650px;
  max-height: calc(100vh - 100px);
  /* Restored height capacity */
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow-medium);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: var(--transition-smooth);
  pointer-events: none;
  border: 1px solid var(--border-color);
  /* Added border for contrast */
  /* Prevent window from affecting page layout */
  contain: layout style paint;
  will-change: transform, opacity;
}

/* Force SVG visibility and color */
#chat-flowi-widget svg {
  display: inline-block !important;
  vertical-align: middle;
}

#chat-flowi-widget .close-button svg {
  stroke: #ffffff !important;
}

#chat-flowi-widget #send-button svg {
  stroke: #ffffff !important;
}

#chat-flowi-widget .attachment-btn svg {
  stroke: #7F8C8D !important;
}

#chat-flowi-widget .attachment-btn:hover svg {
  stroke: var(--primary-blue) !important;
}

#chat-flowi-widget #chat-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

#chat-flowi-widget.chat-widget-right #chat-window {
  right: 20px;
}

#chat-flowi-widget.chat-widget-left #chat-window {
  left: 20px;
}

/* ===========================
   HEADER DEL CHAT
   =========================== */
#chat-flowi-widget .chat-header {
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  color: var(--white);
  padding: 24px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: 88px;
  border-radius: 20px 20px 0 0;
  /* Match container radius */
}

#chat-flowi-widget .chat-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

#chat-flowi-widget .chat-logo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary-blue);
  border: 3px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  margin: 0;
  /* Reset */
}

#chat-flowi-widget .chat-logo img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  margin: 0;
  /* Reset */
  padding: 0;
  /* Reset */
}

#chat-flowi-widget .chat-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chat-flowi-widget .chat-title h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  color: #1a202c;
  /* Fallback */
  letter-spacing: -0.02em;
  line-height: 1.2;
}

#chat-flowi-widget .chat-status {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  color: rgba(44, 62, 80, 0.7);
  /* Fallback */
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  line-height: 1;
}

#chat-flowi-widget .chat-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--online-green);
  border-radius: 50%;
  display: inline-block;
  animation: pulse-status 2s infinite;
  box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.4);
}

@keyframes pulse-status {

  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.4);
  }

  50% {
    opacity: 0.8;
    box-shadow: 0 0 0 4px rgba(72, 187, 120, 0);
  }
}

#chat-flowi-widget .close-button {
  background: rgba(0, 0, 0, 0.2);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  transition: var(--transition-smooth);
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

#chat-flowi-widget .close-button:hover {
  background: rgba(0, 0, 0, 0.3);
  transform: rotate(90deg);
}

/* ===========================
   ÁREA DE MENSAJES
   =========================== */
#chat-flowi-widget .chat-messages {
  flex: 1;
  /* Sin min-height:0 el flex item no se encoge por debajo de su contenido y el scroll nunca se activa. */
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  background: var(--background);
  scroll-behavior: smooth;
  /* Optimizaciones de rendimiento */
  will-change: scroll-position;
  contain: layout style paint;
  -webkit-overflow-scrolling: touch;
  /* `overscroll-behavior: contain` evita que el scroll del chat se propague
     a la página por debajo (importante con librerías de smooth-scroll a nivel
     de documento como Lenis, que arrastrarían el body al llegar a los topes). */
  overscroll-behavior: contain;
}

#chat-flowi-widget .chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-flowi-widget .chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-flowi-widget .chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

#chat-flowi-widget .chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===========================
   BURBUJAS DE MENSAJES
   =========================== */
#chat-flowi-widget .message {
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: messageSlideIn 0.3s ease-out;
  /* Optimizaciones de rendimiento */
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#chat-flowi-widget .message.user {
  flex-direction: row-reverse;
}

/* Avatares */
#chat-flowi-widget .message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  margin: 0;
}

#chat-flowi-widget .message.bot .message-avatar {
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  color: var(--white);
  font-weight: 600;
}

#chat-flowi-widget .message.user .message-avatar {
  background: var(--bubble-user);
  color: var(--text-primary);
  font-weight: 600;
}

#chat-flowi-widget .message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  margin: 0;
}

/* Contenedor del mensaje */
#chat-flowi-widget .message>div {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

/* Burbujas */
#chat-flowi-widget .message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  /* Algunos temas de WP fuerzan hyphens:auto en <p>, lo que partía
     mensajes cortos como "hola" en "h-o-la" dentro de la burbuja. */
  -webkit-hyphens: manual;
  hyphens: manual;
  width: fit-content;
  max-width: 100%;
  position: relative;
  box-shadow: none;
  /* Reset shadow */
}

#chat-flowi-widget .message.bot .message-bubble {
  background: var(--bubble-bot);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

#chat-flowi-widget .message.user .message-bubble {
  background: var(--bubble-user);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

#chat-flowi-widget .message-text {
  margin: 0;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  white-space: pre-wrap;
  /* Preserva saltos de línea y espacios */
  word-wrap: break-word;
  /* Rompe palabras largas */
  overflow-wrap: break-word;
  word-break: normal;
  /* Anula hyphens:auto que algunos temas aplican a <p>, evitando
     que mensajes cortos se partan con guiones dentro de la burbuja. */
  -webkit-hyphens: manual;
  hyphens: manual;
  text-align: left;
  text-align-last: auto;
  word-spacing: normal;
  letter-spacing: normal;
  color: inherit;
}

#chat-flowi-widget .message-time {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
  line-height: normal;
}

#chat-flowi-widget .message.bot .message-time {
  text-align: left;
}

#chat-flowi-widget .message.user .message-time {
  text-align: right;
}

/* ===========================
   INDICADOR DE ESCRITURA
   =========================== */
#chat-flowi-widget .typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  /* Optimización de rendimiento */
  will-change: transform;
}

#chat-flowi-widget .typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out;
  /* Optimización de rendimiento - usar GPU */
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

#chat-flowi-widget .typing-dot:nth-child(1) {
  animation-delay: 0s;
}

#chat-flowi-widget .typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

#chat-flowi-widget .typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.7;
  }

  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ===========================
   INPUT DE MENSAJE
   =========================== */
#chat-flowi-widget .chat-input-wrapper {
  background: var(--white);
  padding: 16px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  border-radius: 0 0 20px 20px;
  /* Match container radius */
}

#chat-flowi-widget .chat-input-container {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

/* Botones de adjuntos */
#chat-flowi-widget .attachment-buttons {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

#chat-flowi-widget .attachment-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--background);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  padding: 0;
  margin: 0;
}

#chat-flowi-widget .attachment-btn:hover {
  background: var(--border-color);
  color: var(--primary-blue);
  transform: scale(1.05);
}

#chat-flowi-widget .attachment-btn.recording {
  background: #fee;
  color: #c00;
  animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

#chat-flowi-widget .attachment-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

#chat-flowi-widget #chat-input {
  flex: 1;
  border: 2px solid var(--primary-blue-light);
  border-radius: 28px;
  padding: 14px 20px;
  /* font-size 16px es el mínimo para evitar el zoom automático que hace
     iOS Safari al enfocar un input. Si está por debajo, iOS rescala el
     viewport y se rompe la geometría del chat junto con el teclado. */
  font-size: 16px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 52px;
  transition: var(--transition-smooth);
  outline: none;
  background: var(--white);
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0;
  box-shadow: none;
}

#chat-flowi-widget #chat-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

#chat-flowi-widget #chat-input:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#chat-flowi-widget #send-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary-blue);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

#chat-flowi-widget #send-button:hover:not(:disabled) {
  transform: scale(1.05);
  background: var(--primary-blue-light);
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
}

#chat-flowi-widget #send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chat-flowi-widget #send-button svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ===========================
   MODAL DE CONSENTIMIENTO
   =========================== */
#chat-flowi-widget .consent-modal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  z-index: 10;
  border-radius: 20px;
}

#chat-flowi-widget .consent-modal h3 {
  color: var(--text-primary);
  margin: 0 0 16px 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

#chat-flowi-widget .consent-modal p {
  color: var(--text-secondary);
  margin: 0 0 24px 0;
  font-size: 14px;
  line-height: 1.6;
}

#chat-flowi-widget .consent-modal a {
  color: var(--primary-blue);
  text-decoration: none;
  font-weight: 500;
}

#chat-flowi-widget .consent-modal a:hover {
  text-decoration: underline;
}

#chat-flowi-widget .consent-email {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  transition: var(--transition-smooth);
  color: var(--text-primary);
  background: var(--white);
}

#chat-flowi-widget .consent-email:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

#chat-flowi-widget .consent-buttons {
  display: flex;
  gap: 10px;
  width: 100%;
}

#chat-flowi-widget .consent-btn {
  flex: 1;
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
  margin: 0;
}

#chat-flowi-widget .consent-btn-accept {
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  color: var(--white);
}

#chat-flowi-widget .consent-btn-accept:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
}

#chat-flowi-widget .consent-btn-decline {
  background: var(--border-color);
  color: var(--text-primary);
}

#chat-flowi-widget .consent-btn-decline:hover {
  background: #cbd5e0;
}

/* ===========================
   PREVISUALIZACIÓN DE ARCHIVOS
   =========================== */
#chat-flowi-widget .file-preview-area {
  padding: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#chat-flowi-widget .file-preview-item {
  background: var(--background);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

#chat-flowi-widget .file-preview-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--white);
  overflow: hidden;
}

#chat-flowi-widget .file-preview-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  margin: 0;
}

#chat-flowi-widget .file-preview-icon.loading {
  opacity: 0.5;
}

#chat-flowi-widget .file-preview-info {
  flex: 1;
  min-width: 0;
}

#chat-flowi-widget .file-preview-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  line-height: normal;
}

#chat-flowi-widget .file-preview-size {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

#chat-flowi-widget .file-preview-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--transition-smooth);
  flex-shrink: 0;
  margin: 0;
}

#chat-flowi-widget .file-preview-remove:hover {
  background: rgba(255, 0, 0, 0.1);
  color: #c00;
}

/* ===========================
   ARCHIVOS ADJUNTOS EN MENSAJES
   =========================== */
#chat-flowi-widget .message-attachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chat-flowi-widget .message-attachment {
  border-radius: 8px;
  overflow: hidden;
}

/* Imágenes adjuntas */
#chat-flowi-widget .image-attachment {
  max-width: 100%;
}

#chat-flowi-widget .image-attachment a {
  display: block;
  text-decoration: none;
}

#chat-flowi-widget .image-attachment img {
  max-width: 100%;
  height: auto;
  max-height: 300px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
  cursor: pointer;
  transition: var(--transition-smooth);
  margin: 0;
}

#chat-flowi-widget .image-attachment img:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

/* Audio adjunto */
#chat-flowi-widget .audio-attachment {
  background: rgba(0, 0, 0, 0.05);
  padding: 12px;
  border-radius: 8px;
}

#chat-flowi-widget .audio-attachment audio {
  width: 100%;
  max-width: 300px;
  height: 32px;
}

#chat-flowi-widget .audio-attachment .attachment-info {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#chat-flowi-widget .audio-attachment .attachment-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: normal;
}

#chat-flowi-widget .audio-attachment .attachment-size {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Archivo genérico adjunto */
#chat-flowi-widget .file-attachment {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  transition: var(--transition-smooth);
}

#chat-flowi-widget .file-attachment:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--primary-blue);
}

#chat-flowi-widget .file-attachment a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  text-decoration: none;
  color: var(--text-primary);
}

#chat-flowi-widget .file-attachment .attachment-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  border-radius: 8px;
}

#chat-flowi-widget .file-attachment .attachment-info {
  flex: 1;
  min-width: 0;
}

#chat-flowi-widget .file-attachment .attachment-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  line-height: normal;
  margin-bottom: 2px;
}

#chat-flowi-widget .file-attachment .attachment-size {
  font-size: 11px;
  color: var(--text-secondary);
  display: block;
  margin-top: 2px;
}

#chat-flowi-widget .file-attachment .attachment-download {
  color: var(--primary-blue);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(74, 144, 226, 0.1);
  transition: var(--transition-smooth);
}

#chat-flowi-widget .file-attachment:hover .attachment-download {
  background: var(--primary-blue);
  color: var(--white);
  transform: scale(1.1);
}

/* ===========================
   RESPONSIVE
   El wrapper sigue siendo full-viewport pass-through; lo que cambia
   por breakpoint es el posicionamiento de cada hijo (bubble y window).
   =========================== */
@media (max-width: 768px) {
  #chat-flowi-widget #chat-bubble {
    right: 10px;
    bottom: 80px;
  }

  #chat-flowi-widget.chat-widget-left #chat-bubble {
    left: 10px;
    right: auto;
  }

  #chat-flowi-widget #chat-window {
    width: calc(100vw - 40px);
    max-width: calc(100vw - 40px);
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    bottom: 10px;
    right: 20px;
  }

  #chat-flowi-widget.chat-widget-right #chat-window {
    right: 20px;
    left: auto;
  }

  #chat-flowi-widget.chat-widget-left #chat-window {
    left: 20px;
    right: auto;
  }
}

@media (max-width: 480px) {
  #chat-flowi-widget #chat-bubble {
    right: 10px;
    bottom: 60px;
    width: 56px;
    height: 56px;
  }

  #chat-flowi-widget.chat-widget-left #chat-bubble {
    left: 10px;
    right: auto;
  }

  #chat-flowi-widget #chat-window {
    width: 100% !important;
    /* La altura viene de --chat-app-height (CSS variable que el JS actualiza
       desde window.visualViewport.height en cada resize/scroll del teclado).
       Fallback a 100dvh y 100vh para navegadores muy antiguos. */
    height: 100vh !important;
    height: 100dvh !important;
    height: var(--chat-app-height, 100dvh) !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    max-height: var(--chat-app-height, 100dvh) !important;
    /* Sin `bottom: 0`: con top:0 + height ya está totalmente determinado.
       Si añadimos bottom:0 estaríamos sobre-restringiendo y iOS Safari
       resolvería dejando el chat más corto que el área visible. */
    bottom: auto !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    border-radius: 0;
    margin: 0;
  }

  /* Cuando el chat está abierto en móvil, bloquear el scroll del body para
     que iOS no haga "scroll-to-input" desplazando todo. Sin esto el chat
     se mueve junto al body y queda hueco arriba y/o abajo. */
  body.chat-flowi-locked {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
  }

  #chat-flowi-widget #chat-bubble svg {
    width: 24px;
    height: 24px;
  }

  #chat-flowi-widget .message-bubble {
    max-width: 80%;
  }

  #chat-flowi-widget .chat-header {
    padding: 18px 16px;
    min-height: 76px;
  }

  #chat-flowi-widget .chat-logo {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  #chat-flowi-widget .chat-title h3 {
    font-size: 16px;
  }

  #chat-flowi-widget .chat-status {
    font-size: 12px;
  }

  #chat-flowi-widget .attachment-btn {
    width: 32px;
    height: 32px;
  }

  #chat-flowi-widget .attachment-btn svg {
    width: 16px;
    height: 16px;
  }

  #chat-flowi-widget .file-preview-name {
    max-width: 120px;
  }

  #chat-flowi-widget .file-attachment .attachment-name {
    max-width: 150px;
  }

  #chat-flowi-widget .image-attachment img {
    max-height: 200px;
  }
}

/* ===========================
   ANIMACIONES ADICIONALES
   =========================== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Mejora de accesibilidad */
@media (prefers-reduced-motion: reduce) {
  #chat-flowi-widget * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================
   ESTILOS MARKDOWN
   =========================== */
#chat-flowi-widget .markdown-content {
  line-height: 1.5;
  white-space: pre-wrap;
  /* Preserva espacios en blanco y saltos de línea */
  word-wrap: break-word;
  /* Rompe palabras largas */
  overflow-wrap: break-word;
  word-break: normal;
  -webkit-hyphens: manual;
  hyphens: manual;
}

#chat-flowi-widget .markdown-content p {
  margin: 0 0 6px 0;
  /* Reducido de 12px a 6px */
  white-space: pre-wrap;
  /* Preserva saltos de línea en párrafos */
  -webkit-hyphens: manual;
  hyphens: manual;
  word-break: normal;
}

#chat-flowi-widget .markdown-content p:last-child {
  margin-bottom: 0;
}

/* Asegurar que los <br> se muestren correctamente */
#chat-flowi-widget .markdown-content br {
  display: block;
  content: "";
  margin: 0;
  /* Reducido de 4px a 0 */
}

/* Encabezados */
#chat-flowi-widget .markdown-content h1,
#chat-flowi-widget .markdown-content h2,
#chat-flowi-widget .markdown-content h3,
#chat-flowi-widget .markdown-content h4,
#chat-flowi-widget .markdown-content h5,
#chat-flowi-widget .markdown-content h6 {
  margin: 10px 0 6px 0;
  /* Reducido de 16px/8px a 10px/6px */
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

#chat-flowi-widget .markdown-content h1 {
  font-size: 1.5em;
}

#chat-flowi-widget .markdown-content h2 {
  font-size: 1.3em;
}

#chat-flowi-widget .markdown-content h3 {
  font-size: 1.15em;
}

#chat-flowi-widget .markdown-content h4 {
  font-size: 1.05em;
}

#chat-flowi-widget .markdown-content h5 {
  font-size: 1em;
}

#chat-flowi-widget .markdown-content h6 {
  font-size: 0.95em;
}

#chat-flowi-widget .markdown-content h1:first-child,
#chat-flowi-widget .markdown-content h2:first-child,
#chat-flowi-widget .markdown-content h3:first-child,
#chat-flowi-widget .markdown-content h4:first-child,
#chat-flowi-widget .markdown-content h5:first-child,
#chat-flowi-widget .markdown-content h6:first-child {
  margin-top: 0;
}

/* Listas */
#chat-flowi-widget .markdown-content ul,
#chat-flowi-widget .markdown-content ol {
  margin: 6px 0;
  /* Reducido de 8px a 6px */
  padding-left: 24px;
}

#chat-flowi-widget .markdown-content li {
  margin: 2px 0;
  /* Reducido de 4px a 2px */
  line-height: 1.4;
  /* Agregado para líneas más compactas */
}

#chat-flowi-widget .markdown-content ul>li {
  list-style-type: disc;
}

#chat-flowi-widget .markdown-content ol>li {
  list-style-type: decimal;
}

#chat-flowi-widget .markdown-content ul ul,
#chat-flowi-widget .markdown-content ol ul {
  margin: 4px 0;
}

#chat-flowi-widget .markdown-content ul ul>li {
  list-style-type: circle;
}

/* Código */
#chat-flowi-widget .markdown-content code {
  background: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  font-size: 0.9em;
  color: #e83e8c;
}

#chat-flowi-widget .markdown-content pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  border-left: 3px solid var(--primary-blue);
}

#chat-flowi-widget .markdown-content pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.85em;
  line-height: 1.5;
}

/* Enlaces */
#chat-flowi-widget .markdown-content a {
  color: var(--primary-blue);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition-smooth);
}

#chat-flowi-widget .markdown-content a:hover {
  text-decoration: underline;
  color: var(--primary-blue-light);
}

/* Énfasis */
#chat-flowi-widget .markdown-content strong,
#chat-flowi-widget .markdown-content b {
  font-weight: 600;
  color: var(--text-primary);
}

#chat-flowi-widget .markdown-content em,
#chat-flowi-widget .markdown-content i {
  font-style: italic;
}

/* Bloques de cita */
#chat-flowi-widget .markdown-content blockquote {
  margin: 12px 0;
  padding: 8px 16px;
  border-left: 4px solid var(--primary-blue);
  background: rgba(74, 144, 226, 0.05);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

#chat-flowi-widget .markdown-content blockquote p {
  margin: 4px 0;
}

/* Línea horizontal */
#chat-flowi-widget .markdown-content hr {
  border: none;
  border-top: 2px solid var(--border-color);
  margin: 16px 0;
}

/* Tablas */
#chat-flowi-widget .markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 0.9em;
}

#chat-flowi-widget .markdown-content table th,
#chat-flowi-widget .markdown-content table td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

#chat-flowi-widget .markdown-content table th {
  background: rgba(74, 144, 226, 0.1);
  font-weight: 600;
  color: var(--text-primary);
}

#chat-flowi-widget .markdown-content table tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

/* Imágenes */
#chat-flowi-widget .markdown-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
}

/* ===========================
   INTRO BAR (estilo ShareGate)
   =========================== */

#chat-flowi-widget #chat-intro-bar {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  background: var(--white);
  border-radius: 20px;
  box-shadow: var(--shadow-medium);
  border: 1px solid var(--border-color);
  padding: 20px 18px 14px;
  flex-direction: column !important;
  gap: 12px;
  z-index: 999998;
  font-family: inherit;
  box-sizing: border-box;
  /* Asegurar visibilidad completa contra reglas globales del tema */
  visibility: visible !important;
  opacity: 1 !important;
}

/* Garantizar que los hijos de la barra son visibles (algunos temas
   ocultan inputs/forms desconocidos por defecto). */
#chat-flowi-widget .chat-intro-header,
#chat-flowi-widget .chat-intro-form,
#chat-flowi-widget #chat-intro-input,
#chat-flowi-widget #chat-intro-send,
#chat-flowi-widget .chat-intro-greeting,
#chat-flowi-widget .chat-intro-avatar {
  visibility: visible !important;
  opacity: 1 !important;
}

#chat-flowi-widget.chat-widget-left #chat-intro-bar {
  left: 20px;
  right: auto;
}

#chat-flowi-widget #chat-intro-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 150ms ease, color 150ms ease;
  /* iOS necesita esto para que un button transparent reciba taps consistentemente */
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}

#chat-flowi-widget #chat-intro-close:hover {
  background: var(--background);
  color: var(--text-primary);
}

#chat-flowi-widget #chat-intro-close svg {
  stroke: currentColor !important;
}

#chat-flowi-widget .chat-intro-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 28px;
}

#chat-flowi-widget .chat-intro-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}

#chat-flowi-widget .chat-intro-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#chat-flowi-widget .chat-intro-greeting {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
  font-weight: 500;
}

#chat-flowi-widget .chat-intro-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#chat-flowi-widget .chat-intro-suggestions[hidden] {
  display: none;
}

#chat-flowi-widget .chat-intro-suggestion {
  appearance: none;
  border: 1px solid var(--border-color);
  background: var(--background);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.2;
  font-family: inherit;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 100ms ease;
}

#chat-flowi-widget .chat-intro-suggestion:hover {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: var(--white);
  transform: translateY(-1px);
}

#chat-flowi-widget .chat-intro-form {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--background);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 4px 4px 4px 16px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

#chat-flowi-widget .chat-intro-form:focus-within {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

#chat-flowi-widget #chat-intro-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  /* font-size 16px obligatorio para evitar el zoom automático de iOS Safari
     al enfocar inputs. Si fuese 14px, iOS rescalaría el viewport y se
     descuadraría todo el layout cuando aparece el teclado. */
  font-size: 16px;
  color: var(--text-primary);
  font-family: inherit;
  padding: 8px 0;
  min-width: 0;
}

#chat-flowi-widget #chat-intro-input::placeholder {
  color: var(--text-secondary);
}

#chat-flowi-widget #chat-intro-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary-blue), var(--primary-blue-light));
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

#chat-flowi-widget #chat-intro-send svg {
  stroke: var(--white) !important;
}

#chat-flowi-widget #chat-intro-send:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-soft);
}

/* ===========================
   CONTROL DE ESTADOS
   Reglas con :not() ganan en especificidad sobre las reglas base de
   #chat-bubble / #chat-window que están más arriba en el archivo.
   =========================== */
/* !important para blindar contra cualquier hoja de estilos del tema o
   plugin que intente modificar el display de estos elementos. */
#chat-flowi-widget:not(.state-bar) #chat-intro-bar {
  display: none !important;
}

#chat-flowi-widget:not(.state-collapsed) #chat-bubble {
  display: none !important;
}

#chat-flowi-widget:not(.state-open) #chat-window {
  display: none !important;
}

#chat-flowi-widget.state-bar #chat-intro-bar {
  display: flex !important;
}

#chat-flowi-widget.state-collapsed #chat-bubble {
  display: flex !important;
}

#chat-flowi-widget.state-open #chat-window {
  display: flex !important;
}

/* Fallback: si por alguna razón el wrapper NO tiene ninguna clase de estado
   (caché agresiva de tema/plugin que devuelve la plantilla antigua, fallo del
   inline script, etc.), mostramos la barra por defecto en lugar de dejar
   todo oculto. Esto se sobrescribe por las reglas .state-* anteriores cuando
   sí hay clase de estado. */
#chat-flowi-widget:not(.state-bar):not(.state-collapsed):not(.state-open) #chat-intro-bar {
  display: flex !important;
}

/* ===========================
   ANIMACIONES DE TRANSICIÓN
   =========================== */
#chat-flowi-widget.transitioning-bar-to-open #chat-intro-bar {
  animation: chatFlowiBarOutRight 240ms ease-in forwards;
}

#chat-flowi-widget.transitioning-bar-to-collapsed #chat-intro-bar {
  animation: chatFlowiBarOutDown 220ms ease-in forwards;
}

@keyframes chatFlowiBarOutRight {
  0% {
    transform: translateX(0) translateY(0);
    opacity: 1;
  }

  100% {
    transform: translateX(80px) translateY(0);
    opacity: 0;
  }
}

@keyframes chatFlowiBarOutDown {
  0% {
    transform: translateY(0);
    opacity: 1;
  }

  100% {
    transform: translateY(110%);
    opacity: 0;
  }
}

/* ===========================
   INTRO BAR — RESPONSIVE
   =========================== */
@media (max-width: 640px) {
  #chat-flowi-widget #chat-intro-bar {
    right: 10px;
    left: 10px;
    bottom: 10px;
    width: auto;
    max-width: none;
  }

  #chat-flowi-widget.chat-widget-left #chat-intro-bar {
    left: 10px;
    right: 10px;
  }

  #chat-flowi-widget .chat-intro-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -4px;
    padding: 0 4px 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  #chat-flowi-widget .chat-intro-suggestions::-webkit-scrollbar {
    display: none;
  }

  #chat-flowi-widget .chat-intro-suggestion {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* Reduced motion: corta animaciones de transición */
@media (prefers-reduced-motion: reduce) {

  #chat-flowi-widget.transitioning-bar-to-open #chat-intro-bar,
  #chat-flowi-widget.transitioning-bar-to-collapsed #chat-intro-bar {
    animation: none;
  }
}