/* Preloader Styles */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--base-background);
    z-index: 99999999 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

.preloader-content {
    text-align: center;
    color: var(--light);
    max-width: 300px;
    padding: 20px;
}

.preloader-spinner {
    width: 80px;
    height: 80px;
    border: 4px solid var(--card-background);
    border-top: 4px solid var(--base-color);
    border-right: 4px solid var(--hover-color);
    border-radius: 50%;
    animation: spin 1.2s linear infinite;
    margin: 0 auto 30px;
    position: relative;
}

.preloader-spinner::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border: 2px solid transparent;
    border-top: 2px solid var(--base-color-lighter);
    border-radius: 50%;
    animation: spin 2s linear infinite reverse;
}

.preloader-text {
    font-family: var(--font-primary);
    font-size: 24px;
    font-weight: 700;
    color: var(--light);
    margin-bottom: 15px;
    animation: textFade 2s ease-in-out infinite;
    letter-spacing: 0.5px;
}

.preloader-subtext {
    font-family: var(--font-primary);
    font-size: 16px;
    color: var(--greyish);
    animation: textFade 2s ease-in-out infinite 0.5s;
    margin-bottom: 25px;
    font-weight: 400;
}

.preloader-dots {
    display: inline-block;
    margin-left: 5px;
}

.preloader-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

/* Loading bar */
.preloader-bar {
    width: 250px;
    height: 6px;
    background: var(--card-background);
    border-radius: 3px;
    margin: 0 auto 15px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.preloader-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--base-color), var(--hover-color), var(--base-color));
    background-size: 200% 100%;
    border-radius: 3px;
    width: 0%;
    animation: barShimmer 2s ease-in-out infinite;
    position: relative;
    transition: width 0.3s ease-out;
}

.preloader-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: barGlow 1.5s ease-in-out infinite;
}

/* Progress percentage */
.preloader-progress {
    font-family: var(--font-primary);
    font-size: 14px;
    color: var(--base-color);
    font-weight: 600;
    animation: textFade 2s ease-in-out infinite 1s;
}

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

@keyframes textFade {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}


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

@keyframes barGlow {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* Light theme adjustments */
:root[data-theme="light"] .preloader {
    background: var(--base-background);
}

:root[data-theme="light"] .preloader-text {
    color: var(--text-color);
}

:root[data-theme="light"] .preloader-subtext {
    color: var(--lighter-light);
}

:root[data-theme="light"] .preloader-progress {
    color: var(--lighter-light);
}

/* Responsive design */
@media (max-width: 768px) {
    .preloader-spinner {
        width: 60px;
        height: 60px;
    }
    
    .preloader-text {
        font-size: 20px;
    }
    
    .preloader-subtext {
        font-size: 14px;
    }
    
    .preloader-bar {
        width: 200px;
    }
    
    .preloader-content {
        max-width: 250px;
        padding: 15px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .preloader-spinner,
    .preloader-text,
    .preloader-subtext,
    .preloader-progress,
    .preloader-bar-fill {
        animation: none;
    }
    
    .preloader-spinner::before {
        animation: none;
    }
    
    .preloader-bar-fill::after {
        animation: none;
    }
    
    .preloader-dots::after {
        animation: none;
        content: '...';
    }
  }