/**
 * Performance-Optimized CSS
 * Critical styles and performance enhancements
 */

/* ==========================================
   1. CRITICAL CSS - ABOVE THE FOLD
   ========================================== */

/* Critical layout styles that should be inlined */
.critical-layout {
    /* Navigation */
    .navbar-modern {
        position: sticky;
        top: 0;
        z-index: 1000;
        background: #ffffff;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Hero section */
    .hero-section {
        min-height: 70vh;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #E8A239 0%, #0D5F3C 100%);
    }
    
    /* Main content container */
    .main-content {
        min-height: 50vh;
    }
}

/* ==========================================
   2. FONT LOADING OPTIMIZATION
   ========================================== */

/* Font display swap for better performance */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap; /* Shows fallback font immediately */
    src: url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
}

/* Font loading classes */
.font-loading {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.fonts-loaded {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ==========================================
   3. IMAGE OPTIMIZATION
   ========================================== */

/* Responsive images with aspect ratio */
.img-responsive {
    width: 100%;
    height: auto;
    max-width: 100%;
    display: block;
}

/* Lazy loading placeholder */
.img-lazy {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 200px;
}

.img-lazy[data-loaded="true"] {
    animation: none;
    background: none;
}

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

/* WebP support detection */
.webp .hero-bg {
    background-image: url('hero-image.webp');
}

.no-webp .hero-bg {
    background-image: url('hero-image.jpg');
}

/* Image optimization with object-fit */
.img-cover {
    object-fit: cover;
    object-position: center;
}

.img-contain {
    object-fit: contain;
}

/* ==========================================
   4. CSS CONTAINMENT FOR PERFORMANCE
   ========================================== */

/* Layout containment for independent sections */
.section-contained {
    contain: layout style paint;
}

.card-contained {
    contain: layout;
}

/* Content containment for dynamic content */
.dynamic-content {
    contain: content;
}

/* ==========================================
   5. WILL-CHANGE OPTIMIZATION
   ========================================== */

/* Optimize animations and transforms */
.will-animate {
    will-change: transform;
}

.will-animate:hover {
    transform: translateY(-2px);
}

.will-animate:not(:hover) {
    will-change: auto; /* Remove will-change when not needed */
}

/* Scroll-triggered animations */
.scroll-animate {
    will-change: transform, opacity;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

.scroll-animate.in-view {
    transform: translateY(0);
    opacity: 1;
    will-change: auto;
}

/* ==========================================
   6. EFFICIENT SELECTORS
   ========================================== */

/* Avoid expensive selectors */
/* BAD: * { margin: 0; } */
/* GOOD: Specific resets */
body, h1, h2, h3, h4, h5, h6, p, ul, ol, li {
    margin: 0;
    padding: 0;
}

/* Use class selectors instead of complex nesting */
.btn-primary { /* GOOD: Simple class selector */ }
/* .navbar .nav .nav-item .nav-link.active { BAD: Deep nesting } */

/* ==========================================
   7. ANIMATION PERFORMANCE
   ========================================== */

/* Use transform and opacity for animations */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px); /* Use transform instead of changing layout properties */
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide animations using transform */
.slide-in-left {
    transform: translateX(-100%);
    transition: transform 0.3s ease-out;
}

.slide-in-left.active {
    transform: translateX(0);
}

/* Hardware acceleration for smooth animations */
.gpu-accelerated {
    transform: translateZ(0); /* Force GPU acceleration */
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ==========================================
   8. REDUCED PAINT AND LAYOUT THRASHING
   ========================================== */

/* Minimize layout changes */
.fixed-dimensions {
    width: 100%;
    height: 200px; /* Fixed height prevents layout shifts */
    overflow: hidden;
}

/* Use absolute positioning for overlays */
.overlay-positioned {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    /* Doesn't affect document flow */
}

/* Avoid changing box model properties in animations */
.smooth-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease; /* GOOD */
    /* transition: width 0.2s ease, height 0.2s ease; BAD */
}

.smooth-hover:hover {
    transform: scale(1.05); /* GOOD: Uses composite layer */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* ==========================================
   9. MOBILE PERFORMANCE OPTIMIZATIONS
   ========================================== */

/* Touch optimizations */
.touch-optimized {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Scroll performance on mobile */
.smooth-scroll {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Prevent zoom on form inputs */
.no-zoom input,
.no-zoom select,
.no-zoom textarea {
    font-size: 16px; /* Prevents iOS zoom */
}

/* ==========================================
   10. CSS VARIABLES FOR DYNAMIC THEMING
   ========================================== */

/* Efficient custom properties usage */
:root {
    /* Core colors that are frequently accessed */
    --primary: #E8A239;
    --secondary: #0D5F3C;
    --white: #ffffff;
    --gray-900: #111827;
    
    /* Commonly used values */
    --border-radius: 8px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --transition: 0.2s ease;
}

/* Use CSS variables for dynamic changes */
.theme-dynamic {
    background-color: var(--primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: background-color var(--transition);
}

/* ==========================================
   11. LOADING STATES
   ========================================== */

/* Skeleton loading for better perceived performance */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.2s ease-in-out infinite;
    border-radius: 4px;
}

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

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}

.skeleton-paragraph {
    height: 16px;
    margin-bottom: 8px;
}

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

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

/* Progressive loading */
.content-loading {
    opacity: 0.5;
    pointer-events: none;
}

.content-loaded {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

/* ==========================================
   12. CRITICAL PATH CSS OPTIMIZATION
   ========================================== */

/* Essential styles that must load first */
.critical {
    /* Reset */
    * {
        box-sizing: border-box;
    }
    
    /* Typography */
    body {
        font-family: system-ui, -apple-system, sans-serif;
        font-size: 16px;
        line-height: 1.5;
        color: #111827;
    }
    
    /* Layout */
    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 16px;
    }
    
    /* Navigation */
    .navbar {
        background: #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        position: sticky;
        top: 0;
        z-index: 1000;
    }
}

/* ==========================================
   13. BROWSER-SPECIFIC OPTIMIZATIONS
   ========================================== */

/* Safari optimizations */
@supports (-webkit-appearance: none) {
    .safari-smooth {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Firefox optimizations */
@-moz-document url-prefix() {
    .firefox-specific {
        scrollbar-width: thin;
        scrollbar-color: #E8A239 #f1f1f1;
    }
}

/* Chrome optimizations */
@supports (background: paint(something)) {
    .chrome-optimized {
        /* Chrome-specific optimizations */
    }
}

/* ==========================================
   14. PRINT PERFORMANCE
   ========================================== */

@media print {
    /* Remove unnecessary elements for print */
    .no-print,
    .navbar,
    .footer,
    .floating-whatsapp,
    .back-to-top {
        display: none !important;
    }
    
    /* Optimize print styles */
    * {
        background: transparent !important;
        box-shadow: none !important;
        text-shadow: none !important;
        color: black !important;
    }
    
    /* Ensure good contrast */
    a, a:visited {
        text-decoration: underline;
        color: #000 !important;
    }
    
    /* Page breaks */
    .page-break {
        page-break-after: always;
    }
    
    .avoid-break {
        page-break-inside: avoid;
    }
}

/* ==========================================
   15. PERFORMANCE MONITORING
   ========================================== */

/* Performance markers for debugging */
.perf-marker::before {
    content: attr(data-perf-label);
    position: absolute;
    top: -20px;
    left: 0;
    background: #ff0000;
    color: white;
    padding: 2px 4px;
    font-size: 10px;
    z-index: 9999;
    display: none;
}

/* Show performance markers in development */
body.debug-performance .perf-marker::before {
    display: block;
}

/* Resource hints support detection */
.supports-prefetch {
    /* Styles for browsers that support resource hints */
}

/* Service worker support */
.sw-supported {
    /* Styles when service worker is available */
}

.sw-not-supported {
    /* Fallback styles */
}

/* ==========================================
   16. UTILITY CLASSES FOR PERFORMANCE
   ========================================== */

/* Visibility utilities that don't affect layout */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Prevent layout shifts */
.prevent-layout-shift {
    min-height: 1px; /* Prevents collapse */
}

/* Force hardware acceleration */
.force-gpu {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Optimize text rendering */
.optimize-text {
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* High performance scrolling */
.high-perf-scroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Content that can be safely hidden during scroll */
.hide-during-scroll {
    opacity: 1;
    transition: opacity 0.1s ease;
}

body.scrolling .hide-during-scroll {
    opacity: 0;
}

/* ==========================================
   17. RESPONSIVE PERFORMANCE
   ========================================== */

/* Efficient media queries */
@media (max-width: 768px) {
    /* Mobile-specific performance optimizations */
    .desktop-only {
        display: none !important;
    }
    
    /* Reduce animation complexity on mobile */
    .reduce-motion {
        animation-duration: 0.1s !important;
        transition-duration: 0.1s !important;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

/* Connection-aware styling */
@media (prefers-reduced-data) {
    /* Styles for slow connections */
    .heavy-animation {
        animation: none !important;
    }
    
    .heavy-shadow {
        box-shadow: none !important;
    }
}

/* ==========================================
   18. ACCESSIBILITY PERFORMANCE
   ========================================== */

/* Reduce motion for accessibility */
@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;
    }
}

/* High contrast mode optimizations */
@media (prefers-contrast: high) {
    /* Simplified styles for high contrast */
    .complex-gradient {
        background: solid !important;
    }
    
    .subtle-shadow {
        box-shadow: none !important;
        border: 1px solid currentColor !important;
    }
}