:root {
    --doc-sidebar-width: 280px;
    --doc-toc-width: 240px;
    --doc-navbar-height: 60px;
    --doc-subnav-height: 44px;
    --doc-primary: #ef4444;
    --doc-primary-hover: #dc2626;
    --doc-primary-soft: #fef2f2;
    --doc-bg: #ffffff;
    --doc-bg-secondary: #fafafa;
    --doc-text: #0f172a;
    --doc-text-muted: #475569;
    --doc-border: #e5e7eb;
}

[data-bs-theme="dark"] {
    --doc-bg: #0f172a;
    --doc-bg-secondary: #1e293b;
    --doc-text: #f1f5f9;
    --doc-text-muted: #94a3b8;
    --doc-border: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--doc-bg);
    color: var(--doc-text);
}

.doc-navbar {
    background-color: var(--doc-bg);
    border-bottom: 1px solid var(--doc-border);
    height: var(--doc-navbar-height);
    backdrop-filter: blur(12px);
}
.doc-navbar .container-fluid {
    max-width: 1500px;
    margin: 0 auto;
}

.doc-navbar .navbar-brand { color: var(--doc-primary); font-size: 1.25rem; }
.doc-navbar .nav-link { color: var(--doc-text-muted); font-weight: 500; padding: 0.5rem 1rem; }
.doc-navbar .nav-link:hover, .doc-navbar .nav-link.active { color: var(--doc-text); }

.doc-subnav {
    position: fixed;
    top: var(--doc-navbar-height);
    left: 0;
    right: 0;
    z-index: 1028;
    height: var(--doc-subnav-height);
    background: var(--doc-bg);
    border-bottom: 1px solid var(--doc-border);
}

.doc-subnav-inner {
    max-width: 1500px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0 1.25rem;
}

.doc-subnav-link {
    display: inline-flex;
    align-items: center;
    height: 100%;
    white-space: nowrap;
    color: var(--doc-text-muted);
    text-decoration: none;
    font-size: 0.92rem;
    border-bottom: 2px solid transparent;
}

.doc-subnav-link:hover {
    color: var(--doc-text);
}

.doc-subnav-link.active {
    color: var(--doc-primary);
    border-bottom-color: var(--doc-primary);
    font-weight: 600;
}

.search-box .input-group {
    background-color: var(--doc-bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--doc-border);
}
.search-box .form-control { background: transparent; border: none; box-shadow: none !important; color: var(--doc-text); }
.search-box .input-group-text { border: none; color: var(--doc-text-muted); background: transparent; }

.doc-container {
    display: flex;
    gap: 0;
    max-width: 1500px;
    margin: calc(var(--doc-navbar-height) + var(--doc-subnav-height)) auto 0;
    min-height: calc(100vh - var(--doc-navbar-height) - var(--doc-subnav-height));
}

.doc-sidebar {
    position: sticky;
    top: calc(var(--doc-navbar-height) + var(--doc-subnav-height));
    width: var(--doc-sidebar-width);
    flex: 0 0 var(--doc-sidebar-width);
    height: calc(100vh - var(--doc-navbar-height) - var(--doc-subnav-height));
    overflow-y: auto;
    padding: 1.5rem;
    background-color: var(--doc-bg);
    border-right: 1px solid var(--doc-border);
}

.sidebar-heading {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--doc-text-muted);
    margin-bottom: 0.75rem;
    padding-left: 0.75rem;
}

.sidebar-section { margin-bottom: 1.5rem; }

.sidebar-nav .nav-link {
    color: #334155;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
}
.sidebar-nav .nav-link:hover { color: var(--doc-text); background-color: var(--doc-bg-secondary); }
.sidebar-nav .nav-link.active { color: var(--doc-primary); background-color: var(--doc-primary-soft); font-weight: 600; }

.sidebar-nav .nav-link[class*="tree-indent-"] {
    position: relative;
}

.sidebar-nav .nav-link.tree-indent-2,
.sidebar-nav .nav-link.tree-indent-3,
.sidebar-nav .nav-link.tree-indent-4,
.sidebar-nav .nav-link.tree-indent-5 {
    --tree-guide-x: 0.75rem;
    --tree-dot-x: 0.6rem;
}

