/* =============================================
   PERFORMANCE.CSS — Lazy loading, parallax, smooth scroll
   ============================================= */

/* ── Smooth Scroll Nativo ── */
html {
  scroll-behavior: smooth;
}

/* ── Lazy Loading de Imágenes ── */
img[loading="lazy"],
img.lazy {
  opacity: 0;
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

img[loading="lazy"].loaded,
img.lazy.loaded {
  opacity: 1;
}

/* Blur-up effect (placeholder temporal) */
img.lazy[data-src]:not(.loaded) {
  background: linear-gradient(90deg, rgba(200, 200, 200, 0.2) 25%, rgba(200, 200, 200, 0.1) 50%, rgba(200, 200, 200, 0.2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

/* ── Parallax en Desktop (sutil) ── */
@media (min-width: 768px) and (hover: hover) {
  .parallax {
    will-change: transform;
  }

  .parallax[data-speed="0.5"] {
    transform: translateY(calc(var(--scroll) * 0.5px));
  }

  .parallax[data-speed="0.3"] {
    transform: translateY(calc(var(--scroll) * 0.3px));
  }
}

/* Deshabilitar parallax en móvil y low motion */
@media (max-width: 768px),
       (prefers-reduced-motion: reduce) {
  .parallax {
    transform: none !important;
  }
}

/* ── Reduced Motion (Accesibilidad) ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Optimización de Performance ── */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Evitar layout shift en imágenes cargadas */
img:not([width]) {
  width: 100%;
}

/* Critical images — priorizar carga */
img[data-critical] {
  loading: eager;
  fetchpriority: high;
}

/* Background images con carga optimizada */
.bg-lazy {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"/>')!important;
  background-size: cover;
  background-position: center;
}

.bg-lazy.loaded {
  background-attachment: fixed;
}

/* ── Network Information API (offline support) ── */
@media (prefers-reduced-data: reduce) {
  img {
    max-width: 100vw;
  }

  .hero-visual img,
  .gallery-item img {
    filter: grayscale(10%);
  }
}
