/* 09-billing: staff hosting-billing pages (/hosting, /invoices). Owned by lane A3, then B3 (1B).
   Loads after 08-admin-components and before 21-theme-radzen (App.razor order is load-bearing).
   Use the role tokens from 02-tokens.css (--foreground, --border, --card, --success, --danger,
   --*-strong for text on tints); never the legacy appearance-named aliases.
   The public pay pages do NOT use this file: they are script-free, CSP 'self'-only, and link
   wwwroot/css/pay.css (lane A4).

   Mobile first: base rules are the phone layout; the min-width queries widen it. */

/* ---- Page furniture --------------------------------------------------------- */
.bill-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.bill-toolbar .header-actions {
    flex-wrap: wrap;
}

/* Counts inside the filter pills (.pill from 08 has no count slot of its own). */
.pill .segmented-count {
    margin-left: 6px;
}

.pill.active .segmented-count {
    background: var(--primary-ink);
    color: var(--primary);
}

.bill-muted {
    color: var(--foreground-muted);
    font-size: 0.78rem;
}

.bill-chip-gap {
    margin-left: 6px;
}

.bill-sub {
    display: block;
    color: var(--foreground-muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

/* ---- Banners (billing disabled, standing notice, charge result) -------------
   Tint fill + intent-coloured rule; the text stays --foreground so it clears AA on
   every tint, and only the glyph takes the -strong ink. */
.bill-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: var(--hairline) solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    background: var(--card);
    color: var(--foreground);
    font-size: 0.8125rem;
    line-height: 1.45;
}

.bill-banner > .bi {
    font-size: 1.1rem;
    line-height: 1.3;
    flex-shrink: 0;
}

.bill-banner strong {
    display: block;
    margin-bottom: 2px;
}

.bill-banner .bill-banner-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bill-banner.warning { background: var(--warning-subtle); border-color: var(--warning); }
.bill-banner.warning > .bi { color: var(--warning-strong); }
.bill-banner.danger { background: var(--danger-subtle); border-color: var(--danger); }
.bill-banner.danger > .bi { color: var(--danger-strong); }
.bill-banner.info { background: var(--info-subtle); border-color: var(--info); }
.bill-banner.info > .bi { color: var(--info-strong); }
.bill-banner.success { background: var(--success-subtle); border-color: var(--success); }
.bill-banner.success > .bi { color: var(--success-strong); }
.bill-banner.neutral { background: var(--neutral-subtle); border-color: var(--border-strong); }
.bill-banner.neutral > .bi { color: var(--foreground-muted); }

/* ---- Forms -------------------------------------------------------------------
   One column on a phone, two from 720px. .span-2 fields take the full row. */
.bill-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px 16px;
}

.bill-form .form-group {
    margin-bottom: 0;
    min-width: 0;
}

.bill-hint {
    display: block;
    margin-top: 4px;
    color: var(--foreground-subtle);
    font-size: 0.72rem;
}

.bill-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--foreground);
    cursor: pointer;
}

.bill-check input {
    margin-top: 3px;
}

.bill-check.is-disabled {
    color: var(--foreground-muted);
    cursor: default;
}

.bill-errors {
    margin: 0;
    padding: 10px 14px 10px 30px;
    border: var(--hairline) solid var(--danger);
    border-radius: var(--radius);
    background: var(--danger-subtle);
    color: var(--foreground);
    font-size: 0.8rem;
}

.bill-errors li + li {
    margin-top: 2px;
}

.bill-form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}

/* ---- Invoice line editor -----------------------------------------------------
   A phone stacks each line as a small card; from 720px it is one row per line. */
