/**
 * DAMP Performance Optimization Styles
 * CSS optimizations for speed, smooth animations, and visual performance
 * Google Engineering Standards with Security Focus
 * Copyright 2025 WeCr8 Solutions LLC
 */

/* ==========================================================================
   PERFORMANCE FUNDAMENTALS
   ========================================================================== */

/* Critical rendering optimizations */
* {
    box-sizing: border-box;
}

/* Optimize font rendering */
html {
    font-display: swap;
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent layout shifts */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   LAZY LOADING OPTIMIZATIONS
   ========================================================================== */

/* Lazy loading states */
.lazy-loading {
    opacity: 0.6;
    filter: blur(2px);
    transition: opacity 0.3s ease-in-out, filter 0.3s ease-in-out;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 100%);
}

.lazy-loaded {
    opacity: 1;
    filter: none;
}

.lazy-error {
    opacity: 0.8;
    filter: grayscale(100%);
    background: linear-gradient(135deg, #ff4757 0%, #ff6b35 100%);
}

/* Skeleton loading animations */
.skeleton {
    background: linear-gradient(90deg, #0f0f23 25%, #1a1a2e 50%, #0f0f23 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

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

/* ==========================================================================
   WILL-CHANGE OPTIMIZATIONS
   ========================================================================== */

/* Optimize animations for GPU */
.hero-animation-overlay,
.animation-bubble,
.nav-scrolled,
.modal-content,
.auth-modal {
    will-change: transform, opacity;
}

/* Remove will-change after animations complete */
.animation-complete .hero-animation-overlay,
.animation-complete .animation-bubble {
    will-change: auto;
}

/* ==========================================================================
   CRITICAL CSS INLINING HELPERS
   ========================================================================== */

/* Above-the-fold critical styles */
.critical-content {
    contain: layout style paint;
}

/* Non-critical content */
.non-critical {
    content-visibility: auto;
    contain-intrinsic-size: 1px 500px;
}

/* ==========================================================================
   SMOOTH SCROLLING OPTIMIZATIONS
   ========================================================================== */

/* Enhanced smooth scrolling */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 100px;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   EFFICIENT ANIMATIONS
   ========================================================================== */

/* Use transform and opacity for smooth animations */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease forwards;
}

.fade-in-delayed {
    animation-delay: 0.2s;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Optimized hover effects */
.optimized-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.optimized-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.2);
}

/* ==========================================================================
   LAYOUT STABILITY
   ========================================================================== */

/* Prevent cumulative layout shift */
.aspect-ratio-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-ratio-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1 / 1;
}

/* Image containers with fixed aspect ratios */
.image-container {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 100%);
}

.image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================================================
   RESOURCE HINTS STYLES
   ========================================================================== */

/* Optimize font loading */
@font-face {
    font-family: 'System UI';
    src: local('system-ui'), local('-apple-system'), local('BlinkMacSystemFont');
    font-display: swap;
}

/* ==========================================================================
   PERFORMANCE MONITORING INDICATORS
   ========================================================================== */

/* Performance indicator (only visible in development) */
.performance-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 212, 255, 0.9);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 10000;
    display: none;
}

.performance-indicator.show {
    display: block;
}

.performance-good { background: rgba(0, 255, 136, 0.9); }
.performance-warning { background: rgba(255, 107, 53, 0.9); }
.performance-poor { background: rgba(255, 71, 87, 0.9); }

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

/* Optimize large lists */
.virtual-list {
    overflow-y: auto;
    contain: strict;
}

.virtual-list-item {
    contain: layout style paint;
}

/* ==========================================================================
   RESPONSIVE PERFORMANCE
   ========================================================================== */

/* Mobile-first performance optimizations */
@media (max-width: 768px) {
    /* Reduce animation complexity on mobile */
    .complex-animation {
        animation: none;
    }
    
    /* Simplify shadows on mobile */
    .heavy-shadow {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Optimize transforms on mobile */
    .mobile-optimized {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .high-dpi-optimized {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ==========================================================================
   DARK MODE PERFORMANCE
   ========================================================================== */

/* Efficient dark mode transitions */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ==========================================================================
   ACCESSIBILITY PERFORMANCE
   ========================================================================== */

/* Focus indicators that don't cause layout shifts */
.focus-optimized:focus {
    outline: 2px solid #00d4ff;
    outline-offset: 2px;
}

/* Skip links for performance */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #00d4ff;
    color: #0f0f23;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 6px;
}

/* ==========================================================================
   PRINT OPTIMIZATIONS
   ========================================================================== */

@media print {
    /* Remove non-essential elements for printing */
    .no-print,
    .hero-animation-overlay,
    .auth-modal,
    .performance-indicator {
        display: none !important;
    }
    
    /* Optimize for print */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a, a:visited {
        text-decoration: underline;
    }
    
    /* Show URLs after links */
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ==========================================================================
   PERFORMANCE UTILITIES
   ========================================================================== */

/* GPU acceleration utilities */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Contain utilities */
.contain-layout { contain: layout; }
.contain-style { contain: style; }
.contain-paint { contain: paint; }
.contain-size { contain: size; }
.contain-strict { contain: strict; }

/* Visibility utilities for performance */
.visually-hidden {
    position: absolute !important;
    clip: rect(1px, 1px, 1px, 1px) !important;
    padding: 0 !important;
    border: 0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden !important;
}

/* Loading states */
.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 212, 255, 0.3);
    border-top: 2px solid #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   CRITICAL PERFORMANCE METRICS
   ========================================================================== */

/* Largest Contentful Paint optimization */
.lcp-element {
    contain: layout style paint;
    content-visibility: auto;
}

/* First Input Delay optimization */
.fid-optimized {
    pointer-events: auto;
    touch-action: manipulation;
}

/* Cumulative Layout Shift prevention */
.cls-stable {
    min-height: 1px;
    contain: layout;
}
