@layer htmxo {
.htmxo-sortable-table thead th { cursor: pointer; }
.htmxo-sortable-table thead th[colspan] { cursor: default; text-align: center; border-bottom: none; }
/* Body cells with a hyperscript handler are clickable too (htmx-attr cells
   already get cursor:pointer from the global rule in htmxo_utility_styles). */
.htmxo-sortable-table tbody td[_] { cursor: pointer; }
/* A :tally group summary (`ColumnSummary(:tally, …)`): the total, then a
   stacked bar as long as the total on the scale the column's rows of one
   level share (`--htmxo-tally-max`, from `htmxoTallyScale`), one segment
   per category, 2px of the row between segments. Every track has the same
   width (`--htmxo-tally-width`, set it for a narrow column), so bars
   compare; it wraps under the total where the cell is narrower. */
.htmxo-tally { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .1em .4em; vertical-align: middle; }
.htmxo-tally-total { font-variant-numeric: tabular-nums; }
.htmxo-tally-track { display: block; flex: none; inline-size: var(--htmxo-tally-width, 5rem); }
.htmxo-tally-bar { display: flex; gap: 2px; inline-size: calc(var(--htmxo-tally-total) / var(--htmxo-tally-max, var(--htmxo-tally-total)) * 100%); max-inline-size: 100%; block-size: .7em; }
.htmxo-tally-bar > span { flex: var(--htmxo-tally-n, 1) 1 0; min-inline-size: 2px; background: var(--htmxo-tally-color, var(--htmxo-category-other)); }
.htmxo-tally-bar > span:first-child { border-start-start-radius: 2px; border-end-start-radius: 2px; }
.htmxo-tally-bar > span:last-child { border-start-end-radius: 2px; border-end-end-radius: 2px; }
/* The categorical palette a :tally colours its first eight categories with,
   in this order; the rest take the grey. Dark mode has its own steps of the
   same hues. In the layer, so an app's own values win. */
:root {
    --htmxo-category-1: #2a78d6; --htmxo-category-2: #eb6834; --htmxo-category-3: #1baf7a; --htmxo-category-4: #eda100;
    --htmxo-category-5: #e87ba4; --htmxo-category-6: #008300; --htmxo-category-7: #6250d6; --htmxo-category-8: #e34948;
    --htmxo-category-other: #8f8e88;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --htmxo-category-1: #3987e5; --htmxo-category-2: #d95926; --htmxo-category-3: #199e70; --htmxo-category-4: #c98500;
        --htmxo-category-5: #d55181; --htmxo-category-6: #008300; --htmxo-category-7: #9085e9; --htmxo-category-8: #e66767;
        --htmxo-category-other: #75746e;
    }
}
:root[data-theme="dark"] {
    --htmxo-category-1: #3987e5; --htmxo-category-2: #d95926; --htmxo-category-3: #199e70; --htmxo-category-4: #c98500;
    --htmxo-category-5: #d55181; --htmxo-category-6: #008300; --htmxo-category-7: #9085e9; --htmxo-category-8: #e66767;
    --htmxo-category-other: #75746e;
}
}
/* Master/detail paired-row rules — INTENTIONALLY UNLAYERED so they beat
   Pico's unlayered tr/td defaults. The sortable_table_js convention pairs
   a primary row `tr#row-<key>` with a hidden detail row `tr#detail-<key>`. */
.htmxo-sortable-table tbody tr[id^="row-"]:hover {
    background: var(--pico-table-row-stripped-background-color);
}
.htmxo-sortable-table tbody tr[id^="row-"][onclick] > td { cursor: pointer; }
.htmxo-sortable-table tbody tr[id^="detail-"] > td { padding: 0; border: none; }
/* Column alignment (`ColumnSpec(label; align)`): a number cell sits at the
   right of its column, and a column's `data-htmxo-align`, on its header and
   cells, wins over that. Unlayered, as Pico's `td, th { text-align: start }`
   is; the header's sort button follows its <th> (`text-align: inherit`). */
