/*
 * DX Single Product - front-end + editor styles
 * Matches the 22Words product-json worker (desktop + mobile).
 */

:root {
	--dxsp-pink: #ff1493;
	--dxsp-pink-deep: #f00084;
	--dxsp-card-bg: #ffffff;
	--dxsp-text: #1a1a1a;
	--dxsp-muted: #555555;
	--dxsp-btn: #00c6c3;
	--dxsp-btn-hover: #16a8b0;
	--dxsp-radius: 24px;
	--dxsp-card-max: 620px;
	--dxsp-image-box: 280px;
}

/* ---------- Multi-column page width overrides ---------- */
/*
 * When 2–4 products per row are selected the body gets dxsp-cols-N.
 * Widen .dxsp-main and .dxsp-footer so the row has room to breathe.
 * 1260px covers 2× 620px cards + gutter; 3–4 cols also cap at 1260px.
 */
.dxsp-cols-2 .dxsp-main,
.dxsp-cols-2 .dxsp-footer,
.dxsp-cols-3 .dxsp-main,
.dxsp-cols-3 .dxsp-footer,
.dxsp-cols-4 .dxsp-main,
.dxsp-cols-4 .dxsp-footer {
	max-width: 1260px;
}

/* ---------- Page chrome (front-end only) ---------- */

body.dxsp-body {
	margin: 0;
	padding: 0;
	background: var(--dxsp-pink);
	color: var(--dxsp-text);
	font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
		Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.dxsp-page {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 0 16px 32px;
	box-sizing: border-box;
}

.dxsp-header {
	width: 100%;
	padding: 8px 16px 16px;
	display: flex;
	justify-content: center;
	align-items: center;
}

.dxsp-logo {
	display: inline-flex;
	align-items: center;
	text-decoration: none;
	color: #fff;
}

.dxsp-logo-img {
	height: 40px;
	width: auto;
	display: block;
}

.dxsp-main {
	width: 100%;
	max-width: var(--dxsp-card-max);
	flex: 1 0 auto;
	padding: 0 0 8px;
}

.dxsp-footer {
	width: 100%;
	max-width: var(--dxsp-card-max);
	margin-top: 24px;
	padding: 0 16px 32px;
	text-align: center;
	color: #f9e9f5;
	font-size: 11px;
	line-height: 1.5;
	flex-shrink: 0;
}

.dxsp-footer a {
	color: #f9e9f5;
	text-decoration: underline;
}

.dxsp-footer .dxsp-editorial {
	margin: 0 0 8px;
}

.dxsp-footer .dxsp-copy {
	margin: 0;
}

/* Clear fixed sticky ad bar (#ad-anchor) on mobile — same as product-json worker */
@media (max-width: 991px) {
	body.dxsp-body {
		padding-bottom: 80px;
	}

	body.dxsp-body .dxsp-page {
		padding-bottom: 16px;
	}

	body.dxsp-body .dxsp-footer {
		padding-bottom: 48px;
	}
}

/* ---------- The pattern (works in editor + front-end) ---------- */

.dxsp-card-wrap {
	width: 100%;
	max-width: var(--dxsp-card-max);
	margin: 0 auto !important;
}

.dxsp-card-wrap:not(:first-child),
.dxsp-card-wrap ~ .dxsp-card-wrap,
.wp-block-group.dxsp-card-wrap + .wp-block-group.dxsp-card-wrap {
	margin-top: 40px !important;
}

@media (max-width: 640px) {
	.dxsp-card-wrap:not(:first-child),
	.dxsp-card-wrap ~ .dxsp-card-wrap,
	.wp-block-group.dxsp-card-wrap + .wp-block-group.dxsp-card-wrap {
		margin-top: 28px !important;
	}
}

.dxsp-card {
	background: var(--dxsp-card-bg);
	border-radius: var(--dxsp-radius);
	padding: 24px 20px 28px;
	box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
	border: none;
}

.dxsp-card > * + * {
	margin-top: 18px;
}

.dxsp-title {
	font-size: 26px;
	font-weight: 800;
	line-height: 1.18;
	color: var(--dxsp-text);
	margin: 0 0 18px;
	cursor: pointer;
	text-align: left;
}

.dxsp-title a {
	color: inherit;
	text-decoration: none;
}

.dxsp-title a.amazon-buy-link,
.dxsp-description a.amazon-buy-link {
	color: #683bed;
	text-decoration: underline;
}

/* Product image — match worker .image-inner / .image-link sizing */
.dxsp-image {
	margin: 0 0 18px;
	cursor: pointer;
	display: flex;
	justify-content: center;
	width: 100%;
}

.dxsp-image figure,
.dxsp-image .wp-block-image {
	position: relative;
	width: 100%;
	max-width: var(--dxsp-image-box);
	margin: 0 auto;
	aspect-ratio: 1 / 1;
	min-height: var(--dxsp-image-box);
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--dxsp-card-bg);
}

