:root {
    --bg-main: #ffffff;
    --bg-nav: rgba(255, 255, 255, 0.8);
    --bg-sidebar: #f8f9fa;
    --bg-hover: #f1f3f5;
    --text-main: #24292f;
    --text-muted: #57606a;
    --border-color: #d0d7de;
    --primary-color: #0969da;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --nav-height: 60px;
    --sidebar-width: 280px;
}

[data-theme="dark"] {
    --bg-main: #0d1117;
    --bg-nav: rgba(13, 17, 23, 0.8);
    --bg-sidebar: #161b22;
    --bg-hover: #21262d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --border-color: #30363d;
    --primary-color: #58a6ff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden; /* Prevent body scroll, use container scroll */
    transition: background-color 0.3s, color 0.3s;
}

/* === Navbar === */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-nav);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    margin-left: 0.5rem;
    color: var(--text-main);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.search-box {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem 1rem;
    width: 300px;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: text;
    transition: border-color 0.2s;
}

.search-box:hover {
    border-color: var(--text-muted);
}

/* === Layout === */
.app-container {
    display: flex;
    margin-top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    width: 100vw;
}

/* === Sidebar (Left) === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar.closed {
    width: 0;
    border-right: none;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    min-width: var(--sidebar-width);
}

.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    min-width: var(--sidebar-width);
}

.tree-item {
    padding: 0.4rem 0.5rem;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-item:hover {
    background: var(--bg-hover);
}

.tree-item.active {
    background: rgba(9, 105, 218, 0.1);
    color: var(--primary-color);
    font-weight: 600;
}

.tree-children {
    padding-left: 1rem;
    margin-left: 0.5rem;
    border-left: 1px solid var(--border-color); /* VSCode like guide lines */
    display: none;
}

.tree-children.open {
    display: block;
}

/* === Main Content === */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 4rem;
    position: relative;
    scroll-behavior: smooth;
    min-width: 0;
}

/* === Right Sidebar (TOC & Local Graph) === */
.right-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    flex-shrink: 0;
}

.right-sidebar.closed {
    width: 0;
    border-left: none;
}

.toc-header, .local-graph-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    min-width: var(--sidebar-width);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toc-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    min-width: var(--sidebar-width);
}

.local-graph-container {
    height: 300px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-width: var(--sidebar-width);
}

.local-graph-header {
    border-bottom: none;
    padding-bottom: 0;
}

.toc-item {
    display: block;
    padding: 0.3rem 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.toc-item:hover {
    color: var(--primary-color);
}

.toc-h1 { padding-left: 0; font-weight: 600; color: var(--text-main); margin-top: 0.5rem; }
.toc-h2 { padding-left: 0.8rem; }
.toc-h3 { padding-left: 1.6rem; }
.toc-h4 { padding-left: 2.4rem; }
.toc-h5 { padding-left: 3.2rem; }
.toc-h6 { padding-left: 4.0rem; }

/* === Modals === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.modal.open {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-main);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

/* Search Modal */
.search-modal {
    width: 600px;
    max-width: 90vw;
    height: 70vh;
    margin-top: -10vh;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}

.search-input-wrapper i {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.search-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1.2rem;
    color: var(--text-main);
    outline: none;
}

.search-filters {
    padding: 0.8rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background: var(--bg-main);
}

.filter-group {
    display: flex;
    align-items: center;
    background: var(--bg-hover);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    width: fit-content;
}

.filter-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0 0.8rem 0 0.5rem;
}

.filter-pill {
    position: relative;
    cursor: pointer;
    margin: 0;
}

.filter-pill input[type="radio"] {
    display: none;
}

.filter-pill span {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.filter-pill:has(input:checked) span {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.search-result-item {
    padding: 1rem 1.5rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-title {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.3rem;
}

.search-result-path {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.search-result-snippet {
    font-size: 0.85rem;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-highlight {
    background: rgba(255, 213, 79, 0.4);
    font-weight: bold;
}

/* Graph Modal */
.graph-modal {
    width: 90vw;
    height: 90vh;
}

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

.graph-controls {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.control-group input[type="range"] {
    width: 100px;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--text-main);
}

/* === Responsive === */
@media (max-width: 768px) {
    .nav-brand { display: none; }
    .search-box span { display: none; }
    .search-box { width: auto; padding: 0.4rem; justify-content: center; background: transparent; border: none; }
    
    .sidebar {
        position: fixed;
        top: var(--nav-height);
        left: 0;
        height: calc(100vh - var(--nav-height));
        z-index: 900;
        transform: translateX(0); /* Override width logic for mobile */
        width: var(--sidebar-width);
    }
    
    .sidebar.closed {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        border: none;
    }
    
    .right-sidebar {
        position: fixed;
        top: var(--nav-height);
        right: 0;
        height: calc(100vh - var(--nav-height));
        z-index: 900;
        transform: translateX(0);
        width: var(--sidebar-width);
    }
    
    .right-sidebar.closed {
        transform: translateX(100%);
        width: var(--sidebar-width);
        border: none;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .graph-controls {
        display: none;
    }
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: transparent; 
}
::-webkit-scrollbar-thumb {
    background: #c1c1c1; 
    border-radius: 5px;
    border: 2px solid var(--bg-main);
}
::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8; 
}
[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #4b535d; 
}
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #6e7681; 
}
