/**
 * CLS (Cumulative Layout Shift) Fixes - حلول جذرية لمشاكل تغيير التصميم
 * @package Lahzat_News
 * @version 1.0
 * 
 * هذا الملف يحتوي على حلول شاملة لمشاكل CLS:
 * 1. إصلاح تحميل الخطوط
 * 2. إصلاح تحميل الصور
 * 3. تحديد أبعاد ثابتة للعناصر
 * 4. تحسين استقرار التخطيط
 */

/* ========================================
   Font Loading Fixes - إصلاح تحميل الخطوط
   ======================================== */

/* استخدام font-display: swap لجميع الخطوط */
@font-face {
    font-family: 'Cairo';
    font-display: swap;
    src: local('Cairo'), local('Cairo-Regular');
}

@font-face {
    font-family: 'Kufi';
    font-display: swap;
    src: local('Kufi'), local('Kufi-Regular');
}

/* تحديد أبعاد الخطوط مسبقاً لمنع التغيير */
:root {
    /* أبعاد الخطوط الأساسية */
    --font-size-base: 16px;
    --font-size-h1: 32px;
    --font-size-h2: 28px;
    --font-size-h3: 24px;
    --font-size-h4: 20px;
    --font-size-h5: 18px;
    --font-size-h6: 16px;
    --font-size-small: 14px;
    --font-size-large: 18px;
    
    /* أبعاد الخطوط للموبايل */
    --font-size-mobile-base: 16px;
    --font-size-mobile-h1: 24px;
    --font-size-mobile-h2: 22px;
    --font-size-mobile-h3: 20px;
    --font-size-mobile-h4: 18px;
    --font-size-mobile-h5: 16px;
    --font-size-mobile-h6: 14px;
    
    /* أبعاد الخطوط للعناوين */
    --font-size-post-title: 28px;
    --font-size-post-title-mobile: 22px;
    --font-size-widget-title: 20px;
    --font-size-widget-title-mobile: 18px;
    
    /* أبعاد الخطوط للقوائم */
    --font-size-menu: 15px;
    --font-size-menu-mobile: 14px;
    
    /* أبعاد الخطوط للأزرار */
    --font-size-button: 14px;
    --font-size-button-mobile: 13px;
}

/* تطبيق الأبعاد الثابتة على جميع العناصر */
body {
    font-size: var(--font-size-base) !important;
    line-height: 1.6 !important;
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
}

h1, .entry-title, .article-title {
    font-size: var(--font-size-h1) !important;
    line-height: 1.3 !important;
    font-weight: 700 !important;
}

h2 {
    font-size: var(--font-size-h2) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

h3 {
    font-size: var(--font-size-h3) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

h4 {
    font-size: var(--font-size-h4) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

h5 {
    font-size: var(--font-size-h5) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

h6 {
    font-size: var(--font-size-h6) !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
}

/* عناوين المقالات */
.post-title, .grid-item-title, .list-item-title {
    font-size: var(--font-size-post-title) !important;
    line-height: 1.3 !important;
    font-weight: 700 !important;
}

/* عناوين الويدجتات */
.widget-title, .section-title {
    font-size: var(--font-size-widget-title) !important;
    line-height: 1.3 !important;
    font-weight: 700 !important;
}

/* القوائم */
.main-nav .menu > li > a {
    font-size: var(--font-size-menu) !important;
    font-weight: 600 !important;
}

/* الأزرار */
.btn, .button, button {
    font-size: var(--font-size-button) !important;
    font-weight: 600 !important;
}

/* النصوص الصغيرة */
.small, .meta, .breadcrumb {
    font-size: var(--font-size-small) !important;
}

/* النصوص الكبيرة */
.large, .lead {
    font-size: var(--font-size-large) !important;
}

/* ========================================
   Image Loading Fixes - إصلاح تحميل الصور
   ======================================== */

/* تحديد أبعاد ثابتة للصور البارزة */
.featured-image-container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    overflow: hidden;
    background: #f5f5f5;
    border-radius: 8px;
}

.featured-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    display: block;
}

/* تحديد أبعاد ثابتة لصور المقالات */
.post-thumbnail {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    overflow: hidden;
    background: #f5f5f5;
}

.post-thumbnail img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    display: block;
}

/* تحديد أبعاد ثابتة لصور الشبكة */
.posts-grid .post-card {
    position: relative;
    overflow: hidden;
}

.posts-grid .post-thumbnail {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 60%; /* نسبة مختلفة للشبكة */
    overflow: hidden;
    background: #f5f5f5;
}

.posts-grid .post-thumbnail img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    display: block;
}

/* تحديد أبعاد ثابتة لصور السليدرات */
.slider-image {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    overflow: hidden;
    background: #f5f5f5;
}

.slider-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
    display: block;
}

/* تحديد أبعاد ثابتة لصور الويدجتات */
.widget img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* تحديد أبعاد ثابتة لصور المحتوى */
.entry-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    border-radius: 8px;
}

/* ========================================
   Layout Stability Fixes - إصلاح استقرار التخطيط
   ======================================== */

/* تحديد أبعاد ثابتة للحاوي الرئيسي */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
}

/* تحديد أبعاد ثابتة للهيدر */
.site-header {
    position: sticky;
    top: 0;
    z-index: 999;
    height: 70px;
    min-height: 70px;
    max-height: 70px;
}

