/**
 * Negar Theme — reusable components.
 *
 *  1. Section header (title with the shared gold ornament)
 *  2. Slider arrows
 *  3. Product card
 *  4. Product rail (slider)
 *  5. Empty state & sample badge
 */

/* 1. Section header ------------------------------------------------------ */
/* Centred title block; the optional aside («مشاهده همه» + arrows) sits at the inline end on
 * ≥768px and below the title on phones. */
.section-header {
	display: grid;
	gap: var(--space-2) var(--space-4);
	margin-block-end: var(--space-5);
}

.section-header__text {
	min-width: 0;
	text-align: center;
}

.section-ornament {
	display: block;
	height: 1.25rem;
	margin-block-end: var(--space-1);
	color: var(--color-accent);
	line-height: 0;
}

.section-ornament .negar-ornament {
	width: 1.25rem;
	height: 1.25rem;
}

.section-title {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	max-width: 100%;
	margin: 0;
	color: var(--color-primary);
	font-size: var(--font-size-xl);
	font-weight: var(--font-weight-bold);
	line-height: 1.5;
}

.section-title__text {
	min-width: 0;
}

.section-title__flourish {
	flex-shrink: 0;
	color: var(--color-accent);
	line-height: 0;
}

.section-title__flourish .negar-ornament {
	width: 2rem;
	height: 0.5rem;
}

/* The flourish points away from the title on both sides. */
.section-title__flourish--end {
	transform: scaleX(-1);
}

.section-subtitle {
	margin: var(--space-1) 0 0;
	color: var(--color-text-muted);
	font-size: var(--font-size-sm);
	line-height: 1.8;
}

.section-header__aside {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: var(--space-3);
}

.section-link {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	min-height: var(--icon-button);
	color: var(--color-primary);
	font-size: var(--font-size-sm);
	font-weight: var(--font-weight-bold);
	line-height: 1;
	text-decoration: none;
	white-space: nowrap;
	transition: color var(--transition);
}

.section-link:hover {
	color: var(--color-gold-text);
}

.section-link .negar-icon {
	transition: transform var(--transition);
}

.section-link:hover .negar-icon--chevron-l {
	transform: translateX(-3px);
}

.section-link:hover .negar-icon--chevron-r {
	transform: translateX(3px);
}

@media (min-width: 480px) {
	.section-title__flourish .negar-ornament {
		width: 3rem;
		height: 0.75rem;
	}
}

@media (min-width: 768px) {
	.section-header {
		margin-block-end: var(--space-6);
	}

	.section-header--aside {
		grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
		align-items: end;
	}

	.section-header--aside .section-header__text {
		grid-column: 2;
	}

	.section-header--aside .section-header__aside {
		grid-column: 3;
		grid-row: 1;
		padding-block-end: var(--space-1);
	}
}

/* 2. Slider arrows ------------------------------------------------------- */
.slider-arrows {
	display: flex;
	align-items: center;
	gap: var(--space-2);
}

/* Round white buttons with a hairline and a soft shadow; navy on hover. */
.slider-arrow {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--icon-button);
	height: var(--icon-button);
	min-height: 0;
	padding: 0;
	border: 0;
	border-radius: var(--radius-pill);
	background: var(--color-white);
	box-shadow: var(--shadow-card);
	color: var(--color-primary);
	cursor: pointer;
	transition: background-color var(--transition), color var(--transition), box-shadow var(--transition), opacity var(--transition);
}

.slider-arrow:hover {
	background: var(--color-primary);
	box-shadow: 0 4px 14px rgb(34 44 90 / 0.18);
	color: var(--color-white);
}

.slider-arrow:active {
	transform: scale(0.96);
}

.slider-arrow .negar-icon {
	width: 18px;
	height: 18px;
}

.slider-arrow[disabled] {
	opacity: 0.35;
	cursor: default;
	pointer-events: none;
}

/* Header arrows on ≥768px; the copy below the cards on phones. */
.section-header__arrows {
	display: none;
}

.rail-controls {
	justify-content: center;
	margin-block-start: var(--space-4);
}

@media (min-width: 768px) {
	.section-header__arrows {
		display: flex;
	}

	.rail-controls {
		display: none;
	}
}

/* Nothing to scroll: no arrows at all. */
.is-static .slider-arrows {
	display: none;
}

/* 3. Product card -------------------------------------------------------- */
/* One card everywhere (template-parts/components/product-card.php): product archives, home
 * rails, related/upsell rails. Only the surrounding grid/rail differs.
 * White card on a whisper of shadow, a soft lift on hover; photo shown whole (contain) in a
 * fixed frame (1:1 phones, 5:6 ≥768px); title · specs · price · «مشاهده جزئیات» at the bottom,
 * so cards in a row share one height. */
