/* ============================================================
   Layout — каркас кабинета
   ============================================================ */

/* --------------------------------------------------------
   Основной контейнер приложения
   -------------------------------------------------------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 100vh;
    width: 100%;
}

/* --------------------------------------------------------
   Сайдбар
   -------------------------------------------------------- */
.sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: var(--z-sidebar);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    min-height: var(--header-height);
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: var(--fw-bold);
    letter-spacing: -0.02em;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-logo img,
.sidebar-logo svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.sidebar-brand-text {
    flex: 1;
    min-width: 0;
}

.sidebar-brand-title {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-brand-sub {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Меню --- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3) var(--space-3);
}

.sidebar-section {
    margin-bottom: var(--space-5);
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: var(--fw-semibold);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0 var(--space-3);
    margin-bottom: var(--space-2);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 36px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease);
    margin-bottom: 2px;
    user-select: none;
    position: relative;
    text-decoration: none;
}

.sidebar-item:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-item.is-active {
    background: var(--accent-subtle);
    color: var(--accent-text);
    font-weight: var(--fw-semibold);
}

.sidebar-item.is-active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.sidebar-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sidebar-item-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-item-badge {
    font-size: 10px;
    font-weight: var(--fw-semibold);
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--color-danger);
    color: var(--text-inverse);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.sidebar-item.is-active .sidebar-item-badge {
    background: var(--accent-primary);
}

/* --- Footer (юзер-карточка) --- */
.sidebar-footer {
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-3);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease);
}

.sidebar-user:hover {
    background: var(--bg-subtle);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.sidebar-user-role {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

/* --------------------------------------------------------
   Основная область
   -------------------------------------------------------- */
.main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-app);
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
}

.header-title {
    font-size: var(--fs-xl);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    letter-spacing: -0.015em;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
}

.header-title small {
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    color: var(--text-tertiary);
    letter-spacing: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* --- Content --- */
.content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
}

.content-inner {
    max-width: var(--content-max-width);
    margin: 0 auto;
    width: 100%;
}

/* --------------------------------------------------------
   Сетки (утилиты)
   -------------------------------------------------------- */
.grid {
    display: grid;
    gap: var(--space-4);
}

.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1024px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------
   Заголовок страницы (внутри .content)
   -------------------------------------------------------- */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    flex-wrap: wrap;
}

.page-head-text {
    flex: 1;
    min-width: 200px;
}

.page-head-title {
    font-size: var(--fs-2xl);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.page-head-desc {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-top: var(--space-1);
    line-height: 1.5;
}

.page-head-actions {
    display: flex;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* --------------------------------------------------------
   Стек карточек
   -------------------------------------------------------- */
.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.stack-tight {
    gap: var(--space-2);
}

/* --------------------------------------------------------
   Утилиты отступов
   -------------------------------------------------------- */
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* --------------------------------------------------------
   Flexbox утилиты
   -------------------------------------------------------- */
.row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.row-between {
    justify-content: space-between;
}

.row-wrap {
    flex-wrap: wrap;
}

.row-top {
    align-items: flex-start;
}

.col {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.flex-1 { flex: 1; min-width: 0; }

/* --------------------------------------------------------
   Текстовые утилиты
   -------------------------------------------------------- */
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-xs        { font-size: var(--fs-xs); }
.text-sm        { font-size: var(--fs-sm); }
.text-base      { font-size: var(--fs-base); }
.text-lg        { font-size: var(--fs-lg); }
.text-semibold  { font-weight: var(--fw-semibold); }
.text-medium    { font-weight: var(--fw-medium); }
.text-nowrap    { white-space: nowrap; }
.text-center    { text-align: center; }
.text-right     { text-align: right; }

/* --------------------------------------------------------
   Мобильная адаптация
   -------------------------------------------------------- */
@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform var(--duration-base) var(--ease);
        box-shadow: var(--shadow-xl);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .content {
        padding: var(--space-4);
    }

    .header {
        padding: 0 var(--space-4);
    }
}

/* --------------------------------------------------------
   Backdrop для мобильного сайдбара
   -------------------------------------------------------- */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: calc(var(--z-sidebar) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-base) var(--ease);
    display: none;
}

@media (max-width: 768px) {
    .sidebar-backdrop { display: block; }
    .sidebar-backdrop.is-open {
        opacity: 1;
        pointer-events: auto;
    }
}