.sidebar-nav .nav-link.tree-indent-2 {
    padding-left: 1.45rem;
    --tree-guide-x: 0.68rem;
    --tree-dot-x: 0.54rem;
}

.sidebar-nav .nav-link.tree-indent-3 {
    padding-left: 2.2rem;
    font-size: 0.88rem;
    --tree-guide-x: 1.38rem;
    --tree-dot-x: 1.24rem;
}

.sidebar-nav .nav-link.tree-indent-4 {
    padding-left: 2.95rem;
    font-size: 0.86rem;
    --tree-guide-x: 2.1rem;
    --tree-dot-x: 1.96rem;
}

.sidebar-nav .nav-link.tree-indent-5 {
    padding-left: 3.65rem;
    font-size: 0.84rem;
    --tree-guide-x: 2.8rem;
    --tree-dot-x: 2.66rem;
}

.sidebar-nav .nav-link.tree-indent-2::before,
.sidebar-nav .nav-link.tree-indent-3::before,
.sidebar-nav .nav-link.tree-indent-4::before,
.sidebar-nav .nav-link.tree-indent-5::before {
    content: "";
    position: absolute;
    left: var(--tree-guide-x);
    top: 0.28rem;
    bottom: 0.28rem;
    width: 1px;
    background: rgba(100, 116, 139, 0.35);
}

.sidebar-nav .nav-link.tree-indent-2::after,
.sidebar-nav .nav-link.tree-indent-3::after,
.sidebar-nav .nav-link.tree-indent-4::after,
.sidebar-nav .nav-link.tree-indent-5::after {
    content: "";
    position: absolute;
    left: var(--tree-dot-x);
    top: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transform: translateY(-50%);
    background: rgba(100, 116, 139, 0.55);
}

.sidebar-nav .nav-link.active.tree-indent-2::after,
.sidebar-nav .nav-link.active.tree-indent-3::after,
.sidebar-nav .nav-link.active.tree-indent-4::after,
.sidebar-nav .nav-link.active.tree-indent-5::after {
    background: var(--doc-primary);
}

.doc-content {
    flex: 1;
    padding: 2.5rem 2rem;
}

.doc-home {
    max-width: 900px;
    margin: 0 auto;
}

.hero-section {
    padding-top: 3.5rem !important;
    padding-bottom: 2.5rem !important;
}

.hero-section h1 {
    letter-spacing: -0.02em;
}

.hero-section .lead {
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
}

.doc-footer { color: var(--doc-text-muted); font-size: 0.875rem; }
.doc-footer a { text-decoration: none; }
.doc-footer a:hover { color: var(--doc-primary); }

.recent-updates {
    max-width: 860px;
    margin-left: auto;
    margin-right: auto;
}

.recent-updates .list-group-item {
    border-radius: 10px;
    margin-bottom: 0.6rem;
    border: 1px solid var(--doc-border);
}

.recent-updates .list-group-item:hover {
    border-color: rgba(239, 68, 68, 0.32);
    background: rgba(239, 68, 68, 0.04);
}

.recent-updates .list-group-item h6 {
    color: var(--doc-text);
}

.btn-primary {
    background-color: var(--doc-primary);
    border-color: var(--doc-primary);
    color: #ffffff !important;
    font-weight: 600;
}
.btn-primary:hover {
    background-color: var(--doc-primary-hover);
    border-color: var(--doc-primary-hover);
    color: #ffffff !important;
}
.btn-outline-secondary:hover {
    color: var(--doc-primary);
    border-color: var(--doc-primary);
    background: var(--doc-primary-soft);
}

.doc-content a:not(.btn):not(.nav-link):not(.list-group-item) {
    color: var(--doc-primary);
}

.doc-content a:not(.btn):not(.nav-link):not(.list-group-item):hover {
    color: var(--doc-primary-hover);
}

.doc-article-shell {
    max-width: 860px;
    margin: 0 auto;
}

.doc-toc {
    position: sticky;
    top: calc(var(--doc-navbar-height) + var(--doc-subnav-height));
    width: var(--doc-toc-width);
    flex: 0 0 var(--doc-toc-width);
    height: calc(100vh - var(--doc-navbar-height) - var(--doc-subnav-height));
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    border-left: 1px solid var(--doc-border);
    background: var(--doc-bg);
}

