/* Partner Balances extras (balances-extras.js) */
.bx {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}
.bx-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.bx-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
}
.bx-field select,
.bx-form select,
.bx-form input,
.bx-log select {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 8px;
    background: var(--bg-card, #fff);
    color: inherit;
    font: inherit;
    max-width: 260px;
}
.bx-toolbar-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}
.bx-banner {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 10px;
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
}
.bx-explain {
    background: var(--bg-card, #fff);
    border: 1px dashed var(--border-light, #cbd5e1);
    border-radius: 12px;
    padding: 0.7rem 1rem;
    font-size: 0.88rem;
    line-height: 1.55;
    text-align: right;
}
.bx-explain-note {
    display: block;
    color: var(--text-muted, #64748b);
    font-size: 0.78rem;
    margin-top: 0.2rem;
}

.bx-me-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin: 0.5rem 0;
}
.bx-me-grid small {
    display: block;
    color: var(--text-muted, #64748b);
    font-size: 0.72rem;
}
.bx-me-grid b {
    font-size: 1.1rem;
}
.bx-me-line {
    font-size: 1rem;
    margin: 0.4rem 0;
}
.bx-me-list {
    margin: 0.2rem 0 0 1.1rem;
    font-size: 0.88rem;
}

.bx-pos {
    color: #16a34a;
}
.bx-neg {
    color: #dc2626;
}
.bx-even {
    color: var(--text-muted, #64748b);
}

.bx-settle {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.bx-transfer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4rem 1rem;
    align-items: center;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 10px;
}
.bx-tf-amt {
    text-align: right;
    font-weight: 700;
    font-size: 1.05rem;
}
.bx-tf-amt small {
    display: block;
    font-weight: 400;
    color: var(--text-muted, #64748b);
    font-size: 0.75rem;
}
.bx-tf-act {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}
.bx-badge {
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(100, 116, 139, 0.15);
    color: #475569;
}
.bx-st-proposed {
    background: rgba(245, 158, 11, 0.18);
    color: #b45309;
}
.bx-st-sent {
    background: rgba(59, 130, 246, 0.18);
    color: #1d4ed8;
}
.bx-st-received {
    background: rgba(34, 197, 94, 0.18);
    color: #15803d;
}
.bx-log-title {
    font-weight: 600;
    margin: 1rem 0 0.3rem;
    font-size: 0.9rem;
}
.bx-upl {
    cursor: pointer;
    margin-left: 0.4rem;
    color: var(--color-primary, #6366f1);
}

.bx-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
    margin-top: 0.8rem;
}
.bx-form label {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
}
.bx-form .bx-wide {
    flex: 1 1 220px;
}
.bx-form .bx-wide input {
    max-width: none;
}
.bx-form-col {
    flex-direction: column;
    align-items: stretch;
}
.bx-form-col input {
    max-width: none;
}

.bx-total td,
.bx-total th {
    background: rgba(100, 116, 139, 0.08);
}
.bx-matrix td,
.bx-matrix th {
    text-align: right;
    white-space: nowrap;
}
.bx-matrix th:first-child {
    text-align: left;
}
.bx-diag {
    background: rgba(100, 116, 139, 0.1);
}
.bx-lang {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.bx-msg {
    width: 100%;
    font: inherit;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 10px;
    padding: 0.6rem;
    background: var(--bg-card, #fff);
    color: inherit;
    box-sizing: border-box;
}

/* main table: soft-colour balances, drill-down, alerts */
.bx-chip {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-weight: 700;
}
.bx-chip-debt {
    background: rgba(239, 68, 68, 0.13);
    color: #b91c1c;
}
.bx-chip-credit {
    background: rgba(34, 197, 94, 0.15);
    color: #15803d;
}
.bx-chip-even {
    background: rgba(148, 163, 184, 0.2);
    color: #64748b;
}
.bx-ils,
.bx-state {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted, #64748b);
    font-weight: 400;
}
.bx-drill {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.bx-drill i {
    font-size: 0.65rem;
    margin-left: 0.3rem;
    opacity: 0.55;
}
.bx-alert {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    background: rgba(245, 158, 11, 0.18);
    color: #b45309;
    white-space: nowrap;
}
.bx-has-alert {
    box-shadow: inset 3px 0 0 #f59e0b;
}
.bx-actions-th {
    width: 1%;
}
.bx-wa i {
    color: #25d366;
}

[data-theme='dark'] .bx-chip-debt {
    color: #fca5a5;
}
[data-theme='dark'] .bx-chip-credit {
    color: #86efac;
}

/* phones: one card per partner, the owed / owes figure large, WhatsApp button */
@media (max-width: 720px) {
    .bx-toolbar-actions {
        margin-left: 0;
    }
    .bx-transfer {
        grid-template-columns: 1fr;
    }
    .bx-tf-amt {
        text-align: left;
    }
    #balances-table thead {
        display: none;
    }
    #balances-table,
    #balances-table tbody {
        display: block;
    }
    #balances-table tbody tr.clickable-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.15rem 0.8rem;
        padding: 0.8rem;
        margin-bottom: 0.7rem;
        border: 1px solid var(--border-light, #e2e8f0);
        border-radius: 12px;
        background: var(--bg-card, #fff);
    }
    #balances-table tbody tr.clickable-row td {
        display: block;
        border: 0;
        padding: 0.15rem 0;
        text-align: left;
    }
    #balances-table tbody tr.clickable-row td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.66rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--text-muted, #64748b);
    }
    #balances-table tbody tr.clickable-row td:first-child {
        grid-column: 1 / -1;
        order: -2;
    }
    #balances-table tbody tr.clickable-row td:first-child::before {
        display: none;
    }
    #balances-table tbody tr.clickable-row td.bx-bal-cell {
        grid-column: 1 / -1;
        order: -1;
        font-size: 1.35rem;
        padding: 0.3rem 0 0.5rem;
    }
    #balances-table tbody tr.clickable-row td.bx-actions {
        grid-column: 1 / -1;
    }
    #balances-table tbody tr.clickable-row td.bx-actions::before {
        display: none;
    }
    #balances-table tbody tr.clickable-row td.bx-actions .bx-wa {
        width: 100%;
        justify-content: center;
    }
}
@media print {
    #pb-extras .bx-toolbar,
    #pb-extras .bx-form {
        display: none;
    }
}
