/* Operator shell (sidebar + header) and Administration shell.
   Uses only token names from tokens.css — never a literal color. These rules supersede the older
   .app-header / .app-sidebar / .nav-item block that lived in layout.css: the shell is now a flex
   row (sidebar beside a column holding header + main) instead of a fixed header with an absolutely
   positioned sidebar and a margin-left on main. */

.app-container {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

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

.app-header {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}

.header-spacer {
    flex: 1;
}

.app-main {
    flex: 1;
    padding: 22px 24px 32px;
    min-width: 0;
}

/* ── sidebar ──────────────────────────────────────────────────────────────── */

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 248px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    transition: width .2s ease;
    /* NOT overflow:hidden. The profile menu (the app's only Sign Out) is absolutely positioned
       inside the footer at 220px wide; clipping the sidebar clipped the menu to the 64px rail
       and left a collapsed-sidebar user with no way to sign out at all. The scrolling nav below
       does its own clipping, and the labels are clipped individually when collapsed. */
    overflow: visible;
    /* position: sticky ALWAYS establishes its own stacking context (unlike position: relative,
       which only does with an explicit z-index) — so without a z-index here, the sidebar and
       everything painted inside it, including the warehouse selector's OWN z-index: 30 menu, are
       confined to the root context's z-index:auto tier. .scope-menu-scrim is a root-level
       sibling with an explicit z-index (25, below), which outranks z-index:auto regardless of
       any local z-index inside the sidebar — so without this, the scrim painted over the entire
       open warehouse menu and every click on it (including its own options) closed the menu
       instead of choosing one. Must stay above .scope-menu-scrim's z-index. */
    z-index: 26;
}

.app-sidebar.collapsed {
    width: 64px;
}

/* Collapsing hides these VISUALLY but keeps them in the accessibility tree: the icons are
   aria-hidden, so `display: none` on the label would leave every link in the collapsed rail with
   no accessible name at all. The clip technique is the same one .sr-only uses. */
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .sidebar-user-text {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* These carry no accessible name that anything depends on — the brand link has its own
   aria-label, the group headings label a list that is still reachable item by item, and the
   warehouse scope is a static label — so they are removed outright. */
.app-sidebar.collapsed .nav-group,
.app-sidebar.collapsed .sidebar-wordmark,
.app-sidebar.collapsed .sidebar-scope-text {
    display: none !important;
}

/* The chevron on the Administration door is decoration that only reads in the wide rail. */
.app-sidebar.collapsed .nav-chevron {
    display: none !important;
}

.app-sidebar.collapsed .nav-item,
.app-sidebar.collapsed .sidebar-user-btn {
    justify-content: center;
    padding: 9px 0;
}

.app-sidebar.collapsed .sidebar-scope {
    justify-content: center;
    padding: 8px 0;
}

.app-sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 16px 0 10px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 14px 10px 16px;
    min-height: 60px;
    color: var(--accent-fg);
    text-decoration: none;
}

/* The wordmark is an <a>, so the global a:hover would repaint the mark on hover. A logo that
   changes colour under the pointer reads as a state change that isn't one. */
.sidebar-brand:hover {
    color: var(--accent-fg);
}

.sidebar-wordmark {
    display: flex;
    align-items: baseline;
    gap: 5px;
}

.sidebar-wordmark-name {
    font-weight: 800;
    font-size: 17px;
    letter-spacing: -.01em;
    color: var(--text);
}

.sidebar-wordmark-suffix {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-3);
    letter-spacing: .06em;
}

.sidebar-scope {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 10px 4px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
}

