:root {
    /* --- Enterprise Design System --- */
    
    /* Core Palette - Dark Mode Optimized */
    --color-bg-base: #0d1117;       /* Deep Github-like dark */
    --color-bg-surface: #161b22;    /* Slightly lighter for cards/sidebar */
    --color-bg-elevated: #21262d;   /* Hover states, inputs */
    
    --color-border-subtle: #30363d; /* Separators */
    --color-border-active: #8b949e; /* Focus/Active borders */
    
    --color-text-primary: #f0f6fc;  /* High contrast text */
    --color-text-secondary: #8b949e; /* Metadata, subtitles */
    --color-text-muted: #484f58;    /* Disabled, placeholders */
    
    /* Brand Colors */
    --color-accent: #58a6ff;        /* Primary Blue */
    --color-accent-dim: rgba(88, 166, 255, 0.15);
    --color-success: #238636;
    --color-danger: #da3633;
    --color-warning: #d29922;
    --color-info: #58a6ff;
    
    /* Syntax Highlighting Background */
    --color-code-bg: #0d1117;       /* Seamless code blocks */
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    
    /* Layout Dimensions */
    --header-height: 64px;
    --sidebar-width: 280px;
    --toc-width: 240px;
    --content-width: 960px; /* Wider for enterprise docs */
    --transition-speed: 0.2s;
}

[data-theme="light"] {
    --color-bg-base: #ffffff;
    --color-bg-surface: #f6f8fa;
    --color-bg-elevated: #eaeef2;
    
    --color-border-subtle: #d0d7de;
    --color-border-active: #0969da;
    
    --color-text-primary: #24292f;
    --color-text-secondary: #57606a;
    --color-text-muted: #8c959f;
    
    --color-accent: #0969da;
    --color-accent-dim: rgba(9, 105, 218, 0.1);
    --color-code-bg: #f6f8fa;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background-color: var(--color-bg-base);
    color: var(--color-text-primary);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color var(--transition-speed);
}

a:hover {
    text-decoration: underline;
    color: #79c0ff;
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
    padding-top: var(--header-height);
}

/* --- Header --- */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: rgba(22, 27, 34, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 1000;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Mobile Toggle */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
    padding: 0.5rem;
}

.header-logo a {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--color-text-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Search Input */
.header-search {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 1rem;
}

.header-search input {
    width: 100%;
    background: var(--color-bg-base);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.header-search input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-dim);
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: 6px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.3);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
}

.search-item {
    display: block;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
}

.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--color-bg-elevated); text-decoration: none; }

.search-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.search-item-title { font-weight: 600; font-size: 0.95rem; }
.search-item-badge { 
    font-size: 0.75rem; 
    color: var(--color-text-secondary);
    background: var(--color-bg-base);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--color-border-subtle);
}

/* --- Sidebar Navigation --- */
.app-sidebar {
    background: var(--color-bg-surface);
    border-right: 1px solid var(--color-border-subtle);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    position: sticky;
    top: var(--header-height);
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 1.5rem;
}

.nav-group { margin-bottom: 2rem; }
.nav-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    padding-left: 0.5rem;
}

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

.nav-item a {
    display: block;
    padding: 0.4rem 0.6rem;
    color: var(--color-text-primary);
    font-size: 0.9rem;
    border-radius: 4px;
    text-decoration: none;
    transition: background 0.15s;
    opacity: 0.9;
}

.nav-item a:hover {
    background: var(--color-bg-elevated);
    opacity: 1;
}

.nav-item a.active {
    background: var(--color-accent-dim);
    color: var(--color-accent);
    font-weight: 600;
    opacity: 1;
}

/* --- Main Content --- */
.app-content {
    flex-grow: 1;
    max-width: var(--content-width);
    padding: 2.5rem 3rem;
    min-width: 0;
}

.markdown-body {
    font-size: 1rem;
    line-height: 1.65;
    text-align: left;
}

.markdown-body h1 { font-size: 2.25rem; font-weight: 700; border-bottom: 1px solid var(--color-border-subtle); padding-bottom: 0.5rem; margin-bottom: 2rem; }
.markdown-body h2 { font-size: 1.75rem; font-weight: 600; margin-top: 3rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border-subtle); padding-bottom: 0.3rem; }
.markdown-body h3 { font-size: 1.4rem; font-weight: 600; margin-top: 2rem; margin-bottom: 0.75rem; }
.markdown-body p { margin-bottom: 1.2rem; }

/* Code Blocks & Copy Button */
.code-wrapper {
    position: relative;
    margin: 1.5rem 0;
}

.markdown-body pre {
    background: #0d1117; /* Hardcoded dark for contrast */
    border: 1px solid var(--color-border-subtle);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--color-text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-btn:hover { background: rgba(255,255,255,0.2); color: white; }
.copy-btn.copied { border-color: var(--color-success); color: var(--color-success); }

/* Tables */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.95rem;
}

