/* ============================================================
   App-shell: левый сайдбар + контент (паттерн Medux).
   Сайдбар и фон страницы — единый тон (--color-bg), без заливки
   и правого бордера; контент — белые плитки (.card) поверх.
   ============================================================ */

.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--color-bg);
}

/* ---------- Сайдбар ---------- */
.app-sidebar {
    /* Ширина настраивается пользователем (ручка .sidebar-resizer): значение
       кладётся в --sidebar-width инлайном на <html> и хранится в localStorage.
       Fallback 300px — дефолт, когда пользователь ничего не менял. */
    flex: 0 0 var(--sidebar-width, 300px);
    width: var(--sidebar-width, 300px);
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    /* z-index выше липкой шапки календаря (.week-head-row z-index:5), иначе
       фиксированная панель уведомлений (потомок сайдбара) уходит под календарь. */
    z-index: 50;
}

/* Шапка сайдбара: знак + имя пользователя (роль подзаголовком) + колокольчик + выход */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 2px 4px 16px;
}

.brand-badge {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--color-brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-text);
    text-decoration: none;
}

.sidebar-brand {
    position: relative;
}

/* Имя + роль в шапке сайдбара занимают середину, колокольчик/выход — справа. */
.sidebar-brand .sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-brand .notif {
    margin-left: auto;
    /* relative — чтобы счётчик уведомлений (.notif-badge) крепился к колокольчику,
       а не к правому краю шапки (иначе висит на кнопке выхода). Фикс-панель это
       не затрагивает — у неё явные top/left. */
    position: relative;
    flex-shrink: 0;
}

.sidebar-brand .sidebar-logout {
    flex-shrink: 0;
}

/* Панель уведомлений в сайдбаре: fixed-поповер (сайдбар со скроллом обрезал бы
   absolute-панель по краю). Прижата к левому верхнему углу, видна целиком. */
.sidebar-brand .notif-panel {
    position: fixed;
    top: 58px;
    left: 12px;
    right: auto;
    width: 300px;
    max-width: calc(100vw - 24px);
    max-height: 70vh;
    /* Поверх всех окон, включая модалки (.modal z-index:1000). */
    z-index: 3000;
}

/* Панель, вынесенная в body (см. notifications.ts openNotifPanel): вне сайдбара
   селектор .sidebar-brand не действует, поэтому дублируем фикс-позиционирование.
   Двойной класс — специфичность выше базового .notif-panel в _layout.css, чтобы
   position:fixed не перебивался position:absolute независимо от порядка файлов. */
.notif-panel.notif-panel--floating {
    position: fixed;
    top: 58px;
    left: 12px;
    right: auto;
    width: 300px;
    max-width: calc(100vw - 24px);
    max-height: 70vh;
    z-index: 3000;
}

/* ---------- Настройки интерфейса (шестерёнка рядом с колокольчиком) ---------- */
.sidebar-brand .settings {
    position: relative;
    flex-shrink: 0;
}

/* Панель настроек: fixed-поповер у левого верхнего угла (как у уведомлений),
   чтобы скролл сайдбара её не обрезал. */
.settings-panel {
    position: fixed;
    top: 58px;
    left: 12px;
    right: auto;
    width: 220px;
    max-width: calc(100vw - 24px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
    padding: 12px;
    z-index: 3000;
}

.settings-group + .settings-group {
    margin-top: 12px;
}

.settings-label {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.settings-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

    .settings-options button {
        flex: 1 1 auto;
        padding: 6px 8px;
        font-size: 13px;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-sm);
        background: var(--color-surface);
        color: var(--color-text-secondary);
        cursor: pointer;
    }

        .settings-options button:hover {
            background: var(--color-surface-muted);
        }

        .settings-options button.active {
            background: var(--color-accent-soft);
            border-color: var(--color-accent);
            color: var(--color-accent-strong);
        }

/* Тулбар справа: разворачиваем flex-порядок app-shell; панели-поповеры
   (настройки) прижимаем к правому краю. */
.app-shell.sidebar-right {
    flex-direction: row-reverse;
}

    .app-shell.sidebar-right .settings-panel {
        left: auto;
        right: 12px;
    }

/* ---------- Переключатель кабинетов (дропдаун) ---------- */
.cab-switch {
    position: relative;
    margin-bottom: 14px;
}

.cab-switch-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-md);
    background: var(--color-accent-soft);
    color: var(--color-accent-strong);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

    .cab-switch-btn .cab-switch-label {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* При наведении глобальный button:hover красит фон тёмным (accent-strong),
       а текст кнопки — тоже accent-strong → сливается. Явно задаём читаемый
       контраст: индиго-фон + белый текст (иконки внутри — currentColor). */
    .cab-switch-btn:hover {
        background: var(--color-accent);
        color: #fff;
    }

.cab-switch-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 40;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
    padding: 4px;
}

.cab-switch-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--color-text-secondary);
    text-decoration: none;
    cursor: pointer;
}

    .cab-switch-item:hover {
        background: var(--color-surface-muted);
    }

    .cab-switch-item.active {
        background: var(--color-accent-soft);
        color: var(--color-accent-strong);
    }

    .cab-switch-item .ic-check {
        margin-left: auto;
    }

/* ---------- Навигация по секциям кабинета ---------- */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-text-secondary);
    text-decoration: none;
    cursor: pointer;
    background: transparent;
    border: none;
    text-align: left;
    width: 100%;
    transition: background 0.15s;
}

    .sidebar-link:hover {
        background: var(--color-surface-muted);
    }

    /* Активный пункт — белая плитка с индиго-иконкой */
    .sidebar-link.active {
        background: var(--color-surface);
        color: var(--color-accent-strong);
        box-shadow: var(--shadow-card);
    }

        .sidebar-link.active .ic {
            color: var(--color-accent);
        }