.sidebar-scope-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-scope-label {
    font-size: 10.5px;
    color: var(--text-3);
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.sidebar-scope-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-scope-wrap { position: relative; }
.sidebar-scope-btn { width: calc(100% - 20px); text-align: left; cursor: pointer; font: inherit; }
.sidebar-scope-btn:hover { background: var(--surface-2); }
.sidebar-scope-btn .nav-chevron { margin-left: auto; }
.app-sidebar.collapsed .sidebar-scope-btn .nav-chevron { display: none; }
.scope-menu { position: absolute; left: 10px; right: 10px; top: calc(100% - 2px); z-index: 30; display: flex; flex-direction: column; max-height: min(60vh, 420px); overflow-y: auto; padding: 6px; border: 1px solid var(--border-2); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-overlay); }
.scope-menu-right { left: auto; right: 0; top: calc(100% + 6px); min-width: 220px; }
.scope-menu-i { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.scope-menu-i:hover { background: var(--surface-2); }
.scope-menu-i.sel { background: var(--accent-soft); color: var(--accent-fg); font-weight: 700; }
.scope-menu-code { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.client-pill-wrap { position: relative; }
.client-pill { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-full); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.client-pill:hover { background: var(--surface-2); }

/* Same escape as .sidebar-user-menu below: in the collapsed 64px rail, left:10px/right:10px
   would squeeze warehouse names and codes into a sliver a few pixels wide. Anchor past the
   rail's right edge instead. */
.app-sidebar.collapsed .sidebar-scope-wrap .scope-menu {
    left: calc(100% - 8px);
    right: auto;
    top: 0;
    min-width: 220px;
}

/* Click-away dismissal for the warehouse and client menus (DashboardLayout.razor renders this
   whenever either is open). Sits below .scope-menu's LOCAL z-index (30, inside the client pill's
   unpositioned ancestors, so it competes here directly) so that menu stays interactive; the
   warehouse selector's copy of .scope-menu instead relies on .app-sidebar's z-index (26, above)
   outranking this one at the root level — see the comment there. This must stay BELOW
   .app-sidebar's z-index for that to hold, and below the narrow-breakpoint .app-sidebar (40) and
   .sidebar-scrim (35) too, which it already is. Transparent because closing on an outside click
   needs no visible dimming, unlike the mobile sidebar-scrim below. */
.scope-menu-scrim { position: fixed; inset: 0; z-index: 25; background: transparent; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 10px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-group {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 14px 10px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    border: 0;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent-fg);
}

.nav-item svg {
    flex-shrink: 0;
}

.nav-chevron {
    margin-left: auto;
    color: var(--text-3);
}

.sidebar-footer {
    padding: 8px 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-user {
    position: relative;
}

.sidebar-user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    width: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    color: var(--text);
    border-radius: var(--radius-sm);
}

.sidebar-user-btn:hover {
    background: var(--surface-2);
}

.sidebar-user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-3);
}

/* The profile menu opens UPWARD (the user card sits at the bottom) and, in the collapsed rail,
   escapes the 64px width rather than being squeezed into it. */
.sidebar-user-menu {
    left: 10px;
    right: auto;
    bottom: 56px;
    top: auto;
    z-index: 50;
}

.app-sidebar.collapsed .sidebar-user-menu {
    left: calc(100% - 8px);
    bottom: 8px;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--accent-fg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    flex-shrink: 0;
}

.icon-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.header-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

/* ── status tabs (Orders) ─────────────────────────────────────────────────── */

.status-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    overflow-x: auto;
}

.status-tab {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.status-tab:hover {
    color: var(--text);
}

.status-tab.active {
    color: var(--accent-fg);
    border-bottom-color: var(--accent);
}

/* ── Administration shell ─────────────────────────────────────────────────── */

.admin-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

.admin-header {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}

.admin-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--text-2);
    font-size: 13px;
    text-decoration: none;
}

.admin-back:hover {
    color: var(--text);
}

.admin-header-divider {
    width: 1px;
    height: 22px;
    background: var(--border-2);
}

.admin-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 800;
}

.admin-title-mark {
    color: var(--accent-fg);
    display: inline-flex;
}

.admin-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.admin-nav {
    width: 250px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--bg-2);
    padding: 8px 10px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* The operator sidebar separates an item from its group heading with the icon every item carries.
   The Administration nav has no icons, so sharing .nav-item unchanged left both flush at the same
   left edge in the same weight family: "General" read as a sibling of "ORGANIZATION" rather than a
   destination under it, and nothing said it was clickable until the pointer was already on it.
   Indent the destinations under their heading, and let brightness carry the affordance — a link is
   --text (the interactive tier), a heading stays --text-3 (inert). AdminNavHierarchyTests locks
   both, because no other test in this repo can see it. */
.admin-nav .nav-item {
    padding-left: 22px;
    color: var(--text);
}

/* Higher specificity than the rule above, so the selected page keeps the accent. */
.admin-nav .nav-item.active {
    color: var(--accent-fg);
}

.admin-main {
    flex: 1;
    overflow: auto;
    padding: 26px 32px 40px;
    min-width: 0;
}

/* Dismiss target for the overlay sidebar. Hidden entirely above the breakpoint, where the
   sidebar is a column beside the page and nothing needs dismissing. */
.sidebar-scrim {
    display: none;
}

