/* ===== OPTIMIZACIONES ANTI-CLS (Cumulative Layout Shift) ===== */

/* Estabilización de fuentes web */
@font-face {
  font-family: 'Roboto';
  font-display: swap;
  font-weight: 300 700;
  src: url('https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2') format('woff2');
}

/* Fallbacks de fuentes para evitar FOIT/FOUT */
body {
  font-family: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-display: swap;
}

/* Reservar espacio para elementos que se cargan dinámicamente */

/* Modales - Estado inicial optimizado */
.privacy-modal,
.cookies-modal,
.terms-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 9999;
  contain: layout style paint;
  will-change: opacity, visibility;
}

/* Banner de cookies - Espacio reservado */
.cookie-banner-placeholder {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0;
  transition: height 0.3s ease;
  z-index: 9999;
  contain: layout style;
}

.cookie-banner-placeholder.active {
  height: 80px; /* Altura aproximada del banner */
}

/* Títulos de sección - Dimensiones estables */
.section-title {
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout style;
  will-change: auto;
}

/* Imágenes - Prevenir saltos de layout */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Placeholder para imágenes que se cargan */
.img-placeholder {
  background: #f0f0f0;
  display: inline-block;
  min-height: 200px;
  width: 100%;
  position: relative;
}

.img-placeholder::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid #e02b20;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Grids de productos - Estabilización */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  contain: layout style;
}

.product-card {
  min-height: 320px;
  contain: layout style paint;
  will-change: transform;
}

/* Banners - Dimensiones reservadas */
.banner-container {
  min-height: 200px;
  contain: layout style paint;
  overflow: hidden;
}

.banner-container img {
  width: 100%;
  height: auto;
  display: block;
}

/* Navegación - Estabilización */
.navbar-pc {
  min-height: 80px;
  contain: layout style;
}

.navbar-mobile {
  min-height: 60px;
  contain: layout style;
}

/* Secciones principales - Contención */
.features-section,
.products-section,
#servicios,
#ubicaciones,
#horarios-pagos,
#preguntas-frecuentes {
  contain: layout style;
}

/* FAQ - Prevenir CLS en acordeones */
.faq-item {
  contain: layout style;
  will-change: auto;
}

.faq-answer {
  contain: layout style;
  will-change: max-height, opacity;
}

/* Elementos con transformaciones */
.feature-item,
.product-card,
.btn-ver-mas {
  will-change: transform;
  contain: layout style paint;
}

/* Optimización para elementos fijos */
.fixed-element {
  contain: layout style paint;
  will-change: transform;
}

/* Media queries para responsive sin CLS */
@media (max-width: 768px) {
  .section-title {
    min-height: 2.5rem;
  }
  
  .banner-container {
    min-height: 150px;
  }
  
  .product-card {
    min-height: 300px;
  }
}

@media (max-width: 480px) {
  .section-title {
    min-height: 2rem;
  }
  
  .banner-container {
    min-height: 120px;
  }
  
  .product-card {
    min-height: 280px;
  }
}

/* Prevenir CLS en elementos que cambian de estado */
.loading-state {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-state {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Optimizaciones específicas para Lighthouse */
.lighthouse-optimized {
  contain: layout style paint;
  will-change: auto;
}

/* Contenedores de layout estables */
.stable-container {
  contain: layout;
  position: relative;
}

.stable-content {
  contain: style paint;
} 