/* ================================================================
 * knowledge.css — 知识库模块专用样式
 * ================================================================
 * 职责: 知识库页面布局 + 文章排版 + 导航树 + 搜索
 * 依赖: theme.css (CSS变量), tailwind
 * ================================================================ */

/* ── 布局骨架 ─────────────────────────────── */
.kb-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-base, #0a0a0f);
    color: #e5e7eb;
}

.kb-sidebar {
    width: 280px;
    min-width: 280px;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    background: var(--bg-secondary, #111118);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.kb-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.kb-topbar {
    height: 56px;
    min-height: 56px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    background: var(--bg-base, #0a0a0f);
}

/* 顶部分类标签栏 (MaoDocs风格) */
.kb-category-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    white-space: nowrap;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.kb-category-tabs::-webkit-scrollbar {
    display: none;
}

.kb-category-tab {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #9ca3af;
    cursor: pointer;
    border: none;
    background: none;
    white-space: nowrap;
    transition: all 0.15s;
}

.kb-category-tab:hover {
    color: #e5e7eb;
    background: rgba(255, 255, 255, 0.04);
}

.kb-category-tab.active {
    color: #60a5fa;
    background: rgba(59, 130, 246, 0.1);
}

.kb-content-area {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.kb-content-body {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    display: flex;
    flex-wrap: nowrap;
}

.kb-article-wrap {
    flex: 1;
    min-width: 0;
    max-width: 860px;
    width: 100%;
    padding: 32px 40px 80px;
}

/* ── 拖拽分割条 ── */
.kb-resize-handle {
    width: 4px;
    cursor: col-resize;
    background: rgba(255, 255, 255, 0.04);
    flex-shrink: 0;
    transition: background 0.2s;
}

.kb-resize-handle:hover,
.kb-resize-handle.dragging {
    background: rgba(59, 130, 246, 0.5);
}

/* ── 右侧聊天面板 ── */
.kb-chat-panel {
    width: 380px;
    min-width: 260px;
    max-width: 50vw;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    background: var(--bg-secondary, #111118);
    flex-shrink: 0;
}

.kb-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 13px;
    font-weight: 600;
    color: #d1d5db;
}

.kb-chat-toggle-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
}

.kb-chat-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #d1d5db;
}

.kb-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.kb-chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
    font-size: 13px;
    line-height: 1.7;
}

.kb-chat-welcome strong {
    color: #60a5fa;
}

.kb-chat-msg {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: kb-fade-in 0.2s ease;
}

@keyframes kb-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.kb-chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
}

.kb-chat-msg-body {
    flex: 1;
    font-size: 13px;
    line-height: 1.7;
    color: #d1d5db;
    word-break: break-word;
}

.kb-chat-msg-user .kb-chat-msg-body {
    color: #e5e7eb;
}

.kb-chat-typing {
    color: #6b7280;
    font-style: italic;
}

.kb-chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.kb-chat-login-prompt {
    text-align: center;
    padding: 12px;
    font-size: 13px;
    color: #6b7280;
}

.kb-chat-input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.kb-chat-input-wrap textarea {
    flex: 1;
    resize: none;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    color: #e5e7eb;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
    max-height: 120px;
}

.kb-chat-input-wrap textarea:focus {
    border-color: rgba(59, 130, 246, 0.5);
}

.kb-chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: #3b82f6;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.kb-chat-send-btn:hover {
    background: #2563eb;
}

/* ── 侧边导航 ─────────────────────────────── */
.kb-sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.kb-sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: white;
}

.kb-sidebar-logo img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.kb-sidebar-logo .kb-logo-title {
    font-weight: 600;
    font-size: 15px;
}

.kb-sidebar-logo .kb-logo-sub {
    font-size: 11px;
    color: #6b7280;
    margin-left: 4px;
}

.kb-filter-box {
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.kb-filter-input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    color: #e5e7eb;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.kb-filter-input:focus {
    border-color: rgba(59, 130, 246, 0.5);
}

.kb-filter-input::placeholder {
    color: #6b7280;
}

.kb-nav-tree {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 16px;
}

/* 导航分类 */
.kb-nav-category {
    margin-bottom: 4px;
}

.kb-nav-category-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #d1d5db;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    transition: background 0.15s;
}

.kb-nav-category-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.kb-nav-category-btn .kb-chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s;
    flex-shrink: 0;
    color: #6b7280;
}

.kb-nav-category.expanded>.kb-nav-category-btn .kb-chevron {
    transform: rotate(90deg);
}

.kb-nav-category-btn .kb-cat-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: #9ca3af;
}

/* 子节点容器 */
.kb-nav-children {
    display: none;
    padding-left: 12px;
}

.kb-nav-category.expanded>.kb-nav-children {
    display: block;
}

/* 导航节点（目录项）*/
.kb-nav-group {
    margin-bottom: 2px;
}

.kb-nav-group-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 5px 8px;
    border-radius: 5px;
    font-size: 12.5px;
    font-weight: 500;
    color: #c4c8d0;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    transition: all 0.15s;
}

.kb-nav-group-btn:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #e5e7eb;
}

