﻿:root {
    --page-width: 297mm; /* A4 Landscape */
    --page-height: 210mm;
    --margin: 12mm;
    --scale: 1; /* للزووم في المعاينة فقط */
    --bg: #f5f7fb;
    --ink: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --brand: #2563eb;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--ink);
}

.report-viewer {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: .5rem;
    align-items: center;
    justify-content: space-between;
    padding: .65rem .9rem;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

    .report-viewer .left, .report-viewer .right {
        display: flex;
        gap: .5rem;
        align-items: center;
        flex-wrap: wrap;
    }

    .report-viewer .title {
        font-weight: 700;
    }

    .report-viewer .badge {
        background: #eef2ff;
        color: #3730a3;
        padding: .15rem .5rem;
        border-radius: .375rem;
        border: 1px solid #c7d2fe;
    }

    .report-viewer select, .report-viewer button {
        border: 1px solid var(--line);
        background: #fff;
        padding: .35rem .6rem;
        border-radius: .4rem;
        cursor: pointer;
    }

        .report-viewer button.primary {
            background: var(--brand);
            color: #fff;
            border-color: var(--brand);
        }

    .report-viewer .sep {
        width: 1px;
        height: 26px;
        background: var(--line);
        margin: 0 .25rem;
    }

.report-canvas {
    display: flex;
    justify-content: center;
    padding: 1rem;
}

.report-page {
    width: var(--page-width);
    min-height: var(--page-height);
    background: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,.08);
    transform-origin: top center;
    transform: scale(var(--scale)); /* زووم للمعاينة فقط */
}

.page-inner {
    padding: var(--margin);
}

.report-header {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding-bottom: .5rem;
    margin-bottom: .75rem;
}

    .report-header .company h1 {
        font-size: 1.25rem;
        margin: 0 0 .25rem;
    }

    .report-header .meta {
        text-align: end;
        font-size: .9rem;
        color: var(--muted);
    }

    .report-header img {
        max-height: 48px;
    }

.report-statgrid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: .5rem;
    margin: .5rem 0 1rem;
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: .5rem;
    padding: .6rem .7rem;
    background: #fff;
}

.stat-label {
    color: var(--muted);
    font-size: .85rem;
}

.stat-value {
    font-weight: 700;
    font-size: 1.1rem;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
}

    .report-table th, .report-table td {
        border: 1px solid var(--line);
        padding: .45rem .5rem;
        font-size: .9rem;
    }

    .report-table th {
        background: #f9fafb;
        text-align: start;
    }

.text-end {
    text-align: end;
}

.text-center {
    text-align: center;
}

.muted {
    color: var(--muted);
}

/* فواصل الصفحات (اختياري) */
.page-break {
    page-break-before: always;
}

/* RTL دعم */
[dir="rtl"] .report-header .meta {
    text-align: start;
}

[dir="rtl"] .text-end {
    text-align: start;
}

[dir="rtl"] .text-center {
    text-align: center;
}

/* الطباعة */
@media print {
    :root {
        --scale: 1;
    }

    .report-viewer {
        display: none !important;
    }

    html, body {
        background: #fff;
    }

    @page {
        size: A4 landscape;
        margin: 12mm;
    }

    .report-canvas {
        padding: 0;
    }

    .report-page {
        box-shadow: none;
        width: auto;
        min-height: auto;
        transform: none !important;
    }
}

@media print {
    /* إلغاء أي Scroll وإجبار المحتوى يتمدد ويُقسم على صفحات */
    html, body {
        height: auto !important;
        overflow: visible !important;
        background: #fff;
        -webkit-print-color-adjust: exact; /* ألوان أفضل في الطباعة */
        print-color-adjust: exact;
    }

    .report-viewer {
        display: none !important;
    }

    .report-canvas {
        padding: 0 !important;
        overflow: visible !important;
    }

    .report-page {
        width: auto !important;
        min-height: auto !important;
        height: auto !important;
        transform: none !important; /* إلغاء الـ scale */
        box-shadow: none !important;
        overflow: visible !important; /* لا Scroll داخلي */
        background: #fff !important;
    }

    .page-inner {
        padding: 0; /* الهامش هيتم من @page */
    }

    @page {
        size: A4 landscape;
        margin: 12mm; /* نفس قيمة --margin */
    }

    /* تقسيم المحتوى على صفحات مع منع تقطيع العناصر الحرجة */
    .report-header,
    .stat-card,
    .report-statgrid,
    .page-break {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* جداول طويلة: كرر الرأس ومنع تقطيع الصف الواحد */
    .report-table thead {
        display: table-header-group;
    }

    .report-table tfoot {
        display: table-footer-group;
    }

    .report-table tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* إخفاء الـ scrollbar في المتصفحات التي تظهره أثناء الطباعة */
    *::-webkit-scrollbar {
        display: none !important;
    }
}
