/**
 * Lazy Load Flash Effect
 * Creates a shimmer/skeleton loading effect for images before they load
 */

/* Container for lazy loaded images */
.lazy-load-wrapper {
  position: relative;
  display: inline-block;
  overflow: hidden;
  background-color: transparent;
  width: auto;
  max-width: 100%;
}

/* The actual image - hidden until loaded (only for images with data-src) */
.lazy-load-wrapper img[data-src],
.lazy-load-wrapper img[data-srcset] {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
}

/* Images without data-src should be visible immediately */
.lazy-load-wrapper img:not([data-src]):not([data-srcset]) {
  opacity: 1;
}

/* Image is loaded */
.lazy-load-wrapper img.loaded {
  opacity: 1;
}

/* Flash/Shimmer effect overlay */
.lazy-load-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.3) 25%,
    rgba(255, 255, 255, 0.5) 50%,
    rgba(255, 255, 255, 0.3) 75%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: shimmer 1.5s infinite;
  z-index: 1;
}

/* Remove shimmer once loaded */
.lazy-load-wrapper.loaded::before {
  display: none;
}

/* Shimmer animation */
@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* Alternative: Pulse effect */
.lazy-load-wrapper.pulse-effect::before {
  animation: pulse 1.5s ease-in-out infinite;
  background: rgba(255, 255, 255, 0.3);
  left: 0;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.7;
  }
}

/* Skeleton loader styles */
.lazy-load-wrapper.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

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

/* Blur effect while loading */
.lazy-load-wrapper.blur-effect {
  background-color: #e0e0e0;
}

.lazy-load-wrapper.blur-effect img {
  filter: blur(10px);
  transform: scale(1.1);
}

.lazy-load-wrapper.blur-effect img.loaded {
  filter: blur(0);
  transform: scale(1);
  transition: filter 0.5s ease-in-out, transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
}

/* Spinner loader */
.lazy-load-wrapper.spinner::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-top-color: #333;
  border-radius: 50%;
  animation: spinner 0.8s linear infinite;
  z-index: 2;
}

.lazy-load-wrapper.spinner.loaded::after {
  display: none;
}

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

/* Responsive aspect ratio helpers */
.lazy-load-wrapper.aspect-16-9 {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
}

.lazy-load-wrapper.aspect-16-9 img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lazy-load-wrapper.aspect-4-3 {
  position: relative;
  padding-bottom: 75%; /* 4:3 */
  height: 0;
}

.lazy-load-wrapper.aspect-4-3 img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lazy-load-wrapper.aspect-1-1 {
  position: relative;
  padding-bottom: 100%; /* 1:1 */
  height: 0;
}

.lazy-load-wrapper.aspect-1-1 img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Error state */
.lazy-load-wrapper.error {
  background-color: #ffebee;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
}

.lazy-load-wrapper.error::before {
  display: none;
}

.lazy-load-wrapper.error::after {
  content: '⚠ Failed to load image';
  color: #c62828;
  font-size: 14px;
  text-align: center;
  padding: 20px;
}
