/* Signed-in shell */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    height: 100vh;
    padding: var(--space-4) var(--space-3);
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 2px var(--space-2) 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--ink);
    text-decoration: none;
}

.brand img { flex: 0 0 auto; }
.brand-text { display: grid; min-width: 0; line-height: 1.15; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.03em; white-space: nowrap; }
.brand-context { color: var(--muted); font-size: 12px; white-space: nowrap; }

.sidebar .sidebar-close { display: none; }

.sidebar-action { width: 100%; }

.sidebar-nav {
    display: grid;
    gap: var(--space-4);
    align-content: start;
    flex: 1 1 auto;
}

.nav-group { display: grid; gap: 2px; }

.nav-heading {
    margin: 0 0 var(--space-1);
    padding: 0 var(--space-3);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 7px var(--space-3);
    border-radius: var(--radius);
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 450;
    text-decoration: none;
}

.nav-item .icon { color: var(--muted); }

.nav-item:hover {
    background: var(--surface-soft);
    color: var(--ink);
}

.nav-item.is-current {
    background: var(--surface-muted);
    color: var(--ink);
    font-weight: 600;
}

.nav-item.is-current .icon { color: var(--gold-ink); }

.nav-item.is-current::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--gold);
}

.nav-label { flex: 1 1 auto; min-width: 0; }

.nav-badge {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.nav-badge-attention { background: var(--danger); color: #fff; }
.nav-badge-neutral { background: var(--surface-muted); color: var(--ink-2); }
.nav-item.is-current .nav-badge-neutral { background: var(--surface); }

.sidebar-footer {
    display: grid;
    gap: 2px;
    padding-top: var(--space-3);
    border-top: 1px solid var(--line);
}

/* Account menu */
.account-menu { position: relative; margin-top: var(--space-2); }

.account-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.account-trigger:hover,
.account-trigger[aria-expanded="true"] {
    border-color: var(--line);
    background: var(--surface-soft);
}

.account-trigger > .icon { color: var(--muted); }

.avatar {
    display: inline-grid;
    place-items: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.account-text { display: grid; flex: 1 1 auto; min-width: 0; line-height: 1.3; }

.account-name,
.account-detail {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-name { font-size: 13px; font-weight: 600; }
.account-detail { color: var(--muted); font-size: 12px; }

.account-popover {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 6px);
    z-index: 60;
    display: grid;
    gap: 2px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-float);
}

.account-popover-head {
    display: grid;
    gap: 1px;
    margin-bottom: 4px;
    padding: 6px 8px 10px;
    border-bottom: 1px solid var(--line);
}

.account-popover form { margin: 0; }

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 36px;
    padding: 7px 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-2);
    font: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.menu-item .icon { color: var(--muted); }
.menu-item:hover,
.menu-item.is-current { background: var(--surface-muted); color: var(--ink); }

/* Main area */
.app-main { min-width: 0; }

.page {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-8) 56px;
    outline: none;
}

.mobile-bar,
.sidebar-scrim { display: none; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: var(--touch);
    height: var(--touch);
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
}

.icon-button:hover { background: var(--surface-muted); }

/* Page header */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.page-header > :first-child { min-width: 0; flex: 1 1 360px; }

.page-header p,
.page-subtitle {
    max-width: 72ch;
    margin: 6px 0 0;
    color: var(--muted);
}

.page-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-top: 6px;
    color: var(--muted);
}

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

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: var(--space-2);
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}

.back-link:hover { color: var(--ink); text-decoration: underline; }

/* Page feedback */
.notice {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.notice > .icon { margin-top: 1px; }
.notice p:last-child,
.notice ul:last-child { margin-bottom: 0; }
.notice-title { margin: 0 0 2px; font-weight: 600; }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.notice a { font-weight: 500; }

.notice-success { border-color: #bcd9c7; background: var(--ok-soft); }
.notice-success > .icon { color: var(--ok); }
.notice-error { border-color: var(--danger-line); background: var(--danger-soft); color: #5c1c1c; }
.notice-error > .icon { color: var(--danger); }
.notice-warn { border-color: #e9d29b; background: var(--warn-soft); }
.notice-warn > .icon { color: var(--warn); }
.notice-info { border-color: #c4d4ec; background: var(--info-soft); }
.notice-info > .icon { color: var(--info); }

/* Guest pages */
.guest-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
}

.guest-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
}

.guest-link { color: var(--muted); font-size: 13px; }

.guest-main {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-5) var(--space-8);
    outline: none;
}

.guest-footer {
    padding: var(--space-5) var(--space-6);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

/* Narrow screens: the sidebar becomes a drawer opened from a slim top bar */
@media (max-width: 1024px) {
    .app-shell { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 50;
        width: min(300px, calc(100vw - 48px));
        height: 100%;
        transform: translateX(-102%);
        transition: transform 180ms ease;
        box-shadow: var(--shadow-float);
    }

    .sidebar[data-open="true"] { transform: translateX(0); }
    .sidebar .sidebar-close { display: inline-grid; margin-right: -8px; }

    .sidebar-scrim:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 45;
        display: block;
        border: 0;
        background: rgba(31, 36, 32, 0.4);
    }

    body.portal-drawer-open { overflow: hidden; }

    .mobile-bar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        height: var(--mobile-bar-height);
        padding: 0 var(--space-2);
        border-bottom: 1px solid var(--line);
        background: rgba(255, 255, 255, 0.97);
    }

    .mobile-brand { display: inline-grid; place-items: center; width: 32px; height: 32px; }

    .mobile-title {
        min-width: 0;
        overflow: hidden;
        font-size: 15px;
        font-weight: 600;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .page { padding: var(--space-5) var(--space-5) 48px; }
    html { scroll-padding-top: calc(var(--mobile-bar-height) + 16px); }
}

@media (max-width: 640px) {
    .page { padding: var(--space-4) var(--space-4) 40px; }
    h1 { font-size: 21px; }
    .page-header { align-items: stretch; margin-bottom: var(--space-4); }
    .page-header > :first-child { flex-basis: 100%; }
    .page-actions { width: 100%; }
    .page-actions > .btn { flex: 1 1 auto; }
    .guest-bar { padding: var(--space-3) var(--space-4); }
    .guest-link { display: none; }
    .guest-main { padding: var(--space-3) var(--space-4) var(--space-6); }
}

/* Page actions that repeat a sidebar action only appear when the sidebar is folded away */
@media (min-width: 1025px) {
    .drawer-only { display: none !important; }
}
