/**
 * Essential Addons product grid – masonry fallback.
 *
 * Source of the problem: the "Woo Product Grid" widget's Layout control
 * defaulted to `grid` in older Essential Addons releases and now defaults to
 * `masonry`. Widgets built before that change have no saved layout value, so
 * they inherit the new default.
 *
 * The primary fix lives in `inc/eael-product-grid-compat.php`, which restores
 * `grid` before the widget renders. This file is only a safety net: it
 * neutralises masonry markup in case it is produced anyway (saved masonry
 * layout, or markup cached before the module was enabled).
 *
 * Design notes:
 *  - `ul.products` is put back into a CSS grid so cards share equal rows.
 *  - The clearfix pseudo-elements are removed because EAEL's masonry rules
 *    turn them into grid items, shifting every card one cell to the right and
 *    wrapping the last card onto its own row.
 *  - Isotope leaves inline `position:absolute`, `left`, `top` and
 *    `translate3d()` behind, so those are cleared to let the grid place the
 *    cards.
 *  - Column counts are intentionally NOT set here; they still come from
 *    EAEL's own `.eael-product-grid-column-*` utility classes so tablet and
 *    mobile breakpoints keep working.
 */

.eael-product-grid.masonry .woocommerce ul.products,
.eael-post-grid.masonry .woocommerce ul.products {
	display: grid !important;
	position: static !important;
	height: auto !important;
	margin: 0 0 15px 0 !important;
	grid-gap: 25px !important;
}

.eael-product-grid.masonry .woocommerce ul.products::before,
.eael-product-grid.masonry .woocommerce ul.products::after,
.eael-post-grid.masonry .woocommerce ul.products::before,
.eael-post-grid.masonry .woocommerce ul.products::after {
	display: none !important;
	content: none !important;
}

body .eael-product-grid.masonry .woocommerce ul.products li.product,
body .eael-post-grid.masonry .woocommerce ul.products li.product {
	position: relative !important;
	left: auto !important;
	top: auto !important;
	float: none !important;
	width: 100% !important;
	height: auto !important;
	min-width: 0 !important;
	margin: 0 !important;
	transform: none !important;
	transition: none !important;
}

/* Let every card fill its stretched grid row so the boxes end level. */
.eael-product-grid.masonry .woocommerce ul.products li.product .eael-product-wrap {
	height: 100%;
}

/*
 * Homepage responsive grids.
 *
 * The imported widgets are configured for 3 tablet / 2 mobile columns, but
 * EAEL's masonry script writes desktop pixel widths (up to 1560px) directly
 * onto the list. Respect the saved responsive intent and keep all card
 * presentation changes isolated to the front page.
 */
@media (max-width: 1024px) {
	body.home .eael-product-grid.masonry .woocommerce ul.products,
	body.home .eael-post-grid.masonry .woocommerce ul.products {
		width: 100% !important;
		max-width: 100% !important;
		grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
		gap: 18px !important;
	}
}

