/* Block layout that must respond to the phone frame a block sits in, not the browser window:
   the designer canvas is a phone inside a desktop window, so viewport breakpoints disagree with it. */

/* The page's column, and the widest a sheet goes (Material's bottom-sheet maximum). On a screen wider than the column
   the platform's fixed parts keep to it: a bar or a pinned Action Sheet block spans it (.bm-page-column-bar), a
   floating button stands --bm-page-gutter in from the screen's edge. A sheet that opens over the page is centred the
   same way, capped at its own width. The gutter's 100% is left unresolved here, so it measures the containing block of
   whatever uses it: the window on a scan, the device's screen in the designer. Never a size container on the page to
   place them: see .hero-section. */
:root {
    --bm-page-column: 500px;
    --bm-page-gutter: calc((100% - min(100%, var(--bm-page-column))) / 2);
    --bm-sheet-max-width: 640px;
    /* A block's wide form: a form or card goes no wider than a sheet, and text keeps a readable line, about 75
       characters of the theme's font at body size (Hero's subtitle reads it too). In rem, not em, so held text of
       every size shares one left edge; smaller text runs a longer line. */
    --bm-card-max-width: var(--bm-sheet-max-width);
    --bm-text-max-width: 34rem;
    /* The screen a picture keeps to three quarters of. The designer's device frame names its own (PhoneFrame). */
    --bm-screen-height: 100svh;
    /* A Bottom Menu's height (Material's navigation bar). The menu takes it as its own, and whatever must stay clear of
       a pinned menu reads it here. */
    --bm-bottom-menu-height: 80px;
    /* How far the floating utility dock stands off the screen's foot, which whatever must stay clear of its FABs reads. */
    --bm-utility-dock-bottom: 24px;
}

/* A wide page fills the screen up to 1200px. On :root, because the utility dock and the chat sheet sit outside the
   page's container, and so that the gutter, declared beside the column, is worked out from this one. The designer
   marks its canvas the same way while it shows a wide page. */
:root:has(.mobile-experience-container--wide),
:root:has(.preview-canvas--wide) {
    --bm-page-column: 1200px;
}

/* A bar pinned to the foot of a published page: the bottom menu, and an Action Sheet block. The designer's canvas
   places them itself. */
.bm-page-column-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin-inline: auto;
    max-width: var(--bm-page-column);
}

/* A Bottom Menu is one row with a line per label, so it is exactly --bm-bottom-menu-height tall, however long a label
   or large an icon. */
