/**
 * Bulk Add To Cart — front end styles.
 *
 * Theme first. Nothing here sets a font, and no text colour is set, so text
 * inherits the theme's typography. Row shading, borders and the quantity /
 * option boxes are mixed from the theme's own text colour (currentColor), so
 * they suit light and dark themes alike without guessing. The button uses the
 * theme's WooCommerce button styling unless a custom button is chosen.
 *
 * Anything set on the Styling tab (WooCommerce → Bulk add to cart) is printed after
 * this file and overrides the matching token or rule. Every rule is scoped
 * under .bacw so nothing leaks into the rest of the site.
 */

.bacw {
	--bacw-radius: 6px;
	--bacw-gap: 1rem;
	--bacw-columns: 3;
	--bacw-row-gap: 0.6rem;
	--bacw-row-pad: 0.9rem;
	--bacw-image-size: 64px;
	--bacw-select-width: 11rem; /* Every option dropdown is this wide (full width on phones). */
	--bacw-success: #1f8a55; /* Readable on both light and dark themes. */
	--bacw-error: #d63638;

	/* Derived from the theme's text colour. */
	--bacw-soft: color-mix(in srgb, currentColor 68%, transparent);
	--bacw-border: color-mix(in srgb, currentColor 14%, transparent);
	--bacw-border-strong: color-mix(in srgb, currentColor 28%, transparent);
	--bacw-row-bg: color-mix(in srgb, currentColor 4%, transparent);
	/* Hover is a slightly deeper shade of the row colour, whatever it is set to. */
	--bacw-row-bg-hover: color-mix(in srgb, currentColor 5%, var(--bacw-row-bg));
	--bacw-control-bg: color-mix(in srgb, currentColor 10%, transparent);
	--bacw-footer-bg: var(--bacw-row-bg);

	box-sizing: border-box;
	margin: 1.5rem 0;
	max-width: 100%;
}

/* Browsers without color-mix() get fixed, light-theme values instead. */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
	.bacw {
		--bacw-soft: rgba(0, 0, 0, 0.62);
		--bacw-border: rgba(0, 0, 0, 0.12);
		--bacw-border-strong: rgba(0, 0, 0, 0.24);
		--bacw-row-bg: rgba(0, 0, 0, 0.04);
		--bacw-row-bg-hover: rgba(0, 0, 0, 0.065);
		--bacw-control-bg: rgba(0, 0, 0, 0.1);
	}
}

.bacw *,
.bacw *::before,
.bacw *::after {
	box-sizing: inherit;
}

/* Outer box ------------------------------------------------------------- */

.bacw .bacw__form {
	border-radius: var(--bacw-radius);
	margin: 0;
	padding: clamp(0.85rem, 2.5vw, 1.35rem);
}

.bacw--box-border .bacw__form {
	border: 1px solid var(--bacw-border);
}

.bacw--box-none .bacw__form {
	padding: 0;
}

/* Header ---------------------------------------------------------------- */

/* A real heading element, so the theme's heading font, colour and weight apply. */
.bacw .bacw__heading {
	line-height: 1.25;
	margin: 0 0 0.4rem;
	padding: 0;
}

.bacw .bacw__intro {
	color: var(--bacw-soft);
	margin: 0 0 1rem;
}

.bacw .bacw__intro > p:last-child {
	margin-bottom: 0;
}

/* Column grid ----------------------------------------------------------- */

/*
 * Rows and the header share one column template, so prices and quantities
 * line up down the list.
 */
.bacw .bacw__head,
.bacw--table .bacw-item {
	align-items: center;
	display: grid;
	gap: 0 0.9rem;
	grid-template-columns: minmax(0, 1fr) 5.5rem;
}

.bacw--table.bacw--has-price .bacw__head,
.bacw--table.bacw--has-price .bacw-item {
	grid-template-columns: minmax(0, 1fr) 9.5rem 5.5rem;
}

.bacw .bacw__head {
	border-bottom: 1px solid var(--bacw-border-strong);
	font-size: 0.82em;
	font-weight: 600;
	letter-spacing: 0.01em;
	opacity: 0.85;
	padding: 0 var(--bacw-row-pad) 0.5rem;
}

.bacw .bacw__head-cell + .bacw__head-cell {
	border-left: 1px solid var(--bacw-border);
	padding-left: 0.9rem;
	text-align: right;
}

/* Rows ------------------------------------------------------------------ */

