/* The application shell: navigation, top bar, page header band and page container.
   Breakpoints: phone below 768px, tablet 768px to 1227px, desktop from 1228px.
   One state class on .nx-app drives the navigation: is-nav-open.
     desktop: open = full navigation beside the page, closed = rail of area tiles
     tablet:  closed = rail, open = full navigation floating over the page
     phone:   closed = hidden, open = drawer floating over the page */

/* Values derived from the current area. Declared wherever data-area is set so they follow it. */
[data-area] {
    --nx-area-sub: color-mix(in srgb, var(--nx-area-strong) 10%, var(--nx-chrome));
}

.nx-app {
    min-height: 100vh;
}

.nx-main {
    min-height: 100vh;
    margin-left: var(--nx-rail-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left var(--nx-base);
}

.nx-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---------- Navigation: full height, beside the top bar ---------- */

.nx-nav {
    position: fixed;
    z-index: var(--nx-z-nav);
    inset: 0 auto 0 0;
    width: var(--nx-nav-width);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--nx-chrome);
    color: var(--nx-chrome-strong);
    transition: width var(--nx-base);
}

/* The organisation's logo, centred over the navigation's width and level with the top bar. */
.nx-nav-brand {
    position: relative;
    flex: none;
    height: var(--nx-topbar-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    color: var(--nx-chrome-strong);
    font-size: var(--nx-size-lg);
    line-height: var(--nx-leading-tight);
    font-weight: var(--nx-weight-strong);
    text-align: center;
}

.nx-nav-brand-logo {
    min-width: 0;
    max-width: 100%;
    max-height: 40px;
    object-fit: contain;
}

.nx-nav-brand-logo, .nx-nav-brand-name {
    transition: opacity var(--nx-base), visibility var(--nx-base);
}

/* A long organisation name takes a second line; only a third line's worth is cut, and the tooltip has it all. */
.nx-nav-brand-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.nx-nav-close {
    display: none;
    position: absolute;
    top: 9px;
    right: 4px;
    width: var(--nx-control-touch);
    height: var(--nx-control-touch);
}

.nx-nav-groups {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--nx-space-2);
}

.nx-nav-heading {
    padding: 10px 18px 4px;
    font-size: var(--nx-size-2xs);
    font-weight: var(--nx-weight-strong);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--nx-chrome-heading);
    max-height: 32px;
    overflow: hidden;
    white-space: nowrap;
    transition: max-height var(--nx-base), padding var(--nx-base), margin var(--nx-base), color var(--nx-base), background var(--nx-base);
}

.nx-nav-group + .nx-nav-group {
    padding-top: var(--nx-space-2);
}

/* Administration areas are pinned to the foot, under a rule. */
.nx-nav-group--foot {
    margin-top: auto;
    border-top: 1px solid var(--nx-chrome-line);
}

.nx-nav-areas {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nx-nav-area {
    position: relative;
}

.nx-nav-row {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: var(--nx-space-3);
    padding: 0 18px;
    border: 0;
    background: none;
    color: inherit;
    font-weight: var(--nx-weight-strong);
    text-align: left;
    text-decoration: none;
    overflow: hidden;
}

.nx-nav-row:hover {
    background: var(--nx-chrome-hover);
    color: var(--nx-chrome-strong);
    text-decoration: none;
}

.nx-nav-row:focus-visible, .nx-nav-sub a:focus-visible {
    outline-color: var(--nx-chrome-strong);
    outline-offset: -2px;
}

.nx-nav-tile {
    flex: none;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    background: var(--nx-area);
    color: var(--nx-text-on-solid);
}

.nx-nav-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity var(--nx-base);
}

.nx-nav-chevron {
    flex: none;
    opacity: .7;
    transition: transform var(--nx-base), opacity var(--nx-base);
}

.nx-nav-area.is-open .nx-nav-chevron {
    transform: rotate(90deg);
}

/* The area you are in: its row is filled edge to edge with its own colour. */
.nx-nav-area.is-current > .nx-nav-row {
    background: var(--nx-area-strong);
    color: var(--nx-area-on-strong);
}

