/* ============================================================
   pages/library.css
   المكتبة العلمية + صفحة تفاصيل الكتاب
   ------------------------------------------------------------
   ما هو مشترك مع النظام (لا نكرره هنا):
     - .book-card, .books-grid, .cover-container  → component-system
     - .book-info, .book-title, .book-meta         → component-system
     - .book-footer, .book-actions                 → component-system
     - .btn, .btn-primary, .btn-outline            → component-system
     - .ui-empty-state, .no-results                → component-system
     - .pagination-wrap, .load-more                → component-system
   ------------------------------------------------------------
   الأقسام:
     PART 1 — رأس المكتبة (Library Header)
     PART 2 — شريط الأدوات والبحث
     PART 3 — شبكة الكتب (Books Grid)
     PART 4 — تفاصيل الكتاب: Hero (غلاف + معلومات)
     PART 5 — شبكة الميتا (Breadcrumb + Meta)
     PART 6 — نبذة الكتاب
     PART 7 — أزرار الإجراءات
     PART 8 — قسم الكتب ذات الصلة
     PART 9 — الاستجابة للجوال
     PART 10 — RTL / LTR
     PART 11 — حركات الدخول والطباعة
   ============================================================ */

/* ============================================================
   PART 1 — رأس المكتبة (Library Header)
   ============================================================ */
.header-lib {
    background: var(--primary-gradient);
    color: var(--white);
    padding: 28px 24px;
    border-radius: var(--radius-lg);
    text-align: center;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.subtitle {
    font-size: 1.08rem;
    color: rgba(255, 255, 255, 0.92);
    margin: 10px 0 0;
    line-height: 1.8;
}

/* ============================================================
   PART 2 — شريط الأدوات والبحث
   ============================================================ */
.search-container {
    padding: 18px;
    margin-bottom: 24px;
}

.library-content-full {
    width: 100%;
}

.library-topbar {
    flex-wrap: wrap;
    gap: 10px;
}

/* ============================================================
   PART 3 — شبكة الكتب (Books Grid)
   ============================================================ */
/* .books-grid معرّف في component-system.css */

/* ---------- غلاف الكتاب (Library — حجم مختلف عن book-details) ---------- */
.book-card .cover-container {
    height: 290px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #f8fafc 0%, #edf4fb 100%);
}

.book-card .cover-container img {
    width: auto;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    background: var(--white);
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(2, 6, 23, 0.12);
    transition: transform 0.28s ease, box-shadow 0.28s ease;
}

.book-card:hover .cover-container img {
    transform: scale(1.02);
    box-shadow: 0 12px 28px rgba(2, 6, 23, 0.18);
}

.book-card .cover-container::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-bottom: 1px solid rgba(15, 23, 42, 0.04);
}

/* ---------- جسم البطاقة ---------- */
.book-card .book-info {
    padding: 16px 18px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.book-card .author-tag {
    font-size: 0.84rem;
    padding: 6px 12px;
    display: inline-block;
    align-self: center;
    line-height: 1.5;
    max-width: 100%;
    word-break: break-word;
    text-align: center;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: var(--radius-pill);
    font-weight: 700;
}

.book-card .book-title {
    font-size: 1.08rem;
    margin: 0;
    line-height: 1.65;
    text-align: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.65em * 3);
    color: var(--primary-dark);
    font-weight: 800;
}

.book-card .book-meta {
    font-size: 0.92rem;
    line-height: 1.8;
    margin-top: 2px;
    min-height: 48px;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- تذييل البطاقة ---------- */
.book-card .book-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding-top: 10px;
    margin-top: auto;
}

.book-card .book-footer .btn {
    flex: 1 1 auto;
    width: auto;
    padding: 8px 14px;
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 40px;
    text-align: center;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.book-card .book-footer .btn.disabled,
.book-card .book-footer .btn[disabled] {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    background: #e9ecef;
    color: #6c757d;
    border-color: #ced4da;
}

/* ---------- حالة الفراغ (لا نتائج) ---------- */
.no-results {
    text-align: center;
    padding: 60px 20px;
    background: linear-gradient(180deg, #fff 0%, #f8fbff 100%);
    border: 1px dashed rgba(15, 111, 174, 0.22);
    border-radius: 24px;
}

.no-results i {
    font-size: 4rem;
    margin-bottom: 20px;
    color: var(--border-light);
    display: block;
}

.no-results h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--text-main);
}

