/* =============================================
   CSS إضافي غير حرج - يتم تحميله بشكل غير متزامن
   ============================================= */

/* ========== توافق الأزرار والعناصر التفاعلية مع جميع الأجهزة ========== */
@media (max-width: 768px) {
    .btn, a.btn, .btn-primary, .btn-secondary, .hero-cta,
    .filter-btn, .hero-btn, .cta-buttons a, .product-card .btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 20px !important;
        box-sizing: border-box !important;
    }
    button:not(.menu-toggle) {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 20px !important;
        box-sizing: border-box !important;
    }
    .fab-btn, .contact-icon {
        min-width: 48px !important;
        min-height: 48px !important;
    }
    /* مجموعات الأزرار — التفاف وعدم خروج عن الشاشة */
    .cta-buttons, .hero-buttons, .articles-footer {
        flex-wrap: wrap !important;
        gap: 12px !important;
        justify-content: center !important;
    }
    .side-menu a {
        min-height: 48px !important;
        padding: 15px 20px !important;
        display: flex !important;
        align-items: center !important;
    }
}

@media (max-width: 480px) {
    .btn, a.btn, .btn-primary, .btn-secondary, .filter-btn {
        padding: 12px 16px !important;
        font-size: 0.95rem !important;
    }
}

/* حقول النماذج — حجم لمس وعدم تكبير تلقائي على iOS */
@media (max-width: 768px) {
    input[type="text"], input[type="email"], input[type="tel"], input[type="number"],
    select, textarea {
        min-height: 44px !important;
        font-size: 16px !important;
    }
    textarea {
        min-height: 100px !important;
    }
}

/* منطقة آمنة للأزرار الثابتة (هواتف ذات نوتش) */
.fixed-buttons {
    bottom: max(15px, env(safe-area-inset-bottom)) !important;
    left: max(15px, env(safe-area-inset-left)) !important;
}

/* منع Layout Shift - تحسين الخطوط */
html.fonts-loaded { font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif; }

/* إصلاح مشاكل الصور - منع layout shift */
img[width][height] { 
    aspect-ratio: attr(width) / attr(height); 
}
img:not([width]):not([height]) { 
    aspect-ratio: 16/9; 
    width: 100%;
    height: auto;
}

/* تحسين lazy loading للصور */
img[loading="lazy"] {
    opacity: 1;
    transition: opacity 0.3s ease;
}
img[loading="lazy"].loaded {
    opacity: 1;
}

/* إصلاح حجم الـ logo فقط */
.logo-img {
    width: 60px !important;
    height: 60px !important;
    object-fit: cover !important;
    border-radius: 8px !important;
}

/* منع forced reflow */
* { will-change: auto; }
.performance-critical { will-change: transform; }

/* تحسينات إضافية للأداء */
.hero-banner, .swiper-slide {
    contain: layout style paint;
    transform: translateZ(0);
}

/* منع layout shift للعناصر الحرجة */
.fixed-buttons {
    contain: layout;
}

/* تحسينات للتحميل */
.loading { opacity: 0; transition: opacity 0.3s ease; }
.loaded { opacity: 1; }

/* على الجوال: تقليل حجم العناوين لتناسب الشاشة */
@media (max-width: 768px) {
    h1, .h1 { font-size: 1.625rem; line-height: 1.3; }
    h2, .h2 { font-size: 1.375rem; line-height: 1.35; }
    h3, .h3 { font-size: 1.2rem; line-height: 1.4; }
    h4, .h4 { font-size: 1.1rem; }
    h5, .h5, h6, .h6 { font-size: 1rem; }
}

