/* ============================================
   顶部功能导航栏（一级菜单 + 两级下拉，大气风格）
   - 一级菜单：粗体大字、无标签
   - 二级下拉：多列并行、图标 + 文字 + 标签角标
   ============================================ */

/* ---------- 顶部 Logo（左侧） ---------- */
.top-logo {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: calc(var(--sidebar-width, 200px) - 8px);
    height: 68px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 24px;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 2;
}
.top-logo .top-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    height: 68px;
    max-width: 100%;
    overflow: hidden;
}
.top-logo .top-logo-img {
    height: 70px;
    width: auto;
    max-width: 280px;
    max-height: 288px;
    display: block;
    pointer-events: none;
    flex-shrink: 0;
}
.top-logo .top-logo-text {
    font-size: 20px;
    font-weight: 700;
    color: #e53935;
    letter-spacing: 1px;
    white-space: nowrap;
}

/* ============================================
   顶部 Logo 收藏提示（hover + 每日首次共用）
   ============================================ */
.top-logo {
    cursor: grab;
    user-select: none;
    -webkit-user-drag: element;
}
.top-logo:active {
    cursor: grabbing;
}
/* 浏览器拖拽时读取此文字作为书签名称 */
.top-logo .logo-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}
/* 收藏提示 — 浅蓝色矩形（相对 top-function-bar 定位，避开 .top-logo 的 overflow:hidden） */
.bookmark-tooltip {
    position: absolute;
    left: 24px;
    top: 68px;
    margin-top: 6px;
    transform: none;
    background: #e8f4ff;
    border: 1px solid #b3d9ff;
    border-radius: 8px;
    padding: 10px 16px;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 100, 200, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 10px;
}
.bookmark-tooltip.show {
    opacity: 1;
    pointer-events: auto;
}
.bookmark-tooltip .tt-icon {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}
.bookmark-tooltip .tt-text {
    font-size: 15px;
    font-weight: 600;
    color: #1a4d8f;
    line-height: 1.3;
}
.bookmark-tooltip .tt-text small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: #4a7ab5;
    margin-top: 2px;
}
/* 工具条里的红色拖拽按钮 */
.bookmark-tooltip .tt-drag-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 6px;
    background: linear-gradient(135deg, #f75444, #ff7875);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    transition: transform 0.15s;
    white-space: nowrap;
    line-height: 1.3;
}
.bookmark-tooltip .tt-drag-btn:active {
    cursor: grabbing;
    transform: scale(0.95);
}
.bookmark-tooltip .tt-close {
    width: 22px;
    height: 22px;
    border: none;
    background: rgba(0, 100, 200, 0.08);
    border-radius: 50%;
    color: #4a7ab5;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.2s;
}
.bookmark-tooltip .tt-close:hover {
    background: rgba(0, 100, 200, 0.18);
}

/* ============================================
   每日新功能提示（随机定位到顶部菜单项下方 + 每日一次）
   ============================================ */
