:root {
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #e0e0e0;
    --sidebar-hover: #16213e;
    --sidebar-active: #0f3460;
    --accent: #e94560;
    --bg: #ffffff;
    --text: #333333;
    --text-muted: #666666;
    --border: #e0e0e0;
    --card-bg: #f8f9fa;
    --code-bg: #f4f4f4;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: grid;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

body.two-pane {
    grid-template-columns: 312px 1fr;
}

body.three-pane {
    grid-template-columns: 312px 320px 1fr;
}

/* When the section drawer is open, it becomes the 4th grid column. */
body.two-pane.drawer-open {
    grid-template-columns: 312px minmax(0, 1fr) 400px;
}

body.three-pane.drawer-open {
    grid-template-columns: 312px 320px minmax(0, 1fr) 400px;
}

/* ── Sidebar ──────────────────────────────────────────── */

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 0;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1.3em;
    color: #fff;
    margin: 0;
}

.sidebar-subtitle {
    font-size: 0.85em;
    color: var(--text-muted);
    opacity: 0.7;
}

/* ── Tree navigation (collapsible <details>) ────────────── */

.nav-tree,
.nav-tree ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-tree {
    padding: 10px 0;
}

.nav-tree details > summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 20px 8px 36px;
    color: var(--sidebar-text);
    font-size: 0.95em;
    user-select: none;
    position: relative;
    transition: background 0.2s;
}

.nav-tree details > summary::-webkit-details-marker { display: none; }

.nav-tree details > summary::before {
    content: "▸";
    position: absolute;
    left: 20px;
    top: 8px;
    font-size: 0.75em;
    color: var(--text-muted);
    transition: transform 0.15s ease;
    display: inline-block;
}

.nav-tree details[open] > summary::before {
    transform: rotate(90deg);
}

.nav-tree details > summary:hover {
    background: var(--sidebar-hover);
}

.nav-tree .nav-count {
    color: var(--text-muted);
    font-size: 0.82em;
    margin-left: 4px;
}

.nav-tree .nav-link {
    display: block;
    /* Reserve 3px on the left for the active-state border so width/position stays
       identical between active and inactive states regardless of nesting depth. */
    border-left: 3px solid transparent;
    padding: 6px 20px 6px 33px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92em;
    transition: background 0.2s;
}

.nav-tree .nav-link:hover {
    background: var(--sidebar-hover);
}

.nav-tree .nav-link.active {
    background: var(--sidebar-active);
    border-left-color: var(--accent);
    color: #fff;
}

/* Nested levels: each <ul> inside details shifts content right.
   Padding values are 3px lower for .nav-link to compensate for the 3px transparent border. */
.nav-tree details ul .nav-link { padding-left: 49px; }
.nav-tree details ul details > summary { padding-left: 52px; }
.nav-tree details ul details > summary::before { left: 36px; }

.nav-tree details ul details ul .nav-link { padding-left: 65px; }
.nav-tree details ul details ul details > summary { padding-left: 68px; }
.nav-tree details ul details ul details > summary::before { left: 52px; }

/* Эпик-узел в sidebar: ссылка на overview в summary (с обёрткой details для раскрытия). */
.nav-epic > details > summary {
    display: flex;
    align-items: center;
}
.nav-epic-link {
    color: var(--sidebar-text) !important;
    text-decoration: none;
    flex: 1;
}
.nav-epic-link.active {
    color: #fff !important;
    font-weight: 600;
}

