/* Printable Invoice Paper Styles - A4 Sizing & Light Weight Vector Styling (KhataBahi) */
.kb-invoice-paper {
    background: #ffffff;
    padding: 0;
    margin: 0 auto;
    max-width: 800px;
    width: 100%;
    max-height: 280mm;
    height: 280mm;
    min-height: 250mm;
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    position: relative;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
}

.kb-invoice-header,
.kb-template-1 > div:first-child,
.kb-template-2 > div:first-child {
    flex: 0 0 auto;
    width: 100%;
    min-height: 108px !important;
}

.kb-invoice-body,
.kb-template-1 > div:nth-child(2),
.kb-template-2 > div:nth-child(2) {
    flex: 1 1 auto;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    width: 100%;
}

.kb-invoice-footer,
.kb-tpl1-bottom-bar,
.kb-tpl2-footer-banner {
    flex: 0 0 auto;
    width: 100%;
    margin-top: auto !important;
}

.kb-text-center { text-align: center; }
.kb-text-right { text-align: right; }

/* Template 1: Classic Corporate GST Tax Invoice */
.kb-template-1 .kb-tpl1-type {
    text-align: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 1.5px;
    color: #475569;
}

.kb-template-1 .kb-tpl1-company {
    text-align: center;
    color: #1e3a8a;
    font-size: 24px;
    font-weight: 800;
    margin: 6px 0 2px 0;
    letter-spacing: 0.5px;
}

.kb-template-1 .kb-tpl1-sub {
    text-align: center;
    font-size: 11px;
    color: #d97706;
    font-weight: 600;
}

.kb-template-1 .kb-tpl1-sub span { margin: 0 8px; }
.kb-template-1 .kb-tpl1-divider { border: 0; border-top: 2px solid #0f172a; margin: 12px 0 16px 0; }

.kb-template-1 .kb-tpl1-meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.kb-template-1 .kb-tpl1-billto { width: 65%; }
.kb-template-1 .kb-tpl1-invdetails { width: 30%; text-align: right; }

.kb-template-1 .kb-tpl1-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #334155;
    margin-bottom: 16px;
    font-size: 12px;
}

.kb-template-1 .kb-tpl1-table th, 
.kb-template-1 .kb-tpl1-table td {
    border: 1px solid #334155;
    padding: 7px 10px;
}

.kb-template-1 .kb-tpl1-table th {
    background: #f8fafc;
    font-weight: 700;
}

.kb-template-1 .kb-tpl1-notes {
    font-size: 11px;
    margin-bottom: 16px;
    color: #475569;
}

.kb-template-1 .kb-tpl1-footer-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 11px;
    margin-bottom: 16px;
}

.kb-template-1 .kb-sig-img { max-height: 45px; }

.kb-template-1 .kb-tpl1-bottom-bar {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    border-top: 1px solid #cbd5e1;
    padding-top: 8px;
    margin-top: 10px;
}

