/**
 * Bolt checkout — hide the billing / shipping form while Bolt is the chosen method.
 *
 * The fields are HIDDEN, never removed: a hidden input still posts its value, and
 * Bolt needs them present in the serialized checkout form. Validation is dropped
 * separately and only for Bolt, server-side, by
 * ae_bolt_relax_checkout_field_requirements() in woocommerce-overwrite.php.
 *
 * Anchored on body.ae-bolt-checkout, set by ae_bolt_body_class() on the server and
 * kept in sync by assets/js/checkout-bolt.js. It used to be anchored on
 * form.checkout.ae-bolt-active with the rows addressed via #customer_details, but
 * that assumed the fields sit inside that wrapper — which does not hold across every
 * version of this theme's checkout markup, and left the billing fields visible. The
 * selectors below use only the wrapper classes WooCommerce's own form-billing.php and
 * form-shipping.php always emit.
 *
 * !important throughout because the theme's checkout grid styles these same rows with
 * !important (assets/css/theme.css ~5834) and there is no value in a specificity race.
 *
 * ONE row is deliberately left visible: the billing email. Bolt's
 * prepare_checkout_address_data() runs is_email() on it and refuses to build a cart
 * without a valid value, so it is the only detail the customer must still give us.
 */

/* Hidden until Bolt is the chosen method. Also the state a no-JS visitor with
   another gateway selected sees: the form stays fully usable. */
.ae-bolt-notice {
	display: none;
}

body.ae-bolt-checkout .ae-bolt-notice,
form.checkout.ae-bolt-active .ae-bolt-notice {
	display: block;
	max-width: 520px;
	margin: 0 0 8px;
	padding: 18px 20px;
	border: 1px solid #e0e0e0;
	border-radius: 10px;
	background: #fafafa;
}

.ae-bolt-notice__heading {
	margin: 0 0 8px;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.35;
	color: #202020;
}

.ae-bolt-notice__text {
	margin: 0;
	font-size: 14px;
	line-height: 1.5;
	color: #555;
}

/* Hide every address row, plus the headings, the shipping block, the account and
 * additional-field blocks, the ship-to-different-address toggle and the privacy text.
 *
 * The billing rows are hidden individually rather than by hiding
 * .woocommerce-billing-fields, because the email row is a DESCENDANT of it and
 * display:none on an ancestor cannot be undone by a child. The shipping block holds
 * nothing we need to keep, so that one is hidden wholesale. */
body.ae-bolt-checkout .woocommerce-billing-fields h3,
body.ae-bolt-checkout .woocommerce-billing-fields .form-row,
body.ae-bolt-checkout .woocommerce-billing-fields__field-wrapper .form-row,
body.ae-bolt-checkout .woocommerce-shipping-fields,
body.ae-bolt-checkout .woocommerce-account-fields,
body.ae-bolt-checkout .woocommerce-additional-fields,
body.ae-bolt-checkout .woocommerce-privacy-policy-text,
body.ae-bolt-checkout #ship-to-different-address,
body.ae-bolt-checkout #customer_details h3,
body.ae-bolt-checkout #customer_details .form-row {
	display: none !important;
}

/* The one field Bolt cannot do without. Listed after the hiding rules and with
   !important so it wins whichever of them matched. */
body.ae-bolt-checkout #billing_email_field,
body.ae-bolt-checkout .woocommerce-billing-fields #billing_email_field,
body.ae-bolt-checkout .woocommerce-billing-fields__field-wrapper #billing_email_field {
	display: block !important;
	grid-column: 1 / -1 !important;
	width: 100% !important;
	max-width: 520px !important;
	margin: 0 0 18px !important;
	padding: 0 !important;
	float: none !important;
}

/* Collapse the space the hidden rows used to occupy. */
body.ae-bolt-checkout #customer_details .col-1,
body.ae-bolt-checkout #customer_details .col-2 {
	margin: 0;
	padding: 0;
}

