/**
 * PDP calculator widget — ticket/04-pdp-widget.
 *
 * Replaces Woo's quantity + add-to-cart on flagged flooring products.
 * NOT loaded on aurino.co.uk (ACFC_USE_LEGACY_FRONTEND short-circuits
 * the enqueue at the PHP layer — see ProductPageWidget::is_legacy_frontend()).
 *
 * Brand surface uses three retailer CSS vars:
 *   --acfc-primary    : dark ink (live readout card surface, text)
 *   --acfc-secondary  : warm/cream card surface
 *   --acfc-button     : brand CTA accent (add-to-basket, slider fill, tab underline)
 *
 * BrandPalette currently emits the legacy 6-token set
 * (--acfc-bg/--acfc-card-bg/--acfc-fg/--acfc-fg-muted/--acfc-accent/--acfc-dark);
 * this file maps them to the 3 design vars so retailer settings still
 * drive the colour. Ticket/05 may unify the data model.
 */

@font-face {
	font-family: 'Inter';
	font-style: normal;
	font-weight: 400 700;
	font-display: swap;
	src: url('../fonts/inter-variable.woff2') format('woff2-variations');
}
@font-face {
	font-family: 'IBM Plex Mono';
	font-style: normal;
	font-weight: 400 700;
	font-display: swap;
	src: url('../fonts/ibm-plex-mono.woff2') format('woff2');
}
@font-face {
	font-family: 'Fraunces';
	font-style: normal;
	font-weight: 400 700;
	font-display: swap;
	src: url('../fonts/fraunces-variable.woff2') format('woff2-variations');
}

