/*
 * Points wicket-bootstrap5's own custom properties at Tabler's, so none of them stays light-mode.
 *
 * wicket-bootstrap5's responsive-table.css draws the card border, surface and label color from
 * --bs-border-color, --bs-body-bg, --bs-border-radius and --bs-secondary-color. Tabler renames the
 * prefix wholesale: each of those four is declared zero times in tabler.css against 1,374 --tblr-*
 * names in 1.7. The base sheet therefore falls through to its literals, which are light-mode
 * values, so a card in Tabler's dark theme would draw a pale border and a white surface over a dark
 * page.
 *
 * TablerVariableCoverageTest fails when a --bs5-* theme value is declared over there and not
 * remapped here, which is the one failure a green suite would otherwise hide until somebody looked
 * at the dark theme by hand.
 *
 * Scoped through :root purely for specificity, (0,2,0) against the base sheet's (0,1,0). The base
 * arrives lazily, contributed by the first table that opts in, while this is contributed with the
 * theme; either can land first, and the winner must not depend on which did.
 */

:root .table-responsive-cards {
	--bs5-table-card-border: var(--tblr-border-color);
	--bs5-table-card-bg: var(--tblr-bg-surface, var(--tblr-body-bg));
	--bs5-table-card-radius: var(--tblr-border-radius);
	--bs5-table-card-label: var(--tblr-secondary-color, var(--tblr-secondary));
}

/*
 * And the same again for the inbox list in list-rows.css, which reads six: --bs-border-color,
 * --bs-tertiary-bg, --bs-primary, --bs-secondary-color, --bs-border-radius and
 * --bs-primary-bg-subtle. Same problem, same :root for the same specificity reason, (0,2,0) through
 * :is, which takes its most specific argument.
 *
 * Both hosts, the table and a ListRowsBehavior container. Scoped to the table alone, a list outside
 * one fell through to every light-mode literal in Tabler's dark theme.
 *
 * The one that matters most in dark mode is the hover fill. Its literal is #f8f9fa, so without this
 * a hovered row in Tabler's dark theme flashes near-white and takes the text with it.
 *
 * It is the tertiary surface, 2.5% body color in light and 4% in dark, and not --tblr-hover-bg, the
 * 4% and 6% Tabler hovers its own table rows and list groups with. Measured for the Tabler 1.7 audit
 * across all 196 themes: Tabler's fill keeps the muted text at 4.58 or better, but a row's title is
 * a link in the primary color, which several accents put at 4.6 to 4.8 on the bare surface, and the
 * stronger fill takes it under 4.5 in 33 themes where this one does in 17. It also separates a
 * hovered row from the open one no better: their least oklab distance falls from 0.020 to 0.015.
 *
 * The open row is --tblr-primary-lt, 10% primary, and not --tblr-active-bg, the 4% Tabler gives an
 * active list-group item. Measured under the light theme in Chrome, issue #93: --tblr-active-bg
 * resolved to rgb(245, 249, 253) against a hover fill of rgb(248, 250, 252), so the open row read as
 * the hovered one, and it shares its accent bar with an unread row.
 */
:root :is(.table-list-rows, .list-rows) {
	--bs5-list-row-border: var(--tblr-border-color);
	--bs5-list-row-hover: var(--tblr-bg-surface-tertiary, var(--tblr-bg-surface-secondary));
	--bs5-list-row-accent: var(--tblr-primary);
	--bs5-list-row-muted: var(--tblr-secondary-color, var(--tblr-secondary));
	--bs5-list-row-radius: var(--tblr-border-radius);
	--bs5-list-row-current: var(--tblr-primary-lt);
}

/*
 * The open row's muted text is Tabler's --tblr-secondary-text-emphasis, Bootstrap's pairing for
 * text on a subtle tint, as the row's title already takes the body color there. Under Tabler 1.6.1
 * the secondary color kept 4.56:1 on the tint in the light theme; 1.7 took it to 4.46, under the 4.5
 * body text needs in every light base, and to 4.23 under mist with the inverted accent, whose
 * near-black primary makes any primary tint a gray. A lighter tint is no way out: at 6% the open row
 * and a hovered one are 0.009 apart in oklab, and mist with the inverted accent still fails at 5%.
 * The emphasis color measured 6.34 or better in all 196 themes, and stays under the title, 1.33:1 at
 * the closest. states.mjs measures both, and the hovered row's muted text with them.
 */
:root :is(.table-list-rows, .list-rows) .list-row-current {
	--bs5-list-row-muted: var(--tblr-secondary-text-emphasis);
}

/*
 * And detail-list.css, which reads one: --bs-secondary-color, for the caption above each value in
 * its vertical layout. Same problem, same :root for the same specificity reason.
 *
 * Only one, because the horizontal layout deliberately styles nothing of its own - it is Bootstrap's
 * <dl class="row"> unchanged, and Tabler restyles that itself.
 */
:root .bs5-detail-list,
:root .bs5-detail-list-horizontal {
	--bs5-detail-label-color: var(--tblr-secondary-color, var(--tblr-secondary));
}

/*
 * The same again for the selected-row highlight in selection-column.css, which sets the state pair
 * .table-active uses. Tabler renames those wholesale too: --bs-table-bg-state and its three
 * neighbors are declared zero times in tabler.css.
 *
 * No :root here, unlike above. The base rule sets --bs-* names and this one sets --tblr-*, so the
 * two never compete and whichever sheet lands first is immaterial.
 */
.table-select-rows > tbody > tr:has(> .cell-select input:checked) {
	--tblr-table-color-state: var(--tblr-table-active-color);
	--tblr-table-bg-state: var(--tblr-table-active-bg);
}

/*
 * Gives Tabler back its own sort indicator, which wicket-bootstrap5's table-sort.css was dimming.
 *
 * Both sheets draw the indicator. The base rule is :where(.table-sort)::after, so Tabler's own
 * .table-sort::after draws it wherever the two sheets land, its glyph, size and spacing from Tabler's
 * properties. See issue #42.
 *
 * One declaration gets through. Tabler separates unsorted from sorted by color alone, and never sets
 * opacity; the base sheet dims the unsorted arrow to 0.4 because under plain Bootstrap it has no
 * color treatment to distinguish them with. Under Tabler the two compound, so the unsorted arrow
 * rendered at 40% of an already muted color - measured rgb(156, 163, 175) at 0.4, against Tabler's
 * intended rgb(156, 163, 175) at 1.
 *
 * :root for specificity rather than order, for the reason the rules above give, though since the base
 * rule went into :where() a bare class would outrank it too.
 */

:root .table-sort::after {
	opacity: 1;
}
