/*
 * Print stylesheet — minimal, layout-preserving.
 *
 * Strategy:
 *  - hide chrome (sidebar, navbar, action buttons, filters, tabs)
 *  - flow content as a single column
 *  - light cards on white background
 *  - DON'T force page-break-inside: avoid on .card (was breaking pages
 *    with half-empty leftovers and producing blank trailing pages)
 *  - leave page numbers / headers to the browser print dialog
 */

@media print {
    @page {
        size: A4;
        margin: 1.5cm 1.2cm;
    }

    html, body {
        background: #fff !important;
        color: #000 !important;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
        font-size: 10pt;
        line-height: 1.4;
    }

    /* Hide chrome */
    .navbar,
    nav.navbar,
    .sidebar,
    aside.sidebar,
    .topbar,
    .breadcrumb,
    .alert,
    .toast,
    .tooltip,
    .modal,
    .pagination,
    .page-actions,
    .filters,
    form.form-inline,
    .nav-tabs,
    .toolbar,
    .skip-link,
    .help-icon,
    .help-tip,
    .floating-action,
    .print-hide,
    .btn,
    button:not(.print-keep),
    input[type="submit"],
    .dropdown,
    [role="navigation"] {
        display: none !important;
    }

    /* Reset Bootstrap grid to single-column block flow */
    .row,
    [class*="row-cols-"] {
        display: block !important;
    }
    [class*="col-"],
    .col {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        margin: 0 !important;
        padding: 0 !important;
        float: none !important;
        display: block !important;
    }

    /* Reset CSS Grid layouts (.grid-metrics on the dashboard) */
    .grid-metrics {
        display: block !important;
        grid-template-columns: none !important;
    }

    /* Containers to full width */
    main,
    .content,
    .main-content,
    .container,
    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Cards: light borders, no shadow, comfortable spacing */
    .card {
        border: 1px solid #d0d0d0 !important;
        border-radius: 6px !important;
        box-shadow: none !important;
        background: #fff !important;
        margin-bottom: 0.4cm !important;
        page-break-inside: auto;
    }
    .card-header {
        background: #fafafa !important;
        color: #000 !important;
        border-bottom: 1px solid #e0e0e0 !important;
        font-weight: 600;
        padding: 0.25cm 0.4cm !important;
    }
    .card-body {
        padding: 0.4cm !important;
    }

    /* Tables — readable in B/W, repeat header on page break */
    table {
        page-break-inside: auto;
        width: 100%;
    }
    table, th, td {
        border: 1px solid #ccc !important;
        background: #fff !important;
        color: #000 !important;
    }
    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }

    /* Charts: keep readable */
    canvas, svg.chart {
        max-width: 100% !important;
        max-height: 8cm !important;
        height: auto !important;
        page-break-inside: avoid;
    }

    /* Numbers stay bold and dark */
    .metric-value, .display-4 {
        font-weight: 700 !important;
        color: #000 !important;
    }

    /* Branded print header (rendered by layout partial at top of page) */
    .print-only { display: block !important; }
    .print-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        border-bottom: 2px solid var(--im-brand, #1a1a2e);
        padding-bottom: 0.3cm;
        margin: 0 0 0.5cm 0;
    }
    .print-header-logo {
        max-height: 1.2cm;
        max-width: 5cm;
    }
    .print-header-meta {
        text-align: right;
        font-size: 8pt;
        color: #555;
    }
    .print-header-meta .print-page-title {
        font-size: 13pt;
        font-weight: 700;
        color: #000;
        margin-bottom: 0.05cm;
    }

    /* Disable animations / transitions */
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }

    /* Render link URLs after text — but skip nav/buttons */
    a[href]:not(.no-print-url):not(.btn):not(.nav-link)::after {
        content: " (" attr(href) ")";
        font-size: 7pt;
        color: #888;
        word-break: break-all;
    }
    a[href^="#"]::after,
    a[href^="javascript:"]::after,
    .card-header a::after {
        content: "" !important;
    }

    /* Page-break helpers callable from blade */
    .page-break-before { page-break-before: always; }
    .page-break-after  { page-break-after: always; }

    /* Hide common large empty placeholders that look bad on paper */
    .empty-state-illustration { display: none !important; }
}

/* Default screen state: hide print-only blocks */
.print-only {
    display: none;
}
