/**
 * Loading States & Skeletons
 * Skeleton loaders, loading indicators, and progressive image loading
 * 
 * @package Modeo
 * @since 1.0.0
 */

/* ========================================
   Skeleton Loaders
   ======================================== */

.modeo-product-card-skeleton {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    padding: 1rem;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.skeleton-image,
.skeleton-content,
.skeleton-brand,
.skeleton-title,
.skeleton-price,
.skeleton-button {
    background: linear-gradient(
        90deg,
        #f3f4f6 0%,
        #e5e7eb 50%,
        #f3f4f6 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

/* Product card skeleton specific */
.modeo-product-card-skeleton .skeleton-image {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.modeo-product-card-skeleton .skeleton-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ========================================
   Loading Indicators
   ======================================== */

.modeo-loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f4f6;
    border-top-color: #cc1616;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.modeo-loading-spinner--small {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.modeo-loading-spinner--large {
    width: 40px;
    height: 40px;
    border-width: 4px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Loading overlay */
.modeo-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: inherit;
}

.modeo-loading-overlay--dark {
    background: rgba(0, 0, 0, 0.7);
}

/* Loading button state */
.button.loading,
.single_add_to_cart_button.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.button.loading::after,
.single_add_to_cart_button.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Filters loading */
.modeo-filters-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.modeo-filters-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f4f6;
    border-top-color: #cc1616;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 10;
}

/* ========================================
   Progressive Image Loading (Blur-up)
   ======================================== */

.modeo-image-blur-up {
    position: relative;
    overflow: hidden;
}

.modeo-image-blur-up img {
    transition: opacity 0.3s ease-in-out;
}

.modeo-image-blur-up img[data-loaded="false"] {
    opacity: 0;
}

.modeo-image-blur-up img[data-loaded="true"] {
    opacity: 1;
}

/* Blur placeholder */
.modeo-image-blur-up::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f3f4f6;
    background-size: cover;
    background-position: center;
    filter: blur(20px);
    transform: scale(1.1);
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
    z-index: 1;
}

.modeo-image-blur-up img[data-loaded="true"] ~ ::before {
    opacity: 0;
}

.modeo-image-blur-up img {
    position: relative;
    z-index: 2;
}

/* ========================================
   Product Grid Loading State
   ======================================== */

.modeo-products-loading {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 2rem 0;
}

@media (max-width: 768px) {
    .modeo-products-loading {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

/* ========================================
   Add to Cart Loading
   ======================================== */

.add-to-cart-loading {
    position: relative;
}

.add-to-cart-loading .button {
    position: relative;
    color: transparent !important;
}

.add-to-cart-loading .button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Success state */
.add-to-cart-success .button {
    background-color: #10b981 !important;
    color: #ffffff !important;
}

.add-to-cart-success .button::before {
    content: '✓';
    margin-right: 0.5rem;
}

/* ========================================
   Accessibility
   ======================================== */

.modeo-loading-spinner[aria-hidden="true"],
.modeo-product-card-skeleton[aria-hidden="true"] {
    /* Screen readers will skip these */
}

/* Loading text for screen readers */
.modeo-loading-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

