/*
 * rhythm.css — the SINGLE vertical-rhythm system for migrated sites. Spacing between sections is owned by
 * the BOUNDARY (computed from the two sections' fills), not added independently by each section (which is
 * what doubles up). Loaded site-wide so it governs every tier (.nb-content, .nb-cpt-bespoke, CPT views)
 * and any brand palette — no per-design or per-tier patches.
 *
 * Contract (stamped at generation by PageBuilder / SiteCta / the bespoke CPT template / breadcrumbs):
 *   data-bleed         → a full-width band.
 *   data-fill="<key>"  → its background identity: none | base | tint | warm | brand | dark | image.
 *
 * SPECIFICITY (deliberate, no !important): every section is stamped with BOTH attributes, so the rules key
 * on `[data-bleed][data-fill]` (0,2,0) — enough to beat the per-site design.css's `.nb-site section` rules
 * (0,1,1) we generate, without an !important arms-race. Same-fill COLLAPSE + GAP rules are adjacent-sibling
 * (0,4,0) so they win over the per-element INSET (0,2,0). The cause of conflicts is removed at the source:
 * the LAYOUT_RESET's `[data-section]` padding only matches sections that carry data-section (the bespoke
 * front-page design), NOT these stamped bands.
 *
 * Two kinds of space, kept separate:
 *   INSET — padding INSIDE a filled band so its content never touches the coloured edge. Intrinsic; always.
 *   GAP   — space BETWEEN sections; a function of (prevFill, nextFill):
 *     • different filled bands → SEAM: 0 gap, the colour change is the divider (each keeps its inset).
 *     • same filled bands      → COLLAPSE: drop the following band's top inset → one gap, not two.
 *     • a transparent section in the pair → RHYTHM GAP (a margin) so content breathes.
 */

:root {
  /* ── The spacing scale is ACSS's (`--space-xs … --space-xxl`), NOT ours — ACSS already ships a fluid
     scale on :root and its own utilities (`.padding--l`, `[class*="gap--"]`) resolve those same vars, so
     defining our own would shadow them site-wide. We just NAME the two rhythm roles in terms of ACSS steps.
     Each `var()` carries a fallback so the system still renders if ACSS is ever absent (it isn't, on the
     platform). Tune spacing per-site in the ACSS config, and the rhythm follows. ── */
  --rhythm-inset: var(--space-xl, clamp(48px, 6vw, 96px));  /* a filled band's internal top/bottom padding */
  --rhythm-gap:   var(--space-l,  clamp(32px, 4vw, 64px));  /* breathing space at a transparent↔band edge */
}

/* ── FILL FLOOR: what a `data-fill` key LOOKS like, when nothing else says. ─────────────────────────
 *
 * The contract above stamped an identity on every band but only ever spent it on SPACING, so the
 * background lived somewhere else entirely: on `.nb-section--tint` in the parent (scoped to
 * `.nb-content` / `.nb-cpt-bespoke`), and on `.nb-site [data-fill="tint"]` in each site's generated
 * design.css. Two parallel systems for one idea, and a gap between them — a library pattern dropped
 * outside those two wrappers on a spec-built site got NO band styling at all, because its design.css
 * defines zero `.nb-section--*` rules. That is what made the component library's auto-theming broken
 * rather than merely unpolished (docs/theme-architecture.md §5c, docs/component-library.md §7).
 *
 * So the fill keys get their colours here, once, from ACSS tokens — the floor that makes a band render
 * sanely anywhere, on any tier, with no design.css present at all.
 *
 * ⚠ SPECIFICITY IS THE WHOLE POINT: `:where()` keeps every selector below at (0,0,0), so ANY per-site
 * rule wins — the generated `.nb-site [data-fill="tint"]` is (0,2,0) and overrides this without effort.
 * This is a floor, not a preference. Never raise these; add the opinion to the child's design.css.
 */
