/* ── Shell ── */
.terminal-layout {
    display: flex;
    min-height: 100dvh;
    position: relative;
    z-index: 1;
}

/* ── Mobile top bar ── */
.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 16px;
    align-items: center;
    gap: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 200;
}
.mobile-top-bar .app-logo-img { height: 32px; width: auto; }
#menu-btn {
    background: none; border: none; color: var(--text-main);
    cursor: pointer; padding: 8px; border-radius: 5px;
}
#menu-btn:hover { background: var(--glass-bg-hover); }

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.25s ease, width 0.3s ease;
    overflow: hidden;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header-row { padding: 12px 16px 0; flex-shrink: 0; }
.sidebar-mobile-bar {
    display: flex; align-items: center; justify-content: space-between;
}
.sidebar-mobile-bar-title { font-family: var(--font-head); font-weight: 600; }
.sidebar-close-btn, .sidebar-desktop-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: 5px;
}
.sidebar-close-btn:hover, .sidebar-desktop-toggle:hover { color: var(--text-main); background: var(--glass-bg-hover); }
.sidebar-desktop-toggle-wrap { display: none; }

.logo-area { padding: 16px 20px; flex-shrink: 0; }
.logo { display: flex; align-items: center; gap: 10px; }
.app-logo-img { height: 36px; width: auto; }
body.dark-theme .app-logo-img { content: url('../assets/logo_dark.png'); }
.logo-text { font-family: var(--font-head); font-weight: 700; font-size: 1.1rem; white-space: nowrap; }

.nav-scroll-area { flex: 1; overflow-y: auto; padding: 0 12px 12px; }
.menu-group-title {
    font-family: var(--font-code); font-size: 0.7rem; font-weight: 500;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); padding: 16px 12px 6px;
}
.nav-list { list-style: none; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; border-radius: var(--radius-control);
    color: var(--text-muted); text-decoration: none;
    font-size: 0.9rem; font-weight: 500;
    transition: background 0.15s, color 0.15s;
    position: relative; cursor: pointer;
    white-space: nowrap;
}
.nav-item:hover { background: var(--glass-bg-hover); color: var(--text-main); }
.nav-item.active {
    background: var(--primary-glow); color: var(--primary);
}
body.dark-theme .nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(168,85,247,0.08));
    color: #fff;
}
.nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
    width: 3px; border-radius: 0 5px 5px 0; background: var(--primary);
}
.nav-icon { width: 20px; height: 20px; stroke-width: 1.8; flex-shrink: 0; }

.sidebar-bottom { padding: 12px; border-top: 1px solid var(--glass-border); flex-shrink: 0; }
.user-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 0; }
.user-mini { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-name { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-logout-btn, .sidebar-theme-btn {
    background: none; border: none;
    cursor: pointer; padding: 8px; border-radius: 5px;
}
.sidebar-logout-btn {
    color: var(--danger);
}
.sidebar-logout-btn:hover {
    color: #fff;
    background: rgba(239, 68, 68, 0.18);
}
body.dark-theme .sidebar-logout-btn:hover {
    background: rgba(239, 68, 68, 0.28);
}
.sidebar-theme-btn {
    color: var(--text-muted);
}
.sidebar-theme-btn:hover { color: var(--text-main); background: var(--glass-bg-hover); }

/* ── Main pane — fast tab switching via CSS grid stack ── */
.main-pane {
    flex: 1;
    margin-left: 0;
    padding: var(--padding-layout);
    padding-top: calc(var(--padding-layout) + 0px);
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
    overflow: hidden;
}

.content-section {
    grid-area: 1 / 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    align-self: stretch;
    contain: layout style;
}

/* Inactive: hidden but in DOM — instant switch, no reflow */
.content-section:not(.active) {
    visibility: hidden;
    content-visibility: hidden;
    pointer-events: none;
    position: absolute;
    inset: 0;
    width: 100%;
    max-height: 100%;
    overflow: hidden;
    z-index: 0;
}

.content-section.active {
    visibility: visible;
    content-visibility: visible;
    pointer-events: auto;
    position: relative;
    z-index: 1;
    overflow-y: auto;
}

/* ── Desktop sidebar: rail фиксирован, при hover выезжает поверх контента ── */
@media (min-width: 1025px) {
    .mobile-top-bar { display: none !important; }
    .terminal-layout { display: block; }
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        height: 100dvh;
        transform: none;
        width: var(--sidebar-rail);
        transition: width 0.25s ease, box-shadow 0.25s ease;
        z-index: 300;
    }
    .sidebar:hover {
        width: var(--sidebar-width);
        box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
        z-index: 400;
    }
    body.dark-theme .sidebar:hover {
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    }
    .sidebar-header-row { display: none; }
    .sidebar:not(:hover) .logo-area,
    .sidebar:not(:hover) .logo-text,
    .sidebar:not(:hover) .nav-item span,
    .sidebar:not(:hover) .menu-group-title,
    .sidebar:not(:hover) .user-name { display: none; }
    .sidebar:not(:hover) .sidebar-theme-btn { display: none; }
    .sidebar:not(:hover) .nav-item {
        justify-content: center;
        padding: 12px;
    }
    .sidebar:not(:hover) .user-row {
        justify-content: center;
        padding-top: 4px;
    }
    .sidebar:not(:hover) .user-mini {
        justify-content: center;
        gap: 0;
    }
    .sidebar:not(:hover) .sidebar-bottom {
        padding: 12px 8px;
    }
    .sidebar:not(:hover) .nav-scroll-area {
        padding-top: 16px;
    }
    .sidebar:hover .nav-item {
        justify-content: flex-start;
        padding: 10px 14px;
    }
    .main-pane {
        margin-left: var(--sidebar-rail);
        width: auto;
        padding-top: var(--padding-layout);
    }
}

@media (max-width: 1024px) {
    .mobile-top-bar { display: flex; }
    .main-pane { padding-top: calc(56px + var(--padding-layout)); }
    body.menu-open .main-pane { filter: blur(2px); }
    .sidebar-desktop-toggle-wrap { display: none; }
}

@media (max-width: 768px) {
    :root { --padding-layout: 1rem; }
}