/* ---------- زر تحميل المزيد ---------- */
.load-more-container {
    text-align: center;
    margin: 30px 0 10px;
}

.pagination-info {
    font-weight: 700;
    padding: 12px 18px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: var(--radius-pill);
}

.load-more {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--primary-gradient);
    color: var(--white);
    border: none;
    padding: 14px 24px;
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    text-decoration: none;
    border-radius: var(--radius-pill);
    transition: var(--transition);
}

.load-more:hover {
    transform: translateY(-3px);
    color: var(--white);
    box-shadow: var(--shadow-md);
}

.load-more:active {
    transform: translateY(-1px);
}

/* ============================================================
   PART 4 — تفاصيل الكتاب: Hero (غلاف + معلومات)
   ============================================================ */

/* ---------- الحاوية العامة ---------- */
.book-page-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 20px 80px;
    position: relative;
}

/* خلفية زخرفية خفيفة للصفحة */
.book-page-wrap::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 10%, rgba(59, 130, 246, 0.06), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(14, 116, 144, 0.05), transparent 45%);
    pointer-events: none;
}

/* ---------- مسار التنقل (Breadcrumb) ---------- */
.book-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 26px;
    padding: 12px 20px;
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--text-muted);
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.book-breadcrumb a {
    color: #0369a1;
    text-decoration: none;
    padding: 3px 10px;
    border-radius: 8px;
    transition: var(--transition-fast);
}

.book-breadcrumb a:hover,
.book-breadcrumb a:focus-visible {
    color: #0c4a6e;
    background: var(--primary-soft);
    outline: none;
}

.book-breadcrumb span:last-child {
    color: var(--text-dark);
    font-weight: 800;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- القسم الرئيسي (Hero) ---------- */
.book-hero {
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
    padding: 36px;
    border-radius: 28px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 60%, #eff6ff 100%);
    border: 1px solid var(--border-light);
    box-shadow:
        0 4px 6px rgba(15, 23, 42, 0.04),
        0 20px 50px -20px rgba(15, 23, 42, 0.15);
}

/* زخارف دقيقة في الخلفية */
.book-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at top right, rgba(59, 130, 246, 0.12), transparent 35%),
        radial-gradient(circle at bottom left, rgba(14, 116, 144, 0.08), transparent 40%);
    pointer-events: none;
}

.book-hero::after {
    content: "";
    position: absolute;
    top: -60px;
    right: -60px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.15), transparent 70%);
    pointer-events: none;
}

.book-cover-box,
.book-content {
    position: relative;
    z-index: 1;
}

/* ---------- صندوق الغلاف ---------- */
.book-cover-box {
    position: relative;
    perspective: 1200px;
}

.book-cover {
    width: 100%;
    display: block;
    border-radius: 20px;
    box-shadow:
        0 4px 8px rgba(15, 23, 42, 0.08),
        0 30px 60px -20px rgba(15, 23, 42, 0.35),
        0 0 0 1px rgba(15, 23, 42, 0.05) inset;
    background: var(--white);
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.5s ease;
    transform-style: preserve-3d;
}

.book-cover:hover {
    transform: translateY(-8px) rotateY(-3deg) rotateX(2deg);
    box-shadow:
        0 10px 20px rgba(15, 23, 42, 0.12),
        0 40px 80px -20px rgba(15, 23, 42, 0.45);
}

/* شريط زخرفي أسفل الغلاف (ظل أرضي) */
.book-cover-box::after {
    content: "";
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    height: 20px;
    background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.18), transparent 70%);
    border-radius: 50%;
    filter: blur(10px);
    z-index: -1;
}

/* ---------- محتوى الكتاب ---------- */
.book-content {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* شارة علوية */
.book-content .book-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    font-weight: 800;
    font-size: 0.88rem;
    border-radius: var(--radius-pill);
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #1e40af;
    border: 1px solid #93c5fd;
    width: fit-content;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.08);
}

/* العنوان الرئيسي */
.book-content .book-title {
    margin: 0;
    font-size: 2.3rem;
    font-weight: 800;
    line-height: 1.35;
    color: var(--text-dark);
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #0f172a 0%, #1e40af 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    padding-bottom: 14px;
}

