/**
 * Nemcsakkártya - Kiegészítők: product grid cards.
 *
 * Scope: any element with the class "ath-formatted-wcm-col4" that contains a
 * WooCommerce "ul.products" list (Divi Shop module, Woo shortcode, etc.).
 * The markup is not touched; everything below is scoped to the wrapper.
 *
 * Customise per instance by overriding the custom properties on the wrapper,
 * e.g. in the Divi module's Custom CSS: --nckx-columns: 3;
 */

.ath-formatted-wcm-col4 {
	/* Brand colours (accent sampled from the site's buttons). */
	--nckx-accent: #770214;
	--nckx-accent-hover: #5a010f;
	--nckx-accent-soft: rgba(119, 2, 20, 0.07);
	--nckx-text: #2b2b2b;
	--nckx-text-muted: #6b6b6b;
	--nckx-card-bg: #ffffff;
	--nckx-card-border: #ece7e3;
	--nckx-star: #e09b1d;
	--nckx-star-light: #f7c64a;
	--nckx-star-empty: #ece3dd;
	--nckx-star-size: 16px;

	/* Outer panel (the element carrying the wrapper class). */
	--nckx-panel-bg: #faf6f3;
	--nckx-panel-border: #eadfd9;
	--nckx-panel-radius: 20px;
	--nckx-panel-padding: 28px;

	/* Layout. */
	--nckx-columns: 4;
	--nckx-card-min: 160px;
	--nckx-gap: 28px;
	--nckx-radius: 14px;
	--nckx-button-radius: 999px;
	--nckx-shadow: 0 2px 6px rgba(40, 20, 20, 0.05);
	--nckx-shadow-hover: 0 14px 32px rgba(60, 10, 20, 0.12);
}

/* ---------------------------------------------------------------------------
 * Panel: the wrapper itself becomes a soft framed box.
 * Replaces the border set in the Divi module's Design > Border settings
 * (ID-level specificity + !important beats Divi's generated module CSS).
 * Set --nckx-panel-bg: transparent and --nckx-panel-border: transparent on
 * an instance to drop the frame.
 * ------------------------------------------------------------------------ */

:is(#page-container, body) .ath-formatted-wcm-col4 {
	padding: var(--nckx-panel-padding) !important;
	border: 1px solid var(--nckx-panel-border) !important;
	border-radius: var(--nckx-panel-radius) !important;
	background-color: var(--nckx-panel-bg) !important;
	box-shadow: 0 1px 2px rgba(60, 20, 20, 0.04), 0 8px 24px rgba(60, 20, 20, 0.04);
}

/* ---------------------------------------------------------------------------
 * Grid: replace Divi/Woo float layout with CSS grid (equal-height rows).
 * ------------------------------------------------------------------------ */

/*
 * Divi and WooCommerce size the items with percentage widths and margins in
 * their own media queries (e.g. width: 47.25% !important below 980px). Inside
 * a grid cell those percentages shrink the cards into thin strips, so the
 * item box is reset with ID-level specificity + !important.
 */
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products {
	display: grid !important;
	/*
	 * Column count follows the real available width, not the viewport:
	 * at most --nckx-columns, but a column is dropped whenever a card would
	 * get narrower than --nckx-card-min (e.g. phone + wide page padding).
	 */
	grid-template-columns: repeat(
		auto-fill,
		minmax(
			min(100%, max(var(--nckx-card-min), (100% - (var(--nckx-columns) - 1) * var(--nckx-gap)) / var(--nckx-columns))),
			1fr
		)
	) !important;
	gap: var(--nckx-gap) !important;
	width: 100% !important;
	margin: 0 !important;
	padding: 0 !important;
	list-style: none;
}

/* Woo clearfix pseudo elements would become empty grid cells. */
.ath-formatted-wcm-col4 ul.products::before,
.ath-formatted-wcm-col4 ul.products::after {
	content: none;
	display: none;
}