@media (max-width: 900px) {
    .sidebar-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 35;
        background: var(--scrim);
    }

    .app-sidebar {
        position: fixed;
        /* Overrides the base rule's 26. Still above .sidebar-scrim (35) and .scope-menu-scrim
           (25), so the overlay sidebar and its own warehouse menu both stay interactive here
           too. */
        z-index: 40;
    }

    .app-sidebar.collapsed {
        width: 0;
        border-right: 0;
        /* The base rule keeps overflow visible so the desktop rail's sign-out menu can escape
           its 64px width. Here a collapsed sidebar is meant to be GONE — and with overflow still
           visible its nav icons and the warehouse-scope border painted as a strip down the left
           edge of every operator page, over the content (live walk, 2026-09-09). The existing
           width === 0 assertion could not see it: a zero-width box still paints its overflow.
           Nothing needs to escape a closed sidebar, so clip it and take it out of hit-testing. */
        overflow: hidden;
        visibility: hidden;
        /* Hide only once the width animation has closed, so the panel still slides shut
           instead of vanishing on frame 0; opening flips visibility first, then animates. */
        transition: width .2s ease, visibility 0s linear .2s;
    }

    .admin-body {
        flex-direction: column;
    }

    /* On a phone the admin nav is a scrolling strip of tabs, not a column stacked above the
       page: stacked, its 18 links pushed every admin page below the fold, so opening Members
       showed a list of links and no members. The group headings go; the item names carry
       the meaning on their own. */
    .admin-nav {
        width: 100%;
        display: flex;
        flex-direction: row;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px 12px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        scroll-padding-inline: 12px;
        /* The strip clips "Warehous…" at phone width with nothing to say so (UX evaluation
           2026-10, finding 18): the same edge-shade cue the card tables carry — shadows pinned
           to the box under nav-coloured covers that move with the content. */
        background:
            linear-gradient(to right, var(--bg-2) 40%, transparent) left / 40px 100% no-repeat local,
            linear-gradient(to left, var(--bg-2) 40%, transparent) right / 40px 100% no-repeat local,
            linear-gradient(to right, color-mix(in oklab, var(--text) 28%, transparent), transparent) left / 14px 100% no-repeat scroll,
            linear-gradient(to left, color-mix(in oklab, var(--text) 28%, transparent), transparent) right / 14px 100% no-repeat scroll;
        /* The shorthand resets background-color; the strip keeps its own, not the page's. */
        background-color: var(--bg-2);
    }

    .admin-nav .nav-group {
        display: none;
    }

    .admin-nav .nav-item {
        flex: 0 0 auto;
        /* The base .nav-item is width: 100% for the column layout. In a flex row a percentage
           width resolves against the strip, so without this every tab was a viewport-wide
           box and the strip showed "General" alone with 17 screens of swiping to reach
           Members (whole-branch review of #123). */
        width: auto;
        white-space: nowrap;
        padding: 6px 12px;
    }

    .admin-main {
        padding: 20px 16px 32px;
    }
}

/* Customize dashboard panel (Task 13). A right-hand slide-over, shell chrome like the warehouse
   and client scope menus above, so it lives here rather than in dashboard.css. Its own complete
   rule (not a reuse of .sidebar-scrim) so a future reorder of this file can't silently change
   when the scrim shows.

   Stacking: .customize-scrim/.customize-panel sit in the SAME effective stacking context as
   .app-sidebar (.app-container, .app-column and .app-main create none of their own — no
   position:sticky/relative, transform, filter or opacity on any of them), so z-index alone
   decides paint order. 40/41 beats .app-sidebar's 26 on desktop, so opening Customize dims and
   sits above the whole rail. At the narrow breakpoint .app-sidebar's rule ALWAYS sets z-index: 40
   (the media query is not conditioned on whether the sidebar is actually open) — tied with
   .customize-scrim regardless of sidebar state. That tie is still harmless: when the sidebar is
   collapsed at that width it is `width: 0` with nothing painted in it, so there is nothing to
   contend for the tie; when it IS open (not collapsed), its own .sidebar-scrim (z-index 35)
   covers .app-main, including the Customize trigger button, so the panel cannot be opened in
   that state to begin with. Even if the tie were reached some other way, equal z-index falls back
   to DOM order, and .customize-panel is later in the document than .app-sidebar, so it still
   paints on top. */
.customize-scrim { display: block; position: fixed; inset: 0; z-index: 40; background: var(--scrim); }
.customize-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100vw); z-index: 41; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-overlay); }
.customize-h { display: flex; align-items: center; justify-content: space-between; }
.customize-title { margin: 0; font-size: 16px; font-weight: 800; }
.customize-section { display: flex; flex-direction: column; gap: 8px; }
.customize-label { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.customize-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.customize-preset { padding: 6px 12px; border: 1px solid var(--border-2); border-radius: var(--radius-full); background: none; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
.customize-preset.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-fg); }
.customize-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.customize-row-text { min-width: 0; }
.customize-row-t { font-size: 13px; font-weight: 700; }
.customize-row-m { font-size: 12px; color: var(--text-3); }
.customize-row-actions { display: flex; align-items: center; gap: 4px; }
.customize-foot { margin: 0; font-size: 12px; color: var(--text-3); }
.customize-actions { margin-top: auto; display: flex; justify-content: flex-end; }
.switch { position: relative; width: 36px; height: 20px; border-radius: var(--radius-full); border: 1px solid var(--border-2); background: var(--surface-2); cursor: pointer; padding: 0; }
.switch .switch-knob { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-3); transition: transform .15s; }
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on .switch-knob { background: var(--accent-ink); transform: translateX(16px); }
