/*
 * Hand-written stylesheet. No CSS framework by decision (spec 00001, Q3): it keeps the
 * Content-Security-Policy strict and the dependency count at zero.
 */

/*
 * Roche brand colours (ai/memory/roche-style.md). Every text/background pair below passes
 * WCAG AA; the ratios are in doc/arc42/08-crosscutting-concepts.md, section 8.12.
 */
:root {
    --surface: #FFFFFF;          /* White */
    --surface-alt: #F5F5F2;      /* Grey 5: page background */
    --border: #DBD6D1;           /* Grey 4 */
    --text: #544F4F;             /* Grey 1 */
    --text-muted: #706B69;       /* Grey 2 */
    --text-hint: #8A8582;        /* Hints only: 3.65 : 1 on White, below AA by the user's choice (spec 00014) */
    --accent: #0B41CD;           /* Roche Blue: links, primary buttons */
    --accent-hover: #022366;     /* Dark Blue */
    --accent-soft: #BDE3FF;      /* Extra Light Blue: selection, highlights */
    --accent-text: #FFFFFF;
    --ok: #0B41CD;               /* Roche Blue, always with a check icon: the palette has no green */
    --warning: #B22B0D;          /* Extra Dark Orange */
    --error: #C40000;            /* Dark Red */
    --guide: #BC36F0;            /* Dark Purple: the editor's snap guides (UI accent) */
    /* Roche Sans first: used where it is installed now, and served from wwwroot once the
       files and their licence arrive (arc42 8.12). Noto Sans is the shipped fallback. */
    --font: "Roche Sans", "Noto Sans", Arial, sans-serif;
    --shadow: 0 4px 16px rgb(0 0 0 / 0.12);
    --touch: 2.75rem;            /* 44 px: minimum touch target (WCAG 2.5.5) */
    --radius: 6px;
}

/* The brand defines no dark theme; this one uses only palette blues and greys. */
@media (prefers-color-scheme: dark) {
    :root {
        --surface: #203D78;      /* Dark Blue lightened with 12% white: cards */
        --surface-alt: #022366;  /* Dark Blue: page background */
        --border: #4E6594;
        --text: #FFFFFF;
        --text-muted: #DBD6D1;   /* Grey 4 */
        --text-hint: #C2BAB5;    /* Grey 3: hints, dimmer than muted text */
        --accent: #BDE3FF;       /* Extra Light Blue */
        --accent-hover: #FFFFFF;
        --accent-soft: #1482FA;  /* Light Blue: fills only, never behind text */
        --accent-text: #022366;
        --ok: #BDE3FF;
        --warning: #FFBD69;      /* Light Orange */
        --error: #FF8782;        /* Light Red */
    }
}

