/* Chatbot Styles */
.chatbot-container {
  position: fixed;
  bottom: 20px; /* Posicionado debajo del botón de Instagram */
  right: 20px; /* Alineado verticalmente con Instagram */
  z-index: 1001; /* Z-index más alto que Instagram pero menor que menú */
  font-family: 'Inter', sans-serif;
}

/* Accesibilidad - Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible para accesibilidad */
.chatbot-toggle:focus-visible,
.chatbot-close:focus-visible,
.chatbot-send:focus-visible {
  outline: 2px solid #e6d90c;
  outline-offset: 2px;
}

.chatbot-input textarea:focus-visible {
  outline: 2px solid #e6d90c;
  outline-offset: 1px;
}

.chatbot-messages:focus-visible {
  outline: 2px solid #e6d90c;
  outline-offset: -2px;
}

/* Mejoras para dispositivos táctiles */
@media (hover: none) and (pointer: coarse) {
  .chatbot-toggle,
  .chatbot-close,
  .chatbot-send {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Optimizaciones de rendimiento */
/* Reducir animaciones para dispositivos de bajo rendimiento */
@media (prefers-reduced-motion: reduce) {
  .chatbot-toggle,
  .chatbot-window,
  .chatbot-send,
  .message,
  .typing-dot {
    animation: none !important;
    transition: none !important;
  }
  
  .chatbot-window.active {
    animation: none;
  }
  
  @keyframes slideUp {
    from, to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  @keyframes typing {
    0%, 60%, 100% {
      transform: translateY(0);
    }
  }
}

/* Optimizaciones para conexiones lentas */
@media (prefers-reduced-data: reduce) {
  .chatbot-toggle::before {
    display: none;
  }
  
  .chatbot-toggle {
    backdrop-filter: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  }
  
  .chatbot-window {
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
  }
}

/* Optimizaciones para dispositivos de baja potencia */
@media (max-width: 480px) and (max-height: 800px) {
  .chatbot-toggle {
    will-change: transform;
  }
  
  .chatbot-window {
    will-change: opacity, transform;
  }
  
  .chatbot-messages {
    will-change: scroll-position;
  }
  
  /* Simplificar gradientes en móviles */
  .chatbot-toggle {
    background: #FFD700;
  }
  
  .chatbot-toggle:hover {
    background: #FFED4E;
  }
  
  .chatbot-toggle.active {
    background: #E6AC00;
  }
  
  .message.user {
    background: #f4e555;
  }
  
  .chatbot-send {
    background: #f4e555;
  }
}

/* Botón flotante del chatbot - Diseño moderno */
.chatbot-toggle {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  border: 2px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(255, 215, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-toggle::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 100%);
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.chatbot-toggle:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 12px 48px rgba(255, 237, 78, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  background: linear-gradient(135deg, #FFED4E 0%, #FFB800 100%);
}

.chatbot-toggle:hover::before {
  opacity: 1;
}

.chatbot-toggle:active {
  transform: translateY(-2px) scale(1.02);
  transition: all 0.1s ease;
}

.chatbot-toggle svg {
  width: 26px;
  height: 26px;
  color: #000000;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  filter: drop-shadow(0 2px 4px rgba(255, 255, 255, 0.5));
  z-index: 1;
}

.chatbot-toggle:hover svg {
  transform: scale(1.1);
  color: #f8fafc;
}

.chatbot-toggle.active svg {
  transform: rotate(180deg) scale(1.1);
}

.chatbot-toggle.active {
  background: linear-gradient(135deg, #E6AC00 0%, #CC9900 100%);
  box-shadow: 0 12px 48px rgba(230, 172, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Ventana del chat */
.chatbot-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.chatbot-window.active {
  display: flex;
  animation: slideUp 0.3s ease-out;
}

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

/* Header del chat */
.chatbot-header {
  background: linear-gradient(135deg, #0b0b0f, #1a1a1f);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatbot-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chatbot-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.chatbot-close:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Área de mensajes */
.chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9fafb;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

/* Mensajes */
.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
}

.message.user {
  background: linear-gradient(135deg, #e6d90c, #f4e555);
  color: #0b0b0f;
  align-self: flex-end;
  margin-left: auto;
}

.message.bot {
  background: #ffffff;
  color: #374151;
  align-self: flex-start;
  border: 1px solid #e5e7eb;
}

.message.typing {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Animación de escritura */
.typing-indicator {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #9ca3af;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

/* Área de entrada */
.chatbot-input {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  background: white;
}

.chatbot-input-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chatbot-input textarea {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 80px;
  min-height: 40px;
  outline: none;
  transition: border-color 0.2s ease;
}

.chatbot-input textarea:focus {
  border-color: #e6d90c;
}

.chatbot-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e6d90c, #f4e555);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-send:hover {
  transform: scale(1.05);
}

.chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chatbot-send svg {
  width: 16px;
  height: 16px;
  color: #0b0b0f;
}

/* Mensaje de bienvenida */
.welcome-message {
  text-align: center;
  padding: 20px;
  color: #6b7280;
  font-size: 14px;
}

/* Responsive Design - Optimizado para múltiples dispositivos */

/* Tablets y dispositivos medianos (481px - 768px) */
@media (max-width: 768px) and (min-width: 481px) {
  .chatbot-container {
    bottom: 20px;
    right: 20px;
  }
  
  .chatbot-window {
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 100px);
  }
  
  .chatbot-toggle {
    width: 60px;
    height: 60px;
  }
  
  .chatbot-toggle svg {
    width: 24px;
    height: 24px;
  }
  
  .chatbot-messages {
    padding: 16px;
  }
  
  .message {
    font-size: 15px;
    padding: 14px 18px;
  }
}

/* Móviles grandes (376px - 480px) */
@media (max-width: 480px) and (min-width: 376px) {
  .chatbot-container {
    bottom: 15px;
    right: 15px;
  }
  
  .chatbot-window {
    bottom: 75px;
    right: 0;
    left: 15px;
    width: calc(100vw - 30px);
    height: calc(100vh - 140px);
    max-height: 500px;
    border-radius: 12px;
  }
  
  .chatbot-toggle {
    width: 56px;
    height: 56px;
    border-radius: 16px;
  }
  
  .chatbot-toggle svg {
    width: 22px;
    height: 22px;
  }
  
  .chatbot-header {
    padding: 14px 16px;
  }
  
  .chatbot-header h3 {
    font-size: 15px;
  }
  
  .chatbot-messages {
    padding: 14px;
    gap: 10px;
  }
  
  .message {
    font-size: 14px;
    padding: 12px 16px;
    border-radius: 16px;
    max-width: 85%;
  }
  
  .chatbot-input {
    padding: 12px 16px;
  }
  
  .chatbot-input textarea {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 12px 16px;
    border-radius: 18px;
  }
  
  .chatbot-send {
    width: 44px;
    height: 44px;
  }
  
  .chatbot-send svg {
    width: 18px;
    height: 18px;
  }
}

/* Resoluciones específicas problemáticas */
@media (min-width: 393px) and (max-width: 393px) and (min-height: 852px) and (max-height: 852px) {
  .chatbot-container {
    bottom: 16px;
    right: 16px;
  }
  
  .chatbot-window {
    bottom: 75px;
    right: 0;
    left: 16px;
    width: calc(100vw - 32px);
    height: calc(100vh - 140px);
    max-height: 600px;
    border-radius: 12px;
  }
  
  .chatbot-toggle {
    width: 56px;
    height: 56px;
    border-radius: 16px;
  }
  
  .chatbot-messages {
    padding: 14px;
    gap: 10px;
  }
  
  .message {
    font-size: 14px;
    padding: 12px 16px;
    max-width: 85%;
  }
}

@media (min-width: 480px) and (max-width: 480px) and (min-height: 1040px) and (max-height: 1040px) {
  .chatbot-container {
    bottom: 20px;
    right: 20px;
  }
  
  .chatbot-window {
    bottom: 80px;
    right: 0;
    left: 20px;
    width: calc(100vw - 40px);
    height: calc(100vh - 160px);
    max-height: 700px;
    border-radius: 14px;
  }
  
  .chatbot-toggle {
    width: 58px;
    height: 58px;
    border-radius: 18px;
  }
  
  .chatbot-messages {
    padding: 16px;
    gap: 12px;
  }
  
  .message {
    font-size: 15px;
    padding: 14px 18px;
    max-width: 80%;
  }
}

/* Móviles pequeños (320px - 375px) */
@media (max-width: 375px) {
  .chatbot-container {
    bottom: 12px;
    right: 12px;
  }
  
  .chatbot-window {
    bottom: 70px;
    right: 0;
    left: 12px;
    width: calc(100vw - 24px);
    height: calc(100vh - 120px);
    max-height: 480px;
    border-radius: 10px;
  }
  
  .chatbot-toggle {
    width: 52px;
    height: 52px;
    border-radius: 14px;
  }
  
  .chatbot-toggle svg {
    width: 20px;
    height: 20px;
  }
  
  .chatbot-header {
    padding: 12px 14px;
  }
  
  .chatbot-header h3 {
    font-size: 14px;
  }
  
  .chatbot-messages {
    padding: 12px;
    gap: 8px;
  }
  
  .message {
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 14px;
    max-width: 90%;
    line-height: 1.3;
  }
  
  .welcome-message {
    padding: 16px;
    font-size: 13px;
  }
  
  .chatbot-input {
    padding: 10px 14px;
  }
  
  .chatbot-input textarea {
    font-size: 16px; /* Evita zoom en iOS */
    padding: 10px 14px;
    border-radius: 16px;
    min-height: 36px;
  }
  
  .chatbot-send {
    width: 40px;
    height: 40px;
  }
  
  .chatbot-send svg {
    width: 16px;
    height: 16px;
  }
  
  .typing-dot {
    width: 5px;
    height: 5px;
  }
}

/* Modo landscape en móviles */
@media (max-height: 500px) and (orientation: landscape) {
  .chatbot-window {
    height: calc(100vh - 80px);
    max-height: none;
  }
  
  .chatbot-messages {
    flex: 1;
    min-height: 0;
  }
  
  .chatbot-header {
    padding: 10px 16px;
  }
  
  .chatbot-input {
    padding: 10px 16px;
  }
}

/* Modo fullscreen para móviles muy pequeños */
@media (max-width: 320px) {
  .chatbot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    max-height: none;
  }
  
  .chatbot-container {
    bottom: 10px;
    right: 10px;
  }
  
  .chatbot-toggle {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }
  
  .chatbot-toggle svg {
    width: 18px;
    height: 18px;
  }
  
  .chatbot-header {
    padding: 16px;
    background: linear-gradient(135deg, #0b0b0f, #1a1a1f);
  }
  
  .chatbot-messages {
    padding: 16px;
    flex: 1;
  }
  
  .message {
    font-size: 14px;
    padding: 12px 16px;
  }
  
  .chatbot-input {
    padding: 16px;
    background: #ffffff;
    border-top: 2px solid #e5e7eb;
  }
}

/* Modo fullscreen dinámico controlado por JavaScript */
.chatbot-container.fullscreen-mode .chatbot-window {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  border-radius: 0 !important;
  max-height: none !important;
  z-index: 9999;
}

.chatbot-container.fullscreen-mode .chatbot-header {
  padding: 16px;
  background: linear-gradient(135deg, #0b0b0f, #1a1a1f);
  position: sticky;
  top: 0;
  z-index: 1;
}

.chatbot-container.fullscreen-mode .chatbot-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.chatbot-container.fullscreen-mode .chatbot-input {
  padding: 16px;
  background: #ffffff;
  border-top: 2px solid #e5e7eb;
  position: sticky;
  bottom: 0;
}

/* Soporte para Visual Viewport API (teclado virtual) */
@supports (height: 100dvh) {
  .chatbot-container.fullscreen-mode .chatbot-window {
    height: 100dvh !important;
  }
}

/* Mejoras para iOS Safari */
@supports (-webkit-touch-callout: none) {
  .chatbot-container.fullscreen-mode .chatbot-window {
    height: -webkit-fill-available !important;
  }
  
  .chatbot-container.fullscreen-mode .chatbot-messages {
    -webkit-overflow-scrolling: touch;
  }
}

/* Estilos específicos para resoluciones problemáticas */
.chatbot-container.problematic-resolution .chatbot-window {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  border-radius: 0 !important;
  max-height: none !important;
  z-index: 9999;
  transform: none !important;
}

.chatbot-container.problematic-resolution .chatbot-header {
  padding: 20px 16px;
  background: linear-gradient(135deg, #0b0b0f, #1a1a1f);
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chatbot-container.problematic-resolution .chatbot-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  max-height: calc(100vh - 140px);
}

.chatbot-container.problematic-resolution .chatbot-input {
  padding: 16px;
  background: #ffffff;
  border-top: 2px solid #e5e7eb;
  position: sticky;
  bottom: 0;
  z-index: 2;
}

.chatbot-container.problematic-resolution .chatbot-toggle {
  width: 60px;
  height: 60px;
  border-radius: 20px;
}

.chatbot-container.problematic-resolution .message {
  font-size: 15px;
  padding: 14px 18px;
  margin-bottom: 12px;
  max-width: 85%;
  line-height: 1.4;
}

/* Ajustes específicos para viewport dinámico */
@supports (height: 100dvh) {
  .chatbot-container.problematic-resolution .chatbot-window {
    height: 100dvh !important;
  }
  
  .chatbot-container.problematic-resolution .chatbot-messages {
    max-height: calc(100dvh - 140px);
  }
}

/* Mejoras adicionales para dispositivos táctiles */
@media (pointer: coarse) {
  .chatbot-container.problematic-resolution .chatbot-input textarea {
    font-size: 16px; /* Evita zoom automático en iOS */
    padding: 14px 16px;
    min-height: 44px; /* Tamaño mínimo táctil */
  }
  
  .chatbot-container.problematic-resolution .chatbot-send {
    width: 48px;
    height: 48px;
    min-width: 44px; /* Tamaño mínimo táctil */
    min-height: 44px;
  }
}