/* Документация - основные стили */

:root {
    --documentation-layout-width: 1152px;
    --documentation-nav-width: 280px;
    --documentation-article-width: 872px;
}

/* Контейнер документации */
.documentation {
    width: 100%;
    max-width: var(--documentation-layout-width);
    margin: 0 auto;
    padding-top: 3px;
    display: flex;
    align-items: stretch;
    min-height: 0;
    overflow: visible;
    gap: 0;
}

/*
 * В личном кабинете прокруткой владеет правая рабочая область. Это правило
 * также перекрывает legacy-стили .right_block.docs из base1.css.
 */
.right_block.docs {
    height: 100vh;
    height: 100dvh;
    margin-bottom: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

/* В личном кабинете документация начинается от левого края рабочей области. */
.right_block.docs .documentation {
    margin-left: 0;
    margin-right: auto;
}

/* Левая панель - навигация */
.documentation_nav_column {
    flex: 0 0 var(--documentation-nav-width);
    width: var(--documentation-nav-width);
    min-width: var(--documentation-nav-width);
    align-self: stretch;
}

.documentation_nav_container {
    position: static;
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: none;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.documentation_nav_header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.nav_header_title {
    font-weight: 600;
    font-size: 14px;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.documentation_nav_body {
    flex: none;
    min-height: 0;
    overflow: visible;
    padding: 12px 0;
}

/* Дерево документации */
.tree_item {
    position: relative;
}

.tree_item_row {
    display: flex;
    align-items: center;
    padding: 6px 16px 6px 8px;
}

.tree_toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 4px;
    transition: background 0.15s;
}

.tree_toggle:hover {
    background: #f3f4f6;
}

.toggle_icon {
    transition: transform 0.2s;
    stroke: #6b7280;
}

.tree_item:not(.collapsed)>.tree_item_row .toggle_icon {
    transform: rotate(90deg);
}

.tree_spacer {
    width: 24px;
    flex-shrink: 0;
}

.tree_link {
    flex: 1;
    padding: 6px 10px;
    color: #374151;
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    transition: all 0.15s;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree_link:hover {
    background: #f3f4f6;
    color: #111827;
}

.tree_link.active {
    background: #1f90bb;
    color: #fff;
}

.tree_children {
    padding-left: 20px;
    overflow: hidden;
}

.tree_item.collapsed>.tree_children {
    display: none;
}

/* Вложенность дерева - отступы */
.tree_children .tree_children .tree_link {
    font-size: 13px;
}

/* Правая панель - контент */
.documentation_container {
    flex: 1;
    width: auto;
    min-width: 0;
    background: #f9fafb;
    overflow: visible;
    padding: 24px;
    padding-top: 5px;
    display: flex;
    flex-direction: column;
    height: auto;
    box-sizing: border-box;
}

.documentation_header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.doc_title {
    margin: 0;
    font-size: 28px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
}

.doc_actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-left: 16px;
}

.doc_action_btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.doc_action_btn:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.doc_action_btn.add_btn:hover {
    background: #1f90bb;
    color: #fff;
    border-color: #1f90bb;
}

.doc_action_btn.delete_btn:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* Содержимое документации */
.documentation_txt {
    background: #fff;
    border-radius: 8px;
    padding: 32px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    line-height: 1.7;
    color: #374151;
    flex: none;
    overflow: visible;
    min-height: auto;
}

.documentation_txt h1,
.documentation_txt h2,
.documentation_txt h3,
.documentation_txt h4,
.documentation_txt h5,
.documentation_txt h6 {
    color: #111827;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    font-weight: 600;
    line-height: 1.3;
}

.documentation_txt h1:first-child,
.documentation_txt h2:first-child,
.documentation_txt h3:first-child {
    margin-top: 0;
}

.documentation_txt h1 {
    font-size: 24px;
}

.documentation_txt h2 {
    font-size: 20px;
}

.documentation_txt h3 {
    font-size: 18px;
}

.documentation_txt h4 {
    font-size: 16px;
}

.documentation_txt p {
    margin: 0 0 1em;
}

.documentation_txt ul,
.documentation_txt ol {
    margin: 0 0 1em;
    padding-left: 24px;
}

.documentation_txt li {
    margin-bottom: 0.5em;
}

.documentation_txt a {
    color: #1f90bb;
    text-decoration: none;
}

.documentation_txt a:hover {
    text-decoration: underline;
}

.documentation_txt img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

/*
 * Небольшие изображения-кнопки часто вставляются прямо в текст абзаца.
 * Для них убираем блочные отступы и выравниваем по центру строки.
 */
.documentation_txt p img,
.documentation_txt li img {
    display: inline-block;
    width: auto;
    height: auto;
    margin: 0 0.25em;
    vertical-align: middle;
}

/* Самостоятельная иллюстрация внутри абзаца остаётся блочной. */
.documentation_txt p > img:only-child {
    /* display: block; */
    margin: 16px auto;
}

.documentation_txt pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 16px 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
}

.documentation_txt code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: #dc2626;
}

.documentation_txt pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.documentation_txt table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.documentation_txt th,
.documentation_txt td {
    border: 1px solid #e5e7eb;
    padding: 10px 14px;
    text-align: left;
}

.documentation_txt th {
    background: #f9fafb;
    font-weight: 600;
}

.documentation_txt blockquote {
    border-left: 4px solid #1f90bb;
    margin: 16px 0;
    padding: 12px 20px;
    background: #e8f4f8;
    color: #4c4c6d;
}

