/**
 * DevThrives Product Grid — front-end styles.
 * Class names are prefixed with "dtpg-" to avoid clashing with WoodMart's
 * own theme classes. A handful of !important rules are used only where
 * WoodMart/WordPress core tends to apply broad resets (images, lists,
 * link colors) that would otherwise leak into the widget.
 */

.dtpg-wrapper {
	width: 100%;
	position: relative;
}

/* AJAX in flight: dim the grid instead of blocking it, so the change never
   looks like a broken click. */
.dtpg-wrapper.dtpg-loading .dtpg-grid-wrap {
	opacity: 0.45;
	pointer-events: none;
	transition: opacity 0.15s ease;
}

/* ---------- Toolbar / sorting ---------- */

.dtpg-toolbar {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 16px;
	margin: 0 0 20px;
}

.dtpg-result-count {
	margin: 0 auto 0 0;
	font-size: 14px;
	color: #666;
}

.dtpg-sorting-form {
	display: inline-block;
}

.dtpg-orderby {
	padding: 8px 32px 8px 12px;
	border: 1px solid #e0e0e0;
	border-radius: 2px;
	font-size: 14px;
	line-height: 1.4;
	color: #333;
	background-color: #fff;
	cursor: pointer;
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16'%3E%3Cpath fill='%23666666' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 8px center;
}

.dtpg-sort-submit {
	margin-left: 8px;
}

/* ---------- Grid ---------- */

.dtpg-grid {
	display: grid;
	grid-template-columns: repeat(var(--dtpg-cols, 4), 1fr);
	gap: 20px;
}