/* No required marker on the terms row while Bolt is active — the checkbox itself is
   removed server-side by ae_bolt_disable_terms_checkbox(), this covers any other
   terms row a plugin renders. */
body.ae-bolt-checkout .woocommerce-terms-and-conditions-wrapper abbr.required,
body.ae-bolt-checkout .woocommerce-terms-and-conditions-wrapper .required,
form.checkout.ae-bolt-active .woocommerce-terms-and-conditions-wrapper abbr.required,
form.checkout.ae-bolt-active .woocommerce-terms-and-conditions-wrapper .required {
	display: none !important;
}

/* The CART-type popup collects everything, email included, so nothing needs to stay
   visible. Must come after the email un-hide rule above to win. */
body.ae-bolt-hide-all #billing_email_field,
body.ae-bolt-hide-all .woocommerce-billing-fields #billing_email_field,
body.ae-bolt-hide-all .woocommerce-billing-fields__field-wrapper #billing_email_field {
	display: none !important;
}

/* ===========================================================================
   Custom Bolt popup button
   ---------------------------------------------------------------------------
   .ae-bolt-pay is our own styled face with Bolt's real .bolt-checkout-button
   stretched transparently over it, so the click Bolt handles is the one the customer
   sees while the visible styling is entirely ours. Same technique the cart page uses
   (.cmc-bolt-wrap / .cmc-bolt-real, woocommerce-overwrite.php ~1250).

   .ae-bolt-has-button is only added once the button is really in the DOM, so a render
   failure leaves the native submit in place rather than no way to pay.
   =========================================================================== */

form.checkout.ae-bolt-has-button #place_order {
	display: none !important;
}

.ae-bolt-pay {
	position: relative;
	display: block;
	width: 100%;
	min-height: 48px;
	margin: 8px 0 0;
	border-radius: 10px;
	overflow: hidden;
	cursor: pointer;
}

/* What the customer sees. */
.ae-bolt-pay__face {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: 48px;
	padding: 0 18px;
	background: #f90;
	color: #fff;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
}

.ae-bolt-pay:hover .ae-bolt-pay__face {
	background: #e0830f;
}

/* Bolt's real button: invisible, on top, and the actual click target. */
.ae-bolt-pay__real {
	position: absolute;
	inset: 0;
	z-index: 2;
	opacity: 0;
}

.ae-bolt-pay__real iframe,
.ae-bolt-pay__real > div {
	width: 100% !important;
	height: 100% !important;
}

/* Until configure() has run there is nothing to click, so make that legible rather
   than leaving a dead-looking button. */
.ae-bolt-pay:not(.is-ready) .ae-bolt-pay__face {
	opacity: 0.65;
	cursor: progress;
}

.ae-bolt-pay__error {
	margin: 8px 0 0;
	color: #b22222;
	font-size: 13px;
	line-height: 1.4;
}

@media (max-width: 782px) {
	body.ae-bolt-checkout .ae-bolt-notice,
	form.checkout.ae-bolt-active .ae-bolt-notice {
		padding: 14px 16px;
	}
}

/* ===========================================================================
   Bolt button visibility
   ---------------------------------------------------------------------------
   Added at the end of the file on purpose: these rules must win over the button
   styling above, and appending keeps that true without a specificity contest.

   ae_bolt_render_popup_button() now prints the wrapper on every checkout render,
   whether or not Bolt is the chosen method, and this hides it until it is. The markup
   used to be gated in PHP on the chosen method, which made the button depend on the
   session being settled at render time — the most likely cause of a checkout showing
   no Bolt button at all. Toggling visibility in CSS also means switching payment
   method reveals the button immediately instead of after an AJAX refresh.

   Both selectors are needed: body.ae-bolt-checkout covers the server's first paint,
   form.checkout.ae-bolt-active is what checkout-bolt.js maintains afterwards.
   =========================================================================== */

.ae-bolt-pay-wrap {
	display: none;
}

body.ae-bolt-checkout .ae-bolt-pay-wrap,
form.checkout.ae-bolt-active .ae-bolt-pay-wrap {
	display: block;
}
