/**
 * LOD (Level of Detail) Styles
 * CSS for progressive image and video loading
 */

/* ===== IMAGE LOD STYLES ===== */

.lod-image {
  width: 100%;
  height: auto;
  display: block;
  transition: filter 0.3s ease-in-out, opacity 0.3s ease-in-out;
}

/* Blur effect for thumbnail placeholder */
.lod-image.blur-placeholder {
  filter: blur(10px);
  transform: scale(1.05); /* Slightly scale to hide blur edges */
}

/* Loading state */
.lod-image.loading {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  min-height: 200px;
}

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

/* Quality indicators (optional, for debugging) */
.lod-image.low-quality {
  /* Quality level: Low */
  opacity: 1;
}

.lod-image.medium-quality {
  /* Quality level: Medium */
  opacity: 1;
}

.lod-image.high-quality {
  /* Full quality loaded */
  filter: none;
  transform: none;
}

/* ===== VIDEO LOD STYLES ===== */

.lod-video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.lod-video {
  width: 100%;
  height: auto;
  display: block;
  background: #000;
}

/* Video quality selector */
.quality-selector {
  position: absolute;
  bottom: 60px;
  right: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  outline: none;
  transition: background 0.2s ease;
  z-index: 10;
}

/* Quality selector in post detail modal */
.post-detail-container .quality-selector {
  position: absolute;
  top: 20px;
  left: 60px;
  bottom: auto;
  right: auto;
  z-index: 1000;
}

.quality-selector:hover {
  background: rgba(0, 0, 0, 0.95);
}

.quality-selector:focus {
  border-color: rgba(255, 255, 255, 0.5);
}

.quality-selector option {
  background: #1a1a1a;
  color: white;
}

/* Loading spinner for videos */
.lod-video-wrapper::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 5;
}

.lod-video-wrapper.loading::before {
  opacity: 1;
}

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

/* ===== POST FEED STYLES ===== */

.post-item {
  margin-bottom: 20px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
}

.post-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Responsive media container */
.post-media {
  position: relative;
  width: 100%;
  max-height: 600px;
  overflow: hidden;
  background: #f5f5f5;
}

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

@media (max-width: 768px) {
  .quality-selector {
    bottom: 50px;
    right: 8px;
    font-size: 11px;
    padding: 4px 8px;
  }

  .lod-image.loading {
    min-height: 150px;
  }

  .post-media {
    max-height: 500px;
  }
}

/* ===== PERFORMANCE HINTS ===== */

/* Use GPU acceleration for smooth transitions */
.lod-image,
.lod-video {
  will-change: filter, opacity;
}

/* Prevent layout shift during loading */
.lod-image,
.lod-video {
  aspect-ratio: 1 / 1; /* Adjust based on your needs */
}

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

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .lod-image,
  .lod-video,
  .quality-selector {
    transition: none;
    animation: none;
  }

  .lod-image.blur-placeholder {
    filter: none;
    opacity: 0.5;
  }
}

/* Focus indicators for keyboard navigation */
.quality-selector:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* ===== QUALITY BADGE (OPTIONAL) ===== */

/* Add a subtle quality indicator badge */
.lod-video-wrapper[data-quality]::after,
.lod-image[data-quality]::after {
  content: attr(data-quality);
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.lod-video-wrapper:hover[data-quality]::after,
.lod-image:hover[data-quality]::after {
  opacity: 1;
}

/* ===== NETWORK STATUS INDICATORS ===== */

/* Show different indicators based on loading state */
.lod-image[data-network-speed="slow"]::before {
  content: '🐌';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 20px;
}

.lod-image[data-network-speed="fast"]::before {
  content: '⚡';
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 20px;
}

/* ===== DARK MODE SUPPORT ===== */

@media (prefers-color-scheme: dark) {
  .post-item {
    background: #1a1a1a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .post-media {
    background: #0a0a0a;
  }

  .lod-image.loading {
    background: linear-gradient(90deg, #2a2a2a 25%, #1a1a1a 50%, #2a2a2a 75%);
    background-size: 200% 100%;
  }
}

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

/* Force immediate high quality (for featured posts, etc.) */
.lod-force-high .lod-image,
.lod-force-high .lod-video {
  filter: none;
  opacity: 1;
}

/* Disable LOD for specific posts */
.lod-disabled .lod-image,
.lod-disabled .lod-video {
  filter: none !important;
  transition: none !important;
}

/* Error state */
.lod-error {
  position: relative;
  min-height: 200px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lod-error::before {
  content: '⚠️ Failed to load media';
  color: #666;
  font-size: 14px;
}

/* ===== INTERSECTION OBSERVER FADE-IN ===== */

.lod-fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.lod-fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}
