/* Only explicitly marked page cards participate. Collections, popup cards and
   canvas/workspace layouts keep their own sizing and scrolling. */
html:has([data-page-card-active]) {
    height: 100%;
    scrollbar-gutter: auto;
}

body:has([data-page-card-active]) {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

html body > main:has([data-page-card-active]),
html:root body > .container[data-page-card-host]:has(> [data-page-card-active]) {
    --page-card-bottom-gap: 1rem;
    box-sizing: border-box;
    height: calc(100vh - var(--tnx-guest-banner-height, 0px));
    height: calc(100dvh - var(--tnx-guest-banner-height, 0px));
    min-height: 0;
    width: 100%;
    margin: 0 auto;
    padding: 1rem 1rem var(--page-card-bottom-gap);
    overflow: hidden;
    flex: none;
}

/* A shop host can contain a form without itself becoming a second form card. */
html:root body > .container[data-page-card-host]:has(> [data-page-card-active]) {
    max-width: none;
    background: transparent;
    box-shadow: none;
}

html body > main > [data-page-card-host]:has(> [data-page-card-active]) {
    height: 100%;
    min-height: 0;
    width: 100%;
}

html body.shop-page > #overlay:has(> [data-page-card-host] > [data-page-card-active]) {
    padding: 1rem;
}

/* Specificity also covers the form-card rule and the optional design schemes. The card ends close
   below its last row (actions, circles or a table footer); its page gap below closes the window. */
html:root body [data-page-card][data-page-card-active]:is(.container, .big-card) {
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    padding-bottom: .5rem;
    margin-block: 0 !important;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

html:root body [data-page-card][data-page-card-active][data-page-card-scroll] {
    overflow: hidden;
    scrollbar-gutter: auto;
}

/* Full-width editors already use the page viewport. Keep the shared content
   scrolling and actions, without another padded card around them. */
html body > main:has(> [data-page-card="full"][data-page-card-active]) {
    max-width: none;
}
html:root body [data-page-card="full"][data-page-card-active]:is(.container, .big-card) {
    width: 100%;
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0 !important;
    background: transparent;
    box-shadow: none;
}

/* The second scrollbar spans the available window, including the card's exterior gaps and fixed
   toolbars. A guest banner retains its space above it. Popups and menus stay above the track. */
.page-card-scrollbar {
    position: fixed;
    top: var(--tnx-guest-banner-height, 0px);
    bottom: 0;
    z-index: 1;
    width: 12px;
    direction: ltr;
    overflow-x: hidden;
    overflow-y: scroll;
    overscroll-behavior: contain;
    scroll-behavior: auto;
}

/* The global inset styling suits rounded cards, but this track must reach both window edges. */
@supports selector(::-webkit-scrollbar) {
    /* Chromium gives the standard properties priority over the track and button rules below. */
    .page-card-scrollbar { scrollbar-width: auto; scrollbar-color: auto; }
}
.page-card-scrollbar::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.page-card-scrollbar::-webkit-scrollbar-track,
.page-card-scrollbar::-webkit-scrollbar-track-piece:vertical { margin: 0; border-radius: 0; }
.page-card-scrollbar::-webkit-scrollbar-thumb { border-block-width: 0; }

.page-card-scrollbar > div {
    width: 1px;
}

@media (max-width: 719px), print {
    .page-card-scrollbar {
        display: none;
    }
}

/* Shop detail columns share one viewport, just like entry.php. The contact
   footer is placed inside this viewport by PageCard.js so it remains reachable. */
html body.shop-page [data-page-card-active] .entry-layout > :is(.left-section, .right-section) {
    max-height: none;
    overflow: visible;
}

html body.shop-page [data-page-card-active] > .big-card-header {
    position: sticky;
    top: -10px;
    z-index: 2;
    background: var(--border-color);
}

@media (max-width: 719px) {
    html body.shop-page > #overlay:has(> [data-page-card-host] > [data-page-card-active]) {
        padding: 1rem 0.5rem 0;
    }
    html body > main:has([data-page-card-active]),
    html:root body > .container[data-page-card-host]:has(> [data-page-card-active]) {
        --page-card-bottom-gap: 0px;
        width: 100% !important;
        padding-inline: 0.5rem;
    }

    html:root body [data-page-card][data-page-card-active]:is(.container, .big-card) {
        width: 100% !important;
        max-width: none !important;
        padding: 0;
        border: 0;
        /* Optional design schemes must not reintroduce the mobile card frame. */
        border-radius: 0 !important;
        background: transparent;
        box-shadow: none;
        scrollbar-gutter: auto;
    }

    html body.shop-page [data-page-card-active] > .big-card-header {
        top: 0;
        background: var(--bg-color);
    }
}
