/* QC Loader — the site-wide loading vocabulary (Style Book / theme look and
   feel), shipped as a company-scoped globalCSS client extension so every
   page, fragment and client extension can use it with zero markup imports.

   Three things live here:

   1. PAGE loader — a brand scrim + spinner painted over the page while the
      document is still parsing. Rendered as body::before/::after so it needs
      no DOM node and cannot flash: qc-loader.js stamps
      html.qc-page-loading in <head> (before the body paints) and swaps it for
      .qc-page-loaded on DOMContentLoaded. No class = nothing renders, so a
      failure to load the JS degrades to "no loader", never "stuck loader".

   2. FRAGMENT / container loader — put data-qc-loading on any element and it
      gets a scrim + centred spinner inside its own box. CSS-only; a fragment
      can toggle the attribute directly or call QCLoader.show()/hide().

   3. SPINNER + SKELETON utilities — .qc-spinner (3 sizes, on-dark variant)
      and .qc-skeleton* shimmer blocks for inline use.

   Colors come from the --qc-* tokens in qc-global.css, so dark mode
   (html[data-theme="dark"]) flips automatically; only the scrim and the
   skeleton greys need explicit dark values (bottom of this file).

   Logical properties only, and centring is inset:0 + margin:auto (NOT
   inset-inline-start + translateX, which does not mirror under dir="rtl").
   Every animation has a prefers-reduced-motion fallback. */

/* ============================================================
   Shared knobs
   ============================================================ */

:root {
	--qc-loader-size: 2.5rem;
	--qc-loader-thickness: 3px;
	--qc-loader-track: var(--qc-primary-100, #e3c5cb);
	--qc-loader-arc: var(--qc-primary-500, #911731);
	--qc-loader-accent: var(--qc-gold-500, #a66f43);
	--qc-loader-speed: 0.9s;

	/* Near-opaque scrim over the page / the loading container. */
	--qc-loader-scrim: #ffffffee;

	/* Skeleton shimmer */
	--qc-skeleton-base: var(--qc-gray-100, #ededed);
	--qc-skeleton-shine: #ffffff;
}

/* ============================================================
   1. Spinner — a tapered brand "comet" ring (outer, primary) with a
      slower counter-rotating gold inner ring. Built from conic
      gradients + a radial mask so the arc tapers instead of showing
      the hard start/stop of a border-based spinner.
   ============================================================ */

.qc-spinner {
	display: inline-block;
	position: relative;
	flex: 0 0 auto;
	inline-size: var(--qc-loader-size);
	block-size: var(--qc-loader-size);
	border-radius: var(--qc-radius-full, 9999px);
	background:
		conic-gradient(
			from 0turn,
			transparent 0turn,
			var(--qc-loader-arc) 0.85turn
		),
		conic-gradient(var(--qc-loader-track) 0turn 1turn);
	-webkit-mask: radial-gradient(
		farthest-side,
		transparent calc(100% - var(--qc-loader-thickness)),
		#000 calc(100% - var(--qc-loader-thickness))
	);
	mask: radial-gradient(
		farthest-side,
		transparent calc(100% - var(--qc-loader-thickness)),
		#000 calc(100% - var(--qc-loader-thickness))
	);
	animation: qc-loader-spin var(--qc-loader-speed) linear infinite;
}

/* Inner gold ring — inset by the outer thickness + a hairline gap, masked to
   its own 2px ring, spun the other way at roughly half the rate. */
.qc-spinner::after {
	content: "";
	position: absolute;
	inset: calc(var(--qc-loader-thickness) + 3px);
	border-radius: inherit;
	background: conic-gradient(
		from 0.5turn,
		transparent 0turn,
		var(--qc-loader-accent) 0.7turn
	);
	-webkit-mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 2px),
		#000 calc(100% - 2px)
	);
	mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 2px),
		#000 calc(100% - 2px)
	);
	animation: qc-loader-spin calc(var(--qc-loader-speed) * 1.9) linear infinite
		reverse;
}