.bottommenu-component {
    box-sizing: border-box;
    width: 100%;
    height: var(--bm-bottom-menu-height);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--mud-palette-lines-default);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.bottommenu-item {
    flex: 1;
    min-width: 0;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.bottommenu-icon {
    display: flex;
}

.bottommenu-label {
    max-width: 100%;
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The content inset both surfaces apply (padding: 8px): a full-bleed section cancels it. */
.mobile-experience-container,
.preview-canvas {
    --bm-page-inset: 8px;
}

/* The utility dock's column, which a published action sheet keeps clear because the dock floats over its bottom-right
   corner: the floating dock's right offset, the chat FAB (MudFab Large), a gap. The dock is a direct child of the
   consumer shell's content column and of the preview's container, and renders nothing when it has no FAB to show. */
:has(> .tag-experience-utility-dock) .actionsheet-component {
    --bm-utility-dock-reserve: calc(16px + 56px + 8px);
}

/* The floating dock stands above a pinned Bottom Menu rather than over its rightmost item, so the menu's items keep their
   even spacing. */
:root:has(.bottommenu-component.bm-page-column-bar) {
    --bm-utility-dock-bottom: calc(var(--bm-bottom-menu-height) + 16px);
}

.columnlayout-component {
    container-type: inline-size;
}

/* The display title's `cqw` measures the hero, because the older spec made a size container the containing block for
   its fixed descendants: on the page container, a browser that still does that would pin a BottomMenu or an action
   sheet to the bottom of a long page rather than the screen. */
.hero-section {
    container-type: inline-size;
    width: 100%;
}

.bm-columns {
    display: grid;
    grid-template-columns: var(--bm-columns-template, minmax(0, 1fr));
    gap: var(--bm-spacing-sm);
}

/* Columns stay side by side on a phone, on purpose: a saved 50/50 is two columns there too, as the canvas shows it.
   They stack only once a column would drop below roughly 100px. */
@container (max-width: 219px) { .bm-columns--2 { grid-template-columns: minmax(0, 1fr); } }
@container (max-width: 299px) { .bm-columns--3 { grid-template-columns: minmax(0, 1fr); } }
@container (max-width: 379px) { .bm-columns--4 { grid-template-columns: minmax(0, 1fr); } }

/* A block measures the box it is laid out in, never the window, so the canvas and a published page agree: a top-level
   block its own wrapper, a block in a column that column, and a block in a Detail the Detail. The code that draws a
   page's top-level blocks marks their wrappers bm-block-root (ExperienceRenderingEngine.MeasuredBlockClass), and only
   those: a size container stops its child's margins collapsing through it, which moved a phone page's nested blocks; a
   Bottom Menu's and an Action Sheet's blocks are position: fixed (see .hero-section); and a sheet's blocks are always
   drawn as on a phone though a sheet is 640px wide. Named, so a block that is a container itself (Hero, Column Layout)
   takes its wide form from the whole block. */
.bm-block-root,
.bm-column {
    container: bm-block / inline-size;
}

/* The canvas lays each block out in a flex row (DropItemHost), where a block that doesn't ask for the column's width
   shrinks to its content, while a scan stacks blocks; so a block whose width is not its content's asks for it. */
.carousel-gallery,
.in-store-availability,
.image-block-wrapper,
.image-block-frame,
.image-block-link {
    width: 100%;
}

.bm-picture {
    width: 100%;
    height: auto;
}

.hero-picture {
    display: block;
    border-radius: var(--bm-radius-lg);
}

/* Full bleed (FullBleed.cs): a block meant to fill the page runs past the inset to the page's edges, the 1200px page's
   on a wide one. It follows the width rules above, which it overrides. The first block on a page touches its top too;
   on the canvas a block sits one div deeper (DropItemHost). */
.bm-bleed {
    box-sizing: border-box;
    width: calc(100% + 2 * var(--bm-page-inset, 8px));
    max-width: none;
    margin-inline: calc(-1 * var(--bm-page-inset, 8px));
}

/* Inside a column, a Detail, an Action Sheet or a page opened as a sheet there is no page inset to cancel: a block fills
   its box. */
.bm-column,
.detail-component,
.actionsheet-component,
.actionsheet-modal-content {
    --bm-page-inset: 0px;
}

.bm-block-root:first-child > .bm-bleed,
.bm-block-root:first-child > div > .bm-bleed {
    margin-top: calc(-1 * var(--bm-page-inset, 8px));
}

/* A full-width picture fills the width, whatever its own size, on a phone and on a wide page alike. Only an Image block's
   own: a Hero or a banded Column Layout bleeds too, and the pictures inside those keep their wide form. */
.image-block-wrapper.bm-bleed .image-block-frame,
.image-block-wrapper.bm-bleed .image-block-link,
.image-block-wrapper.bm-bleed .bm-picture {
    width: 100%;
    max-width: none;
    max-height: none;
}

/* A form or card keeps a form's width; narrower than that it fills its box, so it needs no breakpoint. */
.bm-form-block,
.bm-yi-card,
.spec-table-component,
.button-block .mud-width-full,
.button-block .button-block__anchor--full {
    width: 100%;
    max-width: var(--bm-card-max-width);
    margin-inline: auto;
}

.button-block .mud-width-full {
    display: flex;
}

/* A block's wide form (BRA-1115): only where it differs from the phone's. A block not named here fills the column. */
@container bm-block (width > 600px) {
    /* Text keeps a readable line. */
    .paragraph-readonly,
    .paragraph-editable,
    .feature-highlight,
    .list-component,
    .html-block-wrapper {
        width: 100%;
        max-width: var(--bm-text-max-width);
        margin-inline: auto;
    }

    /* A form's own text keeps a readable line too. A caption is a span, which a max-width leaves alone. */
    .bm-form-block :is(p, .mud-typography) {
        max-width: var(--bm-text-max-width);
    }

    .bm-form-block span.mud-typography {
        display: inline-block;
    }

    .bm-form-block .mud-typography-align-center {
        margin-inline: auto;
    }

    /* A picture is no wider than its own pixels, nor taller than three quarters of the screen. */
    .bm-picture {
        width: auto;
        max-width: 100%;
        max-height: calc(var(--bm-screen-height) * 0.75);
    }

    .image-block-frame {
        width: fit-content;
        max-width: 100%;
    }

    .image-block-link {
        width: auto;
        max-width: 100%;
    }

    .hero-picture {
        margin-inline: auto;
    }

    .hero-section--left .hero-picture {
        margin-inline-start: 0;
    }

    /* A list of cards shows more per row. A card's own bottom margin spaces the rows. */
    .review-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        column-gap: var(--bm-spacing-md);
    }
}