.markdown-body th {
    background: var(--color-bg-surface);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border-subtle);
}

.markdown-body td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border-subtle);
}

.markdown-body tr:nth-child(even) { background: rgba(255,255,255,0.02); }

/* Admonitions (Alert Blocks) */
.markdown-body .info,
.markdown-body .warning,
.markdown-body .danger,
.markdown-body .tip {
    padding: 1rem 1rem 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid;
    border-radius: 4px;
    background: var(--color-bg-surface);
}

.markdown-body .info { border-color: var(--color-info); }
.markdown-body .warning { border-color: var(--color-warning); }
.markdown-body .danger { border-color: var(--color-danger); }
.markdown-body .tip { border-color: var(--color-success); }

.markdown-body .info::before { content: "ℹ️ Note"; display: block; font-weight: bold; margin-bottom: 0.5rem; color: var(--color-info); }
.markdown-body .warning::before { content: "⚠️ Warning"; display: block; font-weight: bold; margin-bottom: 0.5rem; color: var(--color-warning); }
.markdown-body .danger::before { content: "🛑 Critical"; display: block; font-weight: bold; margin-bottom: 0.5rem; color: var(--color-danger); }
.markdown-body .tip::before { content: "💡 Tip"; display: block; font-weight: bold; margin-bottom: 0.5rem; color: var(--color-success); }

/* --- TOC Sidebar --- */
.app-toc {
    width: var(--toc-width);
    flex-shrink: 0;
    padding: 2.5rem 1.5rem;
    border-left: 1px solid var(--color-border-subtle);
    background: var(--color-bg-base);
}

.toc-sticky {
    position: sticky;
    top: calc(var(--header-height) + 2rem);
}

.toc-sticky h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    margin-bottom: 1rem;
}

.toc-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
}

.toc-content li { margin-bottom: 0.6rem; }
.toc-content a { color: var(--color-text-secondary); text-decoration: none; display: block; line-height: 1.4; }
.toc-content a:hover { color: var(--color-accent); }

/* --- Hero & Portal Components --- */
.hero {
    text-align: left;
    padding: 4rem 0;
    border-bottom: 1px solid var(--color-border-subtle);
    margin-bottom: 3rem;
}

.hero h1 { font-size: 3rem; letter-spacing: -0.03em; margin-bottom: 1rem; line-height: 1.1; }
.hero p { font-size: 1.3rem; color: var(--color-text-secondary); max-width: 600px; }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.card {
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: all 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text-primary);
}

.card-desc {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    flex-grow: 1;
    margin-bottom: 1.5rem;
}

.card-meta {
    border-top: 1px solid var(--color-border-subtle);
    padding-top: 1rem;
    font-size: 0.8rem;
    display: flex;
    gap: 0.5rem;
}

/* Badge */
.badge {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-subtle);
    border-radius: 4px;
    padding: 0.1em 0.5em;
    font-size: 0.75em;
    font-weight: 600;
    color: var(--text-secondary);
    vertical-align: middle;
}

/* --- Breadcrumbs --- */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.breadcrumbs a {
    color: var(--color-text-secondary);
}

.breadcrumbs span.separator {
    color: var(--color-text-muted);
}

/* Heading Anchor Links */
.header-anchor {
    float: left;
    margin-left: -24px;
    padding-right: 8px;
    color: var(--color-accent);
    opacity: 0;
    transition: opacity 0.2s;
    text-decoration: none !important;
}

.markdown-body h2:hover .header-anchor,
.markdown-body h3:hover .header-anchor,
.markdown-body h4:hover .header-anchor {
    opacity: 1;
}

/* --- Scroll to Top --- */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--color-bg-elevated);
    color: var(--color-text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border-subtle);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-to-top:hover {
    background: var(--color-accent);
    color: #000;
    border-color: var(--color-accent);
}

/* Search Highlighting */
mark {
    background: rgba(245, 158, 11, 0.4);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* Media Queries */
@media (max-width: 1250px) {
    .app-toc { display: none; }
}

@media (max-width: 900px) {
    .app-layout { display: block; }
    .mobile-toggle { display: block; }
    .app-sidebar {
        left: -100%;
        transition: left 0.3s ease;
        z-index: 2000;
        width: 85%;
        max-width: 320px;
        box-shadow: 10px 0 30px rgba(0,0,0,0.5);
        position: fixed;
    }
    .app-sidebar.open { left: 0; }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.7);
        z-index: 1999;
    }
    .sidebar-overlay.visible { display: block; }
    .app-content { padding: 2rem 1.2rem; max-width: 100%; }
    .header-search { display: none; }
    .markdown-body h1 { font-size: 1.8rem; }
    .hero h1 { font-size: 2.2rem; }
    .header-anchor { display: none; }
}