/*
 * RahkarTheme — rahkar/products-slider (frontend + shared).
 *
 * The card visuals come from the shared rahkar-product-card stylesheet
 * (.rpc-card*). This file only owns slider-level concerns:
 *
 *   • track layout: flex row + CSS scroll-snap
 *   • arrow buttons (desktop + mobile)
 *   • "view all" tail item
 *   • heading + responsive scaling
 *
 * Design choices:
 *   • Item width is derived from `--rps-cols` (desktop) and `--rps-mob`
 *     (mobile fractional). Touch users can still swipe; arrows are an
 *     additional affordance, not a replacement.
 *   • RTL-correct: rail order follows DOM order under the parent `dir`,
 *     and we use logical properties for padding/offset so "next" lands
 *     visually on the leftward side in RTL.
 *
 * Item width formula:
 *   flex-basis = (100% - gap × (N - 1)) / N
 *
 * Mobile uses N = 2.5 by default → 2 full cards + half of the next, a
 * built-in "scroll me" affordance for swipe-first users.
 */

.wp-block-rahkar-products-slider {
	--rps-cols:   5;
	--rps-mob:    2.5;
	--rps-gap:    12px;
	--rps-radius: 12px;
	--rps-edge:   16px;
	/* --rpc-radius is forwarded from PHP so card corners match. */
	margin-block: 0;
}

/* ─── Heading (optional, used by hardcoded slider in templates) ───── */
.rps-heading {
	margin: 0 0 12px;
	font-size: 1.15rem;
	font-weight: 700;
	line-height: 1.4;
	color: var(--wp--preset--color--contrast, #0f1115);
}

/* ─── Frame: positioning context for arrows. ────────────────────── */
.rps-frame {
	position: relative;
}

/* ─── Track: horizontal flex rail with scroll-snap ───────────────── */
.rps-track {
	display: flex;
	gap: var(--rps-gap);
	list-style: none;
	padding: 0;
	margin: 0;
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	scroll-padding-inline-start: var(--rps-edge);
	padding-inline: var(--rps-edge);
	margin-inline: calc(var(--rps-edge) * -1);
	overscroll-behavior-x: contain;
	scrollbar-width: none;
}
.rps-track::-webkit-scrollbar { display: none; }

/* Direct children get the column width. Targeting via `.rps-track > *`
   covers both .rpc-card items and the trailing .rps-view-all-item. */
.rps-track > * {
	flex: 0 0 calc((100% - var(--rps-gap) * (var(--rps-cols) - 1)) / var(--rps-cols));
	min-width: 0;
	scroll-snap-align: start;
}

/* ─── Arrow buttons ─────────────────────────────────────────────────
   Pinned to the inline-start / inline-end edges of the frame so they
   appear over the rail. Hidden by default on the smallest screens
   when there isn't enough room to overlay without covering cards;
   re-enabled on ≥420px (most phones in portrait).

   `pointer-events: none` on the wrapper would break clicks — we instead
   keep the buttons clickable and let the cards underneath remain
   accessible because the buttons are only ~40px wide. */
.rps-arrow {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.96);
	color: var(--wp--preset--color--contrast, #0f1115);
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
	cursor: pointer;
	z-index: 2;
	padding: 0;
	transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}
.rps-arrow:hover {
	background: #fff;
	transform: translateY(-50%) scale(1.05);
}
.rps-arrow:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary, #0a66c2);
	outline-offset: 2px;
}
.rps-arrow:active {
	transform: translateY(-50%) scale(0.95);
}
/* Disabled state (set by view.js when rail is at the start/end). */
.rps-arrow[aria-disabled="true"] {
	opacity: 0;
	pointer-events: none;
}

/* Position: --prev on inline-start, --next on inline-end. In RTL these
   flip automatically. The chevron itself is picked by PHP (is_rtl()) so
   the visual direction is decided server-side; no CSS flip needed. */
.rps-arrow--prev { inset-inline-start: 4px; }
.rps-arrow--next { inset-inline-end:   4px; }

/* ─── Trailing "view all" item ──────────────────────────────────── */
.rps-view-all-item .rps-view-all {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	width: 100%;
	aspect-ratio: 1 / 1;
	border-radius: var(--rps-radius);
	background: #eaf4fb;
	text-decoration: none;
	color: #1976d2;
	font-weight: 700;
	transition: background 150ms ease;
}
.rps-view-all-item .rps-view-all:hover,
.rps-view-all-item .rps-view-all:focus-visible {
	background: #d3e9f7;
}
.rps-view-all__circle {
	width: 56px;
	height: 56px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: #fff;
	color: #1976d2;
	border: 1.5px solid currentColor;
}
.rps-view-all__label {
	font-size: 0.9em;
}

/* ─── Promo banner (optional sticky first item) ────────────────── */
.rps-promo-item {
	position: sticky;
	inset-inline-start: -18.5%;
	z-index: 2;
	scroll-snap-align: start;
}
.rps-promo-item .rps-promo {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: var(--rps-radius);
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
}
.rps-promo-item .rps-promo__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* ─── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 782px) {
	.rps-promo-item {
		inset-inline-start: -38%;
	}

	.rps-track {
		gap: 8px;
	}

	.rps-track > * {
		flex: 0 0 calc((100% - 8px * (var(--rps-mob) - 1)) / var(--rps-mob));
	}

	.rps-arrow {
		width: 36px;
		height: 36px;
	}
	.rps-arrow--prev { inset-inline-start: 2px; }
	.rps-arrow--next { inset-inline-end:   2px; }

	.rps-view-all__circle {
		width: 44px;
		height: 44px;
	}
	.rps-view-all__circle svg {
		width: 22px;
		height: 22px;
	}
}

/* On very narrow screens (<420px) arrows compete with card content;
   hide them and rely on swipe. */
@media (max-width: 419px) {
	.rps-arrow { display: none; }
}

/* ─── Reduce motion: cancel smooth scroll, keep functionality ──── */
@media (prefers-reduced-motion: reduce) {
	.rps-track { scroll-behavior: auto; }
}
