/* SAHB DMS site theme (docs/design/design-system.md): tokens, then element defaults in the "base" layer (so every widget
   stylesheet - viewer, annotate, redact, repo, search - wins over them without specificity games), then the unlayered app
   shell (html.shell: app bar, sidebar, content, footer), the components and the sign-in card. Rules below the tokens use only
   tokens. Logical properties throughout (RTL-ready); no inline style anywhere (CSP style-src 'self'). */

:root {
    /* Colour scales. Navy 700 is the Bank navy; gold is the accent (focus on dark, badges). Contrast pairs are in the design doc. */
    --navy-50: #f2f5fa;
    --navy-100: #e6ecf5;
    --navy-200: #c9d5e8;
    --navy-300: #9db1d3;
    --navy-400: #6a87b8;
    --navy-500: #3f5f95;
    --navy-600: #2c4a7e;
    --navy-700: #1f3864;
    --navy-800: #182d52;
    --navy-900: #14264a;
    --gray-50: #f8fafc;
    --gray-100: #f4f6f9;
    --gray-150: #eef1f5;
    --gray-200: #e3e8ef;
    --gray-300: #cbd2dc;
    --gray-400: #9aa4b2;
    --gray-500: #767f8e;
    --gray-600: #4a5568;
    --gray-700: #364152;
    --gray-900: #1b2433;
    --gold-100: #fff4d6;
    --gold-400: #ffbf47;
    --green-50: #e8f5ec;
    --green-600: #23824a;
    --green-700: #1e6b3a;
    --amber-50: #fff4d6;
    --amber-500: #c27c0e;
    --amber-700: #7a4b00;
    --red-50: #fdecec;
    --red-600: #b42318;
    --red-700: #a61b1b;
    --red-800: #8f1b13;
    --blue-50: #e8eef8;
    --blue-700: #1f4e8c;

    /* Semantic colours (the names of rounds 1-2 kept). */
    --color-primary: var(--navy-700);
    --color-primary-strong: var(--navy-900);
    --color-primary-soft: var(--navy-600);
    --color-primary-tint: var(--navy-100);
    --color-primary-wash: var(--navy-50);
    --color-accent: var(--gold-400);
    --color-bg: var(--gray-100);
    --color-surface: #fff;
    --color-surface-sunken: var(--gray-50);
    --color-text: var(--gray-900);
    --color-text-muted: var(--gray-600);
    --color-text-inverse: #fff;
    --color-link: var(--blue-700);
    --color-border: var(--gray-300);
    --color-border-subtle: var(--gray-200);
    --color-border-strong: var(--gray-500);
    --color-row-alt: var(--gray-50);
    --color-icon: var(--navy-500);
    --color-danger: var(--red-600);
    --color-danger-strong: var(--red-800);
    --color-danger-text: var(--red-700);
    --color-danger-bg: var(--red-50);
    --color-success: var(--green-600);
    --color-success-text: var(--green-700);
    --color-success-bg: var(--green-50);
    --color-warning: var(--amber-500);
    --color-warning-text: var(--amber-700);
    --color-warning-bg: var(--amber-50);
    --color-info: var(--navy-700);
    --color-info-bg: var(--blue-50);
    --color-inverse-hover: rgb(255 255 255 / 12%);
    --color-backdrop: rgb(16 24 40 / 45%);

    /* Type: Arial / system sans (no web fonts), 16px base, about 1.25 ratio. */
    --font-sans: Arial, "Helvetica Neue", Helvetica, system-ui, sans-serif;
    --font-mono: Consolas, "Courier New", monospace;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-table: 0.9375rem;
    --font-size-base: 1rem;
    --font-size-md: 1.125rem;
    --font-size-lg: 1.375rem;
    --font-size-xl: 1.75rem;
    --font-size-2xl: 2rem;
    --font-weight-normal: 400;
    --font-weight-bold: 700;
    --line-height-tight: 1.25;
    --line-height-base: 1.5;

    /* Space: 4px grid. */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
    --radius-pill: 999px;

    /* Elevation: cards rest on xs/sm, raised panels md, menus and dialogs lg. */
    --shadow-xs: 0 1px 2px rgb(16 24 40 / 5%);
    --shadow-sm: 0 1px 3px rgb(16 24 40 / 8%), 0 1px 2px rgb(16 24 40 / 4%);
    --shadow-md: 0 4px 10px -2px rgb(16 24 40 / 10%), 0 2px 4px -2px rgb(16 24 40 / 6%);
    --shadow-lg: 0 12px 28px -4px rgb(16 24 40 / 16%), 0 4px 8px -4px rgb(16 24 40 / 8%);

    /* Layers: in-page pop-ups (action panels), then the sticky header (over them when the page scrolls; its own menus are inside
       it), the sidebar panel's backdrop and the panel (both start under the header); the skip link (a11y.css) is 100. */
    --z-dropdown: 30;
    --z-header: 35;
    --z-backdrop: 38;
    --z-drawer: 40;

    --border-width: 1px;
    --focus-width: 3px;
    --control-height: 2.5rem;
    --control-height-sm: 2rem;
    --control-height-xs: 1.75rem;
    --icon-size: 1.25rem;
    --header-height: 3.75rem;
    --sidebar-width: 16rem;
    --drawer-width: min(18rem, 85vw);
    --container-max: 100rem;
    --reading-max: 80ch;
    --form-max: 48rem;
    --cell-long-width: 22rem;
    --cell-long-min: 12rem;
    --auth-width: 28rem;
    --duration-fast: 150ms;
}

@layer base {
    *,
    ::before,
    ::after {
        box-sizing: border-box;
    }

    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body {
        margin: 0;
        background: var(--color-bg);
        color: var(--color-text);
        font-family: var(--font-sans);
        font-size: var(--font-size-base);
        line-height: var(--line-height-base);
    }

    h1,
    h2,
    h3,
    h4 {
        margin-block: 0 var(--space-3);
        color: var(--color-primary);
        line-height: var(--line-height-tight);
    }

    h1 {
        font-size: var(--font-size-xl);
    }

    h2 {
        margin-block-start: var(--space-6);
        font-size: var(--font-size-lg);
    }

    h3 {
        margin-block-start: var(--space-5);
        font-size: var(--font-size-md);
    }

    h4 {
        font-size: var(--font-size-base);
    }

    p {
        margin-block: 0 var(--space-3);
    }

    a {
        color: var(--color-link);
        text-underline-offset: 0.15em;
    }

    a:hover {
        color: var(--color-primary-strong);
    }

    code {
        font-family: var(--font-mono);
        font-size: var(--font-size-sm);
        background: var(--color-primary-wash);
        padding: 0 var(--space-1);
        border-radius: var(--radius-sm);
    }

    /* WCAG 2.4.7 / 2.4.11: a 3px outline on every focusable thing; programmatic focus on main (skip link) shows only for keyboard. */
    :focus-visible {
        outline: var(--focus-width) solid var(--color-primary);
        outline-offset: 2px;
    }

    [tabindex="-1"]:focus:not(:focus-visible) {
        outline: none;
    }

    /* Buttons: secondary by default, a submit button is primary, .btn-danger destroys. Small widget buttons keep their size. */
    button:not(.ann-swatch, .ann-media-marker, .viewer-link) {
        min-height: var(--control-height);
        padding: var(--space-1) var(--space-4);
        border: var(--border-width) solid var(--color-primary);
        border-radius: var(--radius-md);
        background: var(--color-surface);
        color: var(--color-primary);
        font: inherit;
        font-weight: var(--font-weight-bold);
        line-height: var(--line-height-tight);
        cursor: pointer;
        transition: background-color var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast);
    }

    button:hover {
        background: var(--color-primary-wash);
    }

    button[type="submit"] {
        background: var(--color-primary);
        color: var(--color-text-inverse);
    }

    button[type="submit"]:hover {
        background: var(--color-primary-strong);
        border-color: var(--color-primary-strong);
    }

    button[aria-pressed="true"] {
        background: var(--color-primary);
        color: var(--color-text-inverse);
    }

    button.btn-danger {
        background: var(--color-danger);
        border-color: var(--color-danger);
        color: var(--color-text-inverse);
    }

    button.btn-danger:hover {
        background: var(--color-danger-strong);
        border-color: var(--color-danger-strong);
    }

    button:disabled {
        opacity: 0.55;
        cursor: not-allowed;
    }

    /* Fields: 3:1 borders (1.4.11), the same height as buttons. */
    input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="file"], [type="range"], [type="color"]),
    select,
    textarea {
        min-height: var(--control-height);
        max-width: 100%;
        padding: var(--space-1) var(--space-3);
        border: var(--border-width) solid var(--color-border-strong);
        border-radius: var(--radius-md);
        background: var(--color-surface);
        color: var(--color-text);
        font: inherit;
        font-weight: var(--font-weight-normal);
    }

    ::placeholder {
        color: var(--color-text-muted);
        opacity: 1;
    }

    textarea {
        line-height: var(--line-height-base);
    }

    input[type="checkbox"],
    input[type="radio"] {
        inline-size: 1.125rem;
        block-size: 1.125rem;
        margin: 0;
        accent-color: var(--color-primary);
    }

    /* QA-088 (WCAG 2.5.8): an 18px box beside a link in a cell keeps a 24px target circle clear of its neighbours. */
    :is(th, td) > input:is([type="checkbox"], [type="radio"]) {
        margin-block: 0.1875rem;
        margin-inline: 0.1875rem 0.5rem;
    }

    input[type="file"] {
        font: inherit;
    }

    label {
        font-weight: var(--font-weight-bold);
    }

    /* A label wrapping its field stacks text over field; side by side with its siblings (filter rows wrap). */
    label:has(> :is(input, select, textarea):not([type="checkbox"], [type="radio"], [type="hidden"])) {
        display: inline-flex;
        flex-direction: column;
        max-inline-size: 100%; /* QA-109: a select with long options stays within a narrow window (its own max-width is of this label) */
        gap: var(--space-1);
        margin-block-end: var(--space-3);
        margin-inline-end: var(--space-4);
        vertical-align: bottom;
    }

    label:has(> input[type="checkbox"], > input[type="radio"]) {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        margin-inline-end: var(--space-4);
        font-weight: var(--font-weight-normal);
    }

    /* One field per line (settings forms): fields share one width. */
    p > label:has(> :is(input, select, textarea):not([type="checkbox"], [type="radio"], [type="hidden"])) {
        display: flex;
        max-inline-size: 32rem;
    }

    p > label[for] {
        display: block;
        margin-block-end: var(--space-1);
    }

    /* QA-109: a fieldset is min-content wide by default, so a wide table inside one (in its scrolling wrapper) pushed the page
       wider than the window; it takes the width it is given like any block. */
    fieldset {
        min-inline-size: 0;
        margin-block: var(--space-4);
        padding: var(--space-3) var(--space-5) var(--space-4);
        border: var(--border-width) solid var(--color-border);
        border-radius: var(--radius-lg);
        background: var(--color-surface);
    }

    legend {
        padding-inline: var(--space-2);
        color: var(--color-primary);
        font-weight: var(--font-weight-bold);
    }

    main form {
        margin-block-end: var(--space-4);
    }

    /* A button beside labelled fields lines up with the fields' bottom edge (the labels stack text over field). */
    form:has(> label > :is(input, select, textarea)) > button {
        margin-block-end: var(--space-3);
        vertical-align: bottom;
    }

    li > form,
    td > form {
        display: inline-block;
        margin-block: 0;
        margin-inline-end: var(--space-1);
    }

    /* Tables: tinted header, zebra rows, compact cells; the wrapper scrolls sideways on narrow screens. */
    /* QA-109: positioned, so screen-reader-only text in a cell (position: absolute) scrolls with the table instead of widening
       the page from the cell's place far to the right. */
    .table-wrap {
        position: relative;
        margin-block: var(--space-3) var(--space-5);
        overflow-x: auto;
        border: var(--border-width) solid var(--color-border);
        border-radius: var(--radius-lg);
        background: var(--color-surface);
        box-shadow: var(--shadow-xs);
    }

    table {
        inline-size: 100%;
        border-collapse: collapse;
        background: var(--color-surface);
        font-size: var(--font-size-table);
    }

    caption {
        padding: var(--space-3) var(--space-4);
        caption-side: top;
        color: var(--color-primary);
        font-weight: var(--font-weight-bold);
        text-align: start;
    }

    th,
    td {
        padding: var(--space-2) var(--space-3);
        border-block-end: var(--border-width) solid var(--color-border-subtle);
        text-align: start;
        vertical-align: top;
    }

    thead th {
        background: var(--color-primary-wash);
        color: var(--color-primary);
        font-size: var(--font-size-sm);
        font-weight: var(--font-weight-bold);
        white-space: nowrap;
        border-block-end-color: var(--color-border);
    }

    /* Dates and times never break; long values (JSON, paths, errors) wrap anywhere inside a fixed-width column. */
    td.date,
    td time {
        white-space: nowrap;
    }

    td.cell-long {
        inline-size: var(--cell-long-width);
        min-inline-size: var(--cell-long-min);
        overflow-wrap: anywhere;
    }

    tbody tr:nth-child(even) {
        background: var(--color-row-alt);
    }

    tbody tr:hover {
        background: var(--color-primary-wash);
    }

    tbody tr:last-child > * {
        border-block-end: 0;
    }

    td button:not(.ann-swatch),
    tbody th button {
        min-height: var(--control-height-xs);
        padding: 0 var(--space-2);
        font-size: var(--font-size-sm);
    }

    td button[type="submit"]:not(.btn-danger) {
        background: var(--color-surface);
        color: var(--color-primary);
    }

    td button[type="submit"]:not(.btn-danger):hover {
        background: var(--color-primary-wash);
    }

    hr {
        border: 0;
        border-block-start: var(--border-width) solid var(--color-border);
    }

}

