/* Wiki: Plane/Notion-стиль для формы и просмотра страниц. */

/* === Форма редактирования =============================================== */
.wiki-title-input input {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    padding: 0.5rem 0.75rem;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}
.wiki-title-input input:focus {
    outline: none !important;
    box-shadow: none !important;
}

.wiki-content-editor .fi-fo-rich-editor-content {
    min-height: 600px;
    font-size: 1rem;
    line-height: 1.65;
}

/* === Страница просмотра ================================================= */
.wiki-view-section,
.wiki-view-section.fi-section {
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
}
.wiki-view-section .fi-section-content-ctn {
    padding-inline: 0 !important;
    padding-block: 0.75rem !important;
}

.wiki-view-content {
    font-size: 1rem;
    line-height: 1.7;
    width: 100%;
}
.wiki-view-content h1 {
    font-size: 1.875rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 1.75rem 0 0.75rem;
}
.wiki-view-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 1.5rem 0 0.5rem;
}
.wiki-view-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 1.25rem 0 0.5rem;
}
.wiki-view-content p {
    margin: 0.75rem 0;
}
.wiki-view-content ul,
.wiki-view-content ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
}
.wiki-view-content ul { list-style: disc; }
.wiki-view-content ol { list-style: decimal; }
.wiki-view-content li { margin: 0.25rem 0; }
.wiki-view-content blockquote {
    border-left: 3px solid #d1d5db;
    padding-left: 1rem;
    margin: 1rem 0;
    color: #4b5563;
    font-style: italic;
}
.wiki-view-content code {
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: ui-monospace, monospace;
}
.wiki-view-content pre {
    background: #f3f4f6;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1rem 0;
}
.wiki-view-content pre code {
    background: transparent;
    padding: 0;
}
.wiki-view-content a {
    color: #2563eb;
    text-decoration: underline;
}
.wiki-view-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
}
.wiki-view-content table th,
.wiki-view-content table td {
    border: 1px solid #d1d5db;
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.wiki-view-content table th {
    background: #f9fafb;
    font-weight: 600;
}
.wiki-view-content img {
    max-width: min(100%, 640px);
    max-height: 480px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 0.375rem;
    margin: 1rem 0;
    display: block;
    border: 1px solid #e5e7eb;
}
.dark .wiki-view-content img {
    border-color: #374151;
}

.dark .wiki-view-content code,
.dark .wiki-view-content pre {
    background: #1f2937;
}
.dark .wiki-view-content table th {
    background: #1f2937;
}
.dark .wiki-view-content table th,
.dark .wiki-view-content table td {
    border-color: #374151;
}
.dark .wiki-view-content blockquote {
    border-left-color: #4b5563;
    color: #9ca3af;
}

/* === Plane-style лист вложенных страниц ================================ */
.wiki-children-tree {
    list-style: none;
    padding: 0;
    margin: 0;
}
.wiki-tree-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3125rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.12s;
    min-height: 28px;
}
.wiki-tree-item:hover {
    background: #f3f4f6;
}
.wiki-tree-icon {
    width: 15px;
    height: 15px;
    color: #6b7280;
    flex-shrink: 0;
}
.wiki-tree-link {
    color: #111827;
    font-size: 0.8125rem;
    line-height: 1.3;
    text-decoration: none;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wiki-tree-link:hover {
    color: #2563eb;
}
.dark .wiki-tree-item:hover {
    background: #1f2937;
}
.dark .wiki-tree-icon {
    color: #9ca3af;
}
.dark .wiki-tree-link {
    color: #e5e7eb;
}
.dark .wiki-tree-link:hover {
    color: #60a5fa;
}

/* Правые контролы (Plane-style: аватар + lock + info + ⋯). */
.wiki-tree-controls {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
    flex-shrink: 0;
    color: #6b7280;
}
.wiki-tree-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    color: #fff;
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
}
.wiki-tree-lock {
    width: 14px;
    height: 14px;
    color: #6b7280;
}
.wiki-tree-lock.locked {
    color: #d97706;
}
.wiki-tree-sep {
    color: #d1d5db;
    font-size: 0.75rem;
    user-select: none;
}
.wiki-tree-info,
.wiki-tree-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: #6b7280;
    text-decoration: none;
    border-radius: 50%;
    cursor: pointer;
}
.wiki-tree-info svg,
.wiki-tree-action svg {
    width: 14px;
    height: 14px;
}
.wiki-tree-action:hover {
    background: #e5e7eb;
    color: #111827;
}
.dark .wiki-tree-controls,
.dark .wiki-tree-lock,
.dark .wiki-tree-info,
.dark .wiki-tree-action {
    color: #9ca3af;
}
.dark .wiki-tree-sep {
    color: #4b5563;
}
.dark .wiki-tree-action:hover {
    background: #374151;
    color: #e5e7eb;
}

