/* ==========================================================================
   QURAN.CSS - أنماط وحدة القرآن الكريم والمصحف الشريف
   ========================================================================== */

/* 1. تعريف الخطوط */
@font-face {
    font-family: 'KFGQPC Uthmanic Script';
    src: url('../fonts/uthman_v2-0.ttf') format('opentype'),
         url('../fonts/uthman_v2-0.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'AmiriQuran';
    src: url('../fonts/amiri-quran.ttf') format('opentype'),
         url('../fonts/amiri-quran.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

/* 2. المتغيرات المحلية للتحكم بالخط */
:root {
    --quran-font-size: 22px;
}

/* 3. تخطيط صفحة المصحف والتبويبات */
.quran-layout-wrap {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 2rem;
}

/* 4. تصميم قائمة السور والأجزاء (Grid Layout) */
.quran-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    margin-top: 0.5rem;
}

/* في الشاشات الكبيرة يظهر على ثلاثة أعمدة بالضبط */
@media (min-width: 992px) {
    .quran-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.quran-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 6px);
    padding: 1.75rem 1.5rem;
    display: flex;
    flex-direction: column !important; /* تخطيط رأسي متسق وسيمتري */
    align-items: center !important;
    text-align: center !important;
    gap: 0.85rem;
    text-decoration: none !important;
    color: var(--text) !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.quran-card:hover {
    transform: translateY(-4px);
    border-color: #b45309;
    box-shadow: 0 8px 20px rgba(180, 83, 9, 0.1) !important;
}

.quran-card::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    transition: background-color 0.2s ease;
}

.quran-card:hover::after {
    background-color: #b45309;
}

/* حالة اختيار البطاقة وإبرازها */
.quran-card.active {
    border-color: #b45309 !important;
    background: #fffcf4 !important; /* خلفية كريمية دافئة تليق بالمصحف */
    box-shadow: 0 8px 25px rgba(180, 83, 9, 0.16) !important;
    transform: translateY(-4px);
}

.quran-card.active::after {
    background-color: #b45309 !important;
}

.quran-card.active .quran-card-num {
    background: #b45309 !important;
    color: #ffffff !important;
    border-color: #b45309 !important;
}

[data-theme="dark"] .quran-card.active {
    background: #24201e !important;
    border-color: #d97706 !important;
    box-shadow: 0 8px 25px rgba(217, 119, 6, 0.15) !important;
}

[data-theme="dark"] .quran-card.active::after {
    background-color: #d97706 !important;
}

[data-theme="dark"] .quran-card.active .quran-card-num {
    background: #d97706 !important;
    color: #1c1917 !important;
    border-color: #d97706 !important;
}

/* رقم السورة أو الجزء الدائري (أصغر وموضع في أعلى اليمين) */
.quran-card-num {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    color: #b45309;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.quran-card:hover .quran-card-num {
    background: #b45309;
    color: #ffffff;
    border-color: #b45309;
}

.quran-card-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
    width: 100%;
}

.quran-card-name {
    font-family: var(--font-title);
    font-weight: 800;
    font-size: 1.35rem;
    margin: 0;
    color: var(--text);
}

