/* Menu Layout — shared across every menu design (designs/menus/*). Controls
   WHERE logo/nav/CTA sit (menu_layout + mobile_bar settings); menu DESIGNS
   control how they look (colors, dropdown/drawer style). Breakpoint tokens:
   1080px/1081px are substituted by srdss_process_breakpoint_css() when the
   admin sets a Mobile Breakpoint other than the default.

   Split layout needs extra elements the other four presets don't (rendered
   by the design template.php via srdss_menu_render_split_half()):
   nav.srd-nav--split-left / --split-right, a desktop-only CTA copy
   div.srd-cta--split-desktop, and a desktop-only HTML Slot copy
   div.srd-html-slot-wrap--split-desktop. All are absent from the DOM for
   every other layout, and hidden below the breakpoint regardless — every
   layout collapses to the same drawer + hamburger experience on mobile. */

/* The header row. Max Width caps the contents and centres them while
   .srd-header keeps its background, border and shadow edge to edge — a
   full-bleed bar with a contained row is the whole point of putting these
   here rather than on the header element.

   box-sizing is declared rather than assumed: width is 100% and the padding
   is the admin's, so a content-box row would overflow its own header by the
   padding. Most themes set border-box globally; the suite may not rely on one
   being there (rule 1).

   All three var() fallbacks reproduce the header as it was before these
   settings existed — no cap, no padding — so a site that leaves them blank
   renders identically. */
.srd-header-wrap {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    box-sizing: border-box;
    width: 100%;
    max-width: var(--srd-header-max-width, none);
    margin-inline: auto;
    padding-block: var(--srd-header-pad-y, 0);
    padding-inline: var(--srd-header-pad-x, 0);
    gap: 0 20px;
}

.srd-header-wrap .srd-logo-link   { grid-column: 1; display: flex; align-items: center; }

/* gap: the HTML Slot's mobile copy (a flex child before .srd-hamburger-wrap
   below the breakpoint) needs breathing room from the hamburger button; on
   desktop the only in-flow child is .srd-drawer (slot/hamburger are
   display:none there), so the gap has nothing else to affect. */
.srd-header-wrap .srd-header-side { grid-column: 2; display: flex; align-items: center; width: 100%; gap: 12px; }

/* Logo sizing. Both dimensions are forced back to auto because the <img> is
   emitted with width/height attributes (CLS — see srdss_img_dimension_attrs()),
   and those attributes are presentational hints: left alone they pin the box to
   the file's own pixel size, so max-height clamps the height while the width
   stays put and the logo is stretched rather than scaled. With both auto the
   replaced-element sizing rules scale the width down with the height, which is
   what makes the Max Height settings mean what they say.

   flex-shrink: 0 / object-fit: contain guard the same distortion from the other
   side: .srd-logo-link is a flex container, and a flex item's main size (here
   the width) is resolved from its max-content size before any cross-axis
   max-height applies. Belt and braces — object-fit is a no-op whenever the
   width did resolve proportionally.

   These live here, not in a design's style.css, because the max-height they
   make work lives here: a design that did not repeat them would silently stop
   honouring the Logo Max Height settings.

   Which of the two logos is on screen is structural too, not a design choice —
   only one Max Height applies at a time because only one is displayed. The
   desktop-side half of that swap is in the mobile block below. */
.srd-header-wrap .srd-logo {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: var(--srd-logo-h, none);
    flex-shrink: 0;
    object-fit: contain;
}

.srd-header-wrap .srd-logo--mobile {
    display: none;
    max-height: var(--srd-logo-m-h, var(--srd-logo-h, none));
}

.srd-header-wrap .srd-nav--split-left,
.srd-header-wrap .srd-nav--split-right,
.srd-header-wrap .srd-cta--split-desktop {
    display: none;
}

/* Mobile Bar — logo/hamburger side, below the breakpoint only. Every layout
   collapses to this same bar on mobile. */
