/**
 * Print Stylesheet for Invoice Generator.
 * Strips away the dark-themed dashboard UI and optimizes the canvas for printing to paper or saving to PDF.
 */

@media print {
    /* Reset background and colors for standard print */
    html, body {
        background-color: #ffffff !important;
        color: #000000 !important;
        font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* Force linear grids and flexboxes to lay out normally */
    .app-container {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
    }

    .main-content {
        display: block !important;
        height: auto !important;
        overflow: visible !important;
        grid-template-columns: 1fr !important;
    }

    /* Hide the editor, sidebar, toolbar headers, and interactive popups */
    .sidebar,
    .panel-editor,
    .preview-toolbar,
    .toast-container,
    .modal-overlay,
    .no-print {
        display: none !important;
    }

    /* Re-route the preview panel to fill the page */
    .panel-preview {
        padding: 0 !important;
        background-color: #ffffff !important;
        background: none !important;
        overflow: visible !important;
        display: block !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Standardize the paper element */
    .invoice-paper-wrapper {
        background-color: #ffffff !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: 0 !important;
        transform: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Define page margins and layout defaults */
    @page {
        size: A4 portrait;
        margin: 8mm 10mm;
    }

    /* Print-specific compact vertical spacing to ensure single-page fitting */
    .invoice-container {
        padding: 5px 10px !important;
        max-width: 100% !important;
    }

    .invoice-header {
        margin-bottom: 12px !important;
        padding-bottom: 10px !important;
    }

    .invoice-header h1 {
        font-size: 1.6rem !important;
    }

    .invoice-client-info {
        margin-bottom: 12px !important;
    }

    .invoice-client-info div {
        padding: 8px 12px !important;
    }

    .invoice-items-table {
        margin-bottom: 12px !important;
    }

    .invoice-items-table th,
    .invoice-items-table td {
        padding-top: 4px !important;
        padding-bottom: 4px !important;
        font-size: 0.8rem !important;
    }

    .invoice-summary-grid {
        margin-top: 8px !important;
        gap: 15px !important;
    }

    .invoice-bank-details {
        padding: 8px 10px !important;
    }

    .invoice-notes-section {
        margin-top: 8px !important;
    }

    .invoice-footer-section {
        margin-top: 12px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    .invoice-footer-section img {
        position: static !important;
        display: block !important;
        margin: 0 auto 2px auto !important;
        max-height: 40px !important;
    }

    .invoice-footer-section div[style*="position: relative"] {
        height: auto !important;
        margin-bottom: 3px !important;
    }

    /* Prevent awkward page splits inside key sections */
    .invoice-bank-details,
    .invoice-totals-section,
    .invoice-notes-section,
    tr {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }

    tr {
        page-break-after: auto;
    }

    thead {
        display: table-header-group;
    }

    /* Force browsers to print background colors in the template */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
