/* Performance Optimizations for Smoother Animations */

/* === CRITICAL PERFORMANCE ENHANCEMENTS === */

/* Hardware Acceleration for All Animated Elements */
#mainNav,
.navbar-particles,
.nav-link,
.navbar-brand,
.footer,
.footer-bg-shapes,
.footer-particles,
.section-title-wrapper,
.floating-shapes,
.particles-container,
.shape,
.particle,
.social-link,
.animated-underline,
.section-divider-3d {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    perspective: 1000px;
    -webkit-perspective: 1000px;
}

/* Optimize Specific Animated Properties */
.navbar-brand::before,
.nav-link::before,
.nav-link::after,
.footer-wave-top svg,
.divider-bar,
.brand-text {
    will-change: opacity, transform;
}

/* CSS Containment for Performance */
#mainNav {
    contain: layout style paint;
}

.footer {
    contain: layout style paint;
}

.section-title-wrapper {
    contain: layout style;
}

/* Reduce Motion Complexity on Lower-End Devices */
@media (prefers-reduced-motion: no-preference) {
    /* Keep animations but optimize them */
    * {
        animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1) !important;
    }
}

/* Mobile Performance Optimizations */
@media (max-width: 768px) {
    /* Simplify complex animations on mobile */
    .navbar-particle,
    .footer-particle,
    .particle {
        animation-duration: 4s !important; /* Faster = less processing */
    }
    
    /* Reduce blur effects (expensive on mobile) */
    #mainNav {
        backdrop-filter: none;
    }
    
    .navbar-collapse {
        backdrop-filter: none;
        background: rgba(0, 0, 0, 0.98) !important;
    }
    
    /* Simplify gradients on mobile */
    .footer-divider,
    .section-divider-3d .divider-bar,
    .nav-link::after {
        background: #E10600 !important;
    }
    
    /* Collaborate section divider stays black on mobile */
    #collaborate .section-divider-3d .divider-bar {
        background: #000000 !important;
    }
    
    /* Disable expensive filters on mobile */
    .navbar-brand img,
    .footer-shape-pyramid,
    .shape-pyramid {
        filter: none;
    }
    
    /* Reduce shadow complexity */
    .social-link:hover,
    .btn:hover,
    .navbar-toggler:hover {
        box-shadow: 0 5px 15px rgba(225, 6, 0, 0.3) !important;
    }
}

/* Very Small Devices - Maximum Performance */
@media (max-width: 480px) {
    /* Disable non-critical animations */
    .navbar-particle,
    .footer-particle:nth-child(n+6) {
        display: none !important;
    }
    
    /* Simplify 3D transforms to 2D */
    .navbar-brand:hover,
    .nav-link:hover,
    .social-link:hover {
        transform: translateY(-3px) !important;
    }
    
    /* Remove expensive background animations */
    #mainNav::before,
    .footer-grid-pattern {
        display: none !important;
    }
    
    /* Disable multiple shape animations */
    .footer-circle-1,
    .footer-circle-2,
    .footer-shape-box,
    .footer-shape-triangle,
    .footer-shape-diamond {
        display: none !important;
    }
}

/* Optimize Animation Performance */
@keyframes optimizedFloat {
    0%, 100% { transform: translate3d(0, 0, 0); }
    50% { transform: translate3d(0, -20px, 0); }
}

@keyframes optimizedRotate {
    from { transform: rotate3d(0, 0, 1, 0deg); }
    to { transform: rotate3d(0, 0, 1, 360deg); }
}

@keyframes optimizedPulse {
    0%, 100% { transform: scale3d(1, 1, 1); opacity: 0.8; }
    50% { transform: scale3d(1.1, 1.1, 1); opacity: 1; }
}

/* Composite Layers for Better Performance */
.hero-section,
.benefits-section,
.testimonials-section,
.collaborate-section,
.footer {
    transform: translateZ(0);
    isolation: isolate;
}

