/*
 * ALCO DuffTuff Commerce Guardrails
 *
 * This stylesheet overlays the existing Elementor/PageKit cart and checkout.
 * It does not replace their markup and intentionally contains no desktop-wide
 * theme reset.
 */

:root {
	--adtc-blue: #0f5aa8;
	--adtc-blue-dark: #0c4a89;
	--adtc-ink: #1a2230;
	--adtc-muted: #566274;
	--adtc-line: #dce3ec;
	--adtc-success: #16713b;
	--adtc-success-bg: #edf8f1;
	--adtc-danger: #a62626;
	--adtc-radius: 8px;
}

/* Prevent custom CSS grids and their descendants from forcing page overflow. */
#duff-cart,
#duff-checkout,
#duff-cart .dfc-grid,
#duff-checkout .dco-grid,
#duff-cart .dfc-items,
#duff-cart .dfc-item,
#duff-cart .dfc-info,
#duff-cart .dfc-summary,
#duff-checkout .dco-left,
#duff-checkout .dco-card,
#duff-checkout .dco-sum,
#duff-checkout .dco-items,
#duff-checkout .dco-it,
.woocommerce-cart-form,
.woocommerce .cart_totals,
.wc-block-cart,
.wc-block-checkout {
	box-sizing: border-box;
	max-width: 100%;
	min-width: 0;
}

#duff-cart .dfc-name,
#duff-cart .dfc-var,
#duff-checkout .dco-it__n,
#duff-checkout .dco-opt__t,
#duff-checkout .dco-opt__s,
.woocommerce-notices-wrapper,
.woocommerce-message,
.woocommerce-info,
.woocommerce-error,
.wc-block-components-notice-banner,
.elementor-popup-modal .dialog-message {
	overflow-wrap: anywhere;
	word-break: normal;
}

/* Keep each payment option's title and supporting copy on separate lines. */
#duff-checkout .dco-opt > span {
	min-width: 0;
}

#duff-checkout .dco-opt__t,
#duff-checkout .dco-opt__s {
	display: block;
}

/* Reliable touch targets in the two bespoke Store API interfaces. */
#duff-cart :is(button, .dfc-btn, .dfc-checkout, .dfc-tool),
#duff-checkout :is(button, .dco-btn, .dco-place),
#duff-checkout .dco-opt,
#duff-checkout .dco-check {
	min-height: 44px;
}

#duff-cart .dfc-qty button,
#duff-cart .dfc-remove {
	align-items: center;
	display: inline-flex;
	height: 44px;
	justify-content: center;
	min-width: 44px;
	width: 44px;
}

#duff-cart .dfc-q {
	height: 44px;
	min-width: 44px;
	width: 48px;
}

#duff-checkout :is(input:not([type="radio"]):not([type="checkbox"]), select, textarea),
.woocommerce-cart :is(input, select, textarea, button, .button),
.woocommerce-checkout :is(input, select, textarea, button, .button) {
	min-height: 44px;
}

#duff-cart :is(button, a, input):focus-visible,
#duff-checkout :is(button, a, input, select, textarea, label[tabindex]):focus-visible,
.adtc-toast :is(button, a):focus-visible {
	outline: 3px solid rgba(15, 90, 168, 0.34);
	outline-offset: 2px;
}

/* The checkout actions are the primary next step; utility tools keep the
 * existing outlined treatment from the authored cart. */
#duff-cart .dfc-checkout,
#duff-checkout .dco-place {
	align-items: center;
	background: var(--adtc-blue) !important;
	border-color: var(--adtc-blue) !important;
	color: #fff !important;
	display: inline-flex;
	justify-content: center;
	text-decoration: none !important;
	transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease !important;
}

#duff-cart .dfc-checkout:hover,
#duff-checkout .dco-place:hover {
	background: var(--adtc-blue-dark) !important;
	border-color: var(--adtc-blue-dark) !important;
	color: #fff !important;
	transform: translateY(-1px);
}

#duff-cart .dfc-checkout:active,
#duff-checkout .dco-place:active {
	transform: translateY(0);
}

#duff-cart .dfc-checkout:disabled,
#duff-checkout .dco-place:disabled {
	cursor: not-allowed;
	opacity: 0.65;
	transform: none;
}

/* Current manual-shipping state. The selected zero-cost rate remains in the
 * document so WooCommerce can create the order; only the customer calculator
 * and misleading $0/Free presentation are suppressed. */
.adtc-shipping-offline-note {
	background: #f3f7fb;
	border: 1px solid #cfdae7;
	border-radius: var(--adtc-radius);
	color: var(--adtc-ink);
	font-size: 0.92rem;
	font-weight: 700;
	line-height: 1.4;
	margin: 0.35rem 0;
	padding: 0.8rem 0.9rem;
}

