/* ==========================================================================
   Shared UI pieces that Web Awesome does not provide (see templates/components/ui.html).
   Prefix: ui-. Colours, radii and spacing come from tokens.css only.
   ========================================================================== */
@layer app-components {

    /* --- Status chip: soft pill, a word always present ----------------------- */
    .ui-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.2rem 0.65rem;
        border-radius: 999px;
        font-size: 0.8125rem;
        font-weight: 600;
        line-height: 1.4;
        white-space: nowrap;
        background: var(--d26-draft-bg);
        color: var(--d26-draft-fg);
    }
    .ui-chip--draft   { background: var(--d26-draft-bg);   color: var(--d26-draft-fg); }
    .ui-chip--wait    { background: var(--d26-wait-bg);    color: var(--d26-wait-fg); }
    .ui-chip--ok      { background: var(--d26-ok-bg);      color: var(--d26-ok-fg); }
    .ui-chip--bad     { background: var(--d26-bad-bg);     color: var(--d26-bad-fg); }
    .ui-chip--settled { background: var(--d26-settled-bg); color: var(--d26-settled-fg); }
    .ui-chip--leave   { background: var(--d26-leave-bg);   color: var(--d26-leave-fg); }

    /* --- Card ----------------------------------------------------------------- */
    .ui-card {
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
        padding: 1.25rem 1.375rem;
        box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    }
    .ui-card-title {
        margin: 0 0 0.75rem;
        font-size: 1rem;
        font-weight: 600;
        color: var(--d26-ink);
    }

    /* --- Section heading (UI_PATTERNS.md 4.3) --------------------------------- */
    .ui-section-head {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 0.75rem;
        margin: 0 0 0.5rem;
    }
    .ui-section-title {
        margin: 0;
        font-size: 0.8125rem;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--d26-ink-2);
    }
    .ui-count {
        display: inline-block;
        min-width: 1.5rem;
        padding: 0 0.4rem;
        border-radius: 999px;
        background: var(--d26-draft-bg);
        color: var(--d26-draft-fg);
        font-size: 0.75rem;
        text-align: center;
        letter-spacing: 0;
    }
    .ui-section-note {
        font-size: 0.8125rem;
        color: var(--d26-ink-2);
    }

    /* --- Page column (the page macro) ---------------------------------------- */
    .ui-page {
        max-width: 74rem;
        margin: 0 auto;
        padding: 1.125rem 1.25rem 2rem;
    }
    @media (max-width: 900px) {
        .ui-page { padding: 1rem; }
    }

    /* --- Page header ---------------------------------------------------------- */
    .ui-page-head {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.75rem 1rem;
        margin: 0 0 1.25rem;
    }
    .ui-page-head > div:first-child { flex: 1 1 18rem; min-width: 0; }
    .ui-page-title {
        margin: 0;
        font-size: 1.375rem;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: var(--d26-ink);
    }
    .ui-page-purpose {
        margin: 0.25rem 0 0;
        font-size: 0.875rem;
        color: var(--d26-ink-2);
    }
    .ui-page-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    /* --- Empty state ---------------------------------------------------------- */
    .ui-empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.35rem;
        padding: 2rem 1rem;
        text-align: center;
        color: var(--d26-ink-2);
    }
    .ui-empty-icon { font-size: 1.75rem; color: var(--d26-ink-3); }
    .ui-empty-title { margin: 0.25rem 0 0; font-weight: 600; color: var(--d26-ink); }
    .ui-empty-text { margin: 0; max-width: 32rem; font-size: 0.9375rem; }
    .ui-empty-action { margin-top: 0.75rem; }

    /* --- Modal footer --------------------------------------------------------- */
    .ui-modal-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    /* --- Card with no padding (a table or list fills it) ---------------------- */
    .ui-card--flush {
        position: relative;
        padding: 0;
        overflow: hidden;
    }

    /* --- Tabs (role="tablist" + buttons with role="tab"). The page script sets
           aria-selected; the active look follows it, so no class is toggled. ---- */
    .ui-tabs {
        display: flex;
        flex-wrap: nowrap;          /* on a narrow screen the tabs scroll sideways instead of stacking */
        overflow-x: auto;
        overflow-y: hidden;         /* no vertical scrollbar */
        scrollbar-width: thin;
        gap: 0.25rem;
        margin: 0 0 1.25rem;
        box-shadow: inset 0 -1px 0 var(--d26-line);   /* the line under the tabs (inside, so nothing overflows) */
    }
    .ui-tab {
        flex: none;
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: var(--d26-target);
        padding: 0 1rem;
        background: none;
        border: 0;
        border-bottom: 2px solid transparent;
        color: var(--d26-ink-2);
        font: inherit;
        font-weight: 600;
        cursor: pointer;
    }
    .ui-tab:hover { color: var(--d26-ink); }
    .ui-tab[aria-selected="true"] {
        color: var(--d26-accent);
        border-bottom-color: var(--d26-accent);
    }

    /* --- Toggle pills (aria-pressed): a year, a month, a quick filter ---------- */
    .ui-pills {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin: 0 0 0.75rem;
    }
    .ui-pill {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        min-height: var(--d26-target);
        padding: 0 1rem;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: 999px;
        color: var(--d26-ink);
        font: inherit;
        font-weight: 600;
        cursor: pointer;
    }
    .ui-pill:hover { border-color: var(--d26-accent); }
    .ui-pill[aria-pressed="true"] {
        background: var(--d26-accent-soft);
        border-color: var(--d26-accent);
        box-shadow: inset 0 0 0 1px var(--d26-accent);
    }

    /* --- Form controls (native elements, so HTMX and the page scripts keep working) */
    .ui-field[hidden] { display: none; }   /* the display rule below would otherwise beat the hidden attribute */
    .ui-field {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        min-width: 0;
    }
    .ui-label {
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--d26-ink-2);
    }
    .ui-input {
        box-sizing: border-box;
        width: 100%;
        min-height: var(--d26-target);
        padding: 0 0.75rem;
        background: #fff;
        border: 1px solid #d5d7dc;
        border-radius: var(--d26-radius-control);
        color: var(--d26-ink);
        font: inherit;
        font-size: 0.9375rem;
    }
    .ui-input::placeholder { color: #6b7280; }
    .ui-input:focus-visible {
        outline: none;
        border-color: var(--d26-accent);
        box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
    }
    .ui-search { position: relative; }
    .ui-search .ui-input { padding-left: 2.25rem; }
    .ui-search-icon {
        position: absolute;
        left: 0.85rem;
        top: 50%;
        transform: translateY(-50%);
        color: var(--d26-ink-2);
        font-size: 0.85rem;
        pointer-events: none;
    }
    .ui-check {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: var(--d26-target);
        color: var(--d26-ink-2);
        font-size: 0.9375rem;
        cursor: pointer;
    }
    .ui-check input {
        width: 18px;
        height: 18px;
        accent-color: var(--d26-accent);
    }

    /* --- Filter bar: fields in a grid that wraps by itself ------------------------ */
    .ui-filter-bar {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
        gap: 0.75rem 1rem;
        align-items: end;
        margin: 0 0 1.25rem;
        padding: 1rem 1.25rem;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
        box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    }
    .ui-filter-wide { grid-column: span 2; }
    .ui-filter-row {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: 0 1.5rem;
    }
    @media (max-width: 520px) {
        .ui-filter-wide { grid-column: 1 / -1; }
    }

    /* --- Loading note and skeleton rows ------------------------------------------- */
    .htmx-indicator { display: none; }
    .htmx-request .htmx-indicator,
    .htmx-request.htmx-indicator { display: inline-flex; align-items: center; gap: 0.4rem; }
    .ui-loading {
        position: absolute;
        top: 0.875rem;
        right: 1rem;
        z-index: 1;
        margin: 0;
        font-size: 0.8125rem;
        color: var(--d26-ink-2);
    }
    .ui-skeleton { padding: 1rem 1.25rem; display: grid; gap: 0.75rem; }
    .ui-skeleton wa-skeleton { height: 1.5rem; --border-radius: 6px; }

    /* --- Data table (scrolls inside its own box; numbers right-aligned) --------- */
    .ui-table-wrap { overflow-x: auto; }
    .ui-table {
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        font-size: 0.875rem;
    }
    .ui-table th {
        padding: 0.75rem 1rem;
        background: var(--d26-surface);
        border-bottom: 1px solid var(--d26-line);
        color: var(--d26-ink-2);
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-align: left;
        text-transform: uppercase;
        white-space: nowrap;
    }
    .ui-table td {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--d26-line);
        color: var(--d26-ink);
        vertical-align: middle;
    }
    .ui-table tbody tr:last-child td { border-bottom: 0; }
    .ui-table tbody tr:hover { background: var(--d26-surface); }
    .ui-table tr.is-muted td { opacity: 0.78; }
    .ui-table tr.is-problem { background: var(--d26-bad-bg); }
    /* Overdue row: tint (kept on hover) and a red bar on the left. Pair it with .ui-overdue-badge. */
    .ui-table tbody tr.is-overdue,
    .ui-table tbody tr.is-overdue:hover { background: var(--d26-bad-bg); }
    .ui-table tr.is-overdue > td:first-child { box-shadow: inset 5px 0 0 var(--d26-bad-fg); }
    .ui-overdue-badge {
        display: flex;
        align-items: center;
        gap: 0.3rem;
        width: fit-content;
        margin-top: 0.25rem;
        padding: 0.2rem 0.5rem;
        border-radius: var(--d26-radius-control);
        background: var(--d26-bad-fg);
        color: #fff;
        font-size: 0.75rem;
        font-weight: 700;
    }
    .ui-table--compact th,
    .ui-table--compact td { padding: 0.5rem 0.75rem; }
    .ui-table tfoot th,
    .ui-table tfoot td { background: var(--d26-surface); border-top: 1px solid var(--d26-line); border-bottom: 0; font-weight: 700; }
    .ui-table tfoot th { text-transform: none; letter-spacing: 0; font-size: 0.875rem; color: var(--d26-ink); }
    .ui-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

    /* Cards: on a narrow table box each row becomes a small card, the column name (data-label) before each value.
       Two thresholds, both measured on the box (.ui-table-wrap), not the screen: narrow (under 40rem) and wide (under 55rem).
       The box only becomes a container when the table opts in (data_table(cards=...)), so other tables are untouched. */
    .ui-table-wrap--cards { container-type: inline-size; }
    @media screen {                                                                  /* paper keeps the table: a printed claim must not turn into cards */
        @container (width <= 40rem) {
            .ui-table--cards-narrow thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
            .ui-table--cards-narrow tr { display: block; padding: 0.5rem 0; border-bottom: 1px solid var(--d26-line); }
            .ui-table--cards-narrow td { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); align-items: start; gap: 0 0.75rem; border-bottom: 0; padding: 0.375rem 1rem; white-space: normal; text-align: left; }
            .ui-table--cards-narrow td > * { grid-column: 2; justify-self: start; }                                /* a cell with several lines stacks in the value column */
            .ui-table--cards-narrow td[data-label]::before { content: attr(data-label); grid-column: 1; color: var(--d26-ink-2); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
            .ui-table--cards-narrow td[colspan] { display: table-cell; }
            .ui-table--cards-narrow td.ui-num { text-align: left; }
            .ui-table--cards-narrow tr[hidden] { display: none; }
        }
        @container (width <= 55rem) {
            .ui-table--cards-wide thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
            .ui-table--cards-wide tr { display: block; padding: 0.5rem 0; border-bottom: 1px solid var(--d26-line); }
            .ui-table--cards-wide td { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); align-items: start; gap: 0 0.75rem; border-bottom: 0; padding: 0.375rem 1rem; white-space: normal; text-align: left; }
            .ui-table--cards-wide td > * { grid-column: 2; justify-self: start; }                                /* a cell with several lines stacks in the value column */
            .ui-table--cards-wide td[data-label]::before { content: attr(data-label); grid-column: 1; color: var(--d26-ink-2); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
            .ui-table--cards-wide td[colspan] { display: table-cell; }
            .ui-table--cards-wide td.ui-num { text-align: left; }
            .ui-table--cards-wide tr[hidden] { display: none; }
        }
    }
    .ui-nowrap { white-space: nowrap; }
    .ui-strong { font-weight: 700; }
    .ui-muted { color: var(--d26-ink-2); }
    .ui-sub {
        display: block;
        margin-top: 2px;
        color: var(--d26-ink-2);
        font-size: 0.75rem;
    }
    .ui-problem {
        display: flex;
        align-items: center;
        gap: 0.25rem;
        margin-top: 2px;
        color: var(--d26-bad-fg);
        font-size: 0.75rem;
        font-weight: 600;
    }
    .ui-actions { text-align: right; white-space: nowrap; }
    .ui-actions > * + * { margin-left: 0.4rem; }
    .ui-chip + .ui-chip { margin-left: 0.4rem; }

    /* Text that acts like a link but is a button (opens a dialog) */
    .ui-link-btn {
        min-height: var(--d26-target);
        padding: 0 0.25rem;
        background: none;
        border: 0;
        color: var(--d26-accent);
        font: inherit;
        font-weight: 700;
        text-decoration: underline;
        cursor: pointer;
    }

    /* Table footer: how many, and the pager */
    .ui-table-foot {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        border-top: 1px solid var(--d26-line);
    }
    .ui-table-count { color: var(--d26-ink-2); font-size: 0.875rem; }
    .ui-pager { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
    .ui-pager-jump { display: inline-flex; align-items: center; gap: 0.375rem; }
    .ui-pager-jump wa-input { width: 4.5rem; }
    /* Left of a table footer: what is shown, and rows per page with its label beside the box */
    .ui-table-info { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.5rem; }
    .ui-page-size { width: auto; }
    .ui-page-size::part(form-control) { display: flex; align-items: center; gap: 0.5rem; }
    .ui-page-size::part(form-control-label) { margin: 0; white-space: nowrap; }
    .ui-page-size::part(combobox) { width: 5.5rem; }
    .ui-pager-page { font-size: 0.875rem; font-weight: 600; }

    /* --- Summary tiles: a count and a label; a button when it filters ---------- */
    .ui-tiles {
        display: flex;
        flex-wrap: wrap;
        gap: 0.625rem;
        margin: 0 0 0.75rem;
    }
    .ui-tile {
        position: relative;
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        gap: 0.625rem;
        min-height: var(--d26-target);
        padding: 0.75rem 1rem;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
        box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
        color: var(--d26-ink);
        font: inherit;
        text-align: left;
    }
    .ui-tile > i:first-child { color: var(--d26-accent); font-size: 0.95rem; }
    .ui-tile-count { font-size: 1.25rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
    .ui-tile-label { color: var(--d26-ink-2); font-size: 0.8125rem; white-space: nowrap; }
    .ui-tile--btn { cursor: pointer; }
    .ui-tile--btn:hover { border-color: var(--d26-accent); }
    .ui-tile[aria-pressed="true"] {
        background: var(--d26-accent-soft);
        border-color: var(--d26-accent);
        box-shadow: inset 0 0 0 1px var(--d26-accent);
    }
    .ui-tile .fa-check { margin-left: 2px; color: var(--d26-accent); }

    /* Smaller pills for lists of people; one that is not a button */
    .ui-pill--sm { font-size: 0.8125rem; }
    .ui-pill--static { cursor: default; background: var(--d26-surface); }
    .ui-pill--static:hover { border-color: var(--d26-line); }

    /* --- Disclosure (wa-details) ------------------------------------------------------------ */
    wa-details.ui-disclosure { margin: 0 0 1rem; background: #fff; }
    wa-details.ui-disclosure::part(header) { min-height: var(--d26-target); padding: 0 0.875rem; }
    wa-details.ui-disclosure::part(summary) { color: var(--d26-ink); font-size: 0.875rem; font-weight: 600; }
    wa-details.ui-disclosure::part(content) { padding: 0; }
    wa-details.ui-disclosure [slot="summary"] i { margin-right: 0.35rem; color: var(--d26-accent); }
    .ui-disclosure-body {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.25rem 0.875rem 0.875rem;
    }
    .ui-disclosure-body--block { display: block; }

    /* --- A large choice button (the Reset claim dialog) ---------------------- */
    .ui-alert-row {
        min-height: var(--d26-target);
        padding: 0.5rem 0.75rem;
        background: var(--d26-bad-bg);
        border: 1px solid transparent;
        border-radius: var(--d26-radius-control);
        color: var(--d26-bad-fg);
        font: inherit;
        font-weight: 600;
        text-align: left;
        cursor: pointer;
    }
    .ui-alert-row:hover,
    .ui-alert-row:focus-visible { border-color: var(--d26-bad-fg); outline: none; }
    .ui-alert-row--quiet { background: var(--d26-draft-bg); color: var(--d26-draft-fg); }
    .ui-alert-row--quiet:hover,
    .ui-alert-row--quiet:focus-visible { border-color: var(--d26-draft-fg); }

    /* --- Plain note, and a failed-load message with a retry button -------------- */
    .ui-note { margin: 0; color: var(--d26-ink-2); font-size: 0.875rem; }
    .ui-state {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem 1.25rem;
        color: var(--d26-danger);
    }

    /* --- Vertical rhythm: a stack of blocks with an even gap ------------------- */
    .ui-stack {
        display: grid;
        gap: 0.75rem;
        margin: 0 0 1rem;
    }
    .ui-stack > * { margin: 0; }

    /* --- Dialogs (wa-dialog): widths ---------------------------------------------- */
    wa-dialog { --width: 36rem; }
    wa-dialog.ui-dialog--narrow { --width: 28rem; }
    wa-dialog.ui-dialog--wide { --width: 52rem; }
    wa-drawer.ui-drawer--wide { --size: min(34rem, 95vw); }
    wa-dialog .ui-dialog-lead { margin: 0 0 1rem; color: var(--d26-ink-2); font-size: 0.875rem; }

    /* --- Forms inside dialogs ------------------------------------------------------ */
    .ui-form-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
    .ui-field--wide { grid-column: 1 / -1; }
    @media (max-width: 560px) {
        .ui-form-grid { grid-template-columns: minmax(0, 1fr); }
    }
    textarea.ui-input {
        min-height: 5rem;
        padding: 0.5rem 0.75rem;
        resize: vertical;
    }
    .ui-hint { margin: 0.25rem 0 0; color: var(--d26-ink-2); font-size: 0.8125rem; }
    .ui-field-error {
        display: block;
        margin-top: 0.25rem;
        color: var(--d26-danger);
        font-size: 0.8125rem;
    }
    wa-callout.ui-form-error { margin-top: 1rem; }
    .ui-form-actions {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
        margin-top: 1.25rem;
    }
    .ui-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
    .ui-inline > .ui-input { flex: 1 1 14rem; min-width: 0; width: auto; }
    .ui-inline > wa-input,
    .ui-inline > wa-select { flex: 1 1 14rem; min-width: 0; width: auto; }
    .ui-inline--end { align-items: flex-end; }   /* a button beside a labelled field lines up with the field, not its label */
    .ui-subhead { margin: 1rem 0 0.5rem; font-size: 0.9375rem; font-weight: 600; }

    /* A search box with a suggestion list under it (combobox) */
    .ui-combo { position: relative; }
    .ui-listbox {
        position: absolute;
        z-index: 5;
        top: 100%;
        left: 0;
        right: 0;
        max-height: 14rem;
        margin: 2px 0 0;
        padding: 4px;
        overflow-y: auto;
        list-style: none;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-control);
        box-shadow: 0 6px 18px rgba(23, 24, 28, 0.12);
    }
    .ui-listbox li {
        display: flex;
        align-items: center;
        min-height: var(--d26-target);
        padding: 6px 10px;
        border-radius: 6px;
        cursor: pointer;
    }
    .ui-listbox li:hover,
    .ui-listbox li.is-active { background: var(--d26-accent-soft); }
    .ui-hint-box {
        margin-top: 0.5rem;
        padding: 0.625rem 0.75rem;
        background: var(--d26-wait-bg);
        border-radius: var(--d26-radius-control);
    }
    .ui-hint-box p { margin: 0 0 0.5rem; color: var(--d26-wait-fg); font-weight: 600; }

    /* Label and value pairs (read-only details) */
    .ui-dl {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem 1.25rem;
        margin: 0 0 1rem;
    }
    .ui-dl-item dt {
        margin: 0 0 2px;
        color: var(--d26-ink-2);
        font-size: 0.6875rem;
        font-weight: 600;
        letter-spacing: 0.03em;
        text-transform: uppercase;
    }
    .ui-dl-item dd { margin: 0; color: var(--d26-ink); font-size: 0.9375rem; overflow-wrap: anywhere; }
    .ui-dl-item--wide { grid-column: 1 / -1; }
    @media (max-width: 560px) {
        .ui-dl { grid-template-columns: minmax(0, 1fr); }
    }

    /* A list of rows, one thing per row, with its own buttons */
    .ui-rows { margin: 0 0 1rem; padding: 0; list-style: none; }
    .ui-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.25rem 0.75rem;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--d26-line);
    }
    .ui-row-main { flex: 1 1 16rem; display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
    /* A short note on the same line as the row, just before its buttons ("Done by ... on ...").
       On a narrow screen it wraps under the text together with the buttons. */
    .ui-row-note {
        flex: 0 1 15rem;
        color: var(--d26-ink-2);
        font-size: 0.75rem;
        line-height: 1.35;
        text-align: right;
        text-wrap: balance;
    }
    .ui-actions { flex: none; }
    /* One line per row: the text column gives way first (it wraps), so the note and the buttons stay on the row.
       Only when the dialog is really narrow do the buttons drop under the text. */
    .ui-row--inline { flex-wrap: nowrap; gap: 0.25rem 1rem; }
    .ui-row--inline .ui-row-main { flex: 1 1 0; min-width: 7rem; }
    @media (max-width: 560px) {
        .ui-row--inline { flex-wrap: wrap; }
        .ui-row--inline .ui-row-main { flex: 1 1 100%; }
        .ui-row--inline .ui-row-note { text-align: left; flex: 1 1 100%; }
    }
    .ui-row-confirm {
        flex: 1 1 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-end;
        gap: 0.5rem;
        font-size: 0.9375rem;
    }

    .ui-pad { padding: 1rem; }

    /* A small number box that sits in a table cell */
    .ui-input--cell { width: 7.5rem; text-align: right; }

    /* --- Result of a check (an import preview): a box with a short list, and a warning inside ---- */
    .ui-result-box {
        margin: 1rem 0 0;
        padding: 0.75rem 0.875rem;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
    }
    .ui-result-box .ui-subhead { margin-top: 0; }
    .ui-bullets { margin: 0; padding-left: 1.25rem; font-size: 0.875rem; }
    .ui-bullets--muted { margin-top: 0.625rem; color: var(--d26-ink-2); }
    .ui-bullets--scroll { max-height: 12rem; overflow: auto; }
    .ui-warn-box {
        margin-top: 0.75rem;
        padding: 0.625rem 0.75rem;
        background: var(--d26-wait-bg);
        border-radius: var(--d26-radius-control);
        color: var(--d26-wait-fg);
    }
    .ui-warn-box summary { cursor: pointer; font-weight: 600; }
    .ui-warn-box .ui-note { margin: 0.375rem 0; color: inherit; }

    /* --- Detail pieces: a coloured panel, a banner hint, small cards, a timeline ------------------- */
    .ui-panel {
        margin: 0 0 1rem;
        padding: 0.75rem 0.875rem;
        background: var(--d26-accent-soft);
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
    }
    .ui-panel .ui-subhead { margin-top: 0; }
    wa-callout { margin: 0 0 0.75rem; }
    .ui-multiline { white-space: pre-wrap; overflow-wrap: anywhere; }
    .ui-cards { margin: 0 0 1rem; padding: 0; list-style: none; display: grid; gap: 0.75rem; }
    .ui-mini-card {
        padding: 0.75rem 0.875rem;
        background: #fff;
        border: 1px solid var(--d26-line);
        border-radius: var(--d26-radius-card);
    }
    /* A tinted card (good / bad). Use only where a word on the card says the same: never colour alone. */
    .ui-mini-card--ok { background: var(--d26-ok-bg); border-color: var(--d26-ok-fg); }
    .ui-mini-card--bad { background: var(--d26-bad-bg); border-color: var(--d26-bad-fg); }
    .ui-mini-card--ok dt, .ui-mini-card--bad dt { color: var(--d26-ink-2); }       /* small labels stay readable on the tint */
    .ui-mini-card-head {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem 0.75rem;
        margin-bottom: 0.5rem;
    }
    .ui-dl--auto { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.625rem 1.25rem; margin: 0; }
    /* A checkbox with a text beside it. The text wraps in its own column (a long one never
       slides under the box or pushes the buttons), and the box stays level with the first line. */
    .ui-check-line {
        display: flex;
        align-items: flex-start;
        gap: 0.625rem;
        min-width: 0;
        cursor: pointer;
        line-height: 1.4;
    }
    .ui-check-line input {
        flex: none;
        width: 18px;
        height: 18px;
        margin: 0.15rem 0 0;
        accent-color: var(--d26-accent);
    }
    .ui-check-text { min-width: 0; overflow-wrap: anywhere; }
    .ui-timeline { margin: 0; padding: 0; list-style: none; }
    .ui-timeline li { padding: 0.625rem 0; border-bottom: 1px solid var(--d26-line); }
    .ui-timeline-line { display: block; color: var(--d26-ink); font-size: 0.9375rem; overflow-wrap: anywhere; }

    /* --- Web Awesome pieces, themed to this app ------------------------------------------------ */
    wa-spinner { --indicator-color: var(--d26-accent); --track-color: var(--d26-line); }

    /* The library's labels follow the small-caps label style used for native fields (.ui-label) */
    wa-input::part(form-control-label),
    wa-select::part(form-control-label),
    wa-textarea::part(form-control-label),
    wa-time-input::part(form-control-label) {
        color: var(--d26-ink-2);
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }
    wa-input, wa-select, wa-textarea, wa-time-input { width: 100%; }
    /* Compact controls inside section headers or list rows should size to content, not force a new line */
    .ui-section-head wa-input,
    .ui-section-head wa-select,
    .ui-row wa-input,
    .ui-row wa-select {
        width: auto;
        min-width: 11rem;
    }
    /* An icon at the start of a field (the search magnifier) needs room before the text */
    wa-input::part(start),
    wa-select::part(start) { margin-inline-end: 0.625rem; }

    /* A button's icon and label sit one gap apart (the theme gives the gap). The icon brings no margin of its own, and an empty
       start or end slot is dropped, so it does not add one more gap to the side that has nothing in it. */
    wa-button > [slot="start"], wa-button > [slot="end"] { margin: 0; }
    wa-button:not(:has(> [slot="start"]))::part(start),
    wa-button:not(:has(> [slot="end"]))::part(end) { display: none; }
    /* A field whose label would only repeat the button beside it: kept for screen readers, hidden on screen */
    .ui-hide-label::part(form-control-label) {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    /* A number box that sits in a table cell */
    wa-input.ui-input--cell { width: 7.5rem; }
    wa-input.ui-input--cell::part(input) { text-align: right; }
    wa-checkbox::part(base) { min-height: var(--d26-target); align-items: center; }

    /* Tabs (wa-tab-group) */
    wa-tab-group {
        --indicator-color: var(--d26-accent);
        --track-color: var(--d26-line);
        margin: 0 0 1.25rem;
    }
    wa-tab::part(base) { gap: 0.5rem; min-height: var(--d26-target); padding: 0 1rem; }
    wa-tab-panel { --padding: 1.25rem 0 0; }   /* space between the tab row and the content */

    /* A sortable column title in a table header: a plain button (Web Awesome has none) with an arrow that follows the th's aria-sort. */
    .ui-sort-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.375rem;
        min-height: var(--d26-target);
        padding: 0;
        border: 0;
        background: none;
        color: inherit;
        font: inherit;
        letter-spacing: inherit;
        text-transform: inherit;
        cursor: pointer;
    }
    .ui-sort-btn:hover { color: var(--d26-accent); }
    .ui-sort-mark { font-size: 0.65rem; color: var(--d26-accent); }
    th[aria-sort="none"] .ui-sort-mark { color: var(--d26-ink-3); }

    /* A round photo that is also a button (Account settings): the circle, the icon or image inside, a visible focus ring. */
    .ui-avatar-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 4.5rem;
        height: 4.5rem;
        padding: 0;
        overflow: hidden;
        border: 2px solid var(--d26-line);
        border-radius: 50%;
        background: var(--d26-accent-soft);
        color: var(--d26-accent);
        font-size: 1.75rem;
        cursor: pointer;
    }
    .ui-avatar-btn:hover { border-color: var(--d26-accent); }
}
