/* ==========================================================================
   PERFORMANCE OPTIMIZATION CSS
   Critical performance improvements for Morocco Taxi Booking Platform
   ========================================================================== */

/* CSS Custom Properties for Performance */
:root {
    /* Animation Performance */
    --animation-duration-fast: 0.15s;
    --animation-duration-normal: 0.3s;
    --animation-duration-slow: 0.5s;
    --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Layout Performance */
    --container-max-width: 1200px;
    --grid-gap: 1rem;
    --border-radius: 8px;
    
    /* Color Performance (reduce repaints) */
    --primary-color: #f7b731;
    --secondary-color: #2c3e50;
    --text-color: #333;
    --background-color: #fff;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   CRITICAL CSS OPTIMIZATIONS
   ========================================================================== */

/* Reduce Layout Shifts */
* {
    box-sizing: border-box;
}

/* Optimize Font Loading */
@font-display: swap;

/* Prevent FOUC (Flash of Unstyled Content) */
html {
    visibility: hidden;
}

html.loaded {
    visibility: visible;
}

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

/* Image Lazy Loading */
img[data-src] {
    opacity: 0;
    transition: opacity var(--animation-duration-normal) var(--animation-easing);
}

img[data-src].loaded {
    opacity: 1;
}

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

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

/* Intersection Observer Optimizations */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity var(--animation-duration-slow) var(--animation-easing),
                transform var(--animation-duration-slow) var(--animation-easing);
}

.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   ANIMATION PERFORMANCE
   ========================================================================== */

/* Hardware Acceleration for Animations */
.animate {
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

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

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

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* ==========================================================================
   LAYOUT PERFORMANCE
   ========================================================================== */

/* Container Queries for Better Performance */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 1rem;
    contain: layout style;
}

/* Grid Performance Optimizations */
.grid {
    display: grid;
    gap: var(--grid-gap);
    contain: layout;
}

.grid-auto {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Flexbox Performance */
.flex {
    display: flex;
    contain: layout;
}

.flex-center {
    justify-content: center;
    align-items: center;
}

.flex-between {
    justify-content: space-between;
    align-items: center;
}

.flex-wrap {
    flex-wrap: wrap;
}

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

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* WebP Support with Fallback */
.webp-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Image Aspect Ratio Containers */
.aspect-ratio {
    position: relative;
    overflow: hidden;
}

.aspect-ratio::before {
    content: '';
    display: block;
    padding-top: var(--aspect-ratio, 56.25%); /* 16:9 default */
}

.aspect-ratio > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Common Aspect Ratios */
.aspect-16-9 { --aspect-ratio: 56.25%; }
.aspect-4-3 { --aspect-ratio: 75%; }
.aspect-1-1 { --aspect-ratio: 100%; }
.aspect-3-2 { --aspect-ratio: 66.67%; }

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

/* Above-the-fold Critical Styles */
.hero-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout style paint;
}

/* Navigation Performance */
.nav {
    contain: layout style;
    transform: translateZ(0);
}

.nav-sticky {
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

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

/* Loading Spinner */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

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

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 60%;
}

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

/* GPU Acceleration */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Contain Layout */
.contain-layout {
    contain: layout;
}

.contain-paint {
    contain: paint;
}

.contain-strict {
    contain: strict;
}

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

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

/* Mobile-First Media Queries */
@media (min-width: 768px) {
    .grid-md-2 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-md-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-lg-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .grid-lg-5 {
        grid-template-columns: repeat(5, 1fr);
    }
}

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

@media print {
    /* Hide non-essential elements */
    .no-print,
    nav,
    .navigation,
    .cookie-banner,
    .floating-social,
    .video-background {
        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;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
    
    abbr[title]:after {
        content: " (" attr(title) ")";
    }
    
    /* Page breaks */
    .page-break {
        page-break-before: always;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    p, blockquote {
        page-break-inside: avoid;
    }
}

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

/* Focus Performance */
:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000;
        --secondary-color: #000;
        --text-color: #000;
        --background-color: #fff;
    }
}

/* Dark Mode Performance */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #ffd700;
        --secondary-color: #f0f0f0;
        --text-color: #f0f0f0;
        --background-color: #1a1a1a;
        --shadow-color: rgba(255, 255, 255, 0.1);
    }
}

/* ==========================================================================
   CRITICAL PERFORMANCE FIXES
   ========================================================================== */

/* Prevent Layout Thrashing */
.no-layout-thrash {
    transform: translateZ(0);
    will-change: auto;
}

/* Optimize Repaints */
.optimize-repaint {
    contain: layout style paint;
}

/* Memory Management */
.cleanup-after-animation {
    animation-fill-mode: forwards;
}

.cleanup-after-animation.animation-complete {
    will-change: auto;
    transform: none;
}

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

/* Performance Markers for Debugging */
.perf-marker::before {
    content: attr(data-perf-label);
    position: absolute;
    top: -20px;
    left: 0;
    font-size: 10px;
    color: red;
    background: yellow;
    padding: 2px 4px;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
}

.debug-performance .perf-marker::before {
    opacity: 1;
} 