/**
 * invoice.css
 * Styles for the Miss Flora Invoice
 * Target: A6 Paper (105mm x 148mm)
 */

/* Main Container */
.invoice-card {
    width: 105mm; /* Standard A6 Width */
    height: 148mm; /* Standard A6 Height */
    margin: 0 auto;
    font-family: 'RTA', Tahoma, sans-serif;
    direction: rtl;
    padding: 5mm; /* Uniform 0.5cm margin for the border */
    box-sizing: border-box;
    color: #000;
    background: #fff;
    position: relative;
    overflow: hidden;
    font-size: 8pt;
    font-weight: 800;
}

/* Border Wrapper (2mm from edge) */
.invoice-border-wrapper {
    width: 100%;
    height: 100%;
    border: 1mm solid #5f3dc4;
    box-sizing: border-box;
    padding: 6mm; /* Content padding inside border */
    position: relative;
}

/* Global Font Flattening for Invoice (Excluding Brandt and Totals) */
.invoice-card *:not(i):not([class*="fa-"]):not(.invoice-brand-name):not(.invoice-total-val) {
    font-weight: 800 !important;
    font-size: 8pt !important;
    color: #000 !important;
}

/* Page Break for Bulk Print */
.invoice-card {
    break-inside: avoid;
}

.invoice-card.has-break {
    page-break-after: always;
    break-after: page;
}

/* Header Section */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6mm;
    border-bottom: 1pt solid #5f3dc4;
    padding-bottom: 3mm;
}

.invoice-header-side {
    flex: 1;
}

.invoice-header-side.left {
    text-align: left;
}

.invoice-header-side.right {
    text-align: right;
}

.invoice-header-center {
    flex: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.invoice-logo-img {
    height: 12mm;
    display: block;
    margin-bottom: 3mm; /* Gap from logo to name */
}

.invoice-brand-name {
    font-size: 16pt !important;
    line-height: 1;
}

.invoice-brand-sub {
    font-size: 8pt !important;
    margin-top: 1mm; /* Reduced gap for better symmetry */
}

/* Customer Section */
.invoice-customer {
    margin-bottom: 6mm;
}

.invoice-customer-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3mm;
}

.invoice-customer-name {
    line-height: 1.2;
}

.invoice-customer-address-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.invoice-customer-city {
    line-height: 1.3;
}

.invoice-customer-details {
    line-height: 1.3;
    text-align: left;
    max-width: 60%;
}

/* Items Table Section */
.invoice-items-section {
    margin-bottom: 10mm;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8pt !important; /* Matches the new global base */
}

.invoice-items-table th {
    border-bottom: 1pt solid #5f3dc4;
    padding: 1.5mm 0;
    font-weight: 800;
}

.invoice-items-table td {
    padding: 1.5mm 0;
    border-bottom: 0.5pt solid #eee;
}

/* Financials (Positioned Bottom-Left) */
.invoice-total-box {
    position: absolute;
    bottom: 12mm;
    left: 4mm;
    padding: 2mm;
    border: 0.5pt solid #5f3dc4; /* Thinner purple border */
    display: flex;
    flex-direction: column;
    gap: 1.5mm;
    min-width: 36mm;
    max-width: 40mm;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    font-size: 8pt !important;
}

.invoice-total-row.grand-total {
    border-top: 0.5pt solid #5f3dc4; /* Thinner purple line */
    padding-top: 1.5mm;
    margin-top: 1mm;
}

.invoice-total-row.grand-total .invoice-total-val {
    font-size: 14pt !important; /* Slightly adjusted scale */
    font-weight: 900 !important;
}

/* Reserved Space for Sticker (Bottom Right) */
.invoice-barcode-space {
    position: absolute;
    bottom: 1mm;
    right: 1mm;
    width: 60mm;
    height: 70mm;
    background: transparent;
}

/* Footer Section (Bottom Left) */
.invoice-footer-note {
    position: absolute;
    bottom: 5mm;
    left: 6mm;
    text-align: left;
}

/* Screen View Hiding */
@media screen {
    .print-only {
        display: none !important;
    }
}

/* Printing logic */
@media print {
    body * { visibility: hidden !important; }
    #invoice-print-area, #invoice-print-area * { visibility: visible !important; }
    
    /* Ensure the container is visible and positioned correctly */
    #invoice-print-area {
        display: block !important;
        visibility: visible !important;
        position: relative;
        left: 0; right: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        background: white;
    }

    /* Page Setup */
    @page {
        size: 105mm 148mm;
        margin: 0;
    }

    /* Cleanup app UI from print */
    .orders-shell, .app-sidebar, .app-topbar, .orders-modal-overlay, .app-bottom-bar {
        display: none !important;
    }

    /* Ensure background colors and images are printed */
    * { 
        -webkit-print-color-adjust: exact !important; 
        print-color-adjust: exact !important; 
    }

    html, body {
        height: auto !important;
        overflow: visible !important;
        margin: 0;
        padding: 0;
    }
}