.newfeat-tooltip {
    position: absolute;
    top: 68px;
    transform: translateX(-50%); /* JS 设置 left 为中心点，这里回移一半实现居中 */
    background: #fff7e8;
    border: 1px solid #ffd591;
    border-radius: 10px;
    padding: 10px 14px;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(230, 150, 30, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}
.newfeat-tooltip.show {
    opacity: 1;
    pointer-events: auto;
}
/* 顶部向上箭头 — 旋转小方块，描边与气泡边框衔接，直指目标导航项；
   水平微调由 JS 写入 --nf-arrow-x，视口钳制后仍对准栏目中心 */
.newfeat-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: calc(50% + var(--nf-arrow-x, 0px));
    width: 12px;
    height: 12px;
    background: #fff7e8;
    border-top: 1px solid #ffd591;
    border-left: 1px solid #ffd591;
    border-top-left-radius: 3px;
    transform: translateX(-50%) rotate(45deg);
}
.newfeat-tooltip .nf-icon {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}
.newfeat-tooltip .nf-text {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.newfeat-tooltip .nf-title {
    font-size: 12px;
    font-weight: 600;
    color: #b26a00;
    letter-spacing: 1px;
}
.newfeat-tooltip .nf-desc {
    font-size: 15px;
    font-weight: 700;
    color: #d4380d;
}
.newfeat-tooltip .nf-desc b {
    font-size: 16px;
    color: #d4380d;
    padding: 0 1px;
}
.newfeat-tooltip .nf-close {
    width: 22px;
    height: 22px;
    border: none;
    background: rgba(230, 150, 30, 0.12);
    border-radius: 50%;
    color: #b26a00;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.2s;
}
.newfeat-tooltip .nf-close:hover {
    background: rgba(230, 150, 30, 0.24);
}

/* 被「今日上新」气泡指向的导航大类：文字变红 + 底部指示条脉冲，与气泡呼应 */
.top-nav-item.newfeat-target > .top-nav-link {
    color: #e53935;
}
.top-nav-item.newfeat-target > .top-nav-link::after {
    content: '';
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: #e53935;
    animation: nfTargetPulse 0.9s ease-in-out infinite;
}
@keyframes nfTargetPulse {
    0%, 100% { opacity: 1; transform: scaleX(1); }
    50% { opacity: 0.3; transform: scaleX(0.55); }
}

/* ---------- 栏体基础 ---------- */
.top-function-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 68px;
    background: #ffffff;
    border-bottom: 1px solid #ececec;
    z-index: 1000;
    padding: 0 32px;
    box-sizing: border-box;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}
.top-function-bar.mega-open {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* ---------- 右上角账户入口 ---------- */
.top-account {
    display: none !important;
    position: absolute;
    top: 9px;
    right: 28px;
    height: 50px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 18px;
    border-left: 1px solid #eeeeee;
    z-index: 3;
}
.top-account-summary {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}
.top-account-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #f75444, #ff7875);
    border: 2px solid #ffffff;
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 1px 5px rgba(247, 84, 68, 0.25);
}
.top-account-avatar.guest {
    background: linear-gradient(135deg, #aeb4bd, #d6d9de);
}
.top-account-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    line-height: 1.25;
}
.top-account-name {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #252a31;
    font-size: 13px;
    font-weight: 600;
}
.top-account-status {
    margin-top: 2px;
    color: #6b7280;
    font-size: 11px;
    white-space: nowrap;
}
.top-account-login,
.top-account-logout {
    min-width: 76px;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all .2s ease;
}
.top-account-login {
    border: 1px solid #f75444;
    background: #f75444;
    color: #ffffff;
}
.top-account-login:hover {
    background: #e8473b;
    border-color: #e8473b;
}
.top-account-logout {
    border: 1px solid #e1e4e8;
    background: #ffffff;
    color: #626a75;
}
.top-account-logout:hover {
    border-color: #f0b4ac;
    background: #fff8f7;
    color: #c25349;
}

.top-nav-inner {
    max-width: 1280px;
    height: 68px;
    margin: 0 220px 0 calc(var(--sidebar-width, 200px) + 8px);
    display: flex;
    align-items: stretch;
    padding-left: 8px;
}

/* ---------- 一级导航项 ---------- */
.top-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    margin-right: 32px;
}
.top-nav-item:last-child {
    margin-right: 0;
}

.top-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    height: 68px;
    padding: 0 6px;
    font-size: 16px;
    color: #1a1a1a;
    font-weight: 600;
    letter-spacing: 1px;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.2s ease;
}

/* 底部指示条（hover / active 共用） */
.top-nav-link:hover::after,
.top-nav-item.top-nav-active .top-nav-link::after {
    content: '';
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: #e53935;
    transition: background 0.2s ease;
}

.top-nav-link:hover {
    color: #e53935;
}