.nx-nav-area.is-current .nx-nav-tile {
    background: rgba(255, 255, 255, .22);
    color: var(--nx-area-on-strong);
}

/* Sub-sections sit close to the left edge on a faint tint of the area colour. An area opens and closes by
   growing its row of the grid from nothing to the height of its pages. */
.nx-nav-subwrap {
    display: grid;
    grid-template-rows: 0fr;
    overflow: hidden;
    visibility: hidden;
    background: var(--nx-area-sub);
    transition: grid-template-rows var(--nx-base) ease-out, visibility var(--nx-base);
}

.nx-nav-area.is-open > .nx-nav-subwrap {
    grid-template-rows: 1fr;
    visibility: visible;
}

.nx-nav-sub {
    min-height: 0;
    list-style: none;
    margin: 0;
    padding: 6px 0 8px;
}

.nx-nav-sub-title {
    display: none;
}

.nx-nav-sub a {
    position: relative;
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 0 18px 0 40px;
    color: var(--nx-chrome-text);
    font-size: var(--nx-size-sm);
    text-decoration: none;
}

.nx-nav-sub a:hover {
    background: var(--nx-chrome-hover);
    color: var(--nx-chrome-strong);
}

/* The page you are on: full-width highlight, white bold text, area-colour pip in the gutter. */
.nx-nav-sub a.is-current {
    background: var(--nx-chrome-selected);
    color: var(--nx-chrome-strong);
    font-weight: var(--nx-weight-strong);
}

.nx-nav-sub a.is-current::before {
    content: "";
    position: absolute;
    left: 23px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -3.5px;
    border-radius: 50%;
    background: var(--nx-area);
}

/* The foot: version on one line, legal links under it, centred above nothing but a separator. */
.nx-nav-foot {
    flex: none;
    margin: var(--nx-space-4) 18px 0;
    padding: var(--nx-space-4) 0 18px;
    border-top: 1px solid var(--nx-chrome-line);
    font-size: var(--nx-size-xs);
    color: var(--nx-chrome-strong);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--nx-base), visibility var(--nx-base);
}

.nx-nav-foot-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 6px;
    margin-top: 2px;
    color: var(--nx-chrome-muted);
}

.nx-nav-foot a {
    color: inherit;
    text-decoration: none;
}

.nx-nav-foot a:hover {
    color: var(--nx-chrome-strong);
    text-decoration: underline;
}

.nx-nav .nx-iconbtn {
    color: inherit;
}

.nx-nav .nx-iconbtn:hover {
    background: var(--nx-chrome-hover);
    color: var(--nx-chrome-strong);
}

.nx-scrim {
    display: none;
    position: fixed;
    z-index: calc(var(--nx-z-nav) - 1);
    inset: 0;
    background: var(--nx-scrim);
}

/* Desktop: the open navigation pushes the page. */
@media (min-width: 1228px) {
    .nx-app.is-nav-open .nx-main {
        margin-left: var(--nx-nav-width);
    }
}

