/* ==========================================================================
   Section

   A band of background color with other blocks inside it.
   ========================================================================== */

.ssb-section {
    /*
     * No background and no color here. "None" must leave whatever is
     * behind it alone, including a section that sits inside a page with
     * its own background.
     */
    display: block;
}


/* --------------------------------------------------------------------------
   Surfaces
   --------------------------------------------------------------------------
   Each surface sets its own text color, and redefines --color-text and
   --color-heading for everything inside it. That second part is what makes
   nested blocks work: a Rate Table dropped into a dark section reads
   var(--color-text) exactly as it always did, and gets the light value
   because the section changed what that means locally.

   Both halves of every pair have a neutral default in the parent theme, so
   a site with no child theme gets a readable section rather than an
   invisible one.
   -------------------------------------------------------------------------- */

/*
 * Base is the page's own surface, and not the same as None: None lets
 * whatever is behind it show through, which is the difference that matters
 * when a block sits inside a tinted section.
 */
.ssb-section--base {
    background-color: var(--color-surface);
    color: var(--color-on-surface);
    --color-text: var(--color-on-surface);
}

.ssb-section--subtle {
    background-color: var(--color-surface-subtle);
    color: var(--color-on-subtle);
    --color-text: var(--color-on-subtle);
    --color-heading: var(--color-on-subtle);
}

.ssb-section--primary {
    background-color: var(--color-primary);
    color: var(--color-on-primary);
    --color-text: var(--color-on-primary);
    --color-heading: var(--color-on-primary);
}

.ssb-section--secondary {
    background-color: var(--color-secondary);
    color: var(--color-on-secondary);
    --color-text: var(--color-on-secondary);
    --color-heading: var(--color-on-secondary);
}

.ssb-section--dark {
    background-color: var(--color-surface-dark);
    color: var(--color-on-dark);
    --color-text: var(--color-on-dark);
    --color-heading: var(--color-on-dark);
}


/* --------------------------------------------------------------------------
   Width
   --------------------------------------------------------------------------
   Full: the color runs the width of whatever contains the block, and the
   content inside is held to the container width.

   Contained: the whole band, color included, sits in the content column.
   -------------------------------------------------------------------------- */

/*
 * The gutters are added to the max-width, not taken out of it.
 *
 * This read `max-width: var(--container-width)` with the gutters padded
 * inside it, which under the box-sizing reset left the content 160px
 * narrower than every .container on the site — the exact mistake the note
 * on .container in design-system.css warns about, repeated here. A Full
 * Section measured 1040px of content where a top-level block measured
 * 1200px.
 */
.ssb-section--full .ssb-section__inner {
    width: 100%;
    max-width: calc(var(--container-width) + var(--block-padding-x) * 2);
    margin-inline: auto;
    padding-inline: var(--block-padding-x);
}


/* --------------------------------------------------------------------------
   Blocks inside a Section
   --------------------------------------------------------------------------
   A Section is a container. So is nearly every block that can go inside
   one — Content, Image & Text and the rest each wrap themselves in
   .container — and nested, the two sets of gutters add up. A Content block
   came out 880px wide inside a Section against 1200px on its own, and the
   editor had no way to see why.

   The inner container gives its width up to the Section, which is the one
   the editor placed and the one carrying the background. Nothing is
   centered twice and nothing is padded twice.

   Two classes, which clears .container in design-system.css.
   -------------------------------------------------------------------------- */

.ssb-section__inner .container {
    max-width: none;
    padding-inline: 0;
}

.ssb-section--contained .ssb-section__inner {
    padding-inline: var(--block-padding-x);
}


/* --------------------------------------------------------------------------
   A Full Section, previewed full width
   --------------------------------------------------------------------------
   The Section block has no Align control on purpose — it carries its own
   Width field, and two controls arguing over the same thing is worse than
   one. Width: Full already goes edge to edge on the page, through

       .entry-content > .ssb-section--full { width: 100vw; ... }

   in design-system.css. That selector needs .entry-content, which the
   editor canvas does not have, so the same block previewed inside the
   content column and shipped full bleed. The editor is the worst place
   for it to look wrong: it is where the decision gets made.

   Not 100vw here. On the page the viewport is the canvas; in the editor
   it is the window, sidebar included, so 100vw would run the band out
   under the inspector. What holds the preview in is a max-width on the
   wrapper the editor draws around the block — measured at 1040px inside
   a 1728px canvas, with the margins either side being `auto` taking up
   the slack. Releasing the max-width is enough on its own: auto margins
   have nothing left to absorb once the box fills its parent.

   Contained is deliberately left alone. The whole point of that variant
   is that the band stays in the content column, so releasing every
   Section would widen exactly the ones that asked not to be.

   Three depths, and no more. :has() is needed because the variant class
   is on the block's markup and the width is on the wrapper above it, but
   a plain descendant :has() would also find a Full Section nested inside
   a Contained one and widen the wrong band. A nested Section sits at
   least five levels down — through .ssb-section__inner, ACF's
   InnerBlocks container and the nested block's own wrapper — so stopping
   at three clears every shape ACF wraps a preview in without reaching
   it.

   The attribute is repeated to carry the selector over whatever the
   editor declares that max-width with. It matches the same element.

   None of this touches the front end: ACF prints the block markup there
   with no wrapper, so there is no [data-type] to find.
   -------------------------------------------------------------------------- */