/* Hidden means hidden, whatever display a class gives. */
[hidden] {
    display: none !important;
}

/* Icons (wwwroot/img/icons.svg via Html.Icon): stroke icons in the text colour, decorative (aria-hidden). */
.ui-icon {
    flex: none;
    inline-size: var(--icon-size);
    block-size: var(--icon-size);
    vertical-align: -0.25em;
}

/* The Office/Outlook/Teams panes (narrow task panes, not testable in a browser here) and the viewer keep the sizes of round 2:
   type 15 px base, 36 px controls, the 82rem column. */
:root:has(main.office-pane, main#signed-in),
.viewer {
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-table: 0.9375rem;
    --font-size-base: 0.9375rem;
    --font-size-md: 1.0625rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
    --control-height: 2.25rem;
    --control-height-sm: 1.75rem;
    --control-height-xs: 1.75rem;
    --container-max: 82rem;
}

.viewer {
    font-size: var(--font-size-base);
}

/* ---------- Pages without the shell (sign-in, panes): a column ---------- */

body {
    display: flex;
    flex-direction: column;
    min-block-size: 100vh;
}

body > main {
    flex: 1;
    inline-size: 100%;
    max-inline-size: var(--container-max);
    margin-inline: auto;
    padding: var(--space-6) var(--space-5) var(--space-7);
}

body > footer {
    padding: var(--space-3) var(--space-5);
    border-block-start: var(--border-width) solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    text-align: center;
}

body > footer p {
    margin: 0;
}

/* ---------- App shell (html.shell): the app bar over a sidebar and the content; the footer under the content ---------- */

.shell {
    scroll-padding-block-start: calc(var(--header-height) + var(--space-4)); /* an in-page link's target clears the sticky bar */
}

.shell body {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header"
        "nav main"
        "nav footer";
}

.shell body > main {
    grid-area: main;
    max-inline-size: var(--container-max);
    margin-inline: 0;
    padding: var(--space-6) var(--space-7) var(--space-7);
}

/* The content uses the full width (tables, filter rows); running text keeps a reading width. */
.shell main > p:not(.flash, .callout, .empty, [role]) {
    max-inline-size: var(--reading-max);
}

.shell body > footer {
    grid-area: footer;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-5);
    justify-content: space-between;
    padding: var(--space-4) var(--space-7);
    border-block-start: var(--border-width) solid var(--color-border-subtle);
    background: transparent;
    text-align: start;
}

/* The app bar: menu button, product mark, search, bell, user menu. One row at every width (the search shrinks); it stays at
   the top while the page scrolls. */
.app-header {
    grid-area: header;
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-header);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    block-size: var(--header-height);
    padding-inline: var(--space-4) var(--space-5);
    background: var(--color-primary);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-sm);
}

.app-header :focus-visible {
    outline-color: var(--color-accent);
}

.app-header a {
    color: var(--color-text-inverse);
}

.app-brand {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: var(--space-3);
    margin-inline-end: var(--space-4);
    color: var(--color-text-inverse);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.01em;
    text-decoration: none;
    white-space: nowrap;
}

.app-brand img {
    display: block;
    inline-size: 2rem;
    block-size: 2rem;
}

.app-brand:hover {
    color: var(--color-text-inverse);
}

.app-brand:hover .app-brand-name {
    text-decoration: underline;
}

/* Icon buttons (menu, bell): a 40px square target. */
.icon-btn {
    position: relative;
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: var(--control-height);
    block-size: var(--control-height);
    padding: 0;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: inherit;
    text-decoration: none;
}

.app-header .icon-btn,
.app-header .icon-btn:hover {
    border: 0;
    background: transparent;
    color: var(--color-text-inverse);
}

.app-header .icon-btn:hover,
.app-header .icon-btn[aria-expanded="true"] {
    background: var(--color-inverse-hover);
}

.app-header .icon-btn .ui-icon {
    inline-size: 1.375rem;
    block-size: 1.375rem;
}

/* The quick search: prominent, white on the navy bar, a search icon inside the box. */
.app-header .quick-search {
    position: relative;
    display: flex;
    flex: 1 1 24rem;
    align-items: center;
    gap: var(--space-2);
    min-inline-size: 0;
    max-inline-size: 40rem;
    margin: 0;
}

.app-header .quick-search > .ui-icon {
    position: absolute;
    inset-inline-start: var(--space-3);
    color: var(--color-text-muted);
    pointer-events: none;
}

.app-header .quick-search input[type="search"] {
    flex: 1;
    inline-size: auto;
    min-inline-size: 0;
    padding-inline-start: 2.5rem;
    border-color: transparent;
    border-radius: var(--radius-md);
}

.app-header .quick-search-submit,
.app-header .quick-search-submit:hover {
    flex: none;
    border-color: rgb(255 255 255 / 70%);
    background: transparent;
    color: var(--color-text-inverse);
}

.app-header .quick-search-submit:hover {
    border-color: var(--color-text-inverse);
    background: var(--color-inverse-hover);
}

/* Three classes: search.css (loaded later) styles ".quick-search .suggestions" with a 18rem minimum width. */
.app-header .quick-search .suggestions {
    z-index: var(--z-dropdown);
    inset-block-start: calc(100% + var(--space-1));
    inline-size: 100%;
    min-inline-size: 0;
    border-color: var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
}

.app-user {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--space-1);
    margin-inline-start: auto;
}

/* The bell: the unread number in a gold badge on the icon (ntf.js; the link's name says "unread"). */
.app-bell-badge:not(:empty) {
    position: absolute;
    inset-block-start: 0.125rem;
    inset-inline-end: 0;
    min-inline-size: 1.25rem;
    padding: 0 var(--space-1);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-pill);
    background: var(--color-accent);
    color: var(--color-primary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    line-height: 1.2;
    text-align: center;
}

/* The user menu: a <details> whose panel drops down at the end of the bar (shell.js closes it on Escape or a click outside). */
.user-menu {
    position: relative;
}

.user-menu > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: var(--control-height);
    padding-inline: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    list-style: none;
    white-space: nowrap;
}

.user-menu > summary::-webkit-details-marker {
    display: none;
}

.user-menu > summary:hover,
.user-menu[open] > summary {
    background: var(--color-inverse-hover);
}

.user-menu > summary .ui-icon:last-child {
    inline-size: 1rem;
    block-size: 1rem;
    transition: transform var(--duration-fast);
}

.user-menu[open] > summary .ui-icon:last-child {
    transform: rotate(180deg);
}

.user-menu-name {
    max-inline-size: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu-panel {
    position: absolute;
    inset-block-start: calc(100% + var(--space-2));
    inset-inline-end: 0;
    z-index: var(--z-dropdown);
    min-inline-size: 16rem;
    padding: var(--space-2);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

.user-menu-panel :focus-visible {
    outline-color: var(--color-primary);
}

.user-menu-who {
    margin: 0 0 var(--space-2);
    padding: var(--space-2) var(--space-3) var(--space-3);
    border-block-end: var(--border-width) solid var(--color-border-subtle);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    overflow-wrap: anywhere;
}

.user-menu-who strong {
    display: block;
    color: var(--color-text);
    font-size: var(--font-size-base);
}

.user-menu-panel form {
    margin: 0;
}

.app-header .user-menu-panel :is(a, button[type="submit"]) {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    inline-size: 100%;
    min-block-size: var(--control-height);
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text);
    font-weight: var(--font-weight-normal);
    text-align: start;
    text-decoration: none;
}

.app-header .user-menu-panel :is(a, button[type="submit"]):hover {
    background: var(--color-primary-wash);
    color: var(--color-primary);
}

.user-menu-panel .ui-icon {
    color: var(--color-icon);
}

/* The sidebar: grouped menu links with icons; its inner part stays in view under the bar while the page scrolls. */
.app-sidebar {
    grid-area: nav;
    min-inline-size: 0;
    border-inline-end: var(--border-width) solid var(--color-border-subtle);
    background: var(--color-surface);
}

.app-sidebar-inner {
    position: sticky;
    inset-block-start: var(--header-height);
    max-block-size: calc(100vh - var(--header-height));
    overflow-y: auto;
    padding: var(--space-4) var(--space-3) var(--space-6);
}

.app-sidebar ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav-group {
    margin: var(--space-5) var(--space-3) var(--space-1);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.app-sidebar nav a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-block-size: var(--control-height);
    padding: var(--space-2) var(--space-3);
    border-inline-start: var(--focus-width) solid transparent;
    border-start-end-radius: var(--radius-md);
    border-end-end-radius: var(--radius-md);
    color: var(--color-text);
    line-height: var(--line-height-tight);
    text-decoration: none;
}

.app-sidebar nav a .ui-icon {
    color: var(--color-icon);
}

.app-sidebar nav a:hover {
    background: var(--color-primary-wash);
    color: var(--color-primary);
}

.app-sidebar nav a[aria-current] {
    border-inline-start-color: var(--color-primary);
    background: var(--color-primary-tint);
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
}

.app-sidebar nav a[aria-current] .ui-icon {
    color: var(--color-primary);
}

.app-sidebar :focus-visible {
    outline-offset: -3px;
}

/* Narrow windows (below 1024px) and the viewer: the sidebar is a panel the menu button opens over the page (shell.js). Without
   script the menu stays on the page, above the content. */
@media (width < 64rem) {
    .shell body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto 1fr auto;
        grid-template-areas:
            "header"
            "nav"
            "main"
            "footer";
    }

    .app-sidebar {
        border-inline-end: 0;
        border-block-end: var(--border-width) solid var(--color-border-subtle);
    }

    .app-sidebar-inner {
        position: static;
        max-block-size: none;
    }

    .shell-js .app-sidebar {
        position: fixed;
        inset-block: var(--header-height) 0;
        inset-inline-start: 0;
        z-index: var(--z-drawer);
        display: none;
        inline-size: var(--drawer-width);
        overflow-y: auto;
        border-inline-end: var(--border-width) solid var(--color-border);
        box-shadow: var(--shadow-lg);
    }

    .shell-js.nav-open .app-sidebar {
        display: block;
    }

    .shell-js.nav-open body::after {
        content: "";
        position: fixed;
        inset: var(--header-height) 0 0;
        z-index: var(--z-backdrop);
        background: var(--color-backdrop);
    }

    .shell body > main,
    .shell body > footer {
        padding-inline: var(--space-5);
    }

    .user-menu-name {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

@media (width < 40rem) {
    .app-header {
        gap: var(--space-2);
        padding-inline: var(--space-2) var(--space-3);
    }

    .app-brand {
        margin-inline-end: 0;
    }

    .app-brand-name {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .app-header .quick-search-submit {
        display: none; /* Enter submits the one-field form */
    }

    .shell body > main,
    .shell body > footer {
        padding-inline: var(--space-4);
    }
}

/* The viewer takes the whole width under the bar at every size (viewer.css sizes its rows): the sidebar opens over it. */
.shell body:has(> main > .viewer) > .app-sidebar {
    position: fixed;
    inset-block: var(--header-height) 0;
    inset-inline-start: 0;
    z-index: var(--z-drawer);
    display: none;
    inline-size: var(--drawer-width);
    overflow-y: auto;
    border-inline-end: var(--border-width) solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.shell.nav-open body:has(> main > .viewer) > .app-sidebar {
    display: block;
}

.shell.nav-open body:has(> main > .viewer)::after {
    content: "";
    position: fixed;
    inset: var(--header-height) 0 0;
    z-index: var(--z-backdrop);
    background: var(--color-backdrop);
}

.shell body:has(> main > .viewer) .app-sidebar-inner {
    position: static;
    max-block-size: none;
}

@media (width > 48rem) {
    .shell body:has(> main > .viewer) {
        grid-template-areas:
            "header"
            "main"
            "footer";
    }
}

/* Same weight as ".shell body > main" and later, so it wins; viewer.css (loaded after) still sets its own padding-block. */
body > main:has(> .viewer) {
    max-inline-size: none;
    padding: var(--space-3) var(--space-4);
}

/* ---------- Components ---------- */

/* Page header: the title and one line on the page, the page's actions at the end (wrapping under on a narrow window). */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-3) var(--space-5);
    margin-block-end: var(--space-5);
}

.page-header-text {
    flex: 1 1 24rem;
    min-inline-size: 0;
}

.page-header h1 {
    margin: 0;
    overflow-wrap: anywhere;
}

.page-desc {
    max-inline-size: var(--reading-max);
    margin: var(--space-2) 0 0;
    color: var(--color-text-muted);
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.page-actions form {
    margin: 0;
}

/* UI/UX round 3, phase B1: an action panel (Upload files, New folder) in the page header opens under the whole header at its
   end edge, so it stays on screen wherever its button sits (beside the title, or wrapped under it on a phone). */
.page-header {
    position: relative;
}

.page-header .action-panel {
    position: static;
}

.page-header .action-panel-body {
    inset-inline: auto 0;
    inline-size: min(36rem, 100%);
}

/* The page's less frequent actions: a row of small secondary buttons under the header (the main ones sit in the header). */
.page-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-block: calc(-1 * var(--space-2)) var(--space-5);
}

.page-tools form {
    margin: 0;
}

/* "More actions" in that row opens under the row from its start edge, as wide as a short list. */
.page-tools {
    position: relative;
}

.page-tools .action-panel {
    position: static;
}

.page-tools .action-panel-body {
    inset-inline: 0 auto;
    inline-size: min(22rem, 100%);
    padding: var(--space-2) var(--space-4);
}

.page-tools :is(.btn, button) {
    min-height: var(--control-height-sm);
    padding: 0 var(--space-3);
    font-size: var(--font-size-sm);
}

.page-tools button[type="submit"]:not(.btn-danger) {
    background: var(--color-surface);
    color: var(--color-primary);
}

.page-tools button[type="submit"]:not(.btn-danger):hover {
    background: var(--color-primary-wash);
}

/* A breadcrumb straight above the page header sits close to it. */
.breadcrumb + .page-header {
    margin-block-start: var(--space-2);
}

/* A section heading with an icon and one line under it. */
.section {
    margin-block-end: var(--space-6);
}

.section-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-block-end: var(--space-3);
}

.section-head h2 {
    margin: 0;
}

.section-desc {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
}

.section-icon,
.card-icon,
.action-tile-icon,
.empty-state-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: 2.5rem;
    block-size: 2.5rem;
    border-radius: var(--radius-lg);
    background: var(--color-primary-tint);
    color: var(--color-primary);
}