.qc-spinner--sm {
	--qc-loader-size: 1.25rem;
	--qc-loader-thickness: 2px;
}

/* Too small to nest a second ring legibly. */
.qc-spinner--sm::after {
	display: none;
}

.qc-spinner--lg {
	--qc-loader-size: 3.5rem;
	--qc-loader-thickness: 4px;
}

/* For placement on a primary / photo surface. */
.qc-spinner--on-dark {
	--qc-loader-track: var(--qc-alpha-white-20, #ffffff33);
	--qc-loader-arc: var(--qc-white, #ffffff);
	--qc-loader-accent: var(--qc-gold-300, #c5a185);
}

@keyframes qc-loader-spin {
	to {
		transform: rotate(1turn);
	}
}

/* ============================================================
   2. Container / fragment loader — data-qc-loading on any element
   ============================================================ */

[data-qc-loading] {
	position: relative;
	cursor: progress;

	/* A container that is still empty while it loads (a fragment about to
	   render its first Object entries) would collapse to zero height and
	   clip the spinner — reserve room for it. */
	min-block-size: calc(var(--qc-loader-size) * 2.5);
}

/* Opt out of the reserved height where the box is already tall enough. */
[data-qc-loading][data-qc-loading-bare] {
	min-block-size: 0;
}

/* Scrim. border-radius: inherit keeps it inside a rounded card. */
[data-qc-loading]::before {
	content: "";
	position: absolute;
	z-index: 30;
	inset: 0;
	border-radius: inherit;
	background: var(--qc-loader-scrim);
	animation: qc-loader-fade-in 0.18s ease-out both;
}

/* Spinner. inset:0 + margin:auto + a definite size centres on BOTH axes with
   no transform, so ar_SA mirrors correctly. */
[data-qc-loading]::after {
	content: "";
	position: absolute;
	z-index: 31;
	inset: 0;
	margin: auto;
	inline-size: var(--qc-loader-size);
	block-size: var(--qc-loader-size);
	border-radius: var(--qc-radius-full, 9999px);
	background:
		conic-gradient(
			from 0turn,
			transparent 0turn,
			var(--qc-loader-arc) 0.85turn
		),
		conic-gradient(var(--qc-loader-track) 0turn 1turn);
	-webkit-mask: radial-gradient(
		farthest-side,
		transparent calc(100% - var(--qc-loader-thickness)),
		#000 calc(100% - var(--qc-loader-thickness))
	);
	mask: radial-gradient(
		farthest-side,
		transparent calc(100% - var(--qc-loader-thickness)),
		#000 calc(100% - var(--qc-loader-thickness))
	);
	animation: qc-loader-spin var(--qc-loader-speed) linear infinite;
}

/* ============================================================
   3. Page loader — html.qc-page-loading, stamped by qc-loader.js in <head>
   ============================================================ */

.qc-page-loading body::before {
	content: "";
	position: fixed;
	z-index: 2000;
	inset: 0;
	background: var(--qc-loader-scrim);
}

.qc-page-loading body::after {
	content: "";
	position: fixed;
	z-index: 2001;
	inset: 0;
	margin: auto;
	inline-size: 3.5rem;
	block-size: 3.5rem;
	border-radius: var(--qc-radius-full, 9999px);
	background:
		conic-gradient(
			from 0turn,
			transparent 0turn,
			var(--qc-loader-arc) 0.85turn
		),
		conic-gradient(var(--qc-loader-track) 0turn 1turn);
	-webkit-mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 4px),
		#000 calc(100% - 4px)
	);
	mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 4px),
		#000 calc(100% - 4px)
	);
	animation: qc-loader-spin var(--qc-loader-speed) linear infinite;
}

