/* =========================================================
   G3 Bill Receipt Templates (separate from legacy pos-receipts)
   ========================================================= */

.bill-tpl,
.bill-tpl * {
    box-sizing: border-box;
}

.bill-tpl {
    --primary: #9b7b52;
    --dark: #222222;
    --muted: #666666;
    --light: #f5f5f5;
    --border: #dddddd;
    background: #ffffff;
    color: #222;
    font-family: Arial, Helvetica, sans-serif;
    margin: 0 auto;
    overflow: hidden;
}

.bill-tpl.a4 {
    width: 210mm;
    min-height: auto;
    padding: 15mm;
}

.bill-tpl.thermal {
    width: 80mm;
    min-height: auto;
    padding: 8mm 5mm;
    color: #000;
    font-size: 11px;
    font-family: "Courier New", Courier, monospace;
    overflow: visible;
}

.bill-tpl.thermal,
.bill-tpl.thermal * {
    font-family: "Courier New", Courier, monospace;
}

.bill-tpl .flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.bill-tpl .text-center { text-align: center; }
.bill-tpl .text-right { text-align: right; }
.bill-tpl .amount { text-align: right; }
.bill-tpl .muted { color: #666; }
.bill-tpl .small { font-size: 12px; }

.bill-tpl table {
    width: 100%;
    border-collapse: collapse;
}

.bill-tpl th,
.bill-tpl td {
    padding: 9px 8px;
    text-align: left;
    vertical-align: top;
}

.bill-tpl .invoice-title {
    margin: 0 0 10px;
    font-size: 27px;
    font-weight: 700;
    letter-spacing: 1px;
}

/* Template 1 — Classic GST */
.bill-tpl .classic-header {
    padding-bottom: 20px;
    margin-bottom: 25px;
    border-bottom: 3px solid #111;
}

.bill-tpl .classic-header h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.bill-tpl .classic-header p {
    margin: 0;
    line-height: 1.6;
    font-size: 13px;
}

.bill-tpl .classic-customer { margin-bottom: 25px; }

.bill-tpl .classic-customer h4 {
    margin: 0 0 8px;
    font-size: 12px;
    letter-spacing: 1px;
}

.bill-tpl .classic-customer p {
    margin: 0;
    line-height: 1.6;
}

.bill-tpl .classic-table thead th {
    background: #222;
    color: #fff;
    font-size: 13px;
}

.bill-tpl .classic-table tbody td {
    border-bottom: 1px solid #ddd;
    font-size: 13px;
}

.bill-tpl .classic-total {
    width: 45%;
    margin: 25px 0 0 auto;
}

.bill-tpl .classic-total td {
    padding: 9px;
    border-bottom: 1px solid #ddd;
}

.bill-tpl .classic-total .grand td {
    background: #222;
    color: #fff;
    font-weight: bold;
    font-size: 16px;
}

.bill-tpl .classic-footer {
    margin-top: 36px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

/* Template 2 — Modern Boutique */
.bill-tpl.modern { border-top: 10px solid #9b7b52; }

.bill-tpl .modern-brand {
    margin: 0;
    color: #9b7b52;
    font-size: 38px;
    letter-spacing: 5px;
}

.bill-tpl .modern-subtitle {
    margin-top: 4px;
    font-size: 12px;
    color: #777;
    letter-spacing: 2px;
}

.bill-tpl .modern-title {
    margin: 0 0 10px;
    color: #9b7b52;
    font-size: 28px;
}

.bill-tpl .modern-customer {
    margin: 30px 0;
    padding: 20px;
    background: #f8f4ef;
    border-left: 5px solid #9b7b52;
}

.bill-tpl .modern-customer small {
    color: #888;
    font-size: 10px;
    letter-spacing: 1px;
}

.bill-tpl .modern-customer p {
    margin-bottom: 0;
    line-height: 1.6;
}

.bill-tpl .modern-table th {
    padding: 11px;
    color: white;
    background: #9b7b52;
    font-size: 13px;
}

.bill-tpl .modern-table td {
    padding: 13px 11px;
    border-bottom: 1px solid #eadfd2;
    font-size: 13px;
}

.bill-tpl .modern-summary {
    width: 42%;
    margin: 25px 0 0 auto;
}

.bill-tpl .modern-summary td { padding: 8px 10px; }

.bill-tpl .modern-grand {
    margin-top: 12px;
    padding: 15px;
    background: #9b7b52;
    color: white;
    text-align: right;
    font-size: 20px;
    font-weight: bold;
}

.bill-tpl .modern-footer {
    margin-top: 100px;
    text-align: center;
}

/* Template 3 — Thermal */
.bill-tpl.thermal h2 {
    margin: 0 0 5px;
    font-size: 18px;
    text-transform: uppercase;
}

.bill-tpl.thermal p { margin: 3px 0; }

.bill-tpl.thermal .thermal-doc-title {
    margin: 0 0 6px;
    font-size: 11px;
    letter-spacing: 1.5px;
    font-weight: 700;
}

.bill-tpl.thermal .thermal-tagline {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.bill-tpl.thermal hr,
.bill-tpl.thermal .thermal-rule {
    margin: 8px 0;
    border: 0;
    border-top: 1px dashed #000;
    height: 0;
    page-break-after: avoid;
    break-after: avoid;
}

.bill-tpl .thermal-meta {
    font-size: 10px;
}

.bill-tpl .thermal-meta td {
    padding: 1px 0;
}

.bill-tpl .thermal-table { font-size: 10px; }

.bill-tpl .thermal-table th,
.bill-tpl .thermal-table td { padding: 4px 2px; }

.bill-tpl .thermal-table th { border-bottom: 1px dashed #000; }

.bill-tpl .thermal-item-meta {
    display: block;
    font-size: 9px;
    opacity: 0.85;
}

.bill-tpl .thermal-count {
    margin: 4px 0 0;
    font-size: 10px;
}

.bill-tpl .thermal-total td {
    padding: 3px 0;
    font-size: 11px;
}

.bill-tpl .thermal-grand td {
    padding: 6px 0;
    font-size: 14px;
    font-weight: bold;
    border-top: 1px dashed #000;
    border-bottom: 1px dashed #000;
}

.bill-tpl .thermal-words {
    margin: 8px 0 4px;
    font-size: 10px;
    line-height: 1.35;
}

.bill-tpl .thermal-notes {
    font-size: 10px;
}

.bill-tpl .thermal-barcode {
    margin: 10px 0 4px;
    text-align: center;
}

.bill-tpl .thermal-barcode svg {
    display: block;
    width: 100%;
    height: 36px;
}

.bill-tpl .thermal-barcode p {
    margin: 4px 0 0;
    font-size: 10px;
    letter-spacing: 1px;
}

.bill-tpl .thermal-terms {
    font-size: 9px;
    line-height: 1.35;
}

/* Template 4 — Detailed GST */
.bill-tpl .gst-box { border: 2px solid #333; }

.bill-tpl .gst-header {
    padding: 15px;
    text-align: center;
    border-bottom: 2px solid #333;
}

.bill-tpl .gst-header h1 {
    margin: 8px 0;
    font-size: 27px;
}

.bill-tpl .gst-header p {
    margin: 0;
    line-height: 1.5;
    font-size: 12px;
}

.bill-tpl .gst-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.bill-tpl .gst-info > div {
    min-height: 120px;
    padding: 15px;
    line-height: 1.7;
    font-size: 12px;
    border-bottom: 1px solid #333;
}

.bill-tpl .gst-info > div:first-child { border-right: 1px solid #333; }

.bill-tpl .gst-table th,
.bill-tpl .gst-table td {
    padding: 8px 5px;
    border: 1px solid #333;
    font-size: 11px;
}

.bill-tpl .gst-table th {
    background: #eee;
    text-align: center;
}

.bill-tpl .gst-summary {
    display: flex;
    justify-content: flex-end;
    padding: 15px;
}

.bill-tpl .gst-summary table { width: 45%; }

.bill-tpl .gst-summary td {
    padding: 5px;
    font-size: 12px;
}

.bill-tpl .gst-grand td {
    padding-top: 10px;
    border-top: 2px solid #333;
    font-size: 16px;
    font-weight: bold;
}

.bill-tpl .amount-words {
    padding: 15px;
    border-top: 1px solid #333;
    font-size: 12px;
}

.bill-tpl .gst-footer {
    display: flex;
    justify-content: space-between;
    min-height: 130px;
    padding: 15px;
    border-top: 1px solid #333;
    font-size: 11px;
}

.bill-tpl .signature {
    align-self: flex-end;
    text-align: center;
}

/* Template 5 — Minimal */
.bill-tpl.minimal { padding: 20mm; }

.bill-tpl .minimal-header { margin-bottom: 45px; }

.bill-tpl .minimal-logo {
    margin: 0;
    font-size: 42px;
    font-weight: 800;
}

.bill-tpl .minimal-number {
    color: #888;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.bill-tpl .minimal-customer { margin-bottom: 40px; }

.bill-tpl .minimal-customer p { margin: 7px 0 0; }

.bill-tpl .minimal-table th {
    padding: 12px 8px;
    color: #888;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid #222;
}

.bill-tpl .minimal-table td {
    padding: 16px 8px;
    border-bottom: 1px solid #eee;
}

.bill-tpl .minimal-summary {
    width: 40%;
    margin: 30px 0 0 auto;
}

.bill-tpl .minimal-summary td { padding: 7px; }

.bill-tpl .minimal-total td {
    padding-top: 15px;
    font-size: 23px;
    font-weight: bold;
    border-top: 2px solid #222;
}

.bill-tpl .minimal-footer {
    margin-top: 150px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

/* Template 6 — Tailoring */
.bill-tpl.tailor { padding: 15mm; }

.bill-tpl .tailor-header {
    margin: -15mm -15mm 30px;
    padding: 25px 15mm;
    background: #463f3a;
    color: white;
}

.bill-tpl .tailor-header h1 { margin: 10px 0 5px; }

.bill-tpl .tailor-header p {
    margin: 0;
    font-size: 12px;
}

.bill-tpl .order-badge {
    display: inline-block;
    padding: 6px 12px;
    color: #222;
    background: #e0afa0;
    border-radius: 20px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
}

.bill-tpl .tailor-customer {
    padding-bottom: 20px;
    margin-bottom: 25px;
    border-bottom: 1px solid #ddd;
}

.bill-tpl .tailor-section-title {
    margin: 25px 0 12px;
    font-size: 15px;
}

.bill-tpl .order-details td {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.bill-tpl .measurement-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.bill-tpl .measurement {
    padding: 13px;
    background: #f4f3ee;
}

.bill-tpl .measurement span {
    display: block;
    margin-bottom: 5px;
    color: #777;
    font-size: 10px;
}

.bill-tpl .measurement strong { font-size: 16px; }

.bill-tpl .instruction-box {
    padding: 15px;
    background: #f8f8f8;
    border-left: 4px solid #463f3a;
    line-height: 1.6;
}

.bill-tpl .delivery-box {
    margin-top: 25px;
    padding: 16px;
    background: #e0afa0;
    font-weight: bold;
}

.bill-tpl .tailor-summary {
    width: 45%;
    margin: 25px 0 0 auto;
}

.bill-tpl .tailor-summary td { padding: 7px; }

.bill-tpl .tailor-balance td {
    padding-top: 12px;
    border-top: 2px solid #463f3a;
    font-size: 17px;
    font-weight: bold;
}

.bill-tpl .tailor-footer {
    margin-top: 70px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

/* Screen preview shell */
.bill-tpl-preview-host {
    background: #e9ecef;
    padding: 16px;
    overflow: auto;
}

.bill-tpl-preview-host .bill-tpl {
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.12);
}

.bill-tpl-preview-host .bill-tpl.a4 {
    width: 100%;
    max-width: 210mm;
    min-height: auto;
    padding: 20px;
    transform-origin: top center;
}

.bill-tpl-preview-host .bill-tpl.thermal {
    width: 80mm;
    max-width: 100%;
}

@media screen and (max-width: 850px) {
    .bill-tpl.a4 {
        width: 100%;
        min-height: auto;
        padding: 20px;
    }

    .bill-tpl .flex { flex-direction: column; }
    .bill-tpl .text-right { text-align: left; }

    .bill-tpl .classic-total,
    .bill-tpl .modern-summary,
    .bill-tpl .minimal-summary,
    .bill-tpl .tailor-summary,
    .bill-tpl .gst-summary table {
        width: 100%;
    }

    .bill-tpl .measurement-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .bill-tpl .gst-info {
        grid-template-columns: 1fr;
    }

    .bill-tpl .gst-info > div:first-child {
        border-right: 0;
    }
}

@media print {
    html, body {
        background: #fff !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    .bill-tpl {
        box-shadow: none !important;
        margin: 0 auto !important;
        overflow: visible !important;
        background: #fff !important;
        color: #000 !important;
        transform: none !important;
        filter: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    .bill-tpl,
    .bill-tpl * {
        color: #000 !important;
        text-shadow: none !important;
        box-shadow: none !important;
        filter: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
        page-break-inside: auto;
        break-inside: auto;
    }

    .bill-tpl.a4 {
        width: 100% !important;
        max-width: 194mm !important;
        min-height: 0 !important;
        height: auto !important;
        padding: 0 !important;
    }

    .bill-tpl.thermal,
    .bill-tpl.thermal * {
        page-break-after: auto !important;
        break-after: auto !important;
        page-break-before: auto !important;
        break-before: auto !important;
        page-break-inside: auto !important;
        break-inside: auto !important;
    }

    .bill-tpl.thermal {
        width: 74mm !important;
        max-width: 74mm !important;
        min-height: 0 !important;
        height: auto !important;
        padding: 2mm !important;
    }

    /* Flex layouts often rasterize blank on some inkjet drivers. */
    .bill-tpl .flex {
        display: block !important;
    }

    .bill-tpl .flex > div {
        width: 100% !important;
        margin-bottom: 10px !important;
        text-align: left !important;
    }

    .bill-tpl .text-right {
        text-align: left !important;
    }

    .bill-tpl th,
    .bill-tpl td {
        background: transparent !important;
        color: #000 !important;
        border-color: #000 !important;
    }

    .bill-tpl .classic-table thead th,
    .bill-tpl .classic-total .grand td,
    .bill-tpl [style*="background"] {
        background: transparent !important;
        color: #000 !important;
        border-top: 1px solid #000 !important;
        border-bottom: 1.5px solid #000 !important;
        font-weight: 700 !important;
    }

    .bill-tpl .classic-table tbody td {
        border-bottom: 1px solid #333 !important;
    }

    .bill-tpl .classic-total {
        width: 100% !important;
        max-width: 90mm !important;
        margin-left: 0 !important;
    }

    .bill-tpl .classic-footer,
    .bill-tpl .modern-footer,
    .bill-tpl .minimal-footer {
        margin-top: 24px !important;
    }

    .bill-tpl .muted,
    .bill-tpl .small {
        color: #000 !important;
    }

    .no-print { display: none !important; }
}

.receipt-print-overlay {
    position: fixed;
    inset: 0;
    z-index: 240;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3vh 16px;
    background: rgba(8, 40, 24, 0.55);
    overflow: auto;
}

.receipt-print-dialog {
    max-width: min(920px, 96vw);
    width: 100%;
    margin: 0 auto;
    padding: 18px 20px 20px;
    max-height: 94vh;
    overflow: auto;
}

.receipt-print-dialog .bq-panel-head {
    margin-bottom: 12px;
}

.receipt-tpl-picker {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.receipt-tpl-picker--two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 0;
}

.receipt-tpl-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
    justify-items: start;
    align-content: start;
    text-align: left;
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--pos-border, #ddd);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.receipt-tpl-picker--two .receipt-tpl-option {
    min-height: 118px;
    padding: 16px 18px;
    gap: 6px;
}

.receipt-tpl-option i {
    color: var(--pos-maroon, #166534);
}

.receipt-tpl-picker--two .receipt-tpl-option i {
    font-size: 1.15rem;
    margin-bottom: 4px;
}

.receipt-tpl-option strong {
    display: block;
    width: 100%;
    font-size: 0.78rem;
}

.receipt-tpl-picker--two .receipt-tpl-option strong {
    font-size: 0.95rem;
    line-height: 1.3;
}

.receipt-tpl-option span {
    display: block;
    width: 100%;
    font-size: 0.68rem;
    color: var(--pos-muted, #666);
    white-space: normal;
    line-height: 1.4;
}

.receipt-tpl-picker--two .receipt-tpl-option span {
    font-size: 0.78rem;
}

.receipt-tpl-option.is-active {
    border-color: var(--pos-maroon, #166534);
    background: var(--pos-pink-soft, #ecfdf5);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--pos-maroon, #166534) 18%, transparent);
}

.receipt-print-preview {
    max-height: 52vh;
    overflow: auto;
    margin-bottom: 12px;
    border-radius: 12px;
}

.receipt-print-preview.is-thermal .bill-tpl.thermal {
    margin: 0 auto;
}

@media (max-width: 800px) {
    .receipt-tpl-picker {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .receipt-tpl-picker--two {
        grid-template-columns: 1fr;
    }
}
