:root {
    --quag-shell-bg: linear-gradient(90deg, #1f2937 0%, #111827 100%);
    --quag-shell-canvas: #f5f6fb;
}

/* Общий каркас приложения с постоянным сайдбаром. */
.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--quag-shell-canvas);
}

.app-sidebar {
    width: 248px;
    background: var(--quag-shell-bg);
    color: #e5e7eb;
    padding: 20px 16px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow: hidden;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.25);
    z-index: 1020;
    transition: width 0.2s ease;
    gap: 16px;
}

/* Отключаем анимации на старте, чтобы избежать визуального мерцания. */
.sidebar-preload .app-sidebar,
.sidebar-preload .app-body,
.sidebar-preload .app-nav .nav-item {
    transition: none;
}

.app-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 24px;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.app-sidebar-brand .logo-mark {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    object-fit: cover;
}

.app-sidebar-brand .logo-text {
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

.app-sidebar-toggle {
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    background: transparent;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-nav-secondary {
    /* Служебные ссылки прижимаем к низу сайдбара и отделяем от основных разделов. */
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(148, 163, 184, 0.22);
}

.app-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}

.app-nav .nav-item i {
    /* Фиксируем ширину иконки, чтобы текст не сдвигался при загрузке шрифта. */
    width: 1.4rem;
    font-size: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-nav .nav-item.active,
.app-nav .nav-item:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.app-body {
    flex: 1;
    margin-left: 248px;
    min-width: 0;
    transition: margin-left 0.2s ease;
}

.layout-no-sidebar .app-body {
    /* Для промо-страниц убираем отступ от отсутствующего сайдбара. */
    margin-left: 0;
}

.app-header {
    background: var(--quag-shell-bg);
}

/* Заголовок шапки центрируем в доступном пространстве между кнопками. */
.app-header-title {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
}

.app-content {
    background: var(--quag-shell-canvas);
}

.app-sidebar-offcanvas {
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    color: #e5e7eb;
}

.app-sidebar-offcanvas .offcanvas-header {
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.app-sidebar-offcanvas .offcanvas-body {
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.app-sidebar-offcanvas .btn-close-white {
    filter: invert(1);
}

.sidebar-collapsed .app-sidebar {
    /* Убираем визуальные излишки ширины в свернутом состоянии. */
    width: 68px;
    padding: 16px 12px;
}

.sidebar-collapsed .app-body {
    /* Синхронизируем отступ контента с новой шириной свернутого сайдбара. */
    margin-left: 68px;
}

.sidebar-collapsed .app-sidebar .app-nav .nav-item span,
.sidebar-collapsed .app-sidebar .app-sidebar-brand .logo-text {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
}

.sidebar-collapsed .app-sidebar .app-sidebar-header {
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.sidebar-collapsed .app-sidebar .app-sidebar-brand {
    justify-content: center;
    width: 100%;
    /* Убираем зазор, который смещал логотип влево относительно кнопки. */
    gap: 0;
}

.sidebar-collapsed .app-sidebar .app-sidebar-toggle {
    width: 32px;
    height: 32px;
    margin: 0 auto;
}

.sidebar-collapsed .app-sidebar .app-nav .nav-item {
    justify-content: center;
    padding: 10px 0;
    /* Убираем flex-gap, чтобы иконки были по центру подсветки. */
    gap: 0;
}

.sidebar-collapsed .app-sidebar .app-nav-secondary {
    padding-top: 12px;
}

.sidebar-collapsed .app-sidebar .app-nav .nav-item i {
    margin: 0;
}

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

@media (max-width: 991.98px) {
    .app-sidebar {
        display: none;
    }

    .app-body,
    .sidebar-collapsed .app-body {
        /* На мобильной ширине сайдбар заменён offcanvas, поэтому место под него не резервируем. */
        margin-left: 0;
    }
}

@media (max-width: 991.98px) {
    .app-header .quag-layout-container {
        gap: 0.65rem !important;
    }
}
