/* ============================================================================
   GlideInventory — Application Shell
   ----------------------------------------------------------------------------
   The chrome shared by the admin console and the customer portal: sidebar,
   nav, top bar, breadcrumb, content well, footer.

   Global (not scoped) on purpose. The sheets this replaces needed ::deep and
   :global(...) escapes because the shell class lives on the layout while the
   nav links render inside a child component. A single global sheet removes
   that coupling — and lets both shells share one vocabulary instead of
   maintaining two.

   Replaces, and is committed alongside the deletion of:
     Layout/AdminLayout.razor.css          (249 lines)
     Layout/AdminNavMenu.razor.css         (~250 lines)
     Layout/AdminTopBar.razor.css          (~120 lines)
     Layout/AdminBreadcrumb.razor.css      (~30 lines)
     Layout/CustomerPortalLayout.razor.css (~200 lines)

   Depends on: tokens.css, primitives.css
   ============================================================================ */

/* ---------------------------------------------------------------------------
   Shell grid
   --------------------------------------------------------------------------- */
.g-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
    background: var(--g-bg);
    font-family: var(--g-font-ui);
}

.g-shell.is-collapsed {
    grid-template-columns: 68px 1fr;
}

/* Login and other chromeless pages drop the sidebar entirely. */
.g-shell.is-chromeless {
    grid-template-columns: 1fr;
}

.g-shell.is-chromeless .g-sidebar,
.g-shell.is-chromeless .g-shell-footer {
    display: none;
}

/* ---------------------------------------------------------------------------
   Sidebar
   The old shell painted a dark navy gradient sidebar against a light shell,
   plus three fixed radial-gradient washes over the whole page. Both are gone:
   structure is carried by a hairline border and a single surface step.
   --------------------------------------------------------------------------- */
.g-sidebar {
    background: var(--g-surface-2);
    border-right: 1px solid var(--g-border);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
    overflow: hidden;
    width: 100%;
}

.g-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--g-space-2);
    padding: var(--g-space-3) var(--g-space-3);
    border-bottom: 1px solid var(--g-border);
    flex-shrink: 0;
    min-height: 53px;
}

.g-brand-logo {
    display: flex;
    align-items: center;
    gap: var(--g-space-2);
    text-decoration: none;
    color: var(--g-text);
    font-weight: 640;
    font-size: var(--g-text-md);
    letter-spacing: -0.02em;
    min-width: 0;
}

.g-brand-logo-full {
    display: block;
    width: 104px;
    max-width: 100%;
    height: auto;
}

.g-brand-logo-icon {
    display: none;
    width: 24px;
    height: 24px;
    flex: none;
}

.g-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    flex-shrink: 0;
    border: 1px solid var(--g-border);
    background: var(--g-surface);
    border-radius: var(--g-radius-sm);
    color: var(--g-text-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.g-collapse:hover {
    background: var(--g-surface-3);
    color: var(--g-text);
}

.g-collapse svg {
    width: 14px;
    height: 14px;
    transition: transform 0.18s ease;
}

.g-shell.is-collapsed .g-collapse svg {
    transform: rotate(180deg);
}

/* Collapsed rail: stack the mark above the toggle. The toggle MUST stay
   visible — hiding it leaves no way to expand again on desktop, since the
   off-canvas toggle only appears at <=1024px. */
.g-shell.is-collapsed .g-brand {
    flex-direction: column;
    justify-content: center;
    gap: var(--g-space-2);
    padding: var(--g-space-3) var(--g-space-1);
}

.g-shell.is-collapsed .g-brand-logo-full {
    display: none;
}

.g-shell.is-collapsed .g-brand-logo-icon {
    display: block;
}

/* ---------------------------------------------------------------------------
   Nav
   --------------------------------------------------------------------------- */
.g-nav-scroll {
    flex: 1;
    padding: var(--g-space-2) var(--g-space-2) var(--g-space-3);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--g-border-strong) transparent;
}

.g-nav {
    display: flex;
    flex-direction: column;
}

.g-nav-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.g-nav-title {
    font-family: var(--g-font-data);
    font-size: 9.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--g-text-subtle);
    font-weight: 500;
    margin: 0;
    padding: var(--g-space-3) var(--g-space-2) var(--g-space-1);
}

.g-nav-link {
    display: flex;
    align-items: center;
    gap: var(--g-space-2);
    padding: 7px var(--g-space-2);
    border-radius: var(--g-radius-sm);
    font-size: var(--g-text-base);
    color: var(--g-text-muted);
    text-decoration: none;
    border: 0;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

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

.g-nav-link.active {
    background: var(--g-surface);
    color: var(--g-text);
    font-weight: 560;
    box-shadow: inset 0 0 0 1px var(--g-border);
}

.g-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex: none;
    opacity: 0.75;
}

.g-nav-icon svg {
    width: 16px;
    height: 16px;
}

.g-nav-link.active .g-nav-icon {
    opacity: 1;
    color: var(--g-accent);
}