:where([data-fill="none"])  { background: transparent; }
:where([data-fill="base"])  { background: var(--base, #fff); }
:where([data-fill="tint"])  { background: var(--primary-ultra-light, #f4f6f4); }
:where([data-fill="warm"])  { background: var(--base-ultra-light, #f1ede2); }
/* `brand` is a WASH, not the solid brand colour — that is how the generated designs actually use it
   (`--brand-wash`), and it is the only safe default: a floor cannot pair colour with background across
   the cascade. A design that overrides just the `background` (which every generated design.css does)
   would keep a light `color` from here and render near-white text on its own light wash. Measured on
   the live Elholm: forcing the pair here turned the brand band into #FBFBF8 on a #DDD9D6 ground.
   So light-on-light is impossible by construction: no `color` is declared for the light fills. */
:where([data-fill="brand"]) { background: color-mix(in srgb, var(--primary, #0a4a24) 12%, var(--base, #fff)); }

/* Only the fills that are DARK in every direction carry a colour: their floor background is dark, and
   every generated design.css also sets a dark background + its own light ink for these two. Overriding
   one without the other cannot produce an unreadable pair here. */
:where([data-fill="dark"])  { background: var(--primary-dark, #23262c); color: var(--text-light, #FBFBF8); }
:where([data-fill="image"]) { color: var(--text-light, #FBFBF8); }  /* the image itself is set per band */
:where([data-fill="dark"], [data-fill="image"])
  :where(h1, h2, h3, h4, h5, h6, p, li, dt, dd, blockquote, figcaption, strong, em, span, a) {
  color: var(--text-light, #FBFBF8);
}

/* ── INSET: one rule per filled fill (no overlap → no specificity conflict). Transparent = no inset. ── */
[data-bleed][data-fill="base"],
[data-bleed][data-fill="tint"],
[data-bleed][data-fill="warm"],
[data-bleed][data-fill="brand"],
[data-bleed][data-fill="dark"]  { padding-block: var(--rhythm-inset); }
[data-bleed][data-fill="image"] { padding-block: var(--space-xxl, clamp(64px, 8vw, 128px)); }  /* taller — content over imagery wants more air */
[data-bleed][data-fill="none"]  { padding-block: 0; }

/* ── A LEADING BLEED IMAGE MEETS THE HEADER (mobile only). ──────────────────────────────────────────
   The inset above separates a band from the one BEFORE it. The first band in `<main>` has nothing
   before it — only the fixed header — so once the hero STACKS on mobile and its photo becomes the
   first thing in flow, that inset is a visible gap between header and image: 33px at 390px wide
   (`--rhythm-inset` is `clamp(30px, 8.5vw, 42px)`). Reported twice by Jesper on elholm.dev —
   "der er noget ekstra afstand i toppen af hero-billedet".

   ⚠ MOBILE ONLY, AND THE BREAKPOINT IS LOAD-BEARING. Above it the same hero is an OVERLAY: the photo
   is `position:absolute` and the inset positions the TEXT over it, not the image. Measured on
   elholm.dev at 1440px — dropping it there does not move the photo one pixel (it is absolute) and
   instead pulls the h1 up 67px, leaving 38px of clearance under the header on a layout that was just
   signed off. The gap only exists where the image is in flow, so the fix lives where the stacking does.

   Scoped to `:has(> img:first-child)`: the bleed-photo hero and nothing else. A leading TEXT band keeps
   its inset or its first line collides with the header, and content pages lead with `.nb-breadcrumbs`,
   untouched. Only the top is dropped — the bottom inset still separates the band from what follows.

   Specificity (0,3,1) beats the (0,2,0) inset rules above without `!important` (Constitution rule 3). */
@media (max-width: 768px) {
  main > [data-bleed]:first-child:has(> img:first-child) { padding-block-start: 0; }
}

/* ── COLLAPSE same-fill adjacency (0,4,0 > inset): two same-colour bands read as ONE → drop the following
   band's top inset so the middle gap is a single inset, not doubled. EXCEPTION: the closing CTA
   (`.nb-site-cta`) is a distinct call-to-action, not a visual continuation of the band above — it keeps its
   own top inset even when the preceding band shares its fill (else its heading butts against that band's
   content). `:not(.nb-site-cta)` on the following band excludes it. ── */
[data-bleed][data-fill="base"]  + [data-bleed][data-fill="base"]:not(.nb-site-cta),
[data-bleed][data-fill="tint"]  + [data-bleed][data-fill="tint"]:not(.nb-site-cta),
[data-bleed][data-fill="warm"]  + [data-bleed][data-fill="warm"]:not(.nb-site-cta),
[data-bleed][data-fill="brand"] + [data-bleed][data-fill="brand"]:not(.nb-site-cta),
[data-bleed][data-fill="dark"]  + [data-bleed][data-fill="dark"]:not(.nb-site-cta),
[data-bleed][data-fill="image"] + [data-bleed][data-fill="image"]:not(.nb-site-cta) { padding-top: 0; }

/* ── RHYTHM GAP (0,4,0): a transparent section in the boundary gets a margin so content breathes off the
   band. Different-fill filled↔filled has NO rule → margin 0 → SEAM (the bands hug). ── */
[data-bleed][data-fill="none"] + [data-bleed][data-fill],
[data-bleed][data-fill]        + [data-bleed][data-fill="none"] { margin-top: var(--rhythm-gap); }

/* ── The closing CTA band (SiteCta, a brand fill) follows the page's last section. It carries a base
   margin-top (for un-stamped contexts like the generic CPT single); a FILLED band directly before it is a
   SEAM → the colours touch (drop the margin). A transparent section before it keeps the base gap. ── */
[data-bleed]:is([data-fill="base"],[data-fill="tint"],[data-fill="warm"],[data-fill="brand"],[data-fill="dark"],[data-fill="image"]) + .nb-site-cta { margin-top: 0; }

/* ── CLOSING BOUNDARY (main→footer, F17 decision 5): the page must always CLOSE against the footer,
   regardless of the last band's fill. A FILLED last band is a SEAM — its own `--rhythm-inset` bottom
   padding IS the closure, so it hugs the footer (no rule needed; the canonical F17 closer, the brand
   `.nb-site-cta`, is exactly this case). A TRANSPARENT (`fill="none"`) last band has 0 padding, so on its
   own it would sit 0px on the footer border (the /om-elholmbegravelse "button on the footer line" defect);
   give it `--rhythm-gap` of breathing space before the footer. Boundary-owned (constitution rule 4) — no
   ad-hoc band margins. Holds across every tier's content main (.nb-content / .nb-cpt-bespoke / CPT
   .nb-single), keyed on the last full-bleed band being the main's last child. ── */
:is(.nb-content, .nb-cpt-bespoke, .nb-single) > [data-bleed][data-fill="none"]:last-child { margin-block-end: var(--rhythm-gap); }

/* ── Breadcrumb boundary: the crumb is chrome (a thin band) just before the first content band. Hug it to a
   full-bleed first section; otherwise its own bottom margin (cpt.css) provides the gap. ── */
.nb-content--bleed-first .nb-breadcrumbs,
.nb-cpt:has(.nb-cpt-bespoke) .nb-breadcrumbs { margin-bottom: 0; }


/* ══ TYPOGRAPHY RHYTHM ════════════════════════════════════════════════════════════════════════════════
   Consistent vertical spacing for headings / paragraphs / lists WITHIN a prose flow — the same philosophy
   as the section rhythm, one level down: the GAP belongs to the boundary. Every `.nb-flow` container gets:
     • a base step between consecutive blocks (paragraph rhythm),
     • MORE space ABOVE a heading (it separates from the prior content),
     • a TIGHT bind BELOW a heading (it introduces the text that follows),
     • NO leading gap on the first child.
   em-based so the step scales with each element's size. Plain single-class `.nb-flow` (0,1,0) is enough:
   the design.css's base `h2/p{margin:0}` resets are scoped SOFT — `:where(.nb-site) p` (0,0,1) — so a
   class beats them with no doubled-class or !important trick (see EtchImport::scope_css $soft). A SECTION
   title is governed by the section rhythm above; a heading INSIDE the flow is governed here. Applied
   everywhere via the `.nb-flow` marker (PageRender / PageBuilder add it). These are the TYPE axis: em-based
   (relative to each element's own size) rather than the viewport-fluid --space-* layout scale — a heading's
   space should track the heading's size, not the page width. The two axes are intentionally separate. ── */
:root { --flow-step: 1.1em; --flow-before-heading: 2em; --flow-after-heading: .55em; }

.nb-flow > * { margin-block: 0; }
.nb-flow > * + * { margin-block-start: var(--flow-step); }
.nb-flow > * + :is(h2, h3, h4, h5) { margin-block-start: var(--flow-before-heading); }
.nb-flow > :is(h1, h2, h3, h4, h5) + * { margin-block-start: var(--flow-after-heading); }

/* A mid-prose INSERT is a block, not a paragraph — it needs air on BOTH sides, and nothing
   above gives it any. The owl only ever adds `margin-block-start`, and `content.css`'s
   `.nb-content p{margin:0 0 1em}` opts paragraphs out of the owl entirely and spaces them
   with a BOTTOM margin instead. So an insert between two paragraphs gets the owl's step
   above it and NOTHING below: measured on elholm 2026-09-02, 20px above and 0px below on
   all six pages carrying one, in both the `.nb-content` and `.nb-cpt-body` contexts. The
   insert's own `margin:32px 0` (cpt.css) never applied — `.nb-flow > *{margin-block:0}`
   above has the same specificity and loads later, so it zeroes it.
   0,2,0 beats that; no `!important` (Constitution rule 3). */
.nb-flow > .nb-midcta { margin-block: var(--flow-insert, 2rem); }