/* Buttons beyond the base: links and summaries that act as buttons, sizes, ghost, icons inside. */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    padding: var(--space-1) var(--space-4);
    border: var(--border-width) solid var(--color-primary);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--duration-fast);
}

.btn:hover {
    background: var(--color-primary-wash);
    color: var(--color-primary);
}

.btn-primary,
.btn-primary:hover {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.btn-primary:hover {
    background: var(--color-primary-strong);
}

button.btn-secondary[type="submit"] {
    background: var(--color-surface);
    color: var(--color-primary);
}

button.btn-secondary[type="submit"]:hover {
    background: var(--color-primary-wash);
}

.btn-ghost,
button.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--color-primary);
}

.btn-ghost:hover,
button.btn-ghost:hover {
    background: var(--color-primary-wash);
}

a.btn-danger {
    border-color: var(--color-danger);
    background: var(--color-danger);
    color: var(--color-text-inverse);
}

.btn-sm,
button.btn-sm {
    min-height: var(--control-height-sm);
    padding: 0 var(--space-3);
    font-size: var(--font-size-sm);
}

.btn .ui-icon,
button .ui-icon {
    inline-size: 1.125rem;
    block-size: 1.125rem;
}

button:has(> .ui-icon) {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

summary.btn {
    list-style: none;
}

summary.btn::-webkit-details-marker {
    display: none;
}

summary.btn::after {
    content: "";
    margin-inline-start: var(--space-2);
    border-inline: 4px solid transparent;
    border-block-start: 5px solid currentColor;
}

details[open] > summary.btn::after {
    border-block-start: 0;
    border-block-end: 5px solid currentColor;
}

/* Cards and grids. */
.card {
    padding: var(--space-4) var(--space-5);
    border: var(--border-width) solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

.card > h2:first-child {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-block-start: 0;
    font-size: var(--font-size-md);
}

.card > h2:first-child .ui-icon {
    color: var(--color-icon);
}

.card-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-block-end: var(--space-3);
}

.card-head h2 {
    margin: 0;
    font-size: var(--font-size-md);
}

.card-desc {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.card-grid {
    display: grid;
    align-items: start;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
    gap: var(--space-4);
    margin-block: var(--space-4);
    padding: 0;
    list-style: none;
}

.admin-overview {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
    align-items: stretch;
}

.widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr));
    align-items: start;
    gap: var(--space-5);
    margin-block: var(--space-5);
}

.card .table-wrap {
    box-shadow: none;
}

/* A card that is one link: the title link covers the card (one tab stop), the card lifts on hover. */
.link-cards {
    align-items: stretch;
}

.link-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.link-card:hover {
    border-color: var(--navy-300);
    box-shadow: var(--shadow-md);
}

.link-card:focus-within {
    outline: var(--focus-width) solid var(--color-primary);
    outline-offset: 2px;
}

.link-card-title {
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
}

.link-card-title::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
}

.link-card-title:focus-visible {
    outline: none;
}

.link-card:hover .link-card-title {
    text-decoration: underline;
}

.link-card p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* Quick actions (dashboard): link cards with an icon. */
.quick-actions {
    margin-block-end: var(--space-5);
}

.action-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.action-tile {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: var(--space-3);
    align-items: center;
}

.action-tile-icon {
    grid-row: span 2;
    align-self: start;
}

/* Compact links in a row (the console overview's pages). */
.chip-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-3) 0 0;
    padding: 0;
    list-style: none;
}

.chip-links a {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--control-height-sm);
    padding: var(--space-1) var(--space-3);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-pill);
    color: var(--color-primary);
    font-size: var(--font-size-sm);
    text-decoration: none;
}

.chip-links a:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-wash);
}

.link-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.link-list li + li {
    border-block-start: var(--border-width) solid var(--color-border-subtle);
}

.link-list a {
    display: block;
    padding-block: var(--space-2);
    text-decoration: none;
}

.link-list a:hover {
    text-decoration: underline;
}

/* Stat tiles: a label, a large figure and a line under it; as links (the queues) the current one is outlined. */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr));
    gap: var(--space-3);
    margin: 0 0 var(--space-5);
    padding: 0;
    list-style: none;
}

.card .stat-tiles {
    margin-block-end: var(--space-3);
}

.stat-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-subtle);
    border-inline-start: 4px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: var(--color-surface);
}

.stat-tile-warning {
    border-inline-start-color: var(--color-warning);
}

.stat-tile > a {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-4));
    padding: var(--space-3) var(--space-4);
    border-radius: inherit;
    color: inherit;
    text-decoration: none;
}

.stat-tile > a:hover {
    background: var(--color-primary-wash);
}

.stat-tile:has(> a[aria-current]) {
    border-color: var(--color-primary);
    background: var(--color-primary-wash);
    box-shadow: inset 0 0 0 1px var(--color-primary);
}

.stat-label,
.stat-tile dt {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
}

.stat-tile dt a {
    color: inherit;
}

.stat-value,
.stat-tile dd {
    margin: 0;
    color: var(--color-primary);
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    line-height: 1.1;
}

.stat-meta {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.stat-tile-warning .stat-meta {
    color: var(--color-warning-text);
    font-weight: var(--font-weight-bold);
}

/* Tabs / sub-navigation: a row of links on a rule; the current one has a navy bar (not colour alone: bar and bold). */
/* The rule under the strip is an inset shadow, so the current tab's bar covers it without a negative margin: nothing overflows
   the strip downwards, and it scrolls sideways only when the tabs are wider than the window, with no vertical scrollbar. */
.tabs ul {
    display: flex;
    gap: var(--space-1);
    margin: 0 0 var(--space-5);
    padding: var(--space-1) var(--space-1) 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    box-shadow: inset 0 calc(-1 * var(--border-width)) 0 var(--color-border);
    list-style: none;
}

.tabs a {
    display: block;
    padding: var(--space-2) var(--space-4);
    border-block-end: var(--focus-width) solid transparent;
    color: var(--color-text-muted);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    white-space: nowrap;
}

.tabs a:hover {
    border-block-end-color: var(--color-primary-tint);
    color: var(--color-primary);
}

.tabs a[aria-current] {
    border-block-end-color: var(--color-primary);
    color: var(--color-primary);
}

.tabs :focus-visible {
    outline-offset: -3px;
}

/* Filter bar: a list's options in one wrapping row on a light panel, the apply button at the end. */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-block-end: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
}

.filter-bar > label,
.filter-bar > button {
    margin: 0;
}

.filter-bar > label:has(> :is(input, select, textarea):not([type="checkbox"], [type="radio"], [type="hidden"])) {
    margin: 0;
}

/* Badges and status pills: text says the state; the colour supports it. */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0 var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--gray-150);
    color: var(--gray-700);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    line-height: 1.6;
    white-space: nowrap;
}

.badge-info {
    background: var(--color-primary-tint);
    color: var(--color-primary);
}

.badge-success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

.badge-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
}

.badge-danger {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

/* Messages: status (info), alert (error), notices, and .callout with an icon; empty states. Script-filled live regions stay
   invisible until they have text; visually hidden ones and the viewer's own status lines keep their look. */
main :is(p, div, ul)[role="status"]:not(:empty, .visually-hidden, .viewer *, .viewer-status, .toast-region),
.notice,
.search-notice {
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-primary-tint);
    border-inline-start: 4px solid var(--color-primary);
    border-radius: var(--radius-md);
    background: var(--color-info-bg);
    color: var(--color-primary);
}

main :is(p, div, ul)[role="alert"]:not(:empty, .visually-hidden, .viewer *),
.page-auth [role="alert"],
.error-summary,
.search-refused,
.search-unavailable {
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-danger-bg);
    border-inline-start: 4px solid var(--color-danger);
    border-radius: var(--radius-md);
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

ul[role="alert"] {
    padding-inline-start: var(--space-6);
}

/* The error summary (Shared/Metadata/_ErrorSummary): its title with an icon, the links to the fields in error under it. */
.error-summary > h2 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-block: 0 var(--space-2);
    color: inherit;
    font-size: var(--font-size-md);
}

.error-summary a {
    color: inherit;
    font-weight: var(--font-weight-bold);
}

.callout {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-block: 0 var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-subtle);
    border-inline-start: 4px solid var(--color-info);
    border-radius: var(--radius-md);
    background: var(--color-surface);
}

.callout > .ui-icon {
    margin-block-start: 0.125rem;
    color: var(--color-info);
}

.callout-info {
    border-color: var(--color-primary-tint);
    border-inline-start-color: var(--color-info);
    background: var(--color-info-bg);
}

.callout-success {
    border-color: var(--color-success-bg);
    border-inline-start-color: var(--color-success-text);
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

.callout-warning {
    border-color: var(--color-warning-bg);
    border-inline-start-color: var(--color-warning);
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
}

.callout-danger {
    border-color: var(--color-danger-bg);
    border-inline-start-color: var(--color-danger);
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

:is(.callout-success, .callout-warning, .callout-danger) > .ui-icon {
    color: inherit;
}

.callout > div > :last-child,
.callout > div > form > :last-child {
    margin-block-end: 0;
}

.callout > div > form {
    margin: 0;
}

.error,
.field-error {
    color: var(--color-danger-text);
}

.field-error:empty {
    display: none;
}

.required {
    color: var(--color-danger-text);
    font-weight: var(--font-weight-normal);
}

.hint {
    display: block;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
}

.field {
    margin-block-end: var(--space-3);
}

.field > label {
    display: block;
    margin-block-end: var(--space-1);
}

/* A form in its own card (a create form under a list): a readable width. */
.form-card {
    max-inline-size: var(--form-max);
    margin-block: var(--space-6) var(--space-4);
}

.form-card > h2 {
    margin-block-start: 0;
}

.form-card form {
    margin-block-end: 0;
}

.empty {
    padding: var(--space-4) var(--space-5);
    border: var(--border-width) dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text-muted);
    text-align: center;
}

/* Empty state: an icon, a title, a sentence and the next step. */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    margin-block: var(--space-4) var(--space-5);
    padding: var(--space-6) var(--space-5);
    border: var(--border-width) dashed var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    text-align: center;
}

.empty-state-icon {
    inline-size: 3.5rem;
    block-size: 3.5rem;
    border-radius: var(--radius-pill);
}

.empty-state-icon .ui-icon {
    inline-size: 1.75rem;
    block-size: 1.75rem;
}

.empty-state h2 {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-md);
}

.empty-state .empty {
    max-inline-size: 40rem;
    margin: 0 0 var(--space-2);
    padding: 0;
    border: 0;
    background: none;
}

/* Breadcrumbs, pagers, view switches. Breadcrumbs (from repo.css, so every page can use them): on narrow screens only the first
   and the last two levels show, with an ellipsis between. */
.breadcrumb {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.breadcrumb ol {
    display: flex;
    flex-wrap: wrap;
    margin: var(--space-2) 0;
    padding: 0;
    list-style: none;
}

.breadcrumb li + li::before {
    padding: 0 0.4em;
    content: "/";
}

@media (width < 40rem) {
    .breadcrumb li:not(:first-child):not(:nth-last-child(-n+2)) {
        display: none;
    }

    .breadcrumb li:first-child:nth-last-child(n+4)::after {
        padding-inline-start: 0.4em;
        content: "/ \2026";
    }
}

.breadcrumb [aria-current] {
    color: var(--color-text);
    font-weight: var(--font-weight-bold);
}

.pager,
.search-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-block: var(--space-4);
}

.pager a {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--control-height-sm);
    padding: var(--space-1) var(--space-3);
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    text-decoration: none;
}

.pager a:hover {
    background: var(--color-primary-wash);
}

.pager [aria-current] {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.view-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* The repository tree and thumbnails. */
main > .tree:not(:has(li)) {
    display: none;
}

main > .tree {
    padding: var(--space-3) var(--space-4);
    border: var(--border-width) solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
}

.tree li {
    padding-block: var(--space-1) 0;
}

.tree button {
    min-inline-size: var(--control-height-xs);
    min-height: var(--control-height-xs);
    margin-inline-end: var(--space-1);
    padding: 0;
    line-height: 1;
}

.thumbs > li {
    padding: var(--space-3);
    border: var(--border-width) solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
}

/* ---------- UI/UX round 3, phase B0: table toolbar, form grid and actions, dialog, toast ---------- */

/* Table toolbar: over a list, its title (with a count badge) at the start, a search or filter form, the actions at the end; the
   list's .table-wrap follows straight under it. */
.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    margin-block: var(--space-5) var(--space-3);
}

.table-toolbar > :is(h2, h3) {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

.table-toolbar form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
}

.table-toolbar label:has(> :is(input, select)) {
    margin: 0;
}

.table-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-inline-start: auto;
}

.table-toolbar + .table-wrap {
    margin-block-start: 0;
}

