/* ============================================================
   KB System - 语雀风格主题
   Design inspired by Yuque (yuque.com)
   Brand: Jade Green #00B96B
   ============================================================ */

:root {
    /* Brand */
    --primary: #00B96B;
    --primary-hover: #00a05c;
    --primary-active: #008c4e;
    --primary-light: #e8f8f0;

    /* Text */
    --text: #262626;
    --text-secondary: #595959;
    --text-muted: #8c8c8c;
    --text-placeholder: #bfbfbf;
    --text-inverse: #fff;

    /* Backgrounds */
    --bg-page: #f0f2f5;
    --bg-card: #ffffff;
    --bg-layer: #fafafa;

    /* Borders */
    --border: #f0f0f0;
    --border-strong: #d9d9d9;

    /* Semantic */
    --success: #52c41a;
    --warning: #faad14;
    --danger: #ff4d4f;
    --info: #1890ff;

    /* Sidebar */
    --sidebar-bg: #ffffff;
    --sidebar-text: #595959;
    --sidebar-text-active: #00B96B;
    --sidebar-hover: #f5f5f5;
    --sidebar-active-bg: #e8f8f0;
    --sidebar-width: 240px;
    --sidebar-border: #f0f0f0;

    /* Sizing */
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(0,0,0,0.03), 0 1px 6px -1px rgba(0,0,0,0.02);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5715;
    color: var(--text);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }

/* ==============================
   Layout
   ============================== */

.layout {
    display: flex;
    min-height: 100vh;
}

/* ==============================
   Sidebar
   ============================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-brand {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: var(--text) !important;
    letter-spacing: -0.3px;
}

.sidebar-desc {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Nav */
.sidebar-nav {
    padding: 8px 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 24px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    line-height: 1.4;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    position: relative;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--text);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    border-left-color: var(--primary);
    font-weight: 500;
}

.nav-icon {
    font-size: 15px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}

.nav-label {
    flex: 1;
}

.nav-section-label {
    padding: 16px 24px 6px;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-footer .nav-item {
    font-size: 13px;
    color: var(--text-muted);
}

.sidebar-footer .nav-item:hover {
    color: var(--danger);
    background: #fff2f0;
    border-left-color: var(--danger);
}

/* ==============================
   Main Content
   ============================== */

.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px 40px;
    min-height: 100vh;
    max-width: calc(100% - var(--sidebar-width));
}

/* ==============================
   Page Header
   ============================== */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
}

/* ==============================
   Cards
   ============================== */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    transition: box-shadow var(--transition);
}

.card:hover {
    box-shadow: var(--shadow);
}

.card-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.card-body { padding: 24px; }

/* ==============================
   Stats Grid
   ============================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px 20px;
    text-align: center;
    transition: all var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border-strong);
}

.stat-card .stat-value {
    font-size: 30px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ==============================
   Buttons
   ============================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 16px;
    height: 32px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5715;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border-strong);
    user-select: none;
}

.btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.btn:active {
    color: var(--primary-active);
    border-color: var(--primary-active);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse) !important;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-primary:active {
    background: var(--primary-active);
    border-color: var(--primary-active);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-inverse) !important;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #ff7875;
    border-color: #ff7875;
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-outline:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-sm {
    padding: 2px 10px;
    height: 26px;
    font-size: 13px;
}

/* ==============================
   Forms
   ============================== */

.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 5px 12px;
    height: 34px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    background: var(--bg-card);
    transition: all var(--transition);
    line-height: 1.5715;
}

.form-control:hover {
    border-color: var(--primary);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 185, 107, 0.15);
}

.form-control::placeholder {
    color: var(--text-placeholder);
}

textarea.form-control {
    min-height: 400px;
    height: auto;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 12px;
    resize: vertical;
}

select.form-control {
    height: 34px;
    cursor: pointer;
}

/* ==============================
   Item List (Article/Changelog/Session lists)
   ============================== */

.item-list { list-style: none; }

.item-list li {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

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

.item-list li:hover { background: var(--bg-layer); }

.item-list .item-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.item-list .item-title a {
    color: var(--text);
    text-decoration: none;
}

.item-list .item-title a:hover { color: var(--primary); }

.item-list .item-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.item-list .item-excerpt {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    line-height: 1.6;
}

/* ==============================
   Badges & Tags
   ============================== */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}