.quran-card-meta {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* 5. شاشة عرض السورة (View Page) */
.quran-view-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.quran-view-header {
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.quran-view-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.quran-view-title h2 {
    font-family: var(--font-title);
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
    color: var(--text);
}

/* لوحة التحكم بالقراءة (حجم الخط والنمط) */
.quran-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.quran-btn-ctrl {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
    transition: all 0.2s ease;
}

/* 6. جسم المصحف الشريف وعرض النصوص */
.quran-text-body {
    padding: 2.5rem 2rem;
    direction: rtl;
    text-align: justify;
    text-align-last: center;
    line-height: 2.4; /* تم تحسينه وتخفيضه بشكل طفيف لزيادة تماسك الحركات بصرياً مع السطر */
    background: var(--bg);
    color: #1c1917; /* لون حبر داكن ومريح للعين */
    max-width: 800px;
    margin: 0 auto;
}

/* التجاوب مع الشاشات الصغيرة لتجنب تباعد الكلمات والخطوط الكبيرة */
@media (max-width: 768px) {
    .quran-text-body {
        padding: 1.25rem 1rem;
        text-align: justify;
        text-align-last: center;
        line-height: 2.2; /* زيادة متناسبة للجوال والتابلت */
    }
    .quran-basmalah {
        margin-bottom: 1.25rem;
    }
    :root {
        --quran-font-size: 16px;
    }
}


@media (max-width: 480px) {
    .quran-text-body {
        padding: 1rem 0.5rem;
        line-height: 2.3; /* زيادة متناسبة لشاشات الجوال الصغيرة */
    }
    :root {
        --quran-font-size: 16px;
    }
}


/* تخصيص الثيم الداكن للنص القرآني */
[data-theme="dark"] .quran-text-body {
    color: #e7e5e4;
}

.quran-font-amiri {
    font-family: 'AmiriQuran', 'Traditional Arabic', 'Amiri', 'Noto Naskh Arabic', serif;
    font-size: var(--quran-font-size);
    text-rendering: optimizeLegibility;
    font-feature-settings: "ccmp" 1, "locl" 1, "calt" 1, "liga" 1, "clig" 1, "rlig" 1, "mark" 1, "mkmk" 1;
}

.quran-font-uthmanic {
    font-family: 'KFGQPC Uthmanic Script', 'AmiriQuran', serif;
    font-size: var(--quran-font-size);
    text-rendering: optimizeLegibility;
    font-feature-settings: "ccmp" 1, "locl" 1, "calt" 1, "liga" 1, "clig" 1, "rlig" 1, "mark" 1, "mkmk" 1;
}

/* البسملة */
.quran-basmalah {
    text-align: center;
    font-size: 1.05em; /* تم تصغيرها لتناسب حجم النص القرآني العام */
    margin-bottom: 2rem;
    font-weight: bold;
    display: block;
    color: var(--primary);
}

/* علامات الوقف الصغيرة */
.quran-pause-mark {
    font-size: 0.78em;
    opacity: 0.85;
}

/* مسافة أفقية خفيفة لمنع تداخل ذيل الواو مع الهمزة السفلية للألف */
.quran-waw-alif-gap {
    margin-right: 0.12em;
}

/* مسافة أفقية لمنع تداخل علامة المد مع الهمزة التالية لها في خط المدينة */
.quran-maddah-gap {
    margin-right: 0.15em;
}

/* إطار رأس السورة الزخرفي المصحفي */
.surah-header-ornament {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 1.5rem auto 0.5rem auto;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.surah-header-ornament svg {
    width: 100%;
    height: auto;
    display: block;
}



/* تظليل الآية النشطة عند القراءة وتتبع الموضع */
.quran-ayah {
    transition: background-color 0.25s ease;
    padding: 0 4px;
    margin: 0 -2px;
    border-radius: 3px;
    cursor: pointer;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.quran-ayah:hover {
    background: linear-gradient(to bottom, transparent 22%, rgba(217, 119, 6, 0.08) 22%, rgba(217, 119, 6, 0.08) 95%, transparent 95%) !important;
}

.quran-ayah.active-reading {
    background: linear-gradient(to bottom, transparent 22%, rgba(217, 119, 6, 0.14) 22%, rgba(217, 119, 6, 0.14) 95%, transparent 95%) !important;
}

.ayah-number {
    font-family: 'AmiriQuran', 'KFGQPC Uthmanic Script', 'Traditional Arabic', 'Amiri', serif;
    font-size: 0.78em; /* تقليص الحجم ليتناسب مع ارتفاع الحروف العربية وتفادي المظهر الضخم */
    color: #b45309; /* لون ذهبي/نحاسي للمكافأة البصرية */
    font-weight: normal;
    margin: 0;
    margin-inline-start: -0.15em; /* استخدام هامش سالب لتقريب القوس من نهاية الآية ومقاومة فراغات الخط المدمجة */
    margin-inline-end: -0.1em;    /* استخدام هامش سالب لتقريب الآية التالية ومنع الفراغ العريض */
    display: inline-block; /* استخدام inline-block لتطبيق الهوامش الثابتة بدقة */
    user-select: none;
    direction: rtl; /* تغييره لـ rtl ليتناسب مع التترتيب الطبيعي للأقواس ﴿ ﴾ في كود الـ HTML */
}

/* وضع قائمة الآيات (Ayah-by-Ayah Mode) */
.quran-ayah-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-width: 850px;
    margin: 0 auto;
    padding: 1.5rem;
}

.quran-ayah-item {
    padding: 1.25rem 1rem;
    border-bottom: 1px dashed var(--border);
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    transition: background 0.15s ease;
}

.quran-ayah-item:hover {
    background: var(--bg-alt);
}

.quran-ayah-item:last-child {
    border-bottom: none;
}

/* منع اختفاء الآية تحت الهيدر المثبت عند التمرير التلقائي */
.quran-ayah, 
.quran-ayah-item {
    scroll-margin-top: 120px !important;
}

.quran-ayah-badge {
    width: 32px;
    height: 32px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.quran-ayah-content {
    flex-grow: 1;
    text-align: right;
    line-height: 2.3; /* زيادة ارتفاع السطر في وضع قائمة الآيات لتفادي تداخل الحركات رأسياً */
}

/* 7. صفحة البحث وإبراز الكلمات */
.quran-search-form-wrap {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.quran-search-result-info {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.quran-search-results-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.quran-search-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: var(--transition);
}

.quran-search-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.quran-search-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.5rem;
}

.quran-search-item-title {
    font-weight: 700;
    color: var(--primary);
}

.quran-search-item-link {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
}

.quran-search-item-link:hover {
    color: var(--danger);
}

/* تظليل الكلمة المبحوث عنها باللون الأحمر وبدون خلفية صفراء */
.highlight-quran {
    background-color: transparent !important;
    color: #dc2626 !important;
    padding: 0;
    border-radius: 0;
    font-family: inherit !important;
    font-weight: inherit !important; /* وراثة سمك الخط لمنع المتصفح من استدعاء خط بديل يعرض ZWJ كعلامات اقتباس */
    font-feature-settings: inherit !important;
    text-rendering: inherit !important;
    border-bottom: none;
    box-shadow: none;
}

/* تنسيق نص البحث القرآني لتجنب التباعد والخط الكبير على الموبايل */
.quran-search-item-text {
    font-size: 24px;
    line-height: 2.3; /* زيادة ارتفاع السطر في صفحة البحث لتفادي تداخل الحركات رأسياً */
    text-align: justify;
    color: #1c1917;
}

@media (max-width: 768px) {
    .quran-search-item-text {
        font-size: 18px;
        text-align: center;
        line-height: 2.0;
    }
}

@media (max-width: 480px) {
    .quran-search-item-text {
        font-size: 16px;
        line-height: 1.9;
    }
}


/* الفلترة الفورية للسور بالـ JS */
.surahs-filter-wrap {
    max-width: 400px;
    margin-bottom: 1.25rem;
}

/* 8. أنماط الطباعة للنتائج */
@media print {
    /* إخفاء القائمة الجانبية، الهيدر، الفلاتر، ونموذج البحث، وأزرار التنقل */
    body {
        background: #ffffff !important;
        color: #000000 !important;
    }
    
    .navbar, 
    #sidebar-drawer, 
    #drawer-overlay, 
    #menu-toggle, 
    .page-header, 
    .tabs-nav, 
    .quran-search-form-wrap, 
    .no-print, 
    button, 
    .quran-search-item-link,
    footer,
    .footer {
        display: none !important;
    }

    /* إزالة الهوامش والظلال والتوسيع للورقة */
    .main-content, 
    .content-wrapper, 
    .container, 
    .card, 
    .card-body {
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* تنسيق بطاقات نتائج البحث المطبوعة */
    .quran-search-results-list {
        display: block !important;
    }

    .quran-search-item {
        page-break-inside: avoid;
        border: none !important;
        border-bottom: 1px solid #000000 !important;
        margin-bottom: 20px !important;
        padding: 15px 0 !important;
    }

    .quran-search-item-header {
        font-size: 12px !important;
        color: #000000 !important;
        border-bottom: 1px dashed #000000 !important;
        margin-bottom: 10px !important;
        padding-bottom: 5px !important;
    }

    .quran-search-item-title {
        color: #000000 !important;
        font-weight: bold !important;
    }

    .quran-font-amiri {
        font-family: 'AmiriQuran', serif !important;
        font-size: 20px !important;
        line-height: 1.8 !important;
        color: #000000 !important;
    }

    .quran-font-uthmanic {
        font-family: 'AmiriQuran', serif !important;
        font-size: 20px !important;
        line-height: 1.8 !important;
        color: #000000 !important;
    }

    /* تلوين الكلمة المبحوث عنها باللون الأحمر في الطباعة */
    .highlight-quran {
        background-color: transparent !important;
        color: #dc2626 !important;
        font-family: 'AmiriQuran', 'KFGQPC Uthmanic Script', serif !important;
        font-weight: inherit !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ==========================================================================
   مؤشر قراءة عائم وجذاب (Glassmorphism)
   ========================================================================== */
.quran-floating-indicator {
    position: fixed;
    left: 24px;
    top: 200px;
    z-index: 999;
    width: 150px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(180, 83, 9, 0.15);
    border-radius: var(--radius-lg, 12px);
    padding: 0.5rem 0.75rem;
    box-shadow: 0 8px 30px rgba(180, 83, 9, 0.08);
    transition: all 0.3s ease;
    direction: rtl;
}

.quran-floating-indicator:hover {
    box-shadow: 0 12px 40px rgba(180, 83, 9, 0.15);
    border-color: rgba(180, 83, 9, 0.3);
}

.quran-indicator-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #b45309;
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid rgba(180, 83, 9, 0.1);
    display: flex;
    align-items: center;
    gap: 4px;
}

.quran-indicator-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    font-size: 0.8rem;
}

.quran-indicator-row:not(:last-child) {
    border-bottom: 1px dashed rgba(0, 0, 0, 0.05);
}

.quran-indicator-label {
    color: var(--text-muted);
}

.quran-indicator-val {
    font-weight: 700;
    color: var(--text);
    font-family: 'AmiriQuran', 'KFGQPC Uthmanic Script', 'Traditional Arabic', serif;
    font-size: 0.9rem;
}

/* التوافق مع الثيم الداكن */
[data-theme="dark"] .quran-floating-indicator {
    background: rgba(28, 25, 23, 0.85);
    border-color: rgba(217, 119, 6, 0.2);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .quran-indicator-row:not(:last-child) {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .quran-indicator-title {
    color: #d97706;
    border-bottom-color: rgba(217, 119, 6, 0.15);
}

/* إخفاء المؤشر في الشاشات الصغيرة لتجنب تغطية المحتوى */
@media (max-width: 1200px) {
    .quran-floating-indicator {
        display: none !important;
    }
}

/* ==========================================================================
   تنسيق ورقة طباعة مقاطع اختبار الحفظ
   ========================================================================== */
.print-paper {
    background: #ffffff;
    color: #1c1917;
    position: relative;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.print-border-frame {
    border: 3px double #d97706;
    padding: 30px;
    border-radius: 6px;
    background: #fdfcf7;
}

.print-test-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #d97706;
}

.print-test-title {
    font-size: 1.8rem;
    font-weight: bold;
    color: #b45309;
    font-family: 'AmiriQuran', 'KFGQPC Uthmanic Script', 'Traditional Arabic', serif;
    margin-bottom: 8px;
}

.print-test-range {
    font-size: 1.05rem;
    color: #78716c;
}

.print-metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
    padding: 15px;
    background: #fbf9f5;
    border: 1px dashed #e4e4e7;
    border-radius: 6px;
}

.print-meta-col {
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.print-dotted-line {
    flex-grow: 1;
    border-bottom: 1px dotted #a8a29e;
    height: 15px;
}

.print-passages-list {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.print-passage-item {
    page-break-inside: avoid;
    border-bottom: 1px dashed rgba(217, 119, 6, 0.2);
    padding-bottom: 20px;
}

.print-passage-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.print-passage-title {
    font-size: 1.3rem;
    font-family: 'Hacen', 'Tajawal', 'Cairo', sans-serif;
    font-weight: bold;
    color: #b45309;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.print-passage-content {
    font-size: 1.55rem;
    line-height: 2.2;
    text-align: justify;
    padding: 0 10px;
    color: #1c1917;
}

@media (max-width: 768px) {
    .print-passage-content {
        font-size: 1.25rem;
        text-align: center;
        padding: 0 5px;
        line-height: 1.9;
    }
}


.print-test-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 15px;
    border-top: 1px solid rgba(217, 119, 6, 0.2);
    font-size: 0.85rem;
    color: #78716c;
    page-break-inside: avoid;
    break-inside: avoid;
}

/* تعديلات الطباعة لورقة الاختبار */
@media print {
    @page {
        margin: 1.2cm;
    }
    /* إخفاء شريط التنقل العلوي وفتات الخبز وعناصر التحكم عند الطباعة */
    #topbar,
    #sidebar,
    #footer,
    .no-print,
    .breadcrumb-bar,
    .breadcrumb-list,
    .breadcrumbs-bar,
    header,
    footer,
    nav {
        display: none !important;
    }

    .print-paper {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .print-border-frame {
        border: 4px double #000000 !important;
        background: #ffffff !important;
        padding: 20px !important;
    }

    .print-test-header {
        border-bottom-color: #000000 !important;
    }

    .print-test-title {
        color: #000000 !important;
    }

    .print-metadata-grid {
        background: #ffffff !important;
        border-color: #000000 !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
        padding: 10px !important;
    }

    .print-passage-title {
        color: #000000 !important;
    }

    .print-passage-content {
        color: #000000 !important;
        font-size: 1.8rem !important;
        line-height: 2.1 !important;
    }
}

/* ==========================================================================
   رسالة تنبيه الشاشات الصغيرة في صفحة اختبار الحفظ
   ========================================================================== */
.quran-mobile-warning {
    display: none;
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--bg-alt);
    border: 1px dashed #d97706;
    border-radius: var(--radius-lg, 12px);
    margin: 2rem auto;
    max-width: 500px;
    box-shadow: var(--shadow-sm);
    direction: rtl;
}

.quran-mobile-warning-title {
    font-size: 1.35rem;
    font-weight: bold;
    color: #b45309;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.quran-mobile-warning-text {
    font-size: 1.05rem;
    color: var(--text-muted);
    line-height: 1.7;
}

/* التبديل التلقائي عند الشاشات الصغيرة للجوالات */
@media (max-width: 768px) {
    .hide-on-mobile {
        display: none !important;
    }
    .quran-mobile-warning {
        display: block !important;
    }
}


