/*
 * E-Com Uni layout integrity guard
 *
 * I keep client branding inside the supported product layout. This file is
 * intentionally loaded last: colours, fonts, sizes and approved alignment
 * choices remain dynamic, while structural regions stay bounded.
 */

html,
body {
    max-width: 100%;
    overflow-x: clip;
}

body.plant-body :is(img, svg, video, canvas) {
    max-width: 100%;
}

body.plant-body :is(
    .shop-section-heading,
    .shop-page-header,
    .admin-inline-page-heading,
    .online-sales-heading,
    .checkout-heading-row,
    .auth-heading-row
) {
    box-sizing: border-box;
    max-width: 100%;
    min-width: 0;
}

body.plant-body :is(
    .shop-section-heading,
    .shop-page-header,
    .admin-inline-page-heading,
    .online-sales-heading,
    .checkout-heading-row,
    .auth-heading-row
) > * {
    min-width: 0;
}

body.plant-body :is(
    .shop-section-heading,
    .shop-page-header,
    .admin-inline-page-heading,
    .online-sales-heading,
    .checkout-heading-row,
    .auth-heading-row
) :is(h1, h2, h3, p, small, span) {
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* The storefront always has two owned desktop regions:
   client identity on the left and application actions on the right. */
body.plant-body.route-shop.route-index #main-content .shop-storefront-heading {
    position: sticky !important;
    z-index: 1200 !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(17rem, 32rem) !important;
    grid-template-areas: "brand actions" !important;
    align-items: center !important;
    column-gap: clamp(1rem, 2.5vw, 3rem) !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    /* I keep the header open so menus may extend beyond its visual boundary.
       The client-controlled brand region below remains independently clipped. */
    overflow: visible !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-brand {
    grid-area: brand !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: min(100%, 58rem) !important;
    min-width: 0 !important;
    justify-self: start !important;
    overflow: hidden !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right {
    grid-area: actions !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 32rem !important;
    min-width: 0 !important;
    justify-self: end !important;
    overflow: visible !important;
}

/* Admin Tools belongs to the application action region. I keep every ancestor
   open and lift the expanded menu above the product toolbar and cards. */
body.plant-body.route-shop.route-index #main-content :is(
    .shop-storefront-right,
    .shop-heading-actions,
    .local-shop-nav,
    .shop-admin-tools-menu
) {
    overflow: visible !important;
}

body.plant-body.route-shop.route-index #main-content .shop-admin-tools-menu {
    position: relative !important;
    isolation: isolate;
    z-index: 1300 !important;
}

body.plant-body.route-shop.route-index #main-content .shop-admin-tools-menu.is-open {
    z-index: 1400 !important;
}

body.plant-body.route-shop.route-index #main-content .admin-tools-menu-panel {
    z-index: 1500 !important;
    max-height: min(34rem, calc(100vh - 7rem));
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
}

body.plant-body.route-shop.route-index #main-content .shop-stock-display {
    position: relative;
    z-index: 1 !important;
}

