:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-sidebar: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.1);
    --sidebar-width: 280px;
    --header-height: 64px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-sidebar: #0b1120;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;
    --accent-primary: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-glow: rgba(96, 165, 250, 0.15);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Layout --- */
.doc-main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 3rem 4rem;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
}

@media (max-width: 768px) {
    .doc-main {
        margin-left: 0;
        padding: 2rem 1.5rem;
    }

    .sidebar {
        transform: translateX(-100%);
    }
}

/* --- Sidebar Styles --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.sidebar-logo-icon {
    font-size: 1.5rem;
}

.sidebar-logo-text {
    display: flex;
    flex-direction: column;
}

.sidebar-logo-title {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.125rem;
    line-height: 1.2;
    letter-spacing: -0.025em;
}

.sidebar-logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Theme Toggle Button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 9999px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: relative;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-muted);
    box-shadow: 0 0 10px var(--accent-glow);
}

.theme-toggle-icon-wrapper {
    position: relative;
    width: 20px;
    height: 20px;
}

.theme-toggle-sun,
.theme-toggle-moon {
    position: absolute;
    top: 0;
    left: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Mode State */
.theme-toggle.is-light .theme-toggle-sun {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.theme-toggle.is-light .theme-toggle-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0);
}

/* Dark Mode State */
.theme-toggle.is-dark .theme-toggle-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0);
}

.theme-toggle.is-dark .theme-toggle-moon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Scrollbar for sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 0.375rem;
    transition: background-color 0.2s;
    user-select: none;
}

.sidebar-section-title:hover {
    background-color: var(--bg-secondary);
}

.sidebar-section-title.active {
    color: var(--accent-primary);
}

.sidebar-section-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-section-arrow svg {
    width: 1rem;
    height: 1rem;
}

.sidebar-section-arrow.open {
    transform: rotate(90deg);
}

.sidebar-section-children {
    display: flex;
    flex-direction: column;
    margin-left: 1rem;
    border-left: 1px solid var(--border-color);
    padding-left: 0.5rem;
    gap: 0.15rem;
    margin-top: 0.25rem;
}

.sidebar-link,
.sidebar-root-link {
    display: block;
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    line-height: 1.5;
}

.sidebar-link:hover,
.sidebar-root-link:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.sidebar-link.active,
.sidebar-root-link.active {
    color: var(--accent-primary);
    background-color: var(--accent-glow);
    font-weight: 500;
}

/* --- DocPage container and hero --- */
.doc-page-container {
    max-width: 800px;
    margin: 0 auto;
}

.doc-page-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin: 0 0 1rem 0;
}

.doc-page-description {
    font-size: 1.125rem;
    color: var(--text-muted);
    margin: 0 0 2.5rem 0;
    line-height: 1.6;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 2rem;
}

/* --- DocContent (Markdown) Styles --- */
.doc-article {
    color: var(--text-primary);
    line-height: 1.75;
    font-size: 1.05rem;
    max-width: 800px;
    margin: 0 auto;
}

.doc-article h1,
.doc-article h2,
.doc-article h3,
.doc-article h4,
.doc-article h5,
.doc-article h6 {
    color: var(--text-primary);
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.doc-article h1 {
    font-size: 2.5rem;
    letter-spacing: -0.025em;
}

.doc-article h2 {
    font-size: 1.875rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 3rem;
}

.doc-article h3 {
    font-size: 1.5rem;
}

.doc-article h4 {
    font-size: 1.25rem;
}

.doc-article p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.doc-article a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 1px transparent;
}

.doc-article a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.doc-article ul,
.doc-article ol {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
    color: var(--text-secondary);
}

.doc-article li {
    margin-bottom: 0.5rem;
}

.doc-article li::marker {
    color: var(--text-muted);
}

.doc-article img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
}

.doc-article code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    background-color: var(--bg-secondary);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    color: var(--accent-primary);
    border: 1px solid var(--border-color);
}

.doc-article pre {
    background-color: #0f172a;
    color: #f8fafc;
    padding: 1.25rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
}

/* Ignore nested code styling inside pre */
.doc-article pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
    font-size: 0.9em;
    border: none;
}

.doc-article blockquote {
    border-left: 4px solid var(--accent-primary);
    padding: 1rem 1.25rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-style: italic;
    background-color: var(--bg-secondary);
    border-radius: 0 0.5rem 0.5rem 0;
}

.doc-article blockquote p:last-child {
    margin-bottom: 0;
}

.doc-article table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.95rem;
}

.doc-article th,
.doc-article td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.doc-article th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.doc-article td {
    color: var(--text-secondary);
}

.doc-article hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 3rem 0;
}