/* ==========================================================================
   1. VARIABLES & RESET
   ========================================================================== */
:root {
    --primary-color: #4A47A3;
    --primary-dark: #3B3882;
    --primary-light: #f0f0f8;
    --text-color: #2D3748;
    --text-light: #718096;
    --background-color: #FFFFFF;
    --surface-color: #F8F9FA;
    --border-color: #E2E8F0;
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    --radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary-color: #8B88E5;
    --primary-dark: #6C6AD0;
    --primary-light: #2c2a4a;
    --text-color: #E2E8F0;
    --text-light: #A0AEC0;
    --background-color: #1A202C;
    --surface-color: #2D3748;
    --border-color: #4A5568;
}

*, *::before, *::after { box-sizing: border-box; }
body { 
    font-family: var(--font-sans); 
    line-height: 1.7; 
    margin: 0; 
    background-color: var(--background-color); 
    color: var(--text-color); 
    transition: background-color 0.3s, color 0.3s;
}
html { scroll-behavior: smooth; }

/* ==========================================================================
   2. HEADER
   ========================================================================== */
.header {
    background-color: var(--background-color);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s, border-color 0.3s;
}
.logo { display: flex; align-items: center; gap: 1rem; }
.logo-img { width: 40px; height: 40px; }
.logo h1 { font-size: 1.25rem; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 1.5rem; }
.btn {
    border: 1px solid var(--border-color); padding: 0.5rem 1.25rem; border-radius: 6px;
    font-size: 0.9rem; font-weight: 500; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; transition: all 0.2s; text-decoration: none;
    background-color: var(--surface-color); color: var(--text-color);
}
.btn:hover { background-color: var(--primary-light); border-color: var(--primary-color); }
.mobile-nav-toggle {
    display: none;
    background: none; border: none; font-size: 1.5rem; color: var(--text-color); cursor: pointer;
}

/* ==========================================================================
   3. THEME SWITCHER
   ========================================================================== */
.theme-switcher { display: flex; align-items: center; gap: 0.5rem; color: var(--text-light); }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 22px;
}
.slider:before {
    position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
    background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(18px); }

/* ==========================================================================
   4. LAYOUT & SIDEBAR
   ========================================================================== */
.container {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}
.sidebar {
    position: sticky;
    top: 93px; /* Header height + padding */
    height: calc(100vh - 110px);
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}
#search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-size: 0.9rem;
}
.sidebar-nav {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-right: 0.5rem; /* For scrollbar */
}
.nav-group .nav-title {
    font-size: 0.9rem; font-weight: 700; color: var(--text-light);
    margin: 0 0 0.75rem 0; text-transform: uppercase; letter-spacing: 0.05em;
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-link {
    display: block; text-decoration: none; color: var(--text-color);
    padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 0.25rem;
    font-size: 0.95rem; border-left: 3px solid transparent;
    transition: background-color 0.2s, color 0.2s, border-left-color 0.2s;
}
.nav-link:hover { background-color: var(--primary-light); color: var(--primary-dark); }
.nav-link.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    font-weight: 700;
    border-left-color: var(--primary-color);
}

/* ==========================================================================
   5. CONTENT AREA
   ========================================================================== */
.content { min-width: 0; }
.content-page { animation: fadeIn 0.5s ease; }
.content h1 { font-size: 2.5rem; font-weight: 700; margin: 0 0 1.5rem 0; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); }
.content h2 { font-size: 1.75rem; font-weight: 700; margin: 2.5rem 0 1rem; }
.content h3 { font-size: 1.25rem; font-weight: 700; margin: 2rem 0 1rem; }
.content p, .content ul li, .content ol li { 
    margin-bottom: 1.25rem; 
    line-height: 1.8; 
    max-width: 75ch; 
}
.content a { color: var(--primary-color); font-weight: 500; text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content code {
    font-family: var(--font-mono); background-color: var(--primary-light); color: var(--primary-dark);
    padding: 0.2em 0.4em; border-radius: 4px; font-size: 0.9em;
}
.content pre {
    background-color: var(--surface-color); border: 1px solid var(--border-color);
    padding: 1.5rem; border-radius: var(--radius); overflow-x: auto;
    box-shadow: var(--shadow-sm); position: relative;
}
.content pre code { background: none; padding: 0; }
.copy-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background-color: var(--border-color);
    color: var(--text-light);
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.2s;
}
.content pre:hover .copy-btn { opacity: 1; }
.content blockquote {
    border-left: 4px solid var(--primary-color); padding: 1rem 1.5rem;
    margin: 1.5rem 0; background-color: var(--primary-light);
    font-style: italic;
}
.content ul, .content ol { padding-left: 1.5rem; margin-bottom: 1.25rem; }

/* ==========================================================================
   6. FOOTER
   ========================================================================== */
.footer {
    text-align: center; padding: 2rem; border-top: 1px solid var(--border-color);
    font-size: 0.9rem; color: var(--text-light);
}
.footer a { color: var(--primary-color); text-decoration: none; font-weight: 500; }
.footer a:hover { text-decoration: underline; }

/* ==========================================================================
   7. RESPONSIVENESS & ANIMATIONS
   ========================================================================== */
@media (max-width: 1024px) {
    .container { grid-template-columns: 240px 1fr; padding: 1.5rem; }
    .sidebar { top: 85px; height: calc(100vh - 100px); }
}

@media (max-width: 768px) {
    .container { grid-template-columns: 1fr; gap: 0; }
    .mobile-nav-toggle { display: block; }
    .sidebar { 
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 280px;
        background-color: var(--background-color);
        box-shadow: var(--shadow-md);
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 200;
        padding: 1.5rem;
        height: 100vh;
    }
    .sidebar.open { transform: translateX(0); }
    .header { padding: 1rem; }
    .header h1 { font-size: 1.1rem; }
    .btn.btn-secondary { display: none; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}