/**
 * ZAI COFFEE — Homepage banner slider (Phase 8)
 * -----------------------------------------------------------------------------
 * Hero carousel with an image or self-hosted video background and an adjustable
 * dark overlay. Loaded on the front page only (see inc/assets.php).
 *
 * LAYERING CONTRACT — the whole point of this file.
 *
 * Every layer is a SIBLING inside .zai-slider__slide and owns an explicit
 * z-index, which is what guarantees the text is never painted behind the video:
 *
 *   .zai-slider__media      z-index 0   the image or <video>
 *   .zai-slider__scrim      z-index 1   the adjustable dark overlay
 *   .zai-slider__gradient   z-index 2   text-side contrast gradient
 *   .zai-slider__content    z-index 3   eyebrow, heading, text, CTA
 *   .zai-slider__controls   z-index 4   arrows and dots
 *
 * The media layer is `position:absolute; inset:0` with `pointer-events:none`, so
 * it can never intercept a click on the CTA.
 *
 * OVERLAY TECHNIQUE: the scrim is the anthracite token at `opacity` driven by a
 * per-slide custom property (a unitless 20–80). Using `opacity` rather than an
 * alpha channel keeps it valid in every engine and guarantees the text sits on a
 * predictable darkening regardless of the underlying photo or video.
 *
 * @package zaicoffeetheme
 * @since   1.8.0
 */

/* ==========================================================================
   1. Shell
   ========================================================================== */

.zai-slider {
	position: relative;
	isolation: isolate;
	background-color: var(--zai-ink);
	color: var(--zai-text-inverse);
	/* A stable stage prevents layout shift while slides change. */
	min-height: clamp(28rem, 62vh, 42rem);
	overflow: hidden;
}

.zai-slider__viewport {
	position: relative;
	min-height: clamp(28rem, 62vh, 42rem);
}

/*
 * Slides share one grid cell so a transition never reflows the page.
 * Inactive slides stay in the DOM (search/no-JS value) but are inert.
 */
.zai-slider__slide {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	opacity: 0;
	visibility: hidden;
	transition:
		opacity var(--zai-dur-slow) var(--zai-ease),
		visibility 0s linear var(--zai-dur-slow);
}

.zai-slider__slide.is-active {
	position: relative;
	opacity: 1;
	visibility: visible;
	transition:
		opacity var(--zai-dur-slow) var(--zai-ease),
		visibility 0s linear 0s;
}

/* With a single slide the stage needs height; no absolute positioning needed. */
.zai-slider--single .zai-slider__slide {
	position: relative;
	opacity: 1;
	visibility: visible;
}

/* ==========================================================================
   2. Layers
   ========================================================================== */

/* Layer 0 — media. Never blocks interaction with the CTA. */
.zai-slider__media {
	position: absolute;
	inset: 0;
	z-index: 0;
	overflow: hidden;
	pointer-events: none;
	background-color: var(--zai-ink);
}