.bacw .bacw__items {
	display: flex;
	flex-direction: column;
	gap: var(--bacw-row-gap);
	margin-top: var(--bacw-row-gap);
}

.bacw .bacw-item {
	background-color: var(--bacw-row-bg);
	border-radius: var(--bacw-radius);
	padding: var(--bacw-row-pad);
	transition: background-color 120ms ease, opacity 120ms ease;
}

.bacw--table .bacw-item:hover {
	background-color: var(--bacw-row-bg-hover);
}

.bacw .bacw-item--off,
.bacw .bacw-item--unavailable {
	opacity: 0.5;
}

.bacw .bacw-item__main {
	align-items: center;
	display: flex;
	gap: 0.75rem;
	min-width: 0;
}

.bacw .bacw-item__select {
	flex: 0 0 auto;
}

.bacw .bacw-item__checkbox {
	cursor: pointer;
	display: inline-flex;
	margin: 0;
}

.bacw .bacw-item__checkbox input {
	height: 1.15em;
	margin: 0;
	width: 1.15em;
}

.bacw .bacw-item__media {
	flex: 0 0 auto;
	line-height: 0;
	width: var(--bacw-image-size);
}

.bacw .bacw-item__media img {
	border: 1px solid var(--bacw-border);
	border-radius: calc(var(--bacw-radius) - 2px);
	display: block;
	height: auto;
	max-width: 100%;
	width: 100%;
}

.bacw .bacw-item__body {
	flex: 1 1 auto;
	min-width: 0;
}

.bacw .bacw-item__title {
	color: inherit;
	display: inline-block;
	font-weight: 600;
	line-height: 1.25;
	text-decoration: none;
}

.bacw .bacw-item__title:hover,
.bacw .bacw-item__title:focus {
	text-decoration: underline;
}

.bacw .bacw-item__note {
	color: var(--bacw-soft);
	font-size: 0.9em;
	margin: 0.15rem 0 0;
}

.bacw .bacw-item__preset {
	color: var(--bacw-soft);
	font-size: 0.9em;
	list-style: none;
	margin: 0.25rem 0 0;
	padding: 0;
}

.bacw .bacw-item__preset li {
	display: inline;
	margin: 0;
}

.bacw .bacw-item__preset li + li::before {
	content: ", ";
}

.bacw .bacw-item__preset span::after {
	content: ": ";
}

/* Option selects -------------------------------------------------------- */

.bacw .bacw-item__options {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-top: 0.4rem;
}

/*
 * Every dropdown is the same width, whatever its options say. Browsers size
 * a dropdown to its longest option by default, so "SML — out of stock" made
 * some wider than others. Long names are cut off with an ellipsis when
 * closed and shown in full when the dropdown is opened.
 */
.bacw .bacw-item__option {
	display: flex;
	flex: 0 1 var(--bacw-select-width);
	flex-direction: column;
	gap: 0.15rem;
	margin: 0;
	max-width: 100%;
	min-width: 0;
}

.bacw .bacw-item__option-label {
	display: block;
	font-size: 0.78em;
	font-weight: 600;
	line-height: 1.3;
	opacity: 0.85;
}

.bacw .bacw-item__option-label:empty {
	display: none;
}

.bacw .bacw-item__option select {
	background-color: var(--bacw-control-bg);
	border: 1px solid var(--bacw-border-strong);
	border-radius: calc(var(--bacw-radius) - 2px);
	box-sizing: border-box;
	color: inherit;
	font: inherit;
	font-size: 0.92em;
	margin: 0;
	max-width: 100%;
	min-width: 0;
	overflow: hidden;
	padding: 0.35em 0.5em;
	text-overflow: ellipsis;
	white-space: nowrap;
	width: 100%;
}

.bacw .bacw-item__stock {
	font-size: 0.85em;
	margin-top: 0.3rem;
}

.bacw .bacw-item__stock:empty {
	display: none;
}

.bacw .bacw-item__stock p,
.bacw .bacw-item__stock .stock {
	margin: 0;
}

/* Price and quantity cells ---------------------------------------------- */

.bacw--table .bacw-item__price,
.bacw--table .bacw-item__qty {
	align-items: center;
	align-self: stretch;
	border-left: 1px solid var(--bacw-border);
	display: flex;
	justify-content: flex-end;
	padding-left: 0.9rem;
	text-align: right;
}

.bacw .bacw-item__price {
	font-weight: 600;
	min-width: 0;
	overflow-wrap: anywhere;
}

