/*
 * Components. Flat class names; variants are additional classes
 * (.btn .btn-primary .btn-sm). State classes start with "is-".
 * Requires tokens.css and base.css.
 */

/* ------------------------------------------------------------------ Buttons */

.btn {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    --btn-border: var(--border-strong);
    --btn-hover-bg: var(--surface-hover);
    --btn-hover-fg: var(--btn-fg);
    --btn-hover-border: var(--input-border-hover);
    --btn-shadow: var(--shadow-xs);

    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: var(--control-h);
    padding: 0 14px;
    border: 1px solid var(--btn-border);
    border-radius: var(--radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    box-shadow: var(--btn-shadow);
    font-size: var(--text-base);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    vertical-align: middle;
    user-select: none;
    cursor: pointer;
    transition: var(--transition-colors);
}

.btn:hover {
    background: var(--btn-hover-bg);
    border-color: var(--btn-hover-border);
    color: var(--btn-hover-fg);
    text-decoration: none;
}

/* Keyboard focus: an outline with a transparent offset, which reads on every background (page, card, alert, dialog). */
.btn:focus-visible {
    outline: var(--focus-width) solid var(--focus);
    outline-offset: var(--focus-offset);
}

.btn:active:not(:disabled) {
    transform: translateY(0.5px);
}

.btn:disabled,
.btn.is-disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    pointer-events: none;
    box-shadow: none;
}

.btn > i,
.btn > svg {
    flex: none;
    font-size: 0.95em;
}

.btn-primary {
    --btn-bg: var(--primary);
    --btn-fg: var(--primary-fg);
    --btn-border: var(--primary);
    --btn-hover-bg: var(--primary-hover);
    --btn-hover-border: var(--primary-hover);
    --btn-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn-accent {
    --btn-bg: var(--accent-solid);
    --btn-fg: #ffffff;
    --btn-border: var(--accent-solid);
    --btn-hover-bg: var(--accent-solid-hover);
    --btn-hover-border: var(--accent-solid-hover);
}

.btn-secondary {
    --btn-bg: var(--surface-active);
    --btn-fg: var(--text);
    --btn-border: transparent;
    --btn-hover-bg: var(--border);
    --btn-hover-border: transparent;
    --btn-shadow: none;
}

.btn-outline {
    --btn-bg: transparent;
    --btn-shadow: none;
}

.btn-ghost {
    --btn-bg: transparent;
    --btn-fg: var(--text-muted);
    --btn-border: transparent;
    --btn-hover-bg: var(--surface-hover);
    --btn-hover-fg: var(--text);
    --btn-hover-border: transparent;
    --btn-shadow: none;
}

.btn-danger {
    --btn-bg: var(--danger-solid);
    --btn-fg: #ffffff;
    --btn-border: var(--danger-solid);
    --btn-hover-bg: var(--danger-solid-hover);
    --btn-hover-border: var(--danger-solid-hover);
}

.btn-danger:focus-visible {
    outline-color: var(--focus-danger);
}

.btn-danger-ghost {
    --btn-bg: transparent;
    --btn-fg: var(--danger);
    --btn-border: transparent;
    --btn-hover-bg: var(--danger-bg);
    --btn-hover-border: transparent;
    --btn-shadow: none;
}

.btn-link {
    --btn-bg: transparent;
    --btn-fg: var(--link);
    --btn-border: transparent;
    --btn-hover-bg: transparent;
    --btn-hover-border: transparent;
    --btn-hover-fg: var(--link-hover);
    --btn-shadow: none;
    height: auto;
    padding: 0;
}

.btn-link:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-sm {
    height: var(--control-h-sm);
    padding: 0 10px;
    gap: 6px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.btn-lg {
    height: var(--control-h-lg);
    padding: 0 20px;
    font-size: var(--text-md);
}

.btn-icon {
    width: var(--control-h);
    padding: 0;
}

.btn-icon.btn-sm {
    width: var(--control-h-sm);
}

.btn-block {
    display: flex;
    width: 100%;
}

/* Loading state: keeps the width, hides the label, shows a spinner. */
.btn.is-loading {
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading > * {
    visibility: hidden;
}

.btn.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid var(--btn-fg);
    border-right-color: transparent;
    border-radius: 50%;
    animation: rb-spin 0.7s linear infinite;
}

.btn-group {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -3px;
    animation: rb-spin 0.7s linear infinite;
}

.spinner-lg {
    width: 24px;
    height: 24px;
}

@keyframes rb-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ------------------------------------------------------------------ Form controls */

.input,
.select,
.textarea {
    display: block;
    width: 100%;
    height: var(--control-h);
    padding: 0 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text);
    box-shadow: var(--shadow-xs);
    font-size: var(--text-base);
    line-height: var(--leading);
    transition: var(--transition-colors);
}

.input::placeholder,
.textarea::placeholder {
    color: var(--text-subtle);
    opacity: 1;
}

/* A one-line field ends an overflowing placeholder or value with an ellipsis while it is not being edited. */
.input {
    text-overflow: ellipsis;
}

.input::placeholder {
    text-overflow: ellipsis;
}

.input:hover,
.select:hover,
.textarea:hover {
    border-color: var(--input-border-hover);
}

/*
 * Focused text fields and selects: the border takes the focus colour (the 3:1 indicator) and a soft
 * halo of the same hue surrounds the field. The transparent outline keeps a visible ring in forced colours.
 */
.input:focus,
.select:focus,
.textarea:focus,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible,
.select-trigger[aria-expanded="true"] {
    outline: var(--focus-width) solid transparent;
    outline-offset: 0;
    border-color: var(--focus);
    box-shadow: var(--focus-ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.input[readonly] {
    /* Colour only: the chevron image of .select stays. */
    background-color: var(--surface-muted);
    color: var(--text-muted);
    box-shadow: none;
}

.input:disabled,
.select:disabled,
.textarea:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.textarea {
    height: auto;
    min-height: 88px;
    padding: 9px 12px;
    resize: vertical;
}

.textarea[data-autogrow] {
    resize: none;
    overflow-y: hidden;
}

.select {
    padding-right: 34px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23646d82' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

:root[data-theme="dark"] .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%238a93a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 6.5 8 10l3.5-3.5'/%3E%3C/svg%3E");
}

.select[multiple] {
    height: auto;
    padding: 6px;
    background-image: none;
}

/* 16 px text keeps mobile browsers from zooming into focused fields. */
@media (max-width: 640px) {
    .input,
    .select,
    .textarea {
        font-size: 16px;
    }
}

.input-sm,
.select.input-sm {
    height: var(--control-h-sm);
    font-size: var(--text-sm);
    border-radius: var(--radius-sm);
}

.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid,
.is-invalid > .input,
.is-invalid > .select,
.is-invalid > .textarea,
.is-invalid .input-group > .input {
    border-color: var(--danger-solid);
}

.input.is-invalid:focus,
.select.is-invalid:focus,
.textarea.is-invalid:focus,
.is-invalid .input:focus,
.is-invalid .select:focus,
.is-invalid .textarea:focus,
.select-trigger.is-invalid[aria-expanded="true"],
.is-invalid .select-trigger[aria-expanded="true"] {
    border-color: var(--focus-danger);
    box-shadow: var(--focus-ring-danger);
}

/* Input with leading icon and/or trailing element: .input-group > i.input-icon + .input (+ .input-addon) */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group > .input-icon {
    position: absolute;
    left: 12px;
    color: var(--text-subtle);
    font-size: 13px;
    pointer-events: none;
}

.input-group > .input-icon ~ .input {
    padding-left: 34px;
}

.input-group > .input-addon {
    position: absolute;
    right: 4px;
}

.input-group > .input:has(~ .input-addon) {
    padding-right: 40px;
}

/* Checkbox and radio; the unchecked border has at least 3:1 contrast against the surfaces (--control-border). */
.checkbox,
.radio {
    position: relative;
    flex: none;
    width: 16px;
    height: 16px;
    margin: 0;
    border: 1px solid var(--control-border);
    background: var(--input-bg);
    box-shadow: var(--shadow-xs);
    appearance: none;
    cursor: pointer;
    vertical-align: -3px;
    transition: var(--transition-colors);
}

.checkbox {
    border-radius: var(--radius-xs);
}

.radio {
    border-radius: 50%;
}

.checkbox:checked,
.radio:checked {
    border-color: var(--primary);
    background-color: var(--primary);
}

.checkbox:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 8.2 2.6 2.6L12 5.4'/%3E%3C/svg%3E");
    background-size: 100%;
}

.checkbox:indeterminate {
    border-color: var(--primary);
    background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4.5 8h7'/%3E%3C/svg%3E") center / 100%;
}

.radio:checked {
    box-shadow: inset 0 0 0 3.5px var(--input-bg);
}

.checkbox:focus-visible,
.radio:focus-visible,
.switch:focus-visible {
    outline: var(--focus-width) solid var(--focus);
    outline-offset: var(--focus-offset);
}

.checkbox:disabled,
.radio:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Label with a checkbox or radio and optional description. */
.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    line-height: 1.4;
}

.check > .checkbox,
.check > .radio {
    margin-top: 1px;
}

.check-label {
    font-weight: 500;
    color: var(--text);
}

.check-description {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 400;
}

/* Selectable option cards (radio lists): label.option > input.radio + .option-body */
.option {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition-colors);
}

