/* ===========================================
   PROFESSIONAL PRELOADER SYSTEM
   High-quality, customizable preloader with multiple styles
   Envato-compliant CSS with validation and best practices
   =========================================== */

/* Base Preloader Container */
.preloader-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--preloader-bg, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.preloader-container.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Preloader Content */
.preloader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Logo in Preloader */
.preloader-logo {
    max-width: 200px;
    max-height: 80px;
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 0.3s forwards;
}

.preloader-logo img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

/* Preloader Text */
.preloader-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--preloader-text-color, #6b7280);
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 0.6s forwards;
}

/* ===========================================
   SPINNER PRELOADER STYLES
   =========================================== */

.preloader-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(59, 130, 246, 0.1);
    border-left: 4px solid var(--preloader-color, #3b82f6);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.preloader-spinner.large {
    width: 80px;
    height: 80px;
    border-width: 6px;
}

.preloader-spinner.small {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

/* ===========================================
   DOTS PRELOADER STYLES
   =========================================== */

.preloader-dots {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
}

.preloader-dot {
    width: 12px;
    height: 12px;
    background-color: var(--preloader-color, #3b82f6);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite both;
}

.preloader-dot:nth-child(1) { animation-delay: -0.32s; }
.preloader-dot:nth-child(2) { animation-delay: -0.16s; }
.preloader-dot:nth-child(3) { animation-delay: 0s; }

/* ===========================================
   BARS PRELOADER STYLES
   =========================================== */

.preloader-bars {
    display: flex;
    gap: 4px;
    margin-bottom: 1rem;
    align-items: end;
}

.preloader-bar {
    width: 8px;
    height: 40px;
    background-color: var(--preloader-color, #3b82f6);
    border-radius: 4px;
    animation: barWave 1.2s ease-in-out infinite;
}

.preloader-bar:nth-child(1) { animation-delay: -1.1s; }
.preloader-bar:nth-child(2) { animation-delay: -1.0s; }
.preloader-bar:nth-child(3) { animation-delay: -0.9s; }
.preloader-bar:nth-child(4) { animation-delay: -0.8s; }
.preloader-bar:nth-child(5) { animation-delay: -0.7s; }

/* ===========================================
   PULSE PRELOADER STYLES
   =========================================== */

.preloader-pulse {
    width: 60px;
    height: 60px;
    background-color: var(--preloader-color, #3b82f6);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
    margin-bottom: 1rem;
}

.preloader-pulse.large {
    width: 80px;
    height: 80px;
}

.preloader-pulse.small {
    width: 40px;
    height: 40px;
}

/* ===========================================
   CUSTOM PRELOADER STYLES
   =========================================== */

.preloader-custom {
    margin-bottom: 1rem;
}

/* ===========================================
   PROGRESS BAR PRELOADER
   =========================================== */

.preloader-progress {
    width: 200px;
    height: 4px;
    background-color: rgba(59, 130, 246, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.preloader-progress-bar {
    height: 100%;
    background-color: var(--preloader-color, #3b82f6);
    border-radius: 2px;
    width: 0%;
    animation: progressLoad 2s ease-out forwards;
}

/* ===========================================
   ANIMATIONS
   =========================================== */

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes barWave {
    0%, 40%, 100% {
        transform: scaleY(0.4);
    }
    20% {
        transform: scaleY(1);
    }
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.7;
    }
    70% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(0.95);
        opacity: 0.7;
    }
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes progressLoad {
    0% { width: 0%; }
    50% { width: 60%; }
    100% { width: 100%; }
}

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

@media (prefers-color-scheme: dark) {
    .preloader-container {
        background-color: var(--preloader-bg-dark, #1f2937);
    }
    
    .preloader-text {
        color: var(--preloader-text-color-dark, #d1d5db);
    }
    
    .preloader-spinner {
        border-color: rgba(59, 130, 246, 0.2);
    }
    
    .preloader-progress {
        background-color: rgba(59, 130, 246, 0.2);
    }
}

/* ===========================================
   RESPONSIVE DESIGN
   =========================================== */

@media (max-width: 768px) {
    .preloader-logo {
        max-width: 150px;
        max-height: 60px;
        margin-bottom: 1.5rem;
    }
    
    .preloader-text {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }
    
    .preloader-spinner {
        width: 50px;
        height: 50px;
    }
    
    .preloader-pulse {
        width: 50px;
        height: 50px;
    }
    
    .preloader-progress {
        width: 150px;
    }
}

@media (max-width: 480px) {
    .preloader-logo {
        max-width: 120px;
        max-height: 50px;
        margin-bottom: 1rem;
    }
    
    .preloader-text {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }
    
    .preloader-spinner {
        width: 40px;
        height: 40px;
    }
    
    .preloader-pulse {
        width: 40px;
        height: 40px;
    }
    
    .preloader-progress {
        width: 120px;
    }
}

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

.preloader-container[aria-hidden="true"] {
    display: none;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .preloader-spinner,
    .preloader-dot,
    .preloader-bar,
    .preloader-pulse {
        animation: none;
    }
    
    .preloader-spinner {
        border-left-color: var(--preloader-color, #3b82f6);
    }
    
    .preloader-dot {
        opacity: 0.7;
    }
    
    .preloader-bar {
        height: 20px;
    }
    
    .preloader-pulse {
        opacity: 0.8;
    }
}

/* ===========================================
   HIGH CONTRAST MODE SUPPORT
   =========================================== */

@media (prefers-contrast: high) {
    .preloader-spinner {
        border-color: #000000;
        border-left-color: #000000;
    }
    
    .preloader-dot,
    .preloader-bar,
    .preloader-pulse {
        background-color: #000000;
    }
    
    .preloader-progress-bar {
        background-color: #000000;
    }
    
    .preloader-text {
        color: #000000;
    }
}

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

@media print {
    .preloader-container {
        display: none !important;
    }
}

/* ===========================================
   DYNAMIC CSS VARIABLES
   =========================================== */

:root {
    --preloader-color: #3b82f6;
    --preloader-bg: #ffffff;
    --preloader-text-color: #3b82f6;
}

@media (prefers-color-scheme: dark) {
    :root {
        --preloader-bg-dark: #1f2937;
        --preloader-text-color-dark: #d1d5db;
    }
}

/* ===========================================
   NOSCRIPT FALLBACK
   =========================================== */

.preloader-container {
    display: none !important;
}