/**
 * Стили сайдбара — иерархическое дерево документов.
 * Анимированное раскрытие, hover-эффекты, SVG иконки разделов.
 */

/* ─── Контейнер сайдбара ──────────────────────────────────────────────────── */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    transition: all var(--duration-slow) var(--ease-out);
    position: relative;
    z-index: 10;
}

/* Скрытый сайдбар */
.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    border-right-width: 0;
    opacity: 0;
    pointer-events: none;
}

/* Логотип / Заголовок сайдбара */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-primary);
    min-height: var(--toolbar-height);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-glow);
}

.sidebar-logo svg {
    width: 18px;
    height: 18px;
    color: white;
}

.sidebar-title {
    font-size: var(--font-size-md);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* ─── Область прокрутки дерева ────────────────────────────────────────────── */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3);
}

/* ─── Элемент дерева (раздел) ─────────────────────────────────────────────── */
.tree-item {
    margin-bottom: 2px;
}

/* Заголовок раздела */
.tree-item-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
    user-select: none;
    position: relative;
}

.tree-item-header:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-item-header.active {
    background: var(--accent-primary-glow);
    color: var(--accent-primary);
}

/* Стрелка раскрытия раздела */
.tree-chevron {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: transform var(--duration-base) var(--ease-out);
    opacity: 0.5;
}

.tree-item.expanded>.tree-item-header .tree-chevron {
    transform: rotate(90deg);
    opacity: 0.8;
}

/* SVG иконка раздела */
.tree-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: color var(--duration-fast);
}

.tree-item-header:hover .tree-icon,
.tree-item-header.active .tree-icon {
    color: var(--accent-primary);
}

.tree-icon svg {
    width: 18px;
    height: 18px;
}

/* Название раздела (полностью, с переносом) */
.tree-label {
    flex: 1;
    font-size: var(--font-size-sm);
    font-weight: 500;
    word-break: break-word;
    line-height: 1.4;
}

/* Количество документов */
.tree-count {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    background: var(--bg-hover);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

/* ─── Дочерние элементы дерева ────────────────────────────────────────────── */
.tree-children {
    padding-left: var(--space-5);
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height var(--duration-slow) var(--ease-out),
        opacity var(--duration-base) var(--ease-out);
}

.tree-item.expanded>.tree-children {
    max-height: 9999px;
    /* Достаточно большое значение для анимированного раскрытия */
    opacity: 1;
}

/* Линия дерева (вертикальная) */
.tree-children {
    position: relative;
}

.tree-children::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 8px;
    width: 1px;
    background: var(--border-primary);
}

/* ─── Элемент документа ───────────────────────────────────────────────────── */
.tree-document {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--duration-fast) var(--ease-out);
    position: relative;
    font-size: var(--font-size-sm);
}

.tree-document:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-document.active {
    background: var(--accent-primary-glow);
    color: var(--accent-primary);
}

.tree-document-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
}

.tree-document-icon svg {
    width: 16px;
    height: 16px;
}

.tree-document.active .tree-document-icon {
    opacity: 1;
    color: var(--accent-primary);
}

/* Название документа (полностью, с переносом) */
.tree-document-name {
    flex: 1;
    word-break: break-word;
    line-height: 1.4;
}

/* Индикатор закладки на документе */
.tree-document-bookmark {
    width: 14px;
    height: 14px;
    color: var(--warning);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--duration-fast);
}

.tree-document.has-bookmark .tree-document-bookmark {
    opacity: 1;
}

/* ─── Сайдбар - кнопка сворачивания ──────────────────────────────────────── */
.sidebar-toggle {
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    box-shadow: var(--shadow-md);
    transition: all var(--duration-fast) var(--ease-out);
    color: var(--text-tertiary);
}

.sidebar-toggle:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: translateY(-50%) scale(1.1);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform var(--duration-base) var(--ease-out);
}

.sidebar-collapsed .sidebar-toggle svg {
    transform: rotate(180deg);
}

/* ─── Ручка ресайза ширины сайдбара ─────────────────────────────────────── */
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    cursor: col-resize;
    z-index: 15;
    transition: background var(--duration-fast);
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle:active {
    background: var(--accent-primary);
}

/* ─── Раздел Избранное ──────────────────────────────────────────────────── */

/* Иконка звезды в разделе Избранное — золотой цвет */
.favorites-icon {
    color: var(--warning) !important;
}

.favorites-icon svg {
    fill: var(--warning);
    stroke: var(--warning);
}

/* Разделитель после Избранного */
.favorites-section {
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-primary);
}

/* Подсказка в пустом разделе Избранное */
.favorites-empty {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    padding: var(--space-2) var(--space-3);
    font-style: italic;
    opacity: 0.7;
}

/* Кнопка удаления из избранного (крестик) */
.tree-fav-remove {
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-tertiary);
    opacity: 0;
    transition: all var(--duration-fast);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.tree-document:hover .tree-fav-remove {
    opacity: 0.6;
}

.tree-fav-remove:hover {
    opacity: 1 !important;
    color: var(--error);
    background: var(--bg-hover);
}

.tree-fav-remove svg {
    width: 14px;
    height: 14px;
}

/* Кнопка звезды в контролах PDF — подсветка при active */
#favoriteBtn.active {
    color: var(--warning);
}

#favoriteBtn.active svg {
    fill: var(--warning);
    stroke: var(--warning);
}