/* ==========================================================================
   CUSTOM PRODUCT DISPLAY
   ========================================================================== */

/* Host
   ========================================================================== */

:host {
	display: block;
	--cpd-cols: 4;
	--cpd-cols-tablet: 2;
	--cpd-gap: 1.5rem;
	--cpd-card-radius: 0.375rem;
	--cpd-card-bg: var(--mmx-color-surface, #ffffff);
	--cpd-card-border: var(--mmx-color-border, #e5e7eb);
	--cpd-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
	--cpd-card-shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.12);
	--cpd-card-name-color: var(--mmx-color-text-primary, #111827);
	--cpd-card-price-color: var(--mmx-color-primary, #1d4ed8);
	--cpd-card-desc-color: var(--mmx-color-text-secondary, #6b7280);
	--cpd-badge-bg: var(--mmx-color-primary, #1d4ed8);
	--cpd-badge-color: #ffffff;
	--cpd-image-bg: var(--mmx-color-surface-alt, #f3f4f6);
	--cpd-transition: 200ms ease;
}

/* Wrapper
   ========================================================================== */

.cpd {
	width: 100%;
}

/* Grid
   ========================================================================== */

.cpd__grid {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(var(--cpd-cols), minmax(0, 1fr));
	gap: var(--cpd-gap);
}

@media screen and (max-width: 1024px) {
	.cpd__grid {
		grid-template-columns: repeat(var(--cpd-cols-tablet), minmax(0, 1fr));
	}
}

@media screen and (max-width: 580px) {
	.cpd__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.875rem;
	}
}

@media screen and (max-width: 360px) {
	.cpd__grid {
		grid-template-columns: 1fr;
	}
}

/* Card
   ========================================================================== */

.cpd__card {
	display: flex;
	flex-direction: column;
}

.cpd__card-link {
	display: flex;
	flex-direction: column;
	height: 100%;
	background-color: var(--cpd-card-bg);
	border: 1px solid var(--cpd-card-border);
	border-radius: var(--cpd-card-radius);
	box-shadow: var(--cpd-card-shadow);
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	transition: box-shadow var(--cpd-transition), transform var(--cpd-transition);
}

.cpd__card-link:hover,
.cpd__card-link:focus-visible {
	box-shadow: var(--cpd-card-shadow-hover);
	transform: translateY(-2px);
	outline: none;
}

.cpd__card-link:focus-visible {
	outline: 2px solid var(--mmx-color-focus, #2563eb);
	outline-offset: 2px;
}

/* Card Image
   ========================================================================== */

.cpd__card-image-wrap {
	position: relative;
	width: 100%;
	padding-top: 100%; /* 1:1 aspect ratio */
	background-color: var(--cpd-image-bg);
	overflow: hidden;
}

.cpd__card-image {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	object-position: center;
	transition: transform var(--cpd-transition);
}

.cpd__card-link:hover .cpd__card-image {
	transform: scale(1.04);
}

.cpd__card-image--placeholder {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Crect width='80' height='80' fill='%23f3f4f6'/%3E%3Cpath d='M30 28h20a4 4 0 0 1 4 4v16a4 4 0 0 1-4 4H30a4 4 0 0 1-4-4V32a4 4 0 0 1 4-4zm10 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8zm-9 18 5-6 3 4 4-5 6 7H31z' fill='%23d1d5db'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 40%;
}

/* Inventory Badge
   ========================================================================== */

.cpd__card-badge {
	position: absolute;
	top: 0.5rem;
	left: 0.5rem;
	padding: 0.2rem 0.5rem;
	background-color: var(--cpd-badge-bg);
	color: var(--cpd-badge-color);
	border-radius: 0.25rem;
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	line-height: 1.4;
}

/* Card Body
   ========================================================================== */

.cpd__card-body {
	flex: 1 1 auto;
	padding: 0.875rem 0.875rem 0.5rem;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.cpd__card-name {
	margin: 0;
	font-size: 0.9375rem;
	font-weight: 600;
	color: var(--cpd-card-name-color);
	line-height: 1.35;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.cpd__card-price {
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
	color: var(--cpd-card-price-color);
}

.cpd__card-desc {
	margin: 0.25rem 0 0;
	font-size: 0.8125rem;
	color: var(--cpd-card-desc-color);
	line-height: 1.5;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* Card Footer
   ========================================================================== */

.cpd__card-footer {
	padding: 0.5rem 0.875rem 0.875rem;
}

.cpd__card-footer mmx-button {
	width: 100%;
}

/* Loading State
   ========================================================================== */

.cpd__loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	padding: 3rem 1rem;
	color: var(--mmx-color-text-secondary, #6b7280);
	font-size: 0.9375rem;
}

.cpd__loading-spinner {
	display: inline-block;
	width: 1.25rem;
	height: 1.25rem;
	border: 2px solid var(--mmx-color-border, #e5e7eb);
	border-top-color: var(--mmx-color-primary, #1d4ed8);
	border-radius: 50%;
	animation: cpd-spin 0.7s linear infinite;
}

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

/* Empty & Error States
   ========================================================================== */

.cpd__empty,
.cpd__error {
	text-align: center;
	padding: 2rem 1rem;
	margin: 0;
	color: var(--mmx-color-text-secondary, #6b7280);
	font-size: 0.9375rem;
}

.cpd__error {
	color: var(--mmx-color-error, #dc2626);
}