/* Ready: fade both layers out; the JS then drops the classes entirely. */
.qc-page-loading.qc-page-loaded body::before,
.qc-page-loading.qc-page-loaded body::after {
	opacity: 0;
	visibility: hidden;
	transition:
		opacity 0.25s ease-out,
		visibility 0s linear 0.25s;
}

/* ============================================================
   3b. Content-area loader — html.qc-content-loading, set by qc-loader.js
       from the first paint (and on every in-site navigation) until the
       page's fragments have fetched their content. The header and footer
       stay visible; the content area holds a page's height with the brand
       scrim + spinner over it, so the footer no longer sits right under
       the header while the sections load.
   ============================================================ */

/* A full screen's height (less the 80px header), so the footer starts BELOW
   the fold while the sections load and does not jump down as they render
   (5 Nov 2026: at 60vh it showed at y~620, then jumped to the page end). */
.qc-content-loading #main-content {
	min-block-size: calc(100vh - 5rem);
	position: relative;
}

/* The footer renders in two steps (its built-in text, then cleared and
   rebuilt from its records), which flickered on every load. It stays hidden
   while the content loads and fades in once the page is ready. */
.qc-global-site-footer {
	transition: opacity 0.25s ease-out;
}

.qc-content-loading .qc-global-site-footer {
	opacity: 0;
	visibility: hidden;
	transition: none;
}

.qc-content-loading #main-content::before {
	content: "";
	position: absolute;
	z-index: 1500;
	inset: 0;
	background: var(--qc-loader-scrim);
}

/* ONE spinner for the whole load (5 Nov 2026: the full-screen spinner faded
   out and this one faded in ~120ms later, so it read as "loading twice").
   While the content loads this is THE spinner: fixed at the viewport centre
   - exactly where the full-screen one sits - and above the full-screen
   scrim, so it keeps turning, unbroken, while that scrim fades away to
   reveal the header and footer; it goes once, when the content is ready.
   inset:0 + margin:auto centres it with no transform (RTL-safe). */
.qc-content-loading #main-content::after {
	content: "";
	position: fixed;
	z-index: 2002;
	inset: 0;
	margin: auto;
	inline-size: 3.5rem;
	block-size: 3.5rem;
	border-radius: var(--qc-radius-full, 9999px);
	background:
		conic-gradient(
			from 0turn,
			transparent 0turn,
			var(--qc-loader-arc) 0.85turn
		),
		conic-gradient(var(--qc-loader-track) 0turn 1turn);
	-webkit-mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 4px),
		#000 calc(100% - 4px)
	);
	mask: radial-gradient(
		farthest-side,
		transparent calc(100% - 4px),
		#000 calc(100% - 4px)
	);
	animation: qc-loader-spin var(--qc-loader-speed) linear infinite;
}

/* ...so the full-screen loader draws only its scrim meanwhile. */
.qc-page-loading.qc-content-loading body::after {
	display: none;
}

/* ============================================================
   4. SPA navigation progress bar — driven by Senna start/endNavigate.
      Less intrusive than a full overlay for an in-place page swap.
   ============================================================ */

.qc-nav-progress {
	position: fixed;
	z-index: 2100;
	inset-block-start: 0;
	inset-inline: 0;
	block-size: 3px;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s ease-out;
}

