/*
    Flex Hub layout shells.

    One structural breakpoint at 900px, one responsive view per route. Below 900px the desktop
    rail becomes an app bar plus a drawer, and a dock takes the bottom of the screen. The
    divergence is deliberate: desktop leads with status, the phone leads with capture.

    Every surface of the shell chrome, the rail, the app bar, the drawer account block and the
    phone page headers, sits on --surface-nav. Teal appears only in the lockup subtitle.

    Mobile first. The min-width block at the bottom is the desktop side.

    Token-table values come through custom properties from tokens.css.
*/

/* ---- Page frame ---- */

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--surface-body);
    color: var(--text-body);
    font: var(--font-body-mobile);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--teal);
    text-decoration: none;
}

/*
    The shell fills the viewport and only the main region scrolls. 100dvh follows the mobile
    browser bars as they show and hide, and 100vh is the fallback where dvh is not supported.
*/
.hub-shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.hub-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
}

/* ---- Brand lockup, shared by the rail and the app bar ---- */

.hub-lockup {
    display: flex;
    align-items: center;
    gap: 11px;
}

/* The text block shrinks to the wordmark, so the subtitle centres under the wordmark itself. */
.hub-lockup__text {
    line-height: 1.05;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* The 32px mark is the same file in the rail head and in the app bar. */
.hub-lockup__mark {
    flex: none;
    display: block;
}

.hub-lockup__wordmark {
    font: var(--font-nav-wordmark-mobile);
    color: var(--text-primary);
    letter-spacing: var(--tracking-wordmark);
}

.hub-lockup__subtitle {
    font: var(--font-lockup-subtitle);
    letter-spacing: var(--tracking-lockup-subtitle);
    color: var(--teal);
}

/*
    ---- Navigation icons, shared by the rail and the drawer ----

    The Dashboard, LineSight and User Accounts marks are all inline SVG drawn on currentColor. The
    rail and the drawer use the same drawings at their own sizes, so this stylesheet only sizes the
    shared box.
*/

.hub-icon {
    flex: none;
}

/* The LineSight mark is an inline SVG drawn in _LineSightIcon.cshtml. Size is an attribute on the
   element, color is currentColor from the nav item. */
.hub-icon--linesight {
    display: block;
}

/* ---- Mobile app bar ---- */
/* The app bar and drawer controls use the rail item colours. */

.hub-appbar {
    background: var(--surface-nav);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 11px;
    flex: none;
}

.hub-appbar .hub-lockup__wordmark {
    font: var(--font-nav-wordmark-appbar);
}

.hub-appbar__menu {
    margin-left: auto;
    width: var(--size-hit-target-gloves);
    height: var(--size-hit-target-gloves);
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4.5px;
    padding: 0;
    cursor: pointer;
}

.hub-appbar__menu span {
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: var(--nav-item);
}

.hub-appbar__menu:hover span {
    background: var(--nav-item-hover);
}

/* ---- Mobile drawer ---- */

.hub-drawer {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
}

.hub-drawer.is-open {
    display: block;
}

.hub-drawer__scrim {
    position: absolute;
    inset: 0;
    background: var(--scrim);
    border: 0;
    width: 100%;
    padding: 0;
    cursor: pointer;
}

.hub-drawer__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--drawer-width);
    max-width: 88%;
    background: var(--surface-drawer);
    border-left: 1px solid var(--border-structural);
    box-shadow: -24px 0 50px -12px rgba(0, 0, 0, .6);
    display: flex;
    flex-direction: column;
}

/*
    Closes the drawer from where the menu button was. The panel sits over the app bar, so the
    button lands on the same spot at the same size, and a tap on the corner that opened the drawer
    closes it again.
*/
.hub-drawer__close {
    position: absolute;
    top: 8px;
    right: 16px;
    width: var(--size-hit-target-gloves);
    height: var(--size-hit-target-gloves);
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
}

.hub-drawer__close span {
    position: absolute;
    width: 18px;
    height: 2px;
    border-radius: 1px;
    background: var(--nav-item);
}

.hub-drawer__close:hover span {
    background: var(--nav-item-hover);
}

.hub-drawer__close span:first-child {
    transform: rotate(45deg);
}

.hub-drawer__close span:last-child {
    transform: rotate(-45deg);
}

/* The whole header block is the tap target for the user's own profile. The right padding keeps
   the chevron clear of the close button that sits over the block's corner. */
.hub-drawer__account {
    background: var(--surface-nav);
    padding: 18px 76px 16px 18px;
    flex: none;
    display: flex;
    align-items: center;
    gap: 12px;
}

