/**
 * Hamper lines in the cart and checkout.
 *
 * The container and its components are separate rows — they have to be, so each
 * is taxed at its own rate — so the styling is what makes them read as one
 * purchase rather than a basket someone filled by hand.
 *
 * Two sets of selectors: the store renders its cart with the WooCommerce Cart
 * block, and the classic shortcode markup is kept in case a page still uses it.
 * The `hbh-line` classes are put on the rows by assets/cart-blocks.js in the
 * first case and by HBH_Cart::cart_item_class() in the second.
 */

:root {
	--hbh-line-accent: var(--pewter-blue, #89a3b5);
	--hbh-line-rule: rgba(137, 163, 181, 0.35);
}

/* -------------------------------------------------------------------------
 * Block cart and checkout
 *
 * The block draws its rows with flexbox, not a real table, and sizes the
 * thumbnail cell with `width: 150px; aspect-ratio: 1/1` — so the row's height
 * follows the image's *width*. Shrinking the picture is therefore what makes a
 * component row short, and the selectors below carry an extra `td` because the
 * block's own rules would otherwise win on specificity.
 * ---------------------------------------------------------------------- */

.wc-block-cart-items__row.hbh-line--parent > td {
	border-top: 2px solid var(--hbh-line-accent);
	padding-top: 18px;
}

.wc-block-cart-items__row.hbh-line--parent .wc-block-components-product-name {
	font-weight: 600;
}

.wc-block-cart-items__row.hbh-line--child {
	margin-bottom: 0;
}

.wc-block-cart-items__row.hbh-line--child > td {
	border-top: 1px solid var(--hbh-line-rule);
	padding-top: 4px;
	padding-bottom: 4px;
}

/* Halves the row height, by way of the aspect ratio described above. */
.wc-block-cart-items__row.hbh-line--child td.wc-block-cart-item__image,
.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__image {
	width: 44px;
	min-width: 44px;
	height: auto;
	aspect-ratio: auto;
	padding-left: 18px;
}

.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__image img {
	width: 44px;
	max-width: 44px;
	height: auto;
	opacity: 0.85;
}

/* Quantity and name on one line, quantity first, so a component reads the way
   the summary wrote it: "2 × Extra Cherry Jam". */
.wc-block-cart-items__row.hbh-line--child td.wc-block-cart-item__product .wc-block-cart-item__wrap {
	display: flex;
	flex-direction: row;
	flex-wrap: nowrap;
	align-items: baseline;
	gap: 10px;
	position: relative;
	padding-left: 16px;
}

.wc-block-cart-items__row.hbh-line--child td.wc-block-cart-item__product .wc-block-cart-item__quantity {
	order: -1;
	flex: 0 0 auto;
	margin: 0;
}

.wc-block-cart-items__row.hbh-line--child .wc-block-components-product-name {
	flex: 1 1 auto;
	font-size: 0.92em;
	line-height: 1.4;
	color: var(--grey-text, #4e4e4e);
}

/* Marks the row as belonging to the hamper above it. Drawn in CSS rather than
   folded into the name, so screen readers are not made to announce it. */
.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__wrap::before {
	content: "\21B3";
	position: absolute;
	left: 0;
	top: 0;
	line-height: 1.4;
	color: var(--hbh-line-accent);
}

/* The block reserves space for a unit price, a description and a sale badge
   that components never carry; collapsed, the row closes up to its own text. */
.wc-block-cart-items__row.hbh-line--child .wc-block-components-product-metadata,
.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__prices {
	display: none;
}

/* The stepper is suppressed server-side, which leaves a read-only field. This
   stops it sitting in the space an editable input used to occupy. */
.wc-block-cart-items__row.hbh-line--child .wc-block-components-quantity-selector {
	min-width: 0;
	width: auto;
	height: auto;
	border: 0;
	background: none;
	margin: 0;
}

.wc-block-cart-items__row.hbh-line--child .wc-block-components-quantity-selector__input {
	width: 2em;
	min-width: 0;
	padding: 0;
	text-align: left;
	font-size: 0.9em;
	color: var(--grey-text, #4e4e4e);
	pointer-events: none;
}

/* -------------------------------------------------------------------------
 * Classic cart and checkout
 * ---------------------------------------------------------------------- */

.woocommerce-cart-form .hbh-line--parent td,
.woocommerce-checkout-review-order-table .hbh-line--parent td {
	border-top: 2px solid var(--hbh-line-accent);
	padding-top: 14px;
}

.woocommerce-cart-form .hbh-line--parent .product-name,
.woocommerce-checkout-review-order-table .hbh-line--parent .product-name {
	font-weight: 600;
}

.woocommerce-cart-form .hbh-line--child td,
.woocommerce-checkout-review-order-table .hbh-line--child td {
	border-top: 1px solid var(--hbh-line-rule);
	padding-top: 6px;
	padding-bottom: 6px;
}

.woocommerce-cart-form .hbh-line--child .product-name,
.woocommerce-checkout-review-order-table .hbh-line--child .product-name {
	padding-left: 22px;
	font-size: 0.92em;
	color: var(--grey-text, #4e4e4e);
}

.hbh-child-marker {
	color: var(--hbh-line-accent);
	margin-right: 4px;
}

.hbh-line--child .product-remove {
	visibility: hidden;
}

.hbh-qty-fixed {
	display: inline-block;
	min-width: 2em;
	text-align: center;
	color: var(--grey-text, #4e4e4e);
}

.hbh-line--child .product-thumbnail img {
	max-width: 38px;
	opacity: 0.75;
}

/* -------------------------------------------------------------------------
 * Small screens
 *
 * Below 768px the block stops laying a row out side by side and stacks its
 * three cells instead — picture, then details, then price. For a container
 * that is right; for its components it is not. Each one became 162px tall, so
 * a single hamper ran past two screens and a fifteen-item one would have run
 * past five, which stops it reading as one purchase at all.
 *
 * The picture is not what makes them tall: the block already shrinks it to
 * 28px here. It is the stacking. So components go back to a single line, and
 * the widths the block assigns for a stacked layout — a 319px quantity cell, a
 * full-width price with vertical margins — have to be undone, or the row runs
 * off the side of the screen.
 *
 * The `!important` markers are not decoration: the block's own mobile rules
 * are more specific than these, and without them the layout silently reverts
 * to the stacked one.
 * ---------------------------------------------------------------------- */

@media (max-width: 768px) {

	.wc-block-cart-items__row.hbh-line--child {
		flex-direction: row !important;
		flex-wrap: nowrap;
		align-items: center;
		gap: 8px;
		padding: 6px 0 !important;
	}

	.wc-block-cart-items__row.hbh-line--child > td.wc-block-cart-item__image {
		flex: 0 0 32px;
		width: 32px !important;
		min-width: 32px;
		height: auto;
		aspect-ratio: auto;
		padding: 0 0 0 12px;
	}

	.wc-block-cart-items__row.hbh-line--child > td.wc-block-cart-item__image img {
		width: 32px !important;
		max-width: 32px;
		height: auto;
	}

	.wc-block-cart-items__row.hbh-line--child > td.wc-block-cart-item__product {
		flex: 1 1 auto;
		width: auto !important;
		min-width: 0;
		padding: 0;
	}

	.wc-block-cart-items__row.hbh-line--child > td.wc-block-cart-item__total {
		flex: 0 0 auto;
		width: auto !important;
		padding: 0;
		text-align: right;
	}

	.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__wrap {
		flex-direction: row !important;
		align-items: baseline;
		gap: 8px;
		padding: 0 0 0 12px;
	}

	.wc-block-cart-items__row.hbh-line--child .wc-block-components-product-name {
		flex: 1 1 auto;
		min-width: 0;
	}

	/* Widths the block assigns for the stacked layout, which overflow the row
	   once the cells sit side by side again. */
	.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__quantity {
		width: auto !important;
		padding: 0 !important;
	}

	.wc-block-cart-items__row.hbh-line--child .wc-block-components-product-price,
	.wc-block-cart-items__row.hbh-line--child .wc-block-cart-item__total-price-and-sale-badge-wrapper {
		width: auto !important;
		margin: 0 !important;
	}

	/* Classic checkout keeps its table layout; only the indent needs easing. */
	.woocommerce-cart-form .hbh-line--child .product-name,
	.woocommerce-checkout-review-order-table .hbh-line--child .product-name {
		padding-left: 14px;
	}

	.hbh-line--child .product-thumbnail img {
		max-width: 28px;
	}
}