.bill-lines {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bill-line {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    border: var(--hairline) solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.bill-line .line-desc {
    grid-column: 1 / -1;
}

.bill-line .line-amount {
    align-self: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.bill-line .line-remove {
    justify-self: end;
    align-self: center;
}

.bill-line label {
    display: block;
    color: var(--foreground-muted);
    font-size: 0.7rem;
    margin-bottom: 3px;
}

.bill-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 10px 2px 0;
    font-size: 0.9rem;
}

.bill-total strong {
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
}

/* ---- Detail pages ------------------------------------------------------------ */
.bill-figures {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.bill-figure {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.bill-figure span {
    color: var(--foreground-muted);
    font-size: 0.72rem;
}

.bill-figure strong {
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.bill-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bill-actions .action-row + .action-row {
    padding-top: 12px;
    border-top: var(--hairline) solid var(--border);
}

.bill-actions .action-controls {
    flex-wrap: wrap;
}

/* A disabled action must not look pressable. The shared rule only dims it (opacity), which
   leaves a filled green or red button that still reads as live on the dark theme (live pass,
   "Charge $1.00" with no card on file). Here it becomes a flat, muted, outlined control. */
.bill-actions .btn:disabled,
.bill-actions .btn:disabled:hover,
.bill-banner-actions .btn:disabled,
.bill-banner-actions .btn:disabled:hover,
.bill-form-actions .btn:disabled,
.bill-form-actions .btn:disabled:hover {
    opacity: 1;
    filter: none;
    background: var(--neutral-subtle);
    border-color: var(--border);
    color: var(--foreground-subtle);
    cursor: not-allowed;
}

.bill-memo {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 0.8125rem;
}

/* ---- Stacked tables ----------------------------------------------------------
   On a phone each row becomes a card: the header row is hidden and every cell
   carries its own label from data-label. From 720px it is an ordinary table. */
.bill-table thead {
    display: none;
}

.bill-table,
.bill-table tbody,
.bill-table tr,
.bill-table td {
    display: block;
    width: 100%;
}

.bill-table tr {
    padding: 10px 14px;
    border-bottom: var(--hairline) solid var(--border);
}

.bill-table tbody tr:last-child {
    border-bottom: none;
}

.bill-table td,
.data-table.bill-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 3px 0;
    border-bottom: none;
    text-align: right;
}

.bill-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--foreground-muted);
    font-size: 0.72rem;
    text-align: left;
}

.bill-table td.bill-primary {
    display: block;
    text-align: left;
    padding-bottom: 6px;
}

.bill-table td.bill-primary::before {
    content: none;
}

.bill-table .empty-row td {
    display: block;
    text-align: center;
}

.bill-table td.bill-hide-sm {
    display: none;
}

.bill-table .empty-row td::before {
    content: none;
}

@media (min-width: 720px) {
    .bill-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bill-form .span-2 {
        grid-column: 1 / -1;
    }

    .bill-line {
        grid-template-columns: minmax(0, 1fr) 90px 130px 110px auto;
        align-items: end;
        padding: 0;
        border: none;
        background: none;
    }

    .bill-line .line-desc {
        grid-column: auto;
    }

    .bill-line .line-amount {
        align-self: end;
        padding-bottom: 8px;
        text-align: right;
    }

    .bill-line .line-remove {
        align-self: end;
    }

    .bill-figures {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .bill-table {
        display: table;
    }

    .bill-table thead {
        display: table-header-group;
    }

    .bill-table tbody {
        display: table-row-group;
    }

    .bill-table tr {
        display: table-row;
        padding: 0;
        border-bottom: none;
    }

    .bill-table td,
    .data-table.bill-table td {
        display: table-cell;
        padding: 8px 14px;
        border-bottom: var(--hairline) solid var(--border);
        text-align: left;
        width: auto;
    }

    .data-table.bill-table td.num {
        text-align: right;
    }

    .bill-table td::before {
        content: none;
    }

    .bill-table td.bill-primary {
        display: table-cell;
        padding-bottom: 8px;
    }

    .bill-table tbody tr:last-child td {
        border-bottom: none;
    }

    .bill-table .empty-row td,
    .bill-table td.bill-hide-sm {
        display: table-cell;
    }

    .bill-table td.nowrap {
        white-space: nowrap;
    }
}

/* ---- 1B: inline action fields, money panels, timeline (lane B3) --------------
   Inline fields sit in an .action-controls row: stacked full width on a phone,
   side by side from 720px. The caption is a real <label> wrapping its input. */
.bill-inline-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1 1 100%;
    min-width: 0;
}

.bill-inline-field > span {
    color: var(--foreground-muted);
    font-size: 0.7rem;
}

.bill-inline-field .form-input {
    padding: 5px 8px;
    font-size: 0.8125rem;
}

.bill-actions .action-desc {
    min-width: 0;
}

/* A row with inline fields takes the full width on a phone, so each field can. */
.bill-actions .action-controls:has(.bill-inline-field) {
    flex: 1 1 100%;
}

.bill-actions .action-controls:has(.bill-inline-field) > .btn {
    align-self: flex-end;
}

/* "Resolve manually": a two-way choice above its fields. */
.bill-choice {
    flex: 1 1 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
}

.bill-choice legend {
    padding: 0;
    margin-bottom: 4px;
    color: var(--foreground-muted);
    font-size: 0.7rem;
}

.bill-choice-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.bill-field-error {
    color: var(--danger-strong);
    font-size: 0.75rem;
}

.bill-panel-empty {
    margin: 0;
    padding: 12px 14px;
}

.bill-actions .bill-panel-empty {
    padding: 0;
}

/* The KPI grid inside a card: the card already draws the frame. */
.bill-money-card .stats-grid {
    border: none;
    border-radius: 0;
}

.bill-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bill-timeline-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    border-bottom: var(--hairline) solid var(--border);
    min-width: 0;
}

.bill-timeline-item:last-child {
    border-bottom: none;
}

.bill-timeline-when {
    color: var(--foreground-muted);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
}

.bill-timeline-what {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 8px;
    font-size: 0.8125rem;
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (min-width: 720px) {
    .bill-inline-field {
        flex: 0 1 120px;
    }

    .bill-inline-field.bill-inline-wide {
        flex: 1 1 180px;
    }

    /* Fields and their button stay on one line; the description wraps instead. */
    .bill-actions .action-controls:has(.bill-inline-field) {
        flex: 0 1 auto;
        flex-wrap: nowrap;
    }

    .bill-actions .action-row:has(.bill-inline-field) {
        flex-wrap: nowrap;
    }

    .bill-actions .action-row:has(.bill-offline-fields),
    .bill-actions .action-row.bill-site-links {
        flex-wrap: wrap;
    }

    .bill-actions .bill-site-links .action-controls {
        flex: 1 1 440px;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: flex-end;
    }

    .bill-choice {
        flex: 0 1 auto;
    }

    .bill-stuck .action-controls {
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: flex-end;
    }

    .bill-actions .action-controls.bill-offline-fields {
        flex: 1 1 520px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .bill-timeline-item {
        display: grid;
        grid-template-columns: 150px minmax(0, 1fr);
        column-gap: 14px;
        align-items: baseline;
    }

    .bill-timeline-item .bill-sub {
        grid-column: 2;
    }
}