/* ---------- Блок пользователя внизу ---------- */
.sidebar-user {
    margin-top: auto;
    border-top: 1px solid var(--color-border-soft);
    padding-top: 12px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-accent-soft);
    color: var(--color-accent-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info {
    min-width: 0;
    flex: 1;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--color-text-muted);
}

.sidebar-logout {
    color: var(--color-text-muted);
    display: inline-flex;
    padding: 6px;
    border-radius: var(--radius-sm);
    text-decoration: none;
}

    .sidebar-logout:hover {
        background: var(--color-surface-muted);
        color: var(--color-danger);
    }

/* ---------- Виджеты сайдбара (сворачиваемые) ---------- */
.sidebar-widgets {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-soft);
}

.sw-widget {
    background: var(--color-surface);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

/* Заголовок виджета — клик сворачивает/разворачивает в строку. */
.sw-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    user-select: none;
}

    .sw-head:hover {
        background: var(--color-surface-muted);
    }

.sw-title {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Шестерёнка настройки плана в заголовке — не сворачивает (data-no-collapse). */
.sw-head .icon-btn {
    flex-shrink: 0;
    font-size: 15px;
    padding: 2px 4px;
}

.sw-chevron {
    flex-shrink: 0;
    display: inline-flex;
    color: var(--color-text-muted);
    transition: transform 0.15s;
}

/* Свёрнуто: тело скрыто, шеврон повёрнут вправо. */
.sw-widget.collapsed .sw-chevron {
    transform: rotate(-90deg);
}

.sw-body {
    padding: 0 12px 12px;
}

.sw-widget.collapsed .sw-body {
    display: none;
}

/* ---------- Ручка изменения ширины сайдбара ---------- */
/* Узкая вертикальная полоса между сайдбаром и контентом: перетаскивание меняет
   --sidebar-width (см. скрипт в _Layout), двойной клик — сброс к дефолту. */
.sidebar-resizer {
    flex: 0 0 6px;
    align-self: stretch;
    cursor: col-resize;
    border-radius: 3px;
    background: transparent;
    transition: background 0.15s;
}

    .sidebar-resizer:hover,
    .sidebar-resizer.dragging {
        background: var(--color-border);
    }

/* ---------- Основная область ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 16px 24px 12px;
}

.app-main > main {
    flex: 1 0 auto;
}

/* Топбар страницы: заголовок + действия (без колокольчика — он в сайдбаре) */
.app-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 600;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Кнопка-гамбургер (drawer) — только на мобильных */
.drawer-toggle {
    display: none;
}

/* Оверлей drawer'а */
.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    border: none;
    padding: 0;
    z-index: 90;
}

/* ---------- Простые страницы (без кабинета): верхняя шапка ---------- */
.plain-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    margin-bottom: 16px;
}

.plain-nav {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

    .plain-nav a {
        color: var(--color-text);
        text-decoration: none;
        padding: 7px 14px;
        border-radius: var(--radius-md);
        background: var(--color-surface);
        border: 1px solid var(--color-border-soft);
        font-size: 13px;
    }

        .plain-nav a:hover {
            background: var(--color-surface-muted);
        }

/* Футер */
.app-footer {
    margin-top: 16px;
    padding: 12px 0 4px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
}

    .app-footer a {
        color: var(--color-brand);
        text-decoration: none;
    }

/* ---------- Нижняя навигация (мобильные) ---------- */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border-soft);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 7px 0 6px;
    font-size: 10px;
    color: var(--color-text-muted);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

    /* Нижнюю навигацию НЕ подсвечиваем: пункты «Календарь / Мои мероприятия» —
       переходы-скроллы, активный пункт не несёт смысла. Перебиваем и глобальный
       button:hover (тёмный акцентный фон «залипал» после тапа на мобильном). */
    .bottom-nav-item.active,
    .bottom-nav-item:hover,
    .bottom-nav-item:focus,
    .bottom-nav-item:active {
        background: none;
        color: var(--color-text-muted);
        outline: none;
    }

/* ============================================================
   Адаптив
   ============================================================ */

/* Планшет: сайдбар чуть уже, но НЕ сжимаем в узкий рельс — иначе пропадут
   виджеты (прогресс/инфо/группы/рекомендации), которые теперь живут в сайдбаре. */
@media (max-width: 1024px) and (min-width: 769px) {
    .app-sidebar {
        flex-basis: var(--sidebar-width, 268px);
        width: var(--sidebar-width, 268px);
    }
}

/* Мобильный: сайдбар — выезжающий drawer, снизу — bottom nav */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        width: 272px;
        flex-basis: 272px;
        background: var(--color-bg);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: none;
        height: 100vh;
    }

    .app-shell.drawer-open .app-sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-popover);
    }

    .app-shell.drawer-open .drawer-overlay {
        display: block;
    }

    .drawer-toggle {
        display: inline-flex;
    }

    /* На мобильном сайдбар — drawer фиксированной ширины, ручка не нужна. */
    .sidebar-resizer {
        display: none;
    }

    /* Навигацию по секциям на мобильном дублирует нижняя панель (.bottom-nav),
       поэтому в drawer её прячем — иначе «Календарь/Мои мероприятия» видны дважды.
       Виджеты сайдбара при этом остаются доступны в drawer. */
    .sidebar-nav {
        display: none;
    }

    .app-main {
        padding: 12px 12px 64px; /* снизу — место под bottom nav */
    }

    .bottom-nav {
        display: flex;
    }
}
