/* ============================================================
   SiteHeader 统一头部组件（方向 B：无侧栏，顶部导航 + 二级下拉）
   P0（2026-09-25）：视觉基准 home-purple-v2.html
   - 依赖：tokens.css、remixicon.css；账户区复用 components/topbar.css
   - 账户区嵌入 #shAccountMount（TenantTopbar render({hideBrand:true})）
   - <1024px：品牌 + 汉堡，导航与账户区收入右侧抽屉（二级手风琴）
   ============================================================ */

/* ===== 头部壳 ===== */
.sh-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    height: var(--sh-header-h);
    background: var(--sh-header-bg);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-bottom: 1px solid var(--sh-line);
    box-shadow: 0 8px 30px rgba(0, 0, 0, .28);
    font-family: var(--sh-font);
    color: var(--sh-text);
}
.sh-header__inner {
    height: 100%;
    /* R96：顶栏宽度改为随视口自适应（满宽 + 流式内边距），不再钉死 1920px。
       原来只有首页自己覆盖成这套值（第五十五轮），其余 50 个页面仍按 1920px 封顶，
       超宽屏上导航被挤在中间、右侧一大片空。现在把这套值提为组件默认，页面仍可用
       --sh-inner-max / --sh-inner-pad-x 覆盖（例如需要和某个窄正文严格对齐时）。 */
    max-width: var(--sh-inner-max, none);
    margin: 0 auto;
    padding: 0 var(--sh-inner-pad-x, clamp(18px, 3.2vw, 56px));
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 20px;
}

/* ===== 品牌区 ===== */
.sh-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0;
}
.sh-brand-logo {
    width: 38px; height: 38px;
    flex: 0 0 38px;
    border-radius: var(--sh-r-md);
    background: var(--sh-brand-grad);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800; color: #fff;
    box-shadow: 0 0 24px rgba(168, 85, 247, .4);
    overflow: hidden;
}
.sh-brand-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sh-brand-text {
    font-size: 18px; font-weight: 700; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: linear-gradient(135deg, #fff 0%, var(--sh-brand-2) 100%);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
}

/* ===== 桌面主导航 ===== */
.sh-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    /* 不能用 overflow:auto：一轴非 visible 时另一轴会被计算成 auto，下拉面板会被裁剪 */
    overflow: visible;
}

.sh-nav-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border-radius: var(--sh-r-pill);
    font-size: 14px; font-weight: 500;
    color: var(--sh-text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: color .2s ease, background .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.sh-nav-item:hover {
    color: #fff;
    background: rgba(168, 85, 247, .12);
    border-color: rgba(168, 85, 247, .25);
    box-shadow: 0 0 20px rgba(168, 85, 247, .16);
}
.sh-nav-item.active {
    color: #fff;
    background: rgba(168, 85, 247, .2);
    border-color: rgba(168, 85, 247, .35);
    box-shadow: var(--sh-shadow-glow);
}
.sh-nav-item i { font-size: 16px; line-height: 1; }

/* 分组触发器 + 下拉 */
.sh-dropdown { position: relative; }
.sh-dropdown__trigger {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 16px;
    border-radius: var(--sh-r-pill);
    font-size: 14px; font-weight: 500;
    color: var(--sh-text-muted);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: color .2s ease, background .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.sh-dropdown__trigger i.caret { font-size: 14px; transition: transform .2s ease; }
.sh-dropdown__trigger:hover,
.sh-dropdown.open .sh-dropdown__trigger,
.sh-dropdown__trigger[aria-expanded="true"] {
    color: #fff;
    background: rgba(168, 85, 247, .12);
    border-color: rgba(168, 85, 247, .25);
    box-shadow: 0 0 20px rgba(168, 85, 247, .16);
}
.sh-dropdown.has-active .sh-dropdown__trigger {
    color: #fff;
    border-color: rgba(168, 85, 247, .3);
}
.sh-dropdown.open .caret { transform: rotate(180deg); }

.sh-dropdown__panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    min-width: 176px;
    max-width: 260px;
    padding: 8px;
    background: rgba(18, 12, 37, .96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--sh-line-soft);
    border-radius: var(--sh-r-md);
    box-shadow: var(--sh-shadow-card);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 1001;
}
/* 悬停热区，避免鼠标移向面板时间隙关闭 */
.sh-dropdown__panel::before {
    content: '';
    position: absolute;
    top: -10px; left: 0; right: 0;
    height: 10px;
}
.sh-dropdown.open .sh-dropdown__panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.sh-dropdown__link {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    border-radius: var(--sh-r-sm);
    font-size: 14px;
    color: var(--sh-text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
    transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.sh-dropdown__link i { font-size: 16px; }
.sh-dropdown__link:hover,
.sh-dropdown__link:focus-visible {
    color: #fff;
    background: rgba(168, 85, 247, .15);
    border-color: rgba(168, 85, 247, .25);
    outline: none;
}
.sh-dropdown__link.active {
    color: #fff;
    background: rgba(168, 85, 247, .22);
    border-color: rgba(168, 85, 247, .35);
}
/* 最右侧分组的面板右对齐，避免溢出视口 */
.sh-dropdown[data-group="tools"] .sh-dropdown__panel {
    left: auto;
    right: 0;
    transform: translateY(6px);
}
.sh-dropdown[data-group="tools"].open .sh-dropdown__panel {
    transform: translateY(0);
}

/* ===== 右侧账户区（嵌入 TenantTopbar，去除其独立顶栏外壳） ===== */
.sh-header__account { display: flex; align-items: center; justify-content: flex-end; }
.sh-account .global-topbar {
    position: static;
    height: auto !important;
    flex: none !important;
    display: block !important;
    align-items: initial !important;
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
}
.sh-account .global-topbar::before { display: none; }
.sh-account .global-topbar-right {
    flex: none;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}
.sh-account .global-topbar-divider { display: none; }

/* ===== 汉堡按钮（<1024px 显示） ===== */
.sh-burger {
    display: none;
    width: 40px; height: 40px;
    align-items: center; justify-content: center;
    border-radius: var(--sh-r-md);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--sh-line);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
}
.sh-burger:hover { background: rgba(168, 85, 247, .15); }

/* ===== 移动抽屉 ===== */
.sh-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1090;
    background: rgba(3, 1, 8, .55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
}
.sh-drawer {
    position: fixed;
    top: var(--sh-header-h);
    right: 0; bottom: 0;
    z-index: 1100;
    width: min(340px, 88vw);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, rgba(18, 12, 37, .98) 0%, rgba(11, 7, 22, .98) 100%);
    border-left: 1px solid var(--sh-line);
    box-shadow: -20px 0 60px rgba(0, 0, 0, .5);
    transform: translateX(105%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}
body.sh-drawer-open .sh-drawer { transform: translateX(0); }
body.sh-drawer-open .sh-backdrop { opacity: 1; pointer-events: auto; }

.sh-drawer__nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sh-mobile-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--sh-r-md);
    font-size: 15px;
    color: var(--sh-text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
}
.sh-mobile-item i { font-size: 18px; width: 20px; text-align: center; }
.sh-mobile-item:hover {
    color: #fff;
    background: rgba(168, 85, 247, .12);
    border-color: rgba(168, 85, 247, .25);
}
.sh-mobile-item.active {
    color: #fff;
    background: rgba(168, 85, 247, .2);
    border-color: rgba(168, 85, 247, .35);
}
.sh-mobile-group { display: flex; flex-direction: column; }
.sh-mobile-group__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 16px;
    border-radius: var(--sh-r-md);
    font-size: 15px;
    color: var(--sh-text-muted);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
}
.sh-mobile-group__toggle:hover,
.sh-mobile-group.open .sh-mobile-group__toggle,
.sh-mobile-group.has-active .sh-mobile-group__toggle {
    color: #fff;
    background: rgba(168, 85, 247, .12);
    border-color: rgba(168, 85, 247, .25);
}
.sh-mobile-group__toggle i.caret { transition: transform .25s ease; }
.sh-mobile-group.open .caret { transform: rotate(180deg); }
.sh-mobile-group__list {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 4px 0 4px 14px;
}
.sh-mobile-group.open .sh-mobile-group__list { display: flex; }
.sh-mobile-group__list .sh-mobile-item { padding: 10px 14px; font-size: 14px; }