.zai-slider__image,
.zai-slider__video {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

/*
 * VIDEO SLIDES — full-bleed fit.
 * -----------------------------------------------------------------------------
 * ROOT CAUSE this block corrects.
 *
 * `.zai-slider__slide` is a content-sized flex box: the stage around it owns the
 * `min-height: clamp(28rem, 62vh, 42rem)` (see §1), while an ACTIVE slide is
 * `position: relative` and therefore only as tall as its own content. On the
 * live page at 1440px the stage measured 499.09px while the slide measured
 * 483.58px, so the bottom 15.5px of the stage showed `.zai-slider`'s own
 * `background-color: var(--zai-ink)` — the dark strip under the video.
 *
 * An <img> hides this because it is a replaced element: `height: 100%` resolves
 * against the content box and the image simply ends where the slide ends, but a
 * large photo still visually covers because the slide is background-sized. A
 * <video> makes it obvious, because the decoder paints only inside its box.
 *
 * The fix gives the VIDEO SLIDE itself the stage height, so the slide, the media
 * layer and the <video> all end on exactly the same edge as the banner:
 *
 *   .zai-slider__viewport  min-height: clamp(28rem, 62vh, 42rem)   ← unchanged
 *   .zai-slider__slide--video  min-height: inherit                  ← same stage
 *
 * `min-height` (never `height`) is deliberate: on a narrow screen the copy can
 * be taller than the clamp, and the slide must still be allowed to grow with its
 * content instead of clipping the text. No banner height setting is changed —
 * the value is inherited from the same clamp the stage already uses.
 *
 * Everything here is scoped to `--video`, so an image-only slide keeps the
 * markup and layout it has always had.
 */
.zai-slider__slide--video {
	/*
	 * Inherit the stage minimum from .zai-slider__viewport so the two boxes can
	 * never disagree, even if the clamp is tuned later. `min-height` not
	 * `height` keeps a tall-content slide free to grow.
	 */
	min-height: inherit;
	/*
	 * The slide already clips its media layer, but stating it here keeps the
	 * video's painted surface strictly inside the banner, so no rounded corner,
	 * baseline gap or 1px overflow can expose the section background.
	 */
	overflow: hidden;
}

/*
 * THE VIDEO ELEMENT ITSELF.
 *
 * Taken out of flow entirely and pinned to all four edges of `.zai-slider__media`
 * (`position: absolute; inset: 0`), which fills the slide. This removes every
 * way the element could fail to fill the banner:
 *
 *   - `position: static` previously let the intrinsic 1920×1080 ratio and the
 *     reset's `video { height: auto }` decide the box;
 *   - `display: block` removes the inline baseline gap under the element;
 *   - `object-fit: cover` crops proportionally instead of stretching;
 *   - `height: 100%` + `inset: 0` make the box identical to its layer.
 *
 * The video stays on z-index 0, BELOW the scrim (1), the gradient (2) and the
 * text (3), and `pointer-events: none` is inherited from the media layer, so the
 * CTA stays clickable. The overlay and its opacity control are untouched.
 */
.zai-slider__slide--video .zai-slider__video {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	/* Neutralise the UA/reset defaults that could reintroduce a gap or ratio. */
	max-width: none;
	max-height: none;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	aspect-ratio: auto;
	object-fit: cover;
	object-position: center;
	/* No inline baseline gap can exist inside an absolutely positioned block. */
	vertical-align: top;
	background-color: transparent;
}

/* Layer 1 — the adjustable dark overlay (per banner, 20–80). */
.zai-slider__scrim {
	position: absolute;
	inset: 0;
	z-index: 1;
	pointer-events: none;
	background-color: var(--zai-ink);
	/*
	 * The custom property is printed inline per slide by hero-slider.php as a
	 * unitless 20–80. Dividing by 100 gives the opacity; the fallback keeps a
	 * slide readable if the property were ever absent.
	 */
	opacity: calc(var(--zai-slider-overlay, 45) / 100);
}

/* Layer 2 — a subtle gradient that strengthens contrast behind the text. */
.zai-slider__gradient {
	position: absolute;
	inset: 0;
	z-index: 2;
	pointer-events: none;
	background-image: linear-gradient(
		90deg,
		rgb(34 34 34 / 55%) 0%,
		rgb(34 34 34 / 25%) 45%,
		rgb(34 34 34 / 0%) 75%
	);
}

/* Layer 3 — text. */
.zai-slider__content {
	position: relative;
	z-index: 3;
	width: 100%;
	padding-block: var(--zai-section-y);
}

.zai-slider__inner {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: var(--zai-space-4);
	max-width: 46rem;
	color: var(--zai-text-inverse);
}

.zai-slider__eyebrow {
	margin: 0;
	color: var(--zai-text-inverse);
	opacity: 0.85;
}

/*
 * Slide titles.
 *
 * `h1` and `h2` are both styled because only the FIRST slide renders an <h1>
 * (one top-level heading per page); later slides render an <h2> with the same
 * class, so the visual hierarchy stays identical while the document outline
 * remains valid.
 */
.zai-slider__title {
	margin: 0;
	font-family: var(--zai-font-display);
	font-size: clamp(2rem, 1.1rem + 3.6vw, 3.75rem);
	font-weight: var(--zai-fw-light);
	line-height: var(--zai-lh-tight);
	letter-spacing: var(--zai-ls-tighter);
	color: var(--zai-text-inverse);
	text-wrap: balance;
	text-shadow: 0 1px 2px rgb(34 34 34 / 35%);
}

/* An h2 slide title must not inherit the global heading size. */
h2.zai-slider__title {
	font-size: clamp(1.75rem, 1rem + 3.2vw, 3.25rem);
}

.zai-slider__text {
	max-width: 38rem;
	margin: 0;
	font-family: var(--zai-font-body);
	font-size: var(--zai-fs-md);
	line-height: var(--zai-lh-relaxed);
	color: var(--zai-text-inverse);
	opacity: 0.92;
	text-shadow: 0 1px 2px rgb(34 34 34 / 30%);
}

.zai-slider__actions {
	margin: var(--zai-space-2) 0 0;
}

.zai-slider__cta {
	gap: var(--zai-space-2);
	background-color: var(--zai-green);
	border-color: var(--zai-green);
	color: var(--zai-text-inverse);
}

.zai-slider__cta:hover {
	background-color: var(--zai-green-hover);
	border-color: var(--zai-green-hover);
	color: var(--zai-text-inverse);
}

/* ==========================================================================
   3. Controls (Layer 4)
   ========================================================================== */

.zai-slider__controls {
	position: absolute;
	inset-inline: 0;
	inset-block-end: var(--zai-space-6);
	z-index: 4;
	display: flex;
	align-items: center;
	gap: var(--zai-space-4);
}

.zai-slider__arrow {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--zai-touch-target);
	height: var(--zai-touch-target);
	min-width: var(--zai-touch-target);
	padding: 0;
	border: var(--zai-border-width) solid rgb(243 240 236 / 45%);
	border-radius: var(--zai-radius-pill);
	background-color: rgb(34 34 34 / 35%);
	color: var(--zai-text-inverse);
	cursor: pointer;
	transition:
		background-color var(--zai-dur-fast) var(--zai-ease),
		border-color var(--zai-dur-fast) var(--zai-ease);
}