/* Form grid: fields in two columns where there is room (a page, not the 36rem upload panel), one column otherwise. A wrapping
   label, a .field or a p > label each take one cell; .form-grid-full (and fieldsets, error summaries) span the row. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
    gap: 0 var(--space-5);
    max-inline-size: 60rem;
}

.form-grid > :is(label, p, .field) {
    margin-block: 0 var(--space-3);
}

.form-grid > label:has(> :is(input, select, textarea)),
.form-grid > p > label:has(> :is(input, select, textarea)) {
    display: flex;
    max-inline-size: none;
    margin-inline-end: 0;
}

.form-grid :is(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea) {
    inline-size: 100%;
    max-inline-size: 100%;
}

.form-grid > :is(.form-grid-full, fieldset, .error-summary, .form-actions) {
    grid-column: 1 / -1;
}

/* Form actions: the submit (primary) first, then the secondary ones, on a rule under the fields. */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-block: var(--space-4) 0;
    padding-block-start: var(--space-4);
    border-block-start: var(--border-width) solid var(--color-border-subtle);
}

.form-actions form {
    margin: 0;
}

/* Dialog: a native <dialog class="dialog" aria-labelledby> opened with showModal() (focus moves in, Escape closes, the page
   behind is inert); its script returns focus to the opener on "close" (folder-picker.js). The title h2 first, the content, then
   .dialog-actions. Opt-in by class: the viewer's dialogs keep viewer.css. */
.dialog {
    inline-size: min(36rem, calc(100vw - 2 * var(--space-4)));
    max-block-size: min(85vh, 48rem);
    padding: var(--space-4) var(--space-5);
    overflow: auto;
    border: var(--border-width) solid var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

.dialog-wide {
    inline-size: min(56rem, calc(100vw - 2 * var(--space-4)));
}

.dialog::backdrop {
    background: var(--color-backdrop);
}

.dialog > h2:first-child {
    margin-block: 0 var(--space-4);
    font-size: var(--font-size-md);
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-block-start: var(--space-4);
}

.dialog-actions form {
    margin: 0;
}

/* Toast: a script-written confirmation over the page at the bottom end (with a callout tone: .toast.callout-success). It stays
   until its script removes it (no timer: WCAG 2.2.1); its container is a role="status" region that exists before the text. */
.toast-region {
    position: fixed;
    inset-block-end: var(--space-5);
    inset-inline-end: var(--space-5);
    z-index: var(--z-dropdown);
    display: grid;
    gap: var(--space-2);
    inline-size: min(26rem, calc(100vw - 2 * var(--space-5)));
}

.toast-region:empty {
    display: none;
}

.toast {
    margin: 0;
    box-shadow: var(--shadow-lg);
}

/* ---------- UX round 2: page structure, action bar, panels, details, flash, empty rows ---------- */

/* A sortable column's header reads as header text; the current sort shows an arrow (aria-sort says it to screen readers).
   Unlayered: the base button rule is more specific than any "thead th button" selector inside the layer. */
thead th button,
thead th button:hover {
    min-height: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-decoration: none;
}

thead th button:hover,
thead th button:focus-visible {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

thead th[aria-sort] button::after {
    content: "";
    display: inline-block;
    margin-inline-start: var(--space-1);
    vertical-align: middle;
    border-inline: 4px solid transparent;
    border-block-end: 5px solid currentColor;
}

thead th[aria-sort="descending"] button::after {
    border-block-end: 0;
    border-block-start: 5px solid currentColor;
}

/* Page structure (round 2 pages): breadcrumb, then the title with the page's actions under it, then the content. */
.page-head {
    margin-block-end: var(--space-5);
}

.page-head h1 {
    margin-block-end: var(--space-3);
    overflow-wrap: anywhere;
}

.action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.action-bar form {
    margin: 0;
}

/* A panel the action bar opens (details/summary: keyboard operable, no script) drops down over the content. */
.action-panel {
    position: relative;
}

.action-panel-body {
    position: absolute;
    inset-block-start: calc(100% + var(--space-1));
    inset-inline-start: 0;
    z-index: var(--z-dropdown);
    inline-size: min(36rem, 90vw);
    padding: var(--space-4) var(--space-5);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}

.action-panel-body form {
    margin-block-end: 0;
}

.upload .drop {
    padding: var(--space-4);
    border: 2px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    text-align: center;
}

.upload [data-upload-results]:empty {
    display: none;
}

/* The list's own bar: the item count, then the view options as joined toggle buttons. */
.list-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    margin-block: var(--space-2);
}

.list-bar p,
.list-bar form {
    margin: 0;
}

.list-count {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.view-options {
    gap: var(--space-4);
}

.segmented {
    display: inline-flex;
    align-items: center;
}

.segmented-label {
    margin-inline-end: var(--space-2);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.segmented button {
    min-height: var(--control-height-sm);
    padding: 0 var(--space-3);
    border-radius: 0;
    font-size: var(--font-size-sm);
}

.segmented button + button {
    margin-inline-start: calc(-1 * var(--border-width));
}

.segmented button:first-of-type {
    border-start-start-radius: var(--radius-md);
    border-end-start-radius: var(--radius-md);
}

.segmented button:last-of-type {
    border-start-end-radius: var(--radius-md);
    border-end-end-radius: var(--radius-md);
}

/* Download as ZIP sits over the list it acts on; its summary lines beside it. */
.zip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
}

.zip [role="status"]:not(:empty) {
    flex: 1;
    margin: 0;
}

.zip [role="status"] p {
    margin: 0;
}

/* Row links: a document's name opens it, its properties are a small secondary link. */
.row-link {
    margin-inline-start: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
}

td.num,
th.num {
    text-align: end;
    white-space: nowrap;
}

.empty-row td {
    padding: var(--space-4);
    color: var(--color-text-muted);
    text-align: center;
}

/* Details panels: label and value side by side; the user's rights as chips. */
.details-layout {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
    align-items: start;
    gap: var(--space-4);
    margin-block: var(--space-4);
}

dl.details {
    display: grid;
    grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
    gap: var(--space-2) var(--space-5);
    margin: 0;
}

dl.details dt {
    color: var(--color-text-muted);
    font-weight: var(--font-weight-bold);
}

dl.details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.chips li {
    padding: 0 var(--space-2);
    border: var(--border-width) solid var(--color-primary-tint);
    border-radius: var(--radius-pill);
    background: var(--color-primary-wash);
    color: var(--color-primary);
    font-size: var(--font-size-sm);
}

.hint-inline {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.link-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
}

/* Collapsed panels for less frequent changes (rename, move, advanced search, customise the dashboard): a bordered row that
   opens in place. */
.disclosures {
    display: grid;
    gap: var(--space-2);
    max-inline-size: 48rem;
    margin-block-end: var(--space-4);
}

details.disclosure {
    border: var(--border-width) solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
}

details.disclosure > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: var(--control-height);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-lg);
    color: var(--color-primary);
    font-weight: var(--font-weight-bold);
    cursor: pointer;
}

details.disclosure > summary:hover {
    background: var(--color-primary-wash);
}

details.disclosure[open] > summary {
    border-end-start-radius: 0;
    border-end-end-radius: 0;
    border-block-end: var(--border-width) solid var(--color-border-subtle);
}

details.disclosure > :not(summary) {
    margin: var(--space-3) var(--space-4);
}

.customise {
    max-inline-size: var(--form-max);
    margin-block-start: var(--space-6);
}

.arrange {
    max-inline-size: 40rem;
    padding: 0;
    list-style: none;
}

.arrange li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-block: var(--space-2);
    border-block-end: var(--border-width) solid var(--color-border-subtle);
}

.arrange li:last-child {
    border-block-end: 0;
}

.arrange li form {
    margin: 0;
}

.arrange li > form:first-of-type {
    margin-inline-start: auto; /* the widget's name at the start, its buttons at the end */
}

.arrange button[type="submit"] {
    min-height: var(--control-height-sm);
    padding: 0 var(--space-3);
    background: var(--color-surface);
    color: var(--color-primary);
    font-size: var(--font-size-sm);
}

.arrange button[type="submit"]:hover {
    background: var(--color-primary-wash);
}

/* The confirmation after a successful POST (Views/Shared/_Flash.cshtml): success colours with a start border and an icon. */
main p.flash[role="status"] {
    border-color: var(--color-success-bg);
    border-inline-start-color: var(--color-success-text);
    background: var(--color-success-bg);
    color: var(--color-success-text);
}

main p.flash[role="status"]:empty {
    margin: 0; /* QA-085: a script-filled confirmation takes no room until it has text */
}

.flash > .ui-icon {
    margin-inline-end: var(--space-2);
}

.flash a {
    margin-inline-start: var(--space-2);
    color: inherit;
    font-weight: var(--font-weight-bold);
}

/* The search page: the query box and button first, the options in one row, the advanced sections collapsed. */
.search-bar,
.search-options {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0 var(--space-2);
}

.search-bar > button {
    margin-block-end: var(--space-3);
}

.search-query {
    flex: 0 1 36rem;
}

.search-query input {
    inline-size: 100%;
}

.search-options > label:has(> input[type="checkbox"]) {
    min-block-size: var(--control-height);
    margin-block-end: var(--space-3);
}

.search-advanced {
    margin-block: var(--space-2) var(--space-4);
}

/* ---------- Sign-in, password and error pages: a centred card with the product mark over a navy band ---------- */

.page-auth {
    align-items: center;
    padding: var(--space-8) var(--space-4);
    background:
        linear-gradient(160deg, var(--navy-700) 0%, var(--navy-600) 100%) top / 100% 18rem no-repeat,
        var(--color-bg);
}

.auth-card {
    flex: none;
    inline-size: 100%;
    max-inline-size: var(--auth-width);
    padding: var(--space-6) var(--space-6) var(--space-5);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}

.auth-brand {
    display: flex;
    align-items: center;
    min-block-size: 2.75rem;
    margin-block-end: var(--space-5);
    padding-block-end: var(--space-4);
    padding-inline-start: 3.5rem;
    border-block-end: var(--border-width) solid var(--color-border-subtle);
    background: url("../img/logo.svg") no-repeat left top / 2.75rem 2.75rem;
    color: var(--color-primary);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
}

.auth-card h1 {
    font-size: var(--font-size-lg);
}

.auth-card input:not([type="hidden"]) {
    inline-size: 100%;
}

.auth-card form > button {
    inline-size: 100%;
    margin-block-start: var(--space-2);
}

.auth-card form + form button[type="submit"] {
    background: var(--color-surface);
    color: var(--color-primary);
}

.auth-card form + form button[type="submit"]:hover {
    background: var(--color-primary-wash);
}

@media (prefers-reduced-motion: reduce) {
    *,
    ::before,
    ::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media print {
    .app-header,
    .app-sidebar,
    .skip-link {
        display: none !important;
    }

    body,
    .shell body {
        display: block;
        background: none;
    }

    .shell body > main {
        max-inline-size: none;
        padding: 0;
    }
}

/* 009 whole-feature review (WCAG 1.3.1, 1.4.1): an unread notification is bold and labelled in text, not told by colour alone. */
li.unread {
    font-weight: bold;
}

.ntf-unread-label {
    margin-inline-end: 0.25em;
}

/* QA-089: the folder picker dialog (folder-picker.js, tree.js in pick mode; the frame is .dialog) and the chosen folder's name
   beside its field. */
.folder-picker ul {
    margin: 0;
    padding-inline-start: var(--space-4);
    list-style: none;
}

.folder-picker-tree {
    max-block-size: 60vh;
    overflow: auto;
}

.folder-picker li > button + button {
    border: 0;
    background: none;
    color: var(--color-primary);
    text-decoration: underline;
    cursor: pointer;
}

.folder-pick-open {
    margin-inline-start: var(--space-1);
}

.folder-pick-name {
    margin-inline-start: var(--space-2);
}

/* ===================== Theme v2 (premium, UI/UX round 3) =====================
   Unlayered on purpose: it sits over the layered base and components above. Tokens apply to the app shell and the sign-in
   pages only (the Office/Outlook/Teams panes keep the base). The viewer is left out of the control and table rules (QA-109,
   QA-111). */
.shell,
.page-auth {
    --brand-900: #0a1630;
    --brand-800: #0f1f40;
    --brand-700: #1f3864;
    --brand-600: #2a4d8f;
    --brand-500: #3563c9;
    --brand-400: #5b86e5;
    --accent-400: #f5b83d;
    --ink-900: #0f172a;
    --ink-700: #334155;
    --ink-500: #5b6b80; /* QA-166: 5:1 on the page background (was #64748b, 4.4:1) */
    --ink-400: #94a3b8;
    --line: #e5e9f2;
    --line-strong: #d4dbe7;
    --canvas: #f4f6fb;

    --color-primary: var(--brand-700);
    --color-primary-strong: var(--brand-900);
    --color-primary-soft: var(--brand-600);
    --color-primary-tint: #e8eefb;
    --color-primary-wash: #f3f6fd;
    --color-bg: var(--canvas);
    --color-text: var(--ink-900);
    --color-text-muted: var(--ink-500);
    --color-link: var(--brand-500);
    --color-border: var(--line-strong);
    --color-border-subtle: var(--line);
    --color-row-alt: #fafbfe;
    --color-icon: var(--brand-600);

    --font-sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-size-base: 0.9375rem;
    --font-weight-bold: 600;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    --shadow-xs: 0 1px 2px rgb(15 23 42 / 4%);
    --shadow-sm: 0 1px 2px rgb(15 23 42 / 4%), 0 4px 12px -2px rgb(15 23 42 / 6%);
    --shadow-md: 0 2px 4px rgb(15 23 42 / 4%), 0 12px 24px -6px rgb(15 23 42 / 10%);
    --shadow-lg: 0 8px 16px -4px rgb(15 23 42 / 8%), 0 24px 48px -12px rgb(15 23 42 / 22%);

    --header-height: 4rem;
    --sidebar-width: 16.5rem;
    --control-height: 2.5rem;
}

html.shell body {
    background: var(--canvas);
    color: var(--ink-900);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
}

/* ---- Layout: the dark sidebar runs the full height; the white app bar sits over the content only ---- */
@media (width >= 64rem) {
    .shell body {
        grid-template-areas:
            "nav header"
            "nav main"
            "nav footer";
    }

    .app-sidebar {
        position: sticky;
        inset-block-start: 0;
        block-size: 100vh;
    }

    .app-sidebar-inner {
        inset-block-start: 0;
        max-block-size: 100vh;
        block-size: 100%;
    }
}

/* ---- App bar: white, frosted, hairline ---- */
.app-header {
    background: rgb(255 255 255 / 86%);
    backdrop-filter: saturate(180%) blur(12px);
    color: var(--ink-900);
    border-block-end: 1px solid var(--line);
    box-shadow: none;
    padding-inline: var(--space-5) var(--space-6);
}

.app-header a,
.app-brand,
.app-brand:hover {
    color: var(--ink-900);
}

.app-header :focus-visible {
    outline-color: var(--brand-500);
}

.app-brand {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    letter-spacing: -0.01em;
}

.app-brand img {
    inline-size: 2.25rem;
    block-size: 2.25rem;
    border-radius: 10px;
    box-shadow: 0 4px 10px -2px rgb(245 184 61 / 45%);
}

.app-header .icon-btn,
.app-header .icon-btn:hover {
    color: var(--ink-700);
    border-radius: 12px;
}

.app-header .icon-btn:hover,
.app-header .icon-btn[aria-expanded="true"] {
    background: #eef2f9;
}

.app-bell-badge:not(:empty) {
    border-color: #fff;
    background: #cf3136; /* QA-166: white text 5:1 (was #e5484d, 3.9:1) */
    color: #fff;
}

.app-header .quick-search input[type="search"] {
    block-size: 2.625rem;
    border: 1px solid transparent;
    border-radius: 999px;
    background: #eef2f8;
    padding-inline-start: 2.75rem;
    transition: background 150ms, border-color 150ms, box-shadow 150ms;
}

.app-header .quick-search input[type="search"]:focus {
    border-color: var(--brand-400);
    background: #fff;
    box-shadow: 0 0 0 4px rgb(53 99 201 / 14%);
    outline: none;
}

.app-header .quick-search > .ui-icon {
    inset-inline-start: 1rem;
    color: var(--ink-500);
}

.app-header .quick-search-submit,
.app-header .quick-search-submit:hover {
    border: 0;
    border-radius: 999px;
    background: var(--brand-700);
    color: #fff;
    padding-inline: 1.125rem;
    block-size: 2.625rem;
}

.app-header .quick-search-submit:hover {
    background: var(--brand-600);
}

.user-menu > summary {
    padding: 0.25rem 0.75rem 0.25rem 0.25rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink-900);
    font-weight: 600;
}