.dxsp-image img {
	width: 100%;
	height: 100%;
	max-width: 100%;
	object-fit: contain;
	display: block;
	border-radius: 8px;
	background: var(--dxsp-card-bg);
}

/* "via Amazon" / "via Walmart" badge (product-json .image-credit) */
.dxsp-card:not(.dxsp-retailer-walmart) .dxsp-image figure::after,
.dxsp-card.dxsp-retailer-amazon .dxsp-image figure::after {
	content: "via Amazon";
	position: absolute;
	bottom: 0;
	right: 0;
	font-size: 10px;
	color: #ffffff;
	font-style: italic;
	font-weight: 400;
	background: rgba(0, 168, 177, 0.6);
	padding: 2px 6px;
	border-radius: 4px;
	pointer-events: none;
	line-height: 1.2;
}

.dxsp-card.dxsp-retailer-walmart .dxsp-image figure::after {
	content: "via Walmart";
}

.dxsp-description {
	font-size: 15px;
	line-height: 1.5;
	color: var(--dxsp-muted);
	margin: 0 0 8px;
}

.dxsp-cta {
	margin-top: 22px !important;
	display: flex;
	justify-content: center;
}

.dxsp-cta .wp-block-button {
	width: auto;
	max-width: 100%;
}

.dxsp-button .wp-block-button__link,
.dxsp-cta .wp-block-button__link {
	background: var(--dxsp-btn) !important;
	color: #ffffff !important;
	border-radius: 999px !important;
	font-weight: 700 !important;
	letter-spacing: 0.04em;
	padding: 12px 32px !important;
	font-size: 15px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	line-height: 1.35;
	white-space: nowrap;
	width: auto;
	max-width: 100%;
	box-sizing: border-box;
	transition: filter 0.15s ease-in-out;
	text-decoration: none;
	text-transform: uppercase;
	gap: 8px;
}

.dxsp-button .wp-block-button__link:hover,
.dxsp-cta .wp-block-button__link:hover {
	filter: brightness(1.05);
}

/* Inner card border like worker .card-inner */
.dxsp-card-wrap > .dxsp-card,
.dxsp-card-wrap > .wp-block-group.dxsp-card {
	border: 4px solid #000;
	border-radius: 18px;
}

/* ---------- Horizontal card layout (Gutenberg Columns-based) ---------- */

/*
 * The horizontal card uses a native wp:columns block inside the card group.
 * Gutenberg renders the same flexbox layout in both the editor and the
 * frontend, so no CSS-grid-vs-wrapper-div fighting.
 *
 * Structure:
 *   .dxsp-card--horizontal
 *     .dxsp-card-cols  (.wp-block-columns)
 *       .dxsp-col-image  (.wp-block-column, flex-basis:280px)
 *         figure.dxsp-image
 *       .dxsp-col-content  (.wp-block-column)
 *         h2.dxsp-title
 *         p.dxsp-description
 *         .dxsp-cta
 */

/* Columns container: stretch columns to equal height */
.dxsp-card--horizontal .dxsp-card-cols.wp-block-columns {
	align-items: stretch !important;
	gap: 0 !important;
	flex-wrap: nowrap !important;
	margin-bottom: 0 !important;
}

/* Image column: fixed width, no padding, stretch to full card height */
.dxsp-col-image.wp-block-column {
	flex: 0 0 var(--dxsp-image-box) !important;
	max-width: var(--dxsp-image-box) !important;
	min-width: 0 !important;
	padding: 0 !important;
	display: flex !important;
	flex-direction: column !important;
	overflow: hidden;
	border-radius: 12px;
}

/* Image figure: fill the full column height */
.dxsp-col-image .dxsp-image {
	flex: 1 !important;
	width: 100% !important;
	margin: 0 !important;
	display: flex !important;
	min-height: unset !important;
	aspect-ratio: unset !important;
	overflow: hidden;
}

.dxsp-col-image .dxsp-image figure,
.dxsp-col-image .dxsp-image .wp-block-image {
	flex: 1;
	width: 100%;
	min-height: unset;
	aspect-ratio: unset;
	margin: 0;
}

/* Image fills the column — cover so it always fills without letterboxing */
.dxsp-col-image .dxsp-image img {
	object-fit: cover !important;
	width: 100% !important;
	height: 100% !important;
	border-radius: 0 !important;
	background: transparent !important;
}

/* Content column: gap from image + flex column so CTA sticks to bottom */
.dxsp-col-content.wp-block-column {
	flex: 1 !important;
	display: flex !important;
	flex-direction: column !important;
	padding-left: 24px !important;
	padding-right: 0 !important;
}

.dxsp-col-content .dxsp-title {
	margin: 0 0 14px !important;
}

.dxsp-col-content .dxsp-description {
	margin: 0 !important;
	flex: 1;
}

.dxsp-col-content .dxsp-cta {
	margin-top: 18px !important;
	justify-content: flex-start !important;
}

