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

:root {
    --sidebar-width: 300px;
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-sidebar: #111320;
    --bg-card: #1a1d2e;
    --bg-code: #1e2235;
    --text-primary: #e4e6f0;
    --text-secondary: #9397ad;
    --text-muted: #5f6380;
    --accent: #7c6bf5;
    --accent-light: #9b8afb;
    --accent-glow: rgba(124, 107, 245, 0.15);
    --border: #252840;
    --border-light: #2d3055;
    --success: #4ade80;
    --warning: #fbbf24;
    --danger: #f87171;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    display: flex;
    min-height: 100vh;
}

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

.sidebar-header {
    padding: 2rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.logo {
    margin-bottom: 0.75rem;
}

.logo-icon {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--accent-light);
    background: var(--accent-glow);
    padding: 0.3rem 0.75rem;
    border-radius: 6px;
    border: 1px solid rgba(124, 107, 245, 0.25);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 0.75rem;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Nav List */
.nav-list {
    list-style: none;
    padding: 1rem 0.75rem;
    flex: 1;
    overflow-y: auto;
}

.nav-list li {
    margin-bottom: 0.35rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-link:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border);
}

.nav-link.active {
    background: var(--accent-glow);
    color: var(--accent-light);
    border-color: rgba(124, 107, 245, 0.3);
}

.nav-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    flex-shrink: 0;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.nav-link.active .nav-icon {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.nav-title {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-desc {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link.active .nav-desc {
    color: rgba(155, 138, 251, 0.6);
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ===== Main Content ===== */
.content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    position: relative;
}

/* ===== Iframe for HTML content ===== */
.content-frame {
    width: 100%;
    height: 100vh;
    border: none;
    background: white;
}

.content-frame.hidden {
    display: none;
}

/* ===== Markdown content area ===== */
.content-inner {
    max-width: 860px;
    margin: 0 auto;
    padding: 3rem 2.5rem 5rem;
    height: 100vh;
    overflow-y: auto;
}

.content-inner.hidden {
    display: none;
}

/* ===== Loading ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 50vh;
    color: var(--text-muted);
    gap: 1rem;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Markdown Body ===== */
.markdown-body {
    animation: fadeIn 0.3s ease;
}

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

.markdown-body h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.markdown-body h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 3rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.markdown-body h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--accent-light);
}

.markdown-body p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

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

.markdown-body li {
    margin-bottom: 0.35rem;
}

.markdown-body code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.markdown-body :not(pre) > code {
    background: var(--bg-code);
    padding: 0.15em 0.45em;
    border-radius: 5px;
    border: 1px solid var(--border);
    color: var(--accent-light);
    font-size: 0.82em;
}

.markdown-body pre {
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.markdown-body pre code {
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 1.5rem 0;
    padding: 0.75rem 1.25rem;
    background: var(--accent-glow);
    border-radius: 0 8px 8px 0;
}

.markdown-body blockquote p {
    color: var(--text-primary);
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.markdown-body th,
.markdown-body td {
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    text-align: left;
}

.markdown-body th {
    background: var(--bg-card);
    font-weight: 600;
}

.markdown-body strong {
    color: var(--text-primary);
}

/* ===== Mobile Menu Toggle ===== */
.menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0;
}

.menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 50;
    backdrop-filter: blur(4px);
}

.overlay.active {
    display: block;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

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

    .sidebar.open {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
    }

    .content-inner {
        padding: 4rem 1.25rem 3rem;
    }

    .markdown-body h1 {
        font-size: 1.6rem;
    }

    .markdown-body h2 {
        font-size: 1.25rem;
    }

    .markdown-body pre {
        border-radius: 8px;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .content-inner {
        padding: 3.5rem 1rem 2rem;
    }
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: inherit;
    transition: all 0.2s ease;
    width: 100%;
    margin-bottom: 0.75rem;
}

.theme-toggle:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ===== Light Theme ===== */
[data-theme="light"] {
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-card: #f0f1f5;
    --bg-code: #f4f5f9;
    --text-primary: #1a1d2e;
    --text-secondary: #4a4f6a;
    --text-muted: #7a7f99;
    --accent: #6c5ce7;
    --accent-light: #5a4bd1;
    --accent-glow: rgba(108, 92, 231, 0.1);
    --border: #dfe1ea;
    --border-light: #c8cad6;
}

[data-theme="light"] body {
    background: var(--bg-primary);
}

[data-theme="light"] .sidebar {
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .nav-icon {
    background: #e8e9f0;
    border-color: #d5d7e2;
}

[data-theme="light"] .logo-icon {
    background: rgba(108, 92, 231, 0.1);
    border-color: rgba(108, 92, 231, 0.2);
    color: var(--accent);
}

[data-theme="light"] .markdown-body h1 {
    background: linear-gradient(135deg, #1a1d2e, #5a4bd1);
    -webkit-background-clip: text;
    background-clip: text;
}

[data-theme="light"] .markdown-body h3 {
    color: #5a4bd1;
}

[data-theme="light"] .markdown-body :not(pre) > code {
    background: #edeef4;
    border-color: #d5d7e2;
    color: #5a4bd1;
}

[data-theme="light"] .markdown-body pre {
    background: #f0f1f5;
    border-color: #dfe1ea;
}

[data-theme="light"] .markdown-body pre code {
    color: #2d3148;
}

[data-theme="light"] .markdown-body th {
    background: #e8e9f0;
}

[data-theme="light"] .menu-toggle {
    background: #fff;
    border-color: #dfe1ea;
}

[data-theme="light"] .menu-toggle span {
    background: #1a1d2e;
}

[data-theme="light"] .overlay {
    background: rgba(0, 0, 0, 0.3);
}

/* ===== Print Styles ===== */
@media print {
    .sidebar,
    .menu-toggle,
    .overlay {
        display: none !important;
    }

    .content {
        margin-left: 0 !important;
    }

    .content-frame {
        position: static;
        height: auto;
    }

    .content-inner {
        height: auto;
        overflow: visible;
        padding: 0;
    }
}