/* Tablet and desktop, navigation closed: a rail of area tiles. Hover or focus shows the area's pages. */
@media (min-width: 768px) {
    .nx-app:not(.is-nav-open) .nx-nav {
        width: var(--nx-rail-width);
        overflow: visible;
    }

    /* Rows keep their padding, so the tiles stay where they are while the navigation narrows; what is beside
       them fades as it is cut off. */
    .nx-app:not(.is-nav-open) .nx-nav-brand-name,
    .nx-app:not(.is-nav-open) .nx-nav-brand-logo,
    .nx-app:not(.is-nav-open) .nx-nav-label,
    .nx-app:not(.is-nav-open) .nx-nav-chevron,
    .nx-app:not(.is-nav-open) .nx-nav-foot {
        opacity: 0;
        visibility: hidden;
    }

    .nx-app:not(.is-nav-open) .nx-nav-foot {
        position: absolute;
        pointer-events: none;
    }

    /* On the rail a rule stands in for the group headings; the first group has none. */
    .nx-app:not(.is-nav-open) .nx-nav-heading {
        max-height: 1px;
        padding: 0;
        margin: 0 14px var(--nx-space-2);
        background: var(--nx-chrome-line);
        color: transparent;
    }

    .nx-app:not(.is-nav-open) .nx-nav-group:first-child .nx-nav-heading {
        max-height: 0;
        margin: 0;
    }

    .nx-app:not(.is-nav-open) .nx-nav-area > .nx-nav-subwrap {
        display: none;
        grid-template-rows: 1fr;
        visibility: visible;
        position: absolute;
        z-index: var(--nx-z-popover);
        left: var(--nx-rail-width);
        top: 0;
        width: 220px;
        border-radius: 0 10px 10px 0;
        box-shadow: var(--nx-shadow-3);
        transition: none;
    }

    .nx-app:not(.is-nav-open) .nx-nav-sub {
        padding: 0 0 8px;
    }

    /* An area pinned to the foot opens its pages upwards so they stay on the screen. */
    .nx-app:not(.is-nav-open) .nx-nav-group--foot .nx-nav-area > .nx-nav-subwrap {
        top: auto;
        bottom: 0;
    }

    .nx-app:not(.is-nav-open) .nx-nav-area:hover > .nx-nav-subwrap,
    .nx-app:not(.is-nav-open) .nx-nav-area:focus-within > .nx-nav-subwrap {
        display: grid;
    }

    .nx-app:not(.is-nav-open) .nx-nav-sub-title {
        height: 44px;
        display: flex;
        align-items: center;
        padding: 0 18px;
        margin-bottom: 6px;
        background: var(--nx-area-strong);
        color: var(--nx-area-on-strong);
        font-weight: var(--nx-weight-strong);
    }

    .nx-app:not(.is-nav-open) .nx-nav-sub a {
        padding-left: 18px;
    }

    .nx-app:not(.is-nav-open) .nx-nav-sub a.is-current {
        padding-left: 40px;
    }
}

/* Tablet and phone, navigation open: it floats over a dimmed page, top bar included. */
@media (max-width: 1227px) {
    .nx-app.is-nav-open .nx-nav {
        box-shadow: var(--nx-shadow-3);
    }

    .nx-app.is-nav-open .nx-scrim {
        display: block;
    }

    .nx-app.is-nav-open .nx-nav-close {
        display: grid;
    }
}

/* Phone: no rail. */
@media (max-width: 767px) {
    .nx-main {
        margin-left: 0;
    }

    .nx-app:not(.is-nav-open) .nx-nav {
        display: none;
    }

    .nx-nav {
        width: min(300px, 86vw);
    }

    .nx-nav-row {
        min-height: 48px;
    }

    .nx-nav-sub a {
        min-height: 40px;
        font-size: var(--nx-size-md);
    }
}

/* ---------- Top bar: one step darker than the navigation, with the area's stripe under it ---------- */

.nx-topbar {
    position: sticky;
    z-index: var(--nx-z-sticky);
    top: 0;
    flex: none;
    height: var(--nx-topbar-height);
    display: flex;
    align-items: center;
    gap: var(--nx-space-3);
    padding: 0 var(--nx-space-4) 0 10px;
    border-bottom: var(--nx-stripe) solid var(--nx-area);
    background: var(--nx-chrome-raised);
    color: var(--nx-chrome-strong);
}

.nx-topbar .nx-iconbtn {
    width: var(--nx-control-touch);
    height: var(--nx-control-touch);
    color: inherit;
}

.nx-topbar .nx-iconbtn:hover, .nx-topbar .nx-iconbtn[aria-expanded="true"] {
    background: var(--nx-chrome-field);
    color: var(--nx-chrome-strong);
}

.nx-topbar .nx-iconbtn:disabled {
    opacity: .55;
    cursor: default;
    background: none;
}

.nx-topbar :focus-visible {
    outline-color: var(--nx-chrome-strong);
}

/* Phone: the trigger says where you are (area tile and page name) and opens the navigation. */
.nx-topbar-area {
    display: none;
    height: var(--nx-control-touch);
    align-items: center;
    gap: var(--nx-space-2);
    min-width: 0;
    padding: 0 10px 0 8px;
    border: 0;
    border-radius: var(--nx-radius-control);
    background: var(--nx-chrome-field);
    color: var(--nx-chrome-strong);
    font-weight: var(--nx-weight-strong);
}

