/* Structure of the shared layouts (templates/layout/app.html and public.html): header, side menu, body and footer.
   The floating notices of api.js live in components.css. Reads tokens.css only. */

/* ---- Brand: the mark and the product name ---- */
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    color: var(--ink);
    font-weight: var(--weight-semibold);
    text-decoration: none;
}

.app-brand:hover {
    text-decoration: none;
}

.app-mark {
    display: block;
    width: var(--mark-size);
    height: var(--mark-size);
}

/* ---- Skip link: the first focusable element, visible only while it has focus ---- */
.skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 200;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    transform: translateY(-200%);
}

.skip-link:focus-visible {
    transform: none;
}

/* ---- Signed-in layout: grid header / side menu / body / footer ---- */
body.app-layout {
    display: grid;
    grid-template-columns: var(--menu-width) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header"
        "menu body"
        "menu footer";
}

.app-header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-4);
    border-bottom: var(--hairline) solid var(--rule);
    background: var(--surface);
}

/* The brand keeps its size: it never shrinks or wraps, whatever the room left by the account group */
.app-header .app-brand {
    flex: none;
    white-space: nowrap;
}

/* The user link and the logout form form one group pushed to the right; the group shrinks, the form does not */
.app-account {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    margin-left: auto;
}

.app-account > form {
    flex: none;
}

/* A long display name is cut with an ellipsis instead of wrapping the header */
.app-header .app-user {
    min-width: 0;
    max-width: var(--user-name-max);
    overflow: hidden;
    font-size: var(--text-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-menu {
    grid-area: menu;
    padding: var(--space-4) 0;
    border-right: var(--hairline) solid var(--rule);
    background: var(--bg);
}

.app-menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-menu a {
    display: block;
    padding: var(--space-2) var(--space-4);
    border-left: var(--marker) solid transparent;
    color: var(--ink);
    text-decoration: none;
}

.app-menu a:hover {
    background: var(--hover);
}

/* The current entry carries the brass marker */
.app-menu a[aria-current="page"] {
    border-left-color: var(--brass);
    font-weight: var(--weight-semibold);
}

.app-menu a:focus-visible,
.app-header a:focus-visible {
    outline-offset: calc(-1 * var(--focus-width));
}

.app-body {
    grid-area: body;
    min-width: 0;
    padding: var(--space-5) var(--space-6);
    background: var(--surface);
}

/* The page's <main> is a column aligned to the left, not a card */
.app-body > main {
    width: 100%;
    max-width: var(--measure);
}

.app-body > main > h1:first-child {
    margin-top: 0;
}

.app-footer {
    grid-area: footer;
    padding: var(--space-3) var(--space-6);
    background: var(--surface);
    color: var(--ink-soft);
}

/* ---- Menu toggle: a checkbox (no script), only used on narrow screens ---- */
input.menu-toggle,
.menu-button {
    display: none;
}

@media (max-width: 48rem) {
    body.app-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "header"
            "menu"
            "body"
            "footer";
    }

    input.menu-toggle {
        display: block;
        position: absolute;
        top: var(--space-2);
        left: var(--space-2);
        z-index: 1;
        width: var(--toggle-width);
        height: var(--touch-target);
        margin: 0;
        padding: 0;
        opacity: 0;
        cursor: pointer;
    }

    /* The label is a base <label>: its top margin would push it off the line of the other header items */
    .menu-button {
        display: inline-block;
        flex: none;
        margin: 0;
        white-space: nowrap;
        padding: var(--space-2);
        border: var(--hairline) solid var(--control-border);
        border-radius: var(--radius);
        background: var(--surface);
        font-size: var(--text-sm);
        font-weight: var(--weight-medium);
    }

    .menu-toggle:focus-visible ~ .app-header .menu-button {
        outline: var(--focus-ring);
        outline-offset: var(--focus-offset);
    }

    /* One row on phones too: the account group takes what the menu button and the brand leave */
    .app-header {
        gap: var(--space-2);
        padding-inline: var(--space-3);
    }

    /* Compact logout button, still a touch-sized hit area */
    .app-account > form > button {
        min-height: var(--touch-target);
        padding-inline: var(--space-2);
        font-size: var(--text-sm);
    }

    .app-menu {
        display: none;
        border-right: 0;
        border-bottom: var(--hairline) solid var(--rule);
    }

    .menu-toggle:checked ~ .app-menu {
        display: block;
    }

    .app-menu a {
        padding-block: var(--space-3);
    }

    .app-body {
        padding: var(--space-4);
    }

    .app-footer {
        padding-inline: var(--space-4);
    }
}

/* ---- Public layout: one narrow column on the paper, the brand above and the footer below ---- */
body.public-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-7) var(--space-4) var(--space-5);
}

body.public-layout > * {
    width: 100%;
    max-width: var(--measure-public);
}

/* The <main> of the public pages: just the column, no card chrome */
body.public-layout > main {
    padding: 0;
}

body.public-layout > main > h1:first-child {
    margin-top: 0;
    padding-bottom: var(--space-3);
    border-bottom: var(--hairline) solid var(--rule);
}

/* Full-width action at the end of a public form */
body.public-layout > main form:not(.inline-form):not(.secondary) > button {
    width: 100%;
}

body.public-layout > main p.actions > a.button {
    display: flex;
}

body.public-layout .app-footer {
    margin-top: auto;
    padding: 0;
    background: transparent;
}

@media (max-width: 40rem) {
    body.public-layout {
        padding-top: var(--space-6);
    }
}
