/**
 * KhataBahi - Modern Invoice Templates & Company Branding Addon CSS
 */

/* 1. Global Box Sizing & Font Rules for Injected Elements */
.kb-tpl-assigned-cell,
.kb-tpl-modal,
.kb-tpl-preview-stage-wrap {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* 2. Company Table: Assigned PDF Template Cell */
.kb-tpl-assigned-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #090d16;
    border: 1px solid #1e293b;
    border-radius: 10px;
    padding: 6px 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}
.kb-tpl-assigned-card.is-core {
    border-color: rgba(245, 158, 11, 0.35);
}
.kb-tpl-assigned-card:hover {
    border-color: #0284c7;
}

.kb-tpl-num-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    background: rgba(2, 132, 199, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.3);
    flex-shrink: 0;
}
.kb-tpl-assigned-card.is-core .kb-tpl-num-badge {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}

.kb-tpl-name-title {
    font-size: 12px;
    font-weight: 800;
    color: #f8fafc;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s ease;
}
.kb-tpl-name-title:hover {
    color: #38bdf8;
}

.kb-tpl-actions-group {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 4px;
    padding-left: 8px;
    border-left: 1px solid #1e293b;
}

.kb-tpl-btn-action {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    text-decoration: none !important;
}

.kb-tpl-btn-eye {
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    border-color: #334155;
    padding: 3px 6px;
}
.kb-tpl-btn-eye:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

.kb-tpl-btn-change {
    background: rgba(2, 132, 199, 0.12);
    color: #38bdf8;
    border-color: rgba(2, 132, 199, 0.3);
}
.kb-tpl-btn-change:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
}

.kb-tpl-btn-reset {
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.3);
}
.kb-tpl-btn-reset:hover {
    background: #d97706;
    color: #ffffff;
    border-color: #d97706;
}

.kb-tpl-default-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2.5px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.25);
    cursor: default;
}

/* 3. Invoice Builder Quick Template Switcher Badge */
.kb-tpl-builder-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 11px;
    color: #cbd5e1;
    margin-top: 6px;
}
.kb-tpl-builder-badge strong {
    color: #38bdf8;
}
.kb-tpl-builder-btn-switch {
    background: rgba(2, 132, 199, 0.2);
    border: 1px solid rgba(2, 132, 199, 0.4);
    color: #38bdf8;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 4px;
}
.kb-tpl-builder-btn-switch:hover {
    background: #0284c7;
    color: #ffffff;
}

