/* 统一顶栏 / 中台壳导航样式(单一来源):layout 现代页 + layui 老页共用。
   token 权威源：/assets/tokens.css（须在本文件前引入）。
   只放导航/壳通用样式，避免覆盖 video-ui.css 管理的卡片等业务样式。
   中台视觉基线（#278）：清晰顶栏、浅色侧栏、统一一档密度、焦点/遮罩/阴影。 */

/* 全站 focus-visible（键盘可达控件；鼠标点击不残留 outline） */
:where(
    a,
    button,
    input:not([class^="el-"]):not([class*=" el-"]),
    select:not([class^="el-"]):not([class*=" el-"]),
    textarea:not([class^="el-"]):not([class*=" el-"]),
    summary,
    [tabindex]:not([tabindex="-1"])
):focus-visible {
    outline: var(--console-focus-outline);
    outline-offset: 2px;
}

:where(
    input:not([class^="el-"]):not([class*=" el-"]),
    select:not([class^="el-"]):not([class*=" el-"]),
    textarea:not([class^="el-"]):not([class*=" el-"])
):focus-visible {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px var(--console-focus-ring);
}

/* ---------- 顶栏（56px，清晰层级） ---------- */
.topbar {
    box-sizing: border-box;
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: var(--console-topbar-h);
    padding: 0 16px;
    border-bottom: 1px solid var(--console-topbar-border);
    background: var(--console-topbar-bg);
    backdrop-filter: blur(14px);
    box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
}

.top-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1 1 auto;
}

.console-brand {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    color: var(--vui-text);
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.console-brand:hover {
    color: var(--vui-primary-active);
}

/* 星形标记在 40 的画布里只占 27，容器要比原来的实心方块大一圈才等重。 */
.console-brand-mark {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: -2px;
}

.console-brand-mark svg {
    display: block;
    width: 100%;
    height: 100%;
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}

.console-brand:hover .console-brand-mark svg {
    transform: rotate(8deg) scale(1.06);
}

.console-sidenav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--vui-border);
    border-radius: var(--vui-radius-sm);
    background: var(--vui-surface);
    color: var(--vui-text-2);
    cursor: pointer;
    flex: 0 0 auto;
}

.console-sidenav-toggle:hover {
    border-color: #93c5fd;
    color: var(--vui-primary-active);
    background: var(--vui-primary-softer);
}

.console-sidenav-toggle-bars,
.console-sidenav-toggle-bars::before,
.console-sidenav-toggle-bars::after {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
    content: "";
}

.console-sidenav-toggle-bars {
    position: relative;
}

.console-sidenav-toggle-bars::before {
    position: absolute;
    top: -5px;
    left: 0;
}

.console-sidenav-toggle-bars::after {
    position: absolute;
    top: 5px;
    left: 0;
}

/* 全局模块导航（顶栏） */
.global-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    overflow-x: auto;
}

/* 顶栏图标渲染 15px：24 画布 × 1.7 描边 ≈ 1.06 视觉粗细，比侧栏的 16px 略细一档，
   和 13px 的模块名配重刚好。 */
.global-nav-icon {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .66;
}

.global-nav a:hover .global-nav-icon,
.global-nav a.active .global-nav-icon {
    opacity: 1;
}

.global-nav a {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 11px;
    border-radius: var(--vui-radius-sm);
    color: var(--vui-text-2);
    font-size: var(--vui-font-sm, 13px);
    font-weight: 700;
    white-space: nowrap;
    text-decoration: none;
    transition: background .12s ease, color .12s ease;
}

.global-nav a:hover {
    background: var(--vui-surface-muted);
    color: var(--vui-primary-active);
}

.global-nav a.active {
    background: var(--vui-primary-soft);
    color: var(--vui-primary-active);
}

.global-nav-new-window {
    display: inline-flex;
    margin-left: 3px;
    font-size: 10px;
    line-height: 1;
    opacity: .68;
    transform: translateY(-1px);
    transition: opacity .12s ease;
}

.global-nav a:hover .global-nav-new-window,
.global-nav a:focus-visible .global-nav-new-window {
    opacity: 1;
}

/* 兼容旧 top-nav（layui header / 页面可选覆写） */
.topbar h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 750;
    white-space: nowrap;
    color: var(--vui-text);
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    overflow-x: auto;
}

.top-nav:empty {
    display: none;
}

.top-nav a {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--vui-radius-sm);
    color: var(--vui-text-2);
    font-size: var(--vui-font-sm, 13px);
    font-weight: 700;
    white-space: nowrap;
    text-decoration: none;
}

.top-nav a:hover,
.top-nav a.active {
    background: var(--vui-primary-soft);
    color: var(--vui-primary-active);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    color: var(--vui-text-3);
    font-size: 12px;
    flex: 0 0 auto;
}

.top-actions:empty {
    display: none;
}

.top-actions > a {
    text-decoration: none;
    color: var(--vui-text-3);
    font-weight: 600;
}