.g-nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Trailing count, e.g. "Devices  4" */
.g-nav-tail {
    font-family: var(--g-font-data);
    font-variant-numeric: tabular-nums;
    font-size: var(--g-text-xs);
    color: var(--g-text-subtle);
    flex: none;
}

/* Expandable group (customer portal "Stocks") */
.g-nav-chevron {
    margin-left: auto;
    flex: none;
    transition: transform 0.18s ease;
    opacity: 0.6;
}

.g-nav-chevron svg {
    width: 12px;
    height: 12px;
    display: block;
}

.g-nav-sub.is-expanded .g-nav-chevron {
    transform: rotate(180deg);
}

.g-nav-submenu {
    display: none;
    flex-direction: column;
    gap: 1px;
}

.g-nav-sub.is-expanded .g-nav-submenu {
    display: flex;
}

.g-nav-submenu .g-nav-link {
    padding-left: calc(var(--g-space-2) + 16px + var(--g-space-2));
    font-size: var(--g-text-sm);
}

/* Collapsed rail: icons only */
.g-shell.is-collapsed .g-nav-title,
.g-shell.is-collapsed .g-nav-label,
.g-shell.is-collapsed .g-nav-tail,
.g-shell.is-collapsed .g-nav-chevron {
    display: none;
}

/* On the rail, a group's children would otherwise be unreachable: the parent
   is a toggle button with no href, and its submenu is off-screen. Surface them
   as a flyout on hover or keyboard focus instead of hiding them. */
.g-shell.is-collapsed .g-nav-sub {
    position: relative;
}

.g-shell.is-collapsed .g-nav-submenu,
.g-shell.is-collapsed .g-nav-sub.is-expanded .g-nav-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    z-index: 20;
    min-width: 184px;
    padding: var(--g-space-1);
    margin-left: var(--g-space-1);
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: var(--g-radius-md);
    box-shadow: var(--g-shadow-2);
}

.g-shell.is-collapsed .g-nav-sub:hover .g-nav-submenu,
.g-shell.is-collapsed .g-nav-sub:focus-within .g-nav-submenu {
    display: flex;
}

.g-shell.is-collapsed .g-nav-submenu .g-nav-link {
    justify-content: flex-start;
    padding: 6px var(--g-space-2);
}

.g-shell.is-collapsed .g-nav-submenu .g-nav-label {
    display: block;
}

.g-shell.is-collapsed .g-nav-link {
    justify-content: center;
    padding: 9px 0;
}

.g-shell.is-collapsed .g-nav-group + .g-nav-group {
    margin-top: var(--g-space-2);
    padding-top: var(--g-space-2);
    border-top: 1px solid var(--g-border);
}

.g-sidebar-footer {
    padding: var(--g-space-2) var(--g-space-3);
    border-top: 1px solid var(--g-border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--g-space-2);
    font-family: var(--g-font-data);
    font-size: var(--g-text-xs);
    color: var(--g-text-subtle);
}

.g-shell.is-collapsed .g-sidebar-footer {
    justify-content: center;
    padding: var(--g-space-2) var(--g-space-1);
}

.g-shell.is-collapsed .g-sidebar-footer .g-sidebar-footer-label {
    display: none;
}

.g-sidebar-logout {
    width: 100%;
}

.g-sidebar-logout svg {
    width: 15px;
    height: 15px;
    flex: none;
}

.g-shell.is-collapsed .g-sidebar-logout {
    padding-inline: 0;
    justify-content: center;
}

/* ---------------------------------------------------------------------------
   Main column
   --------------------------------------------------------------------------- */
.g-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    background: var(--g-surface);
}

.g-topbar {
    display: flex;
    align-items: center;
    gap: var(--g-space-3);
    padding: var(--g-space-2) var(--g-space-5);
    border-bottom: 1px solid var(--g-border);
    background: var(--g-surface);
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 53px;
}

.g-topbar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--g-border);
    background: var(--g-surface);
    border-radius: var(--g-radius-sm);
    color: var(--g-text-muted);
    cursor: pointer;
}

.g-topbar-toggle svg {
    width: 16px;
    height: 16px;
}

.g-topbar-search {
    flex: 1;
    max-width: 380px;
    min-width: 0;
}

.g-topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--g-space-3);
}

.g-topbar-user {
    display: flex;
    align-items: center;
    gap: var(--g-space-2);
    min-width: 0;
}

.g-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--g-accent-wash);
    color: var(--g-accent);
    display: grid;
    place-items: center;
    font-family: var(--g-font-data);
    font-size: var(--g-text-xs);
    font-weight: 700;
    flex: none;
}

.g-topbar-name {
    font-size: var(--g-text-sm);
    font-weight: 560;
    color: var(--g-text);
    line-height: 1.3;
    white-space: nowrap;
}

