/* ==============================================
   MAIN LAYOUT STRUCTURE
   ============================================== */

/* Base body handling for SPA mode */
body.spa-app {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

main.page-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    position: relative;
    overscroll-behavior: auto;
    overscroll-behavior-y: auto;
    padding: 0;
}

/* ==============================================
   STANDARD PAGE CONTAINERS
   ============================================== */

/* The main scrollable container for pages */
.page-container,
.shell-scroll,
.app-page {
    flex-grow: 1;
    width: 100%;
    background-color: var(--bg-primary);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    font-family: var(--font-primary);
    max-width: 100%;
    margin: 0 auto;
    padding:
        0 0 var(--page-container-bottom-desktop-current, var(--spa-shell-inset-bottom-desktop));
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) var(--bg-primary);
}

/* Inner content wrapper to constrain width on large screens */
.content-wrapper,
.shell-content,
.app-page__content {
    margin: var(--spa-shell-inset-top-desktop) auto 0;
    width: 100%;
    max-width: min(100%, var(--spa-shell-max-width));
    min-width: 0;
    box-sizing: border-box;
}

/* ==============================================
   CANONICAL APP PAGE CONTRACTS
   ============================================== */

.app-page__header {
    display: flex;
    flex-direction: column;
    gap: var(--page-header-gap);
    margin-bottom: var(--page-content-gap);
    min-width: 0;
}

.app-page__title {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--text-2xl);
    line-height: var(--line-height-tight);
    overflow-wrap: anywhere;
}

.app-page__subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: var(--text-base);
    line-height: var(--line-height-normal);
    overflow-wrap: anywhere;
}

.app-section {
    display: flex;
    flex-direction: column;
    gap: var(--section-gap);
    min-width: 0;
}

.app-section + .app-section {
    margin-top: var(--section-gap);
}

.app-section__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--touch-target-gap);
    min-width: 0;
}

.app-section__title {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--text-xl);
    font-weight: var(--font-weight-regular);
    line-height: var(--line-height-tight);
    overflow-wrap: anywhere;
}

.app-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--touch-target-gap);
    min-width: 0;
}

.page-container--footer-nav,
.shell-scroll--footer-nav,
.app-page--footer-nav {
    --page-container-bottom-desktop-current: var(--spa-shell-inset-bottom-footer-nav);
}

@media (max-width: 768px) {

    .page-container,
    .shell-scroll,
    .app-page {
        padding: 0 0 var(--page-container-bottom-mobile-current, var(--spa-shell-inset-bottom-mobile));
    }

    .content-wrapper,
    .shell-content,
    .app-page__content {
        padding:
            var(--content-wrapper-top-mobile-current, var(--spa-shell-inset-top-mobile)) var(--spa-shell-inset-inline-mobile);
        margin: 0 auto;
    }

    .page-container--footer-nav,
    .shell-scroll--footer-nav,
    .app-page--footer-nav {
        --page-container-bottom-mobile-current: var(--spa-shell-inset-bottom-footer-nav);
    }

    .page-container--back-button,
    .shell-scroll--back-button,
    .app-page--back-button {
        --content-wrapper-top-mobile-current: var(--spa-shell-inset-top-mobile-back-button);
    }

    .app-section__header,
    .app-actions {
        align-items: stretch;
    }
}

/* Section Headers */
.section-header,
.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.section-header h2,
.section-heading h2,
.section-heading__title {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-regular);
    color: var(--text-primary);
    margin: 0;
}