td[data-htmxo-number] { text-align: right; }
:is(th, td)[data-htmxo-align="left"] { text-align: left; }
:is(th, td)[data-htmxo-align="center"] { text-align: center; }
:is(th, td)[data-htmxo-align="right"] { text-align: right; }
/* Opt-in density. Direct cells only: a detail panel keeps its usual type and
   spacing, and a table inside a cell starts at the normal root type size.
   Unlayered to beat Pico's cell padding. Nothing clips or truncates text. */
table[data-htmxo-density="compact"] > thead > tr > th,
table[data-htmxo-density="compact"] > tbody > tr:not([id^="detail-"]) > :is(td, th) {
    font-size: .9rem; line-height: 1.5; padding: .25rem .5rem;
}
table[data-htmxo-density="compact"] table { font-size: 1rem; }
/* Keep the CSV action above the table, with less empty space around it.
   The title, explanation and caption disclosure keep their own typography. */
figure.captioned:has(> .table-wrap > table[data-htmxo-density="compact"]) > figcaption.caption {
    padding-block: 0; margin-bottom: .25rem;
}
/* Hover linking (`link=`): the rows holding the hovered item are tinted and
   outlined; a shown row that holds it in a collapsed group gets a dashed
   outline, labelled on its top edge by the first cell's note. Neither moves
   the layout or covers the row's own text. */
table[data-htmxo-link] > tbody > tr[data-htmxo-linked] { outline: 2px solid var(--htmxo-accent, Highlight); outline-offset: -2px; }
table[data-htmxo-link] > tbody > tr[data-htmxo-linked=""] > td { background-color: var(--htmxo-linked-row, color-mix(in srgb, var(--htmxo-accent, Highlight) 18%, transparent)); }
table[data-htmxo-link] > tbody > tr[data-htmxo-linked=""] { --htmxo-tinted-primary: color-mix(in srgb, var(--pico-primary) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-primary-hover: color-mix(in srgb, var(--pico-primary-hover) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-secondary: color-mix(in srgb, var(--pico-secondary) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-secondary-hover: color-mix(in srgb, var(--pico-secondary-hover) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-muted: color-mix(in srgb, var(--pico-muted-color) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-htmxo-muted: color-mix(in srgb, var(--htmxo-muted) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-del: color-mix(in srgb, var(--pico-del-color) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-ins: color-mix(in srgb, var(--pico-ins-color) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-success: color-mix(in srgb, var(--htmxo-success) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-warning: color-mix(in srgb, var(--htmxo-warning) 40%, var(--pico-contrast, CanvasText)); --htmxo-tinted-error: color-mix(in srgb, var(--htmxo-error) 40%, var(--pico-contrast, CanvasText)); }
table[data-htmxo-link] > tbody > tr[data-htmxo-linked=""] > td { --pico-primary: var(--htmxo-tinted-primary); --pico-primary-hover: var(--htmxo-tinted-primary-hover); --pico-secondary: var(--htmxo-tinted-secondary); --pico-secondary-hover: var(--htmxo-tinted-secondary-hover); --pico-muted-color: var(--htmxo-tinted-muted); --htmxo-muted: var(--htmxo-tinted-htmxo-muted); --pico-del-color: var(--htmxo-tinted-del); --pico-ins-color: var(--htmxo-tinted-ins); --htmxo-success: var(--htmxo-tinted-success); --htmxo-warning: var(--htmxo-tinted-warning); --htmxo-error: var(--htmxo-tinted-error); }

table[data-htmxo-link] > tbody > tr[data-htmxo-linked="inside"] { outline-style: dashed; }
table[data-htmxo-link] > tbody > tr > td[data-htmxo-linked-note] { position: relative; }
table[data-htmxo-link] > tbody > tr > td[data-htmxo-linked-note]::after { content: attr(data-htmxo-linked-note); position: absolute; z-index: 1; inset-inline-start: .5rem; top: 0; transform: translateY(-50%); padding: 0 .5em; border: 1px dashed var(--htmxo-accent, Highlight); border-radius: 1em; background: var(--pico-background-color, Canvas); color: var(--pico-color, CanvasText); font-size: .7em; line-height: 1.5; white-space: nowrap; pointer-events: none; }
