/*
 * RA Builder — Canvas page shell + scoped reset  (CJ-004 / CJ-005 / CJ-006)
 * ---------------------------------------------------------------------------
 * SINGLE shared source, loaded on BOTH surfaces so editor == frontend:
 *   • frontend  — the canvas template (templates/ra-canvas.php) → `.ra-page` root
 *   • editor    — the builder canvas root `.ra-canvas`
 *
 * Purpose: neutralise the active theme's inherited defaults (body margin /
 * line-height, heading & paragraph margins, list bullets, link colour, box-sizing)
 * so RA content renders identically regardless of the theme wrapping the page.
 *
 * Every reset below uses :where() (specificity 0) so the CSS engine's emitted
 * node rules ALWAYS win — this can only REMOVE theme bleed, never fight the engine.
 * Scoped to `.ra-page` / `.ra-canvas` → cannot leak out to theme chrome.
 */

/* Page shell — fill the viewport so the page background never leaves theme grey showing. */
html,
body.ra-page-body { margin: 0; padding: 0; }
.ra-page { min-height: 100vh; }

/* Box model — the one high-specificity rule we keep, matching the editor's inline reset. */
.ra-page,
.ra-page *,
.ra-canvas,
.ra-canvas * { box-sizing: border-box; }

/*
 * ED-113 — the page's DEFAULT TEXT COLOUR, defined ONCE for every surface that shows an RA page
 * (editor canvas frame, canvas front end, preview route). Before this, the front end set none (the UA's
 * black, or whatever the theme leaked), and the editor frame inherited the colour of the THEME's
 * `global-styles-inline-css` (`body{color:#111}`) cloned in from the editor page: rgb(17,17,17) vs rgb(0,0,0).
 *
 * The value is the palette's text token (`--ra-color-text`, emitted by the CSS engine on `.ra-builder-document`
 * from the effective global styles: site palette, then the document's own) with `#111` as the fallback for a
 * document whose tokens are not emitted.
 *
 * Cascade, lowest first: this default (zero specificity, `:where`) < the page's own text colour (`settings.page
 * .textColor`, emitted on `.ra-builder-document` by the render engine / the editor root style) < the per-node
 * rules of the engine, which set colour on `.ra-node-<id>` wrappers that sit INSIDE this root. It is written on
 * the root every surface has (`.ra-builder-document`) so the token it reads is in scope.
 */
:where(.ra-builder-document) { color: var(--ra-color-text, #111); }

/* Typography / rhythm — reset theme-inherited defaults to the browser baseline the
   editor renders against (no theme in the editor → `normal`). Zero specificity. */
.ra-page,
.ra-canvas { line-height: normal; }

.ra-page :where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, pre),
.ra-canvas :where(h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, pre) { margin: 0; }

.ra-page :where(ul, ol),
.ra-canvas :where(ul, ol) { margin: 0; padding: 0; list-style: none; }

.ra-page :where(a),
.ra-canvas :where(a) { color: inherit; text-decoration: none; }

.ra-page :where(img, svg, video, canvas),
.ra-canvas :where(img, svg, video, canvas) { display: block; max-width: 100%; }

.ra-page :where(button, input, select, textarea),
.ra-canvas :where(button, input, select, textarea) { font: inherit; color: inherit; }

/*
 * CJ-012 RC-A — TEXT-COLOUR theme-bleed fix (engine-wide, every widget, every depth).
 * The active theme colours bare element selectors — Astra ships
 * `h1,h2,h3,h4,h5,h6{color:var(--ast-global-color-…)}` (specificity 0,0,1). Our CSS
 * engine sets colour on the node WRAPPER `.ra-node-{id}` and the inner text tag
 * (`<h4>`, `<p>`, `<li>`, `<a>`, …) INHERITS it — but a direct `h4{color}` beats an
 * inherited value, so the theme colour wins → brand/headings render the theme colour.
 * The :where() resets above (specificity 0) cannot fight it.
 *
 * Fix: force every inner text/semantic tag to INHERIT its node's colour, scoped to the
 * shared `.ra-builder-document` root (present on editor canvas + preview + published),
 * using :is() so the rule carries the root's CLASS weight → specificity (0,1,1),
 * out-specifying the theme's (0,0,1) — Elementor's exact principle (`.wrapper .text{color}`)
 * as ONE engine rule instead of a per-widget text-class across 116 renderers. Colour
 * resolves to wherever the engine set it (the nearest `.ra-node-{id}`), recursively up
 * to the page colour. No `!important`. Outside the byte-identical node-CSS path → parity untouched.
 */
.ra-builder-document :is(h1, h2, h3, h4, h5, h6, p, a, li, button,
  blockquote, cite, figcaption, th, td, dt, dd, span, strong, em, small, label) {
  color: inherit;
}

/*
 * CJ-019 — editor-theme token bleed into the rendered page.
 * In the editor the page renders INSIDE `.ra-app-shell`, which defines the editor's OWN
 * chrome design tokens — several are teal: `--ra-widget-bg:#14393A`, `--ra-container-bg`,
 * `--ra-input-bg`, `--ra-bg-*`, `--ra-hover-overlay`, `--ra-selected-bg` … Because they sit
 * on an ancestor, they INHERIT into `.ra-builder-document`, so ANY rendered content that
 * resolves one of them (a node style like `background: var(--ra-widget-bg)`, a widget default,
 * or a stray rule) paints the editor's TEAL — a colour that does NOT exist on the published
 * page, where these tokens are undefined. That is a real editor≠frontend divergence.
 *
 * Fix: on the document root, in the EDITOR ONLY (`#ra-builder-root` is absent on the front
 * end, so the published page is untouched), reset the editor CHROME tokens to the guaranteed-
 * invalid value. `var(--token)` then falls back exactly like the server (undefined → transparent
 * / the property's initial), so every background renders its REAL colour. The engine RE-emits the
 * design tokens (`--ra-color-*`, `--ra-font-*`, `--ra-space-*`, `--ra-shadow-*`, `--ra-radius-*`,
 * `--ra-fw-*`) on `.ra-builder-document`, so those keep working — only the chrome tokens are cut.
 */
#ra-builder-root .ra-builder-document {
  /*
   * ROOT responsive fix (replaces CJ-024): the editor now renders this document inside a
   * device-width <iframe> (components/CenterCanvas.tsx → IframeCanvas), so the engine's raw
   * `@media` rules evaluate against the frame's own viewport = the device width — byte-identical
   * to the published frontend. The old editor-only `container-type: inline-size; container-name:
   * ra-canvas` (which paired with the App.tsx `@media`→`@container ra-canvas` rewrite) is DELETED:
   * a container query is no longer needed, and it was the source of the intermittent re-layout
   * flake. The chrome-token reset below stays (CJ-019 — neutralise editor teal-token bleed).
   */
  --ra-widget-bg: initial;
  --ra-widget-hover: initial;
  --ra-container-bg: initial;
  --ra-container-selected: initial;
  --ra-input-bg: initial;
  --ra-bg-primary: initial;
  --ra-bg-secondary: initial;
  --ra-bg-tertiary: initial;
  --ra-toolbar-bg: initial;
  --ra-hover-overlay: initial;
  --ra-active-overlay: initial;
  --ra-selected-bg: initial;
}