.badge-security { background: #fff2f0; color: #cf1322; border: 1px solid #ffccc7; }
.badge-bugfix { background: #fffbe6; color: #d4b106; border: 1px solid #ffe58f; }
.badge-feature { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }
.badge-refactor { background: #e6f7ff; color: #096dd9; border: 1px solid #91d5ff; }
.badge-config { background: #f9f0ff; color: #722ed1; border: 1px solid #d3adf7; }
.badge-docs { background: #f5f5f5; color: #595959; border: 1px solid #d9d9d9; }
.badge-update { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }

.category-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    background: var(--primary-light);
    color: var(--primary-active);
    font-weight: 500;
}

.tag {
    display: inline-block;
    padding: 1px 8px;
    background: var(--bg-layer);
    color: var(--text-secondary);
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid var(--border);
}

.version-info {
    color: var(--primary);
    font-weight: 600;
    font-size: 12px;
}

/* ==============================
   Article / Content View
   ============================== */

.article-content, .rendered-content {
    line-height: 1.8;
    font-size: 15px;
    color: var(--text);
}

.article-content h1, .rendered-content h1 { font-size: 26px; margin: 28px 0 14px; font-weight: 700; }
.article-content h2, .rendered-content h2 { font-size: 22px; margin: 24px 0 12px; font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.article-content h3, .rendered-content h3 { font-size: 18px; margin: 20px 0 10px; font-weight: 600; }
.article-content h4, .rendered-content h4 { font-size: 16px; margin: 16px 0 8px; font-weight: 600; }

.article-content p, .rendered-content p { margin-bottom: 16px; }

.article-content ul, .article-content ol,
.rendered-content ul, .rendered-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}
.article-content li, .rendered-content li { margin-bottom: 6px; }

.article-content pre, .rendered-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin-bottom: 20px;
    font-size: 13px;
    line-height: 1.6;
}

.article-content code, .rendered-content code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Courier New", monospace;
    color: #d63384;
}

.article-content pre code, .rendered-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.article-content blockquote, .rendered-content blockquote {
    border-left: 4px solid var(--primary);
    padding: 10px 16px;
    margin-bottom: 20px;
    background: var(--primary-light);
    color: var(--text-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.article-content table, .rendered-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.article-content th, .article-content td,
.rendered-content th, .rendered-content td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.article-content th, .rendered-content th {
    background: var(--bg-layer);
    font-weight: 600;
}

.article-content img, .rendered-content img { max-width: 100%; border-radius: var(--radius-sm); }
.article-content hr, .rendered-content hr { border: none; border-top: 2px solid var(--border); margin: 28px 0; }
.article-content a, .rendered-content a { color: var(--primary); }
.article-content a:hover, .rendered-content a:hover { text-decoration: underline; }

/* ==============================
   Search
   ============================== */

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-box input {
    flex: 1;
    padding: 5px 12px;
    height: 34px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: all var(--transition);
}

.search-box input:hover {
    border-color: var(--primary);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 185, 107, 0.15);
}

/* ==============================
   Login
   ============================== */

.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f0f2f5 0%, #e8f8f0 100%);
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 400px;
    max-width: 90vw;
}

.login-card h1 {
    font-size: 24px;
    text-align: center;
    margin-bottom: 4px;
    color: var(--text);
    font-weight: 700;
}

.login-card p {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
}

.login-card .btn-primary {
    width: 100%;
    justify-content: center;
    height: 40px;
    font-size: 15px;
}

/* ==============================
   Alerts
   ============================== */

.alert {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.alert-error {
    background: #fff2f0;
    color: #cf1322;
    border: 1px solid #ffccc7;
}

.alert-success {
    background: #f6ffed;
    color: #389e0d;
    border: 1px solid #b7eb8f;
}

/* ==============================
   Empty State
   ============================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.empty-state h4 { font-size: 16px; margin-bottom: 8px; color: var(--text); font-weight: 600; }
.empty-state p { font-size: 14px; color: var(--text-muted); }
.empty-state .btn { margin-top: 16px; }

/* ==============================
   Quick Actions Grid
   ============================== */

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
}

.action-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
    color: var(--text);
}

.action-card .action-icon { font-size: 28px; line-height: 1; }
.action-card .action-label { font-size: 14px; font-weight: 600; }
.action-card .action-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ==============================
   Data Table
   ============================== */

.data-table { width: 100%; border-collapse: collapse; }

.data-table th, .data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.data-table th {
    background: var(--bg-layer);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--bg-layer); }

.data-table code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #d63384;
}

/* ==============================
   Editor Toolbar
   ============================== */

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-layer);
    border: 1px solid var(--border-strong);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.editor-toolbar .btn {
    font-size: 13px;
    min-width: 30px;
    text-align: center;
    padding: 2px 8px;
    height: 28px;
    background: transparent;
    border-color: transparent;
}

.editor-toolbar .btn:hover {
    background: var(--sidebar-hover);
    border-color: var(--border-strong);
    color: var(--text);
}

.editor-toolbar .btn i { font-style: italic; }

.toolbar-sep {
    color: var(--border-strong);
    margin: 0 4px;
    font-size: 14px;
    user-select: none;
}

.editor-area {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Courier New", monospace;
}

/* ==============================
   Mobile sidebar toggle (hamburger)
   ============================== */

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

.sidebar-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 99;
}

/* ==============================
   Responsive
   ============================== */

@media (max-width: 1024px) {
    .main {
        padding: 24px 20px;
    }
}

@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 12px rgba(0,0,0,0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

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

    .main {
        margin-left: 0;
        max-width: 100%;
        padding: 16px;
        padding-top: 60px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .action-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .action-grid {
        grid-template-columns: 1fr 1fr;
    }

    .main {
        padding: 12px;
        padding-top: 56px;
    }

    .card-body {
        padding: 16px;
    }
}

/* ==============================
   Transitions & Utilities
   ============================== */

/* Smooth page load fade */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.main > * {
    animation: fadeIn 0.3s ease forwards;
}

.main > .page-header {
    animation-delay: 0s;
}

.main > .card,
.main > .stats-grid,
.main > .action-grid,
.main > .search-box {
    animation-delay: 0.05s;
}

/* Sidebar item slide-in */
.sidebar-nav .nav-item {
    animation: fadeIn 0.25s ease backwards;
}

.sidebar-nav .nav-item:nth-child(1) { animation-delay: 0.02s; }
.sidebar-nav .nav-item:nth-child(2) { animation-delay: 0.04s; }
.sidebar-nav .nav-item:nth-child(3) { animation-delay: 0.06s; }
.sidebar-nav .nav-item:nth-child(4) { animation-delay: 0.08s; }
.sidebar-nav .nav-item:nth-child(5) { animation-delay: 0.10s; }
.sidebar-nav .nav-item:nth-child(6) { animation-delay: 0.12s; }
.sidebar-nav .nav-item:nth-child(7) { animation-delay: 0.14s; }
.sidebar-nav .nav-item:nth-child(8) { animation-delay: 0.16s; }
.sidebar-nav .nav-item:nth-child(9) { animation-delay: 0.18s; }
.sidebar-nav .nav-item:nth-child(10) { animation-delay: 0.20s; }
