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

#chat-flowi-widget {
  /* Colores principales */
  --primary-blue: #4A90E2;
  --primary-blue-light: #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
   =========================== */
#chat-flowi-widget {
  position: fixed;
  bottom: 100px;
  right: 20px;
  /* Default fallback */
  width: 60px;
  height: 60px;
  max-width: 60px;
  max-height: 60px;
  z-index: 999999;
  font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  direction: ltr;
  /* Reset direction */
  text-align: left;
  /* Reset alignment */
  /* Prevent widget from affecting page layout */
  pointer-events: auto;
  /* Removed contain: paint as it traps fixed children */
}

/* El botón con texto es más ancho que la burbuja: el contenedor se adapta */
#chat-flowi-widget.chat-launcher-pill {
  width: auto;
  height: auto;
  max-width: calc(100vw - 40px);
  max-height: none;
}

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

#chat-flowi-widget.chat-widget-left {
  left: 20px;
  /* Sin esto, con right: 20px de la regla base, el botón con texto se
     estiraba de lado a lado en vez de ajustarse a su contenido */
  right: auto;
}

/* ===========================
   BOTÓN FLOTANTE
   =========================== */
#chat-flowi-widget #chat-bubble {
  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);
  position: relative;
  overflow: visible;
  margin: 0;
  /* Reset */
  padding: 0;
  /* Reset */
}

#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;
}

#chat-flowi-widget #chat-bubble:focus-visible {
  outline: 3px solid var(--chat-primary, var(--primary-blue));
  outline-offset: 3px;
}

/* Botón con texto (Ajustes → Apariencia → Estilo del botón) */
#chat-flowi-widget #chat-bubble.launcher-pill {
  width: auto;
  height: 52px;
  max-width: min(320px, calc(100vw - 40px));
  border-radius: 999px;
  padding: 0 22px 0 18px;
  gap: 10px;
}

#chat-flowi-widget #chat-bubble.launcher-pill svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

#chat-flowi-widget #chat-bubble.launcher-pill .launcher-text {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: inherit;
}

#chat-flowi-widget #chat-bubble.launcher-pill.has-unread::after {
  top: -3px;
  right: 6px;
}

/* ===========================
   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: #4A90E2 !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;
  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;
}

#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;
}

/* Mensaje de una persona del equipo (modo atención humana) */
#chat-flowi-widget .message.bot.agent .message-avatar {
  background: #0f766e;
  color: var(--white);
}

#chat-flowi-widget .message.bot.agent .message-bubble {
  border-left: 3px solid #0f766e;
}

/* Respuesta del equipo recibida con el chat cerrado */
#chat-flowi-widget #chat-bubble.has-unread::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid var(--white);
}

#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;
  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 */
  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: 15px;
  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-section {
  width: 100%;
  margin-bottom: 16px;
}

#chat-flowi-widget .consent-email {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 14px;
  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-checkboxes {
  width: 100%;
  margin-bottom: 20px;
  text-align: left;
}

#chat-flowi-widget .consent-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

#chat-flowi-widget .consent-checkbox-label input[type="checkbox"] {
  margin-top: 2px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary-blue);
  flex-shrink: 0;
}

#chat-flowi-widget .consent-checkbox-label span {
  flex: 1;
}

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

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

#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
   =========================== */
@media (max-width: 768px) {
  #chat-flowi-widget {
    /* Ensure widget doesn't cause horizontal overflow on tablets */
    right: 10px;
    bottom: 80px;
  }

  #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 {
    /* Ensure widget container is properly constrained on mobile */
    right: 10px;
    bottom: 60px;
    max-width: 56px;
    max-height: 56px;
  }

  #chat-flowi-widget #chat-window {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    max-height: 100vh !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    border-radius: 0;
    margin: 0;
  }

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

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

  #chat-flowi-widget #chat-bubble.launcher-pill {
    width: auto;
    height: 48px;
    padding: 0 18px 0 15px;
  }

  #chat-flowi-widget #chat-bubble.launcher-pill svg {
    width: 20px;
    height: 20px;
  }

  #chat-flowi-widget #chat-bubble.launcher-pill .launcher-text {
    font-size: 14px;
  }

  /* El límite va en el contenedor: un % en la burbuja se calcula sobre un
     contenedor que mide lo que la burbuja, y partía hasta "hola" en 3 líneas */
  #chat-flowi-widget .message>div {
    max-width: 85%;
  }

  #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;
  /* normal, no pre-wrap: marked ya convierte los saltos en <br> (breaks: true)
     y separa sus bloques con \n, que con pre-wrap se veían como líneas en blanco */
  white-space: normal;
  word-wrap: break-word;
  /* Rompe palabras largas */
}

#chat-flowi-widget .markdown-content p {
  margin: 0 0 6px 0;
  /* Reducido de 12px a 6px */
  white-space: 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;
}
/* =========================================================
   Bloques visuales del bot: productos, imágenes, tarjetas
   ========================================================= */
#chat-flowi-widget .message.bot > div:has(.chat-blocks),
#chat-flowi-widget .message.bot > div:has(.chat-inline-product) {
  max-width: 88%;
  min-width: 0;
}

#chat-flowi-widget .chat-blocks {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  min-width: 0;
}

#chat-flowi-widget .chat-gallery-carousel {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