.option:hover {
    border-color: var(--border-strong);
    background: var(--surface-muted);
}

/* The chosen option is an accent-tinted box: the texts inside take the accent shades. */
.option:has(:checked) {
    --text: var(--accent-title);
    --text-muted: var(--accent-fg);
    --text-subtle: var(--accent-fg);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.option > .radio,
.option > .checkbox {
    margin-top: 2px;
}

.option-list {
    display: grid;
    gap: var(--space-2);
}

/* Switch: input.switch[type=checkbox][role=switch]; the off track has 3:1 contrast against the surfaces. */
.switch {
    position: relative;
    flex: none;
    width: 34px;
    height: 20px;
    margin: 0;
    border-radius: var(--radius-full);
    background: var(--control-border);
    appearance: none;
    cursor: pointer;
    transition: background-color var(--duration) var(--ease);
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
    transition: transform var(--duration) var(--ease);
}

.switch:checked {
    background: var(--primary);
}

.switch:checked::after {
    transform: translateX(14px);
}

.switch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Form field: .field > .field-label + control + .field-help / .field-error */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.35;
}

.field-label .field-optional {
    color: var(--text-subtle);
    font-weight: 400;
}

.field-required {
    color: var(--danger);
    margin-left: 2px;
}

/* Label with something beside it (badges, a small button): .field-head > .field-label + .field-aside */
.field-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-1) var(--space-2);
}

.field-head > .field-label {
    flex: 1 1 12rem;
    min-width: 0;
}

.field-aside {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-2);
}

.field-help {
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: 1.45;
}

/* A fixed value in place of a control (e.g. the address of an invitation): looks read-only, wraps instead of cutting. */
.field-static {
    min-height: var(--control-h);
    padding: 7px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--surface-muted);
    color: var(--text);
    font-size: var(--text-base);
    line-height: 20px;
    overflow-wrap: anywhere;
}

.field-error {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    color: var(--danger);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.45;
}

.field-error > i,
.field-error > svg {
    flex: none;
    margin-top: 2px;
    color: var(--danger-icon);
    font-size: 12px;
}

.field-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.char-counter {
    flex: none;
    margin-left: auto;
    color: var(--text-subtle);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
}

.char-counter.is-near {
    color: var(--warning);
}

.char-counter.is-over {
    color: var(--danger);
    font-weight: 600;
}

.form-stack {
    display: grid;
    gap: var(--space-5);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5) var(--space-4);
}

.form-grid > .span-full {
    grid-column: 1 / -1;
}

@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.form-actions-start {
    justify-content: flex-start;
}

/* Settings-style section: description column + fields column */
.form-section {
    display: grid;
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
    gap: var(--space-6) var(--space-10);
    padding: var(--space-8) 0;
    border-top: 1px solid var(--border);
}

.form-section:first-child {
    border-top: 0;
    padding-top: 0;
}

.form-section-title {
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.35;
}

.form-section-text {
    margin-top: var(--title-gap);
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: var(--leading);
    text-wrap: pretty;
}

@media (max-width: 900px) {
    .form-section {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--space-4);
    }
}

/* Read-only value with copy button: .copy-field > .copy-field-value + .btn */
.copy-field {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--surface-muted);
    overflow: hidden;
}

.copy-field-value {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
}

.copy-field > .btn {
    height: auto;
    border-width: 0 0 0 1px;
    border-radius: 0;
    box-shadow: none;
}

/* ------------------------------------------------------------------ Select (enhanced by core/select.js) */

/*
 * select.is-enhanced  the native control: stays in the form as the submitted field and for constraint
 *                     validation, without taking space or receiving pointer input.
 * .select-trigger     button[role=combobox] after it; carries the classes of the select (.select,
 *                     .input-sm, .is-invalid), so it looks and sizes like the native control.
 * .select-list        [role=listbox] after the trigger; looks like .dropdown-menu.
 * Without JavaScript the native select stays visible and styled by .select.
 */
select.is-enhanced {
    position: absolute;
    width: 1px;
    min-width: 0;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
    clip-path: inset(50%);
}

.select-trigger {
    display: flex;
    align-items: center;
    min-width: min(var(--select-min-width, 0px), 100%);
    text-align: left;
    white-space: nowrap;
    user-select: none;
}

.select-trigger-value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.select-trigger.is-placeholder .select-trigger-value {
    color: var(--text-subtle);
}

.select-trigger[aria-expanded="true"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%23646d82' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 9.5 8 6l3.5 3.5'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] .select-trigger[aria-expanded="true"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='%238a93a8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 9.5 8 6l3.5 3.5'/%3E%3C/svg%3E");
}

.select-list {
    display: none;
    min-width: 160px;
    max-width: min(480px, calc(100vw - 16px));
    max-height: min(340px, calc(100vh - 16px));
    padding: var(--space-1);
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

.select-list.is-open {
    display: block;
    animation: rb-menu-in var(--duration-fast) var(--ease-out);
}

.select-list.is-open[data-placement="top"] {
    animation-name: rb-menu-in-up;
}

.select-option {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 32px;
    padding: 6px 32px 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-base);
    line-height: 1.35;
    overflow-wrap: anywhere;
    cursor: pointer;
    user-select: none;
}

.select-option.is-active {
    background: var(--raised-hover);
}

.select-option[aria-selected="true"] {
    font-weight: 500;
}

/* Check mark of the chosen option, drawn with a mask so it takes the theme colour. */
.select-option[aria-selected="true"]::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 10px;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    background: var(--accent-text);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 8.4 2.9 2.9 6.1-6.6'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 8.4 2.9 2.9 6.1-6.6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.select-option.is-placeholder {
    color: var(--text-subtle);
}

.select-option[aria-disabled="true"] {
    color: var(--text-disabled);
    cursor: not-allowed;
}

.select-option[aria-disabled="true"].is-active {
    background: transparent;
}

.select-group + .select-group,
.select-option + .select-group,
.select-group + .select-option {
    margin-top: var(--space-1);
    padding-top: var(--space-1);
    border-top: 1px solid var(--border-muted);
}

.select-group-label {
    padding: 6px 10px 4px;
    color: var(--text-subtle);
    font-size: var(--text-xs);
    font-weight: 600;
}