@media (max-width: 1080px) {
    .srd-header-wrap .srd-logo--desktop { display: none; }
    .srd-header-wrap .srd-logo--mobile  { display: block; }

    /* HTML Slot copies — the desktop one lives inside the drawer, which is
       where the mobile copy's whole point is not to be. The split-desktop
       copy carries --desktop too, so this one rule covers all of it.

       Doubled class (.srd-html-slot-wrap.srd-html-slot-wrap--desktop) purely
       for specificity: a menu design's own style.css sets display:flex on
       .srd-header-wrap .srd-html-slot-wrap, which matches just as tightly and
       loads after this file. Without the extra class the hide would lose the
       cascade to a cosmetic rule. */
    .srd-header-wrap .srd-html-slot-wrap.srd-html-slot-wrap--desktop {
        display: none;
    }

    /* The drawer copy — inside the open drawer, under the menu or the CTA
       (header_slot_drawer_position decides which by DOM order). */
    .srd-header-wrap .srd-html-slot-wrap.srd-html-slot-wrap--drawer {
        margin-top: 24px;
    }

    /* Stuck to the bottom — the drawer content is a full-height flex column,
       so an auto top margin takes all the free space above the slot. When
       the CTA is itself pushed down (cta-bottom) it already has an auto
       margin, and two auto margins would split the space and leave the CTA
       floating halfway; the CTA's margin does the pushing and the slot keeps
       its ordinary gap below it. Specificity, not source order, settles both
       against the 24px rule above: (0,4,0) and (0,5,0) against (0,3,0). */
    .srd-header-wrap .srd-drawer-content .srd-html-slot-wrap.srd-html-slot-wrap--drawer-bottom {
        margin-top: auto;
    }

    /* ...and pinned there while the drawer scrolls. The drawer is the scroll
       container (overflow-y: auto), so bottom: 0 holds the slot at its foot;
       the drawer's own background goes behind it so the menu scrolls under
       rather than through it.

       Sticky cannot travel outside its containing block, which is the drawer
       content box — and a design sizes that box flex: 1 with min-height: 0,
       which shrinks it to the drawer's height and lets a long menu overflow
       it. The slot would then pin to the bottom of a box that scrolls away.
       --slot-bottom (printed only with this position) makes the box grow to
       its content instead, so it spans the whole scroll. (0,3,0) beats the
       design's (0,2,0) whichever loads last. */
    /* CTA Position "Above the menu" (cta_position = top). The CTA is printed
       after the nav because the same container is the inline nav row on
       desktop, where the CTA belongs on the right — so the drawer's order is
       moved with flex order, below the breakpoint only, and the DOM is left
       alone. A Drawer Slot placed beside the CTA (before_cta or after_cta)
       comes up with it, directly under the buttons and above the menu; the
       stuck-to-the-bottom slot is left at the bottom. (0,3,0) and (0,5,0),
       ahead of the 24px slot gap above. */
    .srd-header-wrap .srd-drawer-content--cta-top .srd-cta {
        order: -2;
        margin-bottom: 24px;
    }

    .srd-header-wrap .srd-drawer-content--cta-top .srd-html-slot-wrap.srd-html-slot-wrap--drawer:not(.srd-html-slot-wrap--drawer-bottom) {
        order: -1;
        margin-top: 0;
        margin-bottom: 24px;
    }

    .srd-header-wrap .srd-drawer-content.srd-drawer-content--slot-bottom {
        flex: 1 0 auto;
    }

    .srd-header-wrap .srd-drawer-content .srd-html-slot-wrap.srd-html-slot-wrap--drawer-bottom {
        position: sticky;
        bottom: 0;
        z-index: 1;
        padding-block: 16px;
        background: var(--srd-mobile-bg, #ffffff);
    }

    .srd-header-wrap .srd-drawer-content--cta-bottom .srd-cta + .srd-html-slot-wrap.srd-html-slot-wrap--drawer-bottom {
        margin-top: 24px;
    }

    /* Swapping only grid-column (not row) leaves the auto-placement cursor
       past column 1 once the (DOM-first) logo takes a later column — the
       side container would otherwise be pushed onto a new row instead of
       backfilling the earlier column. "dense" packing backfills it
       correctly for every reordered variant below. */
    .srd-header-wrap.srd-mb--logo-right,
    .srd-header-wrap.srd-mb--logo-center-left,
    .srd-header-wrap.srd-mb--logo-center-right {
        grid-auto-flow: dense;
    }

    .srd-header-wrap.srd-mb--logo-right .srd-logo-link   { grid-column: 2; justify-content: flex-end; }
    .srd-header-wrap.srd-mb--logo-right .srd-header-side { grid-column: 1; justify-content: flex-start; }

    /* Logo centered — a 3-col grid (spacer | logo | spacer) with the
       hamburger side taking whichever outer column is its edge; the other
       outer column stays empty, keeping the logo visually centered. */
    .srd-header-wrap.srd-mb--logo-center-left,
    .srd-header-wrap.srd-mb--logo-center-right {
        grid-template-columns: 1fr auto 1fr;
    }

    .srd-header-wrap.srd-mb--logo-center-left .srd-logo-link,
    .srd-header-wrap.srd-mb--logo-center-right .srd-logo-link {
        grid-column: 2;
        justify-content: center;
    }

    .srd-header-wrap.srd-mb--logo-center-left .srd-header-side {
        grid-column: 1;
        justify-content: flex-start;
    }

    .srd-header-wrap.srd-mb--logo-center-right .srd-header-side {
        grid-column: 3;
        justify-content: flex-end;
    }

    /* Raw CTA HTML above the preset buttons (CTA HTML Placement setting) —
       the drawer's CTA slot only becomes a flex column when reordering is
       actually needed (:has), leaving the default block flow untouched
       otherwise. Stretch keeps the drawer's full-width button styling. */
    .srd-header-wrap .srd-cta:has(> .srd-cta-raw--m-top) {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .srd-header-wrap .srd-cta-raw--m-top { order: -1; }
}

@media (min-width: 1081px) {
    /* The mobile bar's slot copy — see the note on its counterpart above. */
    .srd-header-wrap .srd-html-slot-wrap.srd-html-slot-wrap--mobile,
    .srd-header-wrap .srd-html-slot-wrap.srd-html-slot-wrap--drawer {
        display: none;
    }

    /* The nav side stretches to the header row's full height (the grid's
       align-items:center would otherwise shrink-wrap it to the nav text) so
       the top-level menu items can span the logo's height — hover covers the
       whole row and dropdowns (top:100% on the li) open flush with its
       bottom edge. The rest of the stretch chain (drawer → nav → menu) lives
       in each menu design's desktop block; the active dropdown design
       re-centers the link text inside the tall li. */
    .srd-header-wrap .srd-header-side {
        align-self: stretch;
        align-items: stretch;
    }

    /* inline-center / inline-right — same base 2-col grid; only the nav's
       internal alignment and the CTA's pin-to-the-right differ. */
    .srd-header-wrap.srd-hl--inline-center .srd-nav > .srd-menu { justify-content: center; }
    .srd-header-wrap.srd-hl--inline-right  .srd-nav > .srd-menu { justify-content: flex-end; }

    .srd-header-wrap.srd-hl--inline-center .srd-cta,
    .srd-header-wrap.srd-hl--inline-right  .srd-cta {
        margin-left: auto;
    }

    /* stacked-center / stacked-left — logo on its own row, nav row below. */
    .srd-header-wrap.srd-hl--stacked-center,
    .srd-header-wrap.srd-hl--stacked-left {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        row-gap: 14px;
    }

    .srd-header-wrap.srd-hl--stacked-center .srd-logo-link,
    .srd-header-wrap.srd-hl--stacked-left   .srd-logo-link {
        grid-column: 1;
        grid-row: 1;
        width: 100%;
    }

    .srd-header-wrap.srd-hl--stacked-center .srd-header-side,
    .srd-header-wrap.srd-hl--stacked-left   .srd-header-side {
        grid-column: 1;
        grid-row: 2;
    }

    .srd-header-wrap.srd-hl--stacked-center .srd-logo-link { justify-content: center; }
    .srd-header-wrap.srd-hl--stacked-left   .srd-logo-link { justify-content: flex-start; }

    /* stacked-center: nav + CTA center as ONE group — no far-right CTA pin. */
    .srd-header-wrap.srd-hl--stacked-center .srd-drawer,
    .srd-header-wrap.srd-hl--stacked-center .srd-drawer-content {
        justify-content: center;
    }

    .srd-header-wrap.srd-hl--stacked-center .srd-nav { flex: 0 0 auto; }
    .srd-header-wrap.srd-hl--stacked-center .srd-nav > .srd-menu { justify-content: center; }

    /* stacked-left: nav fills the row, left-aligned, CTA pinned right. */
    .srd-header-wrap.srd-hl--stacked-left .srd-nav > .srd-menu { justify-content: flex-start; }
    .srd-header-wrap.srd-hl--stacked-left .srd-cta { margin-left: auto; }

    /* split — two half-menus flank a centered logo; the drawer (mobile's
       full menu) and its inline CTA copy step aside entirely. Menu Widget
       gets its own column (4) between the split-right nav and the CTA
       copy, which shifts to column 5. */
    .srd-header-wrap.srd-hl--split {
        grid-template-columns: 1fr auto 1fr auto auto;
    }

    .srd-header-wrap.srd-hl--split .srd-logo-link   { grid-column: 2; justify-content: center; }
    .srd-header-wrap.srd-hl--split .srd-header-side { display: none; }

    /* The half-menus stretch like .srd-header-side above, so split-layout
       items also span the logo's height; the CTA copy stays centered. */
    .srd-header-wrap.srd-hl--split .srd-nav--split-left,
    .srd-header-wrap.srd-hl--split .srd-nav--split-right {
        display: flex;
        align-self: stretch;
        align-items: stretch;
    }

    .srd-header-wrap.srd-hl--split .srd-cta--split-desktop {
        display: flex;
        align-items: center;
    }

    /* The HTML Slot's own split-desktop copy — same treatment as the CTA
       copy above, one column earlier. */
    .srd-header-wrap.srd-hl--split .srd-html-slot-wrap--split-desktop {
        display: flex;
        align-items: center;
    }

    .srd-header-wrap.srd-hl--split .srd-nav--split-left       { grid-column: 1; }
    .srd-header-wrap.srd-hl--split .srd-nav--split-right      { grid-column: 3; }
    .srd-header-wrap.srd-hl--split .srd-html-slot-wrap--split-desktop { grid-column: 4; }
    .srd-header-wrap.srd-hl--split .srd-cta--split-desktop    { grid-column: 5; }

    /* Both halves crowd toward the centered logo. */
    .srd-header-wrap.srd-hl--split .srd-nav--split-left > .srd-menu  { justify-content: flex-end; }
    .srd-header-wrap.srd-hl--split .srd-nav--split-right > .srd-menu { justify-content: flex-start; }

    /* Raw CTA Buttons HTML wrapper — its own flex row with the CTA slot's
       gap, so the hand-written HTML lays out exactly as it did as direct
       children. The --d-before modifier (CTA HTML Placement setting) orders
       it ahead of the preset buttons; DOM order (after) is the default. */
    .srd-header-wrap .srd-cta-raw {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .srd-header-wrap .srd-cta-raw--d-before { order: -1; }
}