/* Mobile: Gutenberg stacks columns by default; restore image sizing */
@media (max-width: 599px) {
	.dxsp-card--horizontal .dxsp-card-cols.wp-block-columns {
		flex-wrap: wrap !important;
	}

	.dxsp-col-image.wp-block-column {
		flex: 0 0 100% !important;
		max-width: 100% !important;
		border-radius: 8px;
		min-height: 200px;
	}

	.dxsp-col-content.wp-block-column {
		padding-left: 0 !important;
		margin-top: 18px !important;
	}
}

/* ---------- Side-by-side product row (2 per row) ---------- */
/*
 * Markup:
 *   .wp-block-columns.dxsp-products-row
 *     .wp-block-column.dxsp-product-col
 *       .wp-block-group.dxsp-card-wrap   (→ existing card styles)
 *     .wp-block-column.dxsp-product-col
 *       .wp-block-group.dxsp-card-wrap
 */

/* Row: equal-height columns, stretch full available width */
.dxsp-products-row.wp-block-columns {
	align-items: stretch;
	max-width: 100% !important;
}

/* Each column fills its card fully */
.dxsp-products-row .dxsp-product-col.wp-block-column {
	display: flex;
	flex-direction: column;
}

/* Cards inside a row fill their column width, no centring margin */
.dxsp-products-row .dxsp-card-wrap {
	max-width: 100% !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
	flex: 1;
	display: flex;
	flex-direction: column;
}

/* The inner .dxsp-card stretches to fill the wrap height */
.dxsp-products-row .dxsp-card {
	flex: 1;
}

/* Reset stacking top-margin inside a row (cards are already separated by column gap) */
.dxsp-products-row .dxsp-card-wrap:not(:first-child),
.dxsp-products-row .wp-block-group.dxsp-card-wrap + .wp-block-group.dxsp-card-wrap {
	margin-top: 0 !important;
}

/* Horizontal cards inside a row: shrink image box proportionally */
.dxsp-products-row .dxsp-card--horizontal .dxsp-col-image.wp-block-column {
	flex: 0 0 160px !important;
	max-width: 160px !important;
}

/* Stack the row on smaller screens */
@media (max-width: 720px) {
	.dxsp-products-row.wp-block-columns {
		flex-wrap: wrap !important;
	}
	.dxsp-products-row .dxsp-product-col.wp-block-column {
		flex: 0 0 100% !important;
		max-width: 100% !important;
	}
	.dxsp-products-row .dxsp-card-wrap:not(:first-child) {
		margin-top: 24px !important;
	}
}

/* ---------- Editor-only ---------- */

body.post-type-single_product .editor-styles-wrapper,
body.post-type-single_product .block-editor-writing-flow,
.editor-styles-wrapper .dxsp-card-wrap {
	background: transparent;
}

body.post-type-single_product .editor-styles-wrapper {
	background-color: var(--dxsp-pink) !important;
}

body.post-type-single_product .editor-styles-wrapper .wp-block {
	color: var(--dxsp-text);
}

/* Tell Gutenberg our content-size and wide-size so it centres blocks correctly.
 * content-size = single card max width; wide-size = multi-column row max width. */
body.post-type-single_product .editor-styles-wrapper {
	--wp--style--global--content-size: 620px;
	--wp--style--global--wide-size:    1260px;
}

/* Products row (alignwide): use the full wide-size, centred by Gutenberg */
.editor-styles-wrapper .wp-block-columns.dxsp-products-row {
	max-width: var(--wp--style--global--wide-size, 1260px) !important;
	margin-left:  auto !important;
	margin-right: auto !important;
}

/* Editor: show credit badges in canvas */
body.post-type-single_product .editor-styles-wrapper .dxsp-card:not(.dxsp-retailer-walmart) .dxsp-image figure::after {
	content: "via Amazon";
}

/* Editor: single-line CTA (avoids stacked/overlapping RichText lines) */
body.post-type-single_product .editor-styles-wrapper .dxsp-button .wp-block-button__link,
body.post-type-single_product .editor-styles-wrapper .dxsp-cta .wp-block-button__link,
body.post-type-single_product .editor-styles-wrapper .dxsp-button .block-editor-rich-text__editable,
body.post-type-single_product .editor-styles-wrapper .dxsp-cta .block-editor-rich-text__editable {
	white-space: nowrap !important;
	line-height: 1.35 !important;
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
	.dxsp-page {
		padding: 0 12px 16px;
	}

	.dxsp-header {
		padding: 6px 16px 12px;
	}

	.dxsp-logo-img {
		height: 36px;
	}

	.dxsp-card {
		padding: 18px 14px 22px;
	}

	.dxsp-title {
		font-size: 22px;
	}

	.dxsp-description {
		font-size: 15px;
	}

}

/* Sticky footer ad from theme / Freestar */
body.dxsp-body #ad-anchor,
body.dxsp-body .ad-anchor {
	z-index: 15;
}

body.dxsp-body .qc-cmp2-persistent-link {
	z-index: 2147483640;
}