.select-empty {
    padding: 8px 10px;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/*
 * Filterable list (core/select.js, more than 15 options): .select-list.has-filter > .select-filter
 * (search field) + .select-status ("No matches" row) + .select-options[role=listbox] (scrolls).
 */
.select-list.has-filter,
.select-list.has-filter.is-floating {
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.select-list.has-filter.is-open {
    display: flex;
}

.select-filter {
    position: relative;
    display: flex;
    flex: none;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.select-filter > i,
.select-filter > svg {
    position: absolute;
    left: 12px;
    color: var(--text-subtle);
    font-size: 13px;
    pointer-events: none;
}

.select-filter-input {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 34px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: var(--text-base);
    text-overflow: ellipsis;
}

.select-filter-input::placeholder {
    color: var(--text-subtle);
    opacity: 1;
    text-overflow: ellipsis;
}

/* The field is focused while the list is open: a focus-coloured line under it marks it. */
.select-filter-input:focus {
    outline: none;
}

.select-filter:focus-within {
    box-shadow: inset 0 -2px 0 var(--focus);
}

.select-options {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    padding: var(--space-1);
    overflow-y: auto;
}

.select-status.select-empty {
    flex: none;
    padding: 10px 14px;
}

@media (pointer: coarse), (max-width: 640px) {
    .select-filter-input {
        height: 44px;
        font-size: 16px;
    }
}

/* Touch screens and phones: larger targets and 16 px text. */
@media (pointer: coarse), (max-width: 640px) {
    .select-option {
        min-height: 44px;
        font-size: 16px;
    }
}

@media (forced-colors: active) {
    .select-option.is-active {
        outline: 2px solid Highlight;
        outline-offset: -2px;
    }

    .select-option[aria-selected="true"]::after {
        background: CanvasText;
    }
}

/* ------------------------------------------------------------------ Cards */

.card {
    position: relative;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

/*
 * Card spacing. The header is a complete box (20 px on every side), so a card with only a heading,
 * or a heading followed directly by a footer, list or table, needs nothing else. A body that follows
 * the header, directly or as a child of a wrapper such as a form, takes over the space below the
 * heading: the header then drops its bottom padding and the body's top padding separates the two.
 * Bordered headers keep their own padding and a divider. A list right under an unbordered header starts
 * with the list item's own padding.
 */
.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5);
}

.card-header:not(.card-header-bordered):has(+ .card-body:not(.card-body-flush), + :not([class*="card-"]) > .card-body:not(.card-body-flush)) {
    padding-bottom: 0;
}

.card-header:not(.card-header-bordered):has(+ .list) {
    padding-bottom: var(--space-2);
}

.card-header-bordered {
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.card-heading {
    display: flex;
    flex-direction: column;
    gap: var(--title-gap);
    min-width: 0;
}

.card-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.008em;
}

/*
 * Leading icon of a title: a fixed 16 px box, so that the description below starts under the title
 * text (icon box plus gap). Its colour follows the tone of the title (--card-title-icon, see .card-danger).
 */
.card-title > i,
.card-title > svg {
    flex: none;
    width: 16px;
    color: var(--card-title-icon, var(--text-subtle));
    font-size: 14px;
    text-align: center;
}

.card-description {
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: var(--leading);
    text-wrap: pretty;
}

.card-title:has(> i:first-child, > svg:first-child) + .card-description {
    padding-left: calc(16px + var(--space-2));
}

/* Title and description outside a .card-heading wrapper. */
.card-title + .card-description {
    margin-top: var(--title-gap);
}

.card-heading > .card-title + .card-description {
    margin-top: 0;
}

.card-actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--space-2);
}

.card-body {
    padding: var(--space-5);
}

.card-body-flush {
    padding: 0;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    background: var(--surface-muted);
}

/* A footer stays at the bottom when the card is stretched (e.g. in a grid row). */
.card:has(> .card-footer) {
    display: flex;
    flex-direction: column;
}

.card:has(> .card-footer) > .card-footer {
    margin-top: auto;
}

.card-footer-start {
    justify-content: space-between;
}

.card-link {
    display: block;
    color: inherit;
    transition: var(--transition-colors);
}

a.card-link:hover,
.card-link:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: inherit;
}

.card-muted {
    background: var(--surface-muted);
    box-shadow: none;
}

.card-danger {
    border-color: var(--danger-border);
}

.card-danger .card-title {
    --card-title-icon: var(--danger-icon);
    color: var(--danger);
}

/* Divided list inside a card: .list > .list-item */
.list {
    display: flex;
    flex-direction: column;
}

.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-muted);
}

.list-item:first-child {
    border-top: 0;
}

a.list-item {
    color: inherit;
    transition: background-color var(--duration-fast) var(--ease);
}

a.list-item:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.list-item-main {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 500;
    color: var(--text);
}

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

/* Description list: dl.dl > div > dt + dd */
/* Rows keep their height when the list is stretched (e.g. beside a taller column). */
.dl {
    display: grid;
    align-content: start;
    gap: 0;
}

/*
 * The label column is a third of the row, between 10rem and 13rem: the same in half-width and
 * full-width cards. Where the value would get less than 12rem beside it (a sidebar card), the value
 * wraps under its label, so neither is squeezed into a narrow column.
 */
.dl > div {
    display: flex;
    flex-wrap: wrap;
    gap: 2px var(--space-4);
    padding: 10px 0;
    border-top: 1px solid var(--border-muted);
}

/* Beside the value the free space goes to the value; alone on its line the label takes the full width. */
.dl > div > dt {
    flex: 1 0 clamp(10rem, 34%, 13rem);
    min-width: 0;
}

.dl > div > dd {
    flex: 999 1 12rem;
}

.dl > div:first-child {
    border-top: 0;
    padding-top: 0;
}