.nx-topbar-area .nx-nav-tile {
    background: var(--nx-area-strong);
    color: var(--nx-area-on-strong);
}

.nx-topbar-area span:not(.nx-nav-tile) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nx-search {
    flex: 1 1 320px;
    max-width: 560px;
    height: var(--nx-control);
    display: flex;
    align-items: center;
    gap: var(--nx-space-2);
    padding: 0 var(--nx-space-3);
    border-radius: var(--nx-radius-control);
    background: var(--nx-chrome-field);
    color: var(--nx-chrome-strong);
}

.nx-search input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: 0;
    background: none;
}

.nx-search input::placeholder {
    color: var(--nx-chrome-text);
    opacity: 1;
}

.nx-search:focus-within {
    outline: 2px solid var(--nx-chrome-strong);
    outline-offset: 1px;
}

.nx-search-key {
    flex: none;
    padding: 2px 6px;
    border: 1px solid var(--nx-chrome-key);
    border-radius: 4px;
    font-family: inherit;
    font-size: var(--nx-size-2xs);
    color: var(--nx-chrome-text);
}

.nx-topbar-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--nx-space-1);
}

/* New is an add button on the chrome: it stays solid blue there. */
.nx-topbar-new {
    height: var(--nx-control);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    margin-right: var(--nx-space-2);
    border: 0;
    border-radius: var(--nx-radius-control);
    background: var(--nx-add);
    color: var(--nx-text-on-solid);
    font-weight: var(--nx-weight-strong);
}

.nx-topbar-new:hover:not(:disabled) {
    background: var(--nx-add-hover);
}

.nx-topbar-new:disabled {
    opacity: .7;
    cursor: default;
}

.nx-topbar-who {
    height: var(--nx-control-touch);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0 var(--nx-space-2);
    margin-left: var(--nx-space-1);
    border: 0;
    border-radius: var(--nx-radius-control);
    background: none;
    color: var(--nx-chrome-strong);
    text-align: left;
}

.nx-topbar-who:hover, .nx-topbar-who[aria-expanded="true"] {
    background: var(--nx-chrome-field);
}

.nx-topbar-who .nx-avatar {
    background: var(--nx-chrome-avatar);
    color: var(--nx-text-on-solid);
}

.nx-topbar-who-text {
    display: flex;
    flex-direction: column;
    line-height: var(--nx-leading-tight);
    max-width: 200px;
}

.nx-topbar-who-text span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nx-topbar-who-name {
    font-size: var(--nx-size-sm);
    font-weight: var(--nx-weight-strong);
}

.nx-topbar-who-org {
    font-size: var(--nx-size-2xs);
    color: var(--nx-chrome-text);
}

@media (max-width: 1000px) {
    .nx-topbar-extra, .nx-search-key {
        display: none;
    }
}

@media (max-width: 767px) {
    .nx-topbar {
        padding: 0 var(--nx-space-2) 0 var(--nx-space-3);
        gap: var(--nx-space-2);
    }

    .nx-topbar-toggle, .nx-search, .nx-topbar-new, .nx-topbar-who-text, .nx-topbar-who-chevron {
        display: none;
    }

    .nx-topbar-area {
        display: inline-flex;
    }
}

/* ---------- Page header: a white band with breadcrumb, title, actions and tabs ---------- */

.nx-header {
    flex: none;
    padding: 14px var(--nx-space-6) 0;
    border-bottom: 1px solid var(--nx-line);
    background: var(--nx-surface);
    --nx-on-grey: initial;
}

.nx-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: var(--nx-size-xs);
    color: var(--nx-text-muted);
}

.nx-crumbs a {
    font-weight: var(--nx-weight-strong);
}

.nx-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--nx-space-3) var(--nx-space-6);
    padding: var(--nx-space-3) 0 14px;
}

.nx-header-lead {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.nx-back {
    flex: none;
    width: var(--nx-control);
    height: var(--nx-control);
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--nx-action-edge);
    border-radius: var(--nx-radius-control);
    background: var(--nx-action);
    color: var(--nx-text);
}

.nx-back:hover {
    background: var(--nx-action-hover);
}