/* Right/under affects only the relationship inside the left brand unit. */
@media (min-width: 64.01rem) {
    body.plant-body.route-shop.route-index #main-content .shop-storefront-brand.shop-heading-right {
        display: grid !important;
        grid-template-columns:
            minmax(7rem, min(38%, var(--shop-logo-width-max, 15rem)))
            minmax(0, 1fr) !important;
        grid-template-areas: "logo title" !important;
        align-items: center !important;
        justify-items: start !important;
        gap: clamp(0.75rem, 1.8vw, 2rem) !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-brand.shop-heading-under {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas:
            "logo"
            "title" !important;
        align-content: center !important;
        justify-items: start !important;
        gap: 0.45rem !important;
    }
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-brand .shop-page-logo-link {
    grid-area: logo !important;
    box-sizing: border-box !important;
    width: min(100%, clamp(7rem, var(--shop-logo-width-vw, 18vw), var(--shop-logo-width-max, 15rem))) !important;
    max-width: 100% !important;
    min-width: 0 !important;
    justify-self: start !important;
    overflow: hidden !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-brand :is(
    .shop-page-logo,
    .shop-page-logo.logo-left,
    .shop-page-logo-placeholder
) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: clamp(4.5rem, 11vw, 10rem) !important;
    object-fit: contain !important;
    object-position: left center !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-title {
    grid-area: title !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    justify-self: start !important;
    overflow: hidden !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-title h2 {
    width: 100% !important;
    max-width: 100% !important;
    margin-inline: 0 !important;
    line-height: 1.02 !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
    color: var(--theme-safe-page-header-text, var(--shop-header-text, #ffffff)) !important;
    -webkit-text-fill-color: var(--theme-safe-page-header-text, var(--shop-header-text, #ffffff)) !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-title .shop-page-subtitle {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    color: var(--theme-safe-page-header-text, var(--shop-header-text, #ffffff)) !important;
    -webkit-text-fill-color: var(--theme-safe-page-header-text, var(--shop-header-text, #ffffff)) !important;
    opacity: 0.86 !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
    .shop-developer-credit,
    .shop-developer-credit-link,
    .shop-heading-actions,
    .local-shop-nav
) {
    max-width: 100% !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
    .shop-heading-actions,
    .local-shop-nav
) {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
    width: 100% !important;
    min-width: 0 !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
    .shop-heading-actions,
    .local-shop-nav
) > * {
    min-width: 0 !important;
    max-width: 100% !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
    .shop-user-developer-group,
    .shop-developer-credit,
    .shop-developer-credit-link
) {
    min-width: 0 !important;
    max-width: 100% !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right .shop-developer-credit-link {
    flex-wrap: wrap !important;
}

body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
    .shop-developer-credit-text,
    .shop-context-pill,
    .customer-context-pill
) {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
}

/* Move to the product's supported stacked header before either region can
   collide. This breakpoint is based on layout capacity, not device name. */
@media (max-width: 64rem) {
    body.plant-body.route-shop.route-index #main-content .shop-storefront-heading {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas:
            "brand"
            "actions" !important;
        row-gap: 1rem !important;
        overflow: visible !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-brand:is(
        .shop-heading-right,
        .shop-heading-under
    ) {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas:
            "logo"
            "title" !important;
        justify-items: center !important;
        text-align: center !important;
        gap: 0.5rem !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-brand .shop-page-logo-link {
        justify-self: center !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-brand :is(
        .shop-page-logo,
        .shop-page-logo.logo-left,
        .shop-page-logo-placeholder
    ) {
        object-position: center !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-title {
        justify-self: center !important;
        text-align: center !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-right {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        justify-self: stretch !important;
        align-items: center !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
        .shop-heading-actions,
        .local-shop-nav
    ) {
        justify-content: center !important;
    }
}

@media (max-width: 36rem) {
    body.plant-body.route-shop.route-index #main-content .shop-storefront-heading {
        padding-inline: clamp(0.65rem, 3vw, 1rem) !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
        .shop-heading-actions,
        .local-shop-nav
    ) {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        width: 100% !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
        .shop-heading-actions,
        .local-shop-nav
    ) > * {
        box-sizing: border-box !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    body.plant-body.route-shop.route-index #main-content .shop-storefront-right :is(
        .shop-user-developer-group,
        .shop-context-pill,
        .shop-mode-switch,
        .shop-admin-tools-menu
    ) {
        grid-column: 1 / -1 !important;
    }
}

/* The live preview follows the same ownership rules as the real shop. */
body.plant-body.route-branding #main-content .live-preview-shop-header {
    grid-template-columns: minmax(0, 1fr) minmax(9.5rem, max-content) !important;
    grid-template-areas: "preview-brand preview-actions" !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
}

body.plant-body.route-branding #main-content .live-preview-brand {
    grid-area: preview-brand !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
}

body.plant-body.route-branding #main-content .live-preview-brand:not(.header-text-under) {
    grid-template-columns:
        minmax(6rem, min(38%, var(--live-logo-width, 240px)))
        minmax(0, 1fr) !important;
}

body.plant-body.route-branding #main-content .live-preview-title-wrap {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
}

body.plant-body.route-branding #main-content .live-preview-title-wrap :is(h3, small) {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
}

body.plant-body.route-branding #main-content .live-preview-header-right {
    grid-area: preview-actions !important;
    width: max-content !important;
    max-width: 100% !important;
    min-width: 0 !important;
    justify-self: end !important;
}

@media (max-width: 48rem) {
    body.plant-body.route-branding #main-content .live-preview-shop-header {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas:
            "preview-brand"
            "preview-actions" !important;
        overflow: visible !important;
    }

    body.plant-body.route-branding #main-content .live-preview-header-right {
        width: 100% !important;
        justify-self: stretch !important;
        align-items: center !important;
    }
}

/* Data-heavy pages remain usable at every supported width. */
body.plant-body :is(.table-responsive, .responsive-table-shell, .admin-table-shell) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

body.plant-body :is(input, select, textarea, button, .btn) {
    box-sizing: border-box;
    max-width: 100%;
}

body.plant-body :is(.branding-grid, .branding-form-grid, .settings-grid, .form-grid) > * {
    min-width: 0;
}

/* I keep the shared admin header stacked after all theme and legacy styles.
   I match the original ID-scoped component selector so a late two-column rule
   cannot squeeze the title when the category menu grows. */
body.plant-body.admin-workspace #main-content > :is(section.shop-section, section.shop-page, .shop-section, .shop-page)
    > :is(.shop-section-heading, .branding-header):not(.shop-storefront-heading):first-child {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: none !important;
    align-items: start !important;
    min-height: 0 !important;
    height: auto !important;
}
body.plant-body.admin-workspace #main-content > :is(section.shop-section, section.shop-page, .shop-section, .shop-page)
    > :is(.shop-section-heading, .branding-header):not(.shop-storefront-heading):first-child > *,
body.plant-body.admin-workspace #main-content .admin-inline-page-heading > * {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    grid-column: 1 / -1 !important;
    grid-area: auto !important;
}
body.plant-body.admin-workspace #main-content .admin-inline-page-heading {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: start !important;
}
body.plant-body.admin-workspace #main-content :is(.admin-inline-heading-actions, .shop-heading-actions, .branding-header-actions, .online-sales-header-actions) {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
}
body.plant-body.admin-workspace #main-content .admin-command-header-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    align-items: center !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    gap: .55rem !important;
}
body.plant-body.admin-workspace #main-content .admin-command-header-actions > .admin-category-bar {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    grid-column: 1 / -1 !important;
}
body.plant-body.admin-workspace #main-content .admin-inline-page-heading :is(h1, h2, p, .shop-muted) {
    white-space: normal !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    max-width: 100% !important;
}
@media (max-width: 760px) {
    body.plant-body.admin-workspace #main-content .admin-command-header-actions > :is(.btn, form),
    body.plant-body.admin-workspace #main-content .admin-command-header-actions > form > button {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        white-space: normal !important;
    }
}