/* 当前页 / 展开态高亮 */
.top-nav-item.top-nav-active .top-nav-link,
.top-nav-item.mega-open > .top-nav-link {
    color: #e53935;
    font-weight: 700;
}

/* 下拉箭头 */
.top-nav-link .arrow {
    display: inline-block;
    margin-left: 6px;
    font-size: 17px;
    line-height: 1;
    transition: transform 0.2s ease;
    transform: rotate(0deg);
}
.top-nav-item.mega-open > .top-nav-link .arrow {
    transform: rotate(180deg);
}

/* ============================================
   二级下拉（多列并行布局）
   ============================================ */
.sub-dropdown {
    position: fixed;
    top: 74px;
    /* 全屏覆盖：左缘贴屏，右侧贴屏（JS 仍写入 --dd-left，此处不再使用） */
    left: 0;
    right: 0;
    min-width: 0;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid #f0f0f0;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.25s ease-out, transform 0.25s ease-out, visibility 0.25s;
    z-index: 1000;
}
/* 展开状态 */
.top-nav-item.mega-open > .sub-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* 下拉菜单始终以当前一级菜单项为基准水平居中（.top-nav-item 为 position:relative） */

/* 多列网格：根据子项数量自动决定列数（由 JS 设置 data-cols） */
.sub-dropdown[data-cols="2"] {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 24px;
}
.sub-dropdown[data-cols="3"] {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px 20px;
}
.sub-dropdown[data-cols="4"] {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px 20px;
}
.sub-dropdown[data-cols="5"] {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px 20px;
}
/* 少于 4 项时保持单列 */
.sub-dropdown[data-cols="1"] {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px 20px;
}

/* 二级菜单项：图标 + 文字 + 标签 */
.sub-dropdown .sub-item {
    display: flex;
    align-items: center;
    min-height: 58px;
    padding: 0 14px;
    font-size: 15.5px;
    font-weight: 500;
    color: #333333;
    text-decoration: none;
    border-radius: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s ease, background 0.15s ease;
}
.sub-dropdown .sub-item:hover {
    color: #e53935;
    background: #fff5f5;
}

/* 菜单项图标（小方块样） */
.sub-dropdown .sub-item .sub-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-right: 10px;
}
.sub-dropdown .sub-item .sub-icon svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: #e53935;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.sub-dropdown .sub-item:hover .sub-icon svg {
    stroke: #e53935;
}
/* 数据库上传的图片图标 */
.sub-dropdown .sub-item .sub-icon img {
    width: 18px;
    height: 18px;
    object-fit: contain;
    display: block;
}

