/*
 * Theme 1.0.38: add-to-cart row on every product page (simple, variable, external, grouped; with or without the
 * "Limited to one per order." note; sale price; stock notice).
 *
 * Root cause of the squeezed note / giant button: WooCommerce's add-to-cart-form block ships
 *   .wp-block-woocommerce-add-to-cart-form .variations_button,
 *   .wp-block-woocommerce-add-to-cart-form form.cart { display:grid; grid-auto-flow:column; grid-template-columns:min-content auto auto }
 * which beats the theme's flex row. The first grid column is min-content, so .quantity (the visually-hidden input plus
 * the note) collapsed to one character wide and the row (and the stretched button) grew to 400-600px tall.
 * Fix: flex row again, the locked-quantity note takes its own full-width line above the button, the button has a
 * normal height, and on phones the button is full width. Kill switch: add_filter( 'tsd_v1038_cart_layout', '__return_false' ).
 */

/* Variable form: the outer form is a plain block (table of selects, then price/stock/button). */
body.tsd-v1038-cart .wp-block-woocommerce-add-to-cart-form form.variations_form.cart,
body.tsd-v1038-cart form.variations_form.cart {
	display: block;
	grid-template-columns: none;
	grid-auto-flow: row;
}

/* The button row (variable) and the simple/external/grouped form. */
body.tsd-v1038-cart .wp-block-woocommerce-add-to-cart-form .woocommerce-variation-add-to-cart.variations_button,
body.tsd-v1038-cart .wp-block-woocommerce-add-to-cart-form form.cart:not(.variations_form),
body.tsd-v1038-cart .woocommerce-variation-add-to-cart,
body.tsd-v1038-cart form.cart:not(.variations_form) {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-start;
	gap: .75rem;
	grid-template-columns: none;
	grid-auto-flow: row;
	width: 100%;
	max-width: 100%;
	height: auto;
}
/* Grouped products keep their table full width. */
body.tsd-v1038-cart form.cart.grouped_form > table,
body.tsd-v1038-cart form.cart .group_table { flex: 1 1 100%; width: 100%; }

/* Normal quantity box: its natural width, never squeezed. */
body.tsd-v1038-cart .woocommerce-variation-add-to-cart .quantity,
body.tsd-v1038-cart form.cart .quantity {
	flex: 0 0 auto;
	min-width: 0;
	width: auto;
	margin: 0;
	float: none;
}

/* Locked quantity (max 1 / sold individually): the note gets its own full-width line ABOVE the button. */
body.tsd-v1038-cart .quantity:has(.tsd-qty-locked),
body.tsd-v1038-cart .quantity:has(.qty[max="1"]),
body.tsd-v1038-cart form.cart .quantity:has(.tsd-qty-locked),
body.tsd-v1038-cart form.cart .quantity:has(.qty[max="1"]) {
	flex: 1 1 100%;
	width: 100%;
	max-width: 100%;
	display: flex;
	align-items: center;
	height: auto;
	min-height: 0;
	order: 0;
}
body.tsd-v1038-cart .tsd-qty-note {
	white-space: normal;
	word-break: normal;
	overflow-wrap: normal;
	writing-mode: horizontal-tb;
	width: auto;
	min-width: 0;
	max-width: 100%;
	flex: 1 1 auto;
	line-height: 1.4;
	font-size: .9rem;
}
body.tsd-v1038-cart .quantity:has(.tsd-qty-locked) .tsd-qty-note,
body.tsd-v1038-cart .quantity:has(.qty[max="1"]) .tsd-qty-note {
	display: inline-flex;
	align-items: center;
	gap: .45rem;
	padding: .45rem .75rem;
	border-left: 3px solid var(--tt-gold, #ffb81c);
	background: rgba(255, 184, 28, .1);
	color: #2b2b2b;
	border-radius: 0 4px 4px 0;
}
/* Sold-individually products print the quantity as a hidden input: the wrapper must not take space. */
body.tsd-v1038-cart .quantity:has(input.qty[type="hidden"]):not(:has(.tsd-qty-note)) { display: none; }
/* WooCommerce's variation script hides .quantity (inline display:none) for sold-individually variations, which also
   hid the "Limited to one per order." note. Keep the note visible; the hidden input itself stays hidden. */
body.tsd-v1038-cart .variations_button .quantity[style*="none"]:has(.tsd-qty-locked) { display: flex !important; }

/* Button: normal size, never stretched by a tall neighbour. */
body.tsd-v1038-cart .single_add_to_cart_button,
body.tsd-v1038-cart form.cart .button.alt {
	flex: 0 1 auto;
	min-width: min(100%, 14rem);
	width: auto;
	max-width: 100%;
	height: auto;
	min-height: 3rem;
	align-self: center;
	white-space: normal;
	line-height: 1.2;
	padding: .85rem 1.6rem;
}
/* With a visible quantity box the button fills the rest of the row (as before 1.0.32). */
body.tsd-v1038-cart .woocommerce-variation-add-to-cart .quantity:not(:has(.tsd-qty-locked)):not(:has(.qty[max="1"])):not(:has(input.qty[type="hidden"])) ~ .single_add_to_cart_button,
body.tsd-v1038-cart form.cart .quantity:not(:has(.tsd-qty-locked)):not(:has(.qty[max="1"])):not(:has(input.qty[type="hidden"])) ~ .single_add_to_cart_button {
	flex: 1 1 12rem;
	max-width: 24rem;
}

/* Price + stock notice above the button stay on their own lines with a little air. */
body.tsd-v1038-cart .woocommerce-variation.single_variation { margin: .5rem 0 .75rem; }
body.tsd-v1038-cart .woocommerce-variation-price .price { display: block; margin: 0 0 .25rem; }
body.tsd-v1038-cart .woocommerce-variation-availability .stock,
body.tsd-v1038-cart .tt-product__buy .stock,
body.tsd-v1038-cart .product .summary .stock { display: block; margin: .15rem 0 .25rem; font-weight: 700; font-size: .9rem; }
body.tsd-v1038-cart .woocommerce-variation-description a { text-decoration: underline; word-break: break-all; }

/* Phones: everything stacks, button full width. */
@media (max-width: 600px) {
	body.tsd-v1038-cart .single_add_to_cart_button,
	body.tsd-v1038-cart form.cart .button.alt,
	body.tsd-v1038-cart .woocommerce-variation-add-to-cart .quantity:not(:has(.tsd-qty-locked)) ~ .single_add_to_cart_button,
	body.tsd-v1038-cart form.cart .quantity:not(:has(.tsd-qty-locked)) ~ .single_add_to_cart_button {
		flex: 1 1 100%;
		width: 100%;
		max-width: 100%;
		min-width: 0;
	}
	body.tsd-v1038-cart .quantity:has(.tsd-qty-locked) .tsd-qty-note,
	body.tsd-v1038-cart .quantity:has(.qty[max="1"]) .tsd-qty-note { width: 100%; }
	body.tsd-v1038-cart .variations_form select { max-width: 100%; }
}