.hub-drawer__avatar {
    width: 52px;
    height: 52px;
    flex: none;
    border-radius: 50%;
    background: var(--avatar);
    display: flex;
    align-items: center;
    justify-content: center;
    font: 600 15px var(--font-mono);
    color: var(--avatar-text);
}

.hub-drawer__name {
    font: var(--font-drawer-name);
    color: var(--text-primary);
    margin-bottom: 3px;
}

.hub-drawer__role {
    font: 400 11px var(--font-mono);
    color: var(--text-muted);
}

.hub-drawer__chevron {
    margin-left: auto;
    font: 500 13px var(--font-mono);
    color: var(--text-muted);
}

.hub-drawer__nav {
    padding: 14px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.hub-drawer__group-label {
    font: var(--font-drawer-group-label);
    letter-spacing: var(--tracking-drawer-group-label);
    text-transform: uppercase;
    color: var(--text-disabled);
    padding: 0 8px;
    margin-bottom: 5px;
}

.hub-drawer__item {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--size-drawer-nav-item);
    padding: 0 12px;
    border-radius: var(--radius-field-mobile);
    color: var(--text-tertiary);
}

.hub-drawer__item-label {
    font: var(--font-nav-item-mobile);
    color: var(--text-body);
}

.hub-drawer__item.is-active {
    background: var(--accent-fill-nav-active);
    border: 1px solid var(--accent-keyline-nav-active);
    color: var(--accent);
}

.hub-drawer__item.is-active .hub-drawer__item-label {
    font: var(--font-nav-item-mobile-active);
    color: var(--text-nav-active-mobile);
}

.hub-drawer__divider {
    height: 1px;
    background: var(--drawer-divider);
    margin: 11px 8px;
}

/*
    Log out is a submit button inside a post form, so the button's own chrome is reset back to the
    row it replaced. The width keeps it as wide as the nav items above it.
*/
.hub-drawer__logout {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: var(--size-hit-target-gloves);
    padding: 0 12px;
    border: none;
    border-radius: var(--radius-field-mobile);
    background: none;
    text-align: left;
    cursor: pointer;
}

.hub-drawer__logout-glyph {
    font: 500 13px var(--font-mono);
    color: var(--text-muted);
    width: 19px;
    text-align: center;
    flex: none;
}

.hub-drawer__logout-label {
    font: 500 13.5px var(--font-ui);
    color: var(--text-drawer-logout);
}

.hub-drawer__footer {
    padding: 14px 20px 18px;
    border-top: 1px solid var(--drawer-divider);
    flex: none;
    display: flex;
    align-items: center;
    gap: 9px;
    font: var(--font-data);
    color: var(--text-drawer-footer);
}

.hub-drawer__footer-right {
    margin-left: auto;
}

/* ---- Mobile dock ---- */
/*
    The dock owns the bottom of the phone screen. There is no bottom tab bar. Screens fill the
    dock through the Dock section. The shell only owns the surface it sits on.
*/

.hub-dock {
    flex: none;
    border-top: 1px solid var(--border-structural);
    background: var(--surface-dock);
    padding: 12px 16px 16px;
}

/* ---- Desktop navigation rail (hidden below the breakpoint) ---- */

.hub-sidebar {
    display: none;
}

/*
    ---- Page head ----

    Desktop page headers align with the navigation rail header. The bar grows when its content does
    not fit. On the phone it is the page title above the page body, with the page inset.
*/

.hub-page-head {
    padding: 14px 16px 0;
}

.hub-page-head__title {
    font: var(--font-page-title-mobile);
    letter-spacing: var(--tracking-title);
    color: var(--text-primary);
    margin: 0 0 10px;
}

/* ---- Placeholder content ---- */

/* The page inset sits on the parts, so the head can run edge to edge at the wide breakpoint. */
.hub-placeholder {
    padding: 0;
}

.hub-placeholder__body {
    font: var(--font-body-mobile);
    color: var(--text-tertiary);
    max-width: 560px;
    margin: 0;
    padding: 0 16px 14px;
}

/*
    The auth screens have no signed-in chrome and no shell of their own here. Their spotlight frame
    lives in auth.css, which only the auth views pull in.
*/

/* ---- Error page frame, no signed-in chrome ---- */

