/**
 * Random Product Banner for WooCommerce — Stylesheet
 * Version: 2.2.0
 *
 * Brand colour tokens (--color-primary/secondary/accent) are injected at
 * runtime via inline style on .rpb-wrapper, sourced from ACF brand fields.
 * The :root block below provides hardcoded fallbacks for when ACF is inactive.
 */

/* ─────────────────────────────────────────────────────────────────────────────
   1. Global Brand Colour Fallbacks
   These are overridden at runtime by ACF values via inline style on .rpb-wrapper
   ───────────────────────────────────────────────────────────────────────────── */
:root {
	--color-primary:   #111827;
	--color-secondary: #6b7280;
	--color-accent:    #1d4ed8;
}

/* ─────────────────────────────────────────────────────────────────────────────
   2. CSS Custom Properties — Per-instance defaults
      All values can be overridden via inline style on .rpb-wrapper.
      Colour slots that should follow brand use var(--color-*) as their default
      so they automatically inherit ACF values without any JS.
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-wrapper {
	/* Layout */
	--rpb-height:              320px;
	--rpb-width:               100%;
	--rpb-radius:              20px;
	--rpb-content-max-width:   42%;
	--rpb-gradient-width:      180px;

	/* Content panel */
	--rpb-content-bg:          #ffffff;
	--rpb-content-padding:     40px;

	/* Headline pill — defaults to brand primary */
	--rpb-headline-bg:         var(--color-primary);
	--rpb-headline-color:      #ffffff;

	/* Typography */
	--rpb-category-color:      #9ca3af;
	--rpb-category-size:       11px;
	--rpb-title-color:         #111827;
	--rpb-title-size:          26px;
	--rpb-price-color:         #111827;
	--rpb-price-size:          20px;
	/* Sale price — defaults to brand primary */
	--rpb-price-sale-color:    var(--color-primary);

	/* CTA button — defaults to brand primary */
	--rpb-cta-bg:              var(--color-primary);
	--rpb-cta-color:           #ffffff;
	--rpb-cta-radius:          8px;

	/* Mobile overlay */
	--rpb-mob-overlay-rgb:     0,0,0;
	--rpb-mob-overlay-opacity: 0.55;

	/* Mobile typography */
	--rpb-mob-title-size:      20px;
	--rpb-mob-text-align:      left;
	--rpb-mob-valign:          flex-end;

	--rpb-transition: 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ─────────────────────────────────────────────────────────────────────────────
   3. Wrapper
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-wrapper {
	display: block;
	width: var(--rpb-width);
	max-width: 100%;
	margin: 0 auto 1.5rem;
	height: var(--rpb-height);
	border-radius: var(--rpb-radius);
	overflow: hidden;
	box-shadow: 0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
	animation: rpb-fadein 0.55s ease both;
}

/* ─────────────────────────────────────────────────────────────────────────────
   4. Banner Link & Flex Container
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-banner {
	display: flex;
	flex-direction: row;
	align-items: stretch;
	width: 100%;
	height: 100%;
	text-decoration: none;
	color: inherit;
	position: relative;
	background: var(--rpb-content-bg);
	overflow: hidden;
}

/* ─────────────────────────────────────────────────────────────────────────────
   5. Content Panel — shrink-to-fit, gradient bleeds from its right edge
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-content {
	position: relative;
	z-index: 2;
	flex: 0 0 auto;
	width: -moz-fit-content;
	width: fit-content;
	min-width: 140px;
	max-width: var(--rpb-content-max-width);
	background: var(--rpb-content-bg);
	padding: var(--rpb-content-padding);
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 8px;
}

/* Gradient pseudo-element — anchored to right edge of content panel */
.rpb-content::after {
	content: '';
	position: absolute;
	top: 0;
	left: 100%;
	width: var(--rpb-gradient-width);
	height: 100%;
	z-index: 1;
	background: linear-gradient(
		to right,
		var(--rpb-content-bg)              0%,
		rgba(255,255,255,0.85)             25%,
		rgba(255,255,255,0.45)             60%,
		rgba(255,255,255,0)               100%
	);
	pointer-events: none;
}

