/**
 * Optimizaciones de Performance y Conversión
 * Incluir después de Tailwind CSS
 */

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Lazy loading placeholder */
img[loading="lazy"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Prevent layout shift */
img {
  max-width: 100%;
  height: auto;
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */

/* Touch targets mínimo 48px */
@media (max-width: 768px) {
  a, button, input[type="submit"], input[type="button"] {
    min-height: 48px;
    min-width: 48px;
  }

  /* Botones más grandes en mobile */
  .btn-primary, .btn-secondary {
    padding: 16px 32px !important;
    font-size: 16px !important;
  }

  /* Formularios más espaciados */
  input, select, textarea {
    padding: 14px 16px !important;
    font-size: 16px !important; /* Previene zoom en iOS */
  }
}

/* ============================================
   STICKY CTA MOBILE
   ============================================ */

.sticky-cta-mobile {
  display: none;
}

@media (max-width: 768px) {
  .sticky-cta-mobile {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: linear-gradient(135deg, #5D3FD3, #7C3AED);
    padding: 12px 16px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    animation: slideUp 0.3s ease-out;
  }

  .sticky-cta-mobile a {
    display: block;
    text-align: center;
    color: white;
    font-weight: 800;
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
  }

  .sticky-cta-mobile a:active {
    transform: scale(0.98);
  }

  /* Agregar padding al body para compensar sticky CTA */
  body {
    padding-bottom: 80px;
  }
}

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

/* ============================================
   WHATSAPP FLOATING BUTTON
   ============================================ */

.whatsapp-float {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #25D366;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(37, 211, 102, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: pulse 2s infinite;
}

.whatsapp-float:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(37, 211, 102, 0.6);
}

.whatsapp-float:active {
  transform: scale(0.95);
}

.whatsapp-float img {
  width: 32px;
  height: 32px;
  filter: brightness(0) invert(1);
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 4px 20px rgba(37, 211, 102, 0.4);
  }
  50% {
    box-shadow: 0 4px 30px rgba(37, 211, 102, 0.7);
  }
}

@media (max-width: 768px) {
  .whatsapp-float {
    bottom: 100px;
    right: 20px;
    width: 56px;
    height: 56px;
  }

  .whatsapp-float img {
    width: 28px;
    height: 28px;
  }
}

/* ============================================
   EXIT-INTENT POPUP
   ============================================ */

.exit-popup {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease-out;
}

.exit-popup.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.exit-popup-content {
  background: white;
  border-radius: 24px;
  padding: 40px;
  max-width: 500px;
  margin: 20px;
  position: relative;
  animation: scaleIn 0.3s ease-out;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.exit-popup-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.exit-popup-close:hover {
  background: #e2e8f0;
  transform: rotate(90deg);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* No mostrar exit popup en mobile */
@media (max-width: 768px) {
  .exit-popup {
    display: none !important;
  }
}

/* ============================================
   FORM OPTIMIZATIONS
   ============================================ */

/* Loading state en botones */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Validación visual */
input:invalid:not(:placeholder-shown) {
  border-color: #ef4444 !important;
}

input:valid:not(:placeholder-shown) {
  border-color: #10b981 !important;
}

/* Focus states mejorados */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #5D3FD3 !important;
  box-shadow: 0 0 0 3px rgba(93, 63, 211, 0.1) !important;
}

/* ============================================
   TRUST SIGNALS
   ============================================ */

.trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #059669;
}

.trust-badge::before {
  content: "✓";
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #10b981;
  color: white;
  border-radius: 50%;
  font-size: 12px;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus visible para navegación por teclado */
*:focus-visible {
  outline: 2px solid #5D3FD3;
  outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: #5D3FD3;
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 100;
}

.skip-to-content:focus {
  top: 0;
}

/* ============================================
   SMOOTH SCROLL
   ============================================ */

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .sticky-cta-mobile,
  .whatsapp-float,
  .exit-popup,
  header,
  footer {
    display: none !important;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
}

/* Prevent text selection on buttons */
button, .btn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Improve touch scrolling on iOS */
body {
  -webkit-overflow-scrolling: touch;
}