.user-menu > summary:hover,
.user-menu[open] > summary {
    background: #f5f7fc;
}

.user-menu > summary > .ui-icon:first-child {
    box-sizing: content-box;
    inline-size: 1.125rem;
    block-size: 1.125rem;
    padding: 0.4375rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
}

.user-menu-panel {
    border-color: var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

/* ---- Sidebar: deep navy gradient, light text, pill highlight ---- */
.app-sidebar {
    border: 0;
    background: linear-gradient(180deg, var(--brand-800) 0%, var(--brand-900) 100%);
    color: #c7d2e6;
}

.app-sidebar-inner {
    padding: var(--space-5) var(--space-4) var(--space-6);
    scrollbar-color: rgb(255 255 255 / 18%) transparent;
}

.nav-group {
    margin: var(--space-5) var(--space-3) var(--space-2);
    color: #7f8fb0;
    font-size: 0.6875rem;
    letter-spacing: 0.09em;
}

.app-sidebar nav a {
    gap: 0.75rem;
    min-block-size: 2.5rem;
    margin-block: 2px;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: 10px;
    color: #c7d2e6;
    font-weight: 500;
    transition: background 150ms, color 150ms;
}

.app-sidebar nav a .ui-icon {
    color: #8ea0c4;
}

.app-sidebar nav a:hover {
    background: rgb(255 255 255 / 7%);
    color: #fff;
}

.app-sidebar nav a:hover .ui-icon {
    color: #fff;
}

.app-sidebar nav a[aria-current] {
    position: relative;
    background: linear-gradient(90deg, rgb(91 134 229 / 30%), rgb(91 134 229 / 10%));
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 6%);
}

.app-sidebar nav a[aria-current]::before {
    content: "";
    position: absolute;
    inset-block: 0.5rem;
    inset-inline-start: -0.5rem;
    inline-size: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--accent-400);
}

.app-sidebar nav a[aria-current] .ui-icon {
    color: var(--accent-400);
}

.app-sidebar :focus-visible {
    outline-color: var(--accent-400);
}

/* ---- Sidebar groups: <details> accordions (shell-nav.js remembers them). The chevron turns and, where ::details-content is
   supported, the body eases open and shut; both only once shell-nav.js has set the groups (html.nav-ready), so nothing moves on
   load. The clip margin keeps the current link's gold bar, which sits in the gutter. ---- */
.app-sidebar-inner {
    overflow-x: hidden;
}

.app-sidebar nav {
    interpolate-size: allow-keywords;
}

.app-sidebar summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-block-size: 2.25rem;
    padding: 0.375rem 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.app-sidebar summary::-webkit-details-marker {
    display: none;
}

.app-sidebar summary:hover {
    background: rgb(255 255 255 / 5%);
    color: #fff;
}

.app-sidebar summary .ui-icon {
    margin-inline-start: auto;
    inline-size: 1rem;
    block-size: 1rem;
    color: #7f8fb0;
    transform: rotate(-90deg);
}

.app-sidebar details[open] > summary .ui-icon {
    transform: none;
}

.app-sidebar summary:hover .ui-icon {
    color: #fff;
}

.app-sidebar details::details-content {
    block-size: 0;
    overflow: clip;
    overflow-clip-margin: 0.5rem;
}

.app-sidebar details[open]::details-content {
    block-size: auto;
}

.nav-ready .app-sidebar details::details-content {
    transition: block-size 200ms ease, content-visibility 200ms allow-discrete;
}

.nav-ready .app-sidebar summary .ui-icon {
    transition: transform 200ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .nav-ready .app-sidebar details::details-content {
        transition: none;
    }
}

.app-sidebar .nav-group {
    margin: var(--space-4) 0 var(--space-1);
}

.app-sidebar .nav-section:first-child > .nav-group {
    margin-block-start: 0;
}

/* Administration: a hairline above it; the overview link, then the console's areas as nested groups on a guide line. */
.nav-section + .nav-section-admin {
    margin-block-start: var(--space-4);
    padding-block-start: var(--space-2);
    border-block-start: 1px solid rgb(255 255 255 / 9%);
}

.app-sidebar .nav-sub-head {
    padding-inline-start: 2.75rem;
    color: #aab8d3;
    font-size: 0.8125rem;
    font-weight: 600;
}

.nav-sub > .nav-list {
    margin-inline-start: 2.25rem;
    padding-inline-start: 0.25rem;
    border-inline-start: 1px solid rgb(255 255 255 / 9%);
}

.app-sidebar .nav-sub a {
    min-block-size: 2.25rem;
    padding-block: 0.375rem;
    font-size: 0.875rem;
}

.app-sidebar .nav-sub a[aria-current]::before {
    inset-inline-start: calc(-0.25rem - 2px);
}

/* The overview link on another console page ("true"): Administration is the area, not the page; the page's own link has the bar. */
.app-sidebar nav a[aria-current="true"] {
    background: none;
    box-shadow: none;
}

.app-sidebar nav a[aria-current="true"]::before {
    content: none;
}

/* ---- The icon rail (html.nav-rail, wide windows, not the viewer): icons only, the names as tooltips (shell.js) and still read
   out (visually hidden); no headings or nested areas; the overview link stands for Administration. ---- */
