/* الأنماط المخصصة للطباعة - الحل النهائي المعتمد على position: fixed مع جدول لحجز المساحة */
@media print {

    /* أولاً، نخفي كل شيء في الصفحة ما عدا المحتوى الذي نريده */
    body > .wrapper > *:not(.content-page) {
        display: none !important;
    }

    .content-page footer.footer, .navbar-custom, .topnav {
        display: none !important;
    }

    /* إلغاء تأثيرات الحاوية وإصلاح مشاكل تقسيم الصفحات (Page Breaks) */
    html, body, .wrapper, .content-page, .content, .container-fluid, .printable-area {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }

    .printable-area {
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        display: block !important;
    }

    /* السماح بتقسيم الجدول ومحتوياته بشكل صحيح عبر الصفحات */
    table, tbody, tr, td {
        page-break-inside: auto !important;
        break-inside: auto !important;
    }

    /* إصلاح مشاكل الـ Flexbox في Bootstrap للطباعة والتي تسبب فراغات كبيرة */
    .row, .col-12, .col-md-6, .card, .card-body, .d-flex {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        page-break-inside: auto !important;
        break-inside: auto !important;
    }
    
    .card-body {
        padding: 0 !important;
    }

    /* إعداد الهيدر الثابت ليظهر في أعلى كل صفحة */
    .printable-header-fixed {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 9999;
    }

    /* إعداد الفوتر الثابت ليظهر في أسفل كل صفحة تماماً */
    .printable-footer-fixed {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 9999;
    }

    .printable-header-fixed img,
    .printable-footer-fixed img {
        width: 100%;
        height: auto;
        display: block;
    }

    @page {
        size: A4 portrait;
        margin: 0; /* تم تغيير القيمة إلى 0 لإلغاء هوامش المتصفح الافتراضية */
    }

    .no-print-section,
    .no-print-section * {
        display: none !important;
    }

    .table-dark th {
        background-color: #fff !important;
        color: black !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body {
        color: black !important;
        background: #fff !important;
    }

}

/* في وضع الشاشة العادي، نخفي الهيدر والفوتر المخصصين للطباعة والصور الحاجزة للمساحة */
@media screen {
    .printable-header-fixed,
    .printable-footer-fixed,
    .print-spacer {
        display: none !important;
    }
}

