/* =========================================================================
   公共移动端顶部栏 + 导航抽屉（工具 / 案例 / 创作 等底部导航页共用）
   仅移动端（≤991.98px）显示；PC 端完全隐藏，不影响桌面排版。
   ========================================================================= */
:root {
    /* 移动端顶部栏高度（较旧版略减，LOGO 同步缩小） */
    --mobile-topbar-h: 48px;
    --mobile-topbar-bg: #ffffff;
    --mobile-topbar-fg: #1f2937;
    --mobile-topbar-border: #eef1f5;
    --mobile-topbar-accent: #2563eb;
}

/* 默认隐藏（含抽屉），仅移动端且页面带 mobile-topbar-page 时展示 */
.mobile-topbar,
.mobile-drawer,
.mobile-drawer-scrim {
    display: none;
}

@media (max-width: 991.98px) {
    /* 使用公共顶部栏的页面，隐藏 PC 端顶部主导航（避免双头并列） */
    body.mobile-topbar-page .app-header {
        display: none !important;
    }

    /* 首页同时有 app-home-page（body padding-top 56px 为 PC 固定头部预留）
       和 mobile-topbar-page，两者叠加会导致间距过大。
       公共移动端顶部栏已固定定位，container padding-top 已足够偏移，
       因此取消 body 上的额外 padding。 */
    body.mobile-topbar-page.app-home-page {
        padding-top: 0 !important;
    }

    /* 内容容器顶部留白 = 顶部栏高度，避免被固定栏遮挡 */
    body.mobile-topbar-page .container.py-4 {
        padding-top: calc(var(--mobile-topbar-h) + env(safe-area-inset-top, 0px) + 0.35rem) !important;
    }

    /* ---------- 顶部栏 ---------- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-topbar-h) + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 0.5rem 0;
        box-sizing: border-box;
        /* 贴顶：无圆角、无阴影、无边框框 */
        background: var(--mobile-topbar-bg);
        border: 0;
        border-radius: 0;
        box-shadow: none;
        z-index: 1090;
    }

    .mobile-topbar-btn {
        flex: 0 0 auto;
        width: 38px;
        height: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: #475569;
        cursor: pointer;
    }

    .mobile-topbar-btn svg {
        width: 24px;
        height: 24px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .mobile-topbar-logo {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        margin-left: 0.5rem;
        min-width: 0;
    }

    .mobile-topbar-logo img {
        /* 在不改变顶部栏高度的前提下尽量放大 LOGO（栏高 48px，留出上下安全间距） */
        height: 32px;
        width: auto;
        max-width: 46vw;
        object-fit: contain;
    }

    /* 右侧余额区靠右显示：自动外边距把积分/悟空币推到最右侧 */
    .mobile-topbar-actions {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 0.4rem;
        margin-left: auto;
    }

    /* 积分 + 悟空币 迷你条（未登录时由 data-auth-user 控制隐藏） */
    .mobile-balance-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.45rem;
        height: 30px;
        padding: 0 0.6rem;
        background: #f1f5f9;
        border-radius: 999px;
        text-decoration: none;
        color: #334155;
        font-size: 13px;
        white-space: nowrap;
    }

    .mobile-balance-item {
        display: inline-flex;
        align-items: center;
        gap: 0.2rem;
    }

    .mobile-balance-icon {
        width: 15px;
        height: 15px;
    }

    .mobile-balance-item strong {
        font-size: 13px;
        font-weight: 700;
        color: #1f2937;
    }

    .mobile-balance-sep {
        width: 1px;
        height: 14px;
        background: #cbd5e1;
    }

    /* ---------- 导航抽屉 ---------- */
    .mobile-drawer-scrim {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 1095;
        background: rgba(15, 23, 42, 0.35);
    }

    body.mobile-drawer-open .mobile-drawer-scrim {
        display: block;
    }

    .mobile-drawer {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 78%;
        max-width: 320px;
        z-index: 1100;
        background: #fff;
        transform: translateX(-100%);
        transition: transform 0.26s ease;
        display: flex;
        flex-direction: column;
        padding-top: env(safe-area-inset-top, 0px);
        box-shadow: 2px 0 24px rgba(15, 23, 42, 0.12);
    }

    body.mobile-drawer-open .mobile-drawer {
        transform: translateX(0);
    }

    .mobile-drawer-nav {
        display: flex;
        flex-direction: column;
        padding: 14px 12px 16px;
        overflow-y: auto;
        flex: 1 1 auto;
    }

    .mobile-drawer-group {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .mobile-drawer-group + .mobile-drawer-group {
        margin-top: 14px;
        padding-top: 12px;
        border-top: 1px solid #f0f2f5;
    }

    .mobile-drawer-link {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        text-align: left;
        border: 0;
        background: transparent;
        border-radius: 10px;
        padding: 11px 12px;
        font-size: 15px;
        color: #3d4652;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-drawer-link svg {
        width: 19px;
        height: 19px;
        flex: 0 0 19px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .mobile-drawer-link:hover {
        background: #f4f6f9;
    }

    .mobile-drawer-link.is-active {
        background: #e8f1ff;
        color: var(--mobile-topbar-accent);
        font-weight: 600;
    }

    /* ---------- 案例库：类目筛选单行横向滑动（全部按钮常驻左侧） ---------- */
    .case-library-filters {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        padding: 2px 0 6px;
        scrollbar-width: none;
    }

    .case-library-filters::-webkit-scrollbar {
        display: none;
    }

    .case-filter-chip {
        flex: 0 0 auto;
        white-space: nowrap;
        border: 1px solid #e2e8f0;
        background: #fff;
        color: #475569;
        border-radius: 999px;
        padding: 6px 14px;
        font-size: 13px;
        cursor: pointer;
    }

    .case-filter-chip.is-active {
        background: var(--mobile-topbar-accent);
        border-color: var(--mobile-topbar-accent);
        color: #fff;
        font-weight: 600;
    }

    .case-library-filters .case-filter-chip:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: #fff;
        box-shadow: 6px 0 8px -6px rgba(255, 255, 255, 0.95);
    }

    /* 选中态（含“全部”常驻项）保持蓝底白字，避免被上方 sticky 白底覆盖导致文字不可见 */
    .case-library-filters .case-filter-chip:first-child.is-active {
        background: var(--mobile-topbar-accent);
        border-color: var(--mobile-topbar-accent);
        color: #fff;
        box-shadow: 6px 0 8px -6px rgba(37, 99, 235, 0.4);
    }
}

/* 桌面端彻底隐藏公共移动端组件 */
@media (min-width: 992px) {
    .mobile-topbar,
    .mobile-drawer,
    .mobile-drawer-scrim {
        display: none !important;
    }
}
