/*-----------------------------------------------------------------------------------
    Cheval Royal — Canvas 8 / Bootstrap 6 compat

    Two jobs, with deliberately different cascade positions:

    1. Token shim — unlayered `:root` custom properties. Fills the properties the Canvas 8 entry
       references but nothing else in the served chain defines, so declarations that were invalid
       resolve to the numbers Canvas 8 itself uses. `phase2-canvas8-refs.mjs` reports zero
       unresolved tokens with this sheet in the chain. Unlayered because a token must win over the
       Canvas 8 definition it is replacing.
    2. Parity pins — inside `@layer canvas8-compat`. The Canvas 8 sheet wraps everything in
       `@layer canvas8`, and a layer named later (this sheet is linked after it) outranks it
       regardless of specificity. Unlayered Cheval Royal CSS still outranks every layer, so these
       pins override Canvas 8 only and never out-rank the site's own rule for the same property —
       which is why the button pin below does not disturb `.btn-small` / `.header-icon a`, whose
       centring the site declares unlayered.

    Why pins are needed at all: the Canvas 8 layer is lowest in the cascade, so it cannot
    out-rank an existing declaration, but it *does* apply wherever Cheval Royal declares nothing.
    That is how a layered sheet restyles existing markup with no selector change, and each pin
    below answers a difference measured by `tests/e2e/tools/canvas8-impact.mjs` (geometry and
    computed style), `canvas8-box-diff.mjs` (horizontal position and pseudo-elements) or
    `canvas8-probe.mjs` (CSS rule provenance).

    Keep this sheet small and evidence-driven, and say what to revisit when the markup is
    translated to Bootstrap 6.
-----------------------------------------------------------------------------------*/

