:root {
    --brand-primary: #1656B5;
    --brand-primary-dark: #0D3D8C;
    --brand-primary-light: #2A8AE6;
    --brand-accent: #4DA8FF;
    --brand-gray: #8A95A5;
    --brand-gray-light: #C8CDD3;

    --bg-app: #F4F6FA;
    --surface: #FFFFFF;
    --surface-alt: #F8FAFD;
    --border: #E2E6EE;
    --border-strong: #CDD3DE;

    --text-primary: #1A2438;
    --text-secondary: #5A6677;
    --text-muted: #8A95A5;

    --danger: #D63E5A;
    --danger-bg: #FDEEF1;
    --success: #1F9D6D;
    --success-bg: #E8F7F0;

    --shadow-sm: 0 1px 2px rgba(20, 30, 55, 0.05);
    --shadow-md: 0 4px 12px rgba(20, 30, 55, 0.08);
    --shadow-lg: 0 12px 32px rgba(20, 30, 55, 0.12);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    background: var(--bg-app);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    overflow-x: hidden;
}

/* Force Havit toast container to overlay rather than render inline.
   Without this, the empty container's default margin pushes body height
   and creates a small vertical scroll, and toasts can render off-screen. */
.hx-toast-container {
    position: fixed !important;
    bottom: 0;
    right: 0;
    pointer-events: none;
    z-index: 1090;
}

.hx-toast-container > * {
    pointer-events: auto;
}

a {
    color: var(--brand-primary);
    text-decoration: none;
}

a:hover {
    color: var(--brand-primary-dark);
    text-decoration: underline;
}

h1, h2, h3, h4 {
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

h1:focus,
:focus-visible {
    outline: none;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-check-input:focus-visible,
input:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--brand-primary-light);
    outline-offset: 2px;
}

/* ---------- Auth (login layout) form elements ---------- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.auth-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.auth-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.auth-input {
    width: 100%;
    height: 44px;
    padding: 0 0.875rem;
    font-size: 0.9375rem;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.auth-input:focus {
    border-color: var(--brand-primary-light);
    box-shadow: 0 0 0 3px rgba(42, 138, 230, 0.18);
    outline: none;
}

.auth-input.invalid,
.auth-input[aria-invalid="true"] {
    border-color: var(--danger);
}

.auth-error {
    color: var(--danger);
    font-size: 0.8125rem;
}

.auth-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.auth-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand-primary);
}

.auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    padding: 0 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
    text-decoration: none;
}

.auth-btn:active {
    transform: translateY(1px);
}

.auth-btn-primary {
    background: var(--brand-primary);
    color: #fff;
}

.auth-btn-primary:hover {
    background: var(--brand-primary-dark);
    color: #fff;
    text-decoration: none;
}

.auth-btn-secondary {
    background: var(--surface);
    color: var(--brand-primary);
    border-color: var(--border-strong);
}

.auth-btn-secondary:hover {
    background: var(--surface-alt);
    border-color: var(--brand-primary-light);
    color: var(--brand-primary-dark);
    text-decoration: none;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-link-subtle {
    font-size: 0.8125rem;
    color: var(--brand-primary);
    font-weight: 500;
}

.auth-meta {
    text-align: center;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

.auth-status {
    padding: 0.75rem 0.875rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.alert-danger,
.auth-status-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(214, 62, 90, 0.22);
}

.alert-success,
.auth-status-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(31, 157, 109, 0.22);
}

/* ---------- Portal page chrome ---------- */

/* Card-style header used on list pages via the PageHeader component */
.page-header-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.page-header-text {
    min-width: 0;
}

.page-header-title-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.page-header-icon {
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
}

.page-header-icon svg {
    width: 22px;
    height: 22px;
}

.page-header-title {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.page-header-subtitle {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0.4rem 0 0;
}

.page-header-actions {
    flex-shrink: 0;
}

/* Filter / search bar */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    box-shadow: var(--shadow-sm);
}