/* 4. Modal Base Styling */
.kb-tpl-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.kb-tpl-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
}
.kb-tpl-modal-container {
    position: relative;
    z-index: 2;
    width: 95%;
    max-width: 960px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.kb-tpl-preview-container {
    max-width: 900px;
}

.kb-tpl-modal-box {
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #f8fafc;
}

/* Modal Header */
.kb-tpl-modal-header {
    background: #090d16;
    padding: 14px 20px;
    border-bottom: 1px solid #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.kb-tpl-modal-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.kb-tpl-modal-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(2, 132, 199, 0.15);
    border: 1px solid rgba(2, 132, 199, 0.3);
    color: #38bdf8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.kb-tpl-modal-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.kb-tpl-modal-title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.2px;
}
.kb-tpl-modal-subtitle {
    margin: 2px 0 0 0;
    font-size: 11.5px;
    color: #94a3b8;
}
.kb-tpl-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 800;
}
.kb-tpl-badge-gst {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.kb-tpl-badge-nongst {
    background: rgba(2, 132, 199, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.3);
}

.kb-tpl-modal-close {
    background: none;
    border: none;
    font-size: 26px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.15s ease;
}
.kb-tpl-modal-close:hover {
    color: #ffffff;
}

/* Banner */
.kb-tpl-banner {
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
}
.kb-tpl-banner-gst {
    background: rgba(6, 78, 59, 0.3);
    border-bottom: 1px solid rgba(16, 185, 129, 0.3);
    color: #6ee7b7;
}
.kb-tpl-banner-nongst {
    background: rgba(12, 74, 110, 0.3);
    border-bottom: 1px solid rgba(2, 132, 199, 0.3);
    color: #7dd3fc;
}
.kb-tpl-banner-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Filter Toolbar */
.kb-tpl-toolbar {
    padding: 10px 18px;
    background: #0b1120;
    border-bottom: 1px solid #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.kb-tpl-filters {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.kb-tpl-filter-btn {
    background: transparent;
    border: 1px solid #334155;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}
.kb-tpl-filter-btn:hover {
    color: #ffffff;
    border-color: #64748b;
}
.kb-tpl-filter-btn.active {
    background: #0284c7;
    border-color: #0284c7;
    color: #ffffff;
}

/* Grid & Cards */
.kb-tpl-grid-wrap {
    padding: 16px;
    overflow-y: auto;
    max-height: 52vh;
}
.kb-tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.kb-tpl-card {
    background: #090d16;
    border: 2px solid #1e293b;
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.18s ease;
    position: relative;
}
.kb-tpl-card:hover {
    border-color: #38bdf8;
    background: #0f172a;
    transform: translateY(-2px);
}
.kb-tpl-card.selected {
    border-color: #0284c7;
    background: #0e1e36;
    box-shadow: 0 0 0 1px #0284c7, 0 4px 14px rgba(2, 132, 199, 0.25);
}
.kb-tpl-card.is-core-card {
    border-color: rgba(245, 158, 11, 0.35);
}
.kb-tpl-card.is-core-card.selected {
    border-color: #f59e0b;
    box-shadow: 0 0 0 1px #f59e0b, 0 4px 14px rgba(245, 158, 11, 0.25);
}

.kb-tpl-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.kb-tpl-card-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 800;
    color: #38bdf8;
}
.kb-tpl-card.is-core-card .kb-tpl-card-num {
    color: #fbbf24;
}
.kb-tpl-card-type-tag {
    font-size: 9.5px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
}
.kb-tpl-card-title {
    font-size: 12px;
    font-weight: 800;
    color: #ffffff;
    line-height: 1.25;
    margin-bottom: 4px;
}
.kb-tpl-card-desc {
    font-size: 10px;
    color: #94a3b8;
    line-height: 1.35;
    margin-bottom: 10px;
}
.kb-tpl-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #1e293b;
    padding-top: 8px;
    font-size: 9.5px;
    color: #64748b;
    font-weight: 600;
}
.kb-tpl-card-qr-tag {
    color: #38bdf8;
}
.kb-tpl-card-noqr-tag {
    color: #fbbf24;
}

/* Footer */
.kb-tpl-modal-footer {
    background: #090d16;
    padding: 12px 20px;
    border-top: 1px solid #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.kb-tpl-selected-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
}
.kb-tpl-selected-lbl {
    color: #64748b;
}
.kb-tpl-selected-val {
    color: #38bdf8;
    font-weight: 800;
}
.kb-tpl-selected-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(2, 132, 199, 0.2);
    color: #38bdf8;
    border: 1px solid rgba(2, 132, 199, 0.3);
}

.kb-tpl-footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.kb-tpl-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}
.kb-tpl-btn-secondary {
    background: #1e293b;
    color: #94a3b8;
    border-color: #334155;
}
.kb-tpl-btn-secondary:hover {
    background: #334155;
    color: #ffffff;
}
.kb-tpl-btn-preview {
    background: rgba(2, 132, 199, 0.15);
    color: #38bdf8;
    border-color: rgba(2, 132, 199, 0.35);
}
.kb-tpl-btn-preview:hover {
    background: #0284c7;
    color: #ffffff;
}
.kb-tpl-btn-primary {
    background: #0284c7;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}
.kb-tpl-btn-primary:hover {
    background: #0369a1;
}

/* 5. Live Full A4 Preview Stage */
.kb-tpl-preview-stage-wrap {
    background: #090d16;
    padding: 24px;
    overflow: auto;
    max-height: 78vh;
    display: flex;
    justify-content: center;
}
#kb-tpl-stage-render-target {
    background: #ffffff;
    width: 800px;
    min-width: 800px;
    max-width: 800px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* 6. Strict Print Styles for Invoice Output */
@media print {
    .no-print,
    .kb-tpl-modal-header,
    .kb-tpl-modal-footer,
    .kb-tpl-toolbar,
    .kb-tpl-banner {
        display: none !important;
    }
    body, html {
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .kb-invoice-paper {
        margin: 0 auto !important;
        border: none !important;
        box-shadow: none !important;
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
