/* Modules and billing: plan walls, limited home, badges, Clients & billing,
   the organisation's Billing tab and the terms page. Cards, tables and forms
   reuse rbac.css (.rbac-card, .rbac-table, .form-group). */

.billing-wall-modal h2 {
    margin-bottom: var(--space-sm);
}

.billing-wall-body {
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: var(--space-sm);
}

.billing-wall-contact a {
    color: var(--primary-light);
    text-decoration: none;
}

.billing-wall-contact a:hover {
    text-decoration: underline;
}

.limited-home-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 240px;
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--font-size-md);
    line-height: 1.5;
}

.limited-home-hint p {
    max-width: 36rem;
}

.billing-badge {
    display: inline-block;
    margin-left: var(--space-xs);
    padding: 2px var(--space-xs);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
    background: rgba(var(--primary-light-rgb), 0.2);
    color: var(--primary-light);
}

.billing-badge--warning {
    background: rgba(var(--warning-rgb), 0.18);
    color: var(--color-warning);
}

.billing-badge--error {
    background: rgba(var(--error-rgb), 0.18);
    color: var(--color-error);
}

.billing-badge--success {
    background: rgba(var(--success-rgb), 0.18);
    color: var(--color-success);
}

.billing-cap-hint {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    margin-top: var(--space-xs);
}

.billing-limit-banner {
    margin: 0 0 var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(var(--primary-light-rgb), 0.35);
    background: rgba(var(--primary-light-rgb), 0.12);
    color: var(--primary-light);
    font-size: var(--font-size-sm);
}

.billing-limit-banner--over {
    border-color: rgba(var(--error-rgb), 0.45);
    background: rgba(var(--error-rgb), 0.12);
    color: var(--color-error);
}

/* Billing banners for organisation admins, under the top bar. */
.billing-notices {
    display: grid;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
}

.billing-notice {
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(var(--primary-light-rgb), 0.35);
    background: rgba(var(--primary-light-rgb), 0.12);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
}

.billing-notice--warning {
    border-color: rgba(var(--warning-rgb), 0.45);
    background: rgba(var(--warning-rgb), 0.12);
}

.billing-notice--error {
    border-color: rgba(var(--error-rgb), 0.45);
    background: rgba(var(--error-rgb), 0.12);
}

/* Go-live state banner on the Clients & billing tab. */
.billing-mode-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
    margin: 0 0 var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.billing-mode-banner strong {
    color: var(--text-primary);
}

.billing-subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.billing-subtab {
    min-height: var(--control-height);
    padding: 0 var(--space-md);
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.billing-subtab.active {
    background: var(--bg-selected);
    border-color: var(--primary-light);
    color: var(--text-primary);
}

.billing-client-row {
    cursor: pointer;
}

.billing-modules-list {
    display: grid;
    gap: var(--space-xs);
}

.billing-module-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-sm);
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
}

.billing-module-row.is-on {
    border-color: rgba(var(--primary-light-rgb), 0.45);
}

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

.billing-module-meta {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.billing-module-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
}

.billing-feature-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin: var(--space-xs) 0 0;
    padding: 0;
    list-style: none;
}

.billing-feature-chip {
    padding: 2px var(--space-sm);
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    background: rgba(var(--success-rgb), 0.15);
    color: var(--color-success);
}

.billing-feature-chip.is-missing {
    background: rgba(var(--text-secondary-rgb), 0.12);
    color: var(--text-muted);
    text-decoration: line-through;
}

.billing-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: var(--space-sm) var(--space-md);
}

.billing-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.billing-money {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.billing-muted {
    color: var(--text-muted);
}

/* The organisation's payment options, side by side. */
.billing-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: var(--space-sm);
}

.billing-option {
    display: grid;
    gap: var(--space-xs);
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    text-align: left;
    color: var(--text-body);
    cursor: pointer;
}

.billing-option.is-selected {
    border-color: var(--primary-light);
    background: var(--bg-selected);
}

.billing-option.is-current {
    border-style: dashed;
}

.billing-option-title {
    font-weight: 600;
    color: var(--text-primary);
}

