/* 侧边栏容器基础样式 - 适配深色主题 */
.sidebar {
    padding: 0;
    margin-left: 10px;
    margin-top: 10px;
    width: 250px;
    background-color: #1e1e1e !important; /* 深色背景 */
    color: #e0e0e0 !important; /* 浅色文字 */
    transition: all 0.3s ease;
    overflow-y: auto;
    flex-shrink: 0;
    position: sticky;
    top: 110px;
    align-self: flex-start;
    max-height: calc(100vh - 20px);
    border: 1px solid #333 !important; /* 深色边框 */
}

/* 顶级章节项容器 - 修复换行问题 */
.sidebar .nav-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    flex-wrap: nowrap !important;
    border-bottom: 1px solid #333 !important; /* 分隔线 */
}

/* 侧边栏菜单链接 */
.sidebar .nav-link {
    position: relative;
    transition: all 0.2s;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    line-height: 1.2;
    flex: 1;
    min-width: 0;
    padding: 10px 12px !important;
    overflow: hidden;
    text-decoration: none !important;
    color: #e0e0e0 !important;
    background: transparent !important;
    border-left: 3px solid transparent !important; /* 添加透明边框保持布局一致 */
}

/* 菜单文本 - 确保不挤压箭头 */
.sidebar .nav-link .menu-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    max-width: calc(100% - 35px); /* 为箭头预留固定空间 */
    color: #e0e0e0 !important;
    font-weight: 500;
}

.sidebar .nav-link .sub-menu-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
    max-width: calc(100% - 35px);
    color: #b0b0b0 !important;
    font-size: 0.9em;
}

/* 箭头按钮样式 - 完全固定位置 */
.sidebar .arrow-btn {
    cursor: pointer;
    transition: all 0.2s;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 30px !important;
    height: 30px !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    margin-left: auto !important;
    background: transparent !important;
    border: none !important;
    color: #e0e0e0 !important;
    border-radius: 4px;
}

.sidebar .arrow-btn:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* 菜单箭头图标 */
.menu-arrow {
    transition: transform 0.3s ease;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: inherit !important;
}

/* 激活状态 - 深色主题适配 */
.sidebar .nav-link.active {
    background-color: rgba(100, 149, 237, 0.2) !important; /* 深蓝色背景 */
    border-left: 3px solid red !important; /* 红色边框 - 修改这里 */
    color: #ffffff !important;
}

.sidebar .nav-link.active .menu-text {
    color: #ffffff !important;
    font-weight: 600;
}

/* 子菜单活跃状态 - 提高优先级 */
.submenu .nav-link.active {
    background-color: rgba(100, 149, 237, 0.15) !important;
    border-left: 3px solid red !important; /* 子菜单活跃状态红色边框 */
    color: #ffffff !important;
}

/* 防止折叠组件覆盖 active 状态 */
.sidebar .collapse.show .nav-link.active,
.sidebar .collapse:not(.show) .nav-link.active {
    background-color: rgba(100, 149, 237, 0.2) !important;
    border-left: 3px solid red !important;
    color: #ffffff !important;
}

.submenu .collapse.show .nav-link.active,
.submenu .collapse:not(.show) .nav-link.active {
    background-color: rgba(100, 149, 237, 0.15) !important;
    border-left: 3px solid red !important;
    color: #ffffff !important;
}

/* 子菜单样式 */
.submenu {
    background-color: #2a2a2a !important; /* 更深背景 */
}

.submenu .nav-link {
    padding-left: 2rem !important;
    color: #b0b0b0 !important;
    background: transparent !important;
    border-left: 3px solid transparent !important; /* 子菜单也添加透明边框 */
}

.submenu .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.submenu .nav-link.active {
    background-color: rgba(100, 149, 237, 0.15) !important;
    border-left: 3px solid red !important; /* 子菜单活跃状态红色边框 - 修改这里 */
    color: #ffffff !important;
}

/* 悬停效果 */
.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
}

.sidebar .nav-link:hover .menu-text {
    color: #ffffff !important;
}

/* 手机端适配 - 极致紧凑布局 */
@media (max-width: 768px) {
    .sidebar {
        display: none !important;
        background-color: #1a1a1a !important;
    }

    .sidebar.mobile-visible {
        display: block !important;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px !important; /* 稍微减小宽度 */
        z-index: 1040;
        margin: 0;
        max-height: 100vh;
        background-color: #1a1a1a !important;
        border: none !important; /* 移除边框节省空间 */
    }

    .sidebar.mobile-visible .nav-link {
        padding: 6px 10px !important; /* 极致紧凑的内边距 */
        min-height: 32px !important; /* 减小最小高度 */
    }

    .sidebar.mobile-visible .nav-link .menu-text,
    .sidebar.mobile-visible .nav-link .sub-menu-text {
        max-width: calc(100% - 32px);
        font-size: 0.82em; /* 稍微减小字体 */
    }

    .sidebar.mobile-visible .arrow-btn {
        width: 26px !important; /* 减小箭头按钮 */
        height: 26px !important;
        padding: 4px !important;
    }

    .sidebar.mobile-visible .p-3.border-bottom {
        padding: 8px 12px !important; /* 减少标题区域内边距 */
    }

    .sidebar.mobile-visible .p-3.border-bottom h4 {
        font-size: 1rem; /* 减小标题字体 */
        margin: 0;
    }

    .sidebar.mobile-visible .submenu .nav-link {
        padding-left: 1.2rem !important; /* 减少子菜单缩进 */
        padding-top: 4px !important;
        padding-bottom: 4px !important;
    }

    .sidebar.mobile-visible .nav-item {
        min-height: 32px !important; /* 减小项目高度 */
    }

    .sidebar.mobile-visible .submenu {
        padding-left: 0.8rem !important; /* 减少子菜单整体缩进 */
    }

    /* 手机端切换按钮 - 更紧凑 */
    #mobileSidebarToggle {
        display: none;
        position: fixed;
        bottom: 80px; /* 上移位置 */
        left: 12px;
        z-index: 1050;
        background-color: #6495ed;
        border: none;
        border-radius: 4px;
        color: white;
        padding: 6px 10px; /* 减小内边距 */
        font-size: 14px; /* 减小字体 */
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }

    /* 主内容区域极致紧凑 */
    .flex-grow-1.p-2 {
        width: 100% !important;
        margin: 0 !important;
        padding: 4px !important; /* 最小化内边距 */
    }

    .container-content {
        padding: 0 6px !important; /* 减少内容区域内边距 */
    }

    /* 文章内容区域紧凑优化 */
    .border.rounded.p-4 {
        padding: 12px !important; /* 减少文章内边距 */
        margin-bottom: 12px !important;
    }

    .article-content {
        font-size: 0.9em; /* 稍微减小字体 */
        line-height: 1.4; /* 调整行高 */
    }

    .article-content h3 {
        font-size: 1.2rem; /* 减小标题大小 */
        margin-bottom: 8px !important;
    }

    .alert {
        padding: 8px 12px !important; /* 减小警告框内边距 */
        margin-bottom: 8px !important;
        font-size: 0.85em;
    }
}