/* The certificate fonts, shared with the PDF renderer (served from Rendering/Fonts). */
@font-face {
    font-family: "Roche Sans";
    src: url("/fonts/RocheSans-Regular.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Roche Sans";
    src: url("/fonts/RocheSans-Bold.ttf") format("truetype");
    font-weight: 600 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Roche Sans";
    src: url("/fonts/RocheSans-Italic.ttf") format("truetype");
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: "Roche Sans";
    src: url("/fonts/RocheSans-BoldItalic.ttf") format("truetype");
    font-weight: 600 700;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: "Noto Sans";
    src: url("/fonts/NotoSans-Regular.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Noto Sans";
    src: url("/fonts/NotoSans-Bold.ttf") format("truetype");
    font-weight: 600 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Noto Sans";
    src: url("/fonts/NotoSans-Italic.ttf") format("truetype");
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}

* {
    box-sizing: border-box;
}

/* Form controls don't inherit the page font by default. */
button,
input,
select,
textarea {
    font-family: inherit;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-alt);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: var(--accent);
}

code {
    font-family: "Cascadia Mono", Consolas, monospace;
    font-size: 0.9em;
}

/* ------------------------------------------------------------------ layout */

/*
 * Mobile first (spec 00009). Two breakpoints, written as literals because media queries
 * cannot read custom properties: 40rem (phone | tablet) and 64rem (collapsed | full nav).
 */

.app-header {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* Basis 0, so the brand shrinks (ellipsis) before the menu button wraps to a new row. */
.brand {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    font-weight: 600;
    font-size: 1rem;
    text-decoration: none;
    color: var(--text);
}

.brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand img {
    display: block;
    height: 32px;
    width: auto;
    /* Clear space around the logo (roche-style.md). */
    margin: 0.25rem 0.5rem 0.25rem 0;
}

.app-menu {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.5rem;
}

.app-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1.25rem;
}

.app-nav a,
.user-menu-items a {
    display: block;
    padding: 0.5rem 0.125rem;
    border-bottom: 2px solid transparent;
    color: var(--text);
    text-decoration: none;
}

.app-nav a:hover,
.user-menu-items a:hover {
    color: var(--accent);
}

.app-nav a[aria-current="page"],
.user-menu-items a[aria-current="page"] {
    border-bottom-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/*
 * Stable widths (spec 00016): a link reserves the width of its bold form, so marking the
 * current item never pushes the items after it. The layout sets data-label to the text.
 */
.app-nav a[data-label],
.tabs a[data-label],
.stepper .lbl-main[data-label] {
    display: inline-grid;
}

.app-nav a[data-label]::after,
.tabs a[data-label]::after,
.stepper .lbl-main[data-label]::after {
    content: attr(data-label);
    height: 0;
    overflow: hidden;
    visibility: hidden;
    font-weight: 600;
    user-select: none;
    pointer-events: none;
}

.user-menu-sep {
    margin: 0.35rem 0;
    border-top: 1px solid var(--border);
}

.user-menu-items .culture-form {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem 0.125rem;
}

.culture-form .culture-current {
    font-weight: 600;
}

.app-version {
    padding: 0.25rem 0.125rem 0.35rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.user-menu {
    position: relative;
    margin-left: auto;
}

.user-menu summary {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-height: var(--touch);
    padding: 0 0.25rem;
    color: var(--text-muted);
    list-style: none;
}

.user-menu summary::-webkit-details-marker {
    display: none;
}

.user-menu summary::after {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    margin-top: -0.2rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
}

.user-menu[open] summary::after {
    margin-top: 0.2rem;
    transform: rotate(-135deg);
}

.user-menu-items {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    min-width: 13rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.user-menu-items form {
    padding: 0.5rem 0.125rem;
}

.user-menu-items .link-button {
    color: var(--text);
    text-decoration: none;
}

.user-menu-items .link-button:hover {
    color: var(--accent);
}

.nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: var(--touch);
    margin-left: auto;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
}

.nav-toggle[hidden] {
    display: none;
}

/* Three bars from one element: the middle bar plus two shadows. */
.nav-toggle-icon {
    width: 1.1rem;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.nav-open .nav-toggle-icon {
    box-shadow: none;
    height: 2px;
    transform: rotate(45deg);
}

.nav-open .nav-toggle-icon::after {
    content: "";
    display: block;
    width: 1.1rem;
    height: 2px;
    background: currentColor;
    transform: rotate(90deg);
}

/* Below 64rem the scripted header collapses the menu behind the toggle. */
@media (max-width: 63.99rem) {
    .nav-enhanced .app-menu {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding-bottom: 0.5rem;
    }

    .nav-enhanced.nav-open .app-menu {
        display: flex;
    }

    .nav-enhanced .app-nav {
        flex-direction: column;
    }

    .nav-enhanced .app-nav a,
    .nav-enhanced .user-menu-items a {
        min-height: var(--touch);
        padding: 0.6rem 0.75rem;
        border-bottom: none;
        border-left: 3px solid transparent;
    }

    .nav-enhanced .app-nav a[aria-current="page"],
    .nav-enhanced .user-menu-items a[aria-current="page"] {
        border-left-color: var(--accent);
        background: var(--surface-alt);
    }

    /* In the phone menu the user's links are listed, not dropped down. */
    .nav-enhanced .user-menu {
        margin: 0.5rem 0 0;
        padding-top: 0.5rem;
        border-top: 1px solid var(--border);
    }

    .nav-enhanced .user-menu summary {
        padding: 0 0.75rem;
        pointer-events: none;
    }

    .nav-enhanced .user-menu summary::after {
        display: none;
    }

    .nav-enhanced .user-menu-items {
        position: static;
        min-width: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        background: none;
    }

    .nav-enhanced .user-menu-items form {
        padding: 0.6rem 0.75rem;
    }
}

@media (min-width: 64rem) {
    .app-header {
        flex-wrap: nowrap;
        padding: 0.5rem 1.5rem;
    }

    .brand {
        flex: 0 1 auto;
        font-size: 1.1rem;
    }

    .nav-toggle {
        display: none;
    }
}

.user-name {
    color: var(--text-muted);
}

/* Full width, tuned for a 1280 x 800 laptop (spec 00016). */
.app-main {
    flex: 1;
    width: 100%;
    margin: 0;
    padding: 0.75rem 1rem 1rem;
}

.culture-form {
    display: flex;
    gap: 1rem;
}

.login-culture {
    justify-content: center;
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

@media (min-width: 64rem) {
    .app-main {
        padding: 0.75rem 1.25rem 1.25rem;
    }
}

/* Column layouts used by the wizard and the lists; one column below 60rem. */
.cols {
    display: grid;
    gap: 0.75rem;
    align-items: start;
}

@media (min-width: 60rem) {
    .cols-2 {
        grid-template-columns: 1fr 1fr;
    }

    .cols-2-1 {
        grid-template-columns: 3fr 2fr;
    }

    .cols-3 {
        grid-template-columns: 1.1fr 1fr 1fr;
    }
}

/* Pages with a single narrow form keep a readable width. */
.page-narrow {
    max-width: 44rem;
}

/* ------------------------------------------------------------------- cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

@media (min-width: 40rem) {
    .card {
        padding: 1.25rem;
    }
}

.card-narrow {
    max-width: 30rem;
    margin: 0 auto;
}

/* Page title with its actions: stacked on phones, side by side from 40rem. */
.card-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.card-head h1 {
    margin: 0;
}

.card-head p {
    margin: 0.25rem 0 0;
}

.card-head .button-primary,
.card-head .button-secondary,
.card-head form {
    margin-top: 0;
    text-align: center;
}

.card-head form .button-primary,
.card-head form .button-secondary {
    width: 100%;
}

.card-head .button-row > * {
    flex: 1 1 auto;
}

@media (min-width: 40rem) {
    .card-head {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }

    .card-head .button-row {
        flex-wrap: nowrap;
    }

    .card-head form .button-primary,
    .card-head form .button-secondary {
        width: auto;
    }
}

h1 {
    margin-top: 0;
    font-size: 1.35rem;
    line-height: 1.25;
}

@media (min-width: 40rem) {
    h1 {
        font-size: 1.5rem;
    }
}

h2 {
    font-size: 1.15rem;
    margin-top: 2rem;
}

.muted {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Hints: every muted paragraph except metadata (.meta), and the variant notes. Greyer and in
   italics so they read as help, not content (spec 00014). */
p.muted:not(.meta),
.field-note {
    color: var(--text-hint);
    font-style: italic;
}

/* Anything hidden stays hidden, whatever display a class gives it. */
[hidden] {
    display: none !important;
}

/* ------------------------------------------------------------------- forms */

label {
    display: block;
    margin-top: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="search"],
select,
textarea {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
}

input[type="file"] {
    display: block;
    margin-top: 0.25rem;
}

label.checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: normal;
}

label.checkbox input {
    width: auto;
    margin: 0;
}

textarea {
    font: inherit;
    resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.button-primary,
.button-secondary {
    display: inline-block;
    margin-top: 1.25rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-text);
    font-size: 1rem;
    text-decoration: none;
    cursor: pointer;
}

.button-secondary {
    background: transparent;
    color: var(--accent);
}

.button-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.button-secondary:hover:not(:disabled) {
    color: var(--accent-hover);
    border-color: var(--accent-hover);
}

a:hover {
    color: var(--accent-hover);
}

::selection {
    background: var(--accent-soft);
    color: #022366;
}

.button-primary:disabled,
.button-secondary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.link-button {
    padding: 0;
    border: none;
    background: none;
    color: var(--accent);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
}

/* ------------------------------------------------------------------ alerts */

.alert {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-alt);
}

.alert-error {
    border-left-color: var(--error);
}

/*
 * Status icons, so success, warning and error never depend on colour alone (success is
 * blue, like links). Drawn as CSS masks from inline SVG data, which the CSP allows
 * (img-src data:); the icon takes the status colour. The mark inside each shape is cut out
 * by an SVG <mask>, because a CSS mask only reads alpha: a white stroke would vanish.
 */
.alert-success,
.alert-warning,
.alert-error {
    position: relative;
    padding-left: 2.75rem;
}

.alert-success::before,
.alert-warning::before,
.alert-error::before,
.badge-ok::before {
    content: "";
    position: absolute;
    left: 0.9rem;
    top: 0.85rem;
    width: 1.1rem;
    height: 1.1rem;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

.alert-success::before,
.badge-ok::before {
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cmask id='m'%3E%3Crect width='20' height='20' fill='white'/%3E%3Cpath d='M5.5 10.5l3 3 6-6.5' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/mask%3E%3Ccircle cx='10' cy='10' r='10' mask='url(%23m)'/%3E%3C/svg%3E");
    background-color: var(--ok);
}

.alert-warning::before {
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cmask id='m'%3E%3Crect width='20' height='20' fill='white'/%3E%3Cpath d='M10 7v5M10 14.6v.4' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/mask%3E%3Cpath d='M10 1l9.5 17h-19z' mask='url(%23m)'/%3E%3C/svg%3E");
    background-color: var(--warning);
}

.alert-error::before {
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cmask id='m'%3E%3Crect width='20' height='20' fill='white'/%3E%3Cpath d='M6.5 6.5l7 7M13.5 6.5l-7 7' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/mask%3E%3Ccircle cx='10' cy='10' r='10' mask='url(%23m)'/%3E%3C/svg%3E");
    background-color: var(--error);
}

ul.alert-success,
ul.alert-warning,
ul.alert-error {
    padding-left: 3.75rem;
}

.badge-ok {
    position: relative;
    padding-left: 1.4rem;
}

.badge-ok::before {
    left: 0.35rem;
    top: 50%;
    width: 0.8rem;
    height: 0.8rem;
    transform: translateY(-50%);
}

.alert-success {
    border-left-color: var(--ok);
}

.alert-warning {
    border-left-color: var(--warning);
}

.alert-info {
    border-left-color: var(--accent);
}

ul.alert {
    padding-left: 2rem;
}

/* ------------------------------------------------------------------ badges */

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
}


.badge-ok {
    color: var(--ok);
    border-color: var(--ok);
}

/* After .badge, whose padding shorthand would otherwise put the text under the icon. */
.badge.badge-ok {
    padding-left: 1.4rem;
}

.nowrap,
.card-head .button-primary,
.card-head .button-secondary {
    white-space: nowrap;
}

.badge-warning {
    color: var(--warning);
    border-color: var(--warning);
}

.badge-error {
    color: var(--error);
    border-color: var(--error);
}

.badge-idle {
    color: var(--text-muted);
}

/* ------------------------------------------------------------------ tables */

.data-table {
    width: 100%;
    margin-top: 1rem;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

.details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1rem;
    margin: 1rem 0;
}

.details dt {
    color: var(--text-muted);
}

.details dd {
    margin: 0;
}

.correlation-id {
    color: var(--text-muted);
}

/* -------------------------------------------------------------- page bits */

/* A page made of several cards (spec 00014): stacked, with the add cards of the event's
   attendee view side by side on wider screens. */
.card-stack,
.card-grid {
    display: grid;
    gap: 1rem;
    align-items: start;
}

.card-stack > .card > h1:first-child,
.card-stack .card > h2:first-child,
.card-stack .card-head h2 {
    margin-top: 0;
}

@media (min-width: 40rem) {
    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 64rem) {
    .card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* A card in the grid is narrow: the search button goes under the field. */
.card-grid .search-form {
    flex-wrap: wrap;
}

.card-grid .search-form input {
    flex: 1 1 100%;
}

/* The event title with its pencil; the pencil turns it into .title-form (inline-edit.js). */
.title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.title-row h1 {
    margin: 0;
    overflow-wrap: anywhere;
}

.icon-button {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch);
    height: var(--touch);
    margin-top: -0.35rem;
    border-radius: var(--radius);
    color: var(--accent);
}

.icon-button:hover {
    background: var(--surface-alt);
    color: var(--accent-hover);
}

.icon-button::before {
    content: "";
    width: 1.2rem;
    height: 1.2rem;
    background-color: currentColor;
    -webkit-mask: var(--icon) center / contain no-repeat;
    mask: var(--icon) center / contain no-repeat;
}

.icon-edit::before {
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M13.6 2.6a2 2 0 0 1 2.8 0l1 1a2 2 0 0 1 0 2.8L7.2 16.6 2.5 17.5l.9-4.7z' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3Cpath d='M11.8 4.4l3.8 3.8' stroke='black' stroke-width='1.8'/%3E%3C/svg%3E");
}

.title-form input[type="text"] {
    font-size: 1.25rem;
    font-weight: 600;
}

.title-form .button-row {
    margin-top: 0.5rem;
}

.tab-count {
    color: var(--text-muted);
    font-weight: 400;
}

/* Training lists (spec 00014): a table on wide screens; on phones one card per training
   with its name and date, the rest folded in a native <details>. */
.training-cards {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
}

.training-cards li {
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.training-card-main {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem 0;
}

.training-card-main a {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.training-card-date {
    color: var(--text-muted);
    white-space: nowrap;
}

.training-cards summary {
    display: flex;
    align-items: center;
    min-height: var(--touch);
    padding: 0 0.75rem;
    color: var(--accent);
    font-size: 0.9rem;
    cursor: pointer;
}

.training-cards dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.75rem;
    margin: 0;
    padding: 0 0.75rem 0.75rem;
}

.training-cards dt {
    color: var(--text-muted);
}

.training-cards dd {
    margin: 0;
}

@media (max-width: 39.99rem) {
    .training-table {
        display: none;
    }

    .training-cards {
        display: block;
    }
}

.tabs {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
}

.tabs a {
    padding: 0.6rem 0.1rem;
    white-space: nowrap;
    color: var(--text-muted);
    text-decoration: none;
}

.tabs a.tab-active {
    color: var(--text);
    border-bottom: 2px solid var(--accent);
    font-weight: 600;
}

.inline-form {
    display: inline;
}

td.actions {
    white-space: nowrap;
    text-align: right;
}

td.actions a + a,
td.actions a + form,
td.actions form + a {
    margin-left: 0.75rem;
}

.signature-current {
    display: inline-block;
    margin: 0.5rem 0;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
}

.signature-current img {
    display: block;
    max-width: 100%;
    max-height: 8rem;
}

.signature-pad canvas {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 1;
    margin-top: 0.5rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: #ffffff;
    touch-action: none;
    cursor: crosshair;
}

.search-results {
    margin: 0.75rem 0;
    padding-left: 0;
    list-style: none;
}

.search-results li {
    padding: 0.25rem 0;
}

.search-results .inline-form {
    margin-right: 0.5rem;
}

details.inline-create,
details.revoke {
    margin: 0.75rem 0;
}

details summary {
    cursor: pointer;
    color: var(--accent);
}

details.revoke form {
    text-align: left;
}

.issuing-progress progress {
    width: 100%;
    height: 1rem;
}

tr.revoked td {
    color: var(--text-muted);
}

.event-fields .inline-row input[type="date"] {
    width: auto;
}

/* A field whose value differs from the content variant's (spec 00011). */
.field-note {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.variant-switch {
    margin-bottom: 1rem;
}

.variant-switch .inline-row select {
    flex: 1 1 12rem;
}

.change-list {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.button-danger {
    color: var(--error);
    border-color: var(--error);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.search-form input {
    margin-top: 0;
}

.search-form button {
    margin-top: 0;
    white-space: nowrap;
}

.pager {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
}

.inline-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-end;
}

.inline-row label {
    margin-top: 0;
}

.inline-row select {
    width: auto;
}

.inline-row button {
    margin-top: 0;
}

.steps {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.5rem;
    margin: 0.5rem 0 1rem;
    padding: 0;
    list-style: none;
    counter-reset: step;
    color: var(--text-muted);
}

.steps li::before {
    counter-increment: step;
    content: counter(step) ". ";
}

.steps .step-active {
    color: var(--text);
    font-weight: 600;
}

fieldset.choice {
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field-error {
    color: var(--error);
}

.issue-warning {
    color: var(--warning);
}

.import-preview select {
    margin-top: 0.25rem;
    font-size: 0.85rem;
}

.import-preview tr.row-invalid td {
    background: var(--surface-alt);
}

/* ---------------------------------------------------------- responsive bits */

/* Wide data tables that are not phone tasks scroll inside their own box (spec 00009, Q3). */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-scroll > .data-table {
    min-width: 40rem;
}

/*
 * Everyday lists become stacked cards on phones: the header row is hidden and every cell
 * shows its column name from data-label. The first cell (.cell-title) is the card title;
 * a cell without data-label (actions) spans the card.
 */
@media (max-width: 39.99rem) {
    .data-table-stack,
    .data-table-stack tbody,
    .data-table-stack tr,
    .data-table-stack td {
        display: block;
        width: 100%;
    }

    .data-table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .data-table-stack tr {
        margin-top: 0.75rem;
        padding: 0.5rem 0.75rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    .data-table-stack td {
        display: grid;
        grid-template-columns: minmax(6rem, 38%) 1fr;
        gap: 0.75rem;
        padding: 0.2rem 0;
        border-bottom: none;
        overflow-wrap: anywhere;
    }

    .data-table-stack td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.85rem;
    }

    .data-table-stack td:not([data-label]),
    .data-table-stack td.cell-title {
        display: block;
    }

    .data-table-stack td:not([data-label])::before,
    .data-table-stack td.cell-title::before {
        content: none;
    }

    .data-table-stack td.cell-title {
        padding-bottom: 0.35rem;
        font-weight: 600;
        font-size: 1.05rem;
    }

    .data-table-stack td.actions {
        text-align: left;
        white-space: normal;
    }

    .data-table-stack td:empty {
        display: none;
    }

    .details {
        grid-template-columns: 1fr;
        gap: 0 1rem;
    }

    .details dd {
        margin-bottom: 0.5rem;
    }

    .search-form {
        flex-wrap: wrap;
    }

    .search-form input {
        flex: 1 1 12rem;
    }
}

/* Touch screens: every control at least 44 px tall (spec 00009 acceptance). */
@media (pointer: coarse) {
    .button-primary,
    .button-secondary,
    input[type="text"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="search"],
    select {
        min-height: var(--touch);
    }

    td.actions a,
    td.actions .link-button,
    .search-results .link-button,
    .pager a,
    .culture-form .link-button,
    details summary {
        display: inline-block;
        min-height: var(--touch);
        padding: 0.6rem 0.25rem;
    }

    label.checkbox {
        min-height: var(--touch);
    }
}

/* ------------------------------------------------------- partial updates */

/* Spec 00017: a part of the page being saved is dimmed, inert and labelled. */
.is-saving {
    position: relative;
    cursor: progress;
}

.is-saving > * {
    opacity: 0.45;
    transition: opacity 0.15s;
}

.is-saving::after {
    content: attr(data-saving-label);
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    z-index: 2;
    padding: 0.1rem 0.6rem;
    border: 1px solid var(--accent);
    border-radius: 1rem;
    background: var(--surface);
    color: var(--accent);
    font-size: 0.8rem;
}

dialog.modal {
    width: min(32rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

dialog.modal::backdrop {
    background: rgb(0 0 0 / 0.35);
}

dialog.modal h2 {
    margin: 0 0 0.25rem;
    font-size: 1.15rem;
}

dialog.modal .button-row {
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ------------------------------------------------------------ page parts */

.page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.page-head h1,
.page-head h2 {
    margin: 0;
}

.page-head h1 {
    font-size: 1.3rem;
}

.stack {
    display: grid;
    gap: 0.75rem;
    align-content: start;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: end;
    margin-bottom: 0.75rem;
}

.filters > div {
    display: flex;
    flex-direction: column;
}

.filters label {
    margin: 0 0 0.15rem;
    font-size: 0.8rem;
}

.filters input,
.filters select {
    min-width: 9rem;
}

.filters .grow {
    flex: 1 1 16rem;
}

.filters .filters-check {
    margin: 0 0 0.6rem;
}

.field-row {
    display: grid;
    gap: 0 0.75rem;
}

@media (min-width: 40rem) {
    .field-row {
        grid-template-columns: 1fr 1fr;
    }
}

details.more > summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
}

.small-link {
    margin-left: 0.4rem;
    font-size: 0.8rem;
}

.count-pill {
    display: inline-block;
    padding: 0 0.5rem;
    border-radius: 1rem;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 0.8rem;
    vertical-align: middle;
}

.sf-badge {
    display: inline-block;
    padding: 0 0.3rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    font-size: 0.7rem;
    vertical-align: middle;
}

.row-selected td {
    background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}

.subcard {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.subcard h3 {
    margin: 0 0 0.25rem;
    font-size: 1rem;
}

.picture-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.picture-current {
    width: 9rem;
}

/* ------------------------------------------------------------------ wizard */

/* Spec 00021: the step bar is the wizard's only navigation. */
.wiz-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.75rem;
}

.wiz-bar nav {
    flex: 1;
    min-width: 0;
}

.wiz-new {
    white-space: nowrap;
    font-size: 0.9rem;
}

.stepper {
    display: flex;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    list-style: none;
}

.stepper li {
    flex: 1 1 0;
    min-width: 7rem;
}

.stepper a,
.stepper .step-off {
    display: flex;
    gap: 0.45rem;
    align-items: flex-start;
    min-width: 0;
    padding: 0.35rem 0.25rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
}

.stepper .num {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 0.8rem;
}

.stepper .lbl {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 0.9rem;
    line-height: 1.2;
}

.stepper .lbl small {
    overflow: hidden;
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stepper .done .num {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}

.stepper .done a {
    border-bottom-color: var(--accent);
}

.stepper .avail a {
    color: var(--text);
}

.stepper .avail .num {
    border-color: var(--accent);
    color: var(--accent);
}

.stepper .current a {
    border-bottom: 3px solid var(--accent);
    color: var(--text);
}

.stepper .current .lbl-main {
    font-weight: 600;
}

.stepper .current .num {
    border: 2px solid var(--accent);
    color: var(--accent);
}

.stepper .todo .step-off {
    opacity: 0.6;
}

@media (max-width: 39.99rem) {
    .wiz-bar {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .wiz-new {
        margin-left: auto;
    }

    .wiz-bar nav {
        flex: 1 1 100%;
    }

    .stepper li {
        flex: 0 0 auto;
        min-width: 2.5rem;
    }

    .stepper li:not(.current) .lbl {
        display: none;
    }

    .stepper li.current {
        flex: 1 1 auto;
    }
}

/* Selectable tiles: templates, instruments. */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.6rem;
}

.tile-grid-small {
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
}

.tile-form {
    display: contents;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 100%;
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

a.tile:hover,
button.tile:hover:not(:disabled) {
    border-color: var(--accent);
}

.tile.selected {
    padding: calc(0.55rem - 1px);
    border: 2px solid var(--accent);
    background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}

.tile:disabled {
    cursor: default;
}

.tile .thumb {
    display: grid;
    place-items: center;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    border-radius: 4px;
    background: var(--surface-alt);
}

.tile-grid-small .tile .thumb {
    aspect-ratio: 16 / 9;
}

.tile .thumb img,
.tile .thumb canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.tile .thumb-a4 {
    aspect-ratio: 297 / 210;
}

.tile .name {
    font-size: 0.9rem;
    font-weight: 600;
}

.tile .sub {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.tile-other input {
    width: 100%;
}

.tile-inactive {
    opacity: 0.6;
}

.pdf-preview canvas {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-alt);
}

.pdf-preview canvas:not(.pdf-ready) {
    aspect-ratio: 297 / 210;
}

.chosen-line {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.6rem;
    align-items: baseline;
    margin-bottom: 0.75rem;
}

.chosen-line a {
    font-size: 0.85rem;
}

.segmented {
    display: inline-flex;
    margin-bottom: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
}

.segmented a {
    padding: 0.5rem 1.2rem;
    color: var(--accent);
    text-decoration: none;
}

.segmented a.on {
    background: var(--accent);
    color: var(--accent-text);
}

.subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.9rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.subtabs a {
    display: inline-grid;
    padding: 0.3rem 0;
    color: var(--text-muted);
    text-decoration: none;
}

.subtabs a::after {
    content: attr(data-label);
    height: 0;
    overflow: hidden;
    visibility: hidden;
    font-weight: 600;
}

.subtabs a.on {
    border-bottom: 2px solid var(--accent);
    color: var(--text);
    font-weight: 600;
}

/* Step 4 as in legacy: a click moves a person between the lists. */
.move-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.move-list li {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.move-form {
    flex: 1;
    min-width: 0;
}

.move-row {
    display: grid;
    grid-template-columns: 2rem 1fr auto;
    gap: 0.5rem;
    align-items: center;
    width: 100%;
    min-height: var(--touch);
    padding: 0.35rem 0.25rem;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

button.move-row:hover {
    background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}

.move-locked {
    cursor: default;
}

.move-row .mv {
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
}

.move-gender {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.move-list .edit {
    padding: 0.4rem 0.6rem;
    text-decoration: none;
}

.summary-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    margin: 0;
}

.summary-list dt {
    color: var(--text-muted);
}

.summary-list dd {
    margin: 0;
}

.pick-list {
    margin: 0 0 0.75rem;
    padding: 0;
    list-style: none;
}

.pick-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0.25rem;
    border-bottom: 1px solid var(--border);
}

.pick-list li.on {
    background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
    font-weight: 600;
}

/* The first heading of a card sits at the card's padding, not a heading's margin below it. */
.card > h2:first-child,
.card > h3:first-child,
.card > .page-head:first-child h2,
.card > details:first-child > summary {
    margin-top: 0;
}

.card h2 {
    margin-bottom: 0.6rem;
    font-size: 1.1rem;
}

/* A form-wrapped link in a table (Historia, Certyfikaty) reads like a link. */
.data-table .link-button {
    text-align: left;
}

.filters .filters-check {
    display: flex;
    flex-direction: row;
    gap: 0.4rem;
    align-items: center;
}