/* Template 2: Modern Header Banner & UPI QR Code */
.kb-template-2 { padding: 0; border: 1px solid #334155; }

.kb-template-2 .kb-tpl2-header-banner {
    background: #0f172a;
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kb-template-2 .kb-tpl2-logo-text { font-size: 22px; font-weight: 800; color: #38bdf8; }

.kb-template-2 .kb-tpl2-company-info h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
}

.kb-template-2 .kb-tpl2-cin { font-size: 11px; opacity: 0.85; color: #94a3b8; }

.kb-template-2 .kb-tpl2-meta-bar {
    padding: 12px 20px;
    text-align: right;
    font-size: 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.kb-template-2 .kb-tpl2-address-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-bottom: 1px solid #000;
}

.kb-template-2 .kb-tpl2-address-box {
    padding: 12px 16px;
    font-size: 12px;
    line-height: 1.5;
}

.kb-template-2 .kb-tpl2-address-box:first-child { border-right: 1px solid #000; }

.kb-template-2 .kb-tpl2-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.kb-template-2 .kb-tpl2-table th,
.kb-template-2 .kb-tpl2-table td {
    border: 1px solid #000;
    padding: 8px 10px;
}

.kb-template-2 .kb-tpl2-table th {
    background: #f1f5f9;
}

.kb-template-2 .kb-tpl2-summary-grid {
    display: grid;
    grid-template-columns: 1.2fr 1.2fr 1fr;
    border-bottom: 1px solid #000;
    font-size: 11px;
}

.kb-template-2 .kb-tpl2-bank-box,
.kb-template-2 .kb-tpl2-words-box,
.kb-template-2 .kb-tpl2-totals-box {
    padding: 12px;
    border-right: 1px solid #000;
}

.kb-template-2 .kb-tpl2-totals-box { border-right: none; text-align: center; }

.kb-template-2 .kb-tpl2-grand-row {
    font-size: 14px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 6px;
    margin-bottom: 8px;
}

#kb-preview-qr, #kb-upi-qrcode, .kb-qr-container {
    display: inline-block !important;
    width: 81px !important;
    min-width: 81px !important;
    height: 81px !important;
    min-height: 81px !important;
    padding: 2px !important;
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 5px !important;
    text-align: center !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

#kb-preview-qr canvas, #kb-upi-qrcode canvas, .kb-qr-container canvas {
    width: 75px !important;
    height: 75px !important;
    max-width: 75px !important;
    max-height: 75px !important;
    margin: 0 auto !important;
    display: block !important;
    object-fit: contain !important;
}

#kb-preview-qr img[data-uploaded="true"], #kb-upi-qrcode img[data-uploaded="true"], .kb-qr-container img[data-uploaded="true"] {
    width: 75px !important;
    height: 75px !important;
    max-width: 75px !important;
    max-height: 75px !important;
    margin: 0 auto !important;
    display: block !important;
    object-fit: contain !important;
}

#kb-preview-qr img:not([data-uploaded="true"]), #kb-upi-qrcode img:not([data-uploaded="true"]), .kb-qr-container img:not([data-uploaded="true"]) {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

.kb-template-2 .kb-tpl2-footer-banner {
    background: #1e293b;
    color: #ffffff;
    text-align: center;
    padding: 10px 15px;
    font-size: 11px;
    font-weight: 500;
}

/* Template 3: CA Professional GST */
.kb-template-3 { border: 2px solid #0f172a; padding: 15mm; font-size: 12px; }
.kb-template-3 .kb-tpl3-header { display: flex; justify-content: space-between; border-bottom: 2px solid #0f172a; padding-bottom: 10px; }
.kb-template-3 .kb-tpl3-grid-table { width: 100%; border-collapse: collapse; margin: 15px 0; }
.kb-template-3 .kb-tpl3-grid-table td { border: 1px solid #64748b; padding: 8px; }
.kb-template-3 .kb-tpl3-items-table { width: 100%; border-collapse: collapse; margin-bottom: 15px; }
.kb-template-3 .kb-tpl3-items-table th, .kb-template-3 .kb-tpl3-items-table td { border: 1px solid #64748b; padding: 7px; text-align: center; }

/* Template 4: Minimalist Modern */
.kb-template-4 { font-family: 'Segoe UI', sans-serif; padding: 15mm; }
.kb-template-4 .kb-tpl4-line { border: 0; border-top: 2px solid #0f172a; margin: 15px 0; }
.kb-template-4 .kb-tpl4-table { width: 100%; border-collapse: collapse; }
.kb-template-4 .kb-tpl4-table th { border-bottom: 2px solid #0f172a; text-align: left; padding: 10px; }
.kb-template-4 .kb-tpl4-table td { padding: 10px; border-bottom: 1px solid #e2e8f0; }

/* Template 5: Creative Agency Accent */
.kb-template-5 { display: flex; overflow: hidden; }
.kb-template-5 .kb-tpl5-sidebar-accent { width: 10px; background: #2563eb; }
.kb-template-5 .kb-tpl5-content { flex: 1; padding: 15mm; }

/* Template 6: Retail Receipt */
.kb-template-6 { max-width: 100%; font-family: 'Courier New', monospace; border: 1px dashed #000; padding: 15mm; }

/* Print Media & A4 Page Export Optimization */
@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: #ffffff !important;
        width: 210mm !important;
        height: 297mm !important;
        overflow: hidden !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    body * {
        visibility: hidden !important;
    }
    #kb-preview-modal, #modal-invoice-preview,
    #kb-invoice-print-area, #kb-invoice-print-area *,
    #preview-render-target, #preview-render-target * {
        visibility: visible !important;
    }
    #kb-preview-modal, #modal-invoice-preview {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        background: transparent !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        overflow: hidden !important;
    }
    .no-print, .kb-modal-header {
        display: none !important;
    }
    .kb-invoice-paper {
        width: 210mm !important;
        max-width: 210mm !important;
        max-height: 297mm !important;
        height: 297mm !important;
        min-height: 297mm !important;
        box-shadow: none !important;
        border: none !important;
        margin: 0 auto !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        page-break-after: avoid !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    .kb-invoice-header,
    .kb-template-1 > div:first-child,
    .kb-template-2 > div:first-child {
        flex: 0 0 auto !important;
        min-height: 108px !important;
    }
    .kb-invoice-body,
    .kb-template-1 > div:nth-child(2),
    .kb-template-2 > div:nth-child(2) {
        flex: 1 1 auto !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        overflow: hidden !important;
    }
    .kb-invoice-footer,
    .kb-tpl1-bottom-bar,
    .kb-tpl2-footer-banner,
    .kb-template-1 > div:last-child,
    .kb-template-2 > div:last-child {
        flex: 0 0 auto !important;
        margin-top: auto !important;
    }
}
