:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #f3f4f6;
    --border-primary: #d0d7de;
    --border-secondary: #e5e7eb;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-tertiary: #9ca3af;
    --link-color: #0969da;
    --link-hover: #0550ae;
    --sidebar-width: 280px;
    --toc-width: 260px;
    --header-height: 56px;
    --transition-speed: 0.2s;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --collapsed-width: 0px;
}

/* Dark Theme */
body[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #010409;
    --bg-tertiary: #161b22;
    --border-primary: #30363d;
    --border-secondary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #7d8590;
    --text-tertiary: #6e7681;
    --link-color: #2f81f7;
    --link-hover: #539bf5;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-secondary);
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

summary {
  cursor: pointer;
}

/* Главное меню */
.main-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 20px;
    max-width: 1920px;
    margin: 0 auto;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    overflow: hidden;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.current-file-path {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 600px;
}

.current-file-path a {
    color: var(--text-secondary);
    text-decoration: none;
}

.current-file-path a:hover {
    color: var(--link-color);
}

.btn-header-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
}

.btn-header-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Layout */
.layout {
    display: flex;
    min-height: calc(100vh - var(--header-height));
    max-width: 1920px;
    margin: 0 auto;
    position: relative;
}

/* Левая часть: сайдбар */
.sidebar-left-container {
    flex-shrink: 0;
    width: var(--sidebar-width);
    transition: width var(--transition-speed) ease;
    position: relative;
    display: flex;
}

.layout.sidebar-left-collapsed .sidebar-left-container {
    width: 0;
}

/* Центральная область */
.main-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-primary);
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
}

/* Правая часть: сайдбар */
.sidebar-right-container {
    flex-shrink: 0;
    width: var(--toc-width);
    transition: width var(--transition-speed) ease;
    position: relative;
    display: flex;
}

.layout.sidebar-right-collapsed .sidebar-right-container {
    width: 0;
}

/* Sidebar общие стили */
.sidebar {
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    transition: transform var(--transition-speed) ease, opacity var(--transition-speed) ease;
    width: 100%;
}

.sidebar-left {
    border-right: 1px solid var(--border-primary);
}

.sidebar.hidden {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.sidebar-right {
    border-left: 1px solid var(--border-primary);
}

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

.sidebar-collapsed {
    display: none;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    min-height: 60px;
}

.repo-info {
    flex: 1;
}

.repo-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.repo-description {
    font-size: 12px;
    color: var(--text-secondary);
}

.toc-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-body::-webkit-scrollbar {
    width: 8px;
}

.sidebar-body::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-body::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 4px;
}

.sidebar-body::-webkit-scrollbar-thumb:hover {
    background: var(--border-primary);
}

/* Resizable сайдбары */
.sidebar-left-container,
.sidebar-right-container {
    position: relative;
}

.sidebar-resizer {
    position: absolute;
    top: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    transition: background var(--transition-speed) ease;
    z-index: 10;
}

#sidebarLeftResizer {
    right: 0;
}

#sidebarRightResizer {
    left: 0;
}

.sidebar-resizer:hover,
.sidebar-resizer.resizing {
    background: var(--link-color);
}

/* File Tree */
.file-tree {
    padding: 12px 8px;
}

.tree-item {
    margin: 2px 0;
}

.tree-node {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    transition: background var(--transition-speed) ease;
    user-select: none;
}

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

.tree-node.active {
    background: var(--link-color);
    color: #ffffff;
    font-weight: 500;
}

body[data-theme="light"] .tree-node.active {
    background: #ddf4ff;
    color: var(--link-color);
}

.tree-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.tree-icon svg {
    transition: transform var(--transition-speed) ease;
}

.tree-node.collapsed .tree-icon svg {
    transform: rotate(-90deg);
}

.tree-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-label a {
    color: inherit;
    text-decoration: none;
}

.tree-children {
    margin-left: 16px;
    overflow: hidden;
    transition: max-height var(--transition-speed) ease;
}

.tree-children.collapsed {
    max-height: 0;
}

/* Document Content */
.document-content {
    flex: 1;
    padding: 32px 64px;
    max-width: 1080px;
    margin: 0 auto;
    width: 100%;
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-icon {
    margin-bottom: 24px;
    opacity: 0.5;
}

.welcome-screen h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-screen p {
    font-size: 14px;
}

/* Table of Contents */
.table-of-contents {
    padding: 16px 12px;
}

.toc-empty {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    padding: 32px 16px;
}

.toc-item {
    margin: 4px 0;
}

.toc-link {
    display: block;
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
    transition: background var(--transition-speed) ease, color var(--transition-speed) ease;
}

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

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

.toc-link[data-level="1"] {
    font-weight: 500;
    padding-left: 8px;
}

.toc-link[data-level="2"] {
    padding-left: 20px;
}

.toc-link[data-level="3"] {
    padding-left: 32px;
}

.toc-link[data-level="4"] {
    padding-left: 44px;
}

.toc-link[data-level="5"],
.toc-link[data-level="6"] {
    padding-left: 56px;
    font-size: 12px;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

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

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

.loading-state p {
    font-size: 14px;
}

/* Error State */
.error-state {
    padding: 24px;
    margin: 16px;
    background: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 8px;
    color: #c53030;
}

body[data-theme="dark"] .error-state {
    background: #2d1515;
    border-color: #8b3a3a;
    color: #ffa8a8;
}

.error-state h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.error-state p {
    font-size: 14px;
}

/* Floating Buttons */
.floating-buttons {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 900;
}

.btn-floating {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-speed) ease;
}

.btn-floating:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: scale(1.05);
}