.toc-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--doc-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.8rem;
}

.toc-nav .nav-link {
    color: var(--doc-text-muted);
    font-size: 0.85rem;
    border-left: 2px solid transparent;
    padding: 0.22rem 0 0.22rem 0.72rem;
}

.toc-nav .nav-link:hover {
    color: var(--doc-primary);
}

.toc-nav .nav-link.active {
    color: var(--doc-primary);
    border-left-color: var(--doc-primary);
    background: linear-gradient(to right, var(--doc-primary-soft), transparent 70%);
    font-weight: 600;
}

.doc-right-spacer {
    width: var(--doc-toc-width);
    flex: 0 0 var(--doc-toc-width);
    border-left: 1px solid var(--doc-border);
    background: var(--doc-bg);
}

@media (max-width: 992px) {
    :root {
        --doc-navbar-height: 108px;
        --doc-subnav-height: 42px;
    }

    .doc-navbar {
        height: var(--doc-navbar-height);
        padding-top: 0.4rem;
        padding-bottom: 0.35rem;
    }

    .doc-navbar .container-fluid {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        row-gap: 0.45rem;
    }

    .doc-navbar .navbar-brand {
        flex: 1 1 auto;
        min-width: 0;
    }

    .doc-navbar .order-lg-last {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 0.35rem;
    }

    .search-box {
        flex: 1 1 auto;
        width: auto;
        margin-right: 0 !important;
    }

    .search-box .input-group {
        width: 100%;
    }

    .doc-sidebar { display: none; }
    .doc-container {
        margin-top: calc(var(--doc-navbar-height) + var(--doc-subnav-height));
        min-height: calc(100vh - var(--doc-navbar-height) - var(--doc-subnav-height));
    }
    .doc-content {
        width: 100%;
        flex: 1 1 auto;
        padding: 1.25rem 1rem;
    }
    .doc-home,
    .doc-article-shell,
    .recent-updates {
        max-width: 100%;
    }
    .doc-subnav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .doc-subnav-inner {
        width: max-content;
        min-width: 100%;
        padding: 0 0.85rem;
        gap: 0.75rem;
    }
    .doc-subnav-link {
        padding: 0 0.1rem;
    }
    .hero-section {
        padding-top: 2rem !important;
        padding-bottom: 1.4rem !important;
    }
    .hero-section h1 {
        font-size: clamp(1.65rem, 7vw, 2.2rem);
    }
    .hero-section .lead {
        font-size: 0.98rem;
    }
    .hero-section .d-flex {
        flex-direction: column;
        align-items: center;
    }
    .hero-section .btn {
        width: 100%;
        max-width: 320px;
    }
    .recent-updates .list-group-item {
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    .recent-updates .list-group-item > div {
        min-width: 0;
    }
    .recent-updates .list-group-item h6 {
        word-break: break-word;
    }
    .article-title {
        font-size: clamp(1.6rem, 7vw, 2rem);
    }
    .article-body {
        font-size: 0.98rem;
    }
    .article-body h2 {
        font-size: 1.28rem;
    }
    .article-body pre {
        margin-left: -0.35rem;
        margin-right: -0.35rem;
        border-radius: 8px;
    }
    .article-body table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    .category-meta,
    .article-card .small {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.2rem;
    }
    .search-box .input-group-text.small {
        display: none;
    }
}

@media (max-width: 1200px) {
    .doc-toc, .doc-right-spacer { display: none; }
}

@media (max-width: 576px) {
    :root {
        --doc-navbar-height: 102px;
        --doc-subnav-height: 40px;
    }

    .doc-navbar .container-fluid {
        padding-left: 0.65rem !important;
        padding-right: 0.65rem !important;
    }
    .doc-navbar .navbar-brand {
        max-width: 52vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 1.05rem;
    }
    .doc-navbar .order-lg-last {
        gap: 0.2rem;
    }
    .doc-navbar .order-lg-last .btn-link.nav-link {
        padding-left: 0.4rem !important;
        padding-right: 0.4rem !important;
    }
    .search-box .form-control {
        font-size: 0.95rem;
    }
    .doc-content {
        padding: 1rem 0.8rem;
    }
    .doc-subnav-link {
        font-size: 0.86rem;
    }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--doc-border); border-radius: 3px; }