/* ---------------------------------------------------------------------------
 * Card
 * ------------------------------------------------------------------------ */

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product {
	position: relative;
	display: flex;
	flex-direction: column;
	float: none !important;
	clear: none !important;
	width: auto !important;
	min-width: 0;
	max-width: none !important;
	margin: 0 !important;
	padding: 16px 16px 20px;
	background: var(--nckx-card-bg);
	border: 1px solid var(--nckx-card-border);
	border-radius: var(--nckx-radius);
	box-shadow: var(--nckx-shadow);
	transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.ath-formatted-wcm-col4 ul.products li.product:hover {
	transform: translateY(-4px);
	border-color: transparent;
	box-shadow: var(--nckx-shadow-hover);
}

/* Main link (image + title + rating + price) fills the card, buttons sit at the bottom. */
.ath-formatted-wcm-col4 ul.products li.product .woocommerce-loop-product__link {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	color: inherit;
	text-decoration: none;
}

/* ---------------------------------------------------------------------------
 * Image
 * ------------------------------------------------------------------------ */

.ath-formatted-wcm-col4 ul.products li.product .et_shop_image {
	display: block;
	overflow: hidden;
	margin: 0 0 16px;
	border-radius: calc(var(--nckx-radius) - 6px);
	background: #fff;
}

.ath-formatted-wcm-col4 ul.products li.product .et_shop_image img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 1 / 1;
	object-fit: contain;
	margin: 0;
	transition: transform 0.4s ease;
}

.ath-formatted-wcm-col4 ul.products li.product:hover .et_shop_image img {
	transform: scale(1.04);
}

/* Divi's dark hover overlay with icon is replaced by the zoom above. */
.ath-formatted-wcm-col4 ul.products li.product .et_overlay {
	display: none;
}

/* Out of stock: softened image. */
.ath-formatted-wcm-col4 ul.products li.product.outofstock .et_shop_image img {
	opacity: 0.75;
}

/* ---------------------------------------------------------------------------
 * Title, rating, price
 * ------------------------------------------------------------------------ */

.ath-formatted-wcm-col4 ul.products li.product .woocommerce-loop-product__title {
	margin: 0 0 8px;
	padding: 0;
	color: var(--nckx-text);
	font-size: 16px;
	font-weight: 600;
	line-height: 1.35;
	text-align: center;
	transition: color 0.2s ease;
}

.ath-formatted-wcm-col4 ul.products li.product:hover .woocommerce-loop-product__title {
	color: var(--nckx-accent);
}

