/*
 * Spare Parts Manager — Frontend Product Grid
 * Plugin: spare-parts-manager
 * Version: 1.0.1  (added gallery badge + click-cursor)
 *
 * Table of contents:
 *   1. CSS custom properties (design tokens)
 *   2. Grid wrapper
 *   3. Product card
 *   4. Card image + gallery badge
 *   5. Card body (title, description, CTA button)
 *   6. Empty state
 *   7. Responsive breakpoints
 */

/* ── 1. Design tokens ──────────────────────────────────────────────────────── */
:root {
	--spm-gap:          24px;
	--spm-radius:       12px;
	--spm-shadow:       0 4px 20px rgba(0, 0, 0, .08);
	--spm-shadow-hover: 0 12px 32px rgba(0, 0, 0, .16);
	--spm-accent:       #F00000;
	--spm-accent-dark:  #cc0000;
	--spm-text:         #1a1a2e;
	--spm-muted:        #6b7280;
	--spm-bg-card:      #ffffff;
	--spm-img-bg:       #f3f4f6;
	--spm-transition:   0.25s ease;
}

/* ── 2. Grid wrapper ───────────────────────────────────────────────────────── */
.spm-grid {
	display: grid;
	gap: var(--spm-gap);
	padding: 0;
	margin: 0;
	list-style: none;
}

.spm-columns-1 { grid-template-columns: 1fr; }
.spm-columns-2 { grid-template-columns: repeat(2, 1fr); }
.spm-columns-3 { grid-template-columns: repeat(3, 1fr); }
.spm-columns-4 { grid-template-columns: repeat(4, 1fr); }

/* ── 3. Product card ───────────────────────────────────────────────────────── */
.spm-card {
	display: flex;
	flex-direction: column;
	background: var(--spm-bg-card);
	border-radius: var(--spm-radius);
	box-shadow: var(--spm-shadow);
	overflow: hidden;
	cursor: pointer;      /* Whole card is clickable → popup */
	transition: transform var(--spm-transition), box-shadow var(--spm-transition);
	outline-offset: 3px;
}

.spm-card:hover {
	transform: translateY(-5px);
	box-shadow: var(--spm-shadow-hover);
}

.spm-card:focus-visible {
	outline: 3px solid var(--spm-accent);
}

/* ── 4. Card image + gallery badge ─────────────────────────────────────────── */
.spm-card__image-link {
	display: block;
	overflow: hidden;
	flex-shrink: 0;
	position: relative;   /* Anchor for the gallery-count badge */
	aspect-ratio: 4 / 3;
	background: var(--spm-img-bg);
}

.spm-card__image {
	display: block;
	width: 100% !important;
	height: 100% !important;
	object-fit: cover;
	object-position: center;
	transition: transform var(--spm-transition);
}

.spm-card:hover .spm-card__image {
	transform: scale(1.05);
}

/* Placeholder when no image is set */
.spm-card__image--placeholder {
	background: var(--spm-img-bg)
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E")
		center / 48px no-repeat;
	width: 100%;
	height: 100%;
}

/* Gallery image-count badge (bottom-right of image) */
.spm-card__count {
	position: absolute;
	bottom: 10px;
	right: 10px;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.55);
	backdrop-filter: blur(4px);
	color: #fff;
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.03em;
	pointer-events: none;  /* Clicks pass through to the card */
}

.spm-card__count svg {
	flex-shrink: 0;
}

/* ── 5. Card body ──────────────────────────────────────────────────────────── */
.spm-card__body {
	display: flex;
	flex-direction: column;
	height: 210px;        /* Fixed height for content area */
	box-sizing: border-box;
	padding: 20px 22px 24px;
}

/* Title */
.spm-card__title {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	line-height: 1.35;
	color: var(--spm-text);
	/* Clamp to 2 lines for uniform text alignment */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	height: 2.7em;
}

/* Description teaser */
.spm-card__desc {
	margin: 10px 0 0;
	font-size: 0.9rem;
	line-height: 1.5;
	color: var(--spm-muted);
	/* Clamp to 3 lines for uniform text alignment */
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	height: 4.5em;
}

/* CTA pill — positioned at the bottom and centered */
.spm-card__cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin-top: auto;      /* Push to the bottom */
	align-self: center;    /* Center horizontally */
	padding: 9px 24px;
	border-radius: 999px;
	background: var(--spm-accent);
	color: #fff;
	font-size: 0.85rem;
	font-weight: 600;
	text-decoration: none;
	letter-spacing: 0.02em;
	pointer-events: none;  /* Card click opens popup */
	transition: background var(--spm-transition), box-shadow var(--spm-transition), transform var(--spm-transition);
}

.spm-card:hover .spm-card__cta {
	background: var(--spm-accent-dark);
	box-shadow: 0 6px 16px rgba(240, 0, 0, 0.35);
}

/* ── 6. Empty state ────────────────────────────────────────────────────────── */
.spm-no-products {
	color: var(--spm-muted);
	font-style: italic;
	text-align: center;
	padding: 40px 0;
}

/* ── 7. Load More Visibility & Animations ───────────────────────────────────── */

/* Hide cards from 4th child onwards by default if JS is active */
.spm-grid.spm-grid--js .spm-card.spm-card--hidden {
	display: none !important;
}

/* Entrance animation for newly visible cards */
@keyframes spmFadeSlideIn {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.spm-card.spm-card--visible {
	animation: spmFadeSlideIn 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* ── 8. Load More Button ────────────────────────────────────────────────────── */
.spm-load-more-container {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 14px;
	flex-wrap: wrap;
	margin-top: 40px;
	margin-bottom: 20px;
	width: 100%;
}

.spm-load-more-btn[hidden] { display: none !important; }

.spm-load-more-btn--less {
	background: #ffffff;
	color: #F00000;
	border: 2px solid #F00000;
	box-shadow: 0 4px 12px rgba(240, 0, 0, 0.12);
}

.spm-load-more-btn--less:hover {
	background: #F00000;
	color: #ffffff;
}

.spm-load-more-btn {
	background: #F00000;
	color: #ffffff;
	border: none;
	padding: 12px 32px;
	font-size: 0.95rem;
	font-weight: 600;
	border-radius: 6px;   /* Slightly rounded corners */
	cursor: pointer;
	box-shadow: 0 4px 12px rgba(240, 0, 0, 0.2);
	transition: background-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
	outline: none;
}

.spm-load-more-btn:hover {
	background: #cc0000;
	transform: translateY(-2px);
	box-shadow: 0 8px 20px rgba(240, 0, 0, 0.35);
}

.spm-load-more-btn:active {
	transform: translateY(0);
	box-shadow: 0 4px 10px rgba(240, 0, 0, 0.25);
}

.spm-load-more-btn:focus-visible {
	outline: 3px solid rgba(240, 0, 0, 0.4);
	outline-offset: 2px;
}

/* ── 9. Responsive breakpoints ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
	.spm-columns-4 { grid-template-columns: repeat(2, 1fr); }
	.spm-columns-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
	.spm-columns-4,
	.spm-columns-3,
	.spm-columns-2 { grid-template-columns: 1fr; }

	.spm-card__image-link { aspect-ratio: 4 / 3; }
}