.adtc-shipping-offline .shipping-calculator-button,
.adtc-shipping-offline .shipping-calculator-form,
.adtc-shipping-offline .wc-block-components-shipping-calculator,
.adtc-shipping-offline [data-adtc-shipping-calculator],
.adtc-shipping-offline #duff-checkout #dco-ship .dco-opts,
.adtc-shipping-offline #duff-checkout #dco-ship > .dco-hint.adtc-replaced,
.adtc-shipping-offline #shipping_method.adtc-manual-rate,
.adtc-shipping-offline .wc-block-components-shipping-rates-control.adtc-manual-rate,
.adtc-shipping-offline .adtc-zero-shipping-amount {
	display: none !important;
}

.adtc-shipping-value {
	color: var(--adtc-muted) !important;
	font-weight: 700 !important;
	text-align: right;
}

/* PayPal and Link are not available payment choices. CSS is a fast visual
 * guard; PHP removes their gateways and JavaScript catches injected markup. */
.pk-footer__pay .pk-pay[title="PayPal"],
.payment_method_paypal,
.payment_method_ppcp-gateway,
.payment_method_ppcp-card-button-gateway,
.payment_method_ppec_paypal,
.payment_method_stripe_link,
[data-pay="paypal"],
[data-payment-method="paypal"],
[data-gateway_id="paypal"],
[data-gateway_id^="ppcp"],
[data-gateway_id="stripe_link"],
.ppc-button-wrapper,
.paypal-buttons,
.adtc-suppressed-payment {
	display: none !important;
}

body.adtc-po-ineligible #duff-checkout .dco-opt[data-pay="cod"],
body.adtc-po-ineligible #duff-cart .dfc-po,
body.adtc-po-ineligible #duff-checkout .dco-po {
	display: none !important;
}

/* Inline Woo notices remain readable and tappable at every width. */
.woocommerce-notices-wrapper,
.woocommerce-message,
.woocommerce-info,
.woocommerce-error,
.wc-block-components-notice-banner {
	box-sizing: border-box;
	max-width: 100%;
}

.woocommerce-message .button,
.woocommerce-info .button,
.wc-block-components-notice-banner a,
.adtc-inline-success + .button {
	min-height: 44px;
}

/* Accessible add-to-cart confirmation. */
.adtc-toast-region {
	bottom: calc(18px + env(safe-area-inset-bottom, 0px));
	display: grid;
	gap: 10px;
	max-width: min(420px, calc(100vw - 24px));
	pointer-events: none;
	position: fixed;
	right: max(12px, env(safe-area-inset-right, 0px));
	width: max-content;
	z-index: 2147482000;
}

.adtc-toast {
	align-items: center;
	animation: adtc-toast-in 180ms ease-out both;
	background: #fff;
	border: 1px solid #c9ded1;
	border-left: 5px solid var(--adtc-success);
	border-radius: 9px;
	box-shadow: 0 12px 32px rgba(22, 31, 43, 0.22);
	color: var(--adtc-ink);
	display: grid;
	font: 600 15px/1.35 Arial, Helvetica, sans-serif;
	gap: 8px 12px;
	grid-template-columns: auto minmax(0, 1fr) auto;
	max-width: 100%;
	min-height: 58px;
	padding: 10px 11px;
	pointer-events: auto;
	width: 100%;
}

.adtc-toast__icon {
	align-items: center;
	background: var(--adtc-success-bg);
	border-radius: 50%;
	color: var(--adtc-success);
	display: inline-flex;
	font-size: 16px;
	font-weight: 800;
	height: 30px;
	justify-content: center;
	width: 30px;
}

.adtc-toast__body {
	min-width: 0;
	overflow-wrap: anywhere;
}