/*
 * Star rating: the icon-font stars (WooCommerce / Divi ETmodules) are replaced
 * with an SVG star drawn through a CSS mask, in two layers:
 * ::before = empty track, span::before = filled part. WooCommerce sets the
 * span width (e.g. 96%) inline, so partial ratings still render correctly.
 * The label text stays in the DOM for screen readers (wrapper has role="img"
 * and aria-label), it is only hidden visually.
 */
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating {
	--nckx-star-cell: calc(var(--nckx-star-size) * 7 / 6);
	--nckx-star-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 24'%3E%3Cpath d='M12 1.6l3.09 6.26 6.91 1-5 4.87 1.18 6.88L12 17.36l-6.18 3.25L7 13.73 2 8.86l6.91-1z' stroke='%23000' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E");
	position: relative;
	display: block;
	float: none;
	overflow: hidden;
	/* Trailing gap of the last star is cut off so the row is optically centred. */
	width: calc(var(--nckx-star-cell) * 5 - var(--nckx-star-size) / 6);
	height: var(--nckx-star-size);
	/* !important: Divi forces "margin: 4px 0 .3em 0 !important" on .star-rating. */
	margin: 2px auto 10px !important;
	font-family: inherit;
	font-size: 0;
	line-height: 1;
	letter-spacing: 0;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating::before,
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating span::before {
	content: "" !important;
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	-webkit-mask: var(--nckx-star-mask) repeat-x left center / var(--nckx-star-cell) var(--nckx-star-size);
	mask: var(--nckx-star-mask) repeat-x left center / var(--nckx-star-cell) var(--nckx-star-size);
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating::before {
	width: 100%;
	background: var(--nckx-star-empty);
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating span {
	position: absolute;
	top: 0;
	left: 0;
	overflow: hidden;
	height: 100%;
	padding: 0;
	font-size: 0;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .star-rating span::before {
	width: calc(var(--nckx-star-cell) * 5);
	background: linear-gradient(180deg, var(--nckx-star-light) 0%, var(--nckx-star) 100%);
}

/* margin-top:auto keeps prices on one line across the row. */
.ath-formatted-wcm-col4 ul.products li.product .price {
	display: block;
	margin: auto 0 16px;
	padding-top: 4px;
	color: var(--nckx-accent);
	font-size: 18px;
	font-weight: 700;
	text-align: center;
}

.ath-formatted-wcm-col4 ul.products li.product .price del {
	color: var(--nckx-text-muted);
	font-size: 0.8em;
	font-weight: 400;
	opacity: 1;
}

.ath-formatted-wcm-col4 ul.products li.product .price ins {
	text-decoration: none;
}

/* ---------------------------------------------------------------------------
 * Buttons (add to cart / read more / back-in-stock notify)
 *
 * Divi's button rules (customizer + module settings) use ID selectors with
 * !important and change padding / border / font size on :hover, which made
 * the button height jump. ":is(#page-container, body)" always matches body,
 * but carries ID-level specificity, so these rules win on Divi and on any
 * other theme alike. Size-related properties are repeated for every state.
 * ------------------------------------------------------------------------ */

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button {
	display: block;
	width: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 10px 16px !important;
	border: 2px solid var(--nckx-accent) !important;
	border-radius: var(--nckx-button-radius) !important;
	background: var(--nckx-accent) !important;
	color: #fff !important;
	font-size: 15px !important;
	font-weight: 600;
	line-height: 1.3 !important;
	letter-spacing: 0.01em !important;
	text-align: center;
	text-decoration: none;
	text-transform: none;
	cursor: pointer;
	transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease !important;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button ~ .button {
	margin-top: 8px;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:hover,
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:focus,
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:active {
	padding: 10px 16px !important;
	border-width: 2px !important;
	font-size: 15px !important;
	line-height: 1.3 !important;
	letter-spacing: 0.01em !important;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:hover,
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:focus-visible {
	border-color: var(--nckx-accent-hover) !important;
	background: var(--nckx-accent-hover) !important;
	color: #fff !important;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:focus-visible {
	outline: 2px solid var(--nckx-accent);
	outline-offset: 3px;
}

/* Divi's hover arrow icon shifts the label; not needed on full-width buttons. */
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button::after,
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button::before {
	display: none !important;
	content: none !important;
}

/* Secondary style: "read more" on out-of-stock items and the notify-me button. */
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product.outofstock .button:not(.cwg_popup_submit) {
	border-color: var(--nckx-card-border) !important;
	background: transparent !important;
	color: var(--nckx-text) !important;
}

:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product.outofstock .button:not(.cwg_popup_submit):hover {
	border-color: var(--nckx-accent) !important;
	background: var(--nckx-accent-soft) !important;
	color: var(--nckx-accent) !important;
}

/* WooCommerce AJAX states. */
:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button.loading {
	opacity: 0.7;
	pointer-events: none;
}

.ath-formatted-wcm-col4 ul.products li.product .added_to_cart {
	display: block;
	margin-top: 8px;
	color: var(--nckx-accent);
	font-size: 14px;
	font-weight: 600;
	text-align: center;
}

/* ---------------------------------------------------------------------------
 * Responsive
 * ------------------------------------------------------------------------ */

@media (max-width: 980px) {
	.ath-formatted-wcm-col4 {
		--nckx-columns: 2;
		--nckx-gap: 20px;
		--nckx-panel-padding: 20px;
		--nckx-panel-radius: 16px;
	}
}

@media (max-width: 479px) {
	.ath-formatted-wcm-col4 {
		--nckx-gap: 12px;
		--nckx-panel-padding: 12px;
		--nckx-panel-radius: 14px;
	}

	:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product {
		padding: 10px 10px 14px;
	}

	.ath-formatted-wcm-col4 ul.products li.product .woocommerce-loop-product__title {
		font-size: 14px;
	}

	.ath-formatted-wcm-col4 ul.products li.product .price {
		font-size: 16px;
	}

	:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button,
	:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:hover,
	:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:focus,
	:is(#page-container, body) .ath-formatted-wcm-col4 ul.products li.product .button:active {
		padding: 9px 10px !important;
		font-size: 13px !important;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ath-formatted-wcm-col4 ul.products li.product,
	.ath-formatted-wcm-col4 ul.products li.product .et_shop_image img {
		transition: none;
	}

	.ath-formatted-wcm-col4 ul.products li.product:hover,
	.ath-formatted-wcm-col4 ul.products li.product:hover .et_shop_image img {
		transform: none;
	}
}