.dl dt {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.dl dd {
    margin: 0;
    min-width: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ Badges */

/* Height and padding leave the text room on all sides; icons and dots are centred on the cap height. */
.badge {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border: 1px solid var(--neutral-border);
    border-radius: var(--radius-full);
    background: var(--neutral-bg);
    color: var(--neutral);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
}

.badge > i,
.badge > svg {
    flex: none;
    margin-left: -1px;
    font-size: 10px;
}

/* Icon kit SVGs are 1em high with a baseline offset; centred like the dot. */
.badge > svg.svg-inline--fa {
    vertical-align: 0;
}

.badge-accent {
    border-color: var(--accent-border);
    background: var(--accent-subtle);
    color: var(--accent-text);
}

.badge-success {
    border-color: var(--success-border);
    background: var(--success-bg);
    color: var(--success);
}

.badge-warning {
    border-color: var(--warning-border);
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-danger {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-info {
    border-color: var(--info-border);
    background: var(--info-bg);
    color: var(--info);
}

.badge-outline {
    border-color: var(--border-strong);
    background: transparent;
    color: var(--text-muted);
}

.badge-solid {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--primary-fg);
}

.badge-sm {
    gap: 5px;
    height: 20px;
    padding: 0 8px;
    font-size: 11px;
}

.badge-sm > i,
.badge-sm > svg {
    font-size: 9px;
}

.badge-dot::before {
    content: "";
    flex: none;
    width: 6px;
    height: 6px;
    margin-left: -1px;
    border-radius: 50%;
    background: currentColor;
}

.badge-sm.badge-dot::before {
    width: 5px;
    height: 5px;
}

/* Small numeric counter, e.g. in navigation and tabs. */
.count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--surface-active);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.count-accent {
    background: var(--accent-solid);
    color: #ffffff;
}

/* ------------------------------------------------------------------ Tables */

/* The wrapper is the query container of the optional columns (.table-col-md, .table-col-lg). */
.table-wrap {
    position: relative;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    container-type: inline-size;
}

.table {
    width: 100%;
    font-size: var(--text-base);
    text-align: left;
}

.table th {
    padding: 10px var(--space-4);
    border-bottom: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.table td {
    padding: 12px var(--space-4);
    border-bottom: 1px solid var(--border-muted);
    vertical-align: middle;
}

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

.table tbody tr {
    transition: background-color var(--duration-fast) var(--ease);
}

.table-hover tbody tr:hover {
    background: var(--surface-muted);
}

.table th:first-child,
.table td:first-child {
    padding-left: var(--space-5);
}

.table th:last-child,
.table td:last-child {
    padding-right: var(--space-5);
}

.table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.table .actions {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

.table-compact td {
    padding-top: 8px;
    padding-bottom: 8px;
}

/*
 * Main column: th/td.table-main (the name or person column) takes the width the other columns leave
 * and never widens the table, so long names and e-mail addresses in it truncate (.truncate,
 * .table-person) instead of pushing the actions column out of view. It keeps a minimum width
 * (--table-main-min); when even that does not fit, the wrapper scrolls. Mark the cells of the other
 * columns .nowrap where their content (badges, dates) should stay on one line.
 */
.table .table-main {
    width: 100%;
    min-width: var(--table-main-min, 11rem);
    max-width: 0;
}

/*
 * Optional columns, hidden while the table's wrapper is narrow: .table-col-md below 45rem and
 * .table-col-lg below 60rem of available width (the sidebar and the page padding are already taken
 * off, unlike with viewport breakpoints).
 */
@container (max-width: 60rem) {
    .table .table-col-lg {
        display: none;
    }
}

@container (max-width: 45rem) {
    .table .table-col-md {
        display: none;
    }
}

/* Phone widths: the main column may become narrower before the wrapper scrolls. */
@container (max-width: 30rem) {
    .table .table-main {
        min-width: var(--table-main-min-narrow, 8rem);
    }
}

/* Truncating cell outside the main column: its lines end with an ellipsis at --table-cell-max. */
.table .table-clip {
    max-width: var(--table-cell-max, 16rem);
}

.table .table-clip > * {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Person cell: .table-person > avatar + .table-person-body > .table-person-name (+ badges) + .table-person-meta */
.table-person {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.table-person-body {
    flex: 1 1 auto;
    min-width: 0;
}

.table-person-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px var(--space-2);
    min-width: 0;
    font-weight: 500;
}

.table-person-name > .truncate {
    min-width: 0;
    max-width: 100%;
}

.table-person-name > .badge {
    flex: none;
}

.table-person-meta {
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card > .table-wrap:first-child .table th:first-child {
    border-top-left-radius: var(--radius-lg);
}

.card > .table-wrap:first-child .table th:last-child {
    border-top-right-radius: var(--radius-lg);
}

/* ------------------------------------------------------------------ Disclosure */

/*
 * details > summary.disclosure-summary: the browser's marker is replaced by a chevron at the end of the
 * summary, pointing down while closed and up while open. --disclosure-top and --disclosure-right place it.
 */
.disclosure-summary {
    position: relative;
    padding-right: calc(var(--disclosure-right, var(--space-5)) + 22px);
    list-style: none;
    cursor: pointer;
}

.disclosure-summary::-webkit-details-marker {
    display: none;
}

.disclosure-summary::after {
    content: "";
    position: absolute;
    top: var(--disclosure-top, calc(50% - 6px));
    right: var(--disclosure-right, var(--space-5));
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--text-subtle);
    border-bottom: 1.5px solid var(--text-subtle);
    transform: rotate(45deg);
    transition: transform var(--duration-fast) var(--ease);
}

details[open] > .disclosure-summary::after {
    transform: translateY(4px) rotate(-135deg);
}

.disclosure-summary:focus-visible {
    outline: var(--focus-width) solid var(--focus);
    outline-offset: calc(-1 * var(--focus-width));
}

/* ------------------------------------------------------------------ Dialogs */

.dialog {
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    margin: auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--surface-raised);
    color: var(--text);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.dialog:focus,
.dialog:focus-visible {
    outline: none;
}

.dialog[open] {
    display: flex;
    flex-direction: column;
    animation: rb-dialog-in var(--duration-slow) var(--ease-out);
}

.dialog::backdrop {
    background: var(--bg-overlay);
    backdrop-filter: blur(2px);
    animation: rb-fade-in var(--duration) var(--ease);
}

.dialog-sm {
    width: min(420px, calc(100vw - 32px));
}

.dialog-lg {
    width: min(720px, calc(100vw - 32px));
}

.dialog-xl {
    width: min(960px, calc(100vw - 32px));
}

.dialog-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) var(--space-1);
}

/* Once the body has scrolled (class set by core/ui.js), the header gets an edge like the footer's. */
.dialog.is-scrolled .dialog-header {
    position: relative;
    z-index: 1;
    box-shadow: 0 1px 0 var(--border);
}

/* Without a body the header needs its own bottom spacing. */
.dialog-header:has(+ .dialog-footer),
.dialog-header:last-child {
    padding-bottom: var(--space-5);
}

.dialog-heading {
    flex: 1;
    min-width: 0;
}

.dialog-title {
    font-size: var(--text-lg);
    font-weight: 600;
    line-height: 1.3;
}

.dialog-description {
    margin-top: var(--title-gap);
    color: var(--text-muted);
    font-size: var(--text-sm);
    line-height: var(--leading);
    text-wrap: pretty;
}

.dialog-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-subtle);
    color: var(--accent-text);
    font-size: 16px;
}

.dialog-icon-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.dialog-close {
    flex: none;
    margin: -6px -6px 0 0;
}

.dialog-body {
    flex: 1;
    min-height: 0;
    padding: var(--space-4) var(--space-5);
    overflow-y: auto;
}

.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
}

@keyframes rb-dialog-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
}

@keyframes rb-fade-in {
    from {
        opacity: 0;
    }
}

@media (max-width: 640px) {
    .dialog,
    .dialog-sm,
    .dialog-lg,
    .dialog-xl {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 24px);
        margin: auto 0 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .dialog-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .dialog-footer > .btn {
        width: 100%;
    }
}

/* ------------------------------------------------------------------ Dropdowns */

.dropdown {
    position: relative;
    display: inline-flex;
}

/* A menu trigger stays pressed while its menu is open, as the select trigger does. */
.btn[aria-haspopup][aria-expanded="true"] {
    background: var(--btn-hover-bg);
    border-color: var(--btn-hover-border);
    color: var(--btn-hover-fg);
}

.btn-ghost[aria-haspopup][aria-expanded="true"],
.btn-outline[aria-haspopup][aria-expanded="true"] {
    background: var(--surface-active);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: var(--z-dropdown);
    min-width: 200px;
    max-width: min(320px, calc(100vw - 24px));
    padding: var(--space-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
    box-shadow: var(--shadow-lg);
    /* Closed menus take no space, so they never widen the page. */
    display: none;
}

.dropdown-menu-end {
    left: auto;
    right: 0;
}

.dropdown-menu-up {
    top: auto;
    bottom: calc(100% + 6px);
}

.dropdown.is-open > .dropdown-menu {
    display: block;
    animation: rb-menu-in var(--duration-fast) var(--ease-out);
}

@keyframes rb-menu-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
}

.dropdown.is-open > .dropdown-menu-up,
.dropdown.is-open > .dropdown-menu[data-placement="top"] {
    animation-name: rb-menu-in-up;
}

.dropdown.is-open > .dropdown-menu[data-placement="bottom"] {
    animation-name: rb-menu-in;
}

/*
 * Floating layer (core/position.js): an open menu or select list is taken out of its container
 * (fixed position, in the top layer where the Popover API exists), so no overflow, scroll container,
 * stacking context or modal dialog clips or covers it. The script sets top, left and, when the
 * space is short, max-height; the list then scrolls.
 */
.dropdown-menu.is-floating,
.select-list.is-floating {
    position: fixed;
    inset: auto;
    z-index: var(--z-dropdown);
    margin: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

@keyframes rb-menu-in-up {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-base);
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease);
}