/* Kind-группа под эпиком (UseCases, ADR, ApiContract, …). */
.nav-kind-group > details > summary {
    color: var(--text-muted);
    font-size: 0.88em;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* Плоский kind-узел в sidebar: summary содержит ссылку на kind-index страницу. */
.nav-kind-link {
    color: var(--sidebar-text) !important;
    text-decoration: none;
    flex: 1;
}
.nav-kind-link.active {
    color: #fff !important;
    font-weight: 600;
}
.nav-tree > li > details > summary {
    display: flex;
    align-items: center;
}

/* Merged-ячейка «Эпик» в kind-index таблице (rowspan). */
.document-list-table td.epic-cell {
    vertical-align: top;
    border-right: 1px solid var(--border);
    font-weight: 500;
}

/* Document-list-table: компактный табличный вид для index-страниц вместо card-grid.
   Колонки: Название (link), Эпик (опц., link), Статус, Версия. */
.document-list-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}
.document-list-table th,
.document-list-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.document-list-table th {
    background: var(--card-bg);
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.document-list-table td.muted {
    color: var(--text-muted);
}
.document-list-table tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

.empty-list {
    color: var(--text-muted);
    font-style: italic;
}

/* Epic-index page: prominent-ссылка на overview-документ эпика. */
.epic-index-overview-link {
    margin: 8px 0 24px;
}
.epic-index-overview-link a {
    display: inline-block;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff !important;
    border-radius: 4px;
    text-decoration: none !important;
    font-weight: 500;
}
.epic-index-overview-link a:hover {
    background: #0f3460;
}

/* Orphan-fallback папка: документы без kind→folder привязки. Видимый warning-stripe,
   чтобы было сразу понятно «починить» — добавить kind-marker или соответствующий
   IFolderForKind<...>-класс. */
.nav-group-warning > details > summary {
    color: #d97706;
    font-weight: 600;
}
.nav-group-warning > details > ul > .nav-leaf > .nav-link {
    color: #d97706;
}
.nav-group-warning > details {
    border-left: 3px solid #d97706;
    background: rgba(217, 119, 6, 0.06);
}

/* Top-level "Главная" — no chevron. Padding -3px to align with bordered links. */
.nav-tree > li.nav-leaf > .nav-link {
    padding-left: 33px;
}


/* ── Middle list pane ──────────────────────────────────── */

.middle {
    background: #f8f9fa;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

.middle-header {
    padding: 14px 18px;
    font-weight: 600;
    font-size: 0.95em;
    border-bottom: 1px solid var(--border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Middle-pane filter input (used in glossary middle list). */
.middle-filter {
    padding: 8px 14px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 47px;
    z-index: 1;
}
.middle-filter-input {
    width: 100%;
    padding: 6px 10px;
    font-size: 0.88em;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--text);
}
.middle-filter-input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}
.middle-item.is-filtered { display: none; }

.middle-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.middle-item {
    border-bottom: 1px solid var(--border);
}

.middle-item a {
    display: block;
    padding: 10px 18px;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.middle-item a:hover {
    background: #eef2f7;
}

.middle-item.active a {
    background: #fff;
    border-left-color: var(--accent);
}

.middle-code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.78em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.middle-caption {
    font-size: 0.92em;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.middle-item.active .middle-caption {
    color: var(--text);
    font-weight: 500;
}

/* ── Main Content ─────────────────────────────────────── */

.content {
    max-width: 1200px;
    padding: 32px 48px;
    margin: 0 auto;
    width: 100%;
    min-width: 0;
}

.content .count {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.7em;
}

.content .hint {
    color: var(--text-muted);
    font-style: italic;
    padding: 12px 16px;
    background: var(--card-bg);
    border-left: 3px solid var(--border);
    border-radius: 4px;
    margin: 16px 0;
}

/* ── Граф связей (per-epic) ───────────────────────────── */
.epic-graph {
    margin: 24px 0;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.epic-graph > h2 {
    margin-top: 0;
}
.epic-graph .mermaid {
    background: none;
    border: none;
    overflow-x: auto;
}

/* ── Breadcrumbs ──────────────────────────────────────── */

.breadcrumbs {
    margin-bottom: 16px;
    font-size: 0.88em;
    color: var(--text-muted);
}

.breadcrumbs ol {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Альтернативные пути возврата (страница достижима из нескольких разделов) —
   каждый трейл — своя <ol>-строка. */
.breadcrumbs ol + ol {
    margin-top: 4px;
}

.breadcrumbs li {
    display: inline-flex;
    align-items: center;
}

.breadcrumbs li + li::before {
    content: "/";
    margin-right: 8px;
    color: var(--text-muted);
    opacity: 0.5;
}

.breadcrumbs a {
    color: var(--text-muted);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--text);
    text-decoration: underline;
}

.breadcrumbs li[aria-current="page"] {
    color: var(--text);
    font-weight: 500;
}

/* ── Sidebar toggle button ────────────────────────────── */

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    width: 40px;
    height: 40px;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 1.4em;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ── Sidebar search ────────────────────────────────────── */

.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

#site-search {
    width: 100%;
    padding: 6px 10px;
    font-size: 0.9em;
    background: rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    outline: none;
}

#site-search::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

#site-search:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent);
}

#site-search-results {
    display: none;
    list-style: none;
    padding: 4px 0;
    margin: 4px 0 0;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    position: absolute;
    top: 100%;
    left: 16px;
    right: 16px;
    max-height: 360px;
    overflow-y: auto;
    z-index: 99;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#site-search-results.visible {
    display: block;
}

#site-search-results li a {
    display: block;
    padding: 6px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.88em;
    border-bottom: 1px solid var(--border);
}

#site-search-results li:last-child a {
    border-bottom: none;
}

