@layer components {
    /* ---- app shell (sidebar + topbar), used by _LayoutApp ---- */
    .shell {
        display: flex;
        min-height: 100vh;
    }

    .sidebar {
        width: 236px;
        flex-shrink: 0;
        background: var(--sidebar-bg);
        border-right: 1px solid var(--sidebar-border);
        display: flex;
        flex-direction: column;
        padding: 20px 14px;
        position: sticky;
        top: 0;
        height: 100dvh;
        overflow-y: auto;
        /* Sits after .main in DOM (so a generic button[type=submit] query hits the
           page's own form before this ever-present "Sign out" button) but must
           still appear visually first (left of content). */
        order: -1;
    }

    /* ---- mobile nav: below the breakpoint the sidebar becomes an
       off-canvas drawer (toggled by .mobile-topbar's hamburger button)
       instead of a permanently-visible 236px column, which otherwise left
       almost no width for .content on a phone screen. Hidden by default;
       only shown/positioned by the media query below. ---- */
    .mobile-topbar {
        display: none;
    }

    .sidebar-backdrop {
        display: none;
    }

    @media (max-width: 900px) {
        .mobile-topbar {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 16px;
            background: var(--surface);
            border-bottom: 1px solid var(--border);
            position: sticky;
            top: 0;
            z-index: 20;
        }

        .mobile-topbar .brand-mark {
            padding: 0;
        }

        .sidebar-toggle {
            display: flex;
            align-items: center;
            justify-content: center;
            background: none;
            border: none;
            color: var(--text);
            padding: 6px;
            border-radius: var(--radius-sm);
            cursor: pointer;
        }

        .sidebar-toggle:hover {
            background: var(--border);
        }

        .shell {
            flex-direction: column;
        }

        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100dvh;
            width: min(260px, 80vw);
            z-index: 30;
            transform: translateX(-100%);
            transition: transform 0.2s ease;
        }

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

        .sidebar-backdrop {
            display: block;
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.45);
            z-index: 25;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease;
        }

        .sidebar-backdrop.open {
            opacity: 1;
            pointer-events: auto;
        }

        .content {
            padding: 20px 16px 40px;
        }

        .topbar {
            padding: 14px 16px;
        }

        /* Public marketing nav/footer/main also used 40px side padding,
           which on a ~375px phone left barely enough room for the nav's
           brand-mark, links, and Sign in/Try free actions to fit without
           wrapping into three separate rows. */
        .pub-nav {
            padding: 14px 16px;
        }

        .pub-footer {
            padding: 28px 16px;
        }

        .pub-main {
            padding: 32px 16px 56px;
        }
    }

    /* The sidebar is always dark-anchored regardless of the page theme, so its
       brand-mark text needs the sidebar's own always-light text color rather
       than the theme-following default. */
    .sidebar .brand-mark .name {
        color: var(--sidebar-text-active);
    }

    .brand-mark {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 6px 8px 22px;
        text-decoration: none;
    }

    .brand-mark img {
        width: 28px;
        height: 28px;
        border-radius: 7px;
        object-fit: cover;
        flex-shrink: 0;
    }

    /* Default: brand-mark follows the page theme (public nav/footer, auth card).
       The sidebar is always dark-anchored regardless of theme, so it gets its
       own override below rather than being the default. */
    .brand-mark .name {
        color: var(--text);
        font-family: var(--font-display);
        font-size: 17px;
        font-weight: 600;
        letter-spacing: 0.2px;
    }

    .nav-group {
        margin-bottom: 18px;
    }

    .nav-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-faint);
        padding: 0 10px;
        margin-bottom: 6px;
        font-weight: 600;
    }

    .nav-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 10px;
        border-radius: var(--radius-sm);
        color: var(--sidebar-text);
        text-decoration: none;
        font-size: 13.5px;
        font-weight: 500;
        margin-bottom: 2px;
        transition: background 0.12s ease, color 0.12s ease;
    }

    .nav-item svg {
        width: 17px;
        height: 17px;
        flex-shrink: 0;
        opacity: 0.85;
    }

    .nav-item:hover {
        background: rgba(255,255,255,0.05);
        color: var(--sidebar-text-active);
    }

    .nav-item.active {
        background: var(--sidebar-active-bg);
        color: var(--sidebar-text-active);
    }

    .nav-item.active svg {
        opacity: 1;
        color: var(--brand-strong);
    }

    .sidebar-foot {
        margin-top: auto;
        padding-top: 14px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-top: 1px solid var(--sidebar-border);
    }

    .user-chip {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 10px;
        border-radius: var(--radius-sm);
    }

    .user-chip .avatar {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: var(--brand-wash);
        color: var(--brand-strong);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 700;
        flex-shrink: 0;
    }

    .user-chip .who {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .user-chip .who strong {
        color: var(--sidebar-text-active);
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-chip .who span {
        color: var(--text-faint);
        font-size: 11.5px;
    }

    .user-chip form button {
        background: none;
        border: none;
        color: var(--text-faint);
        font-size: 11.5px;
        cursor: pointer;
        padding: 0;
        text-decoration: underline;
    }

    .main {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
    }

    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 32px;
        border-bottom: 1px solid var(--border);
        background: var(--surface);
        position: sticky;
        top: 0;
        z-index: 5;
        gap: 16px;
        flex-wrap: wrap;
    }

    .topbar h1 {
        font-size: 21px;
    }

    .topbar .eyebrow {
        font-size: 12px;
        color: var(--text-muted);
        margin-bottom: 2px;
    }

    .content {
        padding: 28px 32px 48px;
        max-width: 1180px;
    }

    .page-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        flex-wrap: wrap;
        margin-bottom: 24px;
        padding-bottom: 20px;
        border-bottom: 1px solid var(--border);
    }

    .page-head h1 {
        font-size: 21px;
    }

    .page-head .eyebrow {
        font-size: 12px;
        color: var(--text-muted);
        margin-bottom: 2px;
    }

    .section-gap {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .grid-2 {
        display: grid;
        grid-template-columns: 1.4fr 1fr;
        gap: 20px;
        align-items: start;
    }

    @media (max-width: 900px) {
        .grid-2 {
            grid-template-columns: 1fr;
        }
    }

    /* ---- public marketing nav/footer, used by _LayoutPublic ---- */
    .pub-nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 40px;
        border-bottom: 1px solid var(--border);
        background: var(--surface);
        position: sticky;
        top: 0;
        z-index: 10;
        gap: 16px;
        flex-wrap: wrap;
    }

    .pub-nav .links {
        display: flex;
        align-items: center;
        gap: 28px;
    }

    .pub-nav .links a {
        font-size: 13.5px;
        font-weight: 600;
        color: var(--text-muted);
        text-decoration: none;
    }

    .pub-nav .links a:hover {
        color: var(--text);
    }

    .pub-nav .actions {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .pub-footer {
        border-top: 1px solid var(--border);
        padding: 40px;
    }

    .pub-footer .row {
        max-width: 1180px;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 16px;
    }

    .pub-footer .links {
        display: flex;
        gap: 24px;
        flex-wrap: wrap;
    }

    .pub-footer a {
        font-size: 13px;
        color: var(--text-muted);
        text-decoration: none;
    }

    .pub-footer a:hover {
        color: var(--text);
    }

    .pub-footer .copy {
        font-size: 12.5px;
        color: var(--text-faint);
    }

    .pub-main {
        max-width: 1180px;
        margin: 0 auto;
        padding: 56px 40px 80px;
    }

    /* ---- auth shell (centered card), used by _LayoutAuth ---- */
    .auth-shell {
        min-height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 40px 20px;
        background: var(--paper);
    }

    .auth-card {
        width: 100%;
        max-width: 420px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-card);
        padding: 32px 30px;
    }

    .auth-card .brand-mark {
        justify-content: center;
        padding: 0 0 22px;
    }

    .auth-card h1 {
        font-size: 20px;
        text-align: center;
        margin-bottom: 6px;
    }

    .auth-card .sub {
        text-align: center;
        color: var(--text-muted);
        font-size: 13px;
        margin-bottom: 22px;
    }

    .auth-card .field {
        margin-bottom: 16px;
    }

    .auth-card .btn {
        width: 100%;
        justify-content: center;
    }

    .auth-card .foot-link {
        text-align: center;
        font-size: 13px;
        color: var(--text-muted);
        margin-top: 18px;
    }

    .auth-card .foot-link a {
        color: var(--brand-strong);
        font-weight: 600;
        text-decoration: none;
    }
}