.top-actions > a.console-context-action {
    display: inline-flex;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--vui-primary);
    border-radius: 10px;
    background: var(--vui-primary);
    color: var(--vui-surface);
    box-shadow: 0 5px 14px rgba(37, 99, 235, .2);
    font-size: 13px;
    font-weight: 750;
    line-height: 1;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.top-actions > a.console-context-action:hover {
    background: var(--vui-primary-hover);
    color: var(--vui-surface);
    box-shadow: 0 8px 20px rgba(37, 99, 235, .27);
    transform: translateY(-1px);
}

.console-context-action > svg {
    display: block;
    width: 13px;
    height: 13px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s ease;
}

.console-context-action:hover > svg:last-child {
    transform: translateX(2px);
}

.top-actions .logout-link {
    display: inline-flex;
    align-items: center;
    height: var(--vui-ctrl-h-sm, 28px);
    padding: 0 12px;
    border: 1px solid var(--vui-border);
    border-radius: var(--vui-radius-sm);
    color: var(--vui-text-2);
    font-weight: 700;
}

.top-actions .logout-link:hover {
    border-color: var(--vui-primary-active);
    color: var(--vui-primary-active);
}

/* ---------- App shell：顶栏下 侧栏 + 主工作区 ---------- */
.app-shell {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - var(--console-topbar-h));
    min-width: 0;
    background: var(--console-canvas);
}

.app-sidenav {
    flex: 0 0 var(--console-sidenav-w);
    width: var(--console-sidenav-w);
    position: sticky;
    top: var(--console-topbar-h);
    align-self: flex-start;
    height: calc(100vh - var(--console-topbar-h));
    overflow: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--console-sidenav-border);
    background: var(--console-sidenav-bg);
    color: var(--console-sidenav-text);
    z-index: 30;
}

.app-sidenav-inner {
    padding: 14px 10px 24px;
}

.sidenav-group + .sidenav-group {
    margin-top: 14px;
}

/* 分组弱化 */
.sidenav-group-label {
    padding: 4px 12px 6px;
    color: var(--console-sidenav-text-3);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.sidenav-links {
    display: grid;
    gap: 2px;
}

.sidenav-icon {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .62;
}

.sidenav-links a:hover .sidenav-icon,
.sidenav-links a.active .sidenav-icon {
    opacity: 1;
}

.sidenav-links a {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 36px;
    padding: 0 12px;
    border-radius: var(--vui-radius-sm);
    color: var(--console-sidenav-text);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.sidenav-links a > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidenav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 18px;
    height: 18px;
    margin-left: auto;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--vui-danger);
    color: var(--vui-surface);
    font-size: 10px;
    font-style: normal;
    font-weight: 800;
    line-height: 1;
}

.sidenav-badge[hidden] {
    display: none;
}

.sidenav-links a:hover {
    background: var(--console-sidenav-hover);
    color: var(--vui-text);
}

/* 当前项：浅蓝底 / 蓝色文字 / 清晰指示 */
.sidenav-links a.active {
    background: var(--console-sidenav-active-bg);
    color: var(--console-sidenav-active-text);
    font-weight: 800;
    border-left-color: var(--vui-primary);
}

.app-sidenav-mask {
    display: none;
}

.app-content {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    background: var(--console-canvas);
}

/* 无侧栏：Hub / 钱包 / 操作日志 / 未知路径 */
body.no-sidenav .console-sidenav-toggle,
body.no-sidenav .app-sidenav,
body.no-sidenav .app-sidenav-mask {
    display: none !important;
}

body.no-sidenav .app-shell {
    display: block;
}

/* 全站业务模块共享一档密度；禁止 body.module-* 再造控件高度/字号/圆角差异 */

/* 次级水平导航（个别页仍可用） */




/* 通用头像(ui_avatar):有图显图,无图首字母彩圆 */
.ui-avatar {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    color: var(--vui-surface);
    font-size: 12px;
    font-weight: 800;
}

.ui-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 用户菜单(头像+名字+悬停/焦点下拉) */
.usermenu {
    position: relative;
}

.um-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 8px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    color: var(--vui-text-2);
    font-size: var(--vui-font-sm, 13px);
    font-weight: 700;
}

.um-trigger:hover {
    background: var(--vui-surface-muted);
}

.um-avatar {
    width: 26px;
    height: 26px;
    flex: 0 0 auto;
    border-radius: 999px;
    object-fit: cover;
    background: var(--vui-border-muted);
}

.um-avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--vui-text-3);
    font-weight: 800;
    font-size: 12px;
}

.um-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.um-caret {
    font-size: 10px;
    color: var(--vui-text-3);
}

.um-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 156px;
    margin-top: 4px;
    padding: 4px;
    border: 1px solid var(--vui-border);
    border-radius: var(--vui-radius-md);
    background: var(--vui-surface);
    box-shadow: var(--vui-shadow-md);
    display: none;
    z-index: 100;
}

/* hover + 键盘 focus-within 均可打开 */
.usermenu:hover .um-dropdown,
.usermenu:focus-within .um-dropdown {
    display: block;
}