/* Legacy .rpb-gradient div — hidden; pseudo-element handles this now */
.rpb-gradient { display: none; }

/* ─────────────────────────────────────────────────────────────────────────────
   6. Headline Pill
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-headline {
	display: inline-block;
	align-self: flex-start;
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 0.07em;
	text-transform: uppercase;
	color: var(--rpb-headline-color);
	background: var(--rpb-headline-bg);
	padding: 4px 11px 3px;
	border-radius: 999px;
	line-height: 1.4;
	white-space: nowrap;
	animation: rpb-fadein 0.6s 0.1s ease both;
}

/* ─────────────────────────────────────────────────────────────────────────────
   7. Category / Title / Price
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-category {
	display: inline-block;
	font-size: var(--rpb-category-size);
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--rpb-category-color);
	line-height: 1;
	white-space: nowrap;
}

.rpb-title {
	margin: 0;
	padding: 0;
	font-size: var(--rpb-title-size);
	font-weight: 800;
	line-height: 1.2;
	color: var(--rpb-title-color);
	letter-spacing: -0.02em;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.rpb-price {
	font-size: var(--rpb-price-size);
	font-weight: 700;
	color: var(--rpb-price-color);
	line-height: 1.2;
	white-space: nowrap;
}

/* Target WooCommerce's nested price markup:
   <span class="woocommerce-Price-amount"><bdi><span>£</span>9.99</bdi></span>
   WooCommerce's stylesheet often wins on bare `color`, so we go deeper. */
.rpb-price .woocommerce-Price-amount,
.rpb-price .woocommerce-Price-amount bdi,
.rpb-price .woocommerce-Price-amount bdi .woocommerce-Price-currencySymbol {
	color: var(--rpb-price-color);
}

/* Strikethrough original price */
.rpb-price del,
.rpb-price del .woocommerce-Price-amount,
.rpb-price del .woocommerce-Price-amount bdi,
.rpb-price del .woocommerce-Price-amount bdi .woocommerce-Price-currencySymbol {
	color: var(--rpb-category-color) !important;
	font-weight: 400;
	font-size: 0.8em;
}

.rpb-price del {
	margin-right: 5px;
}

/* Sale / insert price */
.rpb-price ins {
	text-decoration: none;
}

.rpb-price ins,
.rpb-price ins .woocommerce-Price-amount,
.rpb-price ins .woocommerce-Price-amount bdi,
.rpb-price ins .woocommerce-Price-amount bdi .woocommerce-Price-currencySymbol {
	color: var(--rpb-price-sale-color) !important;
}

/* ─────────────────────────────────────────────────────────────────────────────
   8. CTA Button
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-cta {
	display: inline-block;
	align-self: flex-start;
	margin-top: 6px;
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--rpb-cta-color);
	background: var(--rpb-cta-bg);
	padding: 9px 20px 8px;
	border-radius: var(--rpb-cta-radius);
	line-height: 1;
	transition: opacity 0.2s ease, transform 0.2s ease;
	white-space: nowrap;
}

.rpb-banner:hover .rpb-cta {
	opacity: 0.85;
	transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   9. Image Area
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-image {
	flex: 1 1 0;
	min-width: 0;
	background-size: cover;
	background-position: center center;
	background-repeat: no-repeat;
	transition: transform var(--rpb-transition);
	transform-origin: center center;
}

/* ─────────────────────────────────────────────────────────────────────────────
   10. Content-on-right variant
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-side-right .rpb-banner { flex-direction: row-reverse; }

.rpb-side-right .rpb-content::after {
	left: auto;
	right: 100%;
	background: linear-gradient(
		to left,
		var(--rpb-content-bg)              0%,
		rgba(255,255,255,0.85)             25%,
		rgba(255,255,255,0.45)             60%,
		rgba(255,255,255,0)               100%
	);
}

/* ─────────────────────────────────────────────────────────────────────────────
   11. Hover & Focus
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-banner:hover .rpb-image { transform: scale(1.04); }

.rpb-banner:focus-visible {
	outline: 3px solid var(--color-accent);
	outline-offset: 3px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   12. Animations
   ───────────────────────────────────────────────────────────────────────────── */
