/* ============================================================================
   The portal shell (HQU-1593) — MainLayout and NavMenu.

   Ported from the AuditTrace portal's WorkspaceShell, WorkspaceNav, NavBrand,
   NavAccountFoot and SurfaceTopBar: a white topbar across the whole width, a
   white labelled rail under it, and ONE page on the paper ground. Global rather
   than scoped so the rail and the layout share one sheet.
   ============================================================================ */

.shell {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
    grid-template-rows: var(--topbar-height) minmax(0, 1fr);
    /* The topbar spans the WHOLE width and the rail starts under it — the bar is the
       app's frame, the rail is one of the things inside it. */
    grid-template-areas:
        "top top"
        "nav pane";
    background: var(--canvas-subtle);
    color: var(--fg-default);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    overflow: hidden;
    transition: grid-template-columns var(--nav-slide-dur) var(--nav-slide-ease);
}

/* Hidden means GONE, not narrow. The column collapses to zero rather than being
   dropped from the track list, so the change animates; the rail keeps its own
   width and slides out rather than squeezing its labels shut. */
.shell--nav-hidden { grid-template-columns: 0px minmax(0, 1fr); }
.shell--nav-hidden .nav {
    transform: translateX(-100%);
    visibility: hidden;   /* also takes it out of the tab order */
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
/* White, like the rail — raised chrome on the paper. It keeps its height whatever
   the trail holds, so arriving on a page never shifts it down. */
.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 0 16px;
    background: var(--canvas-default);
    border-bottom: 1px solid var(--border-default);
}

/* The app's bordered icon button: the one icon-only control in the chrome. */
.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--canvas-default);
    color: var(--fg-muted);
    cursor: pointer;
}
.nav-toggle:hover { background: var(--hover-bg); color: var(--fg-default); }
.nav-toggle .mud-icon-root { font-size: 20px; }

.trail {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: var(--text-md);
    white-space: nowrap;
    overflow: hidden;
}
.trail-item {
    color: var(--fg-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}
a.trail-item:hover { color: var(--fg-default); }
.trail-item.is-current { color: var(--fg-default); font-weight: 600; }
.trail-sep { color: var(--border-input); flex: none; }

/* The trail's head: the project the pages are scoped to, and the control that changes it
   (HQU-1712). Quiet on "All projects"; inked once one is picked, because then every list
   below is showing less than the whole tenant. */
.trail-project {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 280px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--canvas-default);
    color: var(--fg-muted);
    font: inherit;
    cursor: pointer;
}
.trail-project:hover { background: var(--hover-bg); color: var(--fg-default); }
.trail-project.is-selected { color: var(--fg-default); font-weight: 600; border-color: var(--border-input); }
.trail-project .mud-icon-root { flex: none; font-size: 18px; }
.trail-project-name { overflow: hidden; text-overflow: ellipsis; }

/* The project's setup progress, beside the picker (HQU-1725). Neutral while steps are only
   still to do; the attention tone once one is started but wrong. */
.trail-setup {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    height: 30px;
    padding: 0 10px;
    border-radius: var(--radius-pill);
    background: var(--tone-neutral-bg);
    color: var(--tone-neutral-fg);
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
}
.trail-setup:hover { filter: brightness(0.96); }
.trail-setup.needs-attention { background: var(--tone-warning-bg); color: var(--tone-warning-fg); }
.trail-setup .mud-icon-root { font-size: 18px; }

/* ── Rail ───────────────────────────────────────────────────────────────── */
/* White, not grey: a RAISED surface standing on the paper. The right border is
   the only thing separating it from the topbar's white, so it stays full weight. */
.nav {
    grid-area: nav;
    width: var(--nav-w);
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--canvas-default);
    border-right: 1px solid var(--border-default);
    overflow: hidden;
    transition: transform var(--nav-slide-dur) var(--nav-slide-ease),
                visibility var(--nav-slide-dur);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    color: var(--fg-default);
    min-width: 0;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand:hover .nav-brand-name { color: var(--accent-fg); }

/* The mark on the ink tile. */
.nav-brand-mark {
    width: 32px;
    height: 32px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--emphasis-bg);
    color: var(--emphasis-fg);
}
.nav-brand-mark .mud-icon-root { font-size: 18px; }

.nav-brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
/* The one piece of display type in the rail. */
.nav-brand-name {
    font-family: var(--font-display);
    font-size: var(--text-15);
    font-weight: 600;
    letter-spacing: var(--display-tracking);
    line-height: 1.15;
}
.nav-brand-surface {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--fg-muted);
}

.navlist {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 4px 10px 12px;
}

.navgroup { list-style: none; margin: 0; padding: 0; }
.navgroup li { margin: 0; }

/* 15px in a 40px row — the AuditTrace manager density: a person at a desk, not a
   gloved thumb. */
.navlink {
    display: flex;
    align-items: center;
    /* Explicit: the UA stylesheet centres a <button>'s contents, and the group
       toggles are buttons. */
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    margin-bottom: 2px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    font-size: var(--text-15);
    color: var(--fg-muted);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.navlink:hover { background: var(--hover-bg); color: var(--fg-default); text-decoration: none; }

/* Filled INK, not a tint of the brand accent: "you are here" is structural, and a
   solid block is legible at a glance in a way a 10% tint of blue is not. */
.navlink.is-active {
    background: var(--emphasis-bg);
    color: var(--emphasis-fg);
    font-weight: 600;
}
.navlink.is-active:hover { background: var(--emphasis-bg-hover); color: var(--emphasis-fg); }

.navicon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    flex: 0 0 20px;
}
.navicon .mud-icon-root { font-size: var(--text-lg); }