@media (width >= 64rem) {
    .shell.nav-rail {
        --sidebar-width: 4.5rem;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar-inner {
        padding-inline: 0.75rem;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar :is(summary, .nav-sub-item) {
        display: none;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar details::details-content {
        content-visibility: visible;
        block-size: auto;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar .nav-section + .nav-section {
        margin-block-start: var(--space-2);
        padding-block-start: var(--space-2);
        border-block-start: 1px solid rgb(255 255 255 / 9%);
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar nav a {
        position: relative;
        justify-content: center;
        padding-inline: 0;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar nav a > span {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar nav a[aria-current="true"] {
        background: linear-gradient(90deg, rgb(91 134 229 / 30%), rgb(91 134 229 / 10%));
        box-shadow: inset 0 0 0 1px rgb(255 255 255 / 6%);
    }

    .nav-rail body:not(:has(> main > .viewer)) .app-sidebar nav a[aria-current="true"]::before {
        content: "";
    }

    /* The menu button says "expanded" while the full sidebar shows: no pressed tint for that resting state. */
    .shell body:not(:has(> main > .viewer)) .app-menu-button[aria-expanded="true"]:not(:hover) {
        background: transparent;
    }
}

@media (width < 64rem) {
    .shell-js .app-sidebar {
        border: 0;
    }
}

/* ---- Content ---- */
.shell body > main {
    padding: 2rem 2.5rem 3rem;
}

.shell body > footer {
    border-color: var(--line);
    color: var(--ink-500);
    font-size: 0.8125rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) h1,
.page-header h1 {
    font-family: var(--font-display);
    font-size: 1.875rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--ink-900);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) h2 {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
    font-weight: 600;
}

.page-header {
    margin-block-end: 1.75rem;
}

.page-desc,
.section-desc,
.card-desc {
    color: var(--ink-500);
}

.breadcrumb {
    font-size: 0.8125rem;
    color: var(--ink-500);
}

/* ---- Cards ---- */
.card,
.form-card,
.link-card,
.empty-state,
.stat-tile,
.action-tile,
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) section.section > .table-wrap,
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .table-wrap {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.link-card,
.action-tile {
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.link-card:hover,
.action-tile:hover {
    transform: translateY(-2px);
    border-color: #cdd8f0;
    box-shadow: var(--shadow-md);
}

/* Icon chips: tinted squares, colour varies across a set */
.section-icon,
.card-icon,
.action-tile-icon,
.empty-state-icon {
    border-radius: 12px;
    background: #e8eefb;
    color: var(--brand-600);
}

.action-tile-icon {
    inline-size: 2.75rem;
    block-size: 2.75rem;
}

:is(.action-tiles, .quick-actions, .admin-overview, .card-grid, .link-cards) > :nth-child(4n + 2) :is(.action-tile-icon, .card-icon) {
    background: #e3f6ee;
    color: #12805c;
}

:is(.action-tiles, .quick-actions, .admin-overview, .card-grid, .link-cards) > :nth-child(4n + 3) :is(.action-tile-icon, .card-icon) {
    background: #fff3dc;
    color: #b26a00;
}

:is(.action-tiles, .quick-actions, .admin-overview, .card-grid, .link-cards) > :nth-child(4n + 4) :is(.action-tile-icon, .card-icon) {
    background: #f0e9ff;
    color: #6941c6;
}

.empty-state-icon {
    background: linear-gradient(135deg, #e8eefb, #f3f6fd);
    box-shadow: inset 0 0 0 1px #dbe4f7;
}

/* Stat tiles: a big number and a colour rule */
.stat-tile {
    position: relative;
    overflow: hidden;
}

.stat-tile::before {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline: 0;
    block-size: 3px;
    background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
}

.stat-tile-warning::before {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.stat-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    color: var(--ink-900);
}

.stat-label {
    color: var(--ink-500);
    font-weight: 600;
}

/* ---- Buttons ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]),
.auth-card :is(button, .btn) {
    min-block-size: 2.5rem;
    padding-inline: 1rem;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--ink-900);
    font-weight: 600;
    box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
    transition: background 150ms, border-color 150ms, box-shadow 150ms, transform 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]):hover {
    border-color: #b9c4d8;
    background: #f7f9fd;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.btn-primary, button.primary, button[type="submit"].btn-primary),
.auth-card button[type="submit"]:first-of-type,
.page-actions .btn-primary {
    border-color: transparent;
    background: linear-gradient(180deg, var(--brand-600), var(--brand-700));
    color: #fff;
    box-shadow: 0 1px 2px rgb(15 23 42 / 10%), 0 6px 14px -6px rgb(31 56 100 / 55%), inset 0 1px 0 rgb(255 255 255 / 12%);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.btn-primary, button.primary):hover,
.page-actions .btn-primary:hover {
    background: linear-gradient(180deg, #2f59a6, var(--brand-600));
    color: #fff;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.btn-danger, button.danger) {
    border-color: transparent;
    background: #d92d20;
    color: #fff;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .btn-ghost {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
}

/* ---- Forms ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(input:not([type="checkbox"], [type="radio"], [type="file"], [type="submit"], [type="hidden"]), select, textarea),
.auth-card :is(input:not([type="checkbox"], [type="radio"], [type="hidden"]), select) {
    min-block-size: 2.5rem;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--ink-900);
    transition: border-color 150ms, box-shadow 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(input, select, textarea):focus,
.auth-card :is(input, select):focus {
    border-color: var(--brand-400);
    box-shadow: 0 0 0 4px rgb(53 99 201 / 14%);
    outline: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) label,
.auth-card label {
    color: var(--ink-700);
    font-weight: 600;
    font-size: 0.875rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"],
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="radio"] {
    accent-color: var(--brand-600);
    inline-size: 1.05rem;
    block-size: 1.05rem;
}

/* ---- Tables ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) table {
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .table-wrap {
    overflow: auto;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .table-wrap > table {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) table:not(.table-wrap > table) {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) thead th {
    background: #f8fafd;
    border-block-end: 1px solid var(--line);
    color: var(--ink-500);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding-block: 0.75rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody td,
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody th {
    padding-block: 0.8rem;
    border-block-end: 1px solid #eef1f6;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr:last-child > * {
    border-block-end: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr {
    transition: background 120ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr:hover {
    background: #f6f8fe;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr:nth-child(even) {
    background: transparent;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr:nth-child(even):hover {
    background: #f6f8fe;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td a,
.row-link {
    color: var(--brand-600);
    font-weight: 600;
    text-decoration: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td a:hover {
    text-decoration: underline;
}

/* ---- Badges, callouts, flash ---- */
.badge {
    border: 0;
    border-radius: 999px;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.callout,
.notice,
.flash {
    border-radius: 12px;
}

.flash {
    box-shadow: var(--shadow-sm);
}

/* ---- Tabs ---- */
.tabs a[aria-current],
.tabs [aria-selected="true"] {
    color: var(--brand-700);
    font-weight: 600;
}

/* ---- Sign-in ---- */
.page-auth {
    background:
        radial-gradient(1200px 500px at 15% -10%, rgb(91 134 229 / 35%), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgb(245 184 61 / 18%), transparent 55%),
        linear-gradient(180deg, var(--brand-800), var(--brand-900));
    min-block-size: 100vh;
}

.auth-card {
    border: 1px solid rgb(255 255 255 / 60%);
    border-radius: 20px;
    box-shadow: 0 30px 60px -20px rgb(0 0 0 / 45%);
}

/* ---- Dashboard composition ---- */
.action-tiles {
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1rem;
}

.action-tile {
    padding: 1.125rem 1.25rem;
}

.action-tile .link-card-title {
    color: var(--ink-900);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
}

@media (width >= 75rem) {
    .widgets {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .widgets > :first-child {
        grid-column: span 2;
        grid-row: span 2;
    }
}

.dashboard > .page-header {
    position: relative;
    overflow: hidden;
    padding: 1.75rem 2rem;
    border-radius: 20px;
    background:
        radial-gradient(600px 240px at 100% 0%, rgb(245 184 61 / 28%), transparent 60%),
        radial-gradient(700px 300px at 0% 100%, rgb(91 134 229 / 45%), transparent 60%),
        linear-gradient(120deg, var(--brand-800), var(--brand-700) 60%, var(--brand-600));
    color: #fff;
    box-shadow: 0 20px 40px -20px rgb(15 31 64 / 60%);
}

.dashboard > .page-header h1,
.dashboard > .page-header .page-desc {
    color: #fff;
}

.dashboard > .page-header .page-desc {
    opacity: 0.85;
}

.dashboard > .page-header :is(button, .btn) {
    border-color: rgb(255 255 255 / 35%) !important;
    background: rgb(255 255 255 / 12%) !important;
    color: #fff !important;
    box-shadow: none !important;
}

.dashboard > .page-header :is(button, .btn):hover {
    background: rgb(255 255 255 / 20%) !important;
}

.widgets .card {
    padding: 1.25rem 1.5rem;
}

.widgets .card h2 {
    font-size: 1.0625rem;
}

/* Sort buttons in table headers stay header text, not boxed buttons */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) thead :is(button, .btn, a) {
    min-block-size: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    color: inherit !important;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-decoration: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) thead :is(button, a):hover {
    color: var(--brand-600) !important;
}

/* ===================== Page layouts: form, detail, settings and list pages (UI/UX round 3) =====================
   The page standard over Theme v2 (docs/design/design-system.md, "Form pages", "Detail pages with actions", "Settings pages",
   "List pages"). Pages opt in by class. Global in the shell (outside the viewer): the select chevron, the row-header link, end-aligned
   .num cells, the empty-row look and the button tones (danger, primary hover, .btn-link), which Theme v2's generic button rule
   (weight 0,5,2; hover 0,6,2) otherwise overrides. Rules that restyle controls repeat Theme v2's prefix
   ".shell main:not(:has(> .viewer)):not(:has(> .viewer))", buttons its whole button selector, so they win over it. */

/* ---- Selects: no native arrow, a chevron from a static file (CSP img-src 'self'; no data: URI) ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) select:not([multiple], [size]) {
    appearance: none;
    padding-inline: 0.875rem 2.5rem;
    background: #fff url("../img/select-chevron.svg") no-repeat right 0.75rem center / 1rem 1rem;
    cursor: pointer;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) select:not([multiple], [size]):dir(rtl) {
    background-position: left 0.75rem center;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) select:not([multiple], [size]):hover {
    border-color: #b9c4d8;
}

/* ---- Page header for one object: identity block (avatar or icon chip), the title, status pills, Cancel / Save at the end ---- */
.page-header-object {
    align-items: center;
}

.page-header-object > .page-header-text {
    flex: 1 1 20rem;
}

.object-avatar,
.object-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: 3.5rem;
    block-size: 3.5rem;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    box-shadow: 0 6px 14px -6px rgb(31 56 100 / 55%);
}

/* Initials come from data-initials (the span is aria-hidden): no text node, so no uncatalogued text and nothing read twice. */
.object-avatar::before {
    content: attr(data-initials);
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 650;
    letter-spacing: 0.02em;
}

.object-icon {
    border-radius: 16px;
    background: #e8eefb;
    color: var(--brand-600);
    box-shadow: inset 0 0 0 1px #dbe4f7;
}

.object-icon .ui-icon {
    inline-size: 1.75rem;
    block-size: 1.75rem;
}

.page-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.page-header-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

.page-header-meta > li {
    display: contents;
}

.badge-count {
    background: #e8eefb;
    color: var(--brand-700);
    font-size: 0.8125rem;
    padding-inline: 0.625rem;
}

/* ---- Page body: main sections (2/3) beside a side column (1/3: status, actions, related) from 1200px; one column below ---- */
.page-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 1.5rem;
}

.page-main,
.page-side {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 1.5rem;
    min-inline-size: 0;
}

@media (width >= 75rem) {
    .page-body:has(> .page-side) {
        grid-template-columns: minmax(0, 2fr) minmax(18rem, 1fr);
    }
}

.page-body form,
.page-body .card,
.page-stack form {
    margin: 0;
}

/* Page sections stacked under each other (scope cards, settings sections, the edit form's section cards). */
/* A flex column, not a grid: a sticky bar inside it is held by the whole form, not by its own grid row. */
.page-stack {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.page-stack > * {
    min-inline-size: 0;
    margin: 0;
}

.page-stack + .page-stack,
.page-body + .page-stack,
.page-stack + .page-body {
    margin-block-start: 1.5rem;
}

/* ---- Form section: a card with a heading, one line under it, then the field grid ---- */
.form-section {
    container: form-section / inline-size;
    padding: 1.5rem;
}

.form-section-head {
    margin-block-end: 1.25rem;
    padding-block-end: 1rem;
    border-block-end: 1px solid var(--line);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .form-section-head h2 {
    margin: 0;
    color: var(--ink-900);
    font-size: 1.0625rem;
}

.form-section-desc {
    margin: 0.25rem 0 0;
    color: var(--ink-500);
    font-size: 0.875rem;
}

.form-section > :last-child {
    margin-block-end: 0;
}

/* The field grid: columns follow the card's width (container query), not the window: 3 from 54rem (a desktop window with the
   section at full width, or the main column on a wide screen), 2 from 36rem, 1 below. .field-full spans the row. */
.field-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem 1.5rem;
    margin: 0;
}

@container form-section (width >= 36rem) {
    .field-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container form-section (width >= 54rem) {
    .field-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.field-grid > .field-full {
    grid-column: 1 / -1;
}

.field-grid > .field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-inline-size: 0;
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > :is(label, dt) {
    display: block;
    margin: 0;
    color: var(--ink-700);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.3;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > :is(input:not([type="checkbox"], [type="radio"], [type="file"]), select) {
    inline-size: 100%;
    max-inline-size: 100%;
    block-size: var(--control-height);
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > textarea {
    inline-size: 100%;
    max-inline-size: 100%;
    min-block-size: 6rem;
    margin: 0;
    padding-block: 0.5rem;
}

.field-grid .hint,
.field-grid .field-error {
    margin: 0;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.field-grid .field-error {
    font-weight: 600;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid :is(input, select, textarea)[aria-invalid="true"] {
    border-color: #d92d20;
    box-shadow: 0 0 0 4px rgb(217 45 32 / 12%);
}

.field-grid .required {
    margin-inline-start: 0.125rem;
    color: #d92d20;
    font-weight: 700;
}

/* Read-only values in the same rhythm as inputs: dl.field-grid > div.field.field-readonly > dt + dd. */
.field-readonly > dd {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    min-block-size: var(--control-height);
    margin: 0;
    padding: 0.375rem 0.875rem;
    border-radius: 10px;
    background: #f6f8fc;
    color: var(--ink-900);
    overflow-wrap: anywhere;
}

.field-readonly > dd:empty::before,
dl.facts dd:empty::before {
    content: "\2014";
    color: var(--ink-400);
}

/* ---- Switch (opt-in: input type=checkbox role=switch; name, value and posting unchanged) ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"][role="switch"] {
    appearance: none;
    position: relative;
    flex: none;
    inline-size: 2.5rem;
    block-size: 1.5rem;
    margin: 0;
    border: 0;
    border-radius: 999px;
    background: #94a3b8;
    cursor: pointer;
    transition: background 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"][role="switch"]::before {
    content: "";
    position: absolute;
    inset-block-start: 0.1875rem;
    inset-inline-start: 0.1875rem;
    inline-size: 1.125rem;
    block-size: 1.125rem;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 1px 3px rgb(15 23 42 / 30%);
    transition: transform 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"][role="switch"]:checked {
    background: var(--brand-600);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"][role="switch"]:checked::before {
    transform: translateX(1rem);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) input[type="checkbox"][role="switch"]:checked:dir(rtl)::before {
    transform: translateX(-1rem);
}

/* A switch row: the setting's text, the switch at the end (label.switch-field wrapping both). */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) label.switch-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-block-size: var(--control-height);
    margin: 0;
    color: var(--ink-900);
    font-size: 0.875rem;
    font-weight: 500;
}

/* ---- Segmented choice: a small enumeration (Yes / No) as radios sharing one name; exactly one value is posted. A plain
   fieldset (.fieldset-plain: no frame, its legend styled as a field label) groups other controls the same way. ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) fieldset:is(.segmented-field, .fieldset-plain) {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) fieldset:is(.segmented-field, .fieldset-plain) > legend {
    float: inline-start;
    inline-size: 100%;
    margin: 0 0 0.375rem;
    padding: 0;
    color: var(--ink-700);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.3;
}

.segmented-choice {
    display: inline-flex;
    align-self: flex-start;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #eef2f8;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .segmented-choice > label {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-inline-size: 4.5rem;
    min-block-size: 2.0625rem;
    margin: 0;
    padding: 0 1rem;
    border-radius: 8px;
    color: var(--ink-700);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms, color 150ms, box-shadow 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .segmented-choice > label > input[type="radio"] {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .segmented-choice > label:has(> input:checked) {
    background: #fff;
    color: var(--brand-700);
    box-shadow: 0 1px 2px rgb(15 23 42 / 10%), 0 2px 6px -2px rgb(15 23 42 / 12%);
}

.segmented-choice > label:has(> input:focus-visible) {
    outline: 3px solid var(--brand-500);
    outline-offset: 1px;
}

/* ---- Checkbox groups: a long multi-choice list (privileges) as titled groups in columns ---- */
.check-groups {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem 1.25rem;
}

@container form-section (width >= 36rem) {
    .check-groups {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container form-section (width >= 54rem) {
    .check-groups {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .check-group {
    min-inline-size: 0;
    margin: 0;
    padding: 0.75rem 0.875rem 0.875rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfe;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .check-group > :is(legend, h3) {
    margin: 0 0 0.25rem;
    padding-inline: 0.375rem;
    color: var(--ink-700);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.check-list {
    display: grid;
    gap: 0.125rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .check-list label {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    min-block-size: 2rem;
    margin: 0;
    padding: 0.375rem;
    border-radius: 8px;
    color: var(--ink-900);
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.35;
    cursor: pointer;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .check-list label:hover {
    background: #f1f5fd;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .check-list input[type="checkbox"] {
    margin-block-start: 0.0625rem;
}

/* The same list read-only (a built-in role's privileges): a tick before each item. */
.check-list-readonly li {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.25rem 0.375rem;
    font-size: 0.875rem;
}

.check-list-readonly .ui-icon {
    inline-size: 1rem;
    block-size: 1rem;
    margin-block-start: 0.125rem;
    color: #12805c;
}

/* ---- Facts: a card's label / value rows (Source, State, Open sessions, created, modified) ---- */
dl.facts {
    display: grid;
    margin: 0;
}

dl.facts > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    padding-block: 0.625rem;
    border-block-start: 1px solid #eef1f6;
}

dl.facts > div:first-child {
    padding-block-start: 0;
    border-block-start: 0;
}

dl.facts > div:last-child {
    padding-block-end: 0;
}

dl.facts dt {
    color: var(--ink-500);
    font-size: 0.8125rem;
    font-weight: 600;
}

dl.facts dd {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.375rem;
    margin: 0;
    color: var(--ink-900);
    font-weight: 600;
    text-align: end;
    overflow-wrap: anywhere;
}

/* A side card's own title: smaller than a section heading. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .card > h2.card-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 1rem;
    color: var(--ink-900);
    font-size: 0.9375rem;
}

.card > h2.card-title .ui-icon {
    color: var(--brand-600);
}

/* ---- Actions card: one row per object action (title, one line, its control at the end); destructive ones in a danger zone ---- */
.actions-card {
    padding: 1.25rem 1.5rem 1.5rem;
}

.action-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.625rem 1rem;
    padding-block: 0.875rem;
    border-block-start: 1px solid #eef1f6;
}

.action-row:first-child {
    padding-block-start: 0;
    border-block-start: 0;
}

.action-row:last-child {
    padding-block-end: 0;
}

.action-row-text {
    flex: 1 1 12rem;
    min-inline-size: 0;
}

.action-row-title {
    margin: 0;
    color: var(--ink-900);
    font-size: 0.875rem;
    font-weight: 600;
}

.action-row-desc {
    margin: 0.125rem 0 0;
    color: var(--ink-500);
    font-size: 0.8125rem;
    line-height: 1.45;
}

.action-row > form,
.action-row > .btn {
    flex: none;
    margin: 0;
}

/* An action with its own field (a temporary password): label, field and button in one compact row under the text. */
.action-row > form.action-row-form {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
}

.action-row-form > .field {
    display: flex;
    flex: 1 1 10rem;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .action-row-form > .field > label {
    color: var(--ink-500);
    font-size: 0.75rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .action-row-form > .field > input {
    inline-size: 100%;
    block-size: var(--control-height);
}

.danger-zone {
    margin-block-start: 1.25rem;
    padding: 0.875rem 1rem 1rem;
    border: 1px solid #f5c2bd;
    border-radius: 12px;
    background: #fff8f7;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .danger-zone > h3 {
    margin: 0 0 0.75rem;
    color: #b42318;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.danger-zone .action-row {
    border-color: #f8d9d5;
}


/* ---- Sticky action bar: the same Cancel / Save as the header, kept in view at the bottom of a long form ---- */
.form-actions-sticky {
    position: sticky;
    inset-block-end: 0.75rem;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-block-start: 1.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgb(255 255 255 / 92%);
    backdrop-filter: saturate(180%) blur(10px);
    box-shadow: 0 10px 30px -12px rgb(15 23 42 / 28%);
}

.form-actions-sticky-note {
    margin: 0;
    margin-inline-end: auto;
    color: var(--ink-500);
    font-size: 0.8125rem;
}

/* ---- Cards holding a table (members, holders) and list pages: the table runs edge to edge between head and foot ---- */
.card-table,
.list-card {
    padding: 0;
    overflow: hidden;
}

.card-table > .form-section-head {
    margin: 0;
    padding: 1.25rem 1.5rem 1rem;
    border: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.card-table, .list-card, .sub-panel) > .table-wrap {
    margin: 0;
    border: 0;
    border-block-start: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
}

.card-table > .callout,
.card-table > .empty {
    margin: 0 1.5rem 1.25rem;
}

.card-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1.5rem;
    padding: 1rem 1.5rem 1.25rem;
    border-block-start: 1px solid var(--line);
    background: #fbfcfe;
}

.card-foot > form {
    display: flex;
    flex: 1 1 16rem;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
    margin: 0;
}

.card-foot .field {
    display: flex;
    flex: 1 1 10rem;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .card-foot .field > label {
    color: var(--ink-500);
    font-size: 0.75rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .card-foot .field > :is(input, select) {
    inline-size: 100%;
    block-size: var(--control-height);
}

/* ---- List pages: one card holding the toolbar, the table and its footer ---- */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin: 0;
    padding: 1rem 1.25rem;
}

.list-search {
    position: relative;
    display: flex;
    flex: 1 1 16rem;
    flex-direction: column;
    gap: 0.25rem;
    min-inline-size: 0;
}

.list-search > .ui-icon {
    position: absolute;
    inset-block-end: 0.625rem;
    inset-inline-start: 0.75rem;
    color: var(--ink-400);
    pointer-events: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .list-search > input {
    inline-size: 100%;
    block-size: var(--control-height);
    padding-inline-start: 2.5rem;
}

.toolbar-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-inline-size: 9rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.toolbar-field, .list-search) > label {
    margin: 0;
    color: var(--ink-500);
    font-size: 0.75rem;
    font-weight: 600;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .toolbar-field > select {
    inline-size: 100%;
    block-size: var(--control-height);
}

.list-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}


.list-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    margin: 0;
    padding: 0.75rem 1.25rem;
    border-block-start: 1px solid var(--line);
    background: #fbfcfe;
    color: var(--ink-500);
    font-size: 0.8125rem;
}

.list-footer > * {
    margin: 0;
}

/* The record's name in the first column: the bold link into it. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody th[scope="row"] > a {
    color: var(--brand-700);
    font-weight: 600;
    text-decoration: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody th[scope="row"] > a:hover {
    color: var(--brand-500);
    text-decoration: underline;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(th, td).num {
    text-align: end;
    font-variant-numeric: tabular-nums;
}

/* Row actions: the last cell, end-aligned, small buttons in one line. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(th, td).row-actions {
    inline-size: 1%;
    text-align: end;
    white-space: nowrap;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td.row-actions :is(button, .btn) {
    min-block-size: 2rem;
    padding-inline: 0.75rem;
    font-size: 0.8125rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td.row-actions > form {
    display: inline-block;
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr.empty-row td {
    padding-block: 2.5rem;
    color: var(--ink-500);
    text-align: center;
}

/* A create form on a list page: a card further down the page, reached from the header's button (href="#create"). */
.create-card {
    scroll-margin-block-start: calc(var(--header-height) + 1rem);
}

.create-card:target {
    border-color: var(--brand-400);
    box-shadow: 0 0 0 4px rgb(53 99 201 / 14%), var(--shadow-sm);
}

/* A section's own submit row (a create card): end-aligned under the fields on a rule. */
.form-section-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    margin: 1.25rem 0 0;
    padding-block-start: 1rem;
    border-block-start: 1px solid var(--line);
}

/* Callouts and empty lists inside a form section sit flush. */
.form-section > :is(.callout, .empty) {
    margin-block: 0 1.25rem;
}

.form-section > :is(.callout, .empty):last-child {
    margin-block-end: 0;
}

/* ---- Sub-panels: two related lists side by side inside one section card (a scope's groups and its grantees) ---- */
.split-panels {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
}

@container form-section (width >= 48rem) {
    .split-panels {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.sub-panel {
    min-inline-size: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.sub-panel > .form-section-head {
    margin: 0;
    padding: 1rem 1.25rem 0.75rem;
    border: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .form-section-head h3 {
    margin: 0;
    color: var(--ink-900);
    font-size: 0.9375rem;
}

.sub-panel > .card-foot {
    padding: 0.875rem 1.25rem 1rem;
}

.page-stack > .form-actions-sticky {
    margin-block-start: 0;
}

.list-card + .create-card {
    margin-block-start: 1.5rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .list-card > .table-wrap:first-child {
    border-block-start: 0;
}

/* ---- Button tones over Theme v2's generic button rule (its danger and primary-hover rules are lighter and lose) ---- */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]).btn-danger {
    border-color: transparent;
    background: #d92d20;
    color: #fff;
    box-shadow: 0 1px 2px rgb(15 23 42 / 10%), 0 6px 14px -6px rgb(180 35 24 / 50%);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]).btn-danger:hover {
    border-color: transparent;
    background: #b42318;
    color: #fff;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]).btn-primary:hover {
    border-color: transparent;
    background: linear-gradient(180deg, #2f59a6, var(--brand-600));
    color: #fff;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]).btn-link {
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    color: var(--brand-600);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(button, .btn, input[type="submit"]):not(.icon-btn, .link, [class*="viewer"]).btn-link:hover {
    border-color: transparent;
    background: #f1f5fd;
    color: var(--brand-700);
}

/* ===== Lane V page styles ===== */
/* UI/UX round 3, lane V (user-facing pages). Only what the page standard lacks; tokens and Theme v2's prefix as above. */

/* The folder picker's button (folder-picker.js) after an input inside a .field column: its own width, under the input. */
.field > .folder-pick-open {
    align-self: flex-start;
    margin-inline-start: 0;
}

.field > .folder-pick-name:empty {
    display: none;
}

/* A list card's other parts: the folder's list bar (count, view options), Download as ZIP, thumbnails, an empty state. */
.list-card > .list-bar {
    margin: 0;
    padding: 0.75rem 1.25rem;
}

.list-card > .zip {
    padding: 0 1.25rem 0.75rem;
}

.list-card > .thumbs {
    margin: 0;
    padding: 1rem 1.25rem;
    border-block-start: 1px solid var(--line);
}

.list-card > .empty-state {
    margin: 0;
    border: 0;
    border-block-start: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
}

/* A card foot holding only a submit (the rights matrix): the button at the end. */
.card-foot-end {
    justify-content: flex-end;
}

/* A reason inside an action row (Return a version): the textarea fills the row like the inputs. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .action-row-form > .field > textarea {
    inline-size: 100%;
    min-block-size: 4.5rem;
}

/* The version history's last cell: Download, then the restore form's choices and button wrapping in one row. */
td.version-actions > form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem 0.75rem;
    margin: 0.375rem 0 0;
}

/* ---- Search page: the form card, the results card (its head with the view, save and export tools), facets as a side card ---- */
.search-form-card .search-bar {
    align-items: flex-end;
    gap: 0.5rem;
}

.search-form-card .search-bar > button {
    margin: 0;
}

.search-form-card .search-query {
    flex: 1 1 24rem;
}

.search-form-card .search-options {
    gap: 0.75rem;
    margin-block-start: 1rem;
}

.field-grid > .segmented-choice {
    justify-self: start;
}

.search-date {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
    margin-block-start: 1.25rem;
}

.search-results-card {
    padding: 0;
    overflow: hidden;
}

.search-results-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 1rem 1.25rem;
    border-block-end: 1px solid var(--line);
}

.search-results-head:has(> h2[hidden]):has(> .search-tools[hidden]) {
    display: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .search-results-head > h2 {
    margin: 0;
    font-size: 1.0625rem;
}

.search-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

#search-results {
    padding: 1rem 1.25rem 1.25rem;
}

#search-results > .empty-state {
    margin: 0;
    border: 0;
    box-shadow: none;
}

@media (width >= 64rem) {
    #search-results:has(> .search-facets) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 15rem;
        column-gap: 1.5rem;
    }

    #search-results > * {
        grid-column: 1;
    }

    #search-results > .search-facets {
        grid-row: 1 / span 50;
        grid-column: 2;
    }
}

.search-facets {
    align-self: start;
    margin-block-end: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfe;
}

.search-facets:not(:has(li, button)) {
    display: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .search-facets > h2 {
    margin: 0 0 0.5rem;
    font-size: 0.9375rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .search-facets > h3 {
    margin: 0.75rem 0 0.25rem;
    color: var(--ink-500);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.search-facets ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.search-rows {
    margin: 0;
    padding: 0;
    list-style: none;
}

.search-rows > li {
    margin: 0;
    padding: 0.875rem 0;
    border-block-start: 1px solid #eef1f6;
    color: var(--ink-500);
    font-size: 0.875rem;
}

.search-rows > li:first-child {
    border-block-start: 0;
}

.search-rows > li > a:not(.search-share) {
    margin-inline-end: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.search-rows > li > .search-share {
    font-size: 0.8125rem;
}

/* A list box (select multiple or with a size) on the field grid keeps its own height; a checkbox with its text as a field. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > select:is([multiple], [size]) {
    block-size: auto;
    min-block-size: 8rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > label.check-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-block-size: var(--control-height);
    color: var(--ink-900);
    font-size: 0.875rem;
    font-weight: 400;
}

/* A flat checkbox list in columns (a subscription's event types). */
.check-columns {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
    gap: 0.125rem 1rem;
}

/* The notification centre: one row per notification inside the list card, the unread ones marked at their start. */
.ntf-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border-block-start: 1px solid var(--line);
}

.ntf-list > li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    margin: 0;
    padding: 0.875rem 1.25rem;
    border-block-start: 1px solid #eef1f6;
    color: var(--ink-500);
    font-size: 0.875rem;
}

.ntf-list > li:first-child {
    border-block-start: 0;
}

.ntf-list > li.unread {
    background: #f6f9ff;
    box-shadow: inset 3px 0 0 var(--brand-600);
}

.ntf-list > li > a {
    font-weight: 600;
}

.ntf-list > li > form {
    margin: 0;
    margin-inline-start: auto;
}

.list-card > .empty {
    margin: 0;
    padding: 1.5rem 1.25rem;
    border-block-start: 1px solid var(--line);
}

/* Approval pages: wf.css's tables sit flush inside the cards; a checkbox filter in a list toolbar lines up with the fields. */
:is(.list-card, .card-table) .wf-table {
    margin: 0;
}

.list-toolbar > .toolbar-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-block-size: var(--control-height);
    margin: 0;
}

.card-table > .wf-review-doc {
    margin: 0 1.5rem 1.25rem;
}

/* ---- Reports: the filter grid of the form card, the result card (count and exports in its head, pager in its foot), statistics ---- */
.report-filter-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem 1.5rem;
}

@container form-section (width >= 36rem) {
    .report-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container form-section (width >= 54rem) {
    .report-filter-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.report-filter-grid > :is(fieldset, .field-error) {
    grid-column: 1 / -1;
}

.report-filter {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-inline-size: 0;
    margin: 0;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .report-filter > :is(input:not([type="checkbox"], [type="radio"]), select) {
    inline-size: 100%;
    max-inline-size: 100%;
    block-size: var(--control-height);
}

.report-filter > .field-hint {
    color: var(--ink-500);
    font-size: 0.8125rem;
}

fieldset.report-filter,
.report-condition {
    display: flex;
    flex-flow: row wrap;
    align-items: flex-end;
    gap: 0.5rem 0.75rem;
}

.report-run-foot {
    align-items: flex-end;
}

.report-run-foot > .report-filter {
    margin-inline-end: auto;
}

.report-result {
    margin-block-start: 1.5rem;
}

.report-result-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 1rem 1.25rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .report-result-head > h2 {
    margin: 0;
    font-size: 1.0625rem;
}

.report-exports {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.report-exports > form {
    margin: 0;
}

.report-result > .report-header {
    margin: 0 1.25rem 1rem;
}

.report-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.report-pager > p {
    margin-block: 0;
    margin-inline: 0 auto;
}

.report-statistics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr));
    align-items: start;
    gap: 1.5rem;
}

.report-statistics > .report-table {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.report-statistics > .report-table > caption {
    padding: 1rem 1.25rem 0.5rem;
    font-weight: 600;
    text-align: start;
}

/* Template and tool pages (templates.js, tools.js): their cards and notices stacked; a button lined up with the fields beside it;
   an empty, hidden field table takes no room. */
:is(.tools, .templates) > :is(.card, .callout) {
    margin-block: 0 1.5rem;
}

.field-grid > .tpl-preview-field {
    justify-content: flex-end;
}

.field-grid > .tpl-preview-field > button {
    align-self: flex-start;
}

.tools-name-grid {
    margin-block-start: 1.25rem;
}

.table-wrap:has(> table[hidden]) {
    display: none;
}

.tools-sources > ol {
    margin: 0 0 0.5rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .form-section-foot > label.check-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    margin-inline-end: auto;
    font-weight: 400;
}


/* ===== Lane A1 page styles ===== */
/* Text, number and date filters in a list toolbar size like its selects (the audit trail, external shares). */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .toolbar-field > input:not([type="checkbox"], [type="radio"]) {
    inline-size: 100%;
    block-size: var(--control-height);
}

/* A row action that needs a value (cancel a reminder with a reason): label, input and button in one line. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td.row-actions > form.row-action-form {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .row-action-form > label {
    font-size: 0.8125rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .row-action-form > input {
    inline-size: 12rem;
    min-block-size: 2rem;
    block-size: 2rem;
}

/* Cards a list page stacks after its list (one edit card per stamp, then the create card). */
.create-card + .create-card {
    margin-block-start: 1.5rem;
}

/* QA-137: on a narrow window an action's form shrinks and wraps once it is on its own line (a long danger button ran 209 px off a
   390 px screen); the statistics tables' column headings wrap (the activity table ran 23 px over). */
.action-row > form:not(.action-row-form) {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-inline-size: 0;
}

.report-statistics thead th {
    white-space: normal;
}

/* QA-132: a report filter's plain fieldset (date range, field lists, conditions) holds its controls on the filter grid; a condition
   row is that grid too (not a wrapping row), with space between rows. */
.report-filter-grid > fieldset.report-filter.fieldset-plain {
    align-items: stretch;
}

.report-condition.report-filter-grid {
    display: grid;
    gap: 1.25rem 1.5rem;
}

.report-condition + .report-condition {
    margin-block-start: 1rem;
}

/* QA-133: the tools result list (under the status line) takes no room until a run fills it. */
[data-tools-result]:empty {
    display: none;
}

/* ===== Lane A2 page styles ===== */
/* Admin pages of lane A2 (metadata, filing rules, API, search, workflows, templates, capture). Tokens only; control rules carry the
   Theme v2 prefix (docs/design/design-system.md, "Structure of site.css"). */

/* A switch with a hint under it sits in a .field; the field grid's label rule would otherwise make it a small block label. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .field-grid > .field > label.switch-field {
    display: flex;
    color: var(--ink-900);
    font-size: 0.875rem;
    font-weight: 500;
}

/* A table inside a card's own form (a cabinet's rule order, a type's locations, a template's field mapping) sits flush like a
   direct .table-wrap. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) :is(.card-table > form, .card-table > fieldset) > .table-wrap {
    margin: 0;
    border: 0;
    border-block-start: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
}

/* A number box in a table cell (a filing rule's position) and a textarea in a card foot (a class's field order). */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .card-table td > input[type="number"] {
    inline-size: 6rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .card-foot .field > textarea {
    inline-size: 100%;
}

/* A long check list (API scopes, event types, customer channel types) in columns by its card's width, as the field grid. */
@container form-section (width >= 36rem) {
    .check-list-columns {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@container form-section (width >= 54rem) {
    .check-list-columns {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* An empty message inside a sub-panel (capture health's failing and suspended rules) keeps the panel's padding. */
.sub-panel > .empty {
    margin: 0 1.25rem 1rem;
}

/* A confirm disclosure among a row's actions (an archival rule's Delete): opens in the cell, its question wraps. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td.row-actions > details {
    display: inline-block;
    vertical-align: top;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) td.row-actions > details > p {
    min-inline-size: 14rem;
    margin: 0.5rem 0;
    white-space: normal;
    text-align: start;
}

/* ===== Polish pass (UI/UX round 3) ===== */
/* Fixes from walking the merged pages in Chrome. Tokens and Theme v2's prefix as above. */

/* An empty state that opens a list card has no rule above it (as .list-card > .table-wrap:first-child). */
.list-card > .empty-state:first-child {
    border-block-start: 0;
}

/* The audit trail (_Rows, on the search and the track sheet): reasons, old and new values are JSON or long text, so they get a
   readable mono column instead of a narrow wrapped one; the table scrolls sideways inside its card (.table-wrap). */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tr[data-seq] > td.cell-long {
    min-inline-size: 22rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    word-break: break-word;
}

/* A list toolbar with many filters (the audit trail): equal columns that wrap evenly, labels lined up at the top so a field
   that grows under its input (the chosen folder's name) moves nothing else; the buttons sit on the inputs' line. */
.list-toolbar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
    align-items: start;
}

.list-toolbar-grid > .list-toolbar-actions {
    min-block-size: var(--control-height);
    margin-block-start: calc(0.75rem * 1.5 + 0.25rem); /* a toolbar label's line and gap, so the buttons sit on the inputs */
}

/* A folder ID filter with the picker's button (folder-picker.js): label over the input and the button in one line, the chosen
   folder's name under them. */
.toolbar-field:has(> .folder-pick-open) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.25rem 0.5rem;
}

.toolbar-field:has(> .folder-pick-open) > :not(input, .folder-pick-open) {
    grid-column: 1 / -1;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .toolbar-field > .folder-pick-open {
    min-block-size: var(--control-height);
    margin: 0;
    white-space: nowrap;
}

.toolbar-field > .folder-pick-name {
    margin: 0;
    color: var(--ink-500);
    font-size: 0.75rem;
}

.toolbar-field > .folder-pick-name:empty {
    display: none;
}

/* An action-row form with two or more fields (Title and keywords, Reassign): one column, label over input, hint under it, the
   button under the fields. A single-field form keeps its one-line layout. */
.action-row > form.action-row-form:has(> .field ~ .field) {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.75rem;
}

.action-row-form:has(> .field ~ .field) > .field {
    flex: none;
    max-inline-size: 40rem;
    padding-block: 0;
}

.action-row-form:has(> .field ~ .field) > :is(button, .btn) {
    align-self: flex-start;
}

/* The shared empty row (_EmptyRow): a quiet empty state inside the table card, with an icon in a tinted disc. */
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr.empty-row,
.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr.empty-row:hover {
    background: none;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) tbody tr.empty-row td {
    padding: 2.5rem 1.5rem 2.75rem;
    color: var(--ink-500);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
}

.empty-row .ui-icon {
    display: block;
    inline-size: 3rem;
    block-size: 3rem;
    margin: 0 auto 0.75rem;
    padding: 0.75rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #e8eefb, #f3f6fd);
    box-shadow: inset 0 0 0 1px #dbe4f7;
    color: var(--brand-600);
}

/* ===== Typography weights (UI/UX round 3: the product owner found the semibold everywhere too heavy) =====
   Body 400; labels, buttons, menu items, table headers and links 500; headings and stat figures 600. */
.shell,
.page-auth {
    --font-weight-bold: 500;
    --font-weight-normal: 400;
}

html.shell body,
.page-auth {
    font-weight: 400;
    letter-spacing: 0;
}

.shell main h1,
.page-header h1,
.auth-card h1 {
    font-weight: 600;
    letter-spacing: -0.015em;
}

.shell main :is(h2, h3, h4),
.card-title,
.form-section-head h2,
.section-head h2 {
    font-weight: 600;
}

.shell main :is(label, legend, dt),
.auth-card label,
.field > label,
.toolbar-field > label {
    font-weight: 500;
}

.shell main :is(button, .btn, input[type="submit"]),
.auth-card :is(button, .btn),
.app-header .quick-search-submit {
    font-weight: 500;
}

.app-sidebar nav a,
.nav-fold > summary {
    font-weight: 400;
}

.app-sidebar nav a[aria-current] {
    font-weight: 500;
}

.nav-group,
.admin-nav-group {
    font-weight: 600;
}

.shell main thead th {
    font-weight: 500;
}

.shell main :is(td a, th[scope="row"], th[scope="row"] a),
.row-link,
.link-card-title,
.action-tile .link-card-title {
    font-weight: 500;
}

.badge,
.stat-label,
.user-menu > summary,
.app-brand {
    font-weight: 500;
}

.stat-value {
    font-weight: 600;
}

.shell main strong,
.shell main b {
    font-weight: 600;
}

/* ===== Pagination (UI/UX round 3) =====
   One pager for every list (docs/design/design-system.md, "List pages"): Views/Shared/_Pager.cshtml for server-paged lists (links,
   or a POST form's buttons name="page"), table-pager.js for lists sent whole, search.js for search results. In the list's footer:
   the count at the start; Previous, page numbers, Next and rows per page at the end; 32 px rounded controls, the current page navy,
   a light tint on hover. Below 640 px the numbers give way to "Page N of M". Control rules repeat Theme v2's prefix (they restyle
   links, buttons and selects that its generic rules style). Chevrons are borders (no image, no data: URI). */
.pager-count {
    margin: 0;
    color: var(--ink-500);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

:is(.list-footer, .search-pager) > :is(.pager, .report-pager) {
    margin-block: 0;
    margin-inline-start: auto;
}

.pager-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pager-list > li {
    margin: 0;
    padding: 0;
}

.pager-gap {
    min-inline-size: 1.5rem;
    color: var(--ink-400);
    text-align: center;
}

.pager-status {
    display: none;
    padding-inline: 0.5rem;
    color: var(--ink-700);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-list > li > :is(a, button, span).pager-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-inline-size: 2rem;
    min-block-size: 2rem;
    block-size: 2rem;
    margin: 0;
    padding: 0 0.625rem;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    box-shadow: none;
    color: var(--ink-700);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 150ms, border-color 150ms, color 150ms;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-list > li > :is(a[href], button:enabled).pager-link:not([aria-current]):hover {
    border-color: var(--brand-400);
    background: var(--color-primary-tint);
    color: var(--brand-700);
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-list > li > :is(a, button, span).pager-link[aria-current="page"] {
    border-color: var(--brand-700);
    background: var(--brand-700);
    color: #fff;
    font-weight: 600;
    cursor: default;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-list > li > :is(a, button).pager-link:is(:disabled, [aria-disabled="true"]) {
    border-color: var(--line);
    background: #fff;
    color: var(--ink-400);
    cursor: not-allowed;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-list > li > :is(a, button).pager-link:focus-visible {
    outline: 3px solid var(--brand-500);
    outline-offset: 2px;
}

.pager-prev::before,
.pager-next::after {
    content: "";
    inline-size: 0.375rem;
    block-size: 0.375rem;
    border: solid currentColor;
    border-width: 0 0 1.5px 1.5px;
    transform: rotate(45deg);
}

.pager-next::after {
    transform: rotate(-135deg);
}

.pager-prev:dir(rtl)::before {
    transform: rotate(-135deg);
}

.pager-next:dir(rtl)::after {
    transform: rotate(45deg);
}

.pager-size {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-size > label {
    margin: 0;
    color: var(--ink-500);
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-size > select:not([multiple]) {
    inline-size: auto;
    min-block-size: 2rem;
    block-size: 2rem;
    padding-block: 0;
    padding-inline: 0.625rem 2rem;
    border-radius: 8px;
    background-position: right 0.5rem center;
    font-size: 0.8125rem;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-size > select:not([multiple]):dir(rtl) {
    padding-inline: 2rem 0.625rem;
    background-position: left 0.5rem center;
}

.shell main:not(:has(> .viewer)):not(:has(> .viewer)) .pager-size > button:not(.icon-btn) {
    min-block-size: 2rem;
    padding-inline: 0.75rem;
    border-radius: 8px;
    font-size: 0.8125rem;
}

@media (width < 40rem) {
    .pager-list > .pager-num,
    .pager-list > .pager-gap {
        display: none;
    }

    .pager-list > .pager-status {
        display: block;
    }

    :is(.list-footer, .search-pager) > :is(.pager, .report-pager) {
        margin-inline-start: 0;
    }
}

/* QA-147: a file name keeps a readable width next to the exception queue's wide filing form. */
th.cell-name {
    min-inline-size: 12rem;
}

/* Screen-reader-only text stays 1 px wherever it is (a hidden legend in .fieldset-plain was 100% wide, so the page scrolled
   sideways). Last in the file and !important, as a utility must win over every component rule; not while focused (the skip
   link shows on focus). a11y.css has the same rule for pages without site.css. */
/* QA-164: a long saved or recent search wraps inside its card instead of widening the page. */
#saved-searches button,
#recent-searches button {
    max-inline-size: 100%;
    overflow-wrap: anywhere;
    text-align: start;
}

.visually-hidden:not(:focus):not(:active) {
    position: absolute !important;
    inline-size: 1px !important;
    min-inline-size: 0 !important;
    max-inline-size: 1px !important;
    block-size: 1px !important;
    min-block-size: 0 !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
}