.qc-nav-progress__bar {
	display: block;
	inline-size: 0;
	block-size: 100%;
	background: linear-gradient(
		to right,
		var(--qc-loader-arc),
		var(--qc-loader-accent)
	);
	box-shadow: 0 0 8px var(--qc-alpha-primary-30, #9117314d);
}

.qc-nav-progress.is-active {
	opacity: 1;
}

/* CSS gradients take physical directions only, so "to right" does not mirror:
   under RTL the bar grows from the inline start (the right edge), and the
   gradient has to run the other way to keep primary at its leading edge. */
[dir="rtl"] .qc-nav-progress__bar {
	background: linear-gradient(
		to left,
		var(--qc-loader-arc),
		var(--qc-loader-accent)
	);
}

/* Creep towards 80% while the request is in flight — it never reaches the end
   on its own, so it cannot claim "done" before the page actually swaps. */
.qc-nav-progress.is-active .qc-nav-progress__bar {
	animation: qc-nav-progress-creep 8s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

.qc-nav-progress.is-done .qc-nav-progress__bar {
	animation: none;
	inline-size: 100%;
	transition: inline-size 0.2s ease-out;
}

@keyframes qc-nav-progress-creep {
	0% {
		inline-size: 0;
	}
	40% {
		inline-size: 55%;
	}
	100% {
		inline-size: 80%;
	}
}

/* ============================================================
   5. Skeleton blocks — for a fragment that knows its own layout and
      would rather reserve the shape than cover it with a spinner.
   ============================================================ */

.qc-skeleton {
	display: block;
	border-radius: var(--qc-radius-sm, 0.375rem);
	background: linear-gradient(
			90deg,
			transparent 0,
			var(--qc-skeleton-shine) 50%,
			transparent 100%
		)
		var(--qc-skeleton-base);
	background-repeat: no-repeat;
	background-size: 200% 100%;
	/* The shimmer is a background sweep, not DOM/flex order, so it is
	   direction-safe; only the perceived sweep side differs under RTL. */
	animation: qc-skeleton-shimmer 1.4s ease-in-out infinite;
}

.qc-skeleton--text {
	block-size: 0.875rem;
	margin-block-end: var(--qc-spacing-md, 0.5rem);
}

.qc-skeleton--title {
	block-size: 1.5rem;
	inline-size: 60%;
	margin-block-end: var(--qc-spacing-xl, 1rem);
}

.qc-skeleton--circle {
	inline-size: 3rem;
	block-size: 3rem;
	border-radius: var(--qc-radius-full, 9999px);
}

.qc-skeleton--card {
	block-size: 100%;
	min-block-size: 12rem;
	border-radius: var(--qc-radius-2xl, 1rem);
}

/* The last line of a faked paragraph reads as text, not a full bar. */
.qc-skeleton--text:last-child {
	inline-size: 70%;
	margin-block-end: 0;
}

@keyframes qc-skeleton-shimmer {
	0% {
		background-position: 150% 0;
	}

	100% {
		background-position: -50% 0;
	}
}

@keyframes qc-loader-fade-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

/* ============================================================
   6. Reduced motion — keep the "busy" signal, drop the spin/sweep
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
	.qc-spinner,
	.qc-spinner::after,
	[data-qc-loading]::after,
	.qc-content-loading #main-content::after,
	.qc-page-loading body::after {
		animation: qc-loader-pulse 1.4s ease-in-out infinite;
	}

	.qc-skeleton {
		background: var(--qc-skeleton-base);
		animation: qc-loader-pulse 1.6s ease-in-out infinite;
	}

	.qc-nav-progress.is-active .qc-nav-progress__bar {
		animation: none;
		inline-size: 60%;
	}
}

@keyframes qc-loader-pulse {
	0%,
	100% {
		opacity: 1;
	}

	50% {
		opacity: 0.35;
	}
}

/* ============================================================
   7. Dark mode — only the scrim and the greys need values here; the
      spinner reads --qc-* tokens, which qc-global.css already flips
      under [data-theme="dark"]. Literal values (not var()) because the
      mirrored ramp would otherwise pick light-mode tints.
   ============================================================ */

:root[data-theme="dark"] {
	--qc-loader-scrim: #1d1d1bee;
	--qc-loader-track: #4a4a49;
	--qc-loader-arc: #cd96a2;
	--qc-loader-accent: #c5a185;
	--qc-skeleton-base: #2a2a28;
	--qc-skeleton-shine: #3a3a37;
}

/* Visually-hidden live-region text written by QCLoader for screen readers. */
.qc-loader-sr {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