/* min-width:0 is what lets a long label ellipsise rather than run off the row. */
.navlabel { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* A group heading is a row like any other, plus a chevron. When it is shut over the
   current page it says so in ink, so the way back to where you are is never hidden. */
.navgroup-toggle.has-active { color: var(--fg-default); font-weight: 600; }
.navchevron {
    display: inline-flex;
    margin-left: auto;
    color: var(--fg-subtle);
    transition: transform var(--nav-slide-dur) var(--nav-slide-ease);
}
.navchevron .mud-icon-root { font-size: 18px; }
.navchevron.is-open { transform: rotate(180deg); }

/* A group's entries hang from its label edge (11px gutter + 20px icon + 10px gap),
   so the rail reads as one list with indented runs rather than two columns. They
   are a step smaller and shorter than the headings above them. */
.navgroup--sub { margin-bottom: 6px; }
.navlink--sub {
    min-height: 34px;
    padding: 6px 11px 6px 41px;
    font-size: var(--text-md);
}

/* A count on an entry: something on that page is waiting (HQU-1947). Pushed to the
   row's right edge, in the warning tone the setup pill uses, and it keeps its own
   fill on the ink of the current page. */
.navbadge {
    flex: none;
    margin-left: auto;
    min-width: 20px;
    padding: 0 6px;
    border-radius: var(--radius-pill);
    background: var(--tone-warning-bg);
    color: var(--tone-warning-fg);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 20px;
    text-align: center;
}

/* ── Foot ───────────────────────────────────────────────────────────────── */
/* --border-muted, the lighter rule: this parts two runs of the SAME surface. */
.nav-foot {
    flex: 0 0 auto;
    padding: 8px 10px 12px;
    border-top: 1px solid var(--border-muted);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 8px;
    min-width: 0;
}
.nav-avatar {
    width: 32px;
    height: 32px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--emphasis-bg);
    color: var(--emphasis-fg);
    font-size: var(--text-sm);
    font-weight: 600;
}
.nav-user-who { min-width: 0; display: flex; flex-direction: column; }
/* Both ellipsise: the rail is a fixed width and a long email must not push the
   avatar out of it. */
.nav-user-name {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--fg-default);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-user-role {
    font-size: var(--text-sm);
    color: var(--fg-subtle);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Sign out recedes: smaller and muted, under the name it belongs to, so it reads as
   account chrome rather than the last destination in the rail. */
.nav-signout {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    font-size: var(--text-sm);
    color: var(--fg-muted);
    text-align: left;
    cursor: pointer;
}
.nav-signout:hover { background: var(--hover-bg); color: var(--fg-default); }
.nav-signout .navicon .mud-icon-root { font-size: var(--text-15); }

.nav-backdrop { display: none; }

/* ── Pane ───────────────────────────────────────────────────────────────── */
.pane {
    grid-area: pane;
    min-width: 0;
    overflow-y: auto;
    background: var(--canvas-subtle);
}

/* The one page. Capped at --page-max and centred even though the chrome around it is
   full-bleed. The extra bottom padding gives the last row somewhere to sit. */
.doc-host {
    max-width: var(--page-max);
    width: 100%;
    margin-inline: auto;
    padding: 24px 28px 40px;
}

/* The page heading: Archivo on the paper, not a bar of its own. */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    margin-bottom: 20px;
}
.page-title {
    margin: 0;
    min-width: 0;
    font-family: var(--font-display);
    font-size: var(--text-4xl);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: var(--display-tracking);
    color: var(--fg-default);
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex: none;
}

/* ── Setup guide (HQU-1725) ─────────────────────────────────────────────── */
.setup-steps { list-style: none; margin: 0; padding: 0; max-width: 880px; }
.setup-step-body { min-width: 0; flex: 1; }
.setup-issues { margin: 6px 0 0; padding-left: 18px; font-size: var(--text-sm); }
.setup-issues li + li { margin-top: 2px; }

/* ── Project gate (HQU-1735): pick a project before its pages show ─────────── */
.project-choices { list-style: none; margin: 0; padding: 0; max-width: 520px; display: grid; gap: 6px; }
.project-choice {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--canvas-default);
    color: var(--fg-default);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.project-choice:hover { background: var(--hover-bg); }
.project-choice .mud-icon-root { flex: none; font-size: 20px; }
.project-choice-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ── Small screens ──────────────────────────────────────────────────────────
     ≥ 768px   the rail docks beside the page; the toggle hides it
     < 768px   the rail is out of the layout; the toggle slides it OVER the page
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "top"
            "pane";
    }

    /* The docked state means nothing here; the overlay state takes over. */
    .shell .nav,
    .shell--nav-hidden .nav {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 1250;
        width: min(280px, 88vw);
        box-shadow: var(--shadow-floating);
        transform: translateX(-100%);
        visibility: hidden;
    }
    .shell--nav-open .nav,
    .shell--nav-open.shell--nav-hidden .nav { transform: none; visibility: visible; }

    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1240;
        background: var(--scrim);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--nav-slide-dur) var(--nav-slide-ease);
    }
    .shell--nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

    /* Touch targets grow to the 44px minimum; the icons stay their small selves. */
    .nav-toggle { width: 44px; height: 44px; }
    .navlink, .nav-signout { min-height: 44px; }

    .doc-host { padding: 16px 16px 32px; }
    .page-title { font-size: var(--text-3xl); }
}