.zai-slider__arrow:hover {
	background-color: rgb(34 34 34 / 65%);
	border-color: var(--zai-text-inverse);
}

.zai-slider__arrow:focus-visible {
	outline: var(--zai-focus-width) solid var(--zai-focus-color);
	outline-offset: var(--zai-focus-offset);
}

/* The previous arrow reuses the same glyph, mirrored. */
.zai-slider__arrow--prev svg {
	transform: rotate(180deg);
}

.zai-slider__dots {
	display: flex;
	align-items: center;
	gap: var(--zai-space-2);
	margin: 0;
	padding: 0;
	list-style: none;
}

.zai-slider__dot {
	position: relative;
	display: block;
	width: 2.5rem;
	height: 0.25rem;
	padding: 0;
	border: 0;
	border-radius: var(--zai-radius-pill);
	background-color: rgb(243 240 236 / 40%);
	cursor: pointer;
	transition: background-color var(--zai-dur-fast) var(--zai-ease);
}

/*
 * A comfortable hit area without a visually huge dot. The pseudo-element expands
 * the target to roughly 44px tall while the visible bar stays slim.
 */
.zai-slider__dot::before {
	content: "";
	position: absolute;
	inset-block: -1.125rem;
	inset-inline: 0;
}

.zai-slider__dot:hover {
	background-color: rgb(243 240 236 / 70%);
}

.zai-slider__dot.is-active,
.zai-slider__dot[aria-selected="true"] {
	background-color: var(--zai-text-inverse);
}

.zai-slider__dot:focus-visible {
	outline: var(--zai-focus-width) solid var(--zai-focus-color);
	outline-offset: var(--zai-focus-offset);
}

/* ==========================================================================
   4. Responsive
   ========================================================================== */

@media (max-width: 767px) {
	.zai-slider,
	.zai-slider__viewport {
		min-height: clamp(24rem, 70vh, 32rem);
	}

	.zai-slider__content {
		padding-block: var(--zai-space-9) var(--zai-space-11);
	}

	.zai-slider__inner {
		gap: var(--zai-space-3);
	}

	.zai-slider__controls {
		inset-block-end: var(--zai-space-4);
		gap: var(--zai-space-3);
	}

	/* The CTA owns the full width on a phone. */
	.zai-slider__actions,
	.zai-slider__cta {
		width: 100%;
	}

	.zai-slider__cta {
		justify-content: center;
	}
}

/* On narrow screens the sideways gradient is pointless; darken evenly instead. */
@media (max-width: 640px) {
	.zai-slider__gradient {
		background-image: linear-gradient(
			180deg,
			rgb(34 34 34 / 15%) 0%,
			rgb(34 34 34 / 55%) 100%
		);
	}
}

/* ==========================================================================
   5. Reduced motion
   -----------------------------------------------------------------------------
   Transitions collapse and the video layer is hidden: the poster (rendered as the
   <video poster> attribute) or the still image is shown instead. The slider script
   also refuses to autoplay under this preference.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.zai-slider__slide,
	.zai-slider__arrow,
	.zai-slider__dot {
		transition: none;
	}

	/*
	 * NOTE: this selector must stay at least as specific as the full-bleed rule
	 * in §2 (`.zai-slider__slide--video .zai-slider__video`), otherwise that
	 * rule's `display: block` would win and the video would keep playing for a
	 * visitor who asked for reduced motion.
	 */
	.zai-slider__video,
	.zai-slider__slide--video .zai-slider__video {
		display: none;
	}

	/* The poster still occupies the stage through the parent background. */
	.zai-slider__media {
		background-color: var(--zai-ink);
	}
}

