/* 
   Telegraph Egypt CLS (Cumulative Layout Shift) Optimization
   This file contains styles specifically designed to prevent layout shifts
   and improve Core Web Vitals scores
*/

/* ============================================
   1. Font Loading Optimization
   ============================================ */

/* Reserve space for images BEFORE loading */
img[width][height] {
    aspect-ratio: attr(width) / attr(height);
}

/* Ensure images have proper sizing */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ============================================
   2. Container and Layout Optimization
   ============================================ */

/* Header should not shift */
header {
    contain: layout style paint;
    position: relative;
    z-index: 9999;
}

/* Navbar sticky position */
.Navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    contain: layout style paint;
}

/* Navigation stability */
nav, .navbar, .menublock {
    contain: layout style paint;
}

/* Main content areas */
main {
    contain: layout style paint;
}

.main-wrapper {
    contain: layout style paint;
    min-height: auto; /* Natural height, no fixed minimum */
}

/* Article specific */
.article-content-wrapper {
    contain: layout style paint;
    background: #fff;
    width: 100%;
    min-height: auto; /* Remove min-height to prevent CLS */
}

/* ============================================
   3. Advertisement Sections
   ============================================ */

/* Ad slot reserved - only show when has content */
.ad-slot-reserved {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    contain: layout style paint;
}

/* Hide if empty */
.ad-slot-reserved:empty {
    display: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Block ads container */
.BlockAds {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    contain: layout style paint;
}

/* ============================================
   4. Image Optimization
   ============================================ */

/* Prevent CLS during lazy loading */
img.lazyload,
img.lazy,
img[loading="lazy"] {
    background-color: #f0f0f0;
}

/* Ensure all images respect aspect ratio */
picture {
    margin: 0;
    padding: 0;
    display: block;
}

figure, picture {
    margin: 0;
    padding: 0;
    display: block;
}

/* ============================================
   5. Text and Typography
   ============================================ */

/* Consistent line heights */
html {
    line-height: 1.5;
}

body {
    line-height: 1.5;
    font-size: 16px;
}

p {
    margin: 0;
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    margin: 0;
}

/* ============================================
   6. Specific Element Fixes
   ============================================ */

/* List items must remain in list position */
li {
    display: list-item;
    margin: 0;
    padding: 0;
}

/* Social media list stability */
.social-media ul,
.social-links ul {
    display: flex;
    margin: 0;
    padding: 0;
    list-style: none;
}

.social-media li,
.social-links li {
    margin: 0 5px;
    flex-shrink: 0;
}

/* ============================================
   7. Mobile Optimization
   ============================================ */

@media (max-width: 768px) {
    .article-content-wrapper {
        min-height: auto;
    }

    .ad-slot-reserved {
        margin: 10px 0;
    }

    .Navbar {
        top: 0;
        position: sticky;
    }
}