/* Root Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-code: #1f2937;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --sidebar-width: 280px;
    --toc-width: 240px;
    --top-nav-height: 60px;
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    --bg-main: #0f172a;
    --bg-secondary: #1e293b;
    --bg-code: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.2s, color 0.2s;
}

/* Top Navigation */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--top-nav-height);
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    backdrop-filter: blur(10px);
}

.top-nav-container {
    height: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 100%;
}

.logo-link {
    text-decoration: none;
    transition: opacity 0.2s;
}

.logo-link:hover {
    opacity: 0.8;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.logo i {
    color: var(--primary-color);
    font-size: 28px;
}

.logo img {
    height: 32px;
    width: auto;
}

.top-nav-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 240px;
    padding: 8px 36px 8px 40px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-kbd {
    position: absolute;
    right: 8px;
    padding: 2px 6px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}

.theme-toggle {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    color: var(--primary-color);
}

.nav-link {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

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

/* Search Modal */
.search-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    padding: 100px 20px;
}

.search-modal.active {
    display: block;
}

.search-modal-content {
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-main);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    overflow: hidden;
}

.search-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.search-modal-header i {
    color: var(--text-muted);
}

.search-modal-header input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
}

.search-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.search-modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.search-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}

.search-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.search-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.search-result-item {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    display: block;
    color: var(--text-primary);
    transition: all 0.2s;
    margin-bottom: 4px;
}

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

.search-result-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Main Layout */
.docs-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
    margin-top: var(--top-nav-height);
    min-height: calc(100vh - var(--top-nav-height));
}

/* Left Sidebar */
.sidebar {
    position: sticky;
    top: var(--top-nav-height);
    height: calc(100vh - var(--top-nav-height));
    overflow-y: auto;
    padding: 24px 16px;
    background: var(--bg-main);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.nav-section-toggle:hover {
    background: var(--bg-secondary);
}

.nav-section-toggle .chevron {
    font-size: 12px;
    transition: transform 0.2s;
}

.nav-section.expanded .chevron {
    transform: rotate(90deg);
}

.nav-section-items {
    list-style: none;
    margin-top: 4px;
    padding-left: 20px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-section.expanded .nav-section-items {
    max-height: 500px;
}

.nav-section-items .nav-link {
    display: block;
    width: 100%;
    padding: 6px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    border: none;
}

.nav-section-items .nav-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.nav-section-items .nav-link.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    font-weight: 500;
}

.root-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    border: none;
}

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

.root-link.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    max-width: 900px;
    padding: 40px 60px;
    margin: 0 auto;
}

/* Typography & Prose */
.prose {
    color: var(--text-primary);
}

.prose h1 {
    font-size: 40px;
    font-weight: 700;
    margin-bottom: 24px;
    line-height: 1.2;
    color: var(--text-primary);
}

.prose h2 {
    font-size: 28px;
    font-weight: 600;
    margin-top: 48px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.prose h3 {
    font-size: 22px;
    font-weight: 600;
    margin-top: 32px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.prose h4 {
    font-size: 18px;
    font-weight: 600;
    margin-top: 24px;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.prose p {
    margin-bottom: 16px;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.prose a {
    color: var(--primary-color);
    text-decoration: none;
    transition: all 0.2s;
}

.prose a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.prose ul, .prose ol {
    margin-bottom: 16px;
    padding-left: 28px;
}

.prose li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.prose code {
    padding: 2px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    color: var(--primary-color);
}

.prose pre {
    margin: 24px 0;
    padding: 20px;
    background: var(--bg-code);
    border-radius: var(--radius-md);
    overflow-x: auto;
    border: 1px solid var(--border-color);
}

.prose pre code {
    padding: 0;
    background: transparent;
    border: none;
    color: #e5e7eb;
    font-size: 14px;
    line-height: 1.6;
}

.prose blockquote {
    margin: 24px 0;
    padding: 16px 20px;
    border-left: 4px solid var(--primary-color);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.prose blockquote p {
    margin: 0;
    color: var(--text-secondary);
}

.prose table {
    width: 100%;
    margin: 24px 0;
    border-collapse: collapse;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.prose th {
    background: var(--bg-secondary);
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.prose td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.prose tr:last-child td {
    border-bottom: none;
}

.prose img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 24px 0;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.prose img:hover {
    box-shadow: var(--shadow-md);
    transform: scale(1.01);
}

/* Right TOC */
.toc-sidebar {
    position: sticky;
    top: var(--top-nav-height);
    height: calc(100vh - var(--top-nav-height));
    padding: 24px 16px;
    background: var(--bg-main);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
}

.toc-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.toc-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toc-link {
    display: block;
    padding: 6px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    border-left: 2px solid transparent;
    transition: all 0.2s;
}

.toc-link:hover {
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.toc-link.active {
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 500;
}

.toc-link.level-3 {
    padding-left: 24px;
    font-size: 12px;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.sidebar-footer-contacts {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

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

.sidebar-footer-link i {
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-footer-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Footer */
.content-footer {
    margin-top: 80px;
    padding-top: 32px;
    border-top: 1px solid var(--border-color);
}

.footer-info {
    text-align: center;
}

.footer-info p {
    color: var(--text-muted);
    font-size: 13px;
}

/* Responsive */
@media (max-width: 1280px) {
    .docs-container {
        grid-template-columns: var(--sidebar-width) 1fr;
    }

    .toc-sidebar {
        display: none;
    }
}

@media (max-width: 768px) {
    .docs-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        padding: 24px 20px;
    }

    .search-container {
        display: none;
    }
}

/* Image Modal/Lightbox */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    padding: 40px;
    animation: fadeIn 0.2s ease;
}

.image-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.image-modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    animation: zoomIn 0.2s ease;
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.image-modal-content img {
    max-width: 100%;
    max-height: 90vh;
    width: auto;
    height: auto;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    cursor: default;
}

.image-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.image-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

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