.dropdown-item > i,
.dropdown-item > svg {
    flex: none;
    width: 16px;
    color: var(--text-subtle);
    font-size: 13px;
    text-align: center;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
    outline: none;
    background: var(--raised-hover);
    color: var(--text);
    text-decoration: none;
}

.dropdown-item[aria-checked="true"],
.dropdown-item.is-active {
    font-weight: 500;
}

.dropdown-item .dropdown-check {
    margin-left: auto;
    color: var(--accent-text);
    visibility: hidden;
}

.dropdown-item[aria-checked="true"] .dropdown-check,
.dropdown-item.is-active .dropdown-check {
    visibility: visible;
}

.dropdown-item-danger,
.dropdown-item-danger > i,
.dropdown-item-danger > svg {
    color: var(--danger);
}

.dropdown-item-danger:hover,
.dropdown-item-danger:focus-visible {
    background: var(--danger-bg);
    color: var(--danger);
}

.dropdown-item:disabled,
.dropdown-item.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.dropdown-divider {
    height: 1px;
    margin: var(--space-1) calc(var(--space-1) * -1);
    background: var(--border);
}

.dropdown-label {
    padding: 6px 10px 4px;
    color: var(--text-subtle);
    font-size: var(--text-xs);
    font-weight: 500;
}

.dropdown-header {
    padding: 8px 10px;
    line-height: 1.35;
}

.dropdown-header strong {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-weight: 600;
    text-overflow: ellipsis;
}

.dropdown-header span {
    display: block;
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-overflow: ellipsis;
}

.dropdown-form {
    display: contents;
}

.dropdown-caret {
    color: var(--text-subtle);
    font-size: 10px !important;
}

.dropdown-item > .dropdown-external {
    width: auto;
    margin-left: auto;
    font-size: 11px;
}