:root {
	/* Bootstrap 5's radius scale, aliased to Bootstrap 6's `--radius-*` steps.
	   Consumed by `_bs5-compat.scss` (.modal-content) and by Bootstrap 5-era markup that
	   still lives in Page Builder content. Bootstrap 5 had .25rem/.5rem/.75rem; Bootstrap 6
	   keeps a 10-step scale, so the aliases point at the matching Bootstrap 6 steps rather
	   than re-deriving values. */
	--bs-radius-1: var(--radius-1);
	--bs-radius-2: var(--radius-2);
	--bs-radius-3: var(--radius-3);
	--bs-radius-4: var(--radius-4);
	--bs-radius-5: var(--radius-5);
	--bs-radius-6: var(--radius-6);

	/* Canvas' form-control sizing tokens. `_bs6-parity.scss` re-points them for
	   .input-group-lg / .input-group-sm, but the definitions live in the Canvas theme's
	   `_forms.scss`, which is not part of Cheval Royal's entry. Values are Canvas 8's own
	   ($input-btn-* in `_bs5-bridge.scss`), which match Bootstrap 5.
	   Scoped here rather than on `.form-control` so the size steps are inherited by the
	   buttons and addons inside a sized input group. */
	--cnvs-input-btn-padding-y: 0.375rem;
	--cnvs-input-btn-padding-x: 0.75rem;
	--cnvs-input-btn-font-size: 1rem;
	--cnvs-input-btn-line-height: 1.5;
	--cnvs-input-btn-border-width: 1px;
	--cnvs-input-btn-border-radius: 0.375rem;

	--cnvs-input-btn-padding-y-sm: 0.25rem;
	--cnvs-input-btn-padding-x-sm: 0.5rem;
	--cnvs-input-btn-font-size-sm: 0.875rem;

	--cnvs-input-btn-padding-y-lg: 0.5rem;
	--cnvs-input-btn-padding-x-lg: 1rem;
	--cnvs-input-btn-font-size-lg: 1.25rem;

	/* Bootstrap 5 typography tokens that Bootstrap 6 dropped or renamed. The generated legacy
	   subset (`Client/styles/legacy/legacy-public-compat.css`, PurgeCSS output of the Canvas 7
	   sheet) still reads them — `.nav-link` font size/weight, `.breadcrumb-link` font size and
	   `body` text-align — and nothing else in the live cascade defines them, so those declarations
	   resolved to the guaranteed-invalid value and silently fell back to the inherited/initial one.
	   Values are the Bootstrap 5 defaults, i.e. what the shipped markup was designed against. The
	   subset is generated, so the tokens are defined here rather than hand-edited into it. */
	--bs-nav-link-font-size: 1rem;
	--bs-nav-link-font-weight: 400;
	--bs-breadcrumb-font-size: 0.875rem;
	--bs-body-text-align: left;

	/* Cheval Royal theme values in Bootstrap 6 token names.
	   Bootstrap 6 `root`/`reboot` read these unprefixed names (`--font-family-sans-serif`,
	   `--font-size-root`, `--font-weight-body`, `--body-color`, ...). Before this block they
	   resolved to Bootstrap 6's stock defaults, so once Canvas 7 lost its unlayered authority
	   the site fell back to the system font stack, a 16px base and Bootstrap's grey body text.
	   Values are the Cheval Royal design system as measured from the Canvas 7 cascade
	   (`baseline-canvas7.json`): Inter body at clamp(1rem, .97rem + .12vw, 1.075rem),
	   Playfair Display headings, #202735 text on #ffffff, burgundy #c8102e accent, and the
	   10/18/28px radius scale. Unlayered so they outrank the `canvas8` definitions they replace,
	   exactly like the token shim above. */
	--font-family-sans-serif: "Inter", "Inter Fallback", -apple-system, BlinkMacSystemFont,
		"Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
	--font-family-serif: "Playfair Display", "Playfair Display Fallback", Georgia,
		"Times New Roman", serif;
	--font-family-base: var(--font-family-sans-serif);
	/* Bootstrap 5 aliases read by the unlayered legacy-public-compat.css body/reboot block.
	   That sheet is PurgeCSS output of the Crafto bundle and carries Bootstrap 5 core, so its
	   `body { font-family: var(--bs-body-font-family) }` outranks every layer. Re-pointing the
	   aliases here makes Bootstrap 5 emit the Cheval Royal values instead of its stock ones;
	   the Bootstrap 6 chain reads the unprefixed names above. */
	--bs-font-sans-serif: var(--font-family-sans-serif);
	--bs-body-font-family: var(--font-family-sans-serif);
	--bs-body-font-size: var(--font-size-root);
	--bs-body-font-weight: var(--font-weight-body);
	--bs-body-line-height: var(--line-height-body);
	--bs-body-color: var(--body-color);
	--bs-body-bg: var(--body-bg);
	--bs-heading-color: var(--heading-color);
	--bs-link-color: var(--link-color);
	--bs-link-hover-color: var(--link-hover-color);
	--bs-border-color: var(--border-color);
	--bs-border-radius: var(--btn-border-radius);
	/* Crafto theme aliases the legacy subset still reads. */
	--primary-font: var(--font-family-sans-serif);
	--medium-gray: var(--body-color);

	/* Crafto alternate-font alias, still read by the legacy subset. It pointed at
	   "Plus Jakarta Sans", which leaked into `.btn` and heading rules. */
	--alt-font: var(--font-family-sans-serif);

	/* Bootstrap 5 `.btn` defaults carried by the unlayered legacy subset
	   (`--bs-btn-font-weight: 400`, `--bs-btn-font-size: 1rem`). Cheval Royal buttons are
	   700 weight at the theme base size, so re-point the Bootstrap 5 aliases here rather than
	   re-declaring `.btn` and fighting PurgeCSS output. */
	--bs-btn-font-family: var(--font-family-sans-serif);
	--bs-btn-font-weight: var(--btn-font-weight);
	--bs-btn-font-size: var(--font-size-root);
	--bs-btn-border-radius: var(--btn-border-radius);

	/* Theme base typography, unlayered.
	   `body.canvas7` (now `body.cr-canvas-scope`) and the heading font rule lived in
	   canvas7.scss and were the authoritative
	   source of these values. Those rules now live inside `@layer cr-canvas-legacy`, which is the lowest
	   layer, so Bootstrap 5's unlayered `body` reboot outranks it and the site lost Inter, the
	   clamp() base size and Playfair headings. Re-declared here unlayered, in Bootstrap 6 token
	   names, so the theme keeps its authority while Canvas 7 is removed. `body, html` matches the
	   specificity that currently wins in the cascade. */
	body,
	html {
		font-size: var(--font-size-root);
	}

	body {
		font-family: var(--font-family-sans-serif);
		color: var(--body-color);
		background-color: var(--body-bg);
		line-height: var(--line-height-body);
		font-weight: var(--font-weight-body);
		text-rendering: optimizeLegibility;
		-webkit-font-smoothing: antialiased;
	}

	:where(h1, h2, h3, h4, h5, h6, .alt-font) {
		font-family: var(--font-family-serif);
		color: var(--heading-color);
		font-weight: var(--font-weight-heading);
		line-height: var(--line-height-heading);
	}
	--font-family-heading: var(--font-family-serif);
	--font-size-root: clamp(1rem, 0.97rem + 0.12vw, 1.075rem);
	--font-size-body: var(--font-size-root);
	--font-weight-body: 400;
	--font-weight-heading: 650;
	--line-height-body: 1.7;
	--line-height-heading: 1.15;
	--body-bg: var(--cr7-paper, #ffffff);
	--body-color: var(--cr7-text, #202735);
	--heading-color: var(--cr7-ink, #090b10);
	--color-primary: var(--cr7-primary, #c8102e);
	--color-primary-emphasis: var(--cr7-primary-dark, #9f0d25);
	--link-color: var(--cr7-primary, #c8102e);
	--link-hover-color: var(--cr7-primary-dark, #9f0d25);
	--border-color: var(--cr7-line, #dfe4ec);
	--radius-sm: var(--cr7-radius-sm, 10px);
	--radius: var(--cr7-radius, 18px);
	--radius-lg: var(--cr7-radius-lg, 28px);
	--btn-font-weight: 700;
	--btn-border-radius: var(--cr7-radius-sm, 10px);
}

@layer canvas8-compat {
	/*-----------------------------------------------------------------------------------
        Parity pins — Canvas 8 declarations that apply because Cheval Royal declares
        nothing for that property, so being lower in the cascade does not protect the layout.
    -----------------------------------------------------------------------------------*/

	/* Bootstrap 6's reboot sets these on `:root, :host`; the site's CSS never mentions them, so
	   the layered value would otherwise win by default and change the whole document:
	   - `scrollbar-gutter: stable` reserves a gutter, narrowing every container by the scrollbar
	     width (measured 1280 → 1265 px at the viewport, every container and section −15 px, and
	     the footer inherits it).
	   - `color-scheme: light dark` lets the browser paint form controls and scrollbars dark on a
	     dark-mode OS.
	   - `accent-color: var(--primary-base)` recolours native checkboxes and radios.
	   Revisit in Phase 4: adopting them is a design decision, not a migration requirement. */
	:root,
	:host {
		scrollbar-gutter: auto;
		color-scheme: normal;
		accent-color: auto;
	}

	/* Bootstrap 6 re-implements `.collapse` as an animated size (`block-size: 0` +
	   `overflow-y: clip` in the closed state) instead of Bootstrap 5's `display: none` alone.
	   Two consequences on markup written against Bootstrap 5:
	   - `collapse d-lg-block` (the footer's opening-hours block, and the Bootstrap 5 idiom for
	     "hidden on small screens, always shown above the breakpoint") keeps `display: block` from
	     the utility, so it stays visible but is clipped to zero height — measured −344 px, which
	     pulled the footer up by 107 px.
	   - `overflow-y: clip` on an open panel clips focus rings and any overflowing content, and
	     `interpolate-size: allow-keywords` is inherited by its children.
	   The pin is scoped to `:not(.navbar-collapse)`, which leaves exactly one element in shipped
	   markup: the footer's opening-hours block (`OpenHours.cshtml`, the only remaining
	   `collapse d-*-block`). Its toggle carries no `data-bs-toggle="collapse"`, so Bootstrap 6's
	   Collapse data-API never claims it and it is opened by a `.show` class toggle in
	   `chevalroyal-canvas7.js` — restoring the Bootstrap 5 geometry there is behaviour-neutral.
	   Every other `.collapse` (the FAQ card panels, the three contract panels, the header) is now
	   driven by Bootstrap 6's own Collapse data-API, and those panels are meant to take the
	   Bootstrap 6 animation, so they are deliberately *not* pinned.
	   Revisit if a `collapse d-*-block` element is added, or if the opening-hours block moves to a
	   real `data-bs-toggle="collapse"` toggle. */
	.collapse:not(.navbar-collapse) {
		overflow-y: visible;
		interpolate-size: collapse;
		/* Bootstrap 5 animated a collapse through a temporary `.collapsing` class added by its JS,
		   not on `.collapse` itself, so the plain class carried no transition. Without this pin the
		   discrete `display` transition delays the visibility flip by half the duration. */
		transition: none;
	}

	.collapse:not(.show):not(.navbar-collapse) {
		block-size: auto;
	}

	/* Header exemption. Canvas 8 dropped `.navbar-collapse` entirely — its navbar is a `<dialog>`
	   drawer built on container queries, so `chevalroyal-canvas8.css` contains no `.navbar-collapse`
	   rule at all — while Cheval Royal's header geometry is unlayered CSS that already reproduces
	   Bootstrap 5: `critical/_header.scss` gives the closed state `display: none` and the expanded
	   state `display: flex !important`, and `_header-new.scss` sizes the mobile drawer by fixed
	   insets and slides it with `transform`, never by height. Nothing in `Client/styles` sets an
	   explicit height on `.navbar-collapse`, so Bootstrap 6's `block-size` animation is inert there;
	   what *would* reach it is `overflow-y: clip` (clipping desktop dropdowns and focus rings above
	   the breakpoint) and inherited `interpolate-size`. `transition: none` keeps the discrete
	   `display` flip instant, matching Bootstrap 5; the unlayered mobile drawer rule
	   (`transition: var(--cr-mobile-menu-transition)`) still overrides it below the breakpoint, so
	   the drawer slide is unaffected. Revisit if the header moves to Canvas 8's drawer model. */
	.navbar-collapse {
		overflow-y: visible;
		interpolate-size: collapse;
		block-size: auto;
		transition: none;
	}

	/* Bootstrap 6's button component uses `.btn-icon` and `.btn-text` as *button variant* names.
	   Cheval Royal's own button markup uses the same two names for `<span>` wrappers inside
	   `.btn.btn-hover-animation` (`HeroSection.cshtml`, `Events.cshtml`, `EventSchedule.cshtml`),
	   so the variant rules landed on the spans: `span.btn-icon` gained a 1px bordered, rounded box
	   (14 → 20.375 px tall at 480 px, and `aspect-ratio: 1/1` squaring it) and `span.btn-text`
	   gained the same box plus padding and lost its button's bold weight. The pin is limited to
	   elements that are not buttons or links, which is exactly where a variant cannot belong — a
	   real Bootstrap 6 icon button (`<button class="btn btn-icon">`) keeps its styling.
	   `align-items` is pinned on `.btn-text` only: the site already centres `.btn-icon`, so
	   pinning it there would change the pre-wiring value rather than restore it. Revisit in
	   Phase 3 when the button markup adopts Bootstrap 6's variant names for real. */
	.btn-icon:not(button):not(a),
	.btn-text:not(button):not(a) {
		background-color: transparent;
		border: 0;
		border-radius: 0;
		color: inherit;
		font-weight: inherit;
		gap: normal;
		padding: 0;
		vertical-align: baseline;
		/* Bootstrap 6's icon-button variant squares itself up; on a wrapper span that turns the
		   18.375 x 14 px icon box into a square and shifts the glyph 4 px down. */
		aspect-ratio: auto;
		/* Canvas drives the button's nowrap through this token, not a literal declaration, so the
		   token has to be pinned: `text-wrap-mode: normal` is not a valid value and is dropped. */
		--btn-white-space: normal;
	}

	.btn-text:not(button):not(a) {
		align-items: normal;
	}

	/* Bootstrap 6 centres a button's label (`justify-content: center` on every button variant). On
	   a flex button that is wider than its content this moves the label: the footer language
	   switcher (`display: inline-flex`, enforced 139.016 px wide) shifted its globe glyph and
	   language name 0.56 px left — invisible to the geometry gate because the button box itself is
	   unchanged, and visible in the footer of every page. Buttons the site explicitly centres
	   declare it unlayered (`.quantity-controls .btn`, `.cart-panel-actions .btn`, `.btn-small`),
	   which this layered pin cannot out-rank. Non-flex buttons are unaffected either way.
	   Revisit in Phase 4 as an adoption decision. */
	.btn,
	.btn-link,
	.btn-icon,
	.btn-solid,
	.btn-outline,
	.btn-subtle,
	.btn-text {
		justify-content: normal;
	}
}
