/* Performance Optimizations - Mesa Santos Coffee Theme */
/* GPU-accelerated animations and render optimization */

/* ========================================
   CRITICAL RENDERING PATH
   ======================================== */

/* 
 * Font Loading Optimization
 * Fonts are loaded via Google Fonts in functions.php with:
 * - font-display: swap
 * - Preconnect hints
 * See: wp_enqueue_style('mesa-santos-fonts', ...)
 */

/* ========================================
   GPU ACCELERATION
   ======================================== */

/* Force GPU compositing for animated elements */
.site-header,
.hero-section,
.hero-content,
.hero-product,
.hero-background {
    will-change: transform;
    transform: translateZ(0);
}

/* Product and interactive elements */
.product-card,
.variety-circle,
.btn,
.nav-menu li a,
.cart-icon,
.scroll-to-top {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Cursor elements */
.custom-cursor,
.custom-cursor-follower,
.cursor-trail {
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform;
}

/* ========================================
   CONTAIN PROPERTY - Layout Optimization
   ======================================== */

/* Strict containment for independent components */
.product-card,
.variety-item,
.info-item,
.stat-item,
.testimonial-slide,
.footer-section {
    contain: layout style paint;
}

/* Content containment for sections */
.featured-products,
.varieties-section,
.info-section,
.newsletter-section,
.stats-section {
    contain: layout style;
}

/* Strict containment for utility elements */
.scroll-progress-bar,
.scroll-to-top,
.preloader {
    contain: strict;
}

/* ========================================
   CONTENT VISIBILITY - Render Optimization
   ======================================== */

/* Auto-render for off-screen content */
.product-image img,
.hero-product img,
.info-item img,
.variety-circle {
    content-visibility: auto;
    contain-intrinsic-size: 300px;
}

/* Below-fold sections */
.newsletter-section,
.stats-section,
.site-footer {
    content-visibility: auto;
    contain-intrinsic-size: 400px;
}

/* ========================================
   IMAGE OPTIMIZATION
   ======================================== */

img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Lazy load placeholders */
img[data-src] {
    background: linear-gradient(90deg,
            var(--color-accent) 0%,
            var(--color-accent-dark) 50%,
            var(--color-accent) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

img.loaded {
    animation: imageLoad 0.5s ease forwards;
}

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

    100% {
        background-position: -200% 0;
    }
}

@keyframes imageLoad {
    from {
        opacity: 0;
        filter: blur(10px);
    }

    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* ========================================
   SKELETON LOADING STATES
   ======================================== */

.skeleton {
    background: linear-gradient(90deg,
            var(--color-accent) 25%,
            var(--color-accent-dark) 50%,
            var(--color-accent) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 10px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-title {
    height: 28px;
    width: 60%;
    margin-bottom: 16px;
    border-radius: 4px;
}

.skeleton-image {
    height: 300px;
    width: 100%;
    border-radius: 15px;
}

.skeleton-circle {
    width: 150px;
    height: 150px;
    border-radius: 50%;
}

.skeleton-button {
    height: 50px;
    width: 180px;
    border-radius: 25px;
}

/* ========================================
   REDUCED MOTION SUPPORT
   ======================================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Disable complex effects */
    .custom-cursor,
    .custom-cursor-follower,
    .cursor-trail,
    .parallax-layer {
        display: none !important;
    }

    /* Reset transforms */
    .product-card:hover,
    .variety-circle:hover,
    .btn:hover {
        transform: none !important;
    }

    /* Ensure visibility */
    .animate-on-scroll,
    .section-reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ========================================
   PERFORMANCE MODE (Low FPS Detection)
   ======================================== */

body.reduced-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

body.reduced-motion .custom-cursor,
body.reduced-motion .custom-cursor-follower,
body.reduced-motion .cursor-trail,
body.reduced-motion .parallax-layer {
    display: none !important;
}

/* ========================================
   POINTER DEVICE DETECTION
   ======================================== */

/* Fine pointer (mouse) */
@media (hover: hover) and (pointer: fine) {

    .custom-cursor,
    .custom-cursor-follower {
        display: block;
    }

    /* Enable hover effects */
    .product-card,
    .variety-circle,
    .btn {
        cursor: pointer;
    }
}

/* Coarse pointer (touch) - Disable cursor */
@media (hover: none) or (pointer: coarse) {

    .custom-cursor,
    .custom-cursor-follower,
    .cursor-trail {
        display: none !important;
    }

    body.custom-cursor-active,
    body.custom-cursor-active * {
        cursor: auto !important;
    }

    /* Reduce animation complexity on touch */
    .product-card:hover {
        transform: translateY(-10px);
    }

    .variety-circle:hover {
        transform: scale(1.05);
    }
}

/* ========================================
   OPTIMIZED TRANSITIONS
   ======================================== */

/* Use transform instead of top/left */
.product-card,
.btn,
.variety-circle,
.nav-menu li a {
    transition-property: transform, opacity, box-shadow;
    transition-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}

/* Hardware-accelerated transforms */
@supports (transform: translate3d(0, 0, 0)) {
    .product-card:hover {
        transform: translate3d(0, -20px, 0) scale(1.03);
    }

    .btn:hover {
        transform: translate3d(0, -4px, 0);
    }

    .variety-circle:hover {
        transform: translate3d(0, -10px, 0) scale(1.15);
    }
}

/* ========================================
   PAINT WORKLET OPTIMIZATION
   ======================================== */

/* Optimize paint for gradients */
.hero-background,
.featured-products,
.newsletter-section {
    isolation: isolate;
}

/* ========================================
   SCROLL OPTIMIZATION
   ======================================== */

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Optimize scroll containers */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Scrolling state optimization */
body.is-scrolling .custom-cursor-follower {
    opacity: 0.3;
    transition: opacity 0.1s;
}

body.is-scrolling .parallax-layer {
    will-change: transform;
}

/* ========================================
   LAYER PROMOTION
   ======================================== */

/* Force layer promotion for animated elements */
.page-enter,
.page-exit,
.quick-view-modal,
.preloader {
    will-change: opacity, transform;
}

/* Remove will-change after animation */
.page-loaded .hero-section,
.page-loaded .hero-content {
    will-change: auto;
}

/* ========================================
   FONT OPTIMIZATION
   ======================================== */

/* Prevent FOUT/FOIT */
.fonts-loading body {
    font-display: block;
}

.fonts-loaded body {
    font-display: swap;
}

/* ========================================
   CSS LAYERS (Modern browsers)
   ======================================== */

@layer base, utilities, components, animations;

/* ========================================
   PRINT OPTIMIZATION
   ======================================== */

@media print {

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }

    .custom-cursor,
    .custom-cursor-follower,
    .cursor-trail,
    .scroll-to-top,
    .scroll-progress-bar,
    .preloader {
        display: none !important;
    }

    .animate-on-scroll,
    .section-reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ========================================
   MEMORY OPTIMIZATION
   ======================================== */

/* Limit animation count */
.cursor-trail {
    pointer-events: none;
}

/* Clean up old trails */
.cursor-trail:nth-child(n+20) {
    display: none;
}

/* ========================================
   CRITICAL PATH ABOVE FOLD
   ======================================== */

/* Ensure above-fold content renders first */
.site-header {
    z-index: 1000;
    position: fixed;
}

.hero-section {
    z-index: 1;
}

/* Defer non-critical animations */
.site-footer,
.newsletter-section {
    animation-play-state: paused;
}

.site-footer.visible,
.newsletter-section.visible {
    animation-play-state: running;
}