/* 
   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
   ============================================ */

/* Use block display strategy to show content immediately with fallback font */
@font-face {
    font-family: B-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-Bold-2.woff) format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

@font-face {
    font-family: R-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-Regular-1.woff) format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

@font-face {
    font-family: SB-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-SemiBold-2.woff) format('woff');
    font-weight: 600;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

@font-face {
    font-family: Bk-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-Black-1.woff) format('woff');
    font-weight: 900;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

@font-face {
    font-family: L-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-Light-1.woff) format('woff');
    font-weight: 300;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

@font-face {
    font-family: EL-Cairo;
    src: url(../fonts/textfonts/ArbFONTS-Cairo-ExtraLight-1.woff) format('woff');
    font-weight: 200;
    font-style: normal;
    font-display: block;
    size-adjust: 110%;
}

/* ============================================
   2. Image and Media Loading
   ============================================ */

/* Reserve aspect ratio space for images to prevent CLS */
img[width][height] {
    aspect-ratio: attr(width) / attr(height);
}

/* Specific image class handling */
img.img-responsive,
img.article-image,
.news-image img,
.post-thumbnail img {
    width: 100%;
    height: auto;
    display: block;
    background-color: #f0f0f0;
}

/* Video embed containers */
.video-container,
.embed-container,
iframe[src*="youtube"],
iframe[src*="vimeo"] {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
    border: none;
}

/* ============================================
   3. Container and Layout Optimization
   ============================================ */

/* Header should not shift */
header {
    contain: layout style paint;
    position: relative;
    z-index: 9999;
}

/* Navigation stability */
nav, .navbar, .menublock {
    contain: layout style paint;
}

/* Main content areas */
main,
.main-wrapper,
.container {
    contain: layout style paint;
}

/* Article specific */
.article-content-wrapper,
.content-wrapper,
article {
    contain: layout style paint;
}

/* ============================================
   4. Advertisement Sections
   ============================================ */

/* Reserve fixed height for ad slots to prevent shifts */
.ad-slot-reserved,
.BlockAds,
.Adv-container,
.Headerads,
[id*="ad"],
[class*="ad-"] {
    min-height: 250px;
    max-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    overflow: hidden;
    contain: layout style paint;
}

/* Smaller ad slots */
.ad-slot-small {
    min-height: 90px;
    max-height: 100px;
}

/* ============================================
   5. Text and Typography
   ============================================ */

/* Consistent line heights to prevent shift on font load */
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. Lazy Loading Support
   ============================================ */

/* Placeholder for lazy-loaded images */
img.lazyload,
img.lazy,
img[loading="lazy"],
[data-src] {
    background-color: #efefef;
    min-height: 100px;
}

/* Prevent placeholder flickering */
.lazyload-container,
.lazy-container {
    background-color: #f0f0f0;
    position: relative;
}

/* ============================================
   7. 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;
}

/* Date and time elements should not shift */
.TimeDate,
.article-meta,
.post-meta,
.article-info {
    display: flex;
    white-space: nowrap;
}

/* ============================================
   8. Timing and Animation
   ============================================ */

/* Reduce motion for better perceived performance */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   9. Print and Responsive Adjustments
   ============================================ */

@media print {
    .ad-slot-reserved,
    .BlockAds,
    .ads,
    [class*="ad-"] {
        display: none !important;
    }
}

/* Mobile optimization to prevent CLS on small screens */
@media (max-width: 768px) {
    .article-content-wrapper {
        min-height: auto;
    }

    .ad-slot-reserved,
    .BlockAds {
        min-height: 150px;
        max-height: 200px;
    }
}

/* ============================================
   10. Shadow DOM and Web Components
   ============================================ */

/* Ensure web components don't cause layout shifts */
:host,
:host([hidden]) {
    display: none;
}

/* Custom elements should have defined dimensions */
custom-element {
    display: block;
    width: 100%;
}