/**
 * M50 Product Slider
 *
 * A native horizontal scroll-snap slider. Touch/trackpad swipe drives it on
 * every device; the top-right buttons page it by one card on pointer devices.
 *
 * The number of cards visible per row is set per device via the shortcode
 * (desktop / tablet / mobile), landing on the root as --m50ps-desktop /
 * --m50ps-tablet / --m50ps-mobile. Media queries below pick the one in force
 * (--m50ps-per) and derive the card width from it — nothing else changes.
 */

.m50ps {
	--m50ps-gap: 24px;

	/* A slight peek of the next card hints there is more to swipe, without
	   changing how many cards read as "in view". */
	--m50ps-peek: 0.18;

	/* Slides per row, switched per breakpoint below; falls back if the
	   shortcode did not set the device vars. */
	--m50ps-per: var(--m50ps-desktop, 4);

	/* Card width: fit --m50ps-per cards across the viewport, minus their gaps,
	   with a fractional peek so the edge card is partly visible. */
	--m50ps-card: calc(
		(100% - var(--m50ps-per) * var(--m50ps-gap))
		/ (var(--m50ps-per) + var(--m50ps-peek))
	);

	--m50ps-btn-size: 44px;
	position: relative;
	width: 100%;
	max-width: 100%;
	margin-bottom: 15px;

	/* When the shortcode is dropped inside an Elementor Container (which is a
	   flexbox), `.m50ps` becomes a flex item and defaults to min-width:auto —
	   so it refuses to shrink below the total width of all its cards and blows
	   out of the container, breaking the layout and the 100%-based card calc.
	   Forcing min-width:0 lets it shrink back to the container width; flex-basis
	   100% keeps it filling a row container. */
	min-width: 0;
	flex: 1 1 100%;
}

/* Predictable box model regardless of the theme's global default, so the card
   width calc and paddings stay exact. */
.m50ps,
.m50ps *,
.m50ps *::before,
.m50ps *::after {
	box-sizing: border-box;
}

/* ── Header / navigation (top right) ─────────────────────────────────────── */

.m50ps__head {
	display: none;
	justify-content: flex-end;
	align-items: center;
	margin-bottom: 16px;
}

.m50ps__nav {
	display: flex;
	gap: 10px;
}

.m50ps__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--m50ps-btn-size);
	height: var(--m50ps-btn-size);
	padding: 0;
	margin: 0;
	border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
	border-radius: 50%;
	background: color-mix(in srgb, currentColor 6%, transparent);
	color: inherit;
	cursor: pointer;
	line-height: 1;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, transform 0.1s ease;
}

.m50ps__btn svg {
	width: 22px;
	height: 22px;
	display: block;
}

.m50ps__btn:hover:not(:disabled) {
	background: color-mix(in srgb, currentColor 16%, transparent);
	border-color: currentColor;
}

.m50ps__btn:active:not(:disabled) {
	transform: scale(0.94);
}

.m50ps__btn:disabled {
	opacity: 0.3;
	cursor: default;
}

.m50ps__btn:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* ── Viewport + track ────────────────────────────────────────────────────── */

.m50ps__viewport {
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none;              /* Firefox */
	-ms-overflow-style: none;           /* old Edge */
	touch-action: pan-x pan-y;
	/* Keep the scroller bounded to the slider width even inside a flex parent. */
	width: 100%;
	max-width: 100%;
	min-width: 0;
}

/* Mouse users get a grab cursor to advertise drag-to-swipe (JS wires the drag).
   Only pointer devices with a real hover get it, so touch is unaffected. */
@media (hover: hover) and (pointer: fine) {
	.m50ps__viewport {
		cursor: grab;
	}
}

/* While a mouse drag is in progress (class toggled by slider.js): follow the
   cursor 1:1 by switching snap and smooth scrolling off, show the grabbing
   cursor, and stop text/image selection from interrupting the drag. */
.m50ps--dragging .m50ps__viewport {
	scroll-snap-type: none;
	scroll-behavior: auto;
	cursor: grabbing;
}

.m50ps--dragging,
.m50ps--dragging .m50ps__viewport {
	user-select: none;
	-webkit-user-select: none;
}

/* Never let the browser's native drag-ghost of an image or link hijack the
   pointer drag. */
.m50ps-card__media,
.m50ps-card__img {
	-webkit-user-drag: none;
	user-drag: none;
}

.m50ps__viewport::-webkit-scrollbar {
	display: none;                      /* Chrome/Safari */
}

.m50ps__viewport:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
}

.m50ps__track {
	display: flex;
	gap: var(--m50ps-gap);
	align-items: stretch;
	/* Trailing space so the final card can snap to the left edge instead of
	   being stuck against the right of the scroll area. */
	padding-right: var(--m50ps-gap);
}

.m50ps__slide {
	scroll-snap-align: start;
	flex: 0 0 var(--m50ps-card);
	width: var(--m50ps-card);
	max-width: var(--m50ps-card);
	height: auto;
}

/* Let the card fill the slide height so a row of cards keeps an even bottom
   edge regardless of how much content each one has. */
.m50ps__slide > * {
	height: 100%;
}

/* ── Progress line (bottom) ──────────────────────────────────────────────────
   A thin rail with a moving thumb: the thumb's width is the fraction of the row
   that is visible, and its position tracks the scroll. Widths/position are set
   by slider.js; when everything fits, the rail is hidden (the `hidden` attr). */

.m50ps__progress {
	position: relative;
	width: 100%;
	height: 3px;
	margin: 22px auto 0;
	border-radius: 999px;
	background: color-mix(in srgb, currentColor 15%, transparent);
	overflow: hidden;
}

.m50ps__progress[hidden] {
	display: none;
}

