/**
 * Performance CSS
 * flexHUB digital.group
 * 
 * Styles für Lazy Loading, Placeholder und Performance-Optimierungen
 */

/* ============================================
   LAZY LOADING STYLES
   ============================================ */

/* Basis für lazy-loaded Bilder */
img[data-src],
img.lazy {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img.lazy-loaded,
img[data-src].lazy-loaded {
    opacity: 1;
}

/* Native lazy loading Support */
img[loading="lazy"] {
    /* Aspect Ratio Placeholder um Layout Shifts zu vermeiden */
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-200) 100%);
}

/* ============================================
   SKELETON / PLACEHOLDER STYLES
   ============================================ */

/* Skeleton Animation */
@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.skeleton {
    background: linear-gradient(90deg, 
        var(--gray-200) 25%, 
        var(--gray-100) 50%, 
        var(--gray-200) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* Image Placeholder */
.img-placeholder {
    position: relative;
    background: var(--gray-100);
    overflow: hidden;
}

.img-placeholder::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    100% {
        left: 100%;
    }
}

/* ============================================
   BACKGROUND LAZY LOADING
   ============================================ */

[data-bg] {
    background-color: var(--gray-100);
    transition: background-image 0.3s ease;
}

[data-bg].bg-loaded {
    /* Background image wird per JS gesetzt */
    background-color: transparent;
}

/* ============================================
   BLUR-UP EFFECT
   ============================================ */

img[data-placeholder] {
    filter: blur(20px);
    transition: filter 0.5s ease;
    background-size: cover;
    background-position: center;
}

img[data-placeholder].loaded {
    filter: blur(0);
}

/* ============================================
   CONTENT VISIBILITY (Auto)
   ============================================ */

/* Für Abschnitte die nicht im initialen Viewport sind */
.content-lazy {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px; /* Geschätzte Höhe */
}

/* Spezifische Höhen für verschiedene Sections */
.service-section.content-lazy {
    contain-intrinsic-size: 0 600px;
}

.testimonials-section.content-lazy {
    contain-intrinsic-size: 0 400px;
}

.cta-section.content-lazy {
    contain-intrinsic-size: 0 300px;
}

/* Footer */
.footer.content-lazy {
    contain-intrinsic-size: 0 400px;
}

/* ============================================
   FONT DISPLAY OPTIMIZATION
   ============================================ */

/* Fallback wenn Custom Fonts noch laden */
.fonts-loading body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.fonts-loading h1,
.fonts-loading h2,
.fonts-loading h3,
.fonts-loading h4,
.fonts-loading h5,
.fonts-loading h6 {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* ============================================
   REDUCE MOTION
   ============================================ */

@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;
    }
    
    img[data-src],
    img.lazy {
        opacity: 1;
        transition: none;
    }
    
    .img-placeholder::before {
        animation: none;
    }
}

/* ============================================
   LAYOUT SHIFT PREVENTION
   ============================================ */

/* Aspect Ratio Boxes für Bilder */
.aspect-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-1-1 {
    aspect-ratio: 1 / 1;
}

.aspect-3-2 {
    aspect-ratio: 3 / 2;
}

/* Image Container mit fester Größe */
.img-container {
    position: relative;
    overflow: hidden;
    background: var(--gray-100);
}

.img-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================
   CRITICAL PATH OPTIMIZATION
   ============================================ */

/* Above-the-fold Elemente sofort sichtbar */
.hero-section,
.navbar,
.page-header {
    /* Keine content-visibility für kritische Elemente */
    content-visibility: visible;
}

/* SVG Icons optimieren */
svg {
    /* Hardware Acceleration für SVGs */
    will-change: transform;
    transform: translateZ(0);
}

/* ============================================
   PRINT OPTIMIZATION
   ============================================ */

@media print {
    /* Lazy loading deaktivieren für Print */
    img[data-src] {
        opacity: 1 !important;
    }
    
    /* Animationen entfernen */
    * {
        animation: none !important;
        transition: none !important;
    }
    
    /* Hintergründe für besseren Druck */
    .content-lazy {
        content-visibility: visible;
        contain-intrinsic-size: auto;
    }
}