/*
 * Price ranges ("R170,00 – R200,00") can be wider than the column. Let them
 * wrap onto a second line inside the cell instead of spilling over the divider.
 */
.bacw--table .bacw-item__price {
	align-content: center;
	column-gap: 0.25em;
	flex-wrap: wrap;
	line-height: 1.3;
}

.bacw .bacw-item__price del {
	font-weight: 400;
	opacity: 0.6;
}

.bacw .bacw-item__price ins {
	text-decoration: none;
}

/* Line total with the single price underneath, once the quantity is above one. */
.bacw .bacw-item__price-stack {
	align-items: flex-end;
	display: inline-flex;
	flex-direction: column;
	gap: 0.1rem;
	max-width: 100%;
	text-align: right;
}

.bacw .bacw-item__unit {
	color: var(--bacw-soft);
	font-size: 0.78em;
	font-weight: 400;
}

.bacw .bacw-item__unit del {
	opacity: 0.8;
}

.bacw--grid .bacw-item__price-stack {
	align-items: flex-start;
	text-align: left;
}

.bacw .bacw-item__qty label {
	margin: 0;
}

.bacw .bacw-item__qty input {
	background-color: var(--bacw-control-bg);
	border: 1px solid var(--bacw-border-strong);
	border-radius: calc(var(--bacw-radius) - 2px);
	color: inherit;
	font: inherit;
	padding: 0.35em 0.4em;
	text-align: center;
	width: 4.25rem;
}

.bacw .bacw-item__qty-fixed {
	background-color: var(--bacw-control-bg);
	border-radius: calc(var(--bacw-radius) - 2px);
	color: var(--bacw-soft);
	display: inline-block;
	padding: 0.35em 0.6em;
}

/* Footer ---------------------------------------------------------------- */

.bacw .bacw__footer {
	align-items: center;
	background-color: var(--bacw-footer-bg);
	border-radius: var(--bacw-radius);
	display: flex;
	flex-wrap: wrap;
	gap: var(--bacw-gap);
	justify-content: space-between;
	margin-top: var(--bacw-row-gap);
	padding: var(--bacw-row-pad);
}

.bacw .bacw__total {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin: 0;
}

.bacw .bacw__total-label {
	font-weight: 600;
	opacity: 0.85;
}

.bacw .bacw__total-value {
	font-weight: 600;
}

.bacw .bacw__summary {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	min-width: 0;
}

.bacw .bacw__total-count {
	color: var(--bacw-soft);
	font-weight: 400;
}

.bacw .bacw__total-note {
	color: var(--bacw-soft);
	font-size: 0.82em;
	margin: 0;
}

.bacw .bacw__total-note[hidden] {
	display: none;
}

/* Button ---------------------------------------------------------------- */

/* Theme mode: the theme's WooCommerce button styles do the work. */
.bacw .bacw__button {
	cursor: pointer;
	margin: 0;
}

/* The label always follows the button's own text colour. */
.bacw .bacw__button .bacw__button-label {
	color: inherit;
}

/*
 * Safety net: if a theme styles the button's background and text colour from
 * two different places and they end up too similar, frontend.js picks black
 * or white for the resting state. Hover and focus are left to the theme.
 */
.bacw .bacw__button[data-bacw-fix-color]:not(.bacw__button--custom):not(:hover):not(:focus-visible),
.bacw .bacw__button[data-bacw-fix-color]:not(.bacw__button--custom):not(:hover):not(:focus-visible) .bacw__button-label {
	color: var(--bacw-fix-color) !important;
	-webkit-text-fill-color: var(--bacw-fix-color) !important;
}