.product-card {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	padding: var(--space-2);
	border-radius: var(--radius-md);
	background: var(--color-white);
	box-shadow: var(--shadow-card);
	transition: box-shadow 0.25s var(--ease-out), transform 0.25s var(--ease-out);
}

.product-card:hover {
	box-shadow: var(--shadow-card-hover);
	transform: translateY(-2px);
}

.product-card:focus-within {
	outline: 2px solid var(--color-focus);
	outline-offset: 2px;
}

.product-card__media {
	position: relative;
	overflow: hidden;
	aspect-ratio: 1;
	border-radius: var(--radius-sm);
	background: var(--color-background);
	/* Rounded corners stay clipped while the image scales (Safari). */
	isolation: isolate;
}

/* Two classes on purpose: WooCommerce core («.woocommerce-page img { height: auto }») would
 * otherwise win on shop pages, leave the photo at its natural height and let the frame crop it. */
.product-card__media .product-card__image {
	display: block;
	width: 100%;
	max-width: 100%;
	height: 100%;
	object-fit: contain;
	transition: transform 0.5s ease;
}

.product-card:hover .product-card__image {
	transform: scale(1.03);
}

.product-card__badge {
	position: absolute;
	inset-block-start: var(--space-2);
	inset-inline-start: var(--space-2);
	padding: 0.25rem 0.625rem;
	border-radius: var(--radius-pill);
	background: var(--color-accent);
	color: var(--color-footer);
	font-size: var(--font-size-2xs);
	font-weight: var(--font-weight-bold);
	line-height: 1.2;
}

.product-card__badge--muted {
	background: rgb(255 255 255 / 0.92);
	color: var(--color-text-muted);
}

.product-card__tag {
	position: absolute;
	inset-block-start: var(--space-2);
	inset-inline-end: var(--space-2);
	padding: 0.25rem 0.625rem;
	border-radius: var(--radius-pill);
	background: rgb(255 255 255 / 0.94);
	box-shadow: var(--shadow-xs);
	color: var(--color-text);
	font-size: var(--font-size-2xs);
	font-weight: var(--font-weight-bold);
	line-height: 1.2;
}

.product-card__body {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 0.125rem;
	padding: var(--space-3) var(--space-1) var(--space-1);
	text-align: center;
}

/* Titles: up to two lines. «.woocommerce ul.products li.product» gives every loop h3
 * «padding: .5em 0; font-size: 1em»; that padding let the clamped third line show through. */
.product-card__title,
.woocommerce ul.products li.product .product-card__title {
	display: -webkit-box;
	overflow: hidden;
	margin: 0;
	padding: 0;
	color: var(--color-text);
	font-size: 0.875rem;
	font-weight: var(--font-weight-bold);
	/* Anjoman's tall ascenders (1.07em) poke into a clamped box at tighter leading: at 1.9 the
	   hidden third line no longer bleeds through under the second. */
	line-height: 1.9;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
}

.product-card__link {
	color: inherit;
	text-decoration: none;
}

/* Stretched link: the whole card is clickable, but only one link is in the tab order. */
.product-card__link::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
}

.product-card__link:focus-visible {
	outline: none;
}

.product-card:hover .product-card__link {
	color: var(--color-primary);
}

.product-card__meta {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0 0.375rem;
	margin: 0;
	color: var(--color-text-muted);
	font-size: var(--font-size-2xs);
	line-height: 1.7;
}

.product-card__sep {
	opacity: 0.55;
}