/* A form wrapping header, body and footer of a dialog. */
.dialog > form {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

/* ------------------------------------------------------------------ Tabs */

/* Tabs keep 24 px between labels: 8 px of padding on either side (room for an even focus ring) plus the gap. */
.tabs {
    display: flex;
    align-items: stretch;
    gap: var(--space-2);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

/*
 * More tabs behind an edge of a scrolling bar (classes is-overflowing-start / -end set by core/ui.js):
 * that edge fades into the background and shows a chevron. The cue sticks to the edge of the visible
 * part and takes no space (its negative margin cancels its width and the gap). --tabs-bg is the colour
 * behind the bar: the page, or the surface of a card or dialog.
 */
.tabs:not(.tabs-segmented) {
    --tabs-bg: var(--bg);
    --tabs-cue: 48px;
}

.card .tabs:not(.tabs-segmented) {
    --tabs-bg: var(--surface);
}

.dialog .tabs:not(.tabs-segmented) {
    --tabs-bg: var(--surface-raised);
}

.tabs:not(.tabs-segmented).is-overflowing-start::before,
.tabs:not(.tabs-segmented).is-overflowing-end::after {
    position: sticky;
    z-index: 1;
    display: flex;
    flex: none;
    align-items: center;
    width: var(--tabs-cue);
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    pointer-events: none;
}

.tabs:not(.tabs-segmented).is-overflowing-start::before {
    content: "\2039";
    inset-inline-start: 0;
    order: -1;
    justify-content: flex-start;
    margin-inline-end: calc((var(--tabs-cue) + var(--space-2)) * -1);
    background: linear-gradient(to left, transparent, var(--tabs-bg) 60%);
}

.tabs:not(.tabs-segmented).is-overflowing-end::after {
    content: "\203A";
    inset-inline-end: 0;
    justify-content: flex-end;
    margin-inline-start: calc((var(--tabs-cue) + var(--space-2)) * -1);
    background: linear-gradient(to right, transparent, var(--tabs-bg) 60%);
}

.tabs:not(.tabs-segmented):dir(rtl).is-overflowing-start::before {
    content: "\203A";
    background: linear-gradient(to right, transparent, var(--tabs-bg) 60%);
}

.tabs:not(.tabs-segmented):dir(rtl).is-overflowing-end::after {
    content: "\2039";
    background: linear-gradient(to left, transparent, var(--tabs-bg) 60%);
}

.tab {
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: var(--space-2);
    padding: 10px var(--space-2) 11px;
    color: var(--text-muted);
    font-size: var(--text-base);
    font-weight: 500;
    white-space: nowrap;
    transition: color var(--duration-fast) var(--ease);
}
.tab:hover {
    color: var(--text);
    text-decoration: none;
}

/* Active indicator: under the label, 2 px wider on either side. */
.tab::after {
    content: "";
    position: absolute;
    right: 6px;
    bottom: -1px;
    left: 6px;
    height: 2px;
    border-radius: 2px 2px 0 0;
    background: transparent;
    transition: background-color var(--duration-fast) var(--ease);
}

.tab.is-active,
.tab[aria-selected="true"],
.tab[aria-current="page"] {
    color: var(--text);
}

.tab.is-active::after,
.tab[aria-selected="true"]::after,
.tab[aria-current="page"]::after {
    background: var(--accent);
}

.tab:focus-visible {
    outline: none;
    border-radius: var(--radius-xs);
    box-shadow: inset 0 0 0 2px var(--focus);
}

.tab > i,
.tab > svg {
    font-size: 13px;
}

.tab .count {
    height: 18px;
}

.tab.is-active .count,
.tab[aria-selected="true"] .count,
.tab[aria-current="page"] .count {
    background: var(--accent-subtle);
    color: var(--accent-text);
}

/* Segmented control variant */
.tabs-segmented {
    display: inline-flex;
    gap: 2px;
    max-width: 100%;
    padding: 3px;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface-active);
}

.tabs-segmented .tab {
    padding: 0 12px;
    height: 30px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.tabs-segmented .tab::after {
    display: none;
}

.tabs-segmented .tab.is-active,
.tabs-segmented .tab[aria-selected="true"],
.tabs-segmented .tab[aria-current="page"] {
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

/* Dark theme: a quiet track outlined by a hairline, so that it reads on the page and on a card alike. */
:root[data-theme="dark"] .tabs-segmented {
    background: var(--surface-muted);
    box-shadow: inset 0 0 0 1px var(--border);
}

:root[data-theme="dark"] .tabs-segmented .tab.is-active,
:root[data-theme="dark"] .tabs-segmented .tab[aria-selected="true"],
:root[data-theme="dark"] .tabs-segmented .tab[aria-current="page"] {
    background: var(--surface-active);
    box-shadow: none;
}

.tab-panel:focus-visible {
    outline: none;
}

/* ------------------------------------------------------------------ Toasts */

.toast-region {
    position: fixed;
    right: var(--space-4);
    bottom: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-2);
    width: min(400px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    width: 100%;
    padding: 12px 12px 12px 14px;
    border: 1px solid var(--tone-border);
    border-radius: var(--radius);
    background: var(--tone-bg);
    color: var(--tone-title);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-base);
    pointer-events: auto;
    animation: rb-toast-in var(--duration-slow) var(--ease-out);
}

.toast.is-leaving {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease);
}

/* Colours come from the tone of the variant (see Alerts). */
.toast-icon {
    flex: none;
    margin-top: 1px;
    color: var(--tone-icon);
    font-size: 15px;
}

.toast-message {
    flex: 1;
    min-width: 0;
    padding-top: 1px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.toast-close {
    flex: none;
    width: 24px;
    height: 24px;
    margin: -2px -2px 0 0;
    border-radius: var(--radius-sm);
    color: var(--tone-icon);
    font-size: 12px;
}

.toast-close:hover {
    background: var(--tone-btn-hover);
    color: var(--tone-title);
}

@keyframes rb-toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

@media (max-width: 640px) {
    .toast-region {
        right: var(--space-4);
        left: var(--space-4);
        bottom: var(--space-4);
        width: auto;
    }
}

/* ------------------------------------------------------------------ Alerts */

/*
 * Tones: every tinted box (alerts, toasts) reads its colours from --tone-* properties, which the
 * variant classes map to the palette tokens of tokens.css. Background, border, icon, heading, body
 * text, links and the buttons inside the box are all shades of one hue.
 */
.alert,
.toast {
    --tone-bg: var(--neutral-bg);
    --tone-border: var(--neutral-border);
    --tone-icon: var(--neutral-icon);
    --tone-title: var(--neutral-title);
    --tone-fg: var(--neutral-fg);
    --tone-btn-bg: var(--neutral-btn-bg);
    --tone-btn-border: var(--neutral-btn-border);
    --tone-btn-hover: var(--neutral-btn-hover);
}

.alert-info,
.toast-info {
    --tone-bg: var(--info-bg);
    --tone-border: var(--info-border);
    --tone-icon: var(--info-icon);
    --tone-title: var(--info-title);
    --tone-fg: var(--info-fg);
    --tone-btn-bg: var(--info-btn-bg);
    --tone-btn-border: var(--info-btn-border);
    --tone-btn-hover: var(--info-btn-hover);
}

.alert-success,
.toast-success {
    --tone-bg: var(--success-bg);
    --tone-border: var(--success-border);
    --tone-icon: var(--success-icon);
    --tone-title: var(--success-title);
    --tone-fg: var(--success-fg);
    --tone-btn-bg: var(--success-btn-bg);
    --tone-btn-border: var(--success-btn-border);
    --tone-btn-hover: var(--success-btn-hover);
}

.alert-warning,
.toast-warning {
    --tone-bg: var(--warning-bg);
    --tone-border: var(--warning-border);
    --tone-icon: var(--warning-icon);
    --tone-title: var(--warning-title);
    --tone-fg: var(--warning-fg);
    --tone-btn-bg: var(--warning-btn-bg);
    --tone-btn-border: var(--warning-btn-border);
    --tone-btn-hover: var(--warning-btn-hover);
}

.alert-danger,
.toast-error {
    --tone-bg: var(--danger-bg);
    --tone-border: var(--danger-border);
    --tone-icon: var(--danger-icon);
    --tone-title: var(--danger-title);
    --tone-fg: var(--danger-fg);
    --tone-btn-bg: var(--danger-btn-bg);
    --tone-btn-border: var(--danger-btn-border);
    --tone-btn-hover: var(--danger-btn-hover);
}

.alert-accent {
    --tone-bg: var(--accent-subtle);
    --tone-border: var(--accent-border);
    --tone-icon: var(--accent-icon);
    --tone-title: var(--accent-title);
    --tone-fg: var(--accent-fg);
    --tone-btn-bg: var(--accent-btn-bg);
    --tone-btn-border: var(--accent-btn-border);
    --tone-btn-hover: var(--accent-btn-hover);
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: 12px 14px;
    border: 1px solid var(--tone-border);
    border-radius: var(--radius);
    background: var(--tone-bg);
    color: var(--tone-fg);
    font-size: var(--text-base);
    line-height: 1.5;
}

.alert-icon {
    flex: none;
    margin-top: 2px;
    color: var(--tone-icon);
    font-size: 15px;
}

.alert-content {
    flex: 1;
    min-width: 0;
}

.alert-title {
    color: var(--tone-title);
    font-weight: 600;
}

.alert-message {
    color: var(--tone-fg);
}

.alert-title + .alert-message {
    margin-top: var(--title-gap-sm);
}

.alert-content strong,
.alert-content b {
    color: var(--tone-title);
}

.alert-content a:not(.btn) {
    color: var(--tone-title);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
    text-underline-offset: 2px;
}

.alert-content a:not(.btn):hover {
    color: var(--tone-title);
    text-decoration-color: currentColor;
}

.alert-content code {
    background: var(--tone-btn-bg);
    color: var(--tone-title);
}

.alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

/* Secondary buttons on a tinted box take the tone; primary, accent and danger buttons keep their fill. */
:is(.alert, .toast) .btn:not(.btn-primary, .btn-accent, .btn-danger, .btn-link) {
    --btn-bg: var(--tone-btn-bg);
    --btn-fg: var(--tone-title);
    --btn-border: var(--tone-btn-border);
    --btn-hover-bg: var(--tone-btn-hover);
    --btn-hover-fg: var(--tone-title);
    --btn-hover-border: var(--tone-btn-border);
    --btn-shadow: none;
}

:is(.alert, .toast) .btn.btn-ghost {
    --btn-bg: transparent;
    --btn-border: transparent;
    --btn-hover-border: transparent;
}

:is(.alert, .toast) .btn-link {
    --btn-fg: var(--tone-title);
    --btn-hover-fg: var(--tone-title);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.alert-close {
    flex: none;
    width: 24px;
    height: 24px;
    margin: -2px -4px 0 0;
    border-radius: var(--radius-sm);
    color: var(--tone-icon);
    font-size: 12px;
}

.alert-close:hover {
    background: var(--tone-btn-hover);
    color: var(--tone-title);
}

/* ------------------------------------------------------------------ Pagination */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.pagination-summary {
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
}

.pagination-list {
    display: flex;
    align-items: center;
    gap: 2px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    transition: var(--transition-colors);
}

a.page-link:hover {
    background: var(--surface-hover);
    color: var(--text);
    text-decoration: none;
}

.page-link[aria-current="page"] {
    border-color: var(--border-strong);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

.page-link.is-disabled {
    color: var(--text-disabled);
    pointer-events: none;
}

.page-gap {
    min-width: 24px;
    color: var(--text-subtle);
    text-align: center;
}

@media (max-width: 640px) {
    .pagination {
        justify-content: center;
    }

    .pagination-summary {
        width: 100%;
        text-align: center;
    }

    .page-link .page-label {
        display: none;
    }
}

/* ------------------------------------------------------------------ Empty states */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-12) var(--space-6);
    text-align: center;
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-4);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    font-size: 19px;
}

.empty-state-title {
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.35;
}

.empty-state-text {
    max-width: 420px;
    margin-top: var(--title-gap);
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: var(--leading);
    text-wrap: balance;
}

.empty-state-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-5);
}

.empty-state-sm {
    padding: var(--space-8) var(--space-4);
}

.empty-state-sm .empty-state-icon {
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-3);
    font-size: 16px;
}

.empty-state-bordered {
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}

/* ------------------------------------------------------------------ Skeletons */

.skeleton {
    display: block;
    height: 12px;
    border-radius: var(--radius-xs);
    background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton-shine) 40%, var(--skeleton) 80%) 0 0 / 300% 100%;
    animation: rb-shimmer 1.6s ease-in-out infinite;
}

.skeleton-text {
    height: 10px;
    margin: 5px 0;
}

.skeleton-title {
    height: 14px;
    width: 40%;
}

.skeleton-circle {
    border-radius: 50%;
}

.skeleton-block {
    height: 120px;
    border-radius: var(--radius);
}

.skeleton-stack {
    display: grid;
    align-content: start;
    gap: 10px;
}

/* A placeholder card fills the height of its group, so placeholders in one grid row are equally tall. */
.skeleton-group {
    display: flex;
    flex-direction: column;
}

.skeleton-group > .card {
    flex: 1 1 auto;
}

@keyframes rb-shimmer {
    from {
        background-position: 100% 0;
    }

    to {
        background-position: 0 0;
    }
}

/* ------------------------------------------------------------------ Stars and ratings */

/* .stars contains .stars-track (empty stars) and .stars-fill (filled stars clipped to the rating width). */
.stars {
    --star-size: 15px;
    position: relative;
    display: inline-flex;
    flex: none;
    vertical-align: middle;
    line-height: 0;
}

.stars svg {
    flex: none;
    width: var(--star-size);
    height: var(--star-size);
}

.stars-track {
    display: inline-flex;
    color: var(--star-empty);
}