/* Custom mode: colours come from the Styling screen. */
.bacw .bacw__button.bacw__button--custom {
	-webkit-appearance: none;
	appearance: none;
	background-color: var(--bacw-button-bg, #1f2933);
	border: 0;
	border-radius: var(--bacw-button-radius, var(--bacw-radius));
	box-shadow: none;
	color: var(--bacw-button-text, #ffffff);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	padding: 0.7em 1.4em;
	text-decoration: none;
	text-shadow: none;
	transition: background-color 120ms ease, color 120ms ease;
}

.bacw .bacw__button.bacw__button--custom:hover,
.bacw .bacw__button.bacw__button--custom:focus-visible {
	background-color: var(--bacw-button-bg-hover, color-mix(in srgb, var(--bacw-button-bg, #1f2933) 82%, #000000));
	color: var(--bacw-button-text-hover, var(--bacw-button-text, #ffffff));
}

.bacw .bacw__button:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.bacw .bacw__button[disabled] {
	cursor: default;
	opacity: 0.6;
}

/* Messages -------------------------------------------------------------- */

.bacw .bacw__messages:empty {
	display: none;
}

.bacw .bacw__messages {
	margin-top: 0.9rem;
}

.bacw .bacw__message {
	border-left: 3px solid currentColor;
	font-size: 0.93em;
	margin: 0 0 0.4rem;
	padding: 0.45rem 0.7rem;
}

.bacw .bacw__message:last-child {
	margin-bottom: 0;
}

.bacw .bacw__message--success {
	background: color-mix(in srgb, var(--bacw-success) 8%, transparent);
	color: var(--bacw-success);
}

.bacw .bacw__message--error {
	background: color-mix(in srgb, var(--bacw-error) 8%, transparent);
	color: var(--bacw-error);
}

/* Card layout ----------------------------------------------------------- */

.bacw--grid .bacw__items {
	display: grid;
	gap: var(--bacw-gap);
	grid-template-columns: repeat(var(--bacw-columns), minmax(0, 1fr));
}

.bacw--grid .bacw-item {
	border: 1px solid var(--bacw-border);
	display: flex;
	flex-direction: column;
	gap: 0.65rem;
	position: relative;
}

.bacw--grid .bacw-item__main {
	align-items: flex-start;
	flex-direction: column;
	gap: 0.6rem;
}

.bacw--grid .bacw-item__select {
	left: calc(var(--bacw-row-pad) + 0.45rem);
	position: absolute;
	top: calc(var(--bacw-row-pad) + 0.45rem);
	z-index: 1;
}

.bacw--grid .bacw-item__checkbox input {
	background: #ffffff;
}

.bacw--grid .bacw-item__media,
.bacw--grid .bacw-item__body {
	width: 100%;
}

.bacw--grid .bacw-item__price,
.bacw--grid .bacw-item__qty {
	border-top: 1px solid var(--bacw-border);
	padding-top: 0.55rem;
	text-align: left;
	width: 100%;
}

.bacw--grid .bacw-item__price + .bacw-item__qty {
	border-top: 0;
	padding-top: 0;
}

.bacw--grid .bacw-item__price {
	margin-top: auto;
}

.bacw--grid .bacw-item__option {
	flex: 1 1 100%;
}

/* Small screens --------------------------------------------------------- */

@media (max-width: 782px) {
	.bacw--grid .bacw__items {
		grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
	}
}

@media (max-width: 520px) {
	.bacw .bacw__head {
		display: none;
	}

	.bacw--table .bacw-item,
	.bacw--table.bacw--has-price .bacw-item {
		gap: 0.5rem 0; /* Zero column gap so the two rules read as one. */
		grid-template-columns: minmax(0, 1fr) auto;
	}

	.bacw--table .bacw-item__main {
		grid-column: 1 / -1;
	}

	/* A little more room for the fields. */
	.bacw {
		--bacw-row-pad: 0.75rem;
		--bacw-image-size: 48px;
	}

	.bacw .bacw-item__main {
		align-items: flex-start;
		gap: 0.6rem;
	}

	.bacw .bacw-item__select {
		padding-top: 0.15rem;
	}

	/* Dropdowns fill the row, one under another. */
	.bacw .bacw-item__options {
		width: 100%;
	}

	.bacw .bacw-item__option {
		flex: 1 1 100%;
	}

	/*
	 * 16px text stops iPhones zooming the page when a field is tapped, and
	 * 44px is a comfortable finger-sized target.
	 */
	.bacw .bacw-item__option select,
	.bacw .bacw-item__qty input {
		font-size: 16px;
		min-height: 44px;
	}

	.bacw--table .bacw-item__price,
	.bacw--table .bacw-item__qty {
		border-left: 0;
		border-top: 1px solid var(--bacw-border);
		padding: 0.5rem 0 0;
	}

	.bacw--table .bacw-item__price {
		justify-content: flex-start;
		text-align: left;
	}

	.bacw--table .bacw-item__price-stack {
		align-items: flex-start;
		text-align: left;
	}

	.bacw .bacw__footer {
		align-items: stretch;
		flex-direction: column;
	}

	.bacw .bacw__button {
		width: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.bacw * {
		transition: none !important;
	}
}

.bacw-admin-notice {
	background: #fff3cd;
	border-left: 3px solid #b8860b;
	color: #664d03;
	padding: 0.6rem 0.8rem;
}
