.skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 100;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--primary-contrast);
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--text);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--primary);
    color: var(--primary-contrast);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: inset 0 -1px 0 rgb(0 0 0 / 0.12);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: var(--sidebar-w);
    padding: var(--space-5) var(--space-4);
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    view-transition-name: sidebar;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 var(--space-2);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section {
    margin: var(--space-3) var(--space-2) var(--space-1);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 500;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 36px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.nav-link svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: color 120ms var(--ease);
}

.nav-link:hover {
    background: var(--surface-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-link:hover svg {
    color: var(--text-secondary);
}

.nav-link.is-active {
    background: var(--primary-soft);
    color: var(--primary-soft-text);
}

.nav-link.is-active svg {
    color: var(--primary);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-top: auto;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
}

.app-version-sidebar {
    margin-top: var(--space-1);
    text-align: center;
}

.client-switch {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 48px;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: left;
    box-shadow: var(--shadow-sm);
    transition: border-color 120ms var(--ease), background-color 120ms var(--ease);
}

.client-switch:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.client-switch:disabled {
    cursor: default;
}

.client-switch-avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: var(--surface-muted);
    color: var(--text-secondary);
}

.client-switch-avatar svg {
    width: 16px;
    height: 16px;
}

.client-switch-text {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    line-height: 1.25;
}

.client-switch-label {
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.client-switch-name {
    overflow: hidden;
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-switch-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 120ms var(--ease);
}

.client-switch-menu {
    position: relative;
}

.client-switch-menu > summary {
    list-style: none;
    cursor: pointer;
}

.client-switch-menu > summary::-webkit-details-marker {
    display: none;
}

.client-switch-menu[open] > summary .client-switch-chevron {
    transform: rotate(180deg);
}

.client-switch-list {
    position: absolute;
    z-index: 40;
    top: calc(100% + var(--space-2));
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.client-switch-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: 36px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: 500;
}

.client-switch-item:hover {
    background: var(--surface-hover);
    text-decoration: none;
}

.client-switch-item.is-active {
    color: var(--primary);
}

.client-switch-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.main {
    margin-left: var(--sidebar-w);
}

.container {
    --gutter: var(--space-8);

    width: 100%;
    max-width: calc(var(--content-max) + 2 * var(--gutter));
    margin: 0 auto;
    padding: var(--space-8) var(--gutter) var(--space-10);
}

.container-narrow {
    max-width: calc(640px + 2 * var(--gutter));
}

@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        --gutter: var(--space-6);

        padding-top: var(--space-6);
    }
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
    margin-bottom: var(--space-6);
}

.page-header-text {
    min-width: 0;
}

.page-eyebrow {
    margin-bottom: var(--space-1);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

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

.topbar,
.bottom-nav {
    display: none;
}

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

    .topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        height: calc(var(--topbar-h) + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) var(--space-2) 0 var(--space-4);
        background: color-mix(in srgb, var(--surface) 90%, transparent);
        border-bottom: 1px solid var(--border);
        -webkit-backdrop-filter: saturate(1.4) blur(12px);
        backdrop-filter: saturate(1.4) blur(12px);
        view-transition-name: topbar;
    }

    .topbar .client-switch-menu {
        position: static;
        min-width: 0;
    }

    .topbar .client-switch {
        flex: 0 1 auto;
        width: auto;
        min-width: 0;
        min-height: 40px;
        padding: 0 var(--space-2);
        border-color: transparent;
        background: transparent;
        box-shadow: none;
    }

    .topbar .client-switch-avatar,
    .topbar .client-switch-label {
        display: none;
    }

    .topbar .client-switch-list {
        top: calc(100% + var(--space-1));
        left: var(--space-3);
        right: var(--space-3);
        box-shadow: var(--shadow-lg);
    }

    .topbar .client-switch-item {
        min-height: var(--tap);
    }

    .topbar-actions {
        display: flex;
        margin-left: auto;
        align-items: center;
    }

    .main {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    }

    .container {
        --gutter: var(--space-4);

        padding: var(--space-5) var(--gutter) var(--space-8);
    }

    .page-header {
        margin-bottom: var(--space-5);
    }

    .bottom-nav {
        position: fixed;
        inset: auto 0 0;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
        padding: 0 var(--space-2) env(safe-area-inset-bottom);
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        border-top: 1px solid var(--border);
        -webkit-backdrop-filter: saturate(1.4) blur(12px);
        backdrop-filter: saturate(1.4) blur(12px);
        view-transition-name: bottom-nav;
    }

    .bottom-nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: var(--tap);
        color: var(--text-muted);
        font-size: 0.6875rem;
        font-weight: 500;
    }

    .bottom-nav-link:hover {
        text-decoration: none;
    }

    .bottom-nav-icon {
        display: grid;
        place-items: center;
        width: 48px;
        height: 30px;
        border-radius: var(--radius-pill);
        transition: background-color 120ms var(--ease), color 120ms var(--ease);
    }

    .bottom-nav-icon svg {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-link.is-active {
        color: var(--text);
    }

    .bottom-nav-link.is-active .bottom-nav-icon {
        background: var(--primary-soft);
        color: var(--primary);
    }

    .bottom-nav-link.is-primary {
        color: var(--primary);
        font-weight: 600;
    }

    .bottom-nav-link.is-primary .bottom-nav-icon {
        background: var(--primary);
        color: var(--primary-contrast);
        box-shadow: 0 4px 12px -4px rgb(31 58 138 / 0.5);
    }
}