.hub-error {
    min-height: 100vh;
    background: var(--surface-login);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.hub-error__card {
    width: 100%;
    max-width: 380px;
    background: var(--surface-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-panel);
    padding: 28px 24px;
}

.hub-error__title {
    font: var(--font-page-title-mobile);
    letter-spacing: var(--tracking-title);
    color: var(--text-primary);
    margin: 0 0 10px;
}

.hub-error__note {
    font: var(--font-body-mobile);
    color: var(--text-muted);
    margin: 0;
}

/* ---- Desktop ---- */

@media (min-width: 900px) {

    body {
        font: var(--font-body);
    }

    .hub-shell {
        flex-direction: row;
    }

    .hub-appbar,
    .hub-dock,
    .hub-drawer {
        display: none;
    }

    /*
        ---- Navigation rail ----

        One component with two states. Expanded is 212px and collapsed is 64px, and the glyph
        column sits in the same place at both widths, so a toggle moves no glyph. Hub opens
        expanded.

        The state is the class hub-nav-collapsed on the html element. An inline script in the head
        applies it from localStorage before first paint, so the rail never renders at one width and
        then jumps to the other.
    */
    .hub-sidebar {
        width: var(--nav-width-expanded);
        flex: none;
        box-sizing: border-box;
        background: var(--surface-nav);
        border-right: 1px solid var(--nav-divider);
        display: flex;
        flex-direction: column;
    }

    html.hub-nav-collapsed .hub-sidebar {
        width: var(--nav-width-collapsed);
    }

    /* ---- Rail head ---- */

    .hub-sidebar__brand {
        height: var(--nav-head);
        flex: none;
        box-sizing: border-box;
        padding: 0 16px;
        border-bottom: 1px solid var(--nav-divider);
        display: flex;
        align-items: center;
    }

    .hub-sidebar__brand .hub-lockup {
        gap: 10px;
    }

    .hub-sidebar .hub-lockup__wordmark {
        font: var(--font-nav-wordmark);
    }

    html.hub-nav-collapsed .hub-sidebar__brand {
        padding: 0;
        justify-content: center;
    }

    html.hub-nav-collapsed .hub-sidebar__brand .hub-lockup__text {
        display: none;
    }

    /* ---- Rail items ---- */

    /*
        Rows run the full width of the rail with no rounded ends and no gap between them. The
        glyph box is 24px and sits centred in the first 64px at both widths, which is what keeps
        the glyph column still across a toggle.
    */
    .hub-sidebar__item {
        position: relative;
        display: flex;
        align-items: center;
        gap: 14px;
        height: var(--nav-row);
        box-sizing: border-box;
        padding-left: 20px;
        color: var(--nav-item);
        font: var(--font-nav-item);
    }

    .hub-sidebar__brand + .hub-sidebar__item {
        margin-top: 8px;
    }

    .hub-sidebar__glyph {
        width: 24px;
        height: 24px;
        flex: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .hub-sidebar__item:hover {
        color: var(--nav-item-hover);
    }

    .hub-sidebar__item.is-active {
        background: var(--surface-nav-active);
        color: var(--nav-item-active);
        font: var(--font-nav-item-active);
    }

    /*
        An accent edge mark on the active item, matching the same rule in Flex Materials. The active
        fill alone reads as a hover on a dark rail, so the mark is what says which page is open.
        The drawer says the same thing with an accent fill and keyline, so this is desktop only.
    */
    .hub-sidebar__item.is-active::before {
        content: '';
        position: absolute;
        left: 0;
        top: 9px;
        bottom: 9px;
        width: 3px;
        background: var(--accent);
        border-radius: 0 2px 2px 0;
    }

    /* Dim LineSight when the resolved plant has no lines. */
    .hub-sidebar__item.is-dimmed {
        color: var(--text-disabled);
    }

    /* Collapsed, the label is clipped away but still read out as the link's name. */
    html.hub-nav-collapsed .hub-sidebar__item-label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    /* ---- Rail foot ---- */

    /*
        The foot sits at the bottom of the rail. The company logo with no line above it, a divider,
        then the account row with the collapse toggle at its right end. Collapsed, the logo is
        hidden, the account row centres the avatar and the toggle drops to its own row under a
        divider, so the toggle is the last thing in the rail at both widths.
    */
    .hub-sidebar__account-bar {
        position: relative;
        flex: none;
        box-sizing: border-box;
        height: 56px;
        padding: 0 12px 0 16px;
        border-top: 1px solid var(--nav-divider);
        display: flex;
        align-items: center;
    }

    /*
        The account block is a native details menu. The closed summary is styled as the row itself,
        so opening the menu moves nothing else in the rail. The menu is positioned against the bar
        rather than the summary so it can use the full width of the rail.
    */
    .hub-sidebar__account {
        flex: 1;
        min-width: 0;
    }

    .hub-sidebar__account-row {
        display: flex;
        align-items: center;
        gap: 10px;
        cursor: pointer;
        list-style: none;
    }

    .hub-sidebar__account-row::-webkit-details-marker {
        display: none;
    }

    .hub-sidebar__account[open] .hub-sidebar__avatar {
        box-shadow: 0 0 0 1px var(--accent);
    }

    .hub-sidebar__avatar {
        width: 32px;
        height: 32px;
        flex: none;
        border-radius: 50%;
        background: var(--avatar);
        color: var(--avatar-text);
        display: flex;
        align-items: center;
        justify-content: center;
        font: 600 11px var(--font-mono);
    }

    .hub-sidebar__account-text {
        line-height: 1.2;
        min-width: 0;
    }

    .hub-sidebar__account-name {
        font: 500 13px var(--font-ui);
        color: var(--text-primary);
    }

    .hub-sidebar__account-role {
        font: var(--font-data);
        color: var(--text-muted);
    }

    /*
        The 44px toggle sits inside the 56px account row, so it needs no margin of its own. The
        chevron pair points at the edge the rail is about to move towards.
    */
    .hub-sidebar__nav-toggle {
        flex: none;
        width: var(--size-hit-target-min);
        height: var(--size-hit-target-min);
        padding: 0;
        background: none;
        border: none;
        color: var(--nav-item);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    .hub-sidebar__nav-toggle:hover {
        color: var(--nav-item-hover);
    }

    html.hub-nav-collapsed .hub-sidebar__account-bar {
        margin-top: auto;
        height: auto;
        padding: 0;
        flex-direction: column;
        align-items: stretch;
    }

    html.hub-nav-collapsed .hub-sidebar__account-row {
        height: 56px;
        gap: 0;
        justify-content: center;
    }

    html.hub-nav-collapsed .hub-sidebar__account-text {
        display: none;
    }

    /* The toggle row counts its divider inside its 44px, so the rail keeps the same height. */
    html.hub-nav-collapsed .hub-sidebar__nav-toggle {
        width: auto;
        box-sizing: border-box;
        border-top: 1px solid var(--nav-divider);
    }

    html.hub-nav-collapsed .hub-sidebar__nav-toggle svg {
        transform: scaleX(-1);
    }

    /* ---- Account menu ---- */

    .hub-sidebar__account-menu {
        position: absolute;
        left: 0;
        right: 0;
        bottom: calc(100% + 8px);
        z-index: 40;
        padding: 12px;
        background: var(--surface-nav-active);
        border: 1px solid var(--border-card);
        border-radius: var(--radius-field);
        box-shadow: var(--shadow-menu);
    }

    /* Collapsed there is no room above the row, so the menu opens beside the rail. */
    html.hub-nav-collapsed .hub-sidebar__account-menu {
        left: calc(100% + 10px);
        right: auto;
        bottom: 0;
        min-width: 200px;
    }

    .hub-sidebar__account-menu-name {
        font: var(--font-card-title);
        color: var(--text-primary);
        margin-bottom: 10px;
    }

    /*
        The profile entry is the row above Log out. It wears the same box as the sign-out
        control so the two rows read as one menu.
    */
    .hub-sidebar__account-menu-item {
        display: block;
        padding: 8px 10px;
        margin-bottom: 6px;
        border: 1px solid var(--border-card);
        border-radius: var(--radius-control);
        background: var(--surface-card);
        font: var(--font-account-menu-item);
        color: var(--text-body);
    }

    .hub-sidebar__account-menu-item:hover {
        border-color: var(--accent-keyline-soft);
    }

    .hub-sidebar__signout {
        width: 100%;
        padding: 8px 10px;
        border: 1px solid var(--border-card);
        border-radius: var(--radius-control);
        background: var(--surface-card);
        font: var(--font-account-menu-item);
        color: var(--text-logout);
        text-align: left;
        cursor: pointer;
    }

    .hub-sidebar__signout:hover {
        border-color: var(--accent-keyline-soft);
    }

    .hub-sidebar__company {
        margin-top: auto;
        flex: none;
        padding: 14px 16px;
        display: flex;
        justify-content: center;
    }

    /*
        Taller and undimmed, because the wordmark inside the artwork is hard to read at a smaller
        size. At this height it is still well inside the column.
    */
    .hub-sidebar__company img {
        height: 74px;
        width: auto;
        opacity: 1;
        display: block;
    }

    html.hub-nav-collapsed .hub-sidebar__company {
        display: none;
    }

    .hub-page-head {
        min-height: var(--nav-head);
        box-sizing: border-box;
        padding: 0 26px;
        border-bottom: 1px solid var(--nav-divider);
        display: flex;
        align-items: center;
        gap: 16px;
    }

    .hub-page-head__title {
        font: var(--font-page-title);
        letter-spacing: var(--tracking-title);
        color: var(--text-primary);
        margin: 0;
    }

    .hub-placeholder__body {
        font: var(--font-body);
        padding: 24px 26px;
    }

    .hub-error__title {
        font: var(--font-page-title);
    }

    .hub-error__note {
        font: var(--font-body);
    }
}
