/**
 * Site-wide adaptive layout — forms, tables, toolbars (admin AdminLTE + legacy shell + storefront).
 * Pair with common/js/mobile-ui-layer.js (data-label injection for stack tables).
 */

:root {
	--pc-adaptive-gutter: max(0.75rem, env(safe-area-inset-left, 0px));
	--pc-adaptive-break-md: 767.98px;
	--pc-adaptive-break-lg: 991.98px;
	--pc-adaptive-table-min-w: 640px;
	--pc-adaptive-stack-label: 38%;
}

/* ------------------------------------------------------------------ forms */
.pc-adaptive-form {
	width: 100%;
	min-width: 0;
}

.pc-adaptive-form__row {
	display: grid;
	grid-template-columns: repeat(var(--pc-adaptive-cols, 4), minmax(0, 1fr));
	gap: 0.75rem;
	align-items: end;
}

.pc-adaptive-form__row--labels {
	align-items: end;
	margin-bottom: 0.35rem;
}

.pc-adaptive-form__cell {
	min-width: 0;
}

.pc-adaptive-form__cell--full {
	grid-column: 1 / -1;
}

.pc-adaptive-form__cell--action-spacer {
	visibility: hidden;
	pointer-events: none;
}

.pc-adaptive-form__label {
	display: block;
	font-size: 0.8125rem;
	color: #6c757d;
	line-height: 1.25;
	margin-bottom: 0;
}

.pc-adaptive-form__control,
.pc-adaptive-form .form-control,
.pc-adaptive-form .btn {
	width: 100%;
	max-width: 100%;
	min-width: 0;
}

/* ------------------------------------------------------------------ toolbars */
.pc-adaptive-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	min-width: 0;
}

.pc-adaptive-toolbar__title {
	flex: 1 1 auto;
	min-width: 0;
}

.pc-adaptive-toolbar__actions {
	flex: 0 1 auto;
	min-width: 0;
	margin-left: auto;
}

.pc-adaptive-search {
	width: 100%;
	max-width: 14rem;
	min-width: 0;
}

/* ------------------------------------------------------------------ table wrap (horizontal scroll mode) */
.pc-adaptive-table-wrap,
.table-responsive.pc-adaptive-table-wrap {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	overflow-y: visible;
	-webkit-overflow-scrolling: touch;
}

.pc-adaptive-table {
	width: 100%;
	table-layout: auto;
}

.pc-adaptive-table--scroll {
	min-width: var(--pc-adaptive-table-min-w);
}

.pc-adaptive-table code,
.pc-adaptive-table .text-break-all {
	word-break: break-all;
	overflow-wrap: anywhere;
	white-space: normal;
}

/* ------------------------------------------------------------------ stack mode (mobile cards) */
@media (max-width: 991.98px) {
	.pc-adaptive-form__row {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	.pc-adaptive-form__row .pc-adaptive-form__cell--full,
	.pc-adaptive-form__row .pc-adaptive-form__cell--action {
		grid-column: 1 / -1;
	}

	.pc-adaptive-toolbar__actions {
		flex: 1 1 100%;
		margin-left: 0;
	}

	.pc-adaptive-search,
	.pc-adaptive-toolbar .input-group {
		max-width: 100%;
		width: 100%;
	}

	/* Never squeeze fixed-layout tables — scroll or stack instead */
	table.table-layout-fixed,
	table[style*="table-layout: fixed"],
	table.pc-adaptive-table--stack {
		table-layout: auto !important;
	}

	table.pc-adaptive-table--stack colgroup {
		display: none;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready {
		border-collapse: separate;
		border-spacing: 0;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready thead {
		display: none;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody tr {
		display: block;
		margin: 0 0.65rem 0.75rem;
		padding: 0.35rem 0.5rem 0.5rem;
		border: 1px solid rgba(15, 23, 42, 0.1);
		border-radius: 10px;
		background: var(--bs-body-bg, #fff);
		box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		gap: 0.65rem;
		padding: 0.4rem 0.15rem;
		border: none !important;
		border-bottom: 1px solid rgba(15, 23, 42, 0.06) !important;
		text-align: right !important;
		white-space: normal !important;
		word-break: break-word;
		overflow-wrap: anywhere;
		max-width: none !important;
		width: auto !important;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td:last-child {
		border-bottom: none !important;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td::before {
		content: attr(data-label);
		flex: 0 0 var(--pc-adaptive-stack-label);
		max-width: 42%;
		font-weight: 600;
		font-size: 0.72rem;
		line-height: 1.35;
		text-transform: uppercase;
		letter-spacing: 0.04em;
		color: #64748b;
		text-align: left;
		white-space: normal;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td[data-label=""]::before,
	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td:not([data-label])::before {
		content: none;
	}

	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td > .bl-collapse-body,
	.pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody td > div {
		flex: 1 1 auto;
		min-width: 0;
		text-align: left;
	}

	[data-pc-theme="dark"] .pc-adaptive-table--stack.pc-adaptive-table--stack-ready tbody tr {
		background: #1e293b;
		border-color: rgba(255, 255, 255, 0.08);
	}
}

@media (max-width: 575.98px) {
	.pc-adaptive-form__row {
		grid-template-columns: 1fr;
	}
}

@media (min-width: 992px) {
	.pc-adaptive-table-wrap:not(.pc-adaptive-table-wrap--always-scroll) {
		overflow-x: visible;
	}

	.pc-adaptive-table--scroll {
		min-width: 0;
	}
}

/* ------------------------------------------------------------------ admin shells (AdminLTE + legacy) */
@media (max-width: 991.98px) {
	.content-wrapper,
	.content-wrapper > .content,
	#main-dom-content,
	.pc-content {
		min-width: 0;
		max-width: 100%;
		box-sizing: border-box;
	}

	.content-wrapper > .content {
		padding-left: var(--pc-adaptive-gutter);
		padding-right: var(--pc-adaptive-gutter);
	}

	.content-wrapper .table-responsive:not(.pc-adaptive-table-wrap),
	#main-dom-content .table-responsive:not(.pc-adaptive-table-wrap) {
		overflow-x: auto !important;
		-webkit-overflow-scrolling: touch;
		max-width: 100%;
	}

	.content-wrapper .table-responsive:not(.pc-adaptive-table-wrap) > table.table,
	#main-dom-content .table-responsive:not(.pc-adaptive-table-wrap) > table.table {
		table-layout: auto !important;
		min-width: var(--pc-adaptive-table-min-w);
		width: max-content;
		max-width: none;
	}

	.content-wrapper .table-responsive:not(.pc-adaptive-table-wrap) > table.table thead th,
	.content-wrapper .table-responsive:not(.pc-adaptive-table-wrap) > table.table tbody td,
	#main-dom-content .table-responsive:not(.pc-adaptive-table-wrap) > table.table thead th,
	#main-dom-content .table-responsive:not(.pc-adaptive-table-wrap) > table.table tbody td {
		white-space: nowrap;
		word-break: normal;
		overflow-wrap: normal;
	}
}
