.btbl-table-wrapper {
	overflow-x: auto;
	position: relative;
	/* Theming cascade: a table's explicit Accent color sets --btbl-accent inline on this
	   wrapper; otherwise it inherits the theme's global palette primary, falling back to the
	   WordPress admin blue. DataTables 3's control color hooks ride the same accent. */
	--btbl-accent: var(--wp--preset--color--primary, #2271b1);
	--btbl-border: #d0d7de;
	--btbl-muted: #6c757d;
	--btbl-surface: #fff;
	--dt-control_color: var(--btbl-accent);
}

/* The sorted column carries a subtle accent tint instead of DataTables' neutral gray. */
.btbl-table-wrapper table.dataTable > thead th.dt-ordering-asc,
.btbl-table-wrapper table.dataTable > thead th.dt-ordering-desc {
	background: color-mix(in srgb, var(--btbl-accent) 7%, transparent);
}

.btbl-table {
	width: 100%;
}

/* The aggregate footer reads as part of the table: a strong top rule and a quiet tint, so
   "Sum: 60" lands as a footer row rather than a stray number under the last row. The tint
   pairs an explicit dark text color — a dark theme's inherited white text would otherwise
   land on the light surface at ~1:1. */
.btbl-table tfoot td[data-btbl-aggregate]:not([data-btbl-aggregate="none"]) {
	border-top: 2px solid var(--btbl-border);
	background: #f6f8fa;
	color: #1f2328;
	font-weight: 600;
}

.btbl-table td.btbl-condition-accent,
.btbl-table td.dtfc-fixed-start.btbl-condition-accent,
.dtr-data.btbl-condition-accent {
	background-color: #eaf4fb;
	color: #135e96;
}

.btbl-table td.btbl-condition-success,
.btbl-table td.dtfc-fixed-start.btbl-condition-success,
.dtr-data.btbl-condition-success {
	background-color: #edfaef;
	color: #14532d;
}

.btbl-table td.btbl-condition-warning,
.btbl-table td.dtfc-fixed-start.btbl-condition-warning,
.dtr-data.btbl-condition-warning {
	background-color: #fff8e1;
	color: #6b4f00;
}

.btbl-table td.btbl-condition-danger,
.btbl-table td.dtfc-fixed-start.btbl-condition-danger,
.dtr-data.btbl-condition-danger {
	background-color: #fff0f0;
	color: #8a1f11;
}

.btbl-filter-wrapper,
.btbl-filter {
	display: flex;
	flex-direction: column;
}

.btbl-filter-wrapper {
	gap: 12px;
	margin-bottom: 12px;
	position: relative;
}

.btbl-filter {
	gap: 6px;
}

.btbl-filter .ts-wrapper {
	width: 100%;
}

/* Native selects (the plain dropdown variants) match the Tom Select controls' full-width
   rhythm; unstyled, they collapsed to their option text width next to full-width siblings. */
.btbl-filter .btbl-filter-control {
	width: 100%;
}

.btbl-filter .ts-control {
	border: 1px solid var(--btbl-border);
	border-radius: 4px;
}

.btbl-filter .ts-wrapper.focus .ts-control {
	border-color: var(--btbl-accent);
	box-shadow: 0 0 0 1px var(--btbl-accent);
}

.btbl-filter .ts-dropdown {
	border-color: var(--btbl-border);
	border-radius: 4px;
	box-shadow: 0 3px 6px rgba(0, 0, 0, 0.12);
	margin-top: 4px;
	z-index: 9999;
}

.btbl-filter-options label {
	display: inline-block;
	margin-right: 10px;
}

.btbl-table-wrapper .dt-search {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
}

/* Toolbar polish on top of DataTables' own layout: DT renders one start cell (left, via its
   own auto margins) and one end cell (right), so the macro grouping is already correct. What
   is missing is graceful narrow-width behavior: let the row wrap instead of squeezing, keep a
   consistent gap, and never break the "Show N rows" label across lines. Margin overrides are
   deliberately absent -- vendor's div-qualified selectors outrank wrapper-scoped ones, and
   vendor's grouping is what we want. */
.btbl-table-wrapper .dt-layout-row {
	column-gap: 16px;
	flex-wrap: wrap;
	row-gap: 8px;
}

.btbl-table-wrapper .dt-length {
	white-space: nowrap;
}

.btbl-table-wrapper .dt-search label {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
}

.btbl-search-placeholder-visual {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	color: var(--btbl-muted);
	font-size: 13px;
	pointer-events: none;
}

.btbl-has-placeholder-visual .btbl-search-placeholder-visual svg {
	width: 14px;
	height: 14px;
}

.btbl-has-placeholder-visual.btbl-search-filled .btbl-search-placeholder-visual {
	display: none;
}

.btbl-search-columns {
	position: relative;
}

/* Self-contained front-end control styling. The "Clear filters" and "Edit Table" controls carry
   wp-admin's .button classes, which only exist on the front end if the active theme happens to
   define them -- on themes that don't, they rendered as unstyled UA buttons right next to this
   fully-styled toggle. The wp classes stay on the markup as progressive enhancement. The white
   surface pairs an explicit dark text color: with plain `color: inherit`, a dark theme's white
   text landed on the white background and vanished. */
.btbl-search-columns-toggle,
.btbl-reset-button,
.btbl-edit-link {
	border: 1px solid var(--btbl-border);
	background: var(--btbl-surface);
	border-radius: 4px;
	padding: 5px 10px;
	font-size: 13px;
	cursor: pointer;
	line-height: 1.2;
	display: inline-block;
	color: #1f2328;
	text-decoration: none;
}

.btbl-search-columns-toggle:focus,
.btbl-reset-button:focus,
.btbl-edit-link:focus {
	outline: 2px solid var(--btbl-accent);
	outline-offset: 1px;
}

/* Anchored to the inline END, not a physical right edge: in RTL the search control sits at the
   wrapper's other side, and a physical right:0 pushed the panel out of (and under) the wrapper's
   scroll area. max-height + internal scroll keeps a short table from clipping the panel bottom
   into the wrapper's own scrollbar. */
.btbl-search-columns-dropdown {
	position: absolute;
	inset-inline-end: 0;
	top: calc(100% + 5px);
	padding: 10px 10px 10px 12px;
	border: 1px solid var(--btbl-border);
	border-radius: 6px;
	background: var(--btbl-surface);
	color: #1f2328;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
	display: none;
	z-index: 20;
	white-space: nowrap;
	max-height: 60vh;
	overflow-y: auto;
}

.btbl-search-columns-dropdown.is-open {
	display: block;
}

.btbl-search-columns-heading {
	font-weight: 600;
	font-size: 13px;
	margin-bottom: 6px;
}

.btbl-search-columns-list {
	max-height: 220px;
	overflow-y: auto;
	display: grid;
	gap: 6px;
	padding-right: 18px;
}

.btbl-search-columns-option {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
}

.btbl-empty-state {
	display: none;
	margin-top: 10px;
	padding: 10px 12px;
	border: 1px dashed #d63638;
	background: #fff5f5;
	color: #8a1f11;
}

.btbl-runtime-error,
.btbl-source-error {
	margin: 10px 0;
	padding: 10px 12px;
	border: 1px solid #d63638;
	background: #fff5f5;
	color: #8a1f11;
}

.btbl-loading-mask {
	position: absolute;
	inset: 0;
	display: none;
	align-items: center;
	justify-content: center;
	gap: 10px;
	background: rgba(255, 255, 255, 0.9);
	z-index: 50;
}

.btbl-table-wrapper.is-loading .btbl-loading-mask {
	display: flex;
}

.btbl-table-wrapper.is-loading .btbl-filter-wrapper,
.btbl-table-wrapper.is-loading .btbl-table {
	opacity: 0.35;
	filter: blur(0.5px);
}

.btbl-spinner {
	width: 18px;
	height: 18px;
	border: 2px solid #c3c4c7;
	border-top-color: #0073aa;
	border-radius: 50%;
	animation: btbl-spin 0.8s linear infinite;
}

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