#site-search-results li a:hover {
    background: var(--card-bg);
}

#site-search-results .search-kind {
    display: inline-block;
    min-width: 70px;
    padding: 1px 6px;
    margin-right: 6px;
    font-size: 0.75em;
    color: var(--text-muted);
    background: var(--code-bg);
    border-radius: 3px;
    text-transform: uppercase;
}

#site-search-results .search-empty {
    padding: 8px 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Table filter ──────────────────────────────────────── */

.table-filter {
    width: 100%;
    max-width: 400px;
    padding: 6px 10px;
    font-size: 0.9em;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin: 8px 0 12px;
    outline: none;
}

.table-filter:focus {
    border-color: var(--accent);
}

/* ── Reference kind tag in "where used" lists ──────────── */

.ref-kind {
    display: inline-block;
    min-width: 80px;
    padding: 1px 6px;
    margin-right: 6px;
    font-size: 0.75em;
    color: var(--text-muted);
    background: var(--code-bg);
    border-radius: 3px;
    text-transform: uppercase;
}

.content h1 {
    font-size: 2em;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.content h2 {
    font-size: 1.6em;
    font-weight: 700;
    margin: 28px 0 14px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.content h3 {
    font-size: 1.3em;
    font-weight: 700;
    margin: 22px 0 10px;
}

.content h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 18px 0 8px;
}

.content h5 {
    font-size: 1em;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text-muted);
}

.content h6 {
    font-size: 0.9em;
    font-weight: 600;
    margin: 12px 0 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.content p {
    margin: 8px 0;
}

.content ul, .content ol {
    margin: 8px 0 8px 24px;
}

.content blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 16px;
    margin: 12px 0;
    background: var(--card-bg);
    color: var(--text-muted);
}

.content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.content pre {
    background: var(--code-bg);
    padding: 12px 16px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 12px 0;
}

.content a {
    color: #0f3460;
    text-decoration: underline;
}

.content a:hover {
    text-decoration: underline;
    color: var(--accent);
}

/* Markdown-таблицы внутри прозы: Markdig эмитит чистый <table> без классов, ему нужно
   собственное оформление. Похоже на .spec-table, но не привязано к классу. */
.content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    border: 1px solid var(--border);
}

.content table th,
.content table td {
    padding: 8px 12px;
    text-align: left;
    border: 1px solid var(--border);
    vertical-align: top;
}

.content table th {
    background: var(--card-bg);
    font-weight: 600;
}

.content table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.02);
}

/* Inline-chunk: position: relative для абсолютно-позиционированных контролов. */
.document-inline-chunk {
    position: relative;
    margin-bottom: 24px;
    padding-top: 4px;
}

/* Контролы chunk-а (share + source) — справа сверху, видимы только при hover.
   Так раздел не «шумит» постоянно иконками, но контролы доступны когда нужны. */
.chunk-controls {
    position: absolute;
    top: 4px;
    right: 0;
    display: flex;
    gap: 12px;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
}

.document-inline-chunk:hover .chunk-controls,
.chunk-controls:focus-within {
    opacity: 1;
}

.chunk-share,
.chunk-source-link {
    font-size: 0.85em;
    color: var(--text-muted) !important;
    text-decoration: none !important;
    white-space: nowrap;
}