/* 遮罩层 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1039;
}

.sidebar-overlay.visible {
    display: block;
}

/* 主内容区域 */
.flex-grow-1.p-2 {
    margin-right: 10px;
    width: calc(100% - 250px - 20px);
}

/* 标题区域样式 */
.sidebar .p-3.border-bottom {
    background-color: #2a2a2a !important;
    border-bottom: 1px solid #444 !important;
}

.sidebar .p-3.border-bottom h4 {
    color: #ffffff !important;
    margin: 0;
    font-weight: 600;
}

/* 文章内容样式 - 深色主题适配 */
.article-content {
    color: #e0e0e0 !important;
}

.article-content *:not(pre):not(code) {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    word-break: break-word !important;
    max-width: 100%;
    color: #e0e0e0 !important;
}

.article-content pre,
.article-content code {
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-x: auto;
    background-color: #2a2a2a !important;
    color: #e0e0e0 !important;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
    line-height: 1.3;
    color: #ffffff !important;
}

/* 表格样式 - 深色主题 */
.article-content table {
    border-collapse: collapse !important;
    width: 100% !important;
    margin: 1rem 0 !important;
    font-size: 14px !important;
    background-color: #2a2a2a !important;
}

.article-content th,
.article-content td {
    border: 1px solid #444 !important;
    padding: 0.5rem 0.75rem !important;
    text-align: left !important;
    vertical-align: top !important;
    color: #e0e0e0 !important;
}

.article-content th {
    background-color: #333 !important;
    font-weight: 600 !important;
    color: #ffffff !important;
    border-bottom: 2px solid #555 !important;
}

.article-content tbody tr:nth-child(even) {
    background-color: #2f2f2f !important;
}

.article-content tbody tr:hover {
    background-color: #3a3a3a !important;
}

/* 内容区域容器样式 - 与 header 保持一致 */
.container-content {
    max-width: 100%; /* 与 header 容器相同的最大宽度 */
    margin: 0 auto; /* 居中显示 */
    padding: 0 15px; /* 与 header 相同的左右内边距 */
    width: 100%;
    box-sizing: border-box; /* 确保 padding 包含在宽度内 */
}

/* 最高优先级的 active 状态规则 */
.sidebar .nav-item .nav-link.active,
.sidebar .nav-link.active[class],
.sidebar .nav-link.active:not(.collapsed),
.submenu .nav-link.active[class],
.submenu .nav-link.active:not(.collapsed) {
    background-color: rgba(100, 149, 237, 0.2) !important;
    border-left: 3px solid red !important;
    color: #ffffff !important;
}

.submenu .nav-link.active,
.submenu .nav-link.active[class] {
    background-color: rgba(100, 149, 237, 0.15) !important;
    border-left: 3px solid red !important;
    color: #ffffff !important;
}

/* 防止任何可能的覆盖 */
.sidebar a.nav-link.active,
.sidebar .nav > .nav-item > .nav-link.active,
.submenu a.nav-link.active {
    border-left: 3px solid red !important;
    background-color: rgba(100, 149, 237, 0.2) !important;
}

/* 增强代码块样式 - 确保高亮显示 */
.article-content pre[class*="language-"] {
    background: #2d2d2d !important;
    border-radius: 6px !important;
    margin: 1rem 0 !important;
    padding: 1rem !important;
    overflow: auto !important;
    border: 1px solid #444 !important;
}

.article-content code[class*="language-"] {
    background: transparent !important;
    color: #f8f8f2 !important;
    text-shadow: none !important;
    font-family: 'Consolas', 'Monaco', 'Andale Mono', monospace !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
}

/* Prism 行号样式 */
.line-numbers .line-numbers-rows {
    border-right: 1px solid #555 !important;
}

.line-numbers-rows > span:before {
    color: #888 !important;
}

/* 确保代码高亮颜色在深色主题下可见 */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #6a9955 !important;
}

.token.keyword {
    color: #569cd6 !important;
}

.token.string {
    color: #ce9178 !important;
}

.token.function {
    color: #dcdcaa !important;
}

.token.number {
    color: #b5cea8 !important;
}