/**
 * Advanced Table Builder — front-end styles.
 *
 * Only structural / behavioural rules live here. All cosmetic styling (colours,
 * typography, borders, spacing) is generated by Elementor from the widget's
 * controls, so this file stays small and authors keep full control.
 *
 * @package AdvancedTableBuilder
 */

/* The scroll wrapper doubles as the alignment container (justify-content is
 * driven by the "Alignment" control) and the horizontal-scroll viewport. */
.atb-table-scroll {
	display: flex;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.atb-table {
	border-collapse: collapse;
	width: 100%;
}

/* Sensible unstyled defaults so a freshly dropped table is legible before any
 * styling is applied. Authors override every one of these via the controls. */
.atb-cell {
	padding: 12px 16px;
	border: 1px solid #e2e8f0;
	vertical-align: middle;
	text-align: left;
}

.atb-cell--head {
	font-weight: 600;
	background-color: #f8fafc;
}

.atb-cell--foot {
	font-weight: 600;
	background-color: #f8fafc;
}

.atb-cell-image {
	max-width: 100%;
	height: auto;
	display: inline-block;
}

.atb-cell-icon svg,
.atb-cell-icon i {
	width: 1.25em;
	height: 1.25em;
	font-size: 1.25em;
}

.atb-cell-btn {
	display: inline-block;
	padding: 8px 18px;
	border-radius: 4px;
	background-color: #2563eb;
	color: #fff;
	text-decoration: none;
	line-height: 1.2;
}

.atb-cell-btn:hover,
.atb-cell-btn:focus {
	opacity: 0.9;
}

.atb-cell-list {
	margin: 0;
	padding-left: 1.2em;
	text-align: inherit;
}

/* Embedded cells ("split" content type): a mini grid inside one cell. The
 * sub-cells share the space equally so they line up down a column. */
.atb-split {
	display: flex;
	gap: 0;
}

.atb-split--row {
	flex-direction: row;
	align-items: stretch;
}

.atb-split--column {
	flex-direction: column;
}

.atb-split-item {
	flex: 1 1 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 4px 10px;
	text-align: center;
	min-width: 0;
	word-break: break-word;
}

/* Dividers between the embedded cells (not before the first one). */
.atb-split--divided.atb-split--row .atb-split-item + .atb-split-item {
	border-left: 1px solid currentColor;
	border-color: inherit;
}

.atb-split--divided.atb-split--column .atb-split-item + .atb-split-item {
	border-top: 1px solid currentColor;
	border-color: inherit;
}

/* Accessible caption: present for screen readers, visually unobtrusive. */
.atb-caption {
	caption-side: top;
	text-align: left;
	font-size: 0.875em;
	color: #64748b;
	padding: 0 0 8px;
}

/* =====================================================================
 * Click-to-highlight column
 * A cell with a "Highlight Column on Click" value renders as a trigger; the
 * frontend script stamps .atb-col-active onto every cell in the target column.
 * The highlight uses background-image (a gradient) so it sits above any
 * background-color from zebra striping or column overrides without a fight.
 * ===================================================================== */
.atb-table .atb-col-trigger,
.atb-table [data-atb-col-toggle] {
	cursor: pointer;
}

/* Hover affordance on clickable column headers.
 * !important is required: many themes ship `thead .atb-cell--head { background:
 * transparent !important }`, which would otherwise win on these header cells. */
.atb-table thead .atb-cell[data-atb-col-toggle]:hover {
	background-color: #2B2265 !important;
	color: #fff !important;
}

.atb-table .atb-cell.atb-col-active {
	background-image: linear-gradient(to right, #7a80d6 0%, #462a9b 100%) !important;
	color: #fff !important;
}

/* =====================================================================
 * Sticky header
 * ===================================================================== */
.atb-sticky-yes .atb-table-scroll {
	max-height: 70vh;
	overflow-y: auto;
}

.atb-sticky-yes .atb-table thead .atb-cell {
	position: sticky;
	top: 0;
	z-index: 2;
}

/* =====================================================================
 * Tablet (<= 1024px)
 * ===================================================================== */
@media (max-width: 1024px) {
	/* Force a minimum width so columns don't crush — the wrapper scrolls. */
	.atb-tablet-scroll .atb-table {
		min-width: 720px;
	}

	/* Auto-fit lets the table shrink to the viewport (no forced min-width). */
	.atb-tablet-autofit .atb-table {
		min-width: 0;
	}
}

/* =====================================================================
 * Mobile (<= 767px)
 * ===================================================================== */
@media (max-width: 767px) {
	.atb-mobile-scroll .atb-table {
		min-width: 560px;
	}

	/* Single-value tables (label column + one value) have nothing to scroll
	   to. Forcing 560px only spreads the two columns apart and adds a
	   pointless horizontal scrollbar. Detect them by the absence of a third
	   column and let the table size itself to the viewport instead. */
	.atb-mobile-scroll .atb-table:not(:has([data-atb-col="3"])) {
		min-width: 0;
	}

	/* ---- Stacked card layout ---- */
	.atb-mobile-stack .atb-table,
	.atb-mobile-stack .atb-table tbody,
	.atb-mobile-stack .atb-table tfoot,
	.atb-mobile-stack .atb-table .atb-row,
	.atb-mobile-stack .atb-table .atb-cell {
		display: block;
		width: 100% !important;
	}

	/* The header is conveyed per-cell via data-label, so hide the header row. */
	.atb-mobile-stack .atb-table thead {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
		white-space: nowrap;
	}

	.atb-mobile-stack .atb-table .atb-row {
		margin-bottom: 16px;
		border: 1px solid #e2e8f0;
	}

	.atb-mobile-stack .atb-cell {
		display: flex;
		justify-content: space-between;
		gap: 12px;
		border: 0;
		border-bottom: 1px solid #edf2f7;
	}

	.atb-mobile-stack .atb-cell:last-child {
		border-bottom: 0;
	}

	/* Render the column heading as the row label. */
	.atb-mobile-stack .atb-cell[data-label]::before {
		content: attr(data-label);
		font-weight: 600;
		flex: 0 0 45%;
		text-align: left;
	}

	/* Label-above variant stacks the label over the value. */
	.atb-mobile-stack.atb-stacklabel-above .atb-cell {
		flex-direction: column;
		gap: 2px;
	}

	.atb-mobile-stack.atb-stacklabel-above .atb-cell[data-label]::before {
		flex-basis: auto;
	}

	/* Optionally drop empty cells from the stacked view. */
	.atb-mobile-stack.atb-collapse-empty-yes .atb-cell--empty {
		display: none;
	}
}