#chat-flowi-widget .chat-gallery-carousel > .chat-block {
  flex: 0 0 168px;
  scroll-snap-align: start;
}

#chat-flowi-widget .chat-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

#chat-flowi-widget .chat-block {
  background: var(--white, #fff);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 12px;
  overflow: hidden;
  margin: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-flowi-widget .chat-block-image {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
}

#chat-flowi-widget .chat-product-media {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  background: #f1f5f9;
}

#chat-flowi-widget .chat-product-media .chat-block-image {
  height: 100%;
  object-fit: cover;
}

/* Tarjeta suelta (fuera de una galería): horizontal, miniatura a la izquierda */
#chat-flowi-widget .chat-blocks > .chat-product {
  flex-direction: row;
}

#chat-flowi-widget .chat-blocks > .chat-product .chat-product-media {
  flex: 0 0 96px;
  width: 96px;
  height: auto;
  align-self: stretch;
  aspect-ratio: auto;
  min-height: 96px;
}

#chat-flowi-widget .chat-product-body > .chat-product-badge {
  position: static;
  align-self: flex-start;
}

#chat-flowi-widget .chat-product-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}

#chat-flowi-widget .chat-product-body,
#chat-flowi-widget .chat-card-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  flex: 1;
}

#chat-flowi-widget .chat-product-title,
#chat-flowi-widget .chat-card-title {
  color: var(--text-primary, #0f172a);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#chat-flowi-widget .chat-product-price {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

#chat-flowi-widget .chat-product-price-current {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #0f172a);
}

#chat-flowi-widget .chat-product-price-regular {
  font-size: 12px;
  color: var(--text-secondary, #64748b);
}

#chat-flowi-widget .chat-product-stock {
  font-size: 12px;
  color: #b45309;
}

#chat-flowi-widget .is-out-of-stock .chat-product-stock {
  color: #b91c1c;
}

#chat-flowi-widget .chat-card-text {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary, #475569);
}

#chat-flowi-widget .chat-product-cta {
  margin-top: auto;
  display: block;
  text-align: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--chat-primary, var(--primary-blue, #4A90E2));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

#chat-flowi-widget .chat-product-cta:hover,
#chat-flowi-widget .chat-product-cta:focus-visible {
  filter: brightness(0.92);
}

#chat-flowi-widget .chat-image figcaption {
  font-size: 12px;
  color: var(--text-secondary, #64748b);
  padding: 6px 10px;
}

/* Productos integrados en el texto del bot */
#chat-flowi-widget .markdown-content ol.chat-inline-products,
#chat-flowi-widget .markdown-content ul.chat-inline-products {
  padding-left: 0;
  margin: 8px 0;
}

#chat-flowi-widget .markdown-content li.has-inline-product {
  list-style: none;
  margin: 8px 0;
}

#chat-flowi-widget .chat-inline-product {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--white, #fff);
  border-radius: 12px;
  padding: 8px;
  margin: 4px 0;
}

#chat-flowi-widget p.has-inline-product {
  margin: 8px 0;
}

#chat-flowi-widget .chat-inline-product-media {
  flex: 0 0 60px;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  background: #f1f5f9;
  display: block;
}

#chat-flowi-widget .chat-inline-product-media .chat-block-image {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  border-radius: 0;
  object-fit: cover;
}

/* "También te puede interesar": lo que el texto no menciona, en fichas compactas */
#chat-flowi-widget .chat-blocks-caption {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  margin: 2px 2px -2px;
}

#chat-flowi-widget .chat-inline-product-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#chat-flowi-widget .chat-inline-product-text {
  font-size: 14px;
  line-height: 1.4;
}

#chat-flowi-widget .chat-inline-product-text p {
  margin: 0;
}

#chat-flowi-widget .chat-inline-product-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
}

#chat-flowi-widget .chat-inline-badge {
  background: #dc2626;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 6px;
}

#chat-flowi-widget .chat-inline-cta {
  margin-left: auto;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--chat-primary, var(--primary-blue, #4A90E2));
  color: #fff !important;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

#chat-flowi-widget .chat-inline-cta:hover,
#chat-flowi-widget .chat-inline-cta:focus-visible {
  filter: brightness(0.92);
}

/* ===========================
   SUGERENCIAS INICIALES (2.7.0)
   Botones bajo el saludo, alineados con la burbuja del bot
   (avatar de 36px + 10px de separación)
   =========================== */
#chat-flowi-widget .chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 12px 46px;
}

#chat-flowi-widget .chat-suggestion {
  appearance: none;
  border: 1px solid var(--chat-primary, var(--primary-blue, #4A90E2));
  background: var(--white, #fff);
  color: var(--chat-primary, var(--primary-blue, #4A90E2));
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  max-width: 100%;
  cursor: pointer;
  transition: background-color 0.15s ease-out, color 0.15s ease-out;
}

#chat-flowi-widget .chat-suggestion:hover,
#chat-flowi-widget .chat-suggestion:focus-visible {
  background: var(--chat-primary, var(--primary-blue, #4A90E2));
  color: #fff;
}

#chat-flowi-widget .chat-suggestion:focus-visible {
  outline: 2px solid var(--chat-primary, var(--primary-blue, #4A90E2));
  outline-offset: 2px;
}

@media (max-width: 480px) {
  #chat-flowi-widget .chat-suggestions {
    margin-left: 0;
  }
}
