/* The four layouts (docs/ux/design-system.md). */

.app-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 56px;
    padding: var(--space-2) var(--space-4);
    padding-top: max(var(--space-2), env(safe-area-inset-top));
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.app-bar__brand {
    display: flex;
    align-items: center;
    min-height: var(--tap);
    gap: var(--space-2);
    color: var(--color-ink);
    font-family: var(--font-heading);
    word-spacing: var(--heading-word-spacing);
    font-weight: 750;
    text-decoration: none;
}

.app-bar__spacer {
    flex: 1;
}

.page {
    width: 100%;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4) var(--space-7);
}

/* auth: a centred card, the brand above, legal links below */
.layout-auth .page {
    max-width: 480px;
    padding-top: var(--space-4);
}

.layout-auth .page--wide {
    max-width: 960px;
}

.layout-auth__brand {
    display: flex;
    justify-content: center;
    padding: var(--space-6) var(--space-4) 0;
}

.layout-auth__footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 var(--space-2);
    padding: 0 var(--space-4) var(--space-6);
    color: var(--color-muted);
    font-size: var(--text-sm);
}

.layout-auth__footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0 var(--space-2);
    color: var(--color-muted);
}

/* The two ways in stay one above the other inside the narrow auth column. */
.layout-auth .grid-cards {
    grid-template-columns: 1fr;
}

/* worker: content and a bottom tab bar */
.layout-worker .page {
    max-width: 640px;
    padding-bottom: calc(var(--space-7) + 64px);
}

.tab-bar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-bar__inner {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    max-width: 640px;
    margin: 0 auto;
}

/* On phones the keyboard pushes a fixed bar up over the field being typed in: hide it meanwhile (every layout with tabs). */
@media (max-width: 899px) {
    body:has(:is(input:not([type='checkbox'], [type='radio'], [type='submit'], [type='button']), select, textarea):focus) .tab-bar {
        display: none;
    }
}

.tab-bar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-height: 60px;
    padding: var(--space-1) 0;
    color: var(--color-muted);
    font-size: var(--text-xs);
    line-height: 1.2;
    text-align: center;
    font-weight: 600;
    text-decoration: none;
}

.tab-bar__icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 28px;
    border-radius: var(--radius-pill);
}

/* A number on a tab or side nav item (shifts nearby your staff can cover, LA21): a number, not a dot, so not colour alone. */
.tab-bar__icon {
    position: relative;
}

.nav-count {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-1);
    border-radius: var(--radius-pill);
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 1;
}

.tab-bar__icon .nav-count {
    position: absolute;
    top: -6px;
    right: 6px;
}

/* The current tab (its own page, or a page under it) is marked by a filled pill, weight and colour, not colour alone. */
.tab-bar__item[aria-current] {
    color: var(--color-primary-strong);
    font-weight: 750;
}

.tab-bar__item[aria-current] .tab-bar__icon {
    background: var(--color-primary-tint);
}

/* From 900 px the worker's tabs sit at the top, under the app bar. */
@media (min-width: 900px) {
    .layout-worker .tab-bar {
        position: sticky;
        top: 56px;
        inset: auto;
        border-top: 0;
        border-bottom: 1px solid var(--color-border);
    }

    .layout-worker .page {
        padding-bottom: var(--space-7);
    }
}

/* On phones Sign out lives on the Account or Settings page; the app bar keeps only the brand. */
@media (max-width: 899px) {
    .layout-worker .app-bar__signout,
    .layout-centre .app-bar__signout,
    .layout-admin .app-bar__signout {
        display: none;
    }
}

/* A card linked to by its id clears the sticky app bar. */
.card[id] {
    scroll-margin-top: calc(56px + var(--space-4));
}

/* centre and admin: side navigation from 900 px */
.layout-centre .page {
    max-width: 1100px;
}

/* Below 900 px the tab bar is fixed at the bottom: keep the last row clear of it. */
@media (max-width: 899px) {
    .layout-centre .page,
    .layout-admin .page {
        padding-bottom: calc(var(--space-7) + 64px);
    }
}

/* The centre's banners and notices, in the reading column, above the page. */
.page-notices {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.page-notices:has(> *) {
    margin-bottom: var(--space-4);
}

.page-notices .notices {
    margin-bottom: 0;
}

/* Forms and settings read in a column; lists may use the width (C28).
   Below 900 px the column is centred, under the centred tab bar (CB5). */
.layout-centre .page .narrow,
.layout-admin .page .narrow {
    max-width: 640px;
}

@media (max-width: 899px) {
    .layout-centre .page .narrow,
    .layout-admin .page .narrow {
        margin-inline: auto;
    }
}

/* Forced colours drop the pill's background: outline the current tab instead (CB15). */
@media (forced-colors: active) {
    .tab-bar__item[aria-current] .tab-bar__icon {
        outline: 2px solid CanvasText;
    }
}

.layout-admin .page {
    max-width: 1200px;
}

.with-side-nav {
    display: block;
}

.side-nav {
    display: none;
}

@media (min-width: 900px) {
    .with-side-nav:has(> .side-nav) {
        display: grid;
        grid-template-columns: 240px 1fr;
        min-height: calc(100dvh - 56px);
    }

    /* It stays in view on long pages (CB14). */
    .side-nav {
        position: sticky;
        top: 56px;
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        height: calc(100dvh - 56px);
        overflow-y: auto;
        padding: var(--space-4) var(--space-3);
        background: var(--color-surface);
        border-right: 1px solid var(--color-border);
    }

    .side-nav__item {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        min-height: var(--tap);
        padding: 0 var(--space-3);
        border-radius: var(--radius-sm);
        color: var(--color-ink);
        font-weight: 550;
        text-decoration: none;
    }

    .side-nav__item:hover {
        background: var(--color-surface-sunken);
    }

    .side-nav__item--group-start {
        margin-top: var(--space-3);
        position: relative;
    }

    .side-nav__item--group-start::before {
        content: '';
        position: absolute;
        inset: calc(-1 * var(--space-2)) var(--space-3) auto;
        border-top: 1px solid var(--color-border);
    }

    /* Current: tint, bold and a bar on the leading edge, so not by colour alone.
       The bar is a border, which survives forced colours (a shadow doesn't). */
    .side-nav__item[aria-current] {
        padding-inline-start: calc(var(--space-3) - 4px);
        border-inline-start: 4px solid var(--color-primary-strong);
        background: var(--color-primary-tint);
        color: var(--color-primary-strong);
        font-weight: 750;
    }

    .layout-centre .tab-bar,
    .layout-admin .tab-bar {
        display: none;
    }
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.stack--tight {
    gap: var(--space-2);
}

.stack--loose {
    gap: var(--space-5);
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

/* A heading and its one action on the same line, the action at the end. */
.cluster--between {
    justify-content: space-between;
}

.grid-cards {
    display: grid;
    gap: var(--space-4);
}

@media (min-width: 600px) {
    .grid-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

.app-bar__account {
    display: none;
}

@media (min-width: 600px) {
    .app-bar__account {
        display: inline;
        max-width: 24ch;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