.chunk-share:hover,
.chunk-source-link:hover {
    color: var(--accent) !important;
}

/* Подсветка «скопировано» на share-кнопке после клика. */
.chunk-share.copied {
    color: #0a7d29 !important;
}

/* TOC entries: ступенчатый отступ по depth, чтобы h3/h4 визуально подчинялись h2.
   Маркеры списков убираем — нумерация уже есть в тексте каждого пункта ("24.6.1. ..."),
   bullets/circles только зашумляют. */
.document-inline-toc ol,
.document-inline-toc ul { list-style: none; padding-left: 0; }
.document-inline-toc li { list-style: none; }
.document-inline-toc li.toc-h2 { margin-left: 0; }
.document-inline-toc li.toc-h3 { margin-left: 18px; }
.document-inline-toc li.toc-h4 { margin-left: 36px; }

/* ── Tables ───────────────────────────────────────────── */

.spec-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.spec-table th, .spec-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.spec-table th {
    background: var(--card-bg);
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.spec-table tr:hover {
    background: #f0f4ff;
}

/* Таблица экранов: колонки связей (use cases / endpoints / эпики) компактнее, выровнены вверх. */
.page-table td {
    vertical-align: top;
}
.page-table td:not(:first-child) {
    font-size: 0.9em;
}
.page-table .muted {
    color: var(--text-muted);
}

/* ── Status Badges ────────────────────────────────────── */

.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
}

.status-accepted {
    background: #d4edda;
    color: #155724;
}

.status-proposed {
    background: #fff3cd;
    color: #856404;
}

.status-superseded {
    background: #f8d7da;
    color: #721c24;
}

/* ── ADR Cards ────────────────────────────────────────── */

.adr-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 20px;
    margin: 12px 0;
}

.adr-card h2 {
    margin: 0 0 8px;
    border: none;
}

.adr-card .date {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-left: 8px;
}

/* ── Document cards (summary page) ────────────────────── */

.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin: 12px 0 24px;
}

.document-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 20px;
}

.document-card h3 {
    margin: 0 0 8px;
}

.document-card h3 a {
    text-decoration: none;
}

.document-card h3 a:hover {
    text-decoration: underline;
}

.document-card .document-meta {
    font-size: 0.85em;
    color: var(--text-muted);
    margin: 4px 0 10px;
}

.document-card .document-meta code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
}

/* ── Component Cards ──────────────────────────────────── */

.component-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.component-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 20px;
}

.component-card h3 {
    margin: 0 0 4px;
}

.component-card .tech {
    font-size: 0.85em;
    color: var(--text-muted);
    margin: 0 0 8px;
    font-family: "SFMono-Regular", Consolas, monospace;
}

/* ── Description ──────────────────────────────────────── */

.description {
    margin: 12px 0;
}

/* ── Vision ───────────────────────────────────────────── */

.document-overview {
    line-height: 1.7;
}

.document-meta {
    margin: 4px 0 16px;
    font-size: 0.88em;
    color: var(--text-muted);
}