[data-type="acf/ssb-section"][data-type]:has(
    > .ssb-section--full,
    > * > .ssb-section--full,
    > * > * > .ssb-section--full
),
.editor-styles-wrapper [data-type="acf/ssb-section"][data-type]:has(
    > .ssb-section--full,
    > * > .ssb-section--full,
    > * > * > .ssb-section--full
) {
    max-width: none;
}


/* --------------------------------------------------------------------------
   Columns
   --------------------------------------------------------------------------
   Each block placed directly in the Section is one column, filling left to
   right. ACF allows exactly one <InnerBlocks /> per block, so there is no
   container per column to put things in — a column that needs several
   blocks holds a Section of its own, set to one column and no padding.

   The track list is a custom property rather than written into each rule,
   so the collapse to one column on a phone is a single declaration rather
   than a copy of every selector below it.

   Every selector here uses the child combinator. Written as a descendant
   it also matched the inner of any Section nested inside this one — which
   is the very thing the instructions tell an editor to do to group a
   column — so the nested Section inherited the grid and spread its own
   stack across it.

   align-items: start, so a short column does not stretch to the height of
   a tall one beside it. A picture in a narrow column should stay the
   height of the picture.
   -------------------------------------------------------------------------- */

.ssb-section--cols-2 > .ssb-section__inner,
.ssb-section--cols-3 > .ssb-section__inner,
.ssb-section--cols-4 > .ssb-section__inner {
    display: grid;
    grid-template-columns: var(--ssb-section-cols);
    gap: var(--space-lg, 2rem);
    align-items: start;
}

/*
 * minmax(0, …) rather than a bare fraction. A grid track sized in fr is
 * at least as wide as its content by default, so one long unbreakable
 * thing — a URL, a wide table — pushes the track past its share and the
 * columns stop adding up.
 */
.ssb-section--cols-2 > .ssb-section__inner {
    --ssb-section-cols: minmax(0, 1fr) minmax(0, 1fr);
}

.ssb-section--cols-3 > .ssb-section__inner {
    --ssb-section-cols: repeat(3, minmax(0, 1fr));
}

.ssb-section--cols-4 > .ssb-section__inner {
    --ssb-section-cols: repeat(4, minmax(0, 1fr));
}

.ssb-section--split-66-33 > .ssb-section__inner {
    --ssb-section-cols: minmax(0, 2fr) minmax(0, 1fr);
}

.ssb-section--split-33-66 > .ssb-section__inner {
    --ssb-section-cols: minmax(0, 1fr) minmax(0, 2fr);
}

.ssb-section--split-75-25 > .ssb-section__inner {
    --ssb-section-cols: minmax(0, 3fr) minmax(0, 1fr);
}

.ssb-section--split-25-75 > .ssb-section__inner {
    --ssb-section-cols: minmax(0, 1fr) minmax(0, 3fr);
}

/*
 * ACF does not always hand the inner blocks over as direct children of
 * the template's markup — depending on version and on whether this is the
 * editor or the front end, they can arrive inside a container of its own.
 * Both rules below were written as child chains through .ssb-section__inner
 * and so matched nothing when that container was there: the grid had one
 * item instead of two, and the nested Sections kept their gutters. One
 * cause, both symptoms.
 *
 * display: contents takes the container out of the box tree without
 * touching the DOM, so the blocks inside it become the grid's items. It
 * does nothing at all when the container is not there.
 */
.ssb-section__inner > .acf-innerblocks-container {
    display: contents;
}

/*
 * A Section nested inside another carries its own band and gutters, and
 * inside a column neither belongs — the outer Section already drew the
 * band and the column is already inside the gutters.
 *
 * Written as a descendant rather than a child chain, so it holds however
 * many containers ACF puts in between. Three classes, which clears the
 * --full and --contained rules above it whatever the source order.
 */
.ssb-section .ssb-section > .ssb-section__inner {
    max-width: none;
    padding-inline: 0;
}


/* --------------------------------------------------------------------------
   Padding
   -------------------------------------------------------------------------- */

.ssb-section--pad-none .ssb-section__inner {
    padding-block: 0;
}

.ssb-section--pad-small .ssb-section__inner {
    padding-block: var(--space-md);
}

.ssb-section--pad-medium .ssb-section__inner {
    padding-block: var(--space-xl);
}

.ssb-section--pad-large .ssb-section__inner {
    padding-block: var(--space-3xl);
}


/*
 * 768px, and both width classes named.
 *
 * This was one class at 600px, which lost to the two-class rules above
 * and so never applied: a Full Section kept the 80px desktop gutter on a
 * phone, leaving 215px of content on a 375px screen where .container gave
 * 315px. The rule was right and simply outweighed.
 *
 * 768px because that is where .container swaps to the mobile gutter in
 * design-system.css. At 600 the two disagreed between 600 and 768, so a
 * Section and the block beside it had different margins on a tablet.
 */
@media (max-width: 768px) {

    .ssb-section--full .ssb-section__inner,
    .ssb-section--contained .ssb-section__inner {
        padding-inline: var(--block-padding-x-mobile);
    }

    .ssb-section--full .ssb-section__inner {
        max-width: calc(var(--container-width) + var(--block-padding-x-mobile) * 2);
    }

    /*
     * One column on a phone, whatever was chosen.
     *
     * Setting the track list rather than the grid-template-columns itself,
     * and on the same three selectors that set it above — the split rules
     * carry the same weight as these, so an override has to either match
     * them or come later. This does both.
     */
    .ssb-section--cols-2 > .ssb-section__inner,
    .ssb-section--cols-3 > .ssb-section__inner,
    .ssb-section--cols-4 > .ssb-section__inner {
        --ssb-section-cols: minmax(0, 1fr);
    }

}
