/* 侧边栏样式 */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    background-color: #f7f7f7;
    border-right: 1px solid #e1e4e8;
    padding: 20px 12px;
    box-sizing: border-box;
    z-index: 1000;
    font-size: 13px;
    scroll-behavior: smooth;
}

#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#sidebar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#sidebar h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
    color: #24292e;
    padding-bottom: 10px;
    border-bottom: 1px solid #e1e4e8;
}

/* 站内搜索 */
.site-search {
    margin-bottom: 12px;
}

.site-search-input {
    width: 100%;
    box-sizing: border-box;
    height: 34px;
    padding: 0 10px;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    background: #fff;
    color: #24292e;
    outline: none;
}

.site-search-input:focus {
    border-color: #0366d6;
    box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.15);
}

.site-search-status {
    margin-top: 6px;
    font-size: 12px;
    color: #6a737d;
}

.site-search-results {
    margin-top: 8px;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    max-height: 45vh;
    overflow-y: auto;
}

.search-item {
    display: block;
    padding: 10px 10px;
    text-decoration: none;
    border-bottom: 1px solid #f0f1f2;
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover {
    background: #f6f8fa;
}

.search-item-title {
    font-size: 13px;
    font-weight: 600;
    color: #24292e;
    margin-bottom: 2px;
}

.search-item-desc {
    font-size: 12px;
    color: #57606a;
    margin-bottom: 4px;
}

.search-item-snippet {
    font-size: 12px;
    color: #6a737d;
    line-height: 1.35;
}

.search-hit {
    background: #fff3b0; /* 浅黄高亮 */
    padding: 0 2px;
    border-radius: 3px;
}

.main-content .search-hit {
    background: #fff3b0;
}

.search-empty {
    padding: 10px;
    font-size: 12px;
    color: #6a737d;
}

#sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

#sidebar-nav li {
    margin: 0;
    padding: 0;
    position: relative;
}

/* 可折叠的导航项容器 */
.nav-item-container {
    display: flex;
    align-items: flex-start;
}

.nav-item-container > a {
    flex: 1;
    padding: 7px 8px;
    color: #586069;
    text-decoration: none;
    border-radius: 3px;
    transition: background-color 0.2s, color 0.2s;
    min-width: 0;              /* 关键：允许在 flex 容器内正常换行 */
    overflow-wrap: anywhere;   /* 避免长串/中英混排导致被截断 */
    word-break: break-word;
    display: block;
    line-height: 1.4;
}

.nav-item-container > a:hover {
    background-color: #e1e4e8;
    color: #0366d6;
}

.nav-item-container > a.active {
    background-color: #0366d6;
    color: #fff;
    font-weight: 500;
}

/* 折叠/展开按钮 */
.nav-toggle {
    width: 20px;
    height: 20px;
    padding: 0;
    margin-right: 6px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #586069;
    font-size: 11px;
    transition: transform 0.2s, color 0.2s;
    flex-shrink: 0;
    border-radius: 3px;
    margin-top: 2px; /* 多行标题时箭头与第一行对齐，避免遮挡 */
}

.nav-toggle:hover {
    color: #0366d6;
    background-color: rgba(3, 102, 214, 0.1);
}

.nav-toggle::before {
    content: '▶';
    display: block;
    transition: transform 0.2s ease;
    line-height: 1;
}

.nav-toggle.expanded::before {
    transform: rotate(90deg);
}

/* 没有子项的导航项不需要折叠按钮 */
.nav-item-container:not(.has-children) .nav-toggle {
    display: none;
}

/* 嵌套的导航项列表 */
.nav-children {
    list-style: none;
    padding: 0;
    margin: 0 0 4px 0;
    display: none; /* 改为 display 控制，避免 max-height/scrollHeight 造成丢项或不刷新 */
}

.nav-children.expanded {
    display: block;
}

/* 嵌套层级样式 */
.nav-level-1 {
    padding-left: 0;
    font-weight: 500;
}

.nav-level-2 {
    padding-left: 20px;
    font-size: 12.5px;
}

.nav-level-3 {
    padding-left: 36px;
    font-size: 12px;
}

.nav-level-4 {
    padding-left: 52px;
    font-size: 11.5px;
}

/* 主内容区域调整 */
.main-content {
    margin-left: 240px;
    padding: 20px 60px;
    max-width: 1400px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    #sidebar {
        width: 240px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }
    
    #sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
        padding: 20px;
    }
    
    .sidebar-toggle {
        display: block;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        background: #0366d6;
        color: white;
        border: none;
        padding: 10px 15px;
        border-radius: 5px;
        cursor: pointer;
        font-size: 18px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
    
    .sidebar-toggle:hover {
        background: #0256c2;
    }
}

.sidebar-toggle {
    display: none;
}