.kb-nav-group-btn .kb-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform 0.2s;
    color: #4b5563;
}

.kb-nav-group.expanded>.kb-nav-group-btn .kb-chevron {
    transform: rotate(90deg);
}

.kb-nav-group>.kb-nav-children {
    display: none;
    padding-left: 10px;
}

.kb-nav-group.expanded>.kb-nav-children {
    display: block;
}

/* 叶子节点（文章链接）*/
.kb-nav-leaf {
    display: block;
    padding: 4px 8px 4px 22px;
    border-radius: 5px;
    font-size: 12.5px;
    color: #c4c8d0;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
    transition: all 0.15s;
    line-height: 1.5;
    border-left: 2px solid transparent;
}

.kb-nav-leaf:hover {
    background: rgba(255, 255, 255, 0.04);
    color: #f3f4f6;
}

.kb-nav-leaf.active {
    color: #60a5fa;
    background: rgba(59, 130, 246, 0.08);
    border-left-color: #3b82f6;
}

/* 过滤高亮 */
.kb-highlight {
    background: rgba(250, 204, 21, 0.25);
    color: #fbbf24;
    border-radius: 2px;
    padding: 0 1px;
}

.kb-nav-hidden {
    display: none !important;
}

/* ── 面包屑 ───────────────────────────────── */
.kb-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.kb-breadcrumb a {
    color: #9ca3af;
    text-decoration: none;
    transition: color 0.15s;
    cursor: pointer;
}

.kb-breadcrumb a:hover,
.kb-breadcrumb .kb-bc-link:hover {
    color: #60a5fa;
}

.kb-breadcrumb .kb-bc-sep {
    color: #4b5563;
    font-size: 11px;
}

.kb-breadcrumb .kb-bc-current {
    color: #d1d5db;
}

/* ── 文章排版 ─────────────────────────────── */
.kb-article h1 {
    font-size: 26px;
    font-weight: 700;
    color: #f3f4f6;
    margin-bottom: 16px;
    line-height: 1.4;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.kb-article .kb-meta {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    font-size: 12px;
    color: #6b7280;
}

.kb-article .kb-meta-tag {
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    font-size: 11px;
}

/* 文章元数据统计 (类MaoDocs) */
.kb-article-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    font-size: 12px;
    color: #6b7280;
    flex-wrap: wrap;
}

.kb-article-stats .kb-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.kb-article-stats .kb-stat svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

/* 发文信息卡片 (类MaoDocs) */
.kb-article-info-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

.kb-article-info-card h4 {
    font-size: 13px;
    font-weight: 600;
    color: #d1d5db;
    margin: 0 0 10px;
}

.kb-article-info-card ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.kb-article-info-card li {
    font-size: 12.5px;
    color: #9ca3af;
    padding: 3px 0;
    display: flex;
    gap: 4px;
}

.kb-article-info-card li strong {
    color: #d1d5db;
    min-width: 70px;
}