.book-content .book-title::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 70px;
    height: 4px;
    border-radius: 4px;
    background: linear-gradient(90deg, #1e40af 0%, #0ea5e9 100%);
}

/* ============================================================
   PART 5 — شبكة الميتا
   ============================================================ */
.book-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin: 0;
}

.book-meta-item {
    padding: 14px 18px;
    border-radius: 14px;
    background: var(--white);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.book-meta-item::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #1e40af, #0ea5e9);
    border-radius: 0 4px 4px 0;
}

.book-meta-item:hover {
    transform: translateY(-3px);
    border-color: #bfdbfe;
    box-shadow: 0 8px 20px -8px rgba(30, 64, 175, 0.2);
}

.book-meta-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.book-meta-value {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-dark);
    line-height: 1.5;
}

/* ============================================================
   PART 6 — نبذة الكتاب
   ============================================================ */
.book-description {
    position: relative;
    background: var(--white);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    padding: 24px 26px;
    line-height: 2.1;
    font-size: 1.02rem;
    color: var(--text-soft);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.book-description::before {
    content: "";
    position: absolute;
    top: 24px;
    right: -1px;
    width: 4px;
    height: 40px;
    background: linear-gradient(180deg, #0ea5e9 0%, #1e40af 100%);
    border-radius: 4px 0 0 4px;
}

.book-description strong,
.book-description b {
    color: var(--text-dark);
    font-weight: 800;
}

/* ============================================================
   PART 7 — أزرار الإجراءات
   ============================================================ */
.book-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 6px;
}

.book-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 26px;
    text-decoration: none;
    font-weight: 800;
    font-size: 1rem;
    border-radius: 14px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.book-btn-primary {
    background: linear-gradient(135deg, #1e40af 0%, #0369a1 100%);
    color: var(--white);
    box-shadow: 0 8px 20px -8px rgba(30, 64, 175, 0.5);
}

.book-btn-primary::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
    transition: left 0.5s ease;
}

.book-btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px -8px rgba(30, 64, 175, 0.6);
    color: var(--white);
}

.book-btn-primary:hover::before {
    left: 100%;
}

.book-btn-secondary {
    background: var(--white);
    color: #1e40af;
    border-color: #cbd5e1;
}

.book-btn-secondary:hover,
.book-btn-secondary:focus-visible {
    transform: translateY(-3px);
    border-color: #1e40af;
    background: #f0f9ff;
    color: #1e3a8a;
    box-shadow: 0 8px 20px -10px rgba(30, 64, 175, 0.3);
    outline: none;
}

/* ============================================================
   PART 8 — قسم الكتب ذات الصلة
   ============================================================ */
.book-section {
    margin-top: 44px;
    padding: 32px;
    border-radius: 24px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 6px rgba(15, 23, 42, 0.03),
                0 20px 40px -30px rgba(15, 23, 42, 0.15);
    position: relative;
}

.book-section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 26px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-dark);
    position: relative;
    padding-bottom: 16px;
}

.book-section-title::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, #1e40af 0%, transparent 70%);
    border-radius: 2px;
}

/* شبكة الكتب ذات الصلة */
.book-section .related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 20px;
}

/* ============================================================
   PART 9 — الاستجابة للجوال
   ============================================================ */

/* ---------- ≤ 992px ---------- */
@media (max-width: 992px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }

    .book-card .cover-container {
        height: 270px;
    }
}

/* ---------- ≤ 960px ---------- */
@media (max-width: 960px) {
    .book-hero {
        grid-template-columns: 1fr;
        gap: 30px;
        padding: 28px;
    }

    .book-cover-box {
        max-width: 340px;
        width: 100%;
        margin: 0 auto;
    }

    .book-content .book-title {
        font-size: 1.9rem;
    }

    .book-cover:hover {
        transform: translateY(-4px);
    }
}