/* ==========================================================================
   6. Optional banner logo
   -----------------------------------------------------------------------------
   Purely additive. Every rule below is scoped to .zai-slider__inner--with-logo,
   a class that is printed ONLY when the banner has a logo, so a banner without
   one keeps the layout it has always had.

   LAYERING & CONTRAST
   The logo lives inside .zai-slider__content (z-index 3), i.e. ABOVE the media
   (0), the scrim (1) and the gradient (2). That is deliberate: the per-banner
   dark overlay must never mute the logo itself, so a white or Lületaşı mark keeps
   its full contrast on a dark video. On a light image background the existing
   left-heavy gradient already darkens the logo side of the stage, which is what
   lets the green brand mark stay legible. Contrast therefore comes from the
   banner's own background treatment plus the supplied artwork — NOT from a plate,
   border or shadow, none of which is added here.

   PROPORTIONS
   width/height stay auto with object-fit: contain and only a max-width / max-height
   cap, so the artwork is never stretched, cropped or upscaled, and its
   transparency is preserved. The caps keep the mark restrained next to the text.
   ========================================================================== */

/* Both columns share this alignment: centred on mobile, vertically on desktop. */
.zai-slider__inner--with-logo {
	align-items: center;
	gap: var(--zai-space-5);
}

/* Mobile / base: the logo sits ABOVE the text and is centred. */
.zai-slider__logo {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	/*
	 * WIDTH CONTROL. The value comes from a per-banner custom property printed
	 * inline by hero-slider.php, so the slider in the admin sizes the real box and
	 * the layout reserves the right amount of space (no transform scaling).
	 * `min(..., 100%)` guarantees the mark can never overflow the column, and the
	 * fallback is the shipped default so a logo still renders if the property is
	 * ever absent.
	 */
	max-width: min(var(--zai-slider-logo-width-mobile, 192px), 100%);
	min-width: 0;
	color: var(--zai-text-inverse);
}

.zai-slider__logo-image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	/*
	 * HEIGHT CAP, derived from the SAME per-banner property so the box stays
	 * proportional as the width grows or shrinks.
	 *
	 * The multiplier is not arbitrary: 192px × 0.375 = 72px, which is exactly the
	 * max-height this block shipped with before the size control existed. Every
	 * default therefore renders pixel-identically to the previous release, while
	 * moving the slider scales the cap in both directions. Because width and
	 * height stay `auto` and only max-* limits are constrained, the browser
	 * preserves the intrinsic ratio — the mark can never be stretched.
	 */
	max-height: calc(var(--zai-slider-logo-width-mobile, 192px) * 0.375);
	object-fit: contain;
	object-position: center;
	/* No automatic plate, border or shadow — the asset stands on its own. */
	border: 0;
	background: none;
	box-shadow: none;
	/* A logo must not inherit the translucent treatment used for body copy. */
	filter: none;
	opacity: 1;
}

/*
 * The text column. Reproduces the original .zai-slider__inner flex column so the
 * eyebrow / heading / text / CTA rhythm is identical to the no-logo layout.
 */
.zai-slider__body {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: var(--zai-space-4);
	width: 100%;
	min-width: 0;
}

/* Mobile: match the existing narrow-screen inner gap. */
@media (max-width: 767px) {
	.zai-slider__inner--with-logo {
		gap: var(--zai-space-4);
	}

	.zai-slider__body {
		gap: var(--zai-space-3);
	}

	.zai-slider__logo-image {
		/* 192 × 0.3333 ≈ 64px, the exact max-height this block shipped with. */
		max-height: calc(var(--zai-slider-logo-width-mobile, 192px) / 3);
	}
}

/* Desktop: a true two-column composition, both columns vertically centred. */
@media (min-width: 1024px) {
	.zai-slider__inner.zai-slider__inner--with-logo {
		flex-direction: row;
		align-items: center;
		/* Wider than the text-only measure so the prose keeps its line length. */
		max-width: min(64rem, 100%);
		/* Adequate breathing room between the logo and the text. */
		gap: var(--zai-space-8);
	}

	.zai-slider__logo {
		/* Desktop width, same per-banner property, desktop value. */
		max-width: min(var(--zai-slider-logo-width-desktop, 224px), 100%);
	}

	.zai-slider__logo-image {
		/* 224 × 0.5 = 112px, the exact max-height this block shipped with. */
		max-height: calc(var(--zai-slider-logo-width-desktop, 224px) * 0.5);
	}

	.zai-slider__body {
		/* The text keeps exactly the measure it had without a logo. */
		flex: 1 1 auto;
		max-width: 46rem;
	}
}