.header-inner {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* تحديد أبعاد ثابتة للوجو */
.site-logo img,
.custom-logo-link img {
    height: 70px;
    max-height: 70px;
    width: auto;
    display: block;
    object-fit: contain;
}

/* تحديد أبعاد ثابتة للمحتوى */
.site-content {
    min-height: 60vh;
    padding: 40px 0;
}

.content-area {
    width: 100%;
}

/* تحديد أبعاد ثابتة للشريط الجانبي */
.sidebar {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
}

/* تحديد أبعاد ثابتة للويدجتات */
.widget {
    margin-bottom: 30px;
    padding: 25px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 3px 15px rgba(0,0,0,0.08);
}

.widget-title {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid #00A859;
}

/* تحديد أبعاد ثابتة للفوتر */
.site-footer {
    margin-top: 60px;
    padding: 50px 0 0;
}

.footer-widgets {
    padding-bottom: 40px;
}

.footer-bottom {
    padding: 25px 0;
    text-align: center;
}

/* ========================================
   Grid Layout Fixes - إصلاح تخطيط الشبكة
   ======================================== */

/* تحديد أبعاد ثابتة لشبكة المقالات */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.post-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 3px 15px rgba(0,0,0,0.08);
    transition: transform 0.3s ease;
}

.post-card:hover {
    transform: translateY(-5px);
}

/* تحديد أبعاد ثابتة لشبكة الويدجتات */
.footer-widget-area {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 40px;
}

/* ========================================
   Mobile Responsive Fixes - إصلاح التجاوب للموبايل
   ======================================== */

@media (max-width: 768px) {
    /* أبعاد الخطوط للموبايل */
    body {
        font-size: var(--font-size-mobile-base) !important;
    }
    
    h1, .entry-title, .article-title {
        font-size: var(--font-size-mobile-h1) !important;
    }
    
    h2 {
        font-size: var(--font-size-mobile-h2) !important;
    }
    
    h3 {
        font-size: var(--font-size-mobile-h3) !important;
    }
    
    h4 {
        font-size: var(--font-size-mobile-h4) !important;
    }
    
    h5 {
        font-size: var(--font-size-mobile-h5) !important;
    }
    
    h6 {
        font-size: var(--font-size-mobile-h6) !important;
    }
    
    .post-title, .grid-item-title, .list-item-title {
        font-size: var(--font-size-post-title-mobile) !important;
    }
    
    .widget-title, .section-title {
        font-size: var(--font-size-widget-title-mobile) !important;
    }
    
    .main-nav .menu > li > a {
        font-size: var(--font-size-menu-mobile) !important;
    }
    
    .btn, .button, button {
        font-size: var(--font-size-button-mobile) !important;
    }
    
    /* أبعاد الهيدر للموبايل */
    .site-header {
        height: 60px;
        min-height: 60px;
        max-height: 60px;
    }
    
    .header-inner {
        height: 60px;
    }
    
    .site-logo img,
    .custom-logo-link img {
        height: 50px;
        max-height: 50px;
    }
    
    /* أبعاد الشبكة للموبايل */
    .posts-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .footer-widget-area {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    
    /* أبعاد الصور للموبايل */
    .featured-image-container {
        padding-bottom: 50%; /* نسبة مختلفة للموبايل */
    }
    
    .post-thumbnail {
        padding-bottom: 50%; /* نسبة مختلفة للموبايل */
    }
    
    .posts-grid .post-thumbnail {
        padding-bottom: 50%; /* نسبة مختلفة للموبايل */
    }
    
    .slider-image {
        padding-bottom: 50%; /* نسبة مختلفة للموبايل */
    }
}

/* ========================================
   Performance Optimizations - تحسينات الأداء
   ======================================== */

/* تحسين تحميل الصور */
img {
    loading: lazy;
    decoding: async;
    max-width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    object-position: center center;
}

/* تحسين تحميل الخطوط */
@font-face {
    font-family: 'Cairo';
    font-display: swap;
    src: local('Cairo'), local('Cairo-Regular');
}

@font-face {
    font-family: 'Kufi';
    font-display: swap;
    src: local('Kufi'), local('Kufi-Regular');
}

/* إصلاح الصور في المحتوى */
.entry-content img {
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    display: block !important;
    margin: 20px auto !important;
    border-radius: 8px !important;
}

/* إصلاح صور أحدث الأخبار */
.img-top-wrapper,
.img-left-side,
.featured-img-left,
.small-img-top {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 60% !important;
    overflow: hidden !important;
    background: #f5f5f5 !important;
}

.img-top-wrapper img,
.img-left-side img,
.featured-img-left img,
.small-img-top img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
}

/* إصلاح صور السليدرات */
.slider-image {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 56.25% !important;
    overflow: hidden !important;
    background: #f5f5f5 !important;
}

.slider-image img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
}

/* إصلاح صور النتائج */
.result-thumb,
.related-post-thumb {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 56.25% !important;
    overflow: hidden !important;
    background: #f5f5f5 !important;
}

.result-thumb img,
.related-post-thumb img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center center !important;
}

/* ========================================
   Accessibility Fixes - إصلاحات إمكانية الوصول
   ======================================== */

/* دعم الوضع المظلم */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --text-primary: #ffffff;
        --text-secondary: #cccccc;
    }
}

/* دعم التباين العالي */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000000;
        --text-primary: #000000;
        --bg-primary: #ffffff;
    }
}

/* دعم تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
        transform: none !important;
    }
}

/* ========================================
   Print Styles - أنماط الطباعة
   ======================================== */

@media print {
    .site-header,
    .site-footer,
    .sidebar {
        display: none;
    }
    
    .site-content {
        width: 100%;
        margin: 0;
        padding: 0;
    }
    
    .container {
        max-width: none;
        margin: 0;
        padding: 0;
    }
    
    .featured-image-container,
    .post-thumbnail {
        height: auto;
        padding-bottom: 0;
    }
    
    .featured-image-container img,
    .post-thumbnail img {
        position: static;
        width: 100%;
        height: auto;
    }
}
