/* Боковое меню. Цвета и скругления - переменные --au-* из automation.css (тема переключается ими же).
   Компьютер: плавающая карточка слева, можно свернуть до иконок. Телефон: выезжающая шторка (sidebar-mobile.css). */

/* ── Карточка меню ───────────────────────────────────────────── */
.sidebar-drawer {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 9100;
    display: flex;
    flex-direction: column;
    width: 252px;
    height: calc(100% - 24px);
    overflow: hidden;
    background: var(--au-card-solid);
    border: 1px solid var(--au-line);
    border-radius: 20px;
    box-shadow: 0 10px 36px rgba(15, 23, 42, 0.14);
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Место под меню: 12 (отступ) + 252 (ширина) + 16 (зазор) */
body { padding-left: 280px; transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
body.no-sidebar { padding-left: 0; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9050;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    /* без backdrop-filter: на iOS он создаёт слой даже при opacity:0 и перехватывает касания */
    transition: opacity 0.3s;
}

.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

.hamburger-btn { display: none !important; }
.back-btn { display: none !important; }

/* ── Шапка меню: логотип и кнопка «свернуть» ─────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 8px;
    padding: 16px 14px 14px 16px;
    border-bottom: 1px solid var(--au-line);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    gap: 10px;
    overflow: hidden;
    /* запас под тень значка, иначе overflow режет её по прямоугольнику; отрицательный margin - раскладка не меняется */
    padding: 14px;
    margin: -14px;
}

.sidebar-logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

.sidebar-logo-icon img { display: block; width: 100%; height: 100%; object-fit: cover; }

.sidebar-logo-text {
    overflow: hidden;
    font-size: 17px;
    font-weight: 500;
    letter-spacing: -0.2px;
    color: var(--au-text);
    white-space: nowrap;
    transition: opacity 0.2s, width 0.25s;
}

.sidebar-logo-text b { font-weight: 800; background: var(--au-grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.sidebar-collapse-btn,
.sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: var(--au-surface-2);
    color: var(--au-muted);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.25s;
}

.sidebar-collapse-btn:hover,
.sidebar-close-btn:hover { background: var(--au-accent-soft); color: var(--au-accent-ink); }

.sidebar-collapse-btn:focus-visible,
.sidebar-close-btn:focus-visible,
.sidebar-nav-item:focus-visible,
.sidebar-group-head:focus-visible,
.sidebar-notify-btn:focus-visible { outline: 3px solid var(--au-focus); outline-offset: 2px; }

.sidebar-close-btn { display: none; }

/* ── Пункты меню ─────────────────────────────────────────────── */
.sidebar-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 12px 10px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { border-radius: 2px; background: var(--au-line-strong); }

.sidebar-nav-item,
.sidebar-notify-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--au-text-2);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, padding 0.25s, gap 0.25s;
}

.sidebar-nav-item:hover,
.sidebar-notify-btn:hover { background: var(--au-surface-2); color: var(--au-text); }

.sidebar-nav-item.active { background: var(--au-accent-soft); color: var(--au-accent-ink); font-weight: 700; }

.sidebar-nav-item.active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 9px;
    bottom: 9px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--au-grad);
}

.sidebar-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    color: var(--au-muted);
    transition: color 0.15s;
}

.sidebar-nav-item:hover .sidebar-nav-icon,
.sidebar-notify-btn:hover .sidebar-nav-icon { color: var(--au-accent-ink); }
.sidebar-nav-item.active .sidebar-nav-icon { color: var(--au-accent-ink); }
.sidebar-nav-icon svg { width: 20px; height: 20px; }

.sidebar-nav-label {
    overflow: hidden;
    line-height: 1.25;
    white-space: normal;
    transition: opacity 0.2s, width 0.25s;
}

/* ── Раскрывающиеся разделы ──────────────────────────────────── */
.sidebar-group { display: flex; flex-direction: column; margin: 8px 0 4px; }

.sidebar-group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--au-faint);
    font: inherit;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.sidebar-group-head:hover { background: var(--au-surface-2); color: var(--au-muted); }
.sidebar-group-title { display: flex; flex: 1; align-items: center; gap: 8px; min-width: 0; line-height: 1.3; }
.sidebar-group-dot { display: none; }

.sidebar-group-count {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--au-surface-2);
    color: var(--au-muted);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0;
    text-align: center;
}

.sidebar-group-chev { display: grid; place-items: center; flex-shrink: 0; width: 20px; height: 20px; color: var(--au-faint); }
.sidebar-group-chevron { transform: rotate(180deg); transition: transform 0.22s; }
.sidebar-group.closed .sidebar-group-chevron { transform: none; }

.sidebar-group-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 0.24s ease; }
.sidebar-group.closed .sidebar-group-body { grid-template-rows: 0fr; }

.sidebar-group-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    margin: 2px 0 0 22px;
    padding-left: 8px;
    overflow: hidden;
    border-left: 2px solid var(--au-line);
}

.sidebar-group-items .sidebar-nav-item.active::before { left: -10px; }
.sidebar-group.closed .sidebar-group-items { visibility: hidden; transition: visibility 0s 0.24s; }

/* ── Нижние кнопки (уведомления, AI-ассистент - на телефоне) ─── */
.sidebar-notify-section { display: none; flex-shrink: 0; padding: 0 10px 12px; }
.sidebar-notify-divider { height: 1px; margin-bottom: 8px; background: var(--au-line); }

.sidebar-notify-badge {
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    margin-left: auto;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--au-err);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 20px;
    text-align: center;
}

/* ── Свёрнутое меню: только иконки ───────────────────────────── */
body.sidebar-collapsed .sidebar-drawer { width: 64px; }
body.sidebar-collapsed { padding-left: 92px; }

body.sidebar-collapsed .sidebar-nav-label,
body.sidebar-collapsed .sidebar-logo-text {
    width: 0;
    overflow: hidden;
    opacity: 0;
    white-space: nowrap;
    pointer-events: none;
}

body.sidebar-collapsed .sidebar-logo { display: none; }
body.sidebar-collapsed .sidebar-header { justify-content: center; padding: 16px 10px 14px; }
body.sidebar-collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
body.sidebar-collapsed .sidebar-nav { padding: 12px 8px; }
body.sidebar-collapsed .sidebar-nav-item { justify-content: center; gap: 0; padding: 8px; }
body.sidebar-collapsed .sidebar-nav-item.active::before { left: -8px; }

body.sidebar-collapsed .sidebar-group-head { display: none; }
body.sidebar-collapsed .sidebar-group { margin: 0; }
body.sidebar-collapsed .sidebar-group.closed .sidebar-group-body { grid-template-rows: 1fr; }
body.sidebar-collapsed .sidebar-group.closed .sidebar-group-items { visibility: visible; }
body.sidebar-collapsed .sidebar-group-items { margin: 0; padding: 0; border: 0; }

body.sidebar-collapsed .sidebar-nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    z-index: 9200;
    padding: 6px 12px;
    border-radius: 8px;
    background: #1e293b;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-50%);
    transition: opacity 0.15s;
}

body.sidebar-collapsed .sidebar-nav-item:hover::after { opacity: 1; }

/* Без анимации при загрузке страницы - иначе меню «схлопывается» на глазах */
body.sidebar-no-transition,
body.sidebar-no-transition * { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
    .sidebar-drawer, body, .sidebar-group-body { transition: none; }
}

/* Пункт раздела, у которого без модуля доступна только часть (Авто-загрузка без «Репрайсинга») */
.sidebar-nav-lock {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex: none;
    opacity: 0.6;
}
body.sidebar-collapsed .sidebar-nav-lock { display: none; }
