/**
 * Advanced Performance Optimization CSS for AppsZeal
 * Includes lazy loading, critical rendering path optimizations, Core Web Vitals improvements,
 * and advanced caching strategies for maximum performance
 */

/* ==========================================================================
   Critical Performance Variables
   ========================================================================== */

:root {
    /* Performance-optimized colors */
    --primary-color: #1a56db;
    --primary-hover: #1e429f;
    --secondary-color: #f3f4f6;
    --accent-color: #3b82f6;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --text-light: #ffffff;
    --border-color: #e5e7eb;
    --bg-color: #ffffff;
    --bg-alt: #f9fafb;
    --bg-light-blue: #f0f7ff;
    
    /* Performance shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Optimized transitions */
    --transition-fast: all 0.15s ease;
    --transition: all 0.3s ease;
    --transition-slow: all 0.5s ease;
    
    /* Border radius */
    --radius: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
}
/* ==========================================================================
   Core Web Vitals Optimizations
   ========================================================================== */

/* Prevent Cumulative Layout Shift (CLS) */
* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    contain: layout style paint;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-color);
    background-color: var(--bg-color);
    font-display: swap;
    contain: layout style paint;
    margin: 0;
    padding: 0;
}
/* First Input Delay (FID) Optimizations */
button,
.btn,
.interactive-element,
input,
textarea,
select {
    touch-action: manipulation;
    cursor: pointer;
}

/* ==========================================================================
   Advanced Lazy Loading Styles
   ========================================================================== */

/* Base lazy image styles with improved performance */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background-color: #f8f9fa;
    background-image: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                      linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                      linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: loading-shimmer 1.5s infinite linear;
    will-change: opacity, filter;
}

/* Loading state with better performance */
img.lazy-loading {
    opacity: 0.7;
    filter: blur(2px);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Loaded state */
img.lazy-loaded {
    opacity: 1;
    filter: blur(0);
    background: none;
    animation: none;
    will-change: auto;
}

/* Error state */
img.lazy-error {
    opacity: 0.5;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    animation: none;
}

/* Optimized loading shimmer animation */
@keyframes loading-shimmer {
    0% {
        background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    }
    100% {
        background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px;
    }
}

/* WebP support detection */
.webp img.lazy {
    background-image: url('data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA');
}

.no-webp img.lazy {
    background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWGRkqGx0f/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAAECEgMRkf/aAAwDAQACEQMRAD8AltJagyeH0AthI5xdrLcNM91BF5pX2HaH9bcfaSXWGaRmknyJckliyjqTzSlT54b6bk+h0R//2Q==');
}

/* ==========================================================================
   Critical Rendering Path Optimizations
   ========================================================================== */

/* Prevent layout shifts with reserved space */
.content-container {
    min-height: 100vh;
    contain: layout style paint;
}

/* Optimize font loading with system fonts */
@font-face {
    font-family: 'System';
    src: local('system-ui'), local('-apple-system'), local('BlinkMacSystemFont'), 
         local('Segoe UI'), local('Roboto'), local('Oxygen'), local('Ubuntu'), 
         local('Cantarell'), local('Helvetica Neue'), local('sans-serif');
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Enhanced system fonts for better performance */
body {
    font-family: 'System', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 
                 Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Critical above-the-fold styles */
.above-the-fold {
    contain: layout style paint;
    will-change: transform;
}

/* Optimize critical images */
.hero-image,
.logo-image,
.featured-image {
    content-visibility: auto;
    contain-intrinsic-size: 300px 200px;
}

/* ==========================================================================
   Layout Stability (CLS) Improvements
   ========================================================================== */

/* Reserve space for images to prevent layout shifts */
.image-container {
    position: relative;
    overflow: hidden;
}

.image-container::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 aspect ratio */
}

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

/* Product logo containers */
.product-logo-container {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

.product-logo-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* Optimize animations for better performance */
* {
    box-sizing: border-box;
}

/* Use transform instead of changing layout properties */
.btn-hover-effect {
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.btn-hover-effect:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Optimize scrolling performance */
.scroll-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ==========================================================================
   Web Vitals Optimizations
   ========================================================================== */

/* Largest Contentful Paint (LCP) optimizations */
.hero-image {
    will-change: transform;
    transform: translateZ(0);
}

/* First Input Delay (FID) optimizations */
.interactive-element {
    touch-action: manipulation;
}

/* Cumulative Layout Shift (CLS) optimizations */
.dynamic-content {
    min-height: 200px; /* Reserve space for dynamic content */
}

/* ==========================================================================
   Loading States
   ========================================================================== */

/* Skeleton loading for content */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

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

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-title {
    height: 1.5em;
    width: 60%;
    margin-bottom: 1em;
    border-radius: 4px;
}

.skeleton-paragraph {
    height: 1em;
    margin-bottom: 0.5em;
    border-radius: 4px;
}

.skeleton-paragraph:last-child {
    width: 80%;
}

/* ==========================================================================
   Responsive Images
   ========================================================================== */

/* Responsive image containers */
.responsive-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Picture element optimization */
picture {
    display: block;
}

picture img {
    width: 100%;
    height: auto;
}

/* ==========================================================================
   Critical CSS for Above-the-Fold Content
   ========================================================================== */

/* Header styles (critical) */
.main-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* contain: layout style paint; */
}

.header-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.logo-link {
    font-size: 1.5rem;
    font-weight: bold;
    color: #007bff;
    text-decoration: none;
}
/* Hero section (critical) */
.hero-title {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    font-weight: 700;
}
.hero-description {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}
/* ==========================================================================
   Mobile Optimizations
   ========================================================================== */
@media (max-width: 768px) {
    /* Optimize touch targets */
    .btn, .nav-link, .social-share-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Reduce animations on mobile for better performance */
    .btn-hover-effect {
        transition: none;
    }
    
    .btn-hover-effect:hover {
        transform: none;
    }
    
    /* Optimize hero section for mobile */
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-description {
        font-size: 1rem;
    }
    
    /* Optimize image containers for mobile */
    .image-container::before {
        padding-top: 75%; /* 4:3 aspect ratio for mobile */
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    /* Hide non-essential elements when printing */
    .social-share-container,
    .header-actions,
    .sidebar,
    .footer {
        display: none !important;
    }
    
    /* Optimize text for printing */
    body {
        font-size: 12pt;
        line-height: 1.4;
        color: #000;
        background: #fff;
    }
    
    /* Ensure images print well */
    img {
        max-width: 100% !important;
        height: auto !important;
    }
}

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

/* Focus indicators */
.btn:focus,
.nav-link:focus,
input:focus,
textarea:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
}

/* 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;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #ffffff;
        --text-color: #020202;
        --border-color: #333333;
        --card-bg: #888e9b;
    }
    
    body {
        /* background-color: var(--bg-color);
        color: var(--text-color); */
    }
    
    .card,
    .sidebar-widget {
        background-color: var(--card-bg);
        border-color: var(--border-color);
    }
    
    img.lazy {
        background-color: #2d2d2d;
    }
}