.stars-fill {
    position: absolute;
    inset: 0 auto 0 0;
    display: inline-flex;
    overflow: hidden;
    color: var(--star);
}

.stars-xs {
    --star-size: 12px;
}

.stars-sm {
    --star-size: 13px;
}

.stars-lg {
    --star-size: 20px;
}

.stars-xl {
    --star-size: 24px;
}

.rating-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}

.rating-inline-value {
    color: var(--text);
    font-weight: 600;
}

/* Rating summary: big score, stars, count */
.rating-summary {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.rating-summary-score {
    color: var(--text);
    font-size: 40px;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1;
}

.rating-summary-scale {
    margin-left: 4px;
    color: var(--text-subtle);
    font-size: var(--text-md);
    font-weight: 500;
    letter-spacing: 0;
}

.rating-summary-detail {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* The star fill is a percentage of the element width: keep the stars at their natural width. */
.rating-summary-detail > .stars {
    align-self: flex-start;
}

.rating-summary-count {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.rating-summary-empty .rating-summary-score {
    color: var(--text-disabled);
}

.rating-summary-sm {
    gap: var(--space-3);
}

.rating-summary-sm .rating-summary-score {
    font-size: 26px;
}

.rating-summary-sm .rating-summary-detail {
    gap: 3px;
}

.rating-summary-stacked {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
}

.recommend-meter {
    display: flex;
    overflow: hidden;
    width: 120px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--negative);
    gap: 2px;
}

.recommend-meter > span {
    background: var(--positive);
    border-radius: var(--radius-full);
}

/* Star distribution: .distribution > .distribution-row */
.distribution {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.distribution-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 40px;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    border-radius: var(--radius-xs);
}

.distribution-with-count .distribution-row {
    grid-template-columns: 34px minmax(0, 1fr) 40px 48px;
}

/* Rows share the columns of the list, so that large counts widen the count column for every row. */
@supports (grid-template-columns: subgrid) {
    .distribution-with-count {
        grid-template-columns: 34px minmax(0, 1fr) 40px minmax(48px, max-content);
        column-gap: 10px;
    }

    .distribution-with-count .distribution-row {
        grid-column: 1 / -1;
        grid-template-columns: subgrid;
    }
}

a.distribution-row {
    color: var(--text-muted);
}

a.distribution-row:hover {
    color: var(--text);
    text-decoration: none;
}

a.distribution-row:hover .distribution-fill {
    filter: brightness(0.92);
}

.distribution-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text);
    font-weight: 500;
}

.distribution-label svg {
    width: 11px;
    height: 11px;
    color: var(--star);
}

.distribution-bar {
    display: block;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--surface-active);
    overflow: hidden;
}

.distribution-fill {
    display: block;
    height: 100%;
    min-width: 0;
    border-radius: var(--radius-full);
    background: var(--star);
}

.distribution-percent,
.distribution-count {
    text-align: right;
}

.distribution-count {
    color: var(--text-subtle);
}

/* Recommendation indicator */
.recommendation {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    font-weight: 500;
}

.recommendation > i,
.recommendation > svg {
    font-size: 12px;
}

.recommendation-positive {
    color: var(--positive);
}

.recommendation-negative {
    color: var(--negative);
}

/* ------------------------------------------------------------------ Avatars */

.avatar {
    --avatar-size: 36px;
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    background: var(--avatar-bg, var(--neutral-bg));
    color: var(--avatar-fg, var(--neutral));
    font-size: max(10px, calc(var(--avatar-size) * 0.38));
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1;
    overflow: hidden;
    user-select: none;
}

.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--surface);
}

.avatar-xs {
    --avatar-size: 22px;
}

.avatar-sm {
    --avatar-size: 28px;
}

.avatar-lg {
    --avatar-size: 44px;
}

.avatar-xl {
    --avatar-size: 64px;
}

.avatar-square {
    border-radius: var(--radius);
}