.document-meta code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Kind badge — coloured chip identifying document subtype on its page. */
.kind-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 3px;
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 4px;
    vertical-align: middle;
    color: #fff;
    /* Дефолтный фон, чтобы любой неизвестный kind был виден (белый текст на сером). */
    background: #6b7280;
}
.kind-badge.kind-vision { background: #6f42c1; }
.kind-badge.kind-adr { background: #d97706; }
.kind-badge.kind-epic { background: #2563eb; }
.kind-badge.kind-usecase { background: #059669; }
.kind-badge.kind-fr { background: #b45309; }
.kind-badge.kind-domainentity { background: #0891b2; }
.kind-badge.kind-boundedcontext { background: #7c3aed; }
.kind-badge.kind-boundedcontextmodule { background: #8b5cf6; }
.kind-badge.kind-domainservice { background: #0ea5e9; }
.kind-badge.kind-applicationservice { background: #14b8a6; }
.kind-badge.kind-doc { background: #6b7280; }
.kind-badge.kind-apicontract { background: #ea580c; }
.kind-badge.kind-handler { background: #16a34a; }
.kind-badge.kind-uispec { background: #db2777; }
.kind-badge.kind-statemachine { background: #9333ea; }
.kind-badge.kind-infrastructure { background: #475569; }
.kind-badge.kind-module { background: #0d9488; }
.kind-badge.kind-page { background: #ca8a04; }
.kind-badge.kind-application { background: #4338ca; }
.kind-badge.kind-uicomponent { background: #c026d3; }
.kind-badge.kind-changerequest { background: #e11d48; }
.kind-badge.kind-enum { background: #7e22ce; }
.kind-badge.kind-term { background: #0369a1; }
.kind-badge.kind-nfr { background: #be123c; }

/* Подсветка значения enum при переходе по deep-link (RefToEnum). */
.enum-table tr:target {
    background: var(--accent-soft, #fef3c7);
}
.enum-table tr:target td:first-child code {
    outline: 2px solid var(--accent, #d97706);
}

/* Kind-specific metadata block (PrimaryActor, Supersedes, ...). */
.document-kind-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 10px 14px;
    margin: 12px 0 16px;
    font-size: 0.92em;
}
.document-kind-meta dt {
    color: var(--text-muted);
    font-size: 0.85em;
    align-self: center;
}
.document-kind-meta dd {
    margin: 0;
    align-self: center;
}

.document-inline-toc {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 24px;
    margin: 16px 0 24px;
}

.document-inline-toc h2 {
    margin: 0 0 8px;
    border: none;
    font-size: 1.05em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.document-inline-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.document-inline-toc ol ol {
    margin-left: 20px;
}

.document-inline-toc li {
    padding: 3px 0;
}

.document-inline-toc a {
    text-decoration: none;
}

.document-inline-toc a:hover {
    text-decoration: underline;
}

.document-inline-toc .toc-num {
    display: inline-block;
    min-width: 36px;
    font-family: "SFMono-Regular", Consolas, monospace;
    color: var(--text-muted);
    margin-right: 6px;
}

.document-section {
    margin: 24px 0;
    scroll-margin-top: 20px;
}

.document-section .section-num {
    color: var(--text-muted);
    font-family: "SFMono-Regular", Consolas, monospace;
    margin-right: 8px;
    font-weight: normal;
}

.document-body {
    margin: 8px 0;
}

.document-comments {
    margin-top: 12px;
    background: var(--card-bg);
    border-left: 3px solid var(--border);
    padding: 8px 12px;
    border-radius: 4px;
}

.document-comments summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Vision TOC: single-line items (number + title side by side, no wrap). */

.middle-list.document-toc .middle-item a {
    display: flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
}

.middle-list.document-toc .middle-code {
    flex: 0 0 auto;
    margin-bottom: 0;
}

.middle-list.document-toc .middle-caption {
    display: inline;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.middle-list.document-toc .middle-item.toc-depth-1 a { font-weight: 500; }
.middle-list.document-toc .middle-item.toc-depth-2 a { padding-left: 30px; }
.middle-list.document-toc .middle-item.toc-depth-3 a { padding-left: 42px; }
.middle-list.document-toc .middle-item.toc-depth-4 a { padding-left: 54px; }

/* Show typenames toggle (off by default). */
.document-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    margin-bottom: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.88em;
    color: var(--text-muted);
}

.document-toolbar label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.toolbar-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--text);
}
.toolbar-btn:hover {
    border-color: var(--accent);
}

.section-typename {
    display: none;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.72em;
    color: var(--text-muted);
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
    vertical-align: middle;
}

body.show-typenames .section-typename { display: inline-block; }

/* Section heading icons (anchor, info, comments). */
.section-actions {
    display: inline-flex;
    gap: 4px;
    margin-left: 10px;
    vertical-align: middle;
    opacity: 0;
    transition: opacity 0.15s;
}

.document-section:hover > h2 .section-actions,
.document-section:hover > h3 .section-actions,
.document-section:hover > h4 .section-actions,
.document-section:hover > h5 .section-actions,
.document-section:hover > h6 .section-actions {
    opacity: 1;
}

.section-actions .has-comments {
    opacity: 1;
}

.section-actions button {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 0.85em;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.section-actions button:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--accent);
}

.section-actions .has-comments {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeaa7;
}

.section-actions .has-comments .count {
    margin-left: 4px;
    font-weight: 600;
}

/* Links inside vision body — temporarily visible underlines. */
.document-body a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Markdown-rendered tables inside document sections — visible borders for readability. */
.document-body table {
    border-collapse: collapse;
    margin: 12px 0;
}
.document-body table th,
.document-body table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
}
.document-body table th {
    background: var(--card-bg);
    font-weight: 600;
}
.document-body table tr:nth-child(even) td {
    background: color-mix(in srgb, var(--card-bg) 50%, transparent);
}

/* Section drawer — 4th grid column on wide screens, overlay on narrow (see media query below). */
.section-drawer-backdrop {
    /* Hidden on wide screens; visible only in the narrow overlay fallback. */
    display: none;
}

.section-drawer {
    /* Hidden until body.drawer-open; then renders as 4th grid item. */
    display: none;
    background: #fff;
    border-left: 1px solid var(--border);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}

/* Section drawer и structure drawer делят 4-й grid-столбец; режим выбирается
   классом body.drawer-structure (граф) vs его отсутствием (данные секции). */
body.drawer-open:not(.drawer-structure) .section-drawer {
    display: block;
}

.structure-drawer {
    display: none;
    background: #fff;
    border-left: 1px solid var(--border);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}
body.drawer-open.drawer-structure .structure-drawer {
    display: block;
}
.structure-drawer-body {
    padding: 12px 14px;
}

/* Линейный граф связей — кликабельные строки с бейджами (вместо Mermaid-картинки). */
.path-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.path-section-label {
    font-size: 0.74em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 6px 0 2px;
}
.path-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 5px;
    text-decoration: none;
    color: var(--text);
    background: #fff;
    flex-wrap: wrap;
}
a.path-row:hover {
    border-color: var(--accent);
    background: var(--card-bg);
}
.path-center {
    border-width: 2px;
    border-color: #111;
    font-weight: 600;
    background: var(--card-bg);
}
.path-hub {
    border-style: dashed;
}
.path-name {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}
.path-rel {
    font-size: 0.76em;
    color: var(--text-muted);
    white-space: nowrap;
}
.path-arrow {
    text-align: center;
    color: var(--text-muted);
    line-height: 1;
}
.path-divider {
    border-top: 1px dashed var(--border);
    margin: 10px 0 2px;
}
.structure-drawer-hint {
    margin: 0 0 12px;
    font-size: 0.82em;
    color: var(--text-muted);
}
/* Вертикальный граф в узкой колонке — прокрутка вместо сжатия. */
.structure-drawer .mermaid,
.structure-drawer .mermaid-lazy {
    overflow: auto;
}
.structure-drawer .mermaid svg {
    max-width: none;
}

/* Graph modal — отдельная возможность: центрированное окно ~90% экрана с полным графом. */
.graph-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 200;
}
body.graph-modal-open .graph-modal-backdrop {
    opacity: 1;
    visibility: visible;
}
.graph-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: 90vw;
    height: 90vh;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    z-index: 210;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
    overflow: hidden;
}
body.graph-modal-open .graph-modal {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}
.graph-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
    flex-shrink: 0;
}
.graph-modal-header h2 {
    margin: 0;
    font-size: 1.0em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: none;
}
.graph-modal-close {
    background: transparent;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 6px;
}
.graph-modal-close:hover { color: var(--text); }
.graph-modal-body {
    padding: 16px 20px;
    overflow: auto;
    flex: 1;
}
.graph-modal-hint {
    margin: 0 0 12px;
    font-size: 0.85em;
    color: var(--text-muted);
}
.graph-modal-body .mermaid,
.graph-modal-body .mermaid-lazy {
    overflow: auto;
}
.graph-modal-body .mermaid svg {
    max-width: 100%;
    height: auto;
}

.section-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
    position: sticky;
    top: 0;
    z-index: 1;
}

.section-drawer-header h2 {
    margin: 0;
    font-size: 1.0em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: none;
}

.section-drawer-close {
    background: transparent;
    border: none;
    font-size: 1.4em;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 6px;
}

.section-drawer-close:hover { color: var(--text); }

.section-drawer-body {
    padding: 16px 20px;
}

.section-drawer-body dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 0 0 16px;
}

.section-drawer-body dt {
    color: var(--text-muted);
    font-size: 0.85em;
    align-self: center;
}

.section-drawer-body dd {
    margin: 0;
    word-break: break-word;
}

.section-drawer-body dd code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.88em;
}

.section-drawer-comments {
    margin-top: 12px;
}

.section-drawer-comments h3 {
    font-size: 0.9em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px;
}

.section-drawer-comments ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.section-drawer-comments li {
    padding: 8px 12px;
    background: var(--card-bg);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 0.92em;
}

.section-drawer-actions {
    margin-top: 16px;
    display: flex;
    gap: 8px;
}

.section-drawer-actions button {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

.section-drawer-actions button:hover {
    background: var(--bg);
    border-color: var(--accent);
}

/* Toast for copied link. */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 0.88em;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 200;
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Narrow-screen fallback: drawer becomes overlay, backdrop appears. */
@media (max-width: 1024px) {
    body.two-pane.drawer-open,
    body.three-pane.drawer-open {
        grid-template-columns: 1fr;
    }

    .section-drawer,
    .structure-drawer {
        position: fixed;
        top: 0;
        right: 0;
        width: 400px;
        max-width: 100vw;
        z-index: 100;
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
        transform: translateX(100%);
        transition: transform 0.2s ease-out;
        display: block;
    }

    body.drawer-open:not(.drawer-structure) .section-drawer {
        transform: translateX(0);
    }
    body.drawer-open.drawer-structure .structure-drawer {
        transform: translateX(0);
    }

    .section-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.15);
        z-index: 90;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.15s, visibility 0.15s;
    }

    body.drawer-open .section-drawer-backdrop {
        opacity: 1;
        visibility: visible;
    }
}

@media (max-width: 640px) {
    .section-drawer,
    .structure-drawer {
        width: 100vw;
    }
}

/* ── Empty State ──────────────────────────────────────── */

.empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 24px;
    text-align: center;
}

/* ── Traceability ─────────────────────────────────────── */

.traceability-table td {
    vertical-align: top;
    font-size: 0.95em;
}

.traceability-table td small {
    color: var(--text-muted);
}

/* ── Mermaid ──────────────────────────────────────────── */

.mermaid {
    text-align: center;
    background: var(--card-bg);
    padding: 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* ── Unresolved artifact reference ─────────────────────── */

.unresolved {
    color: var(--text-muted);
    font-style: italic;
}

/* ── Onboarding / Workflow blocks ──────────────────────── */

.onboarding-step,
.workflow-stage {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 20px;
    margin: 16px 0;
}

.onboarding-step h2,
.workflow-stage h2 {
    margin-top: 0;
    border: none;
}

.summary {
    font-size: 1.05em;
    color: var(--text);
    margin: 8px 0 16px;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 1280px) {
    body.three-pane {
        grid-template-columns: 240px 280px 1fr;
    }
}

@media (max-width: 1024px) {
    .sidebar-toggle {
        display: block;
    }

    body.two-pane,
    body.three-pane {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 312px;
        z-index: 50;
        transform: translateX(0);
        transition: transform 0.2s ease-out;
    }

    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    .middle {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .content {
        padding: 64px 24px 32px;
    }
}

@media (max-width: 600px) {
    .content {
        padding: 64px 16px 24px;
    }
}

/* ── Glossary terms table (Page_Terms) ──────────────────── */
.terms-table-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0 12px;
}
.terms-table-search {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95em;
    background: #fff;
}
.terms-table-search:focus {
    outline: none;
    border-color: var(--accent);
}
.terms-table-count {
    color: var(--text-muted);
    font-size: 0.88em;
    white-space: nowrap;
}

.terms-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.terms-table thead th {
    background: var(--card-bg);
    text-align: left;
    padding: 10px 14px;
    font-size: 0.85em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}
.terms-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: 0.93em;
}
.terms-table tbody tr:last-child td { border-bottom: none; }
.terms-table tbody tr.is-filtered { display: none; }
.terms-table-title {
    width: 26%;
    font-weight: 500;
}
.terms-table-title a { text-decoration: none; }
.terms-table-title a:hover { text-decoration: underline; }
.terms-table-aliases {
    width: 22%;
    color: var(--text-muted);
    font-size: 0.88em;
}

/* ── Source-view buttons (on document / section headers) ── */
.source-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.82em;
    text-decoration: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    background: var(--card-bg);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.source-link:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.document-toolbar .source-link { margin-left: 12px; }

/* Inline source-link inside section actions: compact, no caption. */
.section-actions .source-link {
    padding: 0 6px;
    margin-left: 4px;
    font-size: 0.9em;
}

/* ── Source-view page (Page_SourceFile) ─────────────────── */
.source-header {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 1.05em;
    color: var(--text);
    word-break: break-all;
}
.source-header .source-icon {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent);
    color: #fff;
    border-radius: 4px;
    margin-right: 8px;
    font-size: 0.85em;
    vertical-align: middle;
}
.source-meta {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 12px;
}
.source-meta .source-stat {
    margin-right: 4px;
}

.source-pre {
    background: #fdfdfd;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    overflow: auto;
    font-size: 0.86em;
    line-height: 1.55;
    max-height: calc(100vh - 220px);
}
.source-pre code {
    font-family: "SFMono-Regular", Consolas, monospace;
    white-space: pre;
}

/* ── Source modal (fetched .cs viewer in-place) ─────────── */
.source-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 200;
}
body.source-modal-open .source-modal-backdrop {
    opacity: 1;
    visibility: visible;
}

.source-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(1100px, 92vw);
    height: min(82vh, 900px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    z-index: 210;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
    overflow: hidden;
}
body.source-modal-open .source-modal {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.source-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
}
.source-modal-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}
.source-modal-icon {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent);
    color: #fff;
    border-radius: 4px;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.82em;
    flex-shrink: 0;
}
.source-modal-title {
    margin: 0;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.95em;
    font-weight: 500;
    color: var(--text);
    border: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-modal-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.source-modal-open-tab,
.source-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 4px;
    color: var(--text-muted);
    text-decoration: none;
    cursor: pointer;
    font-size: 1.1em;
    line-height: 1;
}
.source-modal-close { font-size: 1.4em; }
.source-modal-open-tab:hover,
.source-modal-close:hover { border-color: var(--accent); color: var(--accent); }

.source-modal-body {
    flex: 1;
    overflow: auto;
    padding: 8px 0;
    background: #fdfdfd;
}
.source-modal-body .source-pre {
    border: none;
    border-radius: 0;
    max-height: none;
    margin: 0;
}
.source-modal-loading,
.source-modal-error {
    padding: 16px 22px;
    color: var(--text-muted);
}
.source-modal-error { color: var(--accent); }

@media (max-width: 700px) {
    .source-modal {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
}

/* Артефактные коды (FR-101, БП-3, ADR-SRV-016) рендерятся одной строкой —
   HTML по умолчанию разрешает разрыв по дефису, что некрасиво в узких ячейках таблиц.
   MarkdownHelper.WrapCodesInNowrap оборачивает найденные коды в этот класс. */
.nowrap {
    white-space: nowrap;
}

/* ── Просмотр диаграммы во весь экран ─────────────────────── */

.mermaid { cursor: zoom-in; }
.diagram-zoom-open { overflow: hidden; }

.diagram-zoom {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: var(--bg, #fff);
}
.diagram-zoom.open { display: flex; flex-direction: column; }

.diagram-zoom-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
}
.diagram-zoom-bar button {
    min-width: 34px;
    height: 30px;
    padding: 0 10px;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.diagram-zoom-bar button:hover { border-color: var(--text-muted); }
.diagram-zoom-bar [data-zoom-close] { margin-left: auto; font-size: 18px; }
.diagram-zoom-level {
    min-width: 52px;
    text-align: center;
    font-size: 0.85em;
    color: var(--text-muted);
}

.diagram-zoom-stage {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
}
.diagram-zoom-stage.dragging { cursor: grabbing; }

.diagram-zoom-canvas {
    transform-origin: center center;
}
.diagram-zoom-canvas svg { max-width: none; height: auto; }
