/**
 * Единый сайдбар (десктоп) / нижний бар (мобильная версия).
 * Используется только в layouts/main.php и layouts/guest.php — НЕ в
 * layouts/admin.php, у которого свой отдельный сайдбар (class="sidebar",
 * без иконок) в layout.css. Тот файл сознательно не тронут: он общий
 * для main.php и admin.php, и правки в нём задели бы админку.
 *
 * Из-за этого часть правил ниже (список .sidebar-nav, .nav-item__icon/
 * __label и т.д.) намеренно скопирована под #sidebar — новый сайдбар
 * получил свой собственный id, а не переиспользует старый class="sidebar",
 * поэтому конфликтов с layout.css/admin.php нет в принципе. Токены —
 * только из theme.css, своих цветов файл не заводит.
 */

:root {
    --sidebar-w-collapsed: 72px;
    --sidebar-w-expanded: 240px;
    --bottombar-h: 64px;
}

body {
    --sidebar-w: var(--sidebar-w-collapsed);
}

/* Новый каркас для main.php (вместо старого .app-layout, который остаётся
   за admin.php как есть). .app-header/.app-content — те же классы, что и в
   layout.css, но дочерний селектор ограничивает эти правила только тем
   случаем, когда они лежат прямо внутри .app-shell — на admin.php (там
   родитель .app-layout) это никак не влияет. */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-shell > .app-header {
    flex: 0 0 56px;
}

.app-shell > .app-content {
    flex: 1 1 auto;
    overflow-y: auto;
}

/* Смещение контента под фиксированный #sidebar. Селектор с body./тегом —
   чтобы это правило гарантированно перебивало .guest-layout { padding: … }
   из auth.css независимо от порядка подключения файлов в <head>. */
body.app-shell,
body.guest-layout {
    padding-left: var(--sidebar-w);
    transition: padding-left 0.25s ease;
}

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    padding: 1.25rem 0.75rem;
    background-color: var(--bg-surface);
    border-right: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
    overflow-x: hidden;
    overflow-y: auto;
    transition: width 0.25s ease;
}

.sidebar-top {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 1.25rem;
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    clip-path: var(--clip-tactical);
}

.sidebar-toggle:hover {
    color: var(--brand-color);
    background: color-mix(in srgb, var(--brand-color) 8%, transparent);
}

.sidebar-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

/* Список пунктов — #sidebar .sidebar-nav (не голый .sidebar-nav), чтобы
   list-style/gap здесь не задевали <nav class="sidebar-nav"> в admin.php,
   у которого своя, более простая разметка на тех же именах классов. */
#sidebar .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    list-style: none;
}

#sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
}

.nav-item__icon {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
}

.nav-item__label {
    overflow: hidden;
    width: 0;
    opacity: 0;
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

#sidebar.is-expanded .nav-item__label {
    width: auto;
    opacity: 1;
}

.nav-group {
    display: flex;
    flex-direction: column;
}

.nav-group__row {
    display: flex;
    align-items: center;
}

.nav-group__row .nav-item {
    flex: 1 1 auto;
}

.nav-caret {
    display: none;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

#sidebar.is-expanded .nav-caret {
    display: flex;
}

.nav-caret svg {
    width: 1rem;
    height: 1rem;
    transition: transform 0.15s ease;
}

.nav-caret[aria-expanded="true"] svg {
    transform: rotate(90deg);
}

.nav-submenu {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    margin: 0.125rem 0 0.25rem 1.9rem;
    list-style: none;
}

.nav-submenu[hidden] {
    display: none;
}

.nav-subitem {
    display: block;
    padding: 0.4rem 0.6rem;
    font-family: var(--font-body);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    clip-path: var(--clip-tactical);
}

.nav-subitem:hover {
    color: var(--brand-color);
    background: color-mix(in srgb, var(--brand-color) 8%, transparent);
}

/* Профиль переехал в шапку (.app-header): просто круглая иконка-триггер +
   раскрывающаяся панель побольше прежнего дропдауна, с 4 крупными
   плитками сверху и списком остальных ссылок снизу. Позиционирование —
   как у уже существующей .notifications-panel в components.css (тот же
   принцип: top: calc(100% + .5rem); right: 0), просто пошире. */
.profile-wrap {
    position: relative;
}

.profile-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
}

.profile-trigger .avatar {
    clip-path: var(--clip-tactical);
}

.profile-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 200;
    width: 320px;
    max-width: calc(100vw - 2rem);
    background-color: var(--bg-surface);
    border: 1px solid color-mix(in srgb, var(--text-secondary) 15%, transparent);
    clip-path: var(--clip-tactical);
}

.profile-panel[hidden] {
    display: none;
}

.profile-panel__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
}

.profile-panel__header:hover {
    background-color: color-mix(in srgb, var(--brand-color) 8%, transparent);
}

.profile-panel__name {
    display: block;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.profile-panel__balance {
    display: block;
    font-size: 0.75rem;
    color: var(--brand-color);
}

.profile-panel__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: color-mix(in srgb, var(--text-secondary) 12%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
}

.profile-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 1rem 0.5rem;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    text-decoration: none;
    text-align: center;
}

.profile-tile:hover {
    color: var(--brand-color);
    background-color: color-mix(in srgb, var(--brand-color) 8%, transparent);
}

.profile-tile svg {
    width: 1.375rem;
    height: 1.375rem;
}

.profile-tile span {
    font-size: 0.75rem;
    line-height: 1.2;
}

.profile-panel__links {
    display: flex;
    flex-direction: column;
    max-height: 260px;
    overflow-y: auto;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    text-decoration: none;
}

.dropdown-item:hover {
    background-color: color-mix(in srgb, var(--brand-color) 8%, transparent);
    color: var(--text-primary);
}

.dropdown-item--logout {
    border-top: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
    color: var(--brand-color);
}

.dropdown-logout-form {
    margin: 0;
}

button.dropdown-item--logout {
    width: 100%;
    background: none;
    border: none;
    border-top: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
    font-family: inherit;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

/* ==========================================================================
   Mobile — нижний навигационный бар (SYSTEM_SPEC.md, дополнение к §22)
   ========================================================================== */
@media (max-width: 768px) {
    body.app-shell,
    body.guest-layout {
        padding-left: 0;
        padding-bottom: var(--bottombar-h);
    }

    #sidebar {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: var(--bottombar-h);
        flex-direction: row;
        align-items: center;
        padding: 0 0.25rem;
        border-right: none;
        border-top: 1px solid color-mix(in srgb, var(--text-secondary) 12%, transparent);
        transition: none;
    }

    .sidebar-top {
        display: none;
    }

    #sidebar .sidebar-nav {
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        width: 100%;
        gap: 0;
    }

    #sidebar .sidebar-nav > li {
        display: flex;
    }

    #sidebar .nav-item {
        flex-direction: column;
        gap: 0.2rem;
        padding: 0.4rem;
        clip-path: none;
    }

    .nav-item__label {
        width: auto;
        opacity: 1;
        font-size: 0.5625rem;
        letter-spacing: 0.02em;
    }

    .nav-group__row .nav-caret,
    .nav-submenu {
        display: none !important;
    }
}
