/* Universal A4 Print Standard for DMSA ERP */
@media print {

    /* Better Page Management: Leaves room for page numbers while stripping most URLs */
    @page {
        size: A4 portrait;
        margin: 5mm;
        /* Maximize paper real estate */

        @bottom-right {
            content: "Page " counter(page);
            font-size: 8pt;
        }
    }

    /* Reset body margin since @page is handling safe zones now */
    body {
        margin: 0;
        padding: 0;
    }

    /* Hide Web UI Elements and Charts */
    .no-print,
    header,
    nav,
    aside,
    footer,
    .sidebar,
    .navbar,
    .app-header,
    button,
    form,
    .filter-form,
    select,
    input,
    canvas,
    .chart-container,
    .chart-wrapper,
    .apexcharts-canvas,
    #sidebar {
        display: none !important;
    }

    /* Flatten the UI */
    * {
        box-shadow: none !important;
        background-color: transparent !important;
        background: transparent !important;
        color: #000000 !important;
        /* Strict black for ink conservation */
        border-radius: 0 !important;
    }

    /* Prevent breaking inside cards */
    .bg-white {
        border: 1px solid #ccc !important;
        /* Removed page-break-inside: avoid to fix the blank first page bug! */
    }

    /* Table Formatting & Fonts */
    table,
    th,
    td,
    table * {
        font-size: 9pt !important;
        /* Smaller font to maximize data density on A4 */
    }

    table {
        border-collapse: collapse !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 20px !important;
        table-layout: auto !important;
        /* Forces columns to compress */
        word-wrap: break-word !important;
        /* Prevents long words from breaking the table */
    }

    /* Prevent Totals (tfoot) from repeating on every page */
    tfoot {
        display: table-row-group !important;
    }

    th,
    td {
        border: 1px solid #000 !important;
        padding: 4px !important;
        /* Reduced padding to fit more data */
        color: #000 !important;
        word-break: break-word !important;
        /* Allow text to wrap inside tight columns */
    }

    thead {
        display: table-header-group !important;
    }

    tr {
        page-break-inside: avoid !important;
    }

    /* Ensure borders print properly for structures */
    .border,
    .border-b,
    .border-t,
    .border-l,
    .border-r {
        border-color: #000 !important;
    }

    /* Keep Images in color */
    img {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}