/* Метаданные документа */
.documentation_meta {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.doc_updated {
    font-size: 12px;
    color: #9ca3af;
}

/* Пустое состояние */
.documentation_empty {
    text-align: center;
    padding: 80px 40px;
    background: #fff;
    border-radius: 8px;
}

.empty_icon {
    margin-bottom: 24px;
}

.documentation_empty h2 {
    margin: 0 0 12px;
    font-size: 24px;
    color: #374151;
}

.documentation_empty p {
    margin: 0 0 24px;
    color: #6b7280;
}

.create_doc_btn,
.create_first_doc_btn {
    display: inline-block;
    padding: 12px 24px;
    background: #1f90bb;
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: background 0.15s;
}

.create_doc_btn:hover,
.create_first_doc_btn:hover {
    background: #1f90bb;
}

/* Пустое дерево */
.empty_tree_message {
    padding: 24px 16px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
}

.empty_tree_message p {
    margin: 0 0 16px;
}

/* Хлебные крошки */
.breadcrumb_link {
    color: #6b7280;
    text-decoration: none;
    transition: color 0.15s;
}

.breadcrumb_link:hover {
    color: #1f90bb;
}

.breadcrumb_separator {
    margin: 0 8px;
    color: #d1d5db;
}

.breadcrumb_current {
    color: #374151;
    font-weight: 500;
}

/* Кнопка возврата к началу документации */
.doc-back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    color: #fff;
    background: #1f90bb;
    border: 0;
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(31, 144, 187, 0.32);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.doc-back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.doc-back-to-top:hover,
.doc-back-to-top:focus-visible {
    background: #186f91;
    outline: none;
    box-shadow: 0 10px 28px rgba(31, 144, 187, 0.42);
}

/* Предпросмотр страницы в форме редактирования */
.btn_preview {
    background: #e8f4f8;
    color: #186f91;
}

.btn_preview:hover {
    background: #d4ebf4;
}

.doc-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.72);
}

.doc-preview-overlay.active {
    display: flex;
}

body.doc-preview-open {
    overflow: hidden !important;
}

body.doc-preview-open .right_block.docs {
    overflow: hidden !important;
}

.doc-preview-dialog {
    display: flex;
    flex-direction: column;
    width: min(1200px, 96vw);
    height: min(900px, 92vh);
    height: min(900px, 92dvh);
    overflow: hidden;
    background: #f9fafb;
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
}

.doc-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 56px;
    padding: 12px 16px 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.doc-preview-heading {
    margin: 0;
    color: #111827;
    font-size: 18px;
    font-weight: 600;
}

.doc-preview-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    padding: 0;
    color: #4b5563;
    font-size: 28px;
    line-height: 1;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.doc-preview-close:hover,
.doc-preview-close:focus-visible {
    color: #111827;
    background: #f3f4f6;
    outline: none;
}

.doc-preview-frame {
    flex: 1;
    width: 100%;
    min-height: 0;
    background: #f9fafb;
    border: 0;
}

/* Эти стили используются внутри sandboxed iframe предпросмотра. */
.doc-preview-page {
    width: min(100%, var(--documentation-article-width));
    margin: 0 auto;
    padding: 5px 24px 32px;
}

.doc-preview-page .doc_title {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.doc-preview-empty {
    margin: 0;
    color: #9ca3af;
    font-style: italic;
}

/* Адаптивность */
@media (max-width: 900px) {
    .documentation {
        flex-direction: column;
        min-height: 0;
    }

    .documentation_nav_container {
        position: static;
        align-self: stretch;
        width: 100%;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
        max-height: none;
    }

    .documentation_nav_column {
        flex: none;
        width: 100%;
        min-width: 0;
    }

    .documentation_container {
        padding: 16px;
        height: auto;
        overflow: visible;
    }

    .documentation_txt {
        padding: 20px;
    }

    .doc_title {
        font-size: 22px;
    }

    .doc-preview-overlay {
        padding: 12px;
    }

    .doc-preview-dialog {
        width: 100%;
        height: calc(100vh - 24px);
        height: calc(100dvh - 24px);
    }

    .doc-preview-page {
        padding: 20px;
    }
}

@media (max-width: 600px) {
    .documentation_header {
        flex-direction: column;
        gap: 12px;
    }

    .doc_actions {
        margin-left: 0;
    }

    .form_row {
        flex-direction: column;
        gap: 0;
    }

    .form_row .form_group.small {
        flex: 1;
    }

    .doc-preview-overlay {
        padding: 0;
    }

    .doc-preview-dialog {
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }

    .doc-back-to-top {
        right: 16px;
        bottom: 16px;
        width: 40px;
        height: 40px;
    }
}

figure.image {
    display: table !important;
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    margin: 12px auto;
}

figure.image img {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    display: block;
}

/* Для изображений с inline атрибутами width/height от TinyMCE */
.documentation_txt figure.image {
    display: table !important;
    width: auto !important;
    min-width: 0 !important;
    margin-left: auto;
    margin-right: auto;
}

.documentation_txt figure.image img,
.documentation_txt img[width][height] {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
}

/* Отключение эффекта grayscale при наведении для изображений в документации */
.documentation_txt img:hover,
.documentation_txt figure.image img:hover,
.documentation_txt .image:hover {
    -webkit-filter: none !important;
    filter: none !important;
}