.acfc-widget {
	/* Map legacy 6-token palette → 3 design-spec vars. Retailer settings
	   (BrandPalette) still drive these via the inline <style> in the head. */
	--acfc-primary:   var(--acfc-fg,     #1a1a17);
	--acfc-secondary: var(--acfc-bg,     #f6f1e7);
	--acfc-button:    var(--acfc-accent, #a8331f);
	/* Text colour for content sitting on --acfc-button. Defaults to white;
	   widget.js overrides at boot when the resolved button colour is light
	   (e.g. the legacy tan default) so contrast stays >= WCAG AA. */
	--acfc-button-text: #ffffff;

	/* Stable, non-brand tokens. */
	--acfc-ink:    var(--acfc-primary);
	--acfc-mute:   #6b6358;
	--acfc-faint:  #9a9089;
	--acfc-line:   #e5dfce;
	--acfc-card:   #ffffff;
	--acfc-radius:    8px;
	--acfc-radius-sm: 4px;

	--acfc-sans:  'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--acfc-mono:  'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
	--acfc-serif: 'Fraunces', Georgia, serif;

	box-sizing: border-box;
	margin: 16px 0 22px;
	font-family: var(--acfc-sans);
	color: var(--acfc-ink);
	border: 1px solid var(--acfc-line);
	background: var(--acfc-secondary);
	border-radius: var(--acfc-radius);
	overflow: hidden;
	max-width: 560px;
}
.acfc-widget *,
.acfc-widget *::before,
.acfc-widget *::after { box-sizing: border-box; }

/* ───────── Head ───────── */
.acfc-widget__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 14px;
	padding: 16px 18px;
	background: var(--acfc-card);
	border-bottom: 1px solid var(--acfc-line);
}
.acfc-widget__head-text {
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.acfc-widget__head-text strong {
	font-size: 14px;
	font-weight: 700;
	color: var(--acfc-ink);
	letter-spacing: 0.1px;
}
.acfc-widget__step {
	font-family: var(--acfc-mono);
	font-size: 10px;
	color: var(--acfc-mute);
	letter-spacing: 1px;
	text-transform: uppercase;
}
.acfc-widget__price {
	text-align: right;
	font-family: var(--acfc-mono);
	font-size: 13px;
	color: var(--acfc-ink);
}
.acfc-widget__price span { font-weight: 700; }
.acfc-widget__price small {
	display: block;
	color: var(--acfc-mute);
	font-size: 10px;
	margin-top: 2px;
}

/* ───────── Variation picker (compact dropdown) ───────── */
.acfc-widget__variation {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 18px;
	background: var(--acfc-card);
	border-bottom: 1px solid var(--acfc-line);
}
.acfc-widget__variation-label {
	font-family: var(--acfc-mono);
	font-size: 10px;
	color: var(--acfc-mute);
	letter-spacing: 0.8px;
	text-transform: uppercase;
	flex: 0 0 auto;
}
.acfc-widget__variation-select {
	flex: 1;
	height: 36px;
	padding: 0 10px;
	border: 1px solid var(--acfc-line);
	border-radius: var(--acfc-radius-sm);
	background: #fff;
	color: var(--acfc-ink);
	font-family: var(--acfc-sans);
	font-size: 13px;
	font-weight: 600;
	outline: none;
	min-width: 0;
}
.acfc-widget__variation-select:focus {
	border-color: var(--acfc-button);
	box-shadow: 0 0 0 3px var(--acfc-secondary);
}

/* ───────── Tabs ───────── */
.acfc-widget__tabs {
	display: flex;
	background: var(--acfc-card);
	border-bottom: 1px solid var(--acfc-line);
}
.acfc-widget__tab {
	flex: 1;
	padding: 14px 8px;
	font-size: 12px;
	font-weight: 500;
	background: transparent;
	color: var(--acfc-mute);
	border: none;
	cursor: pointer;
	font-family: var(--acfc-sans);
	border-bottom: 2px solid transparent;
	transition: color 0.15s, border-color 0.15s;
}
.acfc-widget__tab:hover { color: var(--acfc-ink); }
.acfc-widget__tab[data-active] {
	font-weight: 700;
	color: var(--acfc-ink);
	border-bottom-color: var(--acfc-button);
	background: var(--acfc-card);
}
.acfc-widget__tab:focus-visible {
	outline: 2px solid var(--acfc-button);
	outline-offset: -2px;
}

/* ───────── Panel containers ───────── */
.acfc-widget__panel {
	padding: 16px 18px;
}
.acfc-widget__panel[hidden] { display: none; }

/* ───────── Room rows ───────── */
.acfc-widget__rooms {
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.acfc-widget__room {
	position: relative;
	background: var(--acfc-card);
	border: 1px solid var(--acfc-line);
	border-radius: var(--acfc-radius-sm);
	padding: 14px;
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
}
.acfc-widget__room label {
	display: flex;
	flex-direction: column;
	gap: 4px;
}
.acfc-widget__room label > span {
	font-size: 10px;
	font-family: var(--acfc-mono);
	color: var(--acfc-mute);
	letter-spacing: 0.6px;
	text-transform: uppercase;
}
.acfc-widget__room input {
	height: 40px;
	padding: 0 12px;
	border: 1px solid var(--acfc-line);
	background: var(--acfc-card);
	border-radius: var(--acfc-radius-sm);
	font-family: var(--acfc-mono);
	font-size: 14px;
	font-weight: 600;
	color: var(--acfc-ink);
	outline: none;
}
.acfc-widget__room input:focus { border-color: var(--acfc-button); }
.acfc-widget__room-remove {
	position: absolute;
	top: 8px;
	right: 8px;
	width: 28px;
	height: 28px;
	border: none;
	background: transparent;
	color: var(--acfc-mute);
	cursor: pointer;
	border-radius: var(--acfc-radius-sm);
	font-size: 18px;
	line-height: 1;
	display: grid;
	place-items: center;
}
.acfc-widget__room-remove:hover { background: var(--acfc-secondary); color: var(--acfc-button); }
.acfc-widget__add-room {
	margin-top: 12px;
	background: none;
	border: none;
	color: var(--acfc-button);
	font-family: var(--acfc-sans);
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	padding: 4px 0;
}
.acfc-widget__add-room:hover { text-decoration: underline; }

/* Standalone field (Total m² panel, roll widget). */
.acfc-widget__field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 12px;
}
.acfc-widget__field > span {
	font-size: 11px;
	font-family: var(--acfc-mono);
	color: var(--acfc-mute);
	letter-spacing: 0.6px;
	text-transform: uppercase;
}
.acfc-widget__field input,
.acfc-widget__field select {
	height: 44px;
	padding: 0 12px;
	border: 1px solid var(--acfc-line);
	background: var(--acfc-card);
	border-radius: var(--acfc-radius-sm);
	font-family: var(--acfc-mono);
	font-size: 16px;
	font-weight: 600;
	color: var(--acfc-ink);
	outline: none;
}
.acfc-widget__field input:focus,
.acfc-widget__field select:focus { border-color: var(--acfc-button); }

/* Packs stepper. */
.acfc-widget__qty {
	display: flex;
	align-items: center;
	gap: 10px;
}
.acfc-widget__qty button {
	width: 44px;
	height: 44px;
	border: 1px solid var(--acfc-line);
	background: var(--acfc-card);
	border-radius: var(--acfc-radius-sm);
	font-size: 18px;
	font-weight: 600;
	color: var(--acfc-ink);
	cursor: pointer;
}
.acfc-widget__qty button:hover { border-color: var(--acfc-button); color: var(--acfc-button); }
.acfc-widget__qty > span {
	min-width: 48px;
	text-align: center;
	font-family: var(--acfc-mono);
	font-size: 22px;
	font-weight: 700;
	color: var(--acfc-ink);
}
.acfc-widget__qty small {
	color: var(--acfc-mute);
	font-size: 12px;
	margin-left: auto;
}

/* ───────── Wastage slider ───────── */
.acfc-widget__wastage {
	margin-top: 16px;
}
.acfc-widget__wastage-head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	margin-bottom: 8px;
}
.acfc-widget__wastage-head > span {
	font-family: var(--acfc-mono);
	font-size: 11px;
	color: var(--acfc-mute);
	letter-spacing: 0.6px;
	text-transform: uppercase;
}
.acfc-widget__wastage-head strong {
	font-family: var(--acfc-mono);
	font-size: 14px;
	font-weight: 700;
	color: var(--acfc-ink);
}
.acfc-widget__wastage input[type="range"] {
	-webkit-appearance: none;
	appearance: none;
	width: 100%;
	height: 6px;
	background: var(--acfc-line);
	border-radius: 3px;
	outline: none;
	margin: 6px 0;
}
.acfc-widget__wastage input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance: none;
	appearance: none;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--acfc-button);
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.acfc-widget__wastage input[type="range"]::-moz-range-thumb {
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #fff;
	border: 2px solid var(--acfc-button);
	cursor: pointer;
	box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.acfc-widget__wastage input[type="range"]::-moz-range-track {
	background: linear-gradient(to right, var(--acfc-button) 0%, var(--acfc-button) var(--acfc-w, 50%), var(--acfc-line) var(--acfc-w, 50%), var(--acfc-line) 100%);
	height: 6px;
	border-radius: 3px;
}
.acfc-widget__wastage input[type="range"]:focus { outline: none; }
.acfc-widget__wastage-legend {
	display: flex;
	justify-content: space-between;
	font-family: var(--acfc-mono);
	font-size: 10px;
	color: var(--acfc-mute);
	margin-top: 4px;
}

/* ───────── Live readout (dark card) ───────── */
.acfc-widget__result {
	background: var(--acfc-primary);
	color: #f6f1e7;
	padding: 18px;
	border-radius: var(--acfc-radius);
	margin-top: 16px;
}
.acfc-widget__result[hidden] { display: none; }
.acfc-widget__result-line {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 12px;
	font-size: 12px;
	color: #cdc4ba;
	margin-bottom: 6px;
}
.acfc-widget__result-line span,
.acfc-widget__result-line strong { color: inherit; }
.acfc-widget__result-line strong {
	color: #fff;
	font-family: var(--acfc-mono);
	font-weight: 700;
}
.acfc-widget__result-line--big {
	margin-top: 6px;
	margin-bottom: 6px;
	font-size: 14px;
	color: #f6f1e7;
}
.acfc-widget__result-line--big > strong {
	font-family: var(--acfc-mono);
	font-size: 28px;
	font-weight: 700;
	letter-spacing: -0.5px;
	color: #fff;
}
.acfc-widget__result-line--sub {
	font-size: 11px;
	color: #a8a09a;
	margin-bottom: 0;
}
.acfc-widget__result-total {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid rgba(255,255,255,0.12);
}
.acfc-widget__result-total > span {
	font-family: var(--acfc-serif);
	font-style: italic;
	font-size: 15px;
	color: #cdc4ba;
}
.acfc-widget__result-total > strong {
	font-family: var(--acfc-mono);
	font-size: 24px;
	font-weight: 700;
	color: #fff;
	letter-spacing: -0.5px;
}

/* ───────── Spare-pack nudge ───────── */
.acfc-widget__nudge {
	margin-top: 14px;
	padding: 12px;
	background: rgba(255,255,255,0.06);
	border: 1px dashed rgba(255,255,255,0.2);
	border-radius: var(--acfc-radius-sm);
	display: flex;
	align-items: flex-start;
	gap: 10px;
	color: #e8e2d8;
	font-size: 12px;
	line-height: 1.5;
}
.acfc-widget__nudge[hidden] { display: none; }
.acfc-widget__nudge strong { color: #fff; font-weight: 600; }
.acfc-widget__nudge-add {
	background: none;
	border: none;
	color: #e8b87a;
	font-family: var(--acfc-sans);
	font-weight: 600;
	font-size: 12px;
	cursor: pointer;
	padding: 0;
	text-decoration: underline;
}

/* ───────── Hint ───────── */
.acfc-widget__hint {
	padding: 12px 18px;
	font-size: 12px;
	color: var(--acfc-mute);
	background: var(--acfc-card);
	border-top: 1px solid var(--acfc-line);
}
.acfc-widget__hint[hidden] { display: none; }

/* ───────── Form + CTA ───────── */
.acfc-widget__form {
	margin: 0;
	padding: 14px 18px 18px;
	background: var(--acfc-card);
}
.acfc-widget__cta {
	width: 100%;
	height: 60px;
	border: none;
	border-radius: var(--acfc-radius);
	background: var(--acfc-button);
	color: var(--acfc-button-text, #fff);
	font-family: var(--acfc-sans);
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	transition: filter 0.15s;
	-webkit-appearance: none;
	appearance: none;
}
.acfc-widget__cta:hover  { filter: brightness(0.94); }
.acfc-widget__cta:focus-visible { outline: 3px solid rgba(0,0,0,0.4); outline-offset: -3px; }
.acfc-widget__cta[disabled] {
	background: #cfc8be;
	color: #ffffff;
	cursor: not-allowed;
}
.acfc-widget__cta-icon { display: inline-flex; }

.acfc-widget__unavailable {
	padding: 18px;
	background: #fbe7e2;
	color: #7a2418;
	font-size: 13px;
	font-weight: 600;
	text-align: center;
}

/* ───────── Advisory (roll) ───────── */
.acfc-widget__advisory {
	margin: 0 18px 14px;
	padding: 10px 12px;
	background: var(--acfc-secondary);
	border-left: 3px solid var(--acfc-button);
	font-size: 12px;
	color: var(--acfc-ink);
	border-radius: 0 var(--acfc-radius-sm) var(--acfc-radius-sm) 0;
}

/* ───────── Mobile sticky bar ───────── */
.acfc-widget__sticky {
	display: none;
}
@media (max-width: 768px) {
	.acfc-widget__sticky {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		align-items: center;
		gap: 12px;
		padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
		background: #fff;
		border-top: 1px solid var(--acfc-line);
		box-shadow: 0 -8px 24px rgba(0,0,0,0.08);
		z-index: 50;
	}
	.acfc-widget__sticky-summary { flex: 0 0 auto; min-width: 0; }
	.acfc-widget__sticky-meta {
		font-family: var(--acfc-mono);
		font-size: 10px;
		color: var(--acfc-mute);
		text-transform: uppercase;
		letter-spacing: 0.6px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		max-width: 180px;
	}
	.acfc-widget__sticky-price {
		font-family: var(--acfc-mono);
		font-size: 18px;
		font-weight: 700;
		color: var(--acfc-ink);
	}
	.acfc-widget__sticky-btn {
		flex: 1;
		height: 48px;
		border: none;
		border-radius: var(--acfc-radius-sm);
		background: var(--acfc-button);
		color: var(--acfc-button-text, #fff);
		font-family: var(--acfc-sans);
		font-size: 14px;
		font-weight: 600;
		cursor: pointer;
		-webkit-appearance: none;
		appearance: none;
	}
	.acfc-widget__sticky-btn[disabled] {
		background: #cfc8be;
		color: #ffffff;
		cursor: not-allowed;
	}
	/* Push the page content up so the sticky bar doesn't cover anything. */
	body.single-product { padding-bottom: 96px; }
}

/* ───────── Layout polish on small screens ───────── */
@media (max-width: 480px) {
	.acfc-widget__head { padding: 14px 16px; }
	.acfc-widget__panel { padding: 14px 16px; }
	.acfc-widget__room { padding: 12px; }
	.acfc-widget__form { padding: 12px 16px 16px; }
	.acfc-widget__cta { height: 56px; font-size: 15px; }
	.acfc-widget__result-line--big > strong { font-size: 24px; }
	.acfc-widget__result-total > strong { font-size: 20px; }
}