.dtpg-card {
	display: flex;
	flex-direction: column;
	background: #fff;
	border: 1px solid #eee;
	border-radius: 4px;
	overflow: hidden;
	box-sizing: border-box;
	transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

/* ---------- Image + hover swap (pure CSS, no JS) ---------- */

.dtpg-image-wrap {
	position: relative;
	display: block;
	width: 100%;
	aspect-ratio: var(--dtpg-ratio, 1/1);
	overflow: hidden;
	background-color: #f7f7f7;
}

.dtpg-image-link {
	display: block;
	width: 100%;
	height: 100%;
}

.dtpg-image {
	position: absolute !important;
	top: 0 !important;
	left: 0 !important;
	width: 100% !important;
	height: 100% !important;
	max-width: 100% !important;
	margin: 0 !important;
	object-fit: cover !important;
	/* Fast by default — this is what applies the instant the pointer
	   LEAVES the card, so reverting to the main photo feels snappy. */
	transition: opacity 0.25s ease;
}

.dtpg-image-hover {
	opacity: 0;
}

/*
 * Gated behind .dtpg-has-hover-image (added server-side only when the
 * product actually has a gallery photo to swap to). Without this gate,
 * hovering a product with NO gallery image would still fade the only
 * photo it has down to nothing, revealing blank background — this class
 * is what makes the hover effect correctly do nothing on those products.
 */
.dtpg-image-wrap.dtpg-has-hover-image:hover .dtpg-image-main,
.dtpg-image-wrap.dtpg-has-hover-image:hover .dtpg-image-hover {
	/* Slower + slightly delayed on the way IN, so the swap reads as a
	   deliberate reveal rather than a flicker. */
	transition: opacity 0.6s ease 0.1s;
}

.dtpg-image-wrap.dtpg-has-hover-image:hover .dtpg-image-main {
	opacity: 0;
}

.dtpg-image-wrap.dtpg-has-hover-image:hover .dtpg-image-hover {
	opacity: 1;
}

/* ---------- Badges ---------- */

.dtpg-badge {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	height: 44px;
	padding: 0 6px;
	border-radius: 50%;
	font-size: 13px;
	font-weight: 600;
	line-height: 1;
	box-sizing: border-box;
}

.dtpg-badge-sale {
	background-color: #e2231a;
	color: #fff !important;
}

.dtpg-badge-soldout {
	background-color: #fff;
	color: #222 !important;
	border: 1px solid #eee;
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

/* ---------- Content ---------- */

.dtpg-content {
	display: flex;
	flex-direction: column;
	gap: 8px;
	flex-grow: 1;
	padding: 16px;
}

.dtpg-title {
	margin: 0;
	font-size: 15px;
	font-weight: 500;
	line-height: 1.4;
}

.dtpg-title a {
	color: #333;
	text-decoration: none !important;
}

.dtpg-title a:hover {
	color: #a02128;
}

.dtpg-price {
	font-size: 15px;
}

.dtpg-price del {
	margin-right: 6px;
	color: #999;
	font-weight: 400;
	text-decoration: line-through;
	opacity: 0.7;
}

.dtpg-price ins {
	color: #a02128;
	font-weight: 600;
	text-decoration: none !important;
}

/* ---------- Variation swatches ---------- */

.dtpg-swatch-groups {
	display: flex;
	flex-direction: column;
	gap: 4px;
	position: relative;
	transition: opacity 0.15s ease;
}

.dtpg-swatch-groups.dtpg-swatch-loading {
	opacity: 0.55;
	pointer-events: none;
}

.dtpg-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin: 4px 0;
}

.dtpg-swatch {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	min-width: 36px;
	height: 32px !important;
	padding: 0 8px;
	border: 1px solid #ddd;
	border-radius: 2px;
	font-size: 13px;
	color: #444;
	background-color: #fff;
	text-decoration: none !important;
	cursor: pointer;
	font-family: inherit;
	transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.dtpg-swatch:hover {
	border-color: #a02128;
	color: #a02128;
}

.dtpg-swatch-selected {
	background-color: #a02128;
	border-color: #a02128;
	color: #fff !important;
}

.dtpg-swatch-disabled {
	color: #ccc;
	border-color: #eee;
	text-decoration: line-through !important;
	cursor: not-allowed;
}

.dtpg-swatch-message {
	margin: 2px 0 0;
	font-size: 12px;
	color: #666;
}

.dtpg-swatch-message-error {
	color: #c0392b;
}

/* ---------- Order Now button ---------- */

.dtpg-order-btn {
	display: block;
	box-sizing: border-box;
	width: 100%;
	margin-top: auto;
	padding: 12px 16px;
	border: 1px solid #a02128;
	border-radius: 2px;
	background-color: #a02128;
	color: #fff !important;
	text-align: center;
	text-decoration: none !important;
	font-size: 14px;
	font-weight: 600;
	transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dtpg-order-btn:hover {
	background-color: #841b21;
	border-color: #841b21;
	color: #fff !important;
}

.dtpg-sold-out .dtpg-order-btn {
	opacity: 0.6;
}

/* ---------- Empty state ---------- */

.dtpg-no-products,
.dtpg-infinite-end {
	padding: 40px 0;
	text-align: center;
	color: #999;
}

/* ---------- Pagination: shared ---------- */

.dtpg-pagination-wrap {
	display: flex;
	justify-content: center;
	margin-top: 30px;
}

.dtpg-pagination {
	display: flex;
	align-items: center;
	gap: 6px;
}

.dtpg-page-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	height: 36px;
	padding: 0 10px;
	border: 1px solid #e0e0e0;
	border-radius: 2px;
	background-color: #fff;
	color: #444;
	text-decoration: none !important;
	font-size: 14px;
	font-family: inherit;
	cursor: pointer;
	box-sizing: border-box;
	transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.dtpg-page-link:hover:not(.dtpg-page-current):not(:disabled) {
	border-color: #a02128;
	color: #a02128;
}

.dtpg-page-link:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.dtpg-page-current {
	background-color: #a02128;
	border-color: #a02128;
	color: #fff !important;
	cursor: default;
}

.dtpg-page-ellipsis {
	color: #999;
	padding: 0 2px;
}

/* ---------- Pagination: Load on Click ---------- */

.dtpg-load-more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 160px;
	padding: 12px 24px;
	border: 1px solid #a02128;
	border-radius: 2px;
	background-color: #a02128;
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	font-family: inherit;
	cursor: pointer;
	transition: background-color 0.3s ease, border-color 0.3s ease;
}

.dtpg-load-more:hover {
	background-color: #841b21;
	border-color: #841b21;
}

.dtpg-wrapper.dtpg-loading .dtpg-load-more {
	opacity: 0.6;
	pointer-events: none;
}

/* ---------- Pagination: Infinite Scroll ---------- */

.dtpg-infinite-sentinel {
	width: 100%;
	height: 1px;
}

.dtpg-infinite-loader {
	display: none;
	width: 100%;
	justify-content: center;
	padding: 10px 0;
}

.dtpg-wrapper.dtpg-loading .dtpg-infinite-loader {
	display: flex;
}

.dtpg-infinite-loader::before {
	content: "";
	width: 22px;
	height: 22px;
	border: 2px solid rgba(160, 33, 40, 0.25);
	border-top-color: #a02128;
	border-radius: 50%;
	animation: dtpg-spin 0.7s linear infinite;
}

@keyframes dtpg-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.dtpg-image,
	.dtpg-card,
	.dtpg-swatch,
	.dtpg-page-link,
	.dtpg-order-btn,
	.dtpg-load-more {
		transition-duration: 0.01ms !important;
	}

	.dtpg-infinite-loader::before {
		animation-duration: 1.4s;
	}
}
