/* ========================================================
   应用程序布局CSS
   ======================================================== */

/* S0 - 整体容器 */
#S0 {}

/* 折叠屏适配 */
@media (min-width:768px) and (max-width:992px) {
    #S0 {
        display: flex;
    }
}

/* ========================================================
   S1 - 应用导航（侧边栏）
   ======================================================== */
#S1 {
    min-width: 4.6875rem;
    max-width: 4.6875rem;
    height: 100vh;
    min-height: 570px;
    background-color: var(--bs-sidebar-bg);
    display: flex;
    z-index: 9;
    box-shadow: 0 2px 4px rgba(15, 34, 58, 0.12);
}

@media (max-width: 991.98px) {
    #S1 {
        position: fixed;
        bottom: 0;
        height: 3.75rem;
        min-width: 100%;
        min-height: auto;
        display: block;
        border-top: 1px solid var(--bs-border-color);
    }
}

#S1 .navbar-brand-box {
    text-align: center;
}

@media (max-width: 991.98px) {
    #S1 .navbar-brand-box {
        display: none;
    }
}

#S1 .navbar-brand-box .logo {
    line-height: 4.375rem;
    padding: 0 !important;
    margin: 0 !important;
}

#S1 .side-menu-nav {
    --menu-link-highlight-bg: var(--bs-primary-bg-subtle);
    --menu-link-hover-color: var(--bs-primary);
    gap: 0.4rem;
}

#S1 .side-menu-nav .nav-item .nav-link {
    text-align: center;
    font-size: 1rem;
    color: var(--bs-sidebar-menu-item-color);
    width: 3.5rem;
    height: 3.5rem;
    margin: 0px auto;
    border-radius: 8px;
    padding: 0;
}

#S1 .side-menu-nav .nav-item .btn {
    display: flex;
    margin: auto;
    width: 3.5rem;
    height: 3.5rem;
}

@media (max-width: 991.98px) {
    #S1 .side-menu-nav .nav-item .nav-link {
        font-size: 20px;
        width: 3rem;
        height: 3rem;
        line-height: 3rem;
    }

    #S1 .side-menu-nav .nav-item .btn {
        width: 3rem;
        height: 3rem;
    }
}

#S1 .side-menu-nav .nav-item .nav-link.active {
    background-color: var(--bs-sidebar-menu-item-active-bg);
    color: var(--bs-primary);
}

#S1 .side-menu-nav .nav-item.show>.nav-link {
    background-color: var(--bs-sidebar-menu-item-active-bg);
    color: var(--bs-primary);
}

#S1 .side-menu-nav .profile-user {
    height: 36px;
    width: 36px;
    background-color: var(--bs-border-color);
    padding: 3px;
}

@media (max-width: 991.98px) {
    #S1 .side-menu-nav .nav-item {
        flex-basis: 0;
        flex-grow: 1;
        margin: 5px 0;
    }
}

/* 折叠屏适配 - S1 */
@media (min-width: 768px) and (max-width: 992px) {
    #S1 {
        margin-left: 0 !important;
        margin-right: .25rem !important;
        flex-direction: column !important;
        height: 100vh;
        display: flex;
        max-width: 4rem;
        min-width: 4rem;
        position: relative;
    }
}

/* ========================================================
   S2 - 左侧面板
   ======================================================== */
#S2-Wrapper {
    height: 100vh;
}

@media (min-width: 992px) {
    #S2-Wrapper {
        min-width: 23.75rem;
        max-width: 23.75rem;
    }
}

#S2-Wrapper.s2-full-width {
    width: 100%;
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
}

@media (min-width: 1200px) {
    #S2-Wrapper.s2-full-width {
        max-width: 1140px
    }
}

@media (min-width: 1400px) {
    #S2-Wrapper.s2-full-width {
        max-width: 1320px
    }
}

#S2-Wrapper.s2-full-width~#S3-Wrapper {
    display: none
}

#S2-Wrapper,
#S2 {
    height: 100vh;
}

#S2 {
    overflow-x: hidden;
    overflow-y: auto;
}

#S2-Body {
    padding-top: 0;
    padding-bottom: 4em;
}

/* 折叠屏适配 - S2 */
@media (min-width: 768px) and (max-width: 992px) {
    #S2-Wrapper {
        min-width: calc(50vw - 4rem);
        max-width: calc(50vw - 4rem);
    }
}

/* ========================================================
   S3 - 主内容区域
   ======================================================== */
