/**
 * THUMBNAIL OPTIMIZATION STYLES
 * CSS untuk mendukung lazy loading dan smooth image transitions
 * 
 * CARA PAKAI:
 * Include di header.php atau gabungkan dengan style.css yang ada
 */

/* ============================================
   BASE IMAGE STYLES
   ============================================ */

.lazy-image {
    /* Background saat loading */
    background: linear-gradient(135deg, #0f0a1f 0%, #1a1035 100%);
    
    /* Smooth transition */
    transition: opacity 0.3s ease-in-out, 
                filter 0.3s ease-in-out,
                transform 0.3s ease-in-out;
    
    /* Initial state - hidden & blurred */
    opacity: 0;
    filter: blur(10px);
    
    /* Better rendering */
    will-change: opacity, filter;
    transform: translateZ(0); /* Hardware acceleration */
}

.lazy-image.loaded {
    /* Show image smoothly */
    opacity: 1;
    filter: blur(0);
}

.lazy-image.error {
    /* Error state */
    opacity: 0.7;
    filter: grayscale(50%);
    background: linear-gradient(135deg, #1a1035 0%, #2d1b69 100%);
}

/* ============================================
   SKELETON LOADING
   ============================================ */

.thumb-skeleton {
    background: linear-gradient(
        90deg,
        #0f0a1f 0%,
        #1a1035 20%,
        #2d1b69 40%,
        #1a1035 60%,
        #0f0a1f 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 8px;
}

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

/* Pulse alternative untuk browser yang tidak support gradient animation */
@supports not (animation: shimmer 1.5s ease-in-out infinite) {
    .thumb-skeleton {
        animation: pulse 1.5s ease-in-out infinite;
    }
    
    @keyframes pulse {
        0%, 100% {
            opacity: 1;
        }
        50% {
            opacity: 0.5;
        }
    }
}

/* ============================================
   ASPECT RATIO CONTAINERS
   ============================================ */

.aspect-container {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background: #0f0a1f;
}

/* Default 3:4 Portrait */
.aspect-container::before {
    content: '';
    display: block;
    padding-top: 133.33%; /* 3:4 */
}

/* 16:9 Landscape */
.aspect-container.ratio-16-9::before,
.aspect-container[data-aspect="16-9"]::before {
    padding-top: 56.25%;
}

/* Square 1:1 */
.aspect-container.ratio-square::before,
.aspect-container[data-aspect="square"]::before {
    padding-top: 100%;
}

/* 4:3 Traditional */
.aspect-container.ratio-4-3::before,
.aspect-container[data-aspect="4-3"]::before {
    padding-top: 75%;
}

.aspect-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* ============================================
   PROGRESSIVE ENHANCEMENT
   ============================================ */

/* Blur-up effect untuk progressive loading */
.progressive-image {
    position: relative;
}

.progressive-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: blur(20px);
    transform: scale(1.1);
    transition: opacity 0.5s ease;
}

.progressive-image-placeholder.hidden {
    opacity: 0;
}

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

/* Prevent layout shift */
.mini-card {
    contain: layout style paint;
    will-change: auto;
}

.mini-card:hover {
    will-change: transform;
}

/* Better image rendering */
img.lazy-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

img.lazy-image.loaded {
    image-rendering: auto;
}

/* ============================================
   THUMBNAIL STATES
   ============================================ */

/* Loading state */
.thumb-loading {
    position: relative;
}

.thumb-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Error state dengan icon */
.thumb-error {
    position: relative;
    background: linear-gradient(135deg, #1a1035 0%, #2d1b69 100%);
}

.thumb-error::before {
    content: '⚠';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    color: #ef4444;
    opacity: 0.5;
}

/* ============================================
   RESPONSIVE IMAGES
   ============================================ */

/* Optimasi untuk mobile */
@media (max-width: 768px) {
    .lazy-image {
        /* Reduce blur untuk performa lebih baik di mobile */
        filter: blur(5px);
    }
    
    .lazy-image.loaded {
        filter: blur(0);
    }
    
    /* Disable shimmer animation di mobile jika performance issue */
    .thumb-skeleton {
        animation-duration: 2s;
    }
}

/* Optimasi untuk tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .lazy-image {
        filter: blur(8px);
    }
}

/* ============================================
   HOVER EFFECTS
   ============================================ */

.mini-card .lazy-image {
    transition: opacity 0.3s ease-in-out, 
                filter 0.3s ease-in-out,
                transform 0.3s ease;
}

.mini-card:hover .lazy-image.loaded {
    transform: scale(1.05);
}

/* Disable hover effect di touch devices */
@media (hover: none) and (pointer: coarse) {
    .mini-card:hover .lazy-image.loaded {
        transform: none;
    }
}

/* ============================================
   GRID LAYOUT OPTIMIZATION
   ============================================ */

/* Prevent grid layout shift */
.content-grid {
    display: grid;
    gap: 1rem;
}

.content-grid .mini-card {
    min-height: 0; /* Prevent overflow */
}

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

/* Focus styles untuk keyboard navigation */
.mini-card:focus-within .lazy-image {
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

/* Reduced motion untuk users yang prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .thumb-skeleton,
    .progressive-image-placeholder {
        animation: none !important;
        transition: none !important;
    }
    
    .lazy-image.loaded {
        opacity: 1;
        filter: none;
    }
}

/* ============================================
   DARK MODE ADJUSTMENTS
   ============================================ */

@media (prefers-color-scheme: dark) {
    .thumb-skeleton {
        background: linear-gradient(
            90deg,
            #050208 0%,
            #0f0a1f 20%,
            #1a1035 40%,
            #0f0a1f 60%,
            #050208 100%
        );
    }
}

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

@media print {
    .lazy-image,
    .thumb-skeleton {
        animation: none;
        filter: none;
        opacity: 1;
    }
    
    .lazy-image[data-src] {
        /* Ensure images are visible when printing */
        display: block;
    }
}

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

/* Force immediate load */
.thumb-eager {
    opacity: 1 !important;
    filter: none !important;
}

/* Hide thumbnails temporarily */
.thumb-hidden {
    visibility: hidden;
}

/* Thumbnail with overlay (untuk video thumbnails) */
.thumb-with-overlay {
    position: relative;
}

.thumb-with-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.5) 100%);
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.thumb-with-overlay:hover::after {
    opacity: 0.7;
}

/* ============================================
   CRITICAL CSS (Above-the-fold)
   ============================================ */

/* Styles yang perlu dimuat di <head> untuk above-the-fold */
.critical-thumb {
    display: block;
    width: 100%;
    height: auto;
    background: #0f0a1f;
}

/* ============================================
   DEBUGGING CLASSES (Remove in production)
   ============================================ */

.debug-loading .lazy-image::before {
    content: 'LOADING';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #6366f1;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
}

.debug-loading .lazy-image.loaded::before {
    content: 'LOADED';
    color: #10b981;
}

.debug-loading .lazy-image.error::before {
    content: 'ERROR';
    color: #ef4444;
}