@keyframes rpb-fadein {
	from { opacity: 0; transform: translateY(10px); }
	to   { opacity: 1; transform: translateY(0); }
}

.rpb-wrapper.rpb-refreshing { animation: rpb-fadein 0.45s ease both; }

/* ─────────────────────────────────────────────────────────────────────────────
   13. Empty State
   ───────────────────────────────────────────────────────────────────────────── */
.rpb-wrapper .rpb-empty {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	width: 100%;
	font-size: 0.95rem;
	color: var(--rpb-category-color);
	background: #f9fafb;
}

/* ─────────────────────────────────────────────────────────────────────────────
   14. Mobile — full-bleed image + coloured overlay + white text
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

	.rpb-banner {
		flex-direction: column;
		position: relative;
	}

	.rpb-image {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
		flex: none;
		z-index: 0;
		transform: none !important;
	}

	/* Disable desktop gradient pseudo-element */
	.rpb-content::after { display: none; }

	/* Dark overlay — colour and opacity controllable via CSS vars */
	.rpb-banner::after {
		content: '';
		position: absolute;
		inset: 0;
		z-index: 1;
		background: linear-gradient(
			to top,
			rgba(var(--rpb-mob-overlay-rgb), calc(var(--rpb-mob-overlay-opacity) * 1.5)) 0%,
			rgba(var(--rpb-mob-overlay-rgb), var(--rpb-mob-overlay-opacity))              55%,
			rgba(var(--rpb-mob-overlay-rgb), calc(var(--rpb-mob-overlay-opacity) * 0.5)) 100%
		);
		pointer-events: none;
	}

	/* Text panel: positioned above overlay, vertical alignment controllable */
	.rpb-content {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		top: 0;
		z-index: 2;
		flex: none;
		width: 100%;
		max-width: 100%;
		min-width: 0;
		background: transparent;
		padding: 20px 20px 26px;
		gap: 6px;
		display: flex;
		flex-direction: column;
		justify-content: var(--rpb-mob-valign);
		text-align: var(--rpb-mob-text-align);
	}

	/* White text */
	.rpb-headline {
		background: rgba(255,255,255,0.15);
		color: #ffffff;
		border: 1px solid rgba(255,255,255,0.3);
		-webkit-backdrop-filter: blur(4px);
		backdrop-filter: blur(4px);
	}

	.rpb-category { color: rgba(255,255,255,0.65); }
	.rpb-title    { color: #ffffff; font-size: var(--rpb-mob-title-size); -webkit-line-clamp: 2; }

	.rpb-price,
	.rpb-price .woocommerce-Price-amount,
	.rpb-price .woocommerce-Price-amount bdi { color: #ffffff; }

	.rpb-price del,
	.rpb-price del .woocommerce-Price-amount,
	.rpb-price del .woocommerce-Price-amount bdi { color: rgba(255,255,255,0.5) !important; }

	.rpb-price ins,
	.rpb-price ins .woocommerce-Price-amount,
	.rpb-price ins .woocommerce-Price-amount bdi { color: #fca5a5 !important; }

	/* Centre / right alignment helpers */
	.rpb-wrapper .rpb-content { align-items: flex-start; }

	/* Mobile show/hide classes */
	.rpb-mob-hide-headline .rpb-headline { display: none !important; }
	.rpb-mob-hide-category .rpb-category { display: none !important; }
	.rpb-mob-hide-title    .rpb-title    { display: none !important; }
	.rpb-mob-hide-price    .rpb-price    { display: none !important; }
	.rpb-mob-hide-cta      .rpb-cta      { display: none !important; }

	/* Reset right-side panel on mobile */
	.rpb-side-right .rpb-banner { flex-direction: column; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   15. Tablet
   ───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 641px) and (max-width: 900px) {
	.rpb-content { max-width: 55%; }
}
