/* ============================================================
   Billing — Patient Tab + Cross-patient pages + Report
   ============================================================ */

/* ─── Billing Tab bar (inside patient profile) ─── */
.bil-tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 20px;
    margin-top: -4px;
}
.bil-tab {
    padding: 9px 22px;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s;
    user-select: none;
}
.bil-tab.active {
    color: #1565c0;
    border-bottom-color: #1565c0;
}
.bil-tab:hover:not(.active) {
    color: #333;
}

/* ─── Billing Panel (inside patient form) ─── */
.bil-panel {
    padding: 0 0 40px 0;
}

.bil-wallet-card {
    background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
    color: #fff;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.bil-wallet-label {
    font-size: 12px;
    opacity: 0.8;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
}
.bil-wallet-amount {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.bil-wallet-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}
.bil-wallet-btn {
    background: rgba(255,255,255,0.18);
    color: #fff;
    border: 1.5px solid rgba(255,255,255,0.4);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.bil-wallet-btn:hover {
    background: rgba(255,255,255,0.28);
}

/* ─── Section header row ─── */
.bil-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.bil-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a2e;
}
.bil-add-btn {
    background: #1565c0;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.bil-add-btn:hover { background: #0d47a1; }

/* ─── Invoice table ─── */
.bil-table-wrap {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 24px;
}
.bil-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.bil-table thead tr {
    background: #f7f8fa;
    border-bottom: 1.5px solid #e0e0e0;
}
.bil-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: #666;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.bil-table td {
    padding: 11px 14px;
    border-bottom: 0.5px solid #f0f0f0;
    color: #333;
    vertical-align: middle;
}
.bil-table tbody tr:last-child td { border-bottom: none; }
.bil-table tbody tr { cursor: pointer; transition: background 0.1s; }
.bil-table tbody tr:hover { background: #f7f8fa; }
.bil-table .bil-empty {
    text-align: center;
    color: #aaa;
    font-size: 13px;
    padding: 24px;
    cursor: default;
}

/* ─── State chips ─── */
.bil-chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.bil-chip-draft    { background:#f5f5f5; color:#666; }
.bil-chip-confirmed{ background:#E6F1FB; color:#185FA5; }
.bil-chip-warning  { background:#FFF3E0; color:#B45309; }
.bil-chip-paid     { background:#E1F5EE; color:#085041; }
.bil-chip-cancelled{ background:#FCEBEB; color:#A32D2D; }
.bil-chip-credit   { background:#E1F5EE; color:#085041; }
.bil-chip-debit    { background:#FCEBEB; color:#A32D2D; }
.bil-chip-posted   { background:#E6F1FB; color:#185FA5; }

/* ─── Modal overlay ─── */
.bil-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}
.bil-overlay.open { display: flex; }

.bil-modal {
    background: #fff;
    border-radius: 14px;
    width: 640px;
    max-width: 96vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    overflow: hidden;
}
.bil-modal-lg { width: 780px; }

.bil-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.bil-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
}
.bil-modal-sub {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}
.bil-modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.bil-modal-close:hover { color: #333; }

.bil-modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}
.bil-modal-foot {
    padding: 14px 24px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ─── Form controls inside modals ─── */
.bil-field { margin-bottom: 14px; }
.bil-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #444;
    margin-bottom: 5px;
}
.bil-req { color: #e53e3e; }
.bil-input, .bil-select, .bil-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    color: #222;
    box-sizing: border-box;
    transition: border-color 0.15s;
    background: #fff;
}
.bil-input:focus, .bil-select:focus, .bil-textarea:focus {
    outline: none;
    border-color: #1565c0;
}
.bil-textarea { resize: vertical; min-height: 60px; }
.bil-row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.bil-row3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

/* ─── Invoice line items ─── */
.bil-lines-wrap {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 14px;
}
.bil-lines-head {
    display: grid;
    grid-template-columns: 90px 1fr 80px 100px 70px 90px 36px;
    gap: 0;
    background: #f7f8fa;
    border-bottom: 1px solid #e5e7eb;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #666;
    letter-spacing: 0.3px;
}
.bil-line-row {
    display: grid;
    grid-template-columns: 90px 1fr 80px 100px 70px 90px 36px;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 0.5px solid #f0f0f0;
    align-items: center;
}
.bil-line-row:last-child { border-bottom: none; }
.bil-line-select { padding: 5px 8px; font-size: 12px; }
.bil-line-input  { padding: 5px 8px; font-size: 12px; }
.bil-line-subtotal {
    font-size: 13px;
    font-weight: 600;
    color: #1565c0;
    text-align: right;
    padding-right: 4px;
}
.bil-line-del {
    background: none;
    border: none;
    color: #e53e3e;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.bil-add-line-btn {
    background: none;
    border: 1.5px dashed #cbd5e0;
    border-radius: 8px;
    width: 100%;
    padding: 9px;
    font-size: 12px;
    color: #888;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    margin-top: 6px;
}
.bil-add-line-btn:hover { border-color: #1565c0; color: #1565c0; }

/* ─── Invoice totals ─── */
.bil-totals {
    background: #f7f8fa;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 13px;
}
.bil-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    color: #555;
}
.bil-totals-row.total {
    font-weight: 700;
    font-size: 15px;
    color: #1a1a2e;
    border-top: 1px solid #e0e0e0;
    margin-top: 6px;
    padding-top: 8px;
}
.bil-totals-row.balance {
    font-weight: 700;
    color: #e53e3e;
}
.bil-totals-row.balance-zero { color: #085041; }

/* ─── Receipt detail inside invoice modal ─── */
.bil-receipts-list {
    margin-top: 4px;
}
.bil-receipt-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: #444;
}
.bil-receipt-row .rcp-name { font-weight: 600; color: #1565c0; }
.bil-receipt-row .rcp-amt  { font-weight: 600; color: #085041; }

/* ─── Wallet tab ─── */
.bil-wallet-tx-list { margin-top: 8px; }
.bil-tx-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    border-bottom: 0.5px solid #f0f0f0;
    font-size: 12px;
}
.bil-tx-row:last-child { border-bottom: none; }
.bil-tx-ref { font-weight: 600; color: #333; }
.bil-tx-date { color: #888; font-size: 11px; }
.bil-tx-credit { color: #085041; font-weight: 700; }
.bil-tx-debit  { color: #A32D2D; font-weight: 700; }
.bil-tx-balance{ color: #1565c0; font-size: 11px; }

/* ─── Payment modal info box ─── */
.bil-info-box {
    background: #f0f6ff;
    border: 1px solid #bee3f8;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    font-size: 12px;
    color: #1565c0;
}
.bil-info-box .bil-info-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
}
.bil-info-box .bil-info-row .bil-info-val {
    font-weight: 700;
}

/* ─── Separator ─── */
.bil-separator {
    border: none;
    border-top: 1px solid #f0f0f0;
    margin: 16px 0;
}

/* ─── Buttons ─── */
.bil-btn {
    padding: 9px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}
.bil-btn-primary { background: #1565c0; color: #fff; }
.bil-btn-primary:hover { background: #0d47a1; }
.bil-btn-success { background: #085041; color: #fff; }
.bil-btn-success:hover { background: #064535; }
.bil-btn-danger  { background: #e53e3e; color: #fff; }
.bil-btn-danger:hover  { background: #c53030; }
.bil-btn-warning { background: #d97706; color: #fff; }
.bil-btn-warning:hover { background: #b45309; }
.bil-btn-outline {
    background: #fff;
    color: #555;
    border: 1.5px solid #d1d5db;
}
.bil-btn-outline:hover { background: #f7f8fa; }
.bil-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Error / toast ─── */
.bil-error {
    color: #e53e3e;
    font-size: 12px;
    margin-top: 8px;
    display: none;
}
.bil-error.show { display: block; }
.bil-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1a1a2e;
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    z-index: 3000;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}
.bil-toast.show { opacity: 1; transform: translateY(0); }

/* ─── Cross-patient pages (billing_invoices, billing_items) ─── */
.bilp-page {
    padding: 24px 28px;
    max-width: 1100px;
}
.bilp-topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
    flex-wrap: wrap;
}
.bilp-title { font-size: 20px; font-weight: 700; color: #1a1a2e; }
.bilp-sub   { font-size: 13px; color: #888; margin-top: 2px; }
.bilp-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.bilp-chip {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid #d1d5db;
    background: #fff;
    color: #666;
    transition: all 0.15s;
}
.bilp-chip.active { background: #1565c0; color: #fff; border-color: #1565c0; }

/* ─── Report page ─── */
.bilr-page {
    padding: 24px 28px;
    max-width: 1100px;
}
.bilr-topbar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.bilr-date-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.bilr-date-label { font-size: 12px; font-weight: 600; color: #555; }
.bilr-date-input {
    padding: 8px 12px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    color: #222;
}
.bilr-date-input:focus { outline: none; border-color: #1565c0; }
.bilr-fetch-btn {
    background: #1565c0;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.bilr-today-btn {
    background: #fff;
    color: #555;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.bilr-title { font-size: 20px; font-weight: 700; color: #1a1a2e; white-space: nowrap; }

/* Export buttons */
.bilr-export-group { display: flex; gap: 6px; margin-left: auto; }
.bilr-export-btn {
    background: #fff;
    color: #1565c0;
    border: 1.5px solid #1565c0;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.bilr-export-btn:hover { background: #e8f0fe; }

/* Summary cards */
.bilr-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.bilr-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px 20px;
}
.bilr-card-label { font-size: 11px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.bilr-card-value { font-size: 22px; font-weight: 700; color: #1a1a2e; }
.bilr-card-value.positive { color: #085041; }
.bilr-card-value.warning  { color: #C07000; }
.bilr-card-desc { font-size: 10px; color: #aaa; margin-top: 5px; line-height: 1.3; }

/* Tab filter */
.bilr-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 16px;
}
.bilr-tab {
    padding: 9px 22px;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.bilr-tab:hover  { color: #1565c0; }
.bilr-tab.active { color: #1565c0; border-bottom-color: #1565c0; }

/* Status filter bar */
.bilr-status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.bilr-status-chip {
    padding: 5px 16px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    border: 1.5px solid #d1d5db;
    background: #fff;
    color: #555;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.bilr-status-chip:hover { border-color: #1565c0; color: #1565c0; }
.bilr-status-chip.active { background: #1565c0; color: #fff; border-color: #1565c0; }
.bilr-status-chip[data-status="unpaid"].active  { background: #6b7280; border-color: #6b7280; }
.bilr-status-chip[data-status="partial"].active { background: #C07000; border-color: #C07000; }
.bilr-status-chip[data-status="paid"].active    { background: #085041; border-color: #085041; }
.bilr-status-count { font-size: 12px; color: #888; margin-left: 4px; }

/* Totals footer row */
.bilr-tfoot td {
    font-weight: 700;
    background: #f1f5f9;
    border-top: 2px solid #d1d5db;
    font-size: 13px;
}

.bilr-section { margin-bottom: 28px; }
.bilr-section-title { font-size: 14px; font-weight: 700; color: #1a1a2e; margin-bottom: 10px; }

/* ─── Print styles ─── */
@media print {
    .th-sidebar, .th-topnav, .bil-wallet-actions, .bil-add-btn,
    .bilr-topbar button, .bilr-export-group, .bilr-tabs,
    .bil-overlay, .bil-toast, .no-print { display: none !important; }
    .th-main { margin-left: 0 !important; }
    .th-content { padding: 0 !important; }
    .bilr-cards { grid-template-columns: repeat(2, 1fr); }
    .bilr-card-desc { display: none; }
    .dr-report-wrap { font-size: 11px; }
    #bilr-inv-section, #bilr-rcp-section { display: block !important; }
    @page { size: A4 landscape; margin: 10mm; }
}

/* ─── Daily Report ─── */
.dr-report-wrap {
    font-family: Arial, sans-serif;
    font-size: 12px;
    max-width: 1100px;
    color: #111;
}
.dr-header-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1.5px solid #000;
    margin-bottom: 0;
}
.dr-from-cell, .dr-date-cell {
    padding: 5px 10px;
    background: #ffff00;
    font-weight: 700;
    font-size: 12px;
}
.dr-date-cell { text-align: right; color: #ff6600; }
.dr-field-label { color: #000; }
.dr-date-val { color: #cc0000; font-weight: 700; }

.dr-table {
    width: 100%;
    border-collapse: collapse;
    border: 1.5px solid #000;
    margin-top: 0;
}
.dr-table th, .dr-table td { border: 1px solid #999; padding: 4px 8px; }
.dr-th-label { text-align: center; background: #1565c0; color: #fff; font-weight: 700; font-size: 11px; }
.dr-th-count, .dr-th-amount { text-align: center; background: #1565c0; color: #fff; font-weight: 700; font-size: 11px; width: 60px; }
.dr-divider { border: none !important; border-left: 2px solid #000 !important; width: 4px; padding: 0 !important; background: #000; }

.dr-label { font-size: 11.5px; }
.dr-count { text-align: center; font-size: 11.5px; }
.dr-amount { text-align: right; font-size: 11.5px; min-width: 80px; }
.dr-row-highlight { background: #fff8dc; }
.dr-row-empty { color: #bbb; }
.dr-total-row td { font-weight: 700; border-top: 2px solid #000; }
.dr-balance-row td { border-top: 2px solid #000; }

.dr-input {
    width: 90px;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px 5px;
    font-size: 11.5px;
    text-align: right;
}
@media print { .dr-input { border: none; } }
