/*
Performance CSS Framework voor Routemeister
===========================================
CSS optimizations voor betere performance
*/

/* ========================================
   CRITICAL CSS - ABOVE THE FOLD
   ======================================== */

/* Critical styles that should be inlined */
.critical-styles {
    /* Hide non-critical content initially */
    .non-critical {
        display: none;
    }
    
    /* Show after page load */
    .non-critical.loaded {
        display: block;
    }
}

/* ========================================
   LAZY LOADING STYLES
   ======================================== */

/* Lazy loading images */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
    background: #f0f0f0;
    min-height: 200px;
}

img[data-src].loaded {
    opacity: 1;
}

/* Lazy loading containers */
.lazy-container {
    min-height: 200px;
    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; }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Use transform instead of changing layout properties */
.animate-transform {
    transition: transform 0.3s ease;
}

.animate-transform:hover {
    transform: translateY(-2px);
}

/* Use will-change for elements that will animate */
.will-animate {
    will-change: transform, opacity;
}

/* GPU acceleration for smooth animations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ========================================
   CONTENT VISIBILITY
   ======================================== */

/* Hide off-screen content */
.off-screen {
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

/* ========================================
   FONT OPTIMIZATION
   ======================================== */

/* Font display optimization */
@font-face {
    font-family: 'Routemeister';
    font-display: swap; /* Show fallback font immediately */
    src: url('/static/fonts/routemeister.woff2') format('woff2');
}

/* ========================================
   IMAGE OPTIMIZATION
   ======================================== */

/* Responsive images */
.responsive-image {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* WebP support with fallback */
.webp-image {
    background-image: url('/static/images/fallback.jpg');
}

.webp .webp-image {
    background-image: url('/static/images/image.webp');
}

/* ========================================
   LOADING STATES
   ======================================== */

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 60%;
}

/* ========================================
   PERFORMANCE MONITORING
   ======================================== */

/* Performance indicators */
.performance-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 9999;
    display: none;
}

.performance-indicator.show {
    display: block;
}

/* ========================================
   BUNDLE OPTIMIZATION
   ======================================== */

/* Critical path CSS */
.critical-path {
    /* Styles that are needed immediately */
    .header { display: block; }
    .navigation { display: flex; }
    .main-content { display: block; }
}

/* Non-critical CSS loaded later */
.non-critical-path {
    /* Styles that can be loaded after initial render */
    .footer { display: block; }
    .sidebar { display: block; }
    .modals { display: none; }
}

/* ========================================
   CACHING INDICATORS
   ======================================== */

/* Show when content is cached */
.cached-content {
    position: relative;
}

.cached-content::after {
    content: "📦";
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 12px;
    opacity: 0.7;
}

/* ========================================
   NETWORK OPTIMIZATION
   ======================================== */

/* Offline indicators */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff6b6b;
    color: white;
    text-align: center;
    padding: 10px;
    z-index: 10000;
    display: none;
}

.offline-indicator.show {
    display: block;
}

/* ========================================
   MEMORY OPTIMIZATION
   ======================================== */

/* Reduce memory usage for large lists */
.virtual-list {
    height: 400px;
    overflow-y: auto;
    contain: layout style paint;
}

.virtual-list-item {
    height: 50px;
    contain: layout style paint;
}

/* ========================================
   RENDER OPTIMIZATION
   ======================================== */

/* Optimize rendering performance */
.optimized-render {
    contain: layout style paint;
    will-change: auto;
}

/* Reduce repaints */
.stable-layout {
    contain: layout;
}

/* Reduce reflows */
.stable-style {
    contain: style;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Performance utilities */
.hidden { display: none !important; }
.visible { display: block !important; }
.invisible { visibility: hidden; }
.opacity-0 { opacity: 0; }
.opacity-100 { opacity: 1; }

/* Animation utilities */
.no-animation { animation: none !important; }
.no-transition { transition: none !important; }
.no-transform { transform: none !important; }

/* ========================================
   MEDIA QUERIES FOR PERFORMANCE
   ======================================== */

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Optimize for high DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .high-dpi-optimized {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ========================================
   PRINT OPTIMIZATION
   ======================================== */

@media print {
    /* Hide non-essential elements */
    .no-print {
        display: none !important;
    }
    
    /* Optimize for printing */
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
}
