/**
 * Preloader CSS - Hybrid Version
 * Combines V1 performance optimizations with V2 features
 * Bug-free implementation with GPU acceleration
 */

/* ========================================
   PRELOADER CONTAINER
   ======================================== */

#preloader {
    /* Positioning */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;

    /* Layout */
    display: flex;
    justify-content: center;
    align-items: center;

    /* Styling - Using CSS custom properties for dynamic colors */
    background-color: var(--preloader-background-color, rgba(180, 180, 180, 0.9));

    /* Backdrop blur with vendor prefix for better browser support */
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);

    /* Transitions */
    opacity: 1;
    transition: opacity 0.5s ease-out;

    /* Performance optimization - GPU acceleration */
    will-change: opacity;
    transform: translateZ(0);
}

/* ========================================
   HIDDEN STATE
   ======================================== */

#preloader.hidden {
    opacity: 0;
    pointer-events: none;
    /* Note: display: none is set via JavaScript after transition */
}

/* ========================================
   LOADER BASE STYLES
   ======================================== */

.loader {
    /* Performance optimization */
    will-change: transform;
    transform: translateZ(0);

    /* Custom image support */
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* ========================================
   ANIMATION TYPE: SPIN (Rotating Circle)
   ======================================== */

.loader.spin {
    width: 60px;
    height: 60px;
    border: 8px solid transparent;
    border-top: 8px solid var(--preloader-loader-color, #3498db);
    border-radius: 50%;
    animation: preloader-spin 2s linear infinite;
}

@keyframes preloader-spin {
    0% {
        transform: rotate(0deg) translateZ(0);
    }
    100% {
        transform: rotate(360deg) translateZ(0);
    }
}

/* ========================================
   ANIMATION TYPE: ZOOM (Pulsing Effect)
   ======================================== */

.loader.zoom {
    width: 60px;
    height: 60px;
    /* Default circle for zoom animation */
    border-radius: 50%;
    background-color: var(--preloader-loader-color, #3498db);
    animation: preloader-zoom 1.5s ease-in-out infinite;
}

/* When custom image is used with zoom, remove background color */
.loader.zoom[style*="background-image"] {
    background-color: transparent;
}

@keyframes preloader-zoom {
    0% {
        transform: scale(1) translateZ(0);
    }
    50% {
        transform: scale(0.8) translateZ(0);
    }
    100% {
        transform: scale(1) translateZ(0);
    }
}

/* ========================================
   ANIMATION TYPE: BAR (Progress Bar)
   ======================================== */

.loader.bar {
    width: 80%;
    max-width: 400px;
    height: 20px;
    background: #f3f3f3;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}

.loader.bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--preloader-loader-color, #3498db);
    animation: preloader-loading 2s linear infinite;

    /* Performance optimization */
    will-change: left;
}

@keyframes preloader-loading {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* ========================================
   SCROLL BLOCKING
   ======================================== */

body.no-scroll {
    overflow: hidden;
    /* Prevent scroll on mobile webkit browsers */
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
    #preloader {
        transition: opacity 0.01ms;
    }

    .loader.spin,
    .loader.zoom,
    .loader.bar::after {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
    }
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 768px) {
    .loader.spin,
    .loader.zoom {
        width: 50px;
        height: 50px;
    }

    .loader.bar {
        width: 90%;
        max-width: 300px;
        height: 16px;
    }
}

@media (max-width: 480px) {
    .loader.spin,
    .loader.zoom {
        width: 40px;
        height: 40px;
        border-width: 6px; /* For spin animation */
    }

    .loader.spin {
        border-width: 6px;
    }

    .loader.bar {
        width: 95%;
        max-width: 250px;
        height: 14px;
    }
}

/* ========================================
   HIGH DPI DISPLAYS
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure crisp rendering on retina displays */
    #preloader {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    #preloader {
        display: none !important;
    }
}