.adtc-toast__body a {
	color: var(--adtc-blue);
	display: inline-block;
	font-size: 14px;
	margin-top: 3px;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.adtc-toast__close {
	align-items: center;
	background: transparent;
	border: 0;
	border-radius: 5px;
	color: #647184;
	cursor: pointer;
	display: inline-flex;
	font-size: 22px;
	height: 44px;
	justify-content: center;
	padding: 0;
	width: 44px;
}

.adtc-toast.is-leaving {
	animation: adtc-toast-out 150ms ease-in both;
}

@keyframes adtc-toast-in {
	from { opacity: 0; transform: translateY(12px); }
	to { opacity: 1; transform: translateY(0); }
}

@keyframes adtc-toast-out {
	from { opacity: 1; transform: translateY(0); }
	to { opacity: 0; transform: translateY(8px); }
}

/* Elementor popup guardrails: retain the authored design while keeping the
 * dialog inside the viewport and its actions reachable. */
.elementor-popup-modal {
	box-sizing: border-box;
	max-width: 100vw;
}

.elementor-popup-modal .dialog-widget-content,
.elementor-popup-modal .dialog-message {
	box-sizing: border-box;
	max-width: calc(100vw - 24px) !important;
}

.elementor-popup-modal .dialog-message {
	max-height: calc(100dvh - 24px);
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.elementor-popup-modal .dialog-close-button,
.elementor-popup-modal :is(a.elementor-button, button, input[type="button"], input[type="submit"]) {
	align-items: center;
	display: inline-flex;
	justify-content: center;
	min-height: 44px;
}

.elementor-popup-modal .dialog-close-button {
	min-width: 44px;
}

@media (max-width: 860px) {
	#duff-cart .dfc-grid,
	#duff-checkout .dco-grid {
		gap: 16px;
		grid-template-columns: minmax(0, 1fr) !important;
		width: 100%;
	}

	#duff-cart .dfc-summary,
	#duff-checkout .dco-sum {
		position: static !important;
		width: 100%;
	}

	#duff-cart .dfc-item {
		column-gap: 12px;
		grid-template-areas:
			"thumb info remove"
			"thumb qty qty"
			"thumb line line" !important;
		grid-template-columns: 60px minmax(0, 1fr) 44px !important;
		padding: 14px 12px;
		row-gap: 10px;
	}

	#duff-cart :is(.dfc-img, .dfc-thumb, .dfc-media, .dfc-photo),
	#duff-cart .dfc-info,
	#duff-cart .dfc-qty,
	#duff-cart .dfc-line,
	#duff-cart .dfc-remove {
		min-width: 0;
	}

	#duff-cart .dfc-info {
		grid-area: info;
	}

	#duff-cart :is(.dfc-img, .dfc-thumb, .dfc-media, .dfc-photo) {
		align-self: start;
		grid-area: thumb;
	}

	#duff-cart .dfc-qty {
		display: grid !important;
		grid-area: qty;
		grid-template-columns: 44px minmax(58px, 1fr) 44px;
		justify-self: start;
		max-width: 260px;
		width: 100%;
	}

	#duff-cart .dfc-qty button,
	#duff-cart .dfc-q {
		width: 100% !important;
	}

	#duff-cart .dfc-line {
		align-self: center;
		grid-area: line;
		justify-self: end;
		max-width: 100%;
		min-width: 0 !important;
		white-space: nowrap;
	}

	#duff-cart .dfc-remove {
		align-self: start;
		grid-area: remove;
		justify-self: end;
	}

	#duff-checkout .dco-card,
	#duff-checkout .dco-sum,
	#duff-cart .dfc-summary {
		padding: 18px 16px;
	}

	#duff-checkout .dco-opt {
		align-items: center;
		flex-wrap: wrap;
		padding: 10px 12px;
	}

	#duff-checkout .dco-opt__price {
		margin-left: auto;
	}

	.woocommerce-cart-form,
	.woocommerce .cart_totals {
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}
}

@media (max-width: 640px) {
	#duff-checkout .dco-row2,
	#duff-checkout .dco-row3 {
		grid-template-columns: minmax(0, 1fr) !important;
	}

	#duff-checkout :is(input:not([type="radio"]):not([type="checkbox"]), select, textarea) {
		font-size: 16px;
	}

	#duff-cart .dfc-tools {
		align-items: stretch;
		flex-direction: column;
	}

	#duff-cart .dfc-tool,
	#duff-cart .dfc-checkout,
	#duff-checkout .dco-place {
		width: 100%;
	}

	.woocommerce-message,
	.woocommerce-info,
	.woocommerce-error,
	.wc-block-components-notice-banner {
		padding: 12px !important;
	}

	.woocommerce-message .button,
	.woocommerce-info .button,
	.adtc-inline-success + .button {
		display: flex;
		float: none;
		justify-content: center;
		margin: 10px 0 0;
		width: 100%;
	}

	.adtc-toast-region {
		bottom: calc(10px + env(safe-area-inset-bottom, 0px));
		left: max(10px, env(safe-area-inset-left, 0px));
		max-width: none;
		right: max(10px, env(safe-area-inset-right, 0px));
		width: auto;
	}

	.adtc-toast {
		grid-template-columns: auto minmax(0, 1fr) auto;
	}
}

@media (max-width: 390px) {
	#duff-cart .dfc-item {
		grid-template-areas:
			"thumb info remove"
			"qty qty qty"
			"line line line" !important;
		grid-template-columns: 56px minmax(0, 1fr) 44px !important;
	}

	#duff-cart :is(img.dfc-img, .dfc-thumb img, .dfc-media img, .dfc-photo img) {
		height: 56px !important;
		width: 56px !important;
	}

	#duff-cart .dfc-qty {
		grid-area: qty;
	}

	#duff-checkout .dco-card,
	#duff-checkout .dco-sum,
	#duff-cart .dfc-summary {
		padding: 15px 12px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.adtc-toast,
	.adtc-toast.is-leaving {
		animation: none;
	}

	#duff-cart .dfc-checkout,
	#duff-checkout .dco-place {
		transition: none !important;
	}

	#duff-cart .dfc-checkout:hover,
	#duff-cart .dfc-checkout:active,
	#duff-checkout .dco-place:hover,
	#duff-checkout .dco-place:active {
		transform: none !important;
	}
}