@media (max-width: 767px) {
	body.home .eael-product-grid.masonry,
	body.home .eael-post-grid.masonry {
		box-sizing: border-box;
		padding-right: 12px;
		padding-left: 12px;
	}

	body.home .eael-product-grid.masonry,
	body.home .eael-post-grid.masonry,
	body.home .eael-product-grid.masonry .woocommerce,
	body.home .eael-post-grid.masonry .woocommerce {
		width: 100%;
		max-width: 100%;
		overflow: visible !important;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products,
	body.home .eael-post-grid.masonry .woocommerce ul.products {
		width: 100% !important;
		max-width: 100% !important;
		grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
		gap: 16px 12px !important;
		margin-bottom: 0 !important;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product {
		display: flex !important;
		width: auto !important;
		min-width: 0 !important;
		height: 100% !important;
		margin: 0 !important;
		overflow: hidden;
		border: 1px solid #ebe5df !important;
		border-radius: 9px;
		background: #fff;
		box-shadow: 0 6px 18px rgba(47, 39, 31, 0.07) !important;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .eael-product-wrap,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .eael-product-wrap {
		display: flex;
		flex: 1;
		flex-direction: column;
		width: 100%;
		height: 100%;
		overflow: hidden;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .eael-product-wrap > img,
	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .velis-product-image-link > img,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .eael-product-wrap > img,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .velis-product-image-link > img {
		display: block;
		width: 100% !important;
		height: auto !important;
		margin: 0 !important;
		aspect-ratio: 1 / 1;
		object-fit: contain;
		background: #f7f4f1;
	}

	body.home .eael-product-grid.masonry .velis-product-image-link,
	body.home .eael-post-grid.masonry .velis-product-image-link {
		display: flex;
		width: 100%;
		line-height: 0;
		cursor: pointer;
	}

	/* Make the whole rendered image area behave as one consistent link target. */
	body.home .eael-product-grid.masonry .velis-product-image-link > img,
	body.home .eael-post-grid.masonry .velis-product-image-link > img {
		pointer-events: none;
	}

	body.home .eael-product-grid.masonry .eael-product-title,
	body.home .eael-post-grid.masonry .eael-product-title {
		display: flex;
		height: auto !important;
		min-height: 68px;
	}

	body.home .eael-product-grid.masonry .woocommerce-loop-product__link,
	body.home .eael-post-grid.masonry .woocommerce-loop-product__link {
		display: flex;
		width: 100%;
		height: auto !important;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .woocommerce-loop-product__title,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .woocommerce-loop-product__title {
		display: -webkit-box;
		width: 100%;
		height: auto !important;
		min-height: 54px;
		margin: 0 !important;
		padding: 12px 10px 8px !important;
		overflow: hidden;
		font-size: 12.5px !important;
		font-weight: 500 !important;
		line-height: 1.42 !important;
		text-align: left;
		text-transform: none !important;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
	}

	body.home .eael-product-grid.masonry .eael-product-price,
	body.home .eael-post-grid.masonry .eael-product-price {
		display: flex;
		align-items: baseline;
		flex-wrap: wrap;
		gap: 3px 7px;
		width: 100%;
		height: auto !important;
		min-height: 38px;
		margin-top: auto;
		padding: 0 10px 8px;
		text-align: left;
	}

	body.home .eael-product-grid.masonry .eael-product-price del,
	body.home .eael-product-grid.masonry .eael-product-price ins,
	body.home .eael-post-grid.masonry .eael-product-price del,
	body.home .eael-post-grid.masonry .eael-product-price ins {
		display: inline-flex !important;
		width: auto !important;
		margin: 0 !important;
		text-align: left !important;
	}

	body.home .eael-product-grid.masonry .eael-product-price .woocommerce-Price-amount,
	body.home .eael-post-grid.masonry .eael-product-price .woocommerce-Price-amount {
		display: inline-flex;
		width: auto !important;
		margin: 0 !important;
		font-size: 14px !important;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .button,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .button {
		display: inline-flex !important;
		align-items: center;
		justify-content: center;
		width: calc(100% - 20px) !important;
		min-height: 40px;
		margin: 4px 10px 12px !important;
		padding: 9px 10px !important;
		border-radius: 999px !important;
		font-size: 12px !important;
		line-height: 1.2 !important;
		text-align: center;
	}

	body.home .eael-product-grid.masonry .woocommerce ul.products > li.product .onsale,
	body.home .eael-post-grid.masonry .woocommerce ul.products > li.product .onsale {
		top: 8px !important;
		right: 8px !important;
		left: auto !important;
		width: auto !important;
		min-width: 0 !important;
		padding: 6px 8px !important;
		border-radius: 999px !important;
		font-size: 10px !important;
		line-height: 1 !important;
	}
}

@media (max-width: 339px) {
	body.home .eael-product-grid.masonry .woocommerce ul.products,
	body.home .eael-post-grid.masonry .woocommerce ul.products {
		grid-template-columns: minmax(0, 1fr) !important;
	}
}