/* The record's own mark beside its title: a contact's initials on the area tint. */
.nx-header-tile {
    flex: none;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: var(--nx-radius-card);
    background: var(--nx-area-tint);
    color: var(--nx-area-ink);
    font-size: 16px;
    font-weight: var(--nx-weight-strong);
    overflow: hidden;
}

.nx-header-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.nx-header-titles {
    min-width: 0;
}

.nx-header-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px var(--nx-space-3);
}

.nx-tabsrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nx-space-2) var(--nx-space-4);
}

.nx-tabsrow > .nx-tabs {
    flex: 1 1 auto;
    min-width: 0;
}

.nx-tabsrow-end {
    flex: none;
    display: flex;
    align-items: center;
    gap: 2px;
    padding-bottom: 2px;
}

.nx-header-meta, .nx-header-des {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px var(--nx-space-3);
    margin-top: var(--nx-space-1);
    font-size: var(--nx-size-sm);
    color: var(--nx-text-muted);
}

.nx-header-actions {
    display: flex;
    align-items: center;
    gap: var(--nx-space-2);
    flex-wrap: wrap;
}

/* Tabs: an underline in the area colour marks the one you are on. */
.nx-tabs {
    display: flex;
    gap: var(--nx-space-1);
    overflow-x: auto;
    font-size: var(--nx-size-sm);
}

.nx-tab {
    flex: none;
    padding: 10px var(--nx-space-3);
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--nx-text-soft);
    text-decoration: none;
    white-space: nowrap;
}

.nx-tab:hover {
    color: var(--nx-ink);
    border-bottom-color: var(--nx-line-strong);
    text-decoration: none;
}

.nx-tab.is-current {
    border-bottom-color: var(--nx-area);
    color: var(--nx-area-ink);
    font-weight: var(--nx-weight-strong);
}

.nx-tab:disabled, .nx-tab[aria-disabled="true"] {
    opacity: .55;
    cursor: default;
    pointer-events: none;
}

.nx-tab-count {
    margin-left: 6px;
    font-size: var(--nx-size-xs);
    font-weight: var(--nx-weight);
    color: var(--nx-text-muted);
}

/* ---------- Page ---------- */

/* The page is the grey ground: a secondary button straight on it is white. Cards put the white back. */
.nx-page {
    flex: 1 1 auto;
    width: 100%;
    max-width: var(--nx-page-max);
    display: flex;
    flex-direction: column;
    gap: var(--nx-space-5);
    padding: var(--nx-space-5) var(--nx-space-6) var(--nx-space-6);
    --nx-on-grey: var(--nx-surface);
}

.nx-page--form {
    max-width: var(--nx-form-max);
    gap: var(--nx-space-8);
    padding-top: var(--nx-space-6);
}

/* Created and last modified, at the very end of a record's page. */
.nx-page-stamp {
    margin-top: auto;
    font-size: var(--nx-size-xs);
    color: var(--nx-text-muted);
}

.nx-cols {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--nx-space-5);
    align-items: start;
}

.nx-cols--even {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.nx-stack {
    display: flex;
    flex-direction: column;
    gap: var(--nx-space-5);
    min-width: 0;
}

.nx-row {
    display: flex;
    align-items: center;
    gap: var(--nx-space-2);
    flex-wrap: wrap;
}

.nx-grow {
    flex: 1 1 auto;
    min-width: 0;
}

@media (max-width: 1000px) {
    .nx-cols, .nx-cols--even {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 767px) {
    .nx-header {
        padding: var(--nx-space-3) var(--nx-space-4) 0;
    }

    .nx-header h1 {
        font-size: var(--nx-size-2xl);
    }

    .nx-page {
        gap: var(--nx-space-4);
        padding: var(--nx-space-4);
    }
}

/* ---------- Pages outside the shell (not found, start-up) ---------- */

.nx-plain {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--nx-space-6);
}

.nx-plain-box {
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--nx-space-3);
}

/* A form page: the form fills the page so its save bar rests at the end of the form. */
.nx-formpage {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* A dashboard has no header band: its panels sit straight on the ground. */
.nx-page--dashboard {
    max-width: none;
}