/* Subheading: breadcrumb + мета-строка вместо отдельной секции «Метаданные». */
.wiki-subheading {
    font-size: 0.8125rem;
    color: #6b7280;
    line-height: 1.5;
}
.wiki-subheading-meta {
    color: #9ca3af;
}
.wiki-subheading-sep {
    color: #d1d5db;
    margin: 0 0.25rem;
}
.dark .wiki-subheading { color: #9ca3af; }
.dark .wiki-subheading-meta { color: #6b7280; }
.dark .wiki-subheading-sep { color: #4b5563; }

/* === Plane-style sidebar (только на страницах Wiki) ==================== */
/* Sidebar — часть обычного потока Filament-страницы через grid (не fixed!),
   чтобы автоматически двигаться при сворачивании главного меню Filament. */
/* На Wiki снимаем max-width у самой main-области Filament — иначе
   страница остаётся центрированной с пустым местом слева при свёрнутом
   главном меню (fi-main по умолчанию имеет fi-width-XL и т.п.). */
body:has(.wiki-sidebar) .fi-main {
    max-width: none !important;
}

body:has(.wiki-sidebar) .fi-page {
    display: grid;
    /* Sidebar тянется при сворачивании главного Filament-меню:
       минимум 16rem (читаемая ширина названий), целевая ~22% от области,
       максимум 24rem (чтобы не съесть весь экран на широких мониторах). */
    grid-template-columns: clamp(16rem, 22%, 24rem) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
    max-width: none;
    width: 100%;
}

/* Отступ sidebar от верхнего header, чтобы не прилипал. */
body:has(.wiki-sidebar) .wiki-sidebar {
    margin-top: 0.75rem;
}
.wiki-sidebar {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.75rem 0.375rem;
}
.dark .wiki-sidebar {
    background: #111827;
    border-color: #1f2937;
}
.wiki-sidebar-header {
    padding: 0 0.5rem 0.75rem;
}
.wiki-sidebar-home {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    color: #374151;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
}
.wiki-sidebar-home svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.wiki-sidebar-home:hover,
.wiki-sidebar-home.active {
    background: #e5e7eb;
    color: #111827;
}
.wiki-sidebar-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #9ca3af;
    letter-spacing: 0.05em;
    padding: 0.75rem 0.75rem 0.375rem;
}
.wiki-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
.wiki-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-right: 0.5rem;
    padding-top: 0.375rem;
    padding-bottom: 0.375rem;
    border-radius: 0.375rem;
    color: #374151;
    text-decoration: none;
    font-size: 0.8125rem;
    line-height: 1.3;
    overflow: hidden;
}
.wiki-sidebar-icon {
    width: 15px;
    height: 15px;
    color: #6b7280;
    flex-shrink: 0;
}
.wiki-sidebar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wiki-sidebar-link:hover {
    background: #e5e7eb;
    color: #111827;
}
.wiki-sidebar-link.active {
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 500;
}
.wiki-sidebar-link.active .wiki-sidebar-icon {
    color: #1d4ed8;
}

/* Аккордион-папка: контейнер вокруг строки папки + её детей. */
.wiki-sidebar-folder-group {
    display: flex;
    flex-direction: column;
}
.wiki-sidebar-folder-children {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
/* Chevron-кнопка — кликабельная зона для разворачивания. */
.wiki-sidebar-chevron-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    color: #6b7280;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.wiki-sidebar-chevron-btn .wiki-sidebar-chevron {
    width: 12px;
    height: 12px;
    transition: transform 0.15s;
}
.wiki-sidebar-chevron-btn.is-open .wiki-sidebar-chevron {
    transform: rotate(90deg);
}
.wiki-sidebar-chevron-btn:hover {
    color: #111827;
}
.dark .wiki-sidebar-chevron-btn { color: #9ca3af; }
.dark .wiki-sidebar-chevron-btn:hover { color: #f3f4f6; }

/* Когда папка — link состоит из chevron + ссылка с иконкой + текстом.
   Расставим элементы внутри строки папки. */
.wiki-sidebar-link.is-root-folder,
.wiki-sidebar-link.is-folder {
    align-items: center;
}
.wiki-sidebar-folder-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: inherit;
    flex: 1;
    overflow: hidden;
}
.wiki-sidebar-folder-link:hover {
    color: inherit;
}
/* Скрываем содержимое до инициализации Alpine, чтобы не моргало. */
[x-cloak] {
    display: none !important;
}
/* Корневая папка-категория: крупнее, жирная, иконка папки. */
.wiki-sidebar-link.is-root-folder {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #111827;
    margin-top: 0.625rem;
    padding-top: 0.4375rem;
    padding-bottom: 0.4375rem;
}
.wiki-sidebar-link.is-root-folder .wiki-sidebar-icon {
    color: #6b7280;
    width: 17px;
    height: 17px;
}
/* Вложенная папка-подкатегория: обычный регистр, чуть жирнее. */
.wiki-sidebar-link.is-folder {
    font-weight: 600;
    color: #1f2937;
}
.wiki-sidebar-link.is-folder .wiki-sidebar-icon {
    color: #6b7280;
}
.dark .wiki-sidebar-link.is-root-folder { color: #f9fafb; }
.dark .wiki-sidebar-link.is-root-folder .wiki-sidebar-icon { color: #9ca3af; }
.dark .wiki-sidebar-link.is-folder { color: #f3f4f6; }
.dark .wiki-sidebar-link.is-folder .wiki-sidebar-icon { color: #9ca3af; }
.dark .wiki-sidebar-home,
.dark .wiki-sidebar-link { color: #d1d5db; }
.dark .wiki-sidebar-home:hover,
.dark .wiki-sidebar-home.active,
.dark .wiki-sidebar-link:hover { background: #1f2937; color: #f3f4f6; }
.dark .wiki-sidebar-link.active { background: #1e3a8a; color: #93c5fd; }
.dark .wiki-sidebar-link.active .wiki-sidebar-icon { color: #93c5fd; }
.dark .wiki-sidebar-icon { color: #9ca3af; }
.dark .wiki-sidebar-section-label { color: #6b7280; }

/* Маленький значок «приватная страница» справа от названия в sidebar. */
.wiki-sidebar-private {
    width: 12px;
    height: 12px;
    color: #d97706;
    margin-left: auto;
    flex-shrink: 0;
}
.dark .wiki-sidebar-private { color: #f59e0b; }

/* На узких экранах sidebar убираем — он бы съел слишком много места. */
@media (max-width: 1024px) {
    .wiki-sidebar { display: none; }
    body:has(.wiki-sidebar) .fi-page {
        display: block;
    }
}
