/* ==========================================
   Budget panel — the ledger and its computed totals
   Paired with js/budget-panel.js.
   ========================================== */

.budget-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.budget-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--dark-bg-secondary);
}

.budget-stat-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.budget-stat-value {
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.budget-stat-value--ok {
    color: var(--primary-color);
}

.budget-cur {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.budget-stat-note {
    color: var(--text-muted);
    font-size: 0.7rem;
}

.budget-empty {
    padding: 16px 18px;
    margin-bottom: 18px;
    border: 1px dashed var(--line-2);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
}

.budget-empty strong {
    display: block;
    margin-bottom: 4px;
    color: var(--text-primary);
}

/* ── Tables ──────────────────────────────── */

.budget-subhead {
    margin: 22px 0 8px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.budget-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.budget-table th {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line-2);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.budget-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    color: var(--text-primary);
    vertical-align: middle;
}

.budget-table th.num,
.budget-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.budget-table a {
    color: var(--primary-color);
    text-decoration: none;
}

.budget-table a:hover {
    text-decoration: underline;
}

.budget-amount {
    color: var(--text-primary);
    font-weight: 600;
}

.budget-table--breakdown {
    margin-bottom: 6px;
}

.budget-unallocated {
    /* The italic already says this figure is a remainder rather than a commitment; it does not
       also need to be dim. */
    color: var(--text-primary);
    font-style: italic;
}

.budget-row--inactive td {
    opacity: 0.55;
}

/* A note belongs to the row above it, so it is indented and unseparated. */
.budget-note-row td {
    padding: 0 10px 9px 10px;
    border-bottom: 1px solid var(--line);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-style: italic;
}

.budget-row-actions {
    text-align: right;
    white-space: nowrap;
}

/* .btn-link-danger moved to css/buttons.css — the targeting page needs it too and does not
   load this stylesheet. */

/* ── Actions & inline form ───────────────── */

.budget-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.budget-form {
    margin-top: 18px;
    padding: 18px 20px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--dark-bg-secondary);
}

.budget-form .form-section {
    margin-bottom: 0;
    padding: 0;
    border: none;
    background: transparent;
}

.budget-form .form-actions {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
    /* A seven-column ledger cannot shrink usefully; let it scroll rather than wrap into
       unreadable stacks. */
    .budget-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ── Invoice recipients ──────────────────── */
/* Only rendered when an account has more than one: at that point "invoice to" is a real
   decision, and the dropdown alone did not show what the choices were. */

.budget-billing {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--dark-bg-secondary);
}

.budget-billing-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.budget-billing-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.budget-billing-chip {
    position: relative;
    padding: 3px 10px;
    border: 1px solid var(--line-2);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.76rem;
    cursor: help;
}

.budget-billing-chip--default {
    border-color: rgba(34, 199, 224, 0.4);
    color: var(--primary-color);
}

/* ---- Who this recipient is, on hover ----
   Name, address and payment method only — never payment details, not even the masked hint.
   CSS-only: there is nothing to fetch, the list request already carries all three. */

.budget-billing-card {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 5px;
    width: max-content;
    max-width: 280px;
    padding: 10px 13px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: #1a1d24;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    /* The card holds the recipient's name and address — values, even inside a hover card. */
    color: var(--text-primary);
    font-size: 0.76rem;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    cursor: default;
}

.budget-billing-chip:hover .budget-billing-card,
.budget-billing-chip:focus-visible .budget-billing-card {
    display: flex;
}

.budget-billing-card-name {
    color: var(--text-primary);
    font-weight: 600;
}

.budget-billing-card-address {
    color: var(--text-secondary);
}

.budget-billing-card-empty {
    color: var(--text-muted);
    font-style: italic;
}

.budget-billing-card-pay {
    padding-top: 4px;
    border-top: 1px solid var(--line);
    color: var(--text-muted);
}

/* Free (bonus) credit: money-shaped but never invoiced, so it has to read differently. */
.budget-stat-value--free {
    color: var(--text-primary);
}

.budget-free-tag {
    display: inline-block;
    margin-left: 5px;
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-radius: 3px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

/* Free-credit preview under the amount field. Deliberately quieter than an alert: it is an
   opportunity, not a problem, and it re-renders on every keystroke. */
.budget-free-credit {
    margin: 12px 0 4px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--primary-color);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.03);
}

.budget-free-credit--none {
    border-left-color: var(--line);
    color: var(--text-muted);
    font-size: 0.78rem;
}

.budget-free-credit-head {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.84rem;
}

