/* ==========================================================================
   M4H SKELETON LOADING SYSTEM
   Modem, lightweight skeleton screen animation for WooCommerce & Flatsome
   ========================================================================== */

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

@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.65;
    }
}

/* Image-only skeleton. Content, header and page navigation always render
   normally; native lazy loading decides when each image is requested. */
html.m4h-skeleton-enabled img.m4h-lazy-image {
    background: #111111 linear-gradient(90deg, #111111 0%, #242424 20%, #3b3b3b 50%, #242424 80%, #111111 100%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.2s cubic-bezier(0.4, 0, 0.6, 1) infinite, skeleton-pulse 1.8s ease-in-out infinite;
}

html.m4h-skeleton-enabled img.m4h-lazy-image--loaded {
    animation: none;
    background: transparent;
}

.skeleton-shimmer,
.skeleton-box,
.skeleton-img,
.skeleton-thumb,
.skeleton-text,
.skeleton-title,
.skeleton-btn,
.is-loading-skeleton {
    background: #e2e8f0 linear-gradient(90deg, #e2e8f0 0%, #cbd5e1 20%, #ffffff 50%, #cbd5e1 80%, #e2e8f0 100%) !important;
    background-size: 200% 100% !important;
    animation: skeleton-shimmer 1.2s cubic-bezier(0.4, 0, 0.6, 1) infinite, skeleton-pulse 1.8s ease-in-out infinite !important;
    color: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    user-select: none !important;
    pointer-events: none !important;
    border-radius: 8px !important;
}

/* Specific Skeleton Components */
.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 100%;
}
.skeleton-text.short {
    width: 60%;
}
.skeleton-title {
    height: 22px;
    margin-bottom: 12px;
    width: 80%;
}
.skeleton-img {
    min-height: 200px;
    width: 100%;
    display: block;
}

/* Skeleton Product Card Placeholder */
.skeleton-product-card {
    background: #fff;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #f1f1f1;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.skeleton-product-card .skeleton-thumb {
    width: 100%;
    height: 220px;
    border-radius: 6px;
    margin-bottom: 12px;
}
.skeleton-product-card .skeleton-meta {
    padding: 4px 0;
}

/* Skeleton Single Product Page */
.skeleton-single-product-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    margin-bottom: 40px;
}
.skeleton-single-gallery {
    flex: 1 1 500px;
    min-height: 450px;
    border-radius: 8px;
}
.skeleton-single-summary {
    flex: 1 1 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Smooth Fade out when image/content is loaded */
img.lazyloading,
img[data-lazy-src] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}
img.lazyloaded,
img.is-loaded {
    opacity: 1 !important;
}

/* Skeleton Container overlay before page interactive */
#m4h-page-skeleton-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff;
    z-index: 999999;
    opacity: 1;
    transition: opacity 0.4s ease-out, visibility 0.4s ease-out;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 40px;
}
#m4h-page-skeleton-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.m4h-skeleton-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 15px;
}
.m4h-skeleton-logo {
    width: 140px;
    height: 40px;
}
.m4h-skeleton-nav {
    flex: 1;
    height: 20px;
    max-width: 500px;
}
.m4h-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-top: 30px;
}
@media (max-width: 768px) {
    .m4h-skeleton-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Shared AJAX Load More button */
.m4h-loadmore-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 28px 0 36px;
}

.m4h-loadmore-btn {
    display: inline-flex;
    min-width: 208px;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 10px 22px;
    border: 1px solid #d9261c;
    border-radius: 999px;
    background: #ffffff;
    color: #d9261c;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.2;
    box-shadow: 0 5px 14px rgba(217, 38, 28, 0.12);
    cursor: pointer;
    transition: transform .2s ease, background-color .2s ease, color .2s ease, box-shadow .2s ease;
}

.m4h-loadmore-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background: #d9261c;
    color: #ffffff;
    box-shadow: 0 9px 20px rgba(217, 38, 28, 0.25);
}

.m4h-loadmore-btn:focus-visible {
    outline: 3px solid rgba(217, 38, 28, .25);
    outline-offset: 3px;
}

.m4h-loadmore-btn:disabled { cursor: wait; }

.m4h-loadmore-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: m4h-loadmore-spin .65s linear infinite;
}

.m4h-loadmore-btn.is-loading .m4h-loadmore-spinner { display: inline-block; }

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

/* Keep AJAX placeholders aligned with every Flatsome product grid. */
.products > .skeleton-temp-item { display: flex; margin-bottom: 18px; }
.products > .skeleton-temp-item .skeleton-product-card { width: 100%; }

@media (max-width: 549px) {
    .m4h-loadmore-wrapper { margin: 20px 0 28px; }
    .m4h-loadmore-btn { min-width: 190px; min-height: 44px; font-size: 13px; }
    .skeleton-product-card { padding: 8px; }
    .skeleton-product-card .skeleton-thumb { height: 165px; margin-bottom: 9px; }
    .skeleton-title { height: 16px; margin-bottom: 8px; }
    .skeleton-text { height: 11px; margin-bottom: 6px; }
}

/* Site-wide route transition skeleton. It runs during route transitions & page loads. */
#m4h-route-skeleton {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    display: none;
    padding: 18px clamp(16px, 5vw, 64px);
    background: #ffffff;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html.m4h-route-loading #m4h-route-skeleton {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

html.m4h-route-hiding #m4h-route-skeleton {
    display: block !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.m4h-route-skeleton-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding-bottom: 14px;
    border-bottom: 1px solid #edf0f4;
}

.m4h-route-skeleton-logo { width: 104px; height: 28px; }
.m4h-route-skeleton-action { width: 36px; height: 28px; }

.m4h-route-skeleton-content {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    max-width: 1100px;
    margin: 32px auto 0;
}

.m4h-route-skeleton-card {
    min-height: 230px;
    padding: 12px;
    border: 1px solid #eef1f4;
    border-radius: 12px;
    background: #fff;
}

.m4h-route-skeleton-card .skeleton-thumb { height: 155px; margin-bottom: 14px; }

@media (max-width: 549px) {
    #m4h-route-skeleton { padding: 12px 14px; }
    .m4h-route-skeleton-content { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
    .m4h-route-skeleton-card { min-height: 185px; padding: 8px; }
    .m4h-route-skeleton-card .skeleton-thumb { height: 115px; margin-bottom: 10px; }
}