.kb-article .kb-heading {
    font-size: 20px;
    font-weight: 600;
    color: #e5e7eb;
    margin: 32px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.kb-article .kb-subheading {
    font-size: 16px;
    font-weight: 600;
    color: #d1d5db;
    margin: 24px 0 8px;
}

.kb-article p {
    font-size: 14.5px;
    line-height: 1.85;
    color: #d1d5db;
    margin-bottom: 8px;
}

.kb-article .kb-article-clause {
    margin: 16px 0 6px;
    color: #e5e7eb;
}

.kb-article .kb-article-clause strong {
    color: #60a5fa;
    font-weight: 600;
}

/* ── 文章内联 TOC ──────────────────────────── */
.kb-toc-title {
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.kb-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.kb-toc-list li {
    margin-bottom: 2px;
}

.kb-toc-list a {
    display: block;
    padding: 3px 12px;
    font-size: 12px;
    color: #9ca3af;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s;
    line-height: 1.5;
    cursor: pointer;
}

.kb-toc-list a:hover {
    color: #e5e7eb;
}

.kb-toc-list a.active {
    color: #60a5fa;
    border-left-color: #3b82f6;
}

.kb-toc-list a.level-3 {
    padding-left: 24px;
    font-size: 11.5px;
}

.kb-inline-toc {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 24px;
}

/* ── 首页品牌 + 卡片网格 ──────────────── */
.kb-home {
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px);
}

/* 品牌 Hero 区 */
.kb-brand {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 56px 60px 20px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

.kb-brand-logo {
    width: 80px;
    height: 80px;
    border-radius: 18px;
}

.kb-brand-title {
    font-size: 32px;
    font-weight: 700;
    color: #f3f4f6;
    margin: 0;
    line-height: 1.3;
}

.kb-brand-sep {
    color: #4b5563;
    font-weight: 300;
    margin: 0 8px;
    font-size: 28px;
}

.kb-brand-tagline {
    font-size: 16px;
    color: #d1d5db;
    margin: 8px 0 0;
}

.kb-brand-sub {
    font-size: 13px;
    color: #9ca3af;
    margin: 4px 0 0;
}

.kb-home-subtitle {
    font-size: 13px;
    color: #9ca3af;
    text-align: center;
    padding: 12px 60px 24px;
}

/* 卡片网格 (3x3) */
.kb-home-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 0 60px 40px;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

.kb-home-card {
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.2s;
}

.kb-home-card:hover {
    border-color: rgba(59, 130, 246, 0.25);
    background: rgba(255, 255, 255, 0.04);
    transform: translateY(-1px);
}

.kb-home-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: 12px;
}

.kb-home-card-title {
    font-size: 15px;
    font-weight: 600;
    color: #e5e7eb;
    margin-bottom: 4px;
}

.kb-home-card-desc {
    font-size: 12px;
    color: #9ca3af;
    line-height: 1.5;
}

/* ── 文章右侧 TOC 侧栏 (MaoDocs风格) ──────────────── */
.kb-toc-sidebar {
    width: 220px;
    min-width: 200px;
    flex-shrink: 0;
    padding: 24px 0 24px 16px;
    overflow-y: auto;
    position: sticky;
    top: 0;
    align-self: flex-start;
    max-height: calc(100vh - 56px);
    border-left: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── 搜索结果 ─────────────────────────────── */
.kb-search-results {
    padding: 16px 0;
}

.kb-search-result-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.kb-search-result-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.kb-search-result-title {
    font-size: 14px;
    font-weight: 500;
    color: #e5e7eb;
    margin-bottom: 4px;
}

.kb-search-result-path {
    font-size: 12px;
    color: #6b7280;
}

/* ── 空状态 ───────────────────────────────── */
.kb-empty {
    text-align: center;
    padding: 80px 40px;
    color: #6b7280;
}

.kb-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.kb-empty-text {
    font-size: 15px;
}

/* ── 加载状态 ─────────────────────────────── */
.kb-loading {
    text-align: center;
    padding: 60px 40px;
    color: #6b7280;
}

.kb-loading-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: kb-spin 0.6s linear infinite;
    margin: 0 auto 12px;
}

@keyframes kb-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── 移动端抽屉 ───────────────────────────── */
.kb-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

.kb-mobile-menu-btn {
    display: none;
}

@media (max-width: 768px) {
    .kb-sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .kb-sidebar.open {
        left: 0;
    }

    .kb-sidebar.open+.kb-sidebar-overlay {
        display: block;
    }

    .kb-mobile-menu-btn {
        display: flex;
    }

    .kb-toc-sidebar {
        display: none;
    }

    .kb-article-wrap {
        padding: 20px 16px 60px;
    }

    .kb-home {
        padding: 0;
    }

    .kb-brand {
        padding: 24px 16px 16px;
    }

    .kb-home-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 0 16px 24px;
        gap: 10px;
    }
}

@media (max-width: 1100px) {
    .kb-toc-sidebar {
        display: none;
    }
}

/* ── 滚动条 ───────────────────────────────── */
.kb-sidebar::-webkit-scrollbar,
.kb-nav-tree::-webkit-scrollbar,
.kb-content-area::-webkit-scrollbar,
.kb-toc-sidebar::-webkit-scrollbar {
    width: 4px;
}

.kb-sidebar::-webkit-scrollbar-thumb,
.kb-nav-tree::-webkit-scrollbar-thumb,
.kb-content-area::-webkit-scrollbar-thumb,
.kb-toc-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.kb-sidebar::-webkit-scrollbar-track,
.kb-nav-tree::-webkit-scrollbar-track,
.kb-content-area::-webkit-scrollbar-track,
.kb-toc-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

/* ── 导航/文章过渡底部 ────────────────────── */
.kb-nav-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.kb-nav-footer a {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #6b7280;
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}

.kb-nav-footer a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #d1d5db;
}

/* ── QA 搜索视图 ─────────────────────────────── */
.kb-qa-view {
    max-width: 860px;
    width: 100%;
    padding: 32px 40px 80px;
}

.kb-qa-title {
    font-size: 22px;
    font-weight: 700;
    color: #f3f4f6;
    margin-bottom: 20px;
}

.kb-qa-search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.03);
    margin-bottom: 20px;
}

.kb-qa-search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: #e5e7eb;
    font-size: 14px;
}

.kb-qa-search-box input::placeholder {
    color: #4b5563;
}

.kb-qa-results {
    max-height: calc(100vh - 240px);
    overflow-y: auto;
}

.kb-qa-item {
    padding: 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 12px;
    transition: all 0.15s;
}

.kb-qa-item:hover {
    border-color: rgba(59, 130, 246, 0.2);
    background: rgba(255, 255, 255, 0.02);
}

.kb-qa-item-q {
    font-size: 14px;
    font-weight: 600;
    color: #e5e7eb;
    margin-bottom: 8px;
    line-height: 1.5;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.kb-qa-item-a {
    font-size: 13px;
    color: #9ca3af;
    line-height: 1.7;
}

.kb-qa-item-meta {
    font-size: 11px;
    color: #4b5563;
    margin-top: 8px;
}

/* ── 移动端: 隐藏聊天面板 ─────────────────────── */
@media (max-width: 1100px) {

    .kb-chat-panel,
    .kb-resize-handle {
        display: none !important;
    }
}