#S3 {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#S3-Wrapper {
    background-color: var(--bs-body-bg);
    box-shadow: 0 2px 4px rgba(15, 34, 58, 0.12);
    transition: all 0.4s;
    flex-grow: 1;
    /* 这是关键，确保S3可以扩展填充剩余空间 */
}

#S3-Header {
    position: absolute;
    top: env(safe-area-inset-top, 0px);  /* 改这里 */
    left: 0;
    right: 0;
    z-index: 5;
}

#S3-Body {
    overflow-x: hidden;
    overflow-y: auto;
    margin-top: 0;
    padding: 5em 1em;
    height: 100vh;
    flex: 1 0 auto;
}

@media (max-width: 576px) {
    #S3-Body {
        padding: 5em 0;
    }
}

#S3-Footer {
    position: sticky;
    bottom: 0;
    transition: all .3s ease;
    max-height: calc(4.5rem * 3);
    background-color: var(--bs-body-bg);
}

#S3-Footer:empty {
    display: none;
}

#S3-Footer.compact {
    height: 4.5rem;
}

#S3-Footer textarea {
    min-height: 3em;
    max-height: 9em;
}

#S3-Footer a.btn .badge {
    height: fit-content;
}

@media (max-width: 991.98px) {
    #S3-Wrapper {
        position: fixed;
        right: 0;
        top: 0;
        width: 100%;
        height: 100%;
        visibility: hidden;
        transform: translateX(100%);
        z-index: 99;
    }

    #S3-Wrapper.user-chat-show {
        visibility: visible;
        transform: translateX(0);
    }
}

/* 折叠屏适配 - S3 */
@media (min-width: 768px) and (max-width: 992px) {
    #S3-Wrapper {
        position: relative;
        transform: translateY(0);
        visibility: visible;
    }
}

/* ========================================================
   S4 - 右侧辅助面板
   ======================================================== */

/* 第一条：设置基础样式，包括display: none */
#S4 {
    height: 100vh;
    width: 0;
    background-color: var(--bs-theme-component-bg, var(--bs-white));
    display: block;
    min-width: unset;
    max-width: 23.75rem;
    overflow: hidden;
    transition: all .3s ease;
}

/* 媒体查询 - 桌面端边框 */
@media (min-width: 992px) {
    #S4 {
        border-right: 4px solid var(--bs-border-color);
    }
}

/* 媒体查询 - 平板和移动端定位 */
@media (max-width: 1199.98px) {
    #S4 {
        position: fixed;
        right: 0;
        top: env(safe-area-inset-top, 0px);  /* 改这里 */
        z-index: 99;
    }
}

/* 媒体查询 - 小屏幕手机宽度 */
@media (max-width: 575.98px) {
    #S4.show {
        max-width: 100%;
    }
}



/* 显示状态 */
#S4.show {
    width: 100%;
}

/* S4内部元素宽度 */
#S4-Header,
#S4-Body {
    min-width: 23.75rem;
    max-width: 23.75rem;
    width: 100%;
}

/* 媒体查询 - 小屏幕最大宽度限制 */
@media (max-width: 575px) {

    #S4-Header,
    #S4-Body {
        min-width: 20rem;
        max-width: 100vw;
        max-width: 100dvw;
    }
}

/* S4内容区域 */
#S4-Body {
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
}

/* 有头部时的内容区域高度 */
#S4-Header+#S4-Body {
    height: calc(100vh - 60px);
}

/* 折叠屏适配 */
@media (min-width: 768px) and (max-width: 992px) {
    #S4 {
        max-width: 50vw;
    }

    #S4-Header,
    #S4-Body {
        min-width: 50vw;
        max-width: 50vw;
    }
}

/* ========================================================
   S5 - 模态框容器
   ======================================================== */
#S5_post_reply_modal {
    --bs-offcanvas-height: max-content;
    max-height: 75vh;
    background-color: var(--bs-theme-component-bg, var(--bs-white));
    position: sticky;
}

#S5_post_reply_modal.maximize {
    --bs-offcanvas-height: calc(100vh - 4.5rem);
    max-height: calc(100vh - 4.5rem);
}

#S5_post_reply_modal.maximize textarea {
    height: calc(100vh - 4.5rem - 9.5rem);
    resize: none;
}

#S5_post_reply_modal.show .offcanvas-manual-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

/* ========================================================
   S6 - 全屏容器
   ======================================================== */
#S6 {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1098;
    background: var(--bs-body-bg, white);
    display: none;
}

#S6.show {
    display: block;
}

#S6-Body {
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}
