/* ========================================
   App Shell 布局：左侧竖栏导航 + 右侧内容
   在所有样式表之后加载，负责整体版式
   ======================================== */

:root {
    /* 外壳主色 = 全站唯一主色（蓝）。青绿不再作为全局主色，只保留在 logo 上。 */
    --shell-accent: #1576e8;
    --shell-accent-strong: #0b5fd0;
    --shell-accent-soft: #eaf2fd;
    --shell-panel: #ffffff;
    --shell-line: #e8eaee;
    --shell-sidebar-width: 220px;
    --shell-radius: 8px;
    --shell-bg: #f5f6f8;
}

/* ---------- 页面骨架 ---------- */

.container {
    max-width: 1720px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--shell-sidebar-width) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.content {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

body {
    /* 中性灰底，无渐变：分区靠 1px 线，不靠底纹。 */
    background: var(--shell-bg);
    background-attachment: fixed;
}

/* ---------- 侧边栏 ---------- */

.sidebar {
    position: sticky;
    top: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 14px 14px;
    background: var(--shell-panel);
    border: 1px solid var(--shell-line);
    border-radius: var(--shell-radius);
    box-shadow: none;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 8px 14px;
    border-bottom: 1px solid var(--border-light);
    flex: 0 0 auto;
}

.logo-icon {
    width: 38px;
    height: 38px;
    font-size: 19px;
    border-radius: 8px;
    background: var(--shell-accent);
    box-shadow: none;
    flex: 0 0 auto;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-brand h1 {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    line-height: 1.25;
}

.sidebar-brand-sub {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.18em;
    color: var(--text-tertiary);
}

/* ---------- 竖版导航 ---------- */

.nav {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0;
    background: none;
    flex: 1 1 auto;
}

.nav-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 0;
    border: none;
}

.nav-group-label {
    width: 100%;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--text-tertiary);
    padding: 0 10px 6px;
    user-select: none;
}

.nav-btn {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    padding: 9px 12px 9px 18px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.4;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast, 150ms) ease, color var(--transition-fast, 150ms) ease;
}

.nav-btn::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 56%;
    border-radius: 999px;
    background: var(--shell-accent);
    transition: transform var(--transition-fast, 150ms) ease;
}

.nav-btn:hover {
    background: #f2f4f7;
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--shell-accent-soft);
    color: var(--shell-accent);
    font-weight: 600;
}

.nav-btn.active::before {
    transform: translateY(-50%) scaleY(1);
}

/* ---------- 侧边栏底部 ---------- */

.sidebar-footer {
    flex: 0 0 auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-tertiary, #f1f5f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition-fast, 150ms) ease, color var(--transition-fast, 150ms) ease;
}

.theme-toggle:hover {
    background: var(--shell-accent-soft);
    color: var(--shell-accent);
    transform: none;
}

.theme-toggle-label {
    letter-spacing: 0.04em;
}

/* ---------- 内容主面板 ---------- */

.main {
    padding: 26px 28px;
    border-radius: var(--shell-radius);
    background: var(--shell-panel);
    /* 注意：backdrop-filter 会创建新的包含块，realtime-message-workspace.js 的
       lightbox 依赖这个事实（它把浮层挂到 body 上）。保留这行，不要删。 */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--shell-line);
    box-shadow: none;
    min-height: calc(100vh - 48px);
}

.research-workbench {
    border-radius: var(--shell-radius);
}

body.market-page-active .main {
    border-radius: var(--shell-radius);
}

/* ---------- 暗色模式 ---------- */

[data-theme="dark"] body {
    background: #0b1220;
    background-attachment: fixed;
}

[data-theme="dark"] .sidebar,
[data-theme="dark"] .main {
    background: rgba(15, 23, 42, 0.88);
    border-color: rgba(51, 65, 85, 0.9);
    box-shadow: none;
}

[data-theme="dark"] .sidebar-brand,
[data-theme="dark"] .sidebar-footer {
    border-color: var(--border-color);
}

[data-theme="dark"] .sidebar-brand-sub,
[data-theme="dark"] .nav-group-label {
    color: var(--text-tertiary);
}

[data-theme="dark"] .nav-btn {
    color: var(--text-secondary);
}

[data-theme="dark"] .nav-btn:hover {
    background: rgba(148, 163, 184, 0.10);
    color: var(--text-primary);
}

[data-theme="dark"] .nav-btn.active {
    background: rgba(21, 118, 232, 0.18);
    color: #6cb2f7;
}

[data-theme="dark"] .nav-btn.active::before {
    background: #6cb2f7;
}

[data-theme="dark"] .theme-toggle {
    background: rgba(51, 65, 85, 0.55);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

[data-theme="dark"] .theme-toggle:hover {
    background: rgba(21, 118, 232, 0.18);
    color: #6cb2f7;
    transform: none;
}

/* ---------- 响应式：窄屏回落为顶部横栏 ---------- */

@media (max-width: 1080px) {
    .container {
        display: block;
        padding: 16px;
    }

    .sidebar {
        position: static;
        max-height: none;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 16px;
        margin-bottom: 16px;
        overflow: visible;
    }

    .sidebar-brand {
        padding: 0;
        border-bottom: none;
        margin-right: 4px;
    }

    .sidebar-brand-sub {
        display: none;
    }

    .nav {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 6px;
        order: 3;
        width: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav-group {
        flex-direction: row;
        align-items: center;
        gap: 2px;
        padding-right: 8px;
        border-right: 1px solid var(--border-color, #e2e8f0);
        flex: 0 0 auto;
    }

    .nav-group:last-child {
        padding-right: 0;
        border-right: none;
    }

    .nav-group-label {
        display: none;
    }

    .nav-btn {
        width: auto;
        padding: 8px 12px;
        font-size: 13px;
        border-radius: 8px;
    }

    .nav-btn::before {
        display: none;
    }

    .nav-btn.active {
        box-shadow: inset 0 -2px 0 var(--shell-accent);
    }

    [data-theme="dark"] .nav-btn.active {
        box-shadow: inset 0 -2px 0 #6cb2f7;
    }

    .sidebar-footer {
        margin-left: auto;
        padding-top: 0;
        border-top: none;
    }

    .theme-toggle {
        width: auto;
    }

    .theme-toggle-label {
        display: none;
    }

    .main {
        padding: 20px;
        min-height: calc(100vh - 100px);
    }
}

@media (max-width: 640px) {
    .container {
        padding: 10px;
    }

    .sidebar {
        padding: 10px 12px;
        gap: 8px;
    }

    .sidebar-brand h1 {
        font-size: 17px;
    }

    .main {
        padding: 14px;
    }
}

/* ========================================
   P4 暗色模式补充（2026-10-12）
   仅补侧边栏外壳令牌，backdrop-filter 依赖保持不变。
   ======================================== */

[data-theme="dark"] {
    --shell-panel: rgba(15, 23, 42, 0.88);
    --shell-line: rgba(51, 65, 85, 0.9);
    --shell-bg: #0b1220;
}