/**
 * Performance Optimizations CSS
 * تحسينات الأداء والتجربة البصرية
 * Version: 1.0.0
 */

/* ============================================
   1. تحسين الخطوط (Font Loading Optimization)
   ============================================ */

/* استخدام font-display: swap لتحسين أداء تحميل الخطوط */
@font-face {
    font-family: 'Amiri';
    font-display: swap;
    /* يتم تحميل الخط من Google Fonts في layouts.app */
}

@font-face {
    font-family: 'Cairo';
    font-display: swap;
}

@font-face {
    font-family: 'Noto Sans Arabic';
    font-display: swap;
}

/* ============================================
   2. تحسين الصور (Image Optimization)
   ============================================ */

/* Lazy Loading للصور */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Placeholder للصور أثناء التحميل */
img:not([src]) {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

/* تحسين عرض الصور */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ============================================
   3. تحسين الأنيميشن (Animation Performance)
   ============================================ */

/* استخدام will-change للعناصر المتحركة */
.animate-slide-up,
.animate-fade-in,
.animate-float {
    will-change: transform, opacity;
}

/* إيقاف الأنيميشن عند عدم الحاجة */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* تحسين أداء الأنيميشن باستخدام transform بدلاً من position */
.smooth-transform {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ============================================
   4. تحسين التمرير (Scroll Performance)
   ============================================ */

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* تحسين أداء التمرير */
* {
    -webkit-overflow-scrolling: touch;
}

/* إخفاء scrollbar في بعض المتصفحات لتحسين الأداء */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* ============================================
   5. تحسين الظلال (Shadow Optimization)
   ============================================ */

/* استخدام box-shadow محسّن */
.optimized-shadow {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.optimized-shadow-lg {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ============================================
   6. تحسين الـ Hover Effects
   ============================================ */

/* تحسين أداء hover باستخدام transform */
.hover-lift {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ============================================
   7. تحسين الـ Grid & Flexbox
   ============================================ */

/* تحسين أداء Grid */
.optimized-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    contain: layout style;
}

/* تحسين أداء Flexbox */
.optimized-flex {
    display: flex;
    contain: layout style;
}

/* ============================================
   8. تحسين الـ Cards
   ============================================ */

.optimized-card {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    will-change: transform;
    contain: layout style paint;
}

.optimized-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ============================================
   9. تحسين الـ Loading States
   ============================================ */

/* Skeleton Loading Animation */
@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-loader {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* ============================================
   10. تحسين الـ Buttons
   ============================================ */

.optimized-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    outline: none;
    position: relative;
    overflow: hidden;
}

.optimized-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.optimized-btn:hover::before {
    width: 300px;
    height: 300px;
}

/* ============================================
   11. تحسين الـ Forms
   ============================================ */

.optimized-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    outline: none;
}

.optimized-input:focus {
    border-color: var(--primary-color, #1d8a4e);
    box-shadow: 0 0 0 3px rgba(29, 138, 78, 0.1);
}

/* ============================================
   12. تحسين الـ Modals & Overlays
   ============================================ */

.optimized-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.optimized-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   13. تحسين الـ Navigation
   ============================================ */

.optimized-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    will-change: transform;
}

.optimized-nav.hidden {
    transform: translateY(-100%);
}

/* ============================================
   14. تحسين الـ Dark Mode
   ============================================ */

/* تم تعطيل التطبيق التلقائي للوضع الليلي - يتم التفعيل فقط عند الضغط على الزر */
/* @media (prefers-color-scheme: dark) {
    :root {
        --bg-light: #1a1a1a;
        --bg-white: #2d2d2d;
        --text-dark: #ffffff;
        --text-muted: #b0b0b0;
        --border-color: #404040;
    }

    body {
        background-color: var(--bg-light);
        color: var(--text-dark);
    }

    .optimized-card {
        background: var(--bg-white);
        border-color: var(--border-color);
    }

    .skeleton-loader {
        background: linear-gradient(90deg, #2d2d2d 25%, #3d3d3d 50%, #2d2d2d 75%);
        background-size: 200% 100%;
    }
} */

/* الوضع الليلي يتم تطبيقه فقط عند إضافة class="dark-mode" للـ body */
body.dark-mode {
    background-color: #1a1a1a !important;
    color: #e8e8e8 !important;
}

body.dark-mode .optimized-card,
body.dark-mode .card,
body.dark-mode .scholar-card,
body.dark-mode .thinker-card,
body.dark-mode .lecture-card,
body.dark-mode .article-card {
    background: #2d2d2d !important;
    border-color: #404040 !important;
    color: #e8e8e8 !important;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
    color: #d4af37 !important;
}

body.dark-mode .text-muted {
    color: #b0b0b0 !important;
}

body.dark-mode .btn-primary {
    background: linear-gradient(135deg, #1d8a4e 0%, #28a745 100%) !important;
    border-color: #1d8a4e !important;
    color: #ffffff !important;
}

body.dark-mode .btn-outline-primary {
    border-color: #1d8a4e !important;
    color: #1d8a4e !important;
}

body.dark-mode .btn-outline-primary:hover {
    background: #1d8a4e !important;
    color: #ffffff !important;
}

body.dark-mode .navbar {
    background: linear-gradient(135deg, #0a4d2e 0%, #0f7346 100%) !important;
}

body.dark-mode .footer {
    background: linear-gradient(135deg, #0a4d2e 0%, #0f7346 100%) !important;
}

body.dark-mode .skeleton-loader {
    background: linear-gradient(90deg, #2d2d2d 25%, #3d3d3d 50%, #2d2d2d 75%) !important;
    background-size: 200% 100%;
}

/* ============================================
   15. تحسين الطباعة (Print Optimization)
   ============================================ */

@media print {
    /* إخفاء العناصر غير الضرورية عند الطباعة */
    .no-print,
    nav,
    footer,
    .btn,
    .toast-container {
        display: none !important;
    }

    /* تحسين الألوان للطباعة */
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }

    /* تحسين الصفحات */
    @page {
        margin: 2cm;
    }

    /* منع تقسيم العناصر */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }

    img {
        page-break-inside: avoid;
    }
}

/* ============================================
   16. Utility Classes للأداء
   ============================================ */

/* GPU Acceleration */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Contain للأداء */
.contain-layout {
    contain: layout;
}

.contain-paint {
    contain: paint;
}

.contain-strict {
    contain: strict;
}

/* Content Visibility للأداء */
.content-auto {
    content-visibility: auto;
}

/* ============================================
   17. تحسين الـ Accessibility
   ============================================ */

/* Focus Visible */
*:focus-visible {
    outline: 2px solid var(--primary-color, #1d8a4e);
    outline-offset: 2px;
}

/* Skip to Content */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color, #1d8a4e);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-content:focus {
    top: 0;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