/* Notification bell — markup lives in Shared/NotificationBell.razor, whose
   scoped sheet styles only the dropdown. The trigger button was styled by
   AdminTopBar.razor.css, so it moves here with that file's deletion. */
.g-topbar-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--g-border);
    background: var(--g-surface);
    border-radius: var(--g-radius-sm);
    color: var(--g-text-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.g-topbar-bell:hover {
    background: var(--g-surface-2);
    color: var(--g-text);
}

.g-topbar-bell svg {
    width: 16px;
    height: 16px;
}

.g-topbar-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: var(--g-radius-pill);
    background: var(--g-alert);
    color: #fff;
    font-family: var(--g-font-data);
    font-variant-numeric: tabular-nums;
    font-size: 9.5px;
    font-weight: 700;
    display: grid;
    place-items: center;
    line-height: 1;
}

.g-topbar-role {
    font-family: var(--g-font-data);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--g-text-subtle);
    line-height: 1.3;
    white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Breadcrumb
   --------------------------------------------------------------------------- */
.g-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--g-space-2);
    padding: var(--g-space-2) var(--g-space-5);
    border-bottom: 1px solid var(--g-border);
    font-size: var(--g-text-sm);
    color: var(--g-text-subtle);
    background: var(--g-surface);
}

.g-breadcrumb-link {
    color: var(--g-text-muted);
    text-decoration: none;
}

.g-breadcrumb-link:hover {
    color: var(--g-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.g-breadcrumb-link + .g-breadcrumb-link::before,
.g-breadcrumb-link + .g-breadcrumb-current::before {
    content: "/";
    margin-right: var(--g-space-2);
    color: var(--g-border-strong);
}

.g-breadcrumb-current {
    color: var(--g-text);
    font-weight: 550;
}

/* ---------------------------------------------------------------------------
   Content well & footer
   --------------------------------------------------------------------------- */
.g-content {
    padding: var(--g-space-5);
    flex: 1;
    min-width: 0;
    background: var(--g-bg);
}

.g-shell-footer {
    border-top: 1px solid var(--g-border);
    padding: var(--g-space-3) var(--g-space-5);
    color: var(--g-text-subtle);
    font-size: var(--g-text-sm);
    background: var(--g-surface);
}

/* Page header used at the top of most content pages */
.g-page-head {
    display: flex;
    align-items: flex-start;
    gap: var(--g-space-3);
    flex-wrap: wrap;
    margin-bottom: var(--g-space-4);
}

.g-page-head h1 {
    margin: 0;
    font-size: var(--g-text-xl);
    font-weight: 640;
    letter-spacing: -0.02em;
}

.g-page-head p {
    margin: 2px 0 0;
    color: var(--g-text-muted);
    font-size: var(--g-text-base);
}

.g-page-head-actions {
    margin-left: auto;
    display: flex;
    gap: var(--g-space-2);
    flex-wrap: wrap;
}

/* Pre-auth placeholder shown while the admin JWT session is verified. */
.g-shell-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--g-bg);
    color: var(--g-text-muted);
}

/* ---------------------------------------------------------------------------
   Off-canvas overlay (mobile)
   --------------------------------------------------------------------------- */
.g-overlay {
    display: none;
}

@media (max-width: 1024px) {
    .g-shell,
    .g-shell.is-collapsed {
        grid-template-columns: 1fr;
    }

    .g-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 40;
    }

    .g-shell.is-mobile-open .g-sidebar {
        transform: translateX(0);
    }

    /* A collapsed desktop rail must not stay collapsed once it becomes the
       off-canvas drawer, or the drawer opens as a 68px icon strip. */
    .g-shell.is-collapsed .g-nav-title,
    .g-shell.is-collapsed .g-nav-label,
    .g-shell.is-collapsed .g-nav-tail,
    .g-shell.is-collapsed .g-brand-logo-full,
    .g-shell.is-collapsed .g-sidebar-footer-label {
        display: initial;
    }

    .g-shell.is-collapsed .g-nav-link {
        justify-content: flex-start;
        padding: 7px var(--g-space-2);
    }

    /* The drawer is full width, so undo the collapsed rail's stacked brand. */
    .g-shell.is-collapsed .g-brand {
        flex-direction: row;
        justify-content: space-between;
        padding: var(--g-space-3);
    }

    .g-shell.is-collapsed .g-brand-logo-icon {
        display: none;
    }

    .g-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(11, 15, 20, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
        z-index: 30;
    }

    .g-shell.is-mobile-open .g-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .g-topbar-toggle {
        display: inline-flex;
    }
}

@media (max-width: 640px) {
    .g-content {
        padding: var(--g-space-4);
    }

    .g-topbar,
    .g-breadcrumb,
    .g-shell-footer {
        padding-left: var(--g-space-4);
        padding-right: var(--g-space-4);
    }

    .g-topbar-name,
    .g-topbar-role {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .g-sidebar,
    .g-overlay,
    .g-collapse svg,
    .g-nav-chevron {
        transition: none;
    }
}
