body.app-shell {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
    overflow: hidden;
}
body.app-shell > main {
    flex: 1;
    min-width: 0;
}

body.app-shell header {
    background: #0f172a;
    color: #f8fafc;
    padding: var(--s4) var(--s4);
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    position: sticky;
    top: 0;
    height: 100vh;
    width: 250px;
    flex-shrink: 0;
    border-right: 1px solid rgba(148, 163, 184, 0.15);
    overflow-y: auto;
    justify-content: flex-start;
}

body.app-shell header .logo {
    display: flex;
    align-items: center;
    gap: var(--s2);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--fs-lg);
    order: 0;
}

body.app-shell header .logo img {
    width: 28px;
    height: 28px;
}

body.app-shell header nav {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    margin-top: var(--s2);
    order: 1;
}

body.nav-loading header nav {
    opacity: 0;
}

body.app-shell header .nav-toggle {
    display: none;
    background: transparent;
    border: none;
    color: inherit;
}

body.sidebar-collapsed {
    flex-direction: row;
}

body.sidebar-collapsed header {
    width: 76px;
}

body.sidebar-collapsed header .nav-text,
body.sidebar-collapsed header .logo span {
    display: none;
}

body.sidebar-collapsed header .nav-link {
    justify-content: center;
}

body.app-shell header .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    min-height: 44px;
    width: 100%;
    border-radius: var(--r2);
    color: rgba(248, 250, 252, 0.7);
    text-decoration: none;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease;
}

body.sidebar-collapsed header .nav-link {
    padding: 10px;
    position: relative;
}

body.sidebar-collapsed header .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: #0f172a;
    color: #f8fafc;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.78rem;
    white-space: nowrap;
    box-shadow: var(--shadow1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

body.sidebar-collapsed header .nav-link:hover::after {
    opacity: 1;
    transform: translate(2px, -50%);
}

body.app-shell header .nav-link:hover {
    background: rgba(148, 163, 184, 0.15);
    color: #ffffff;
}

body.app-shell header .nav-link.active {
    background: rgba(59, 130, 246, 0.2);
    color: #ffffff;
}

body.app-shell header .nav-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
}

body.app-shell .app-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

body.app-shell .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--s4) var(--s6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s4);
}

.topbar .search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--s2);
    background: var(--surface2);
    border-radius: var(--r2);
    padding: 8px 12px;
    border: 1px solid var(--border);
    position: relative;
}

.topbar .search span {
    color: var(--muted);
    font-size: var(--fs-sm);
}

.topbar .search input {
    border: none;
    background: transparent;
    flex: 1;
    font-size: var(--fs-base);
}

.topbar .search input:focus { box-shadow: none; }

.global-search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r2);
    box-shadow: var(--shadow2);
    z-index: 40;
    max-height: 320px;
    overflow-y: auto;
    display: none;
    padding: var(--s2);
}

.global-search-results.open {
    display: block;
}

.search-section {
    padding: var(--s2);
    border-bottom: 1px solid var(--border);
}

.search-section:last-child {
    border-bottom: none;
}

.search-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.04em;
    margin-bottom: var(--s2);
}

.search-result-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-radius: var(--r2);
    text-decoration: none;
    color: var(--text);
}

.search-result-item:hover {
    background: var(--surface2);
}

.search-result-title {
    font-weight: 600;
    font-size: var(--fs-sm);
}

.search-result-subtitle {
    font-size: 0.75rem;
    color: var(--muted);
}

.topbar .top-actions {
    display: flex;
    align-items: center;
    gap: var(--s3);
}

.topbar .mode-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar .mode-chip {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--muted);
    font-size: var(--fs-sm);
    font-weight: 700;
    white-space: nowrap;
}

body.lite-mode .topbar .mode-chip {
    background: #ecfdf5;
    border-color: #bbf7d0;
    color: #047857;
}

body.lite-mode .topbar .search span {
    display: none;
}

.topbar .btn-ghost {
    box-shadow: none;
}

.topbar .action-menu {
    position: relative;
}

.topbar .action-menu-list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r2);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    box-shadow: var(--shadow2);
    z-index: 30;
}

.topbar .action-menu-list.open { display: flex; }

.topbar .user-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.topbar .user-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.topbar .user-menu-btn::after {
    content: "▾";
    font-size: 0.7rem;
    color: var(--muted);
}

.topbar .user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r2);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    box-shadow: var(--shadow2);
    z-index: 30;
}

.topbar .user-menu-dropdown.open {
    display: flex;
}

.topbar .user-menu-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
}

.topbar .user-menu-meta-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 700;
}

.topbar .user-menu-meta-value {
    font-weight: 600;
    color: var(--text);
}

.topbar .user-menu-item {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
}

.topbar .user-menu-item:hover {
    background: var(--surface2);
    border-color: var(--border);
}

body.app-shell .page-wrap {
    flex: 1;
    overflow-y: auto;
    padding: var(--s6);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--s4);
}

body.app-shell .page-wrap > main {
    width: 100%;
}

.page-title,
.page-header {
    font-family: var(--font-display);
    margin: 0 0 var(--s4) 0;
}

.panel {
    padding: var(--s5);
}

.section-block {
    margin-bottom: var(--s5);
}

@media (max-width: 1100px) {
    body.app-shell header {
        width: 84px;
    }

    body.app-shell header .nav-link .nav-text,
    body.app-shell header .logo span {
        display: none;
    }
}

@media (max-width: 900px) {
    body.app-shell {
        flex-direction: column;
    }

    body.app-shell header {
        position: sticky;
        top: 0;
        height: auto;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        z-index: 30;
        border-left: none;
        width: 100%;
    }

    body.app-shell .app-content { width: 100%; }

    body.app-shell header nav {
        display: none;
        width: 100%;
        padding-top: var(--s4);
    }

    body.app-shell header.nav-open nav {
        display: flex;
    }

    body.app-shell header .logo span {
        display: inline;
    }

    body.app-shell header .nav-link .nav-text {
        display: inline;
    }

    body.app-shell header .nav-link {
        width: 100%;
    }

    body.app-shell .topbar {
        position: relative;
    }

    .topbar .mode-switch {
        display: none;
    }

    body.app-shell header .nav-toggle {
        display: inline-flex;
    }

    body.sidebar-collapsed header {
        width: 100%;
    }
}