.um-dropdown a {
    display: block;
    padding: 7px 10px;
    border-radius: var(--vui-radius-sm);
    color: var(--vui-text-2);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.um-dropdown a:hover {
    background: var(--vui-primary-soft);
    color: var(--vui-primary-active);
}

.um-dropdown .um-admin-entry {
    margin-top: 4px;
    border-top: 1px solid var(--vui-border-muted);
}

.um-dropdown .um-logout {
    margin-top: 4px;
    border-top: 1px solid var(--vui-border-muted);
    color: var(--vui-danger);
}

/* 抽屉打开：锁住背景页滚动（JS 开关 body.sidenav-open；关抽屉 / 回宽屏会清类） */
body.sidenav-open {
    overflow: hidden;
}

/* 窄屏：侧栏变抽屉（与 console-shell.js 1100 断点契约一致） */
@media (max-width: 1100px) {
    body.has-sidenav .console-sidenav-toggle {
        display: inline-flex;
    }

    body.has-sidenav .app-sidenav {
        position: fixed;
        top: var(--console-topbar-h);
        left: 0;
        bottom: 0;
        height: auto;
        transform: translateX(-105%);
        /* 关闭态不可聚焦/点击屏外链；visibility 延后到 transform 结束再 hidden */
        visibility: hidden;
        pointer-events: none;
        transition: transform .2s ease, visibility 0s linear .2s;
        box-shadow: none;
        /* 抽屉态仍用深色中性底，宽度保持 token */
        width: min(var(--console-sidenav-w), 86vw);
        max-width: 86vw;
    }

    body.has-sidenav.sidenav-open .app-sidenav {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
        /* 打开态立刻可见可点，不延迟 visibility */
        transition: transform .2s ease, visibility 0s linear 0s;
        box-shadow: 8px 0 28px rgba(15, 23, 42, .12);
    }

    body.has-sidenav .app-sidenav-mask {
        display: block;
        position: fixed;
        inset: var(--console-topbar-h) 0 0 0;
        z-index: 25;
        background: var(--console-mask);
    }

    body.has-sidenav .app-sidenav-mask[hidden] {
        display: none !important;
    }

    body.has-sidenav .app-shell {
        display: block;
    }
}

@media (max-width: 720px) {
    .console-brand-label {
        display: none;
    }

    .global-nav a {
        padding-inline: 8px;
        font-size: 12px;
    }

    .topbar {
        padding-inline: 8px;
        gap: 8px;
    }
}

/* 窄屏 ≤640：公共顶栏单源布局（base.css 已不再强制 topbar 竖排）
   目标两层：行1 [toggle+brand] …… [usermenu]；行2 global-nav 横向滚动
   高度：padding-top6 + row1 34 + row-gap6 + row2 34 + padding-bottom6 + border-bottom1 = 87
   （横滚可滚但隐藏原生滚动条，避免条高 ~15px 撑破 topbar）
   不改 >640 行为，不隐藏全局模块导航，不碰 JS/DOM */
@media (max-width: 640px) {
    body.has-sidenav {
        --console-topbar-h: 87px;
    }

    .topbar {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        justify-content: space-between;
        gap: 8px;
        padding: 6px 8px;
        min-height: var(--console-topbar-h);
        min-width: 0;
        max-width: 100%;
        overflow-x: clip;
    }

    .top-left {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        width: auto;
        min-width: 0;
        max-width: 100%;
        flex: 1 1 auto;
        /* row-gap 6 = 两行间距；column-gap 8 */
        gap: 6px 8px;
    }

    /* 强制成为 top-left 第二行；自身 overflow-x 横滚，不撑 document；隐藏滚动条 */
    .global-nav {
        flex: 1 0 100%;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .global-nav::-webkit-scrollbar {
        height: 0;
        width: 0;
        display: none;
    }

    .global-nav a {
        height: 34px;
        padding-inline: 8px;
        font-size: 12px;
    }

    /* top-nav 非空时同样落到下一行并自滚动，避免撑破；隐藏滚动条 */
    .top-nav {
        flex: 1 0 100%;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .top-nav::-webkit-scrollbar {
        height: 0;
        width: 0;
        display: none;
    }

    .top-actions {
        width: auto;
        flex: 0 0 auto;
        flex-wrap: nowrap;
        justify-content: flex-end;
        align-items: center;
        align-self: flex-start;
        min-height: 34px;
        white-space: nowrap;
    }

    /* 小屏藏名字，保留头像/入口，给全局导航更多宽度 */
    .um-name {
        display: none;
    }

    body.module-monitor .top-actions .app-feed-switcher > span {
        display: none;
    }

    body.module-monitor .top-actions .app-feed-switcher select {
        max-width: 118px;
    }
}

/* 中台壳画布：layout 页统一背景（不改 body 全局字体，避免碰 Element Plus/Layui） */
body.console-shell {
    margin: 0;
    min-height: 100vh;
    background: var(--console-canvas);
    color: var(--vui-text);
}

/* 防止壳层横向溢出 */
body.console-shell,
body.console-shell .app-shell,
body.console-shell .app-content {
    max-width: 100%;
}