/* Tones chosen deterministically from the name by the avatar partial. */
.avatar-tone-1 { --avatar-bg: #e8ecf5; --avatar-fg: #3b4a6b; }
.avatar-tone-2 { --avatar-bg: #fdf0e1; --avatar-fg: #9a4b0b; }
.avatar-tone-3 { --avatar-bg: #e3f5ec; --avatar-fg: #146c43; }
.avatar-tone-4 { --avatar-bg: #fbe8ee; --avatar-fg: #a12a52; }
.avatar-tone-5 { --avatar-bg: #ece9fb; --avatar-fg: #4d3fb0; }
.avatar-tone-6 { --avatar-bg: #e2f2f8; --avatar-fg: #0f617f; }

:root[data-theme="dark"] .avatar-tone-1 { --avatar-bg: #26304a; --avatar-fg: #b9c3dc; }
:root[data-theme="dark"] .avatar-tone-2 { --avatar-bg: #3a2a1a; --avatar-fg: #f2bf86; }
:root[data-theme="dark"] .avatar-tone-3 { --avatar-bg: #173327; --avatar-fg: #84d6ad; }
:root[data-theme="dark"] .avatar-tone-4 { --avatar-bg: #3a1f2b; --avatar-fg: #f1a1bd; }
:root[data-theme="dark"] .avatar-tone-5 { --avatar-bg: #2a2550; --avatar-fg: #bdb3fa; }
:root[data-theme="dark"] .avatar-tone-6 { --avatar-bg: #15323e; --avatar-fg: #86cde6; }

/* ------------------------------------------------------------------ Platform icon and badge */

.platform-icon {
    --platform-icon-size: 32px;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: var(--platform-icon-size);
    height: var(--platform-icon-size);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--platform-color, var(--text-muted));
    font-size: calc(var(--platform-icon-size) * 0.47);
    line-height: 1;
}

.platform-icon-xs {
    --platform-icon-size: 18px;
    border-radius: var(--radius-xs);
}

.platform-icon-sm {
    --platform-icon-size: 24px;
    border-radius: var(--radius-sm);
}

.platform-icon-lg {
    --platform-icon-size: 44px;
    border-radius: var(--radius-lg);
}

.platform-icon-xl {
    --platform-icon-size: 56px;
    border-radius: var(--radius-xl);
}

.platform-icon-plain {
    border: 0;
    background: none;
}

:root[data-theme="dark"] .platform-icon {
    background: var(--surface-muted);
}

/* Brands whose mark is near-black get a light tone in dark mode. */
:root[data-theme="dark"] .platform-icon.is-dark-brand,
:root[data-theme="dark"] .platform-badge.is-dark-brand .platform-badge-icon {
    color: var(--text);
}

.platform-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    height: 24px;
    padding: 0 9px 0 7px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    /* The icon comes first and has no text baseline; middle keeps the name level with surrounding text. */
    vertical-align: middle;
}

.platform-badge-icon {
    flex: none;
    color: var(--platform-color, var(--text-muted));
    font-size: 12px;
}

.platform-badge-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.platform-badge-sep {
    color: var(--text-disabled);
}

.platform-badge-detail {
    overflow: hidden;
    color: var(--text-muted);
    font-weight: 400;
    text-overflow: ellipsis;
}

.platform-badge-plain {
    height: auto;
    padding: 0;
    border: 0;
    background: none;
    font-size: var(--text-sm);
}

:root[data-theme="dark"] .platform-badge:not(.platform-badge-plain) {
    background: var(--surface-muted);
}

/* ------------------------------------------------------------------ Stat card */

.stat-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-5);
}

a.stat-card:hover {
    text-decoration: none;
}

.stat-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.stat-card-label {
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
}

.stat-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--surface-active);
    color: var(--text-muted);
    font-size: 13px;
}

/* Value, unit ("3.7 / 5": the same 4 px as .rating-summary-scale) and the change at the row's end. */
.stat-card-value {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px;
    color: var(--text);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.025em;
    line-height: 1.1;
}

.stat-card-unit {
    color: var(--text-subtle);
    font-size: var(--text-base);
    font-weight: 500;
    letter-spacing: 0;
}

.stat-card-delta {
    align-self: center;
    margin-left: auto;
    letter-spacing: 0;
    line-height: var(--leading);
}

.stat-card-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    background: var(--neutral-bg);
    color: var(--neutral);
    font-size: var(--text-xs);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.delta > i,
.delta > svg {
    font-size: 10px;
}

.delta-good {
    background: var(--success-bg);
    color: var(--success);
}

.delta-bad {
    background: var(--danger-bg);
    color: var(--danger);
}

.stat-card-chart {
    height: 40px;
    margin-top: var(--space-1);
}

/* ------------------------------------------------------------------ Review card */

.review-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-5);
}

.review-card.is-removed {
    background: var(--surface-muted);
}

.review-card.is-removed .review-body {
    color: var(--text-muted);
}

/*
 * Avatar, author and badges. The author keeps a minimum width; when the badges do not fit beside it in
 * the card (whatever the viewport), they wrap to their own line, indented under the author.
 */
.review-head {
    --review-avatar: 36px;
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-3);
}

.review-card-compact .review-head {
    --review-avatar: 28px;
}

.review-author {
    display: flex;
    flex: 1 1 10rem;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.review-author-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    min-width: 0;
}

.review-author-name {
    overflow: hidden;
    color: var(--text);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/*
 * Meta line: .review-meta > .review-meta-items > .review-meta-item. Every item draws its
 * "·" separator in its left padding; the items row is shifted left by that padding and
 * .review-meta clips it, so the separator of an item that starts a line is never visible.
 */
.review-meta {
    min-width: 0;
    margin: -4px;
    padding: 4px;
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.review-meta-items {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 2px;
    margin-left: -15px;
}

.review-meta-item {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    padding-left: 15px;
}

.review-meta-item.truncate {
    display: block;
}

.review-meta-item::before {
    content: "\00b7";
    position: absolute;
    left: 5px;
    color: var(--text-disabled);
}

.review-meta-sep {
    color: var(--text-disabled);
}

.review-meta a {
    color: inherit;
}

.review-meta a:hover {
    color: var(--text);
}

/* The left margin indents a wrapped badge line under the author; beside the author it only takes
   the author's spare room, which grows to push the badges to the right edge. */
.review-badges {
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    max-width: calc(100% - var(--review-avatar) - var(--space-3));
    margin-left: calc(var(--review-avatar) + var(--space-3));
}

.review-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.review-title {
    color: var(--text);
    font-size: var(--text-base);
    font-weight: 600;
}

.review-body {
    color: var(--text);
    line-height: var(--leading-relaxed);
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.review-body-empty {
    color: var(--text-subtle);
    font-style: italic;
}

/* Clamped text with expand toggle (data-clamp). */
.clamp {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: var(--clamp-lines, 5);
    line-clamp: var(--clamp-lines, 5);
    overflow: hidden;
}

.clamp.is-expanded {
    display: block;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    overflow: visible;
}

.clamp-toggle {
    align-self: flex-start;
    margin-top: 2px;
    color: var(--link);
    font-size: var(--text-sm);
    font-weight: 500;
}

.clamp-toggle:hover {
    color: var(--link-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.review-reply {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: calc(36px + var(--space-3));
    padding: 10px 14px;
    border-left: 2px solid var(--border-strong);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--surface-muted);
}

.review-reply.is-pending {
    border-left-color: var(--warning-solid);
}

.review-reply-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.review-reply-head strong {
    color: var(--text);
    font-weight: 600;
}

.review-reply-body {
    color: var(--text);
    line-height: var(--leading-relaxed);
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* Explanation under a reply that the platform still has to approve. */
.review-reply-hint {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 2px 0 0;
    color: var(--text-muted);
    font-size: var(--text-xs);
    line-height: var(--leading);
}

.review-reply-hint > i,
.review-reply-hint > svg {
    flex: none;
    margin-top: 2px;
    color: var(--warning-icon);
}

/* Link from an excerpt to the full review on the platform. */
.review-excerpt-link {
    margin: var(--space-2) 0 0;
    font-size: var(--text-sm);
}

.review-excerpt-link a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.review-excerpt-link i,
.review-excerpt-link svg {
    font-size: 0.85em;
}

.review-author-name.is-unknown {
    color: var(--text-muted);
    font-weight: 500;
}

.review-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-muted);
}

.review-actions-end {
    margin-left: auto;
}

/* Same inline padding as a card header, so rows of a divided list line up with their card's title. */
.review-card-compact {
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
}

.review-card-compact .review-reply {
    margin-left: 0;
}

.review-card-flat {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
}

.review-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.review-list-divided {
    gap: 0;
}

.review-list-divided > .review-card + .review-card {
    border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
    .review-card:not(.review-card-flat) {
        padding: var(--space-4);
    }

    .review-reply {
        margin-left: 0;
    }
}

/* ------------------------------------------------------------------ Charts */

.chart {
    position: relative;
    width: 100%;
    min-height: 120px;
}

.chart svg {
    display: block;
    overflow: visible;
}

.chart-sparkline {
    min-height: 0;
}

.chart text {
    fill: var(--chart-text);
    font-family: var(--font-sans);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

/* Second axis line, e.g. the year under the first month of a year. */
.chart text.chart-sublabel {
    fill: var(--text);
    font-weight: 600;
}

.chart-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: var(--z-tooltip);
    min-width: 120px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    font-size: var(--text-sm);
    line-height: 1.4;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease);
}

.chart-tooltip.is-visible {
    opacity: 1;
}

.chart-tooltip-title {
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
}

.chart-tooltip-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-tooltip-row strong {
    margin-left: auto;
    padding-left: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.chart-swatch {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--swatch, var(--chart-1));
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-bottom: var(--space-3);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: inherit;
    color: var(--text-subtle);
    font-size: var(--text-sm);
}

/* ------------------------------------------------------------------ Misc */

.divider {
    height: 1px;
    border: 0;
    background: var(--border);
}

.divider-label {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--text-subtle);
    font-size: var(--text-xs);
}

.divider-label::before,
.divider-label::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.progress {
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--surface-active);
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width var(--duration-slow) var(--ease);
}

.progress-warning > span {
    background: var(--warning-solid);
}

.progress-danger > span {
    background: var(--danger-solid);
}

/* Numbered steps: ol.steps > li */
.steps {
    display: grid;
    gap: var(--space-3);
    counter-reset: rb-step;
}

.steps > li {
    position: relative;
    padding-left: 36px;
    min-height: 24px;
    counter-increment: rb-step;
}

.steps > li::before {
    content: counter(rb-step);
    position: absolute;
    top: 0;
    left: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-xs);
    font-weight: 600;
}

.steps > li.is-done::before {
    content: "\2713";
    border-color: var(--success-solid);
    background: var(--success-solid);
    color: #ffffff;
}

/* CSS tooltip: any element with data-tooltip="text" */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    z-index: var(--z-tooltip);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--surface-inverse);
    color: var(--text-inverse);
    font-size: var(--text-xs);
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 2px);
    transition: opacity var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease);
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
    transition-delay: 300ms;
}

/* Filter bar above lists */
.filter-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.filter-bar > .input-group {
    flex: 1 1 220px;
    max-width: 320px;
}

/* Not the hidden native control of an enhanced select: sized to its longest option it would widen the page. */
.filter-bar > .select:not(.is-enhanced) {
    width: auto;
    min-width: 140px;
}

@media (max-width: 640px) {
    .filter-bar > .input-group,
    .filter-bar > .select:not(.is-enhanced) {
        flex: 1 1 100%;
        max-width: none;
    }

    /* Under full-width fields the buttons share the last row in full. */
    .filter-bar > .btn {
        flex: 1 1 0;
    }
}
