/**
 * Loading Optimizer CSS - Skeleton Loaders, Loading States, and Animations
 */

/* ============================================
   Page Loader Overlay
   ============================================ */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.loader-content {
    text-align: center;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1e3a5f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.loader-text {
    color: #1e3a5f;
    font-size: 1.1rem;
    font-weight: 600;
}

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

/* ============================================
   Section Loader
   ============================================ */
.section-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 200px;
}

.section-loader .loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #13c296;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================
   Lazy Loading Image Styles
   ============================================ */
.lazy-image-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    overflow: hidden;
}

.lazy-loading {
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.lazy-loaded {
    opacity: 1;
    animation: fadeIn 0.5s ease-in;
}

.lazy-error {
    opacity: 0.5;
    background: #f3f3f3;
}

.lazy-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

/* ============================================
   Skeleton Loaders
   ============================================ */
.skeleton-container {
    position: relative;
    overflow: hidden;
}

.skeleton-loader {
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-shimmer {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0) 0%, 
        rgba(255, 255, 255, 0.3) 50%, 
        rgba(255, 255, 255, 0) 100%);
    animation: shimmer 1.5s infinite;
}

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

/* Skeleton Card */
.skeleton-card {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 1rem;
    position: relative;
    overflow: hidden;
}

.skeleton-content {
    padding: 0.5rem 0;
}

.skeleton-line {
    height: 12px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    position: relative;
    overflow: hidden;
}

.skeleton-line::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.6), 
        transparent);
    animation: shimmer 1.5s infinite;
}

.skeleton-title {
    width: 70%;
    height: 16px;
}

.skeleton-short {
    width: 50%;
}

.skeleton-text {
    padding: 1rem 0;
}

.skeleton-default {
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

/* ============================================
   Progressive Image Loading
   ============================================ */
img[data-progressive] {
    transition: filter 0.3s ease, opacity 0.3s ease;
}

.progressive-loaded {
    filter: blur(0px) !important;
}

/* ============================================
   Fade In Animation
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.6s ease-out;
}

/* ============================================
   Loading States for Buttons
   ============================================ */
.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #ffffff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ============================================
   Loading States for Forms
   ============================================ */
.form-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.form-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Carousel Loading State
   ============================================ */
.carousel-loading {
    position: relative;
    min-height: 400px;
    background: #f0f0f0;
}

.carousel-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1e3a5f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ============================================
   Content Loading States
   ============================================ */
.content-loading {
    position: relative;
    min-height: 200px;
}

.content-loading .skeleton-container {
    padding: 2rem;
}

/* ============================================
   Image Gallery Loading
   ============================================ */
.gallery-loading {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.gallery-loading .skeleton-image {
    aspect-ratio: 1;
    height: auto;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .loader-spinner {
        width: 40px;
        height: 40px;
        border-width: 3px;
    }

    .loader-text {
        font-size: 1rem;
    }

    .skeleton-image {
        height: 150px;
    }

    .skeleton-line {
        height: 10px;
    }
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .skeleton-shimmer,
    .loader-spinner,
    .fade-in {
        animation: none;
    }

    .lazy-loaded {
        animation: none;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .page-loader,
    .section-loader,
    .lazy-placeholder,
    .skeleton-container {
        display: none !important;
    }
}