.product-card__subtitle {
	margin: 0;
	overflow: hidden;
	color: var(--color-text-muted);
	font-size: var(--font-size-2xs);
	line-height: 1.7;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.product-card__price {
	margin: auto 0 0;
	padding-block-start: var(--space-1);
	color: var(--color-primary);
	font-size: 0.875rem;
	font-weight: var(--font-weight-bold);
}

.product-card__price del {
	margin-inline-end: var(--space-2);
	color: var(--color-text-muted);
	font-size: 0.75rem;
	font-weight: var(--font-weight-regular);
}

.product-card__price ins {
	text-decoration: none;
}

.product-card__cta {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-1);
	align-self: center;
	width: 100%;
	min-height: 2.125rem;
	margin-block-start: var(--space-2);
	padding: 0 var(--space-2);
	border: 1px solid rgb(34 44 90 / 0.3);
	border-radius: var(--radius-sm);
	color: var(--color-primary);
	font-size: var(--font-size-xs);
	font-weight: var(--font-weight-bold);
	line-height: 1;
	white-space: nowrap;
	transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.product-card__cta .negar-icon {
	flex: 0 0 auto;
	width: 14px;
	height: 14px;
	transition: transform var(--transition);
}

.product-card:hover .product-card__cta {
	border-color: var(--color-primary);
	background: var(--color-primary);
	color: var(--color-white);
}

.product-card:hover .product-card__cta .negar-icon {
	transform: translateX(-3px);
}

@media (min-width: 768px) {
	.product-card {
		padding: 0.625rem;
	}

	.product-card__media {
		aspect-ratio: 5 / 6;
	}

	.product-card__body {
		padding: var(--space-4) var(--space-3) var(--space-2);
	}

	.product-card__title,
	.woocommerce ul.products li.product .product-card__title {
		font-size: var(--font-size-base);
	}

	.product-card__meta,
	.product-card__subtitle {
		font-size: var(--font-size-xs);
	}

	.product-card__price {
		font-size: var(--font-size-base);
	}

	.product-card__cta {
		width: 84%;
		min-height: 2.375rem;
		margin-block-start: var(--space-3);
		font-size: var(--font-size-sm);
	}

	.product-card__tag {
		inset-block-start: var(--space-3);
		inset-inline-end: var(--space-3);
		font-size: var(--font-size-xs);
	}
}

/* 4. Product rail -------------------------------------------------------- */
/* Vertical cards in every width; never full-width horizontal cards on phones. Widths follow the
 * archive grid so the shared card looks the same in both (two columns on phones there):
 *   <480px: ~1.8 cards · 480–767: ~2.6 · 768–1023: 3 · ≥1024: 4.
 * Arrows never take width from the cards (header row on ≥768px, below the cards on phones). */
.product-rail {
	--rail-gap: var(--space-3);
	--rail-card: calc((100% - var(--rail-gap)) / 1.8);

	position: relative;
}

@media (min-width: 480px) {
	.product-rail {
		--rail-card: calc((100% - 2 * var(--rail-gap)) / 2.6);
	}
}

@media (min-width: 768px) {
	.product-rail {
		--rail-gap: var(--space-5);
		--rail-card: calc((100% - 2 * var(--rail-gap)) / 3);
	}
}

@media (min-width: 1024px) {
	.product-rail {
		--rail-card: calc((100% - 3 * var(--rail-gap)) / 4);
	}
}

.product-rail__viewport {
	overflow-x: auto;
	overscroll-behavior-x: contain;
	/* Room for the card shadow and hover lift without shifting the layout. */
	margin-block: calc(-1 * var(--space-4));
	padding-block: var(--space-4);
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}

.product-rail__viewport::-webkit-scrollbar {
	display: none;
}

.product-rail__viewport:focus-visible {
	outline: 2px solid var(--color-focus);
	outline-offset: 2px;
	border-radius: var(--radius-md);
}

.product-rail__track {
	display: grid;
	grid-auto-columns: var(--rail-card);
	grid-auto-flow: column;
	gap: var(--rail-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.product-rail__item {
	scroll-snap-align: start;
}

/* Loop slider (main.js): clipped viewport, track moved with a transform. */
.product-rail.is-loop .product-rail__viewport {
	overflow: hidden;
	scroll-snap-type: none;
	touch-action: pan-y;
}

.product-rail.is-loop .product-rail__track {
	transition: transform 0.5s var(--ease-out);
	will-change: transform;
}

/* While dragging: follow the pointer 1:1 and do not select text or drag images. */
.is-dragging [data-slider-track],
.is-dragging.hero .hero__track {
	transition: none !important;
}

.is-loop [data-slider-track],
.is-loop .design-grid {
	cursor: grab;
	-webkit-user-select: none;
	user-select: none;
}

.is-dragging [data-slider-track],
.is-dragging .design-grid {
	cursor: grabbing;
}

.is-loop [data-slider-track] img,
.is-loop .design-grid img {
	-webkit-user-drag: none;
}

/* 5. Empty state & sample badge ----------------------------------------- */
.empty-state {
	display: grid;
	gap: var(--space-4);
	padding: var(--space-7) var(--space-5);
	border-radius: var(--radius-md);
	background: var(--color-section);
	text-align: center;
}

.empty-state__text {
	margin: 0;
	color: var(--color-text-muted);
}

/* Marks preview-only sample content (visible to administrators only). */
.sample-badge {
	display: inline-block;
	margin-block-end: var(--space-2);
	padding: 0.2rem 0.625rem;
	border: 1px dashed var(--color-primary);
	border-radius: var(--radius-pill);
	background: var(--color-white);
	color: var(--color-primary);
	font-size: var(--font-size-2xs);
	font-weight: var(--font-weight-bold);
	line-height: 1.4;
}
