/* ================================================
   Skeleton Loader & Page Transition System
   ================================================ */

/* --- Skeleton Loading Animations --- */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }

    100% {
        background-position: 1000px 0;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Skeleton Base Styles --- */
.skeleton {
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 2000px 100%;
    animation: shimmer 1s infinite linear;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.skeleton::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(255, 255, 255, 0.6) 50%,
            transparent 100%);
}

/* --- Skeleton Component Variants --- */
.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.large {
    height: 24px;
}

.skeleton-text.small {
    height: 12px;
}

.skeleton-title {
    height: 32px;
    width: 60%;
    margin-bottom: 16px;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    padding-bottom: 100%;
    /* Square aspect ratio */
    border-radius: 8px;
}

.skeleton-image.rect {
    padding-bottom: 66.67%;
    /* 3:2 aspect ratio */
}

.skeleton-card {
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 16px;
}

.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: 0;
    /* Square per design system */
}

/* --- Product Grid Skeleton --- */
.skeleton-product {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 24px;
    padding: 24px 0;
}

.skeleton-product-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.skeleton-product-card .skeleton-image {
    margin-bottom: 16px;
}

.skeleton-product-card .skeleton-text {
    margin-bottom: 12px;
}

/* --- Header Skeleton --- */
.skeleton-header {
    height: 80px;
    background: white;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
}

.skeleton-logo {
    width: 150px;
    height: 40px;
    border-radius: 0;
}

.skeleton-search {
    flex: 1;
    height: 44px;
    max-width: 500px;
    border-radius: 0;
}

/* --- Page Transition Overlay --- */
.page-transition-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.page-transition-overlay.active {
    display: flex;
}

.page-transition-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f0f0f0;
    border-top: 4px solid var(--theme-color, #ff6f00);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Content Fade In --- */
.content-loaded {
    animation: fadeIn 0.25s ease-out;
    /* Faster: 0.25s instead of 0.4s */
}

.content-loaded.slide {
    animation: slideDown 0.3s ease-out;
    /* Faster: 0.3s instead of 0.5s */
}

/* --- Loading State Class --- */
body.loading {
    overflow: hidden;
}

body.loading .page-transition-overlay {
    display: flex;
}

/* --- Hide Content During Initial Load --- */
.loading-initial .main-content,
.loading-initial section {
    opacity: 0;
}

.loaded .main-content,
.loaded section {
    animation: fadeIn 0.35s ease-out forwards;
    /* Faster: 0.35s instead of 0.6s */
}

/* --- Skeleton Dark Mode Support --- */
@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg,
                #2a2a2a 0%,
                #3a3a3a 20%,
                #2a2a2a 40%,
                #2a2a2a 100%);
    }

    .page-transition-overlay {
        background: rgba(0, 0, 0, 0.95);
    }
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .skeleton-product {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 16px;
    }

    .skeleton-header {
        height: 60px;
    }
}

/* --- Accessibility: Respect Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {

    .skeleton,
    .content-loaded,
    .page-transition-spinner {
        animation: none;
    }

    .content-loaded {
        opacity: 1;
        transform: none;
    }
}