/* إصلاح خاص للشاشات الصغيرة */
@media (max-width: 768px) {
    html, body {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    body {
        font-size: 1rem;
    }
    
    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 15px !important;
        margin: 0 !important;
    }
    
    main {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* إصلاح العناصر التي قد تسبب overflow */
    .hero-section,
    .product-grid,
    .article-grid,
    .swiper-container,
    .swiper-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* ===== إصلاح زر الهامبرغر للشاشات الصغيرة ===== */

/* زر القائمة للشاشات الصغيرة */
.menu-toggle {
    display: none;
    cursor: pointer;
    padding: 10px;
    background: #205781;
    border-radius: 5px;
    z-index: 1001;
}

.menu-toggle .icon-bars {
    display: block;
    width: 25px;
    height: 3px;
    background-color: white;
    margin: 5px 0;
    transition: 0.3s;
    position: relative;
}

.menu-toggle .icon-bars::before,
.menu-toggle .icon-bars::after {
    content: '';
    position: absolute;
    width: 25px;
    height: 3px;
    background-color: white;
    transition: 0.3s;
}

.menu-toggle .icon-bars::before {
    top: -8px;
}

.menu-toggle .icon-bars::after {
    bottom: -8px;
}

/* تحريك الأشرطة عند التفعيل */
.menu-toggle.active .icon-bars {
    background-color: transparent;
}

.menu-toggle.active .icon-bars::before {
    transform: rotate(45deg);
    top: 0;
}

.menu-toggle.active .icon-bars::after {
    transform: rotate(-45deg);
    bottom: 0;
}

/* على الديسكتوب: إخفاء القائمة الجانبية والـ overlay */
@media (min-width: 769px) {
    .side-menu,
    .menu-overlay {
        display: none !important;
    }
}

/* إظهار زر القائمة في الشاشات الصغيرة */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        order: 1;
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
        background: #205781 !important;
        color: white !important;
        border: none;
        border-radius: 8px;
    }
    .menu-toggle:hover,
    .menu-toggle:focus {
        background: #133a56 !important;
        color: white !important;
    }
    .menu-toggle .menu-icon {
        display: block !important;
        font-size: 1.5rem;
        line-height: 1;
        color: inherit;
    }
    .mobile-search-toggle {
        color: #205781 !important;
    }
    .mobile-search-toggle:hover {
        background: rgba(32, 87, 129, 0.1) !important;
        color: #133a56 !important;
    }
    
    .main-nav {
        display: none !important;
    }
    
    .main-nav.active {
        display: block !important;
        position: fixed;
        top: 0;
        right: -300px;
        width: 300px;
        height: 100vh;
        background: white;
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }
    
    /* إظهار القائمة الجانبية */
    .side-menu {
        display: block !important;
        position: fixed;
        top: 0;
        right: -300px;
        width: 300px;
        height: 100vh;
        background: white;
        z-index: 1000;
        transition: right 0.3s ease;
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    }
    
    .side-menu.active {
        right: 0;
    }
    .side-menu .menu-content {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .side-menu .menu-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 20px;
        background: linear-gradient(135deg, #205781 0%, #133a56 100%);
        color: white;
    }
    
    .side-menu .menu-header h3,
    .side-menu .menu-title {
        margin: 0;
        font-size: 1.2rem;
        font-weight: 700;
        color: white;
    }
    
    .side-menu .menu-close {
        font-size: 28px;
        line-height: 1;
        cursor: pointer;
        color: white !important;
        background: rgba(255,255,255,0.15);
        border: none;
        padding: 4px 10px;
        border-radius: 6px;
    }
    .side-menu .menu-close:hover {
        background: rgba(255,255,255,0.25);
        color: white !important;
    }
    
    .side-menu ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    
    .side-menu li {
        border-bottom: 1px solid #f0f0f0;
    }
    
    .side-menu a {
        display: block;
        padding: 15px 20px;
        color: #333;
        text-decoration: none;
        transition: background-color 0.2s ease, color 0.2s ease;
    }
    
    .side-menu a:hover {
        background: rgba(32, 87, 129, 0.08);
        color: #205781;
    }
    
    .side-menu a.active {
        background: linear-gradient(90deg, rgba(32, 87, 129, 0.15) 0%, transparent 100%);
        color: #205781;
        font-weight: 700;
        border-right: 4px solid #205781;
    }
}

/* Overlay للقائمة الجانبية */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.overlay.active {
    display: block;
}

/* overlay القائمة */
.menu-overlay {
    pointer-events: none;
}
.menu-overlay.active {
    pointer-events: auto;
}

@media (max-width: 768px) {
    .main-header .right-section .social-icons {
        display: flex !important;
    }
}

/* توافق الجداول مع الجوال — تمرير أفقي عند الضرورة */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

@media (max-width: 576px) {
    .fixed-buttons {
        bottom: 15px !important;
        left: 15px !important;
    }
    .fab-btn {
        width: 50px !important;
        height: 50px !important;
        font-size: 20px !important;
    }
}