.m50ps__progress-bar {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 30%;                 /* placeholder; slider.js sets the real width */
	border-radius: inherit;
	background: #1A1C18;
	transition: transform 0.12s ease, width 0.2s ease;
	will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
	.m50ps__progress-bar {
		transition: none;
	}
}

/* ── Per-device slide counts ─────────────────────────────────────────────── */

/* Tablet: 768–1024px. */
@media (max-width: 1024px) {
	.m50ps {
		--m50ps-per: var(--m50ps-tablet, 2);
		--m50ps-gap: 18px;
	}
}

/* Mobile: < 768px. */
@media (max-width: 767px) {
	.m50ps {
		--m50ps-per: var(--m50ps-mobile, 1);
		--m50ps-gap: 14px;
		--m50ps-btn-size: 40px;
	}

	.m50ps__btn svg {
		width: 20px;
		height: 20px;
	}
}

/* Respect users who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
	.m50ps__viewport {
		scroll-behavior: auto;
	}
}

/* ═══════════════════════════════════════════════════════════════════════════
   Product card — a large image, then title + price. Modelled on the reference:
   a flat neutral image panel, quiet type, a sale badge, and (for variable
   products) small option chips.
   ═══════════════════════════════════════════════════════════════════════════ */

.m50ps-card {
	--m50ps-ink: #1A1C18;
	--m50ps-muted: #6B6F68;
	--m50ps-panel: #ECECEC;
	--m50ps-sale: #C4362E;
	--m50ps-chip-bg: #F2F2EF;

	display: flex;
	flex-direction: column;
	height: 100%;
	background: transparent;
	color: var(--m50ps-ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	line-height: 1.4;
}

/* ── Media (image + hover swap + badge) ──────────────────────────────────── */

.m50ps-card__media {
	position: relative;
	display: block;
	aspect-ratio: 3 / 4;
	overflow: hidden;
	text-decoration: none;
}

.m50ps-card__img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	margin: 0;
}

.m50ps-card__img--placeholder {
	background: var(--m50ps-panel);
}

/* Hover swap: the 2nd image sits on top, hidden, and cross-fades in on hover
   of the media (pointer devices only — see the coarse-pointer reset below). */
.m50ps-card__img--secondary {
	opacity: 0;
	transition: opacity 0.35s ease;
}

.m50ps-card--has-hover .m50ps-card__media:hover .m50ps-card__img--secondary,
.m50ps-card--has-hover .m50ps-card__media:focus-visible .m50ps-card__img--secondary {
	opacity: 1;
}

/* A gentle zoom on the primary image adds life on hover. */
.m50ps-card__img--primary {
	transition: transform 0.5s ease;
}

.m50ps-card__media:hover .m50ps-card__img--primary {
	transform: scale(1.03);
}

/* On touch devices there is no hover — never hide the 2nd image behind a state
   the user cannot trigger, and skip the zoom. */
@media (hover: none) {
	.m50ps-card__img--secondary {
		display: none;
	}
	.m50ps-card__media:hover .m50ps-card__img--primary {
		transform: none;
	}
}

.m50ps-card__badge {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 2;
	display: inline-block;
	padding: 5px 9px;
	border-radius: 6px;
	background: var(--m50ps-sale);
	color: #fff;
	font-size: 13px;
	font-weight: 700;
	line-height: 1;
	letter-spacing: 0.02em;
}

/* ── Body (title + price) ────────────────────────────────────────────────── */

.m50ps-card__body {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	padding: 14px 2px 0;
}

.m50ps-card__title {
	margin: 0;
        font-family: Larsseit;
	font-size: 15px;
	font-weight: 400;
	line-height: 1.35;
	/* Keep cards even when titles differ in length. */
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.m50ps-card__title a {
	color: inherit;
	text-decoration: none;
}

.m50ps-card__title a:hover,
.m50ps-card__title a:focus-visible {
	text-decoration: underline;
}

/* Variation options overlaid on the image, bottom-centered, white on a dark
   translucent chip so they read over any photo. */
.m50ps-card__variations {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 12px;
	z-index: 2;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px;
	padding: 0 12px;
}

.m50ps-card__variation {
	display: inline-block;
	padding: 7px 10px;
	border-radius: 3px;
	background: var(--m50ps-ink);
	color: #fff;
	font-size: 12px;
	font-weight: 500;
	line-height: 1.3;
	letter-spacing: 0.01em;
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
}

.m50ps-card__price {
	margin-top: 0;
	padding-top: 4px;
	font-size: 14px;
	color: var(--m50ps-muted);
}

/* WooCommerce price markup: dim the struck-through regular price, keep the sale
   price in the ink colour so the active price reads first. */
.m50ps-card__price .price {
	color: inherit;
}

.m50ps-card__price del {
	opacity: 0.6;
	margin-right: 6px;
	font-weight: 400;
}

.m50ps-card__price ins {
	text-decoration: none;
	color: var(--m50ps-ink);
	font-weight: 600;
}

/* ── Administrator debug window ──────────────────────────────────────────── */

.m50ps-debug {
	margin: 0 0 16px;
	padding: 12px 16px;
	background: var(--c-admin-rose, #F0D5DA);
	border-radius: 10px;
	color: #5c2230;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 13px;
	line-height: 1.5;
}

.m50ps-debug__title {
	margin: 0 0 6px;
	font-size: 14px;
	font-weight: 700;
}

.m50ps-debug__meta {
	margin: 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.m50ps-debug__meta code {
	padding: 1px 5px;
	border-radius: 4px;
	background: rgba(92, 34, 48, 0.1);
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 12px;
	word-break: break-word;
}

.m50ps-debug__note {
	margin: 8px 0 0;
	font-size: 11px;
	font-style: italic;
	opacity: 0.75;
}