/* Optimize Scroll Performance */
body {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Prevent Layout Shifts */
.navbar-brand img,
.social-link,
.testimonial-card {
    content-visibility: auto;
}

/* Don't apply content-visibility to benefit cards to prevent hiding issues */
.benefit-card {
    content-visibility: visible !important;
}

/* Reduce Paint Areas */
.nav-link::before,
.nav-link::after {
    contain: layout style paint;
}

/* Optimize Font Rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-display: swap;
}

/* Critical Rendering Path Optimization */
.hero-section {
    contain: layout style;
}

/* Reduce Repaints on Scroll */
.navbar-scroll-indicator {
    contain: layout size style;
}

/* GPU Composition for Images */
img {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Optimize SVG Performance */
svg {
    shape-rendering: geometricPrecision;
    transform: translateZ(0);
}

.footer-wave-top svg {
    will-change: transform;
    contain: layout style paint;
}

/* Prevent Unnecessary Reflows */
.container {
    contain: layout style;
}

/* Optimize Table Performance */
.table {
    contain: layout style;
}

/* Battery-Friendly Animations */
@media (prefers-reduced-motion: no-preference) and (max-width: 768px) {
    /* Reduce animation frequency on mobile */
    .navbar-particle,
    .footer-particle,
    .particle {
        animation-iteration-count: 3;
        animation-duration: 5s !important;
    }
}

/* Optimize Hover States */
@media (hover: hover) and (pointer: fine) {
    /* Only apply expensive hover effects on devices that support proper hover */
    .nav-link:hover,
    .social-link:hover,
    .navbar-brand:hover {
        will-change: transform, opacity;
    }
}

/* Disable Hover Effects on Touch Devices */
@media (hover: none) {
    .nav-link:hover::before,
    .navbar-brand:hover::before {
        display: none;
    }
    
    .nav-link:hover {
        transform: none;
    }
}

/* Optimize Modal/Overlay Performance */
.navbar-overlay,
.sidebar-overlay {
    will-change: opacity;
    contain: layout style paint;
}

/* Reduce Animation Complexity During Scroll */
@media (prefers-reduced-motion: no-preference) {
    body.scrolling * {
        animation-play-state: paused !important;
        transition-duration: 0.1s !important;
    }
    
    body.scrolling .navbar-scroll-indicator {
        animation-play-state: running !important;
    }
}

/* Critical Performance: Limit Concurrent Animations */
@media (max-width: 768px) {
    /* Stagger animations to reduce load */
    .navbar-particle:nth-child(1) { animation-delay: 0s; }
    .navbar-particle:nth-child(2) { animation-delay: 0.5s; }
    .navbar-particle:nth-child(3) { animation-delay: 1s; }
    .navbar-particle:nth-child(4) { animation-delay: 1.5s; }
    .navbar-particle:nth-child(5) { animation-delay: 2s; }
    
    .footer-particle:nth-child(1) { animation-delay: 0s; }
    .footer-particle:nth-child(2) { animation-delay: 0.8s; }
    .footer-particle:nth-child(3) { animation-delay: 1.6s; }
    .footer-particle:nth-child(4) { animation-delay: 2.4s; }
    .footer-particle:nth-child(5) { animation-delay: 3.2s; }
}

/* Optimize Transform Origin */
.navbar-brand .fa-dumbbell,
.shape,
.particle {
    transform-origin: center center;
}

/* Reduce Composite Layers on Low Memory Devices */
@media (max-device-width: 768px) and (max-device-height: 1024px) {
    .footer-bg-shapes > *:nth-child(n+4),
    .floating-shapes > *:nth-child(n+3) {
        display: none;
    }
}

/* Optimize Video/Heavy Content Areas */
.carousel-item {
    contain: layout style;
    will-change: transform;
}

/* Reduce Paint on Scroll */
.testimonial-card,
.step-card {
    contain: layout style paint;
}

/* More lenient containment for benefit cards */
.benefit-card {
    contain: none !important;
}

/* Use Efficient Selectors */
.nav-link-text {
    display: inline-block;
    transform: translateZ(0);
}

/* Optimize Background Gradients */
@media (max-width: 768px) {
    body,
    .hero-section,
    .benefits-section,
    .footer {
        background-attachment: scroll !important;
    }
}

/* Connection-Aware Performance */
@media (prefers-reduced-data: reduce) {
    /* Disable non-critical animations on slow connections */
    .navbar-particle,
    .footer-particle,
    .particle,
    .shape,
    #mainNav::before,
    .footer-grid-pattern,
    .footer-wave-top {
        display: none !important;
    }
    
    .navbar-brand img,
    .social-link {
        filter: none !important;
    }
}

/* Optimize for Low-End Devices */
@media (max-width: 768px) and (max-height: 600px) {
    /* Very low-end devices or landscape tablets */
    .navbar-particles,
    .footer-particles,
    .footer-bg-shapes,
    .floating-shapes {
        display: none !important;
    }
}

/* Prevent Jank on State Changes */
.navbar-toggler[aria-expanded] {
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.navbar-collapse {
    transition: height 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Optimize Carousel Performance */
.carousel-inner {
    contain: layout style;
}

.carousel-item {
    will-change: transform;
    backface-visibility: hidden;
}

/* High Refresh Rate Optimization */
@media (min-resolution: 120dpi) {
    /* Smoother animations on high refresh rate displays */
    * {
        animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
    }
}

/* Critical: Defer Off-Screen Animations */
.footer {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* Optimize Button Interactions */
.btn,
.btn-primary,
.btn-secondary {
    contain: layout style paint;
    will-change: transform;
}

/* Performance Monitoring Helper */
@media (prefers-reduced-motion: no-preference) {
    /* Flag for performance monitoring */
    :root {
        --performance-mode: optimized;
    }
}

/* Idle State Optimizations */
@media (prefers-reduced-motion: no-preference) {
    /* Pause animations when user is idle */
    body:not(:hover):not(:focus-within) .navbar-particle,
    body:not(:hover):not(:focus-within) .footer-particle {
        animation-play-state: paused;
    }
}

/* Memory-Efficient Gradients */
@media (max-width: 768px) {
    [style*="linear-gradient"],
    [style*="radial-gradient"] {
        background-image: none !important;
        background-color: var(--primary-color, #E10600) !important;
    }
}

/* Optimize Focus States */
:focus-visible {
    outline: 2px solid #E10600;
    outline-offset: 2px;
    transition: outline-offset 0.1s;
}

/* Reduce Animation Complexity on Battery Saver */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Network-Aware Loading */
.lazy-animation {
    animation-play-state: paused;
}

.lazy-animation.visible {
    animation-play-state: running;
}

/* Final Performance Boost */
* {
    /* Use faster easing functions */
    transition-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Force GPU Composition */
@supports (will-change: transform) {
    .navbar-brand,
    .nav-link,
    .social-link,
    .benefit-card,
    .shape,
    .particle {
        will-change: transform, opacity;
    }
}

/* Smooth Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(225, 6, 0, 0.5);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(225, 6, 0, 0.8);
}

/* Prevent Scroll Jank */
html {
    scroll-padding-top: 80px;
}

/* Optimize Critical Path */
.hero-section,
#mainNav {
    content-visibility: visible;
}