.filter-bar .search-input {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.filter-bar .search-icon {
    position: absolute;
    left: 0.75rem;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.filter-bar .search-field {
    width: 100%;
    height: 38px;
    padding: 0 0.875rem 0 2.25rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-bar .search-field:focus {
    border-color: var(--brand-primary-light);
    box-shadow: 0 0 0 3px rgba(42, 138, 230, 0.18);
    outline: none;
}

.filter-bar .clear-filters {
    color: var(--brand-primary);
    font-size: 0.875rem;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.filter-bar .clear-filters:hover {
    text-decoration: underline;
}

/* Table cell polish */
.cell-with-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.cell-with-icon svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.cell-link {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 500;
}

.cell-link:hover {
    color: var(--brand-primary-dark);
    text-decoration: underline;
}

/* Legacy (non-card) header - still used by editor pages and dashboard */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* ---------- Account settings (Manage) layout ---------- */
.manage-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1rem;
    align-items: start;
}

@media (max-width: 768px) {
    .manage-grid {
        grid-template-columns: 1fr;
    }
}

.manage-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.manage-nav-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.manage-nav-list li {
    padding: 0;
}

.manage-nav-list .nav-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    line-height: 1.2;
}

.manage-nav-list .nav-link:hover {
    background: var(--surface-alt);
    color: var(--text-primary);
}

.manage-nav-list .nav-link.active {
    background: rgba(22, 86, 181, 0.08);
    color: var(--brand-primary);
    font-weight: 600;
}

.manage-nav-list .nav-link svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.manage-nav-list .nav-link.active svg {
    color: var(--brand-primary);
}

.manage-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Recovery code styling */
.recovery-code-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

@media (max-width: 480px) {
    .recovery-code-grid {
        grid-template-columns: 1fr;
    }
}

.recovery-code {
    display: block;
    padding: 0.5rem 0.75rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: 0.04em;
}

/* QR code container for authenticator setup */
.qr-code-host {
    display: inline-block;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid var(--border);
}

.shared-key {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.9375rem;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

/* Static-key/value list used on Profile page header */
.read-only-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.read-only-field-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.read-only-field-value {
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.field-help {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0.375rem 0 0;
}

.setup-list {
    padding-left: 1.25rem;
    margin: 0;
}

.setup-list > li {
    margin-bottom: 1.5rem;
}

.setup-list > li:last-child {
    margin-bottom: 0;
}

/* Passkey list */
.passkey-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.passkey-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    background: var(--surface-alt);
}

.passkey-info {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.passkey-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.passkey-name {
    font-weight: 500;
    color: var(--text-primary);
}

.passkey-actions {
    display: flex;
    gap: 0.375rem;
    margin: 0;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
    letter-spacing: -0.015em;
}

.page-subtitle {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9375rem;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1.125rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

a.kpi-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}

a.kpi-link:hover {
    border-color: var(--brand-primary-light);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: inherit;
}

a.kpi-link:active {
    transform: translateY(1px);
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.kpi-value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin: 0.375rem 0 0.25rem;
    letter-spacing: -0.02em;
}

.kpi-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.kpi-muted {
    color: var(--text-muted);
}

.panel-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

@media (max-width: 900px) {
    .panel-grid {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
}

.panel-title {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.panel-body {
    padding: 1.25rem;
}

.panel-empty {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

.panel-empty p {
    margin: 0;
}

.checklist {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.checklist li {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--success-bg);
    color: var(--success);
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.check.pending {
    background: var(--surface-alt);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* ---------- Identity scaffolded form polish (non-auth-layout pages) ---------- */
.form-floating > .form-control:focus,
.form-floating > .form-control-plaintext:focus {
    border-color: var(--brand-primary-light);
    box-shadow: 0 0 0 3px rgba(42, 138, 230, 0.18);
}

.btn-primary {
    color: #fff;
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--brand-primary-dark);
    border-color: var(--brand-primary-dark);
}

.btn-link,
a.btn-link {
    color: var(--brand-primary);
}

.darker-border-checkbox.form-check-input {
    border-color: var(--border-strong);
}

.form-check-input:checked {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--success);
}

.invalid {
    outline: 1px solid var(--danger);
}

.validation-message {
    color: var(--danger);
}

/* Small status component used by auth pages */
::deep .alert {
    padding: 0.75rem 0.875rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.blazor-error-boundary {
    background: var(--danger);
    color: white;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* Bootstrap form-floating keeps the placeholder transparent until the input
   is focused or filled — the label sits in its place. Only restyle the
   placeholder for the focused/filled state so we don't collide with the label. */
.form-floating > .form-control:focus::placeholder,
.form-floating > .form-control:not(:placeholder-shown)::placeholder,
.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control-plaintext:not(:placeholder-shown)::placeholder {
    color: var(--text-muted);
}

/* ---- Billing / Stripe ---- */
.stripe-mode-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: #FFF6E0;
    color: #6B4F00;
    border-bottom: 1px solid #F2D27A;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.stripe-mode-banner svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.billing-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    overflow-x: auto;
}

.billing-tab {
    padding: 0.6rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}

.billing-tab:hover {
    color: var(--text-primary);
}

.billing-tab.active {
    color: var(--brand-primary);
    border-bottom-color: var(--brand-primary);
}

.status-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.status-badge-paid, .status-badge-active, .status-badge-succeeded {
    background: var(--success-bg);
    color: var(--success);
}

.status-badge-open, .status-badge-trialing {
    background: #E5F1FF;
    color: var(--brand-primary);
}

.status-badge-draft, .status-badge-incomplete {
    background: #F1F2F4;
    color: var(--text-secondary);
}

.status-badge-uncollectible, .status-badge-past_due, .status-badge-failed, .status-badge-canceled, .status-badge-void {
    background: var(--danger-bg);
    color: var(--danger);
}

.amount-cell {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.linked-customer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.linked-customer-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.invoice-line-row {
    display: grid;
    grid-template-columns: 2fr 1fr 80px 120px auto;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.5rem;
}

.no-stripe-config {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    background: var(--surface-alt);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
}