.btn-floating#btnScrollTop {
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
}

.btn-floating#btnScrollTop.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Markdown Content Styles */
.markdown-body {
    font-size: 16px;
    line-height: 1.6;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    scroll-margin-top: calc(var(--header-height) + 20px);
}

.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-secondary);
}

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-secondary);
}

.markdown-body h3 {
    font-size: 1.25em;
}

.markdown-body h4 {
    font-size: 1em;
}

.markdown-body h5 {
    font-size: 0.875em;
}

.markdown-body h6 {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.markdown-body p {
    margin-top: 0;
    margin-bottom: 16px;
}

.markdown-body a {
    color: var(--link-color);
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body strong {
    font-weight: 600;
}

.markdown-body em {
    font-style: italic;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    background-color: rgba(175,184,193,0.2);
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
}

body[data-theme="dark"] .markdown-body code {
    background-color: rgba(110,118,129,0.4);
}

.markdown-body pre {
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background-color: var(--bg-secondary);
    border-radius: 6px;
    margin-bottom: 16px;
}

.markdown-body pre code {
    display: inline;
    padding: 0;
    margin: 0;
    overflow: visible;
    line-height: inherit;
    background-color: transparent;
    border: 0;
}

.markdown-body ul,
.markdown-body ol {
    margin-top: 0;
    margin-bottom: 16px;
    padding-left: 2em;
}

.markdown-body li {
    margin-top: 0.25em;
}

.markdown-body blockquote {
    margin: 0 0 16px 0;
    padding: 0 1em;
    color: var(--text-secondary);
    border-left: 0.25em solid var(--border-primary);
}

.markdown-body table {
    border-spacing: 0;
    border-collapse: collapse;
    margin-bottom: 16px;
    width: 100%;
    overflow: auto;
}

.markdown-body table th {
    font-weight: 600;
    padding: 6px 13px;
    border: 1px solid var(--border-primary);
    background-color: var(--bg-secondary);
}

.markdown-body table td {
    padding: 6px 13px;
    border: 1px solid var(--border-primary);
}

.markdown-body table tr {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-primary);
}

.markdown-body table tr:nth-child(2n) {
    background-color: var(--bg-secondary);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 16px 0;
}

.markdown-body hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background-color: var(--border-secondary);
    border: 0;
}

/* Mermaid diagrams */
.mermaid {
    text-align: center;
    margin: 24px 0;
}

/* MathJax */
.MathJax {
    font-size: 1em !important;
}

/* Overlay для мобильных */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.overlay.visible {
    display: block;
    opacity: 1;
}

/* Mermaid Controls */
.mermaid-wrapper {
    position: relative;
    margin: 24px 0;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

.mermaid-wrapper:fullscreen {
    background: var(--bg-primary);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.mermaid-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}

body[data-theme="dark"] .mermaid-controls {
    background: rgba(13, 17, 23, 0.95);
}

.mermaid-wrapper:fullscreen .mermaid-controls {
    position: fixed;
    top: 20px;
    right: 20px;
}

.mermaid-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    padding: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed) ease;
}

.mermaid-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.mermaid-container {
    overflow: auto;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

.mermaid-wrapper:fullscreen .mermaid-container {
    flex: 1;
    min-height: auto;
    height: 100%;
    width: 100%;
}

.mermaid-content {
    transition: transform 0.1s ease;
    transform-origin: center center;
    cursor: grab;
    user-select: none;
}

.mermaid-content:active {
    cursor: grabbing;
}

.mermaid-content svg {
    max-width: 100%;
    height: auto;
    display: block;
}

.mermaid-wrapper:fullscreen .mermaid-content svg {
    max-width: none;
    max-height: none;
}

/* Адаптивность для планшетов */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
        --toc-width: 220px;
    }
    
    .document-content {
        padding: 24px 32px;
    }
    
    .current-file-path {
        max-width: 400px;
    }
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    .header-center {
        display: none;
    }
    
    .layout {
        display: block;
    }
    
    .sidebar-left-container,
    .sidebar-right-container {
        width: 100% !important;
    }
    
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        max-width: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        height: calc(100vh - var(--header-height));
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: none;
    }
    
    .sidebar-right {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }
    
    .sidebar-right.mobile-open {
        transform: translateX(0);
    }
    
    .document-content {
        padding: 24px 20px;
    }
    
    .sidebar-resizer {
        display: none;
    }
    
    .floating-buttons {
        bottom: 16px;
        right: 16px;
    }
    
    .btn-floating {
        width: 44px;
        height: 44px;
    }
}

/* Печать */
@media print {
    .main-header,
    .sidebar,
    .sidebar-collapsed,
    .sidebar-resizer,
    .floating-buttons {
        display: none !important;
    }
    
    .layout {
        display: block !important;
    }
    
    .main-content {
        max-width: 100%;
    }
    
    .document-content {
        max-width: 100%;
        padding: 0;
    }
}

.sidebar-left-collapsed .sidebar-left-container, .sidebar-right-collapsed .sidebar-right-container{
    width: 0!important;
}

/* Mermaid Wrapper Resizable */
.mermaid-wrapper {
    position: relative;
    margin: 24px 0;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    overflow: auto;
    background: var(--bg-secondary);
    resize: both;
    min-width: 400px;
    min-height: 300px;
    max-width: 100%;
}

.mermaid-wrapper:fullscreen {
    background: var(--bg-primary);
    padding: 20px;
    display: flex;
    flex-direction: column;
    resize: none;
    max-width: none;
    max-height: none;
}