.budget-free-credit-sub {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

/* The offer ladder: what is published, what applies, what the gap is. */
.budget-offer-table {
    margin: 9px 0 0;
    font-size: 0.75rem;
}

.budget-offer-table th {
    font-size: 0.68rem;
}

.budget-offer-table td {
    padding: 5px 8px;
    color: var(--text-primary);
}

/* The concrete amount under the percentage — a tier reads as money, not as arithmetic homework. */
.budget-offer-grant {
    display: block;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

.budget-offer-state {
    font-size: 0.72rem;
    white-space: nowrap;
}

.budget-offer-row--applied td,
.budget-offer-row--applied .budget-offer-state {
    color: var(--success-color);
}

.budget-offer-row--gap .budget-offer-state {
    color: var(--text-primary);
}

.budget-offer-row--past td,
.budget-offer-row--beaten td {
    color: var(--text-muted);
}

.budget-free-credit-note {
    margin: 9px 0 0;
    color: var(--text-muted);
    font-size: 0.73rem;
    line-height: 1.5;
}

/* ──────────────────────────────────────────────────────────────
   The order: review, terms, confirmation
   ──────────────────────────────────────────────────────────────
   Laid out as an order confirmation reads — heading and date, recipient, what it is
   for, the line items, the conditions — not as a grid of tiles. Tiles gave every
   block the same weight and let the reader pick an order; a document that commits
   money should read top to bottom. */

.budget-order-doc {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.budget-order-title h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.4;
}

.budget-order-stamp {
    margin: 3px 0 0;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
}

.budget-order-section {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.budget-order-section h5 {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Two blocks that belong together — advertisement/campaign, targeting/rates. */
.budget-order-pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}

.budget-order-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 3px 0;
    font-size: 0.79rem;
}

.budget-order-row > span:first-child {
    color: var(--text-muted);
}

.budget-order-row > span:last-child {
    color: var(--text-primary);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── Invoice recipient: an address block, as on an invoice ── */

.budget-order-section--recipient {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(220px, 1fr);
    gap: 4px 18px;
    align-items: start;
}

.budget-order-section--recipient h5 {
    grid-column: 1 / -1;
}

.budget-order-address {
    color: var(--text-primary);
    font-size: 0.82rem;
    font-style: normal;
    line-height: 1.55;
}

.budget-order-address strong {
    display: block;
}

/* ── Line items ── */

.budget-order-items {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.budget-order-items td {
    padding: 7px 0;
    color: var(--text-primary);
    vertical-align: top;
}

.budget-order-items td.num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.budget-order-items tbody td {
    border-bottom: 1px solid var(--line);
}

/* The sub-line under an item: what it means, not another figure. */
.budget-order-item-note {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.45;
}

/* Free credit is money-shaped but never invoiced, so it must not read like a charge. */
/* A free line is marked by its tag, not by being harder to read: the amount on it is still a
   figure somebody has to check against an invoice. */
.budget-order-item--free td {
    color: var(--text-primary);
}

.budget-order-items tfoot td {
    padding: 5px 0;
    color: var(--text-primary);
}

.budget-order-items tfoot tr:first-child td {
    padding-top: 9px;
}

.budget-order-items-total td {
    padding-top: 8px;
    border-top: 1px solid var(--line-2);
    color: var(--text-primary);
    font-size: 0.88rem;
}

/* A figure that is deliberately not stated here. */
.budget-order-open {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.76rem;
}

.budget-order-note {
    margin: 7px 0 0;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.5;
}

.budget-order-notes {
    margin: 0;
    padding-left: 18px;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ── Terms ── */

.budget-order-terms {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.budget-order-terms h5 {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.budget-order-version {
    margin-left: 6px;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

/* Draft terms say so. Presenting unreviewed wording as final would be the worse failure. */
.budget-order-draft {
    margin: 0 0 9px;
    padding: 7px 9px;
    border-left: 3px solid var(--warning-color);
    border-radius: 4px;
    background: rgba(255, 193, 7, 0.08);
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.budget-order-terms-list {
    margin: 0;
    font-size: 0.76rem;
}

.budget-order-terms-list dt {
    margin-top: 7px;
    color: var(--text-primary);
    font-weight: 600;
}

.budget-order-terms-list dd {
    margin: 2px 0 0;
    /* dd is the answer, dt is the question — the terms list had them the other way round. */
    color: var(--text-primary);
    line-height: 1.55;
}

/* ── Acceptance and refusal ── */

.budget-order-accept {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 14px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
}

.budget-order-accept input {
    margin-top: 2px;
}

.budget-order-blockers {
    margin-top: 14px;
    padding: 9px 11px;
    border-left: 3px solid var(--danger-color);
    border-radius: 4px;
    background: rgba(220, 53, 69, 0.08);
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.budget-order-blockers ul {
    margin: 5px 0 0;
    padding-left: 18px;
}

/* ── Receipt ── */

.budget-receipt {
    position: relative;
    margin: 12px 0;
    padding: 14px 16px;
    border: 1px solid var(--success-color);
    border-radius: 8px;
    background: rgba(63, 185, 80, 0.05);
}

.budget-receipt-close {
    position: absolute;
    top: 12px;
    right: 14px;
}

/* Room for the close button, which floats over the heading row. */
.budget-receipt .budget-order-title h4 {
    padding-right: 84px;
}

.budget-receipt-note {
    margin: 0 0 12px;
    color: var(--text-secondary);
    font-size: 0.76rem;
}

@media (max-width: 620px) {
    /* Recipient and facts stack rather than squeezing an address into half a phone. */
    .budget-order-section--recipient {
        grid-template-columns: 1fr;
    }

    .budget-receipt-close {
        position: static;
        margin-bottom: 10px;
    }

    .budget-receipt .budget-order-title h4 {
        padding-right: 0;
    }
}

/* A figure nobody should be comfortable with: delivery that was handed out for free because no
   budget could carry it. Styled to be noticed rather than read past. */
.budget-stat--warn {
    border-color: var(--warning-color);
}

.budget-stat--warn .budget-stat-value {
    color: var(--warning-color);
}
