/*
 * 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:    0px;
	--rps-radius: 12px;
	--rps-edge:   16px;
	/* --rpc-radius is forwarded from PHP so card corners match. */
	margin-block: 0;
}

/* ─── Header row: heading (inline-start) + "همه" link (inline-end) ──── */
.rps-header {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-block: 0 12px;
}

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

/* "همه" link — pinned to the inline-end of the header row (top-left in RTL)
   via the auto margin, so it sits opposite the title even with no heading. */
.rps-view-all-top {
	margin-inline-start: auto;
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	text-decoration: none;
	white-space: nowrap;
	color: var(--wp--preset--color--primary, #0a66c2);
	font-size: 0.9rem;
	font-weight: var(--wp--custom--fw--strong);
	transition: opacity 0.15s ease;
}
.rps-view-all-top:hover,
.rps-view-all-top:focus-visible { opacity: 0.7; }
.rps-view-all-top__ico { flex: 0 0 auto; }

/* ─── 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; }

/* Desktop drag-to-scroll affordance. view.js engages pointer-drag only on
   fine-pointer (mouse/trackpad) devices — touch keeps its native fling — so
   the grab cursor is scoped the same way. While dragging, view.js adds
   `.is-dragging`: snap + smooth-scroll are turned off for a 1:1 follow, links
   are click-disabled (so a drag never opens a product), and selection/native
   image-drag are suppressed. */
@media (hover: hover) and (pointer: fine) {
	.rps-track { cursor: grab; }
	.rps-track.is-dragging { cursor: grabbing; }
}
.rps-track.is-dragging {
	scroll-behavior: auto;
	scroll-snap-type: none;
	user-select: none;
}
.rps-track.is-dragging a { pointer-events: none; }
.rps-track img { -webkit-user-drag: none; user-drag: 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 ──────────────────────────────────── */
/* The li is a flex container so the inner card stretches to the FULL height
   of the rail row (= the height of the product cards: square image + 2-line
   title + price), instead of the old square aspect-ratio that left it short. */
.rps-view-all-item { display: flex; }
/* Colors are derived from the Primary brand token — the light fill is a
   low-% color-mix of Primary into Base, matching the brands-slider idiom, so
   nothing here is a hardcoded blue (fallbacks kept for ancient engines). */
.rps-view-all-item .rps-view-all {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	width: 100%;
	height: 100%;
	border-radius: var(--rps-radius);
	background: color-mix(in srgb, var(--wp--preset--color--primary, #0a66c2) 8%, var(--wp--preset--color--base, #fff));
	text-decoration: none;
	color: var(--wp--preset--color--primary, #0a66c2);
	font-weight: var(--wp--custom--fw--strong);
	transition: background 150ms ease;
}
.rps-view-all-item .rps-view-all:hover,
.rps-view-all-item .rps-view-all:focus-visible {
	background: color-mix(in srgb, var(--wp--preset--color--primary, #0a66c2) 16%, var(--wp--preset--color--base, #fff));
}
.rps-view-all__circle {
	width: 56px;
	height: 56px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: var(--wp--preset--color--base, #fff);
	color: var(--wp--preset--color--primary, #0a66c2);
	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; }
}