.billing-option-price {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.billing-option-saving {
    font-size: var(--font-size-sm);
    color: var(--color-success);
}

.billing-quote-table td:last-child,
.billing-quote-table th:last-child {
    text-align: right;
}

/* Full-screen terms page shown before anything else when terms are due. */
/* Opens while the start-up loading overlay is still up, which only clears once the terms are accepted. */
.terms-gate {
    position: fixed;
    inset: 0;
    z-index: var(--z-terms-gate);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: var(--bg);
}

.terms-gate-panel {
    display: flex;
    flex-direction: column;
    width: min(48rem, 100%);
    max-height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-panel);
    box-shadow: var(--shadow-modal);
}

.terms-gate-header,
.terms-gate-footer {
    padding: var(--space-md) var(--space-lg);
}

.terms-gate-header h1 {
    margin: 0 0 var(--space-xs);
    font-size: var(--font-size-xl);
}

.terms-gate-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.terms-gate-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: pre-wrap;
    line-height: 1.6;
    color: var(--text-body);
}

.terms-gate-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.terms-text-preview {
    max-height: 24rem;
    overflow-y: auto;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    white-space: pre-wrap;
    line-height: 1.5;
}

.terms-editor {
    width: 100%;
    min-height: 18rem;
    font-family: var(--font-sans);
    line-height: 1.5;
}

/* Organisation Billing tab: card, Bob use bars, packs and auto top-up. */
.billing-card-needed {
    border-color: rgba(var(--warning-rgb), 0.45);
}

.billing-usage-bar {
    display: grid;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.billing-usage-bar-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-sm);
    font-size: var(--font-size-sm);
}

.billing-usage-track {
    height: 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    overflow: hidden;
}

.billing-usage-fill {
    height: 100%;
    background: var(--primary-light);
}

.billing-usage-bar.is-near .billing-usage-fill {
    background: rgb(var(--warning-rgb));
}

.billing-usage-bar.is-out .billing-usage-fill {
    background: rgb(var(--error-rgb));
}

.billing-usage-state {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.billing-pack-group {
    margin-top: var(--space-md);
}

.billing-pack-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: var(--space-sm);
}

.billing-option:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.billing-topup {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-sm);
    margin-top: var(--space-sm);
    font-size: var(--font-size-sm);
}

.billing-topup input[type="number"] {
    width: 4.5rem;
}

/* An organisation's price list: a line priced differently from the master. */
.billing-price-own td {
    background: rgba(var(--primary-light-rgb), 0.08);
}

/* A client page module that is live, and one whose Stop on date has passed. */
.billing-row-on td {
    background: rgba(var(--success-rgb), 0.08);
}

.billing-module-stopped {
    color: var(--color-warning);
}

/* Rapid Fusion billing pages (master price list, client page): cards stacked
   with space between them, each table group with its heading and hint, and
   fixed column widths so tables under one card line up. */
.billing-page {
    display: grid;
    gap: var(--space-md);
}

.billing-page > :empty {
    display: none;
}

.billing-page .rbac-card > .rbac-hint {
    margin-bottom: var(--space-md);
    max-width: 80ch;
}

.billing-group + .billing-group {
    margin-top: var(--space-lg);
}

.billing-group .rbac-hint {
    margin-bottom: var(--space-sm);
}

.billing-price-table {
    table-layout: fixed;
    min-width: 58rem;
}

.billing-price-table td {
    vertical-align: middle;
}

.billing-price-table input[type="number"],
.billing-price-table input[type="date"] {
    width: 100%;
    max-width: 9rem;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-strong);
    color-scheme: var(--color-scheme);
    font-size: var(--font-size-sm);
    font-family: inherit;
}

.billing-price-table input[type="number"]:focus,
.billing-price-table input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
}

.billing-price-table td.rbac-actions {
    display: table-cell;
    text-align: right;
}

.billing-col-short {
    width: 7rem;
}

.billing-col-money {
    width: 10rem;
}

.billing-col-input {
    width: 11rem;
}

.billing-col-actions {
    width: 16rem;
}

.billing-renewal-date {
    margin: 0 0 var(--space-xs);
    font-size: var(--font-size-xl);
    font-weight: 600;
}

.billing-renewal-text {
    margin: 0 0 var(--space-lg);
    max-width: 70ch;
}

.billing-renewal-edit {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-md);
}

.billing-renewal-edit .form-group {
    margin: 0;
}

.billing-renewal-edit input[type="date"] {
    width: 12rem;
}

.billing-seat-offer {
    width: 100%;
}

.billing-seat-offer th {
    background: none;
    text-align: left;
    font-weight: 500;
    white-space: normal;
}

.billing-seat-offer td {
    white-space: nowrap;
    text-align: right;
}