.sh-drawer__account {
    flex: 0 0 auto;
    border-top: 1px solid var(--sh-line);
    padding: 14px;
    position: relative;
}
/* 抽屉内账户区纵向铺开 */
.sh-drawer__account .sh-account { width: 100%; }
.sh-drawer__account .global-topbar { width: 100%; }
.sh-drawer__account .global-topbar-right {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}
.sh-drawer__account .global-topbar-item {
    width: 100%;
    height: 42px;
    justify-content: flex-start;
    padding: 0 14px;
}
.sh-drawer__account .global-topbar-text { display: inline !important; }
.sh-drawer__account .global-topbar-user-menu {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: 70vh;
    overflow-y: auto;
}
.sh-drawer__account .global-topbar-mobile-panel {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: 70vh;
    overflow-y: auto;
}

/* ===== 页面布局适配（试点页使用） ===== */
/* G1：原 TenantShell 全屏页：内容主区固定在头部之下 */
.sh-page-shell {
    position: fixed;
    top: var(--sh-header-h);
    left: 0; right: 0; bottom: 0;
    overflow: hidden;
}
.sh-page-shell > .page-body {
    position: absolute;
    inset: 0;
    overflow: hidden;
}
/* G2：原 layout.js 页：common.css 的 .main 侧栏/头部占位清零（.main-container 为 ai_drama 等个别页变体） */
body.sh-pilot .main,
body.sh-pilot .main-container {
    margin-left: 0 !important;
    margin-top: var(--sh-header-h) !important;
    height: calc(100vh - var(--sh-header-h)) !important;
    width: 100%;
}

/* ===== 响应式：P0 试点实测 6 个分组导航在 <1180px 放不下，抽屉断点取 1180 ===== */
/* 中宽桌面（1180~1280）：收紧胶囊，配合 purple 主题在 ≤1200 隐藏账户文字，保持一行不溢出 */
@media (max-width: 1280px) {
    .sh-header__inner { gap: 12px; padding: 0 18px; }
    .sh-nav { gap: 2px; }
    .sh-nav-item { padding: 8px 12px; font-size: 13px; }
    .sh-dropdown__trigger { padding: 8px 12px; font-size: 13px; }
}
@media (max-width: 1179.98px) {
    .sh-header__inner { grid-template-columns: auto 1fr auto; gap: 12px; padding: 0 16px; }
    .sh-nav { display: none; }
    .sh-header__account { display: none; }
    /* DOM 中汉堡在第 4 位，nav/account 隐藏后需显式放到第 3 列贴右，避免落到中间列 */
    .sh-burger { display: inline-flex; grid-column: 3; justify-self: end; }
    .sh-brand-text { font-size: 16px; }
}
@media (min-width: 1180px) {
    .sh-backdrop { display: none !important; }
    /* 桌面态下抽屉即使残留 open 类也不可见 */
    .sh-drawer { display: none; }
}
/* 抽屉打开时隐藏页面级 AI 悬浮球（其 z-index 极高，会压住抽屉） */
body.sh-drawer-open #aiFab,
body.sh-drawer-open #aiFabPanel { display: none !important; }