/* ---------- ≤ 768px ---------- */
@media (max-width: 768px) {
    .header-lib {
        padding: 22px 18px;
    }

    .subtitle {
        font-size: 1rem;
    }

    .search-container {
        padding: 15px;
    }

    .books-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .book-card .cover-container {
        height: 250px;
        padding: 8px 10px;
    }

    .book-card .cover-container img {
        padding: 4px;
        border-radius: 10px;
    }

    .book-card .book-info {
        padding: 15px 16px 18px;
    }

    .book-card .book-title {
        font-size: 1rem;
    }

    .book-card .book-meta {
        font-size: 0.9rem;
        min-height: auto;
    }

    .pagination-info,
    .load-more {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .book-section .related-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

/* ---------- ≤ 640px ---------- */
@media (max-width: 640px) {
    .book-page-wrap {
        padding: 20px 12px 60px;
    }

    .book-breadcrumb {
        padding: 10px 14px;
        font-size: 0.87rem;
        gap: 6px;
    }

    .book-breadcrumb span:last-child {
        max-width: 180px;
    }

    .book-hero,
    .book-section {
        padding: 22px 18px;
        border-radius: 20px;
    }

    .book-content .book-title {
        font-size: 1.55rem;
        padding-bottom: 12px;
    }

    .book-content .book-title::after {
        width: 50px;
        height: 3px;
    }

    .book-description {
        padding: 18px;
        font-size: 0.97rem;
        line-height: 1.95;
    }

    .book-meta {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .book-meta-item {
        padding: 12px 14px;
    }

    .book-meta-value {
        font-size: 0.95rem;
    }

    .book-actions {
        flex-direction: column;
    }

    .book-btn {
        width: 100%;
        padding: 13px 20px;
    }

    .book-section-title {
        font-size: 1.25rem;
        margin-bottom: 20px;
    }
}

/* ---------- ≤ 420px ---------- */
@media (max-width: 420px) {
    .book-card .cover-container {
        height: 235px;
    }

    .book-card .book-title {
        font-size: 0.98rem;
    }

    .book-card .author-tag {
        font-size: 0.8rem;
        padding: 5px 10px;
    }

    .book-card .book-info {
        padding: 14px 14px 16px;
    }
}

/* ============================================================
   PART 10 — RTL / LTR
   ============================================================ */
body[dir="rtl"] .book-meta-item::before {
    right: 0;
    left: auto;
    border-radius: 0 4px 4px 0;
}

body[dir="rtl"] .book-description::before {
    right: -1px;
    left: auto;
    border-radius: 4px 0 0 4px;
}

body[dir="rtl"] .book-content .book-title::after {
    right: 0;
    left: auto;
}

body[dir="ltr"] .book-meta-item::before {
    left: 0;
    right: auto;
    border-radius: 4px 0 0 4px;
}

body[dir="ltr"] .book-description::before {
    left: -1px;
    right: auto;
    border-radius: 0 4px 4px 0;
}

body[dir="ltr"] .book-content .book-title::after {
    left: 0;
    right: auto;
}

body[dir="ltr"] .book-section-title::after {
    background: linear-gradient(270deg, #1e40af 0%, transparent 70%);
}

/* ============================================================
   PART 11 — حركات الدخول والطباعة
   ============================================================ */
@keyframes book-fade-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.book-hero {
    animation: book-fade-up 0.5s ease-out;
}

.book-section {
    animation: book-fade-up 0.5s ease-out 0.1s backwards;
}

/* احترام تفضيلات المستخدم */
@media (prefers-reduced-motion: reduce) {
    .book-hero,
    .book-section {
        animation: none;
    }

    .book-cover {
        transition: none;
    }
}

/* ---------- الطباعة ---------- */

/* ============================================================
   ملاحظة للمطور
   ------------------------------------------------------------
   الملف يدمج library.css + book-details.css.

   الأصناف التي حُذفت لأنها في component-system.css:
     - .book-card (النسخة الكاملة)
     - .cover-container (النسخة العامة)
     - .book-info, .book-title, .book-meta (النسخة العامة)
     - .book-footer, .book-actions (النسخة العامة)
     - .btn, .btn-primary, .btn-outline
     - .ui-empty-state, .no-results

   الأصناف التي أُبقيت مع تخصيص:
     - .book-card .cover-container (حجم خاص)
     - .book-card .book-title (سطور محدودة)
     - .book-content .book-title (تدرج لوني للنص)

   الأخطاء التي أُصلحت:
     1) لا يوجد تكرار لـ .book-meta (كان في library.css + book-details.css)
     2) لا يوجد تعارض بين .book-title (كتاب المكتبة vs تفاصيل الكتاب)
     3) لا تكرار لـ body[dir="rtl"] (كان معرّفاً في كل ملف)
   ============================================================ */