/* 二级标签角标：悬挂在名称右上角的上标徽章（参考图2） */
.sub-dropdown .sub-item .sub-name-wrap {
    position: relative;
    display: inline-block;
    min-width: 0;
    max-width: 100%;
    vertical-align: middle;
    line-height: 1.4;
    padding-right: 2px;
}
/* 名称单行省略（原作用在 .sub-name 上的能力保留） */
.sub-dropdown .sub-item .sub-name {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}
.sub-dropdown .sub-item .sub-tag {
    position: absolute;
    top: -9px;
    right: -14px;
    z-index: 2;
    display: inline-block;
    padding: 1px 6px;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.sub-tag.t-hot { background: #ff5722; color: #ffffff; }
.sub-tag.t-rec { background: #e53935; color: #ffffff; }
.sub-tag.t-new { background: #1e88e5; color: #ffffff; }
.sub-tag.t-free { background: #43a047; color: #ffffff; }
.sub-tag.t-todo { background: #e0e0e0; color: #666666; }
.sub-tag.t-gray { background: #f5f5f5; color: #999999; }
.sub-tag.t-default { background: #ffebee; color: #e53935; }

/* ---------- 布局补偿：侧边栏下移一个功能栏高度 ---------- */
.sidebar {
    top: 68px !important;
    height: calc(100vh - 68px) !important;
    /* sidebar.css 里的 min-height:100vh 会把 height 重新顶成整屏，
       导致底部 68px 被顶出屏幕外，必须一并覆盖 */
    min-height: 0 !important;
}

/* 菜单为可滚动区域：不再撑满整个侧栏，可视区截止到「个人中心」，
   多出的菜单项在内部滚动 */
.sidebar .nav-menu {
    /* 用户登录区已改为文档流贴底，菜单区弹性撑满剩余高度、底边紧贴登录块 */
    flex: 1 1 auto;
    max-height: none;
    padding-bottom: 4px;
}

/* 主内容区整体下移：
   同时收紧 min-height，避免 margin-top:68px 与 index.css 的 min-height:100vh
   叠加导致总高度变成 100vh+68px、页面底部多出滚动空间（出现双滚动条） */
.main-content {
    margin-top: 68px !important;
    min-height: calc(100vh - 68px) !important;
}

/* ---------- 宽屏适配 ---------- */
@media (min-width: 1920px) and (max-width: 2559px) {
    .top-logo {
        width: var(--sidebar-width-large, 220px);
    }
    .top-nav-inner {
        margin-left: calc(var(--sidebar-width-large, 220px) + 8px);
    }
}

@media (min-width: 2560px) {
    .top-logo {
        width: calc(var(--sidebar-width, 200px) * 1.3);
    }
    .top-nav-inner {
        margin-left: calc(var(--sidebar-width, 200px) * 1.3 + 8px);
    }
}

/* ---------- 响应式 ---------- */
@media (max-width: 1200px) {
    .top-logo {
        width: calc(var(--sidebar-width, 200px) - 8px);
    }
    .top-nav-inner {
        margin-left: calc(var(--sidebar-width, 200px) + 8px);
    }
    .top-nav-item {
        margin-right: 24px;
    }
}

@media (max-width: 992px) {
    .top-nav-item {
        margin-right: 18px;
    }
    .top-nav-link {
        font-size: 15px;
        padding: 0 4px;
    }
    .sub-dropdown[data-cols="3"],
    .sub-dropdown[data-cols="4"],
    .sub-dropdown[data-cols="5"] {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .top-function-bar {
        padding: 0 8px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    .top-logo {
        width: var(--sidebar-width-mobile, 70px);
        padding-left: 14px;
    }
    .top-logo .top-logo-img {
        height: 36px;
        max-height: 36px;
    }
    .top-logo .top-logo-text {
        display: none;
    }
    .top-nav-inner {
        margin: 0 110px 0 var(--sidebar-width-mobile, 70px);
        width: max-content;
        min-width: 640px;
    }
    .top-nav-item {
        margin-right: 20px;
    }
    .top-nav-link {
        font-size: 14px;
        height: 68px;
        padding: 0 2px;
    }
    .sub-dropdown {
        position: absolute;
        left: 50%;
        right: auto;
        transform: translate(-50%, -10px);
    }
    .top-nav-item.mega-open > .sub-dropdown {
        transform: translate(-50%, 0);
    }
    .sub-dropdown[data-cols="2"],
    .sub-dropdown[data-cols="3"],
    .sub-dropdown[data-cols="4"] {
        grid-template-columns: 1fr;
        width: 220px;
    }
    .sub-dropdown .sub-item {
        min-height: 40px;
    }
    /* 移动端无书签栏拖拽场景，隐藏收藏提示避免被 overflow 裁剪 */
    .bookmark-tooltip {
        display: none;
    }
    /* 移动端隐藏新功能提示，避免遮挡导航 */
    .newfeat-tooltip {
        display: none;
    }
    .top-account {
        right: 12px;
        padding-left: 10px;
        gap: 8px;
    }
    .top-account-info {
        display: none;
    }
    .top-account-login,
    .top-account-logout {
        min-width: 0;
        padding: 7px 9px;
    }
}
