.form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 32rem;
}

/* In a row of fields, one shrinks to fit rather than widen the page to its
   select's longest option, someone's long name (docs/adr/0108). */
.form__field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.form__label {
    font-weight: 700;
}

/* A required field's asterisk (form_ui.requiredMark), after its label or legend. */
.form__required {
    margin-left: 0.2em;
    color: var(--error);
    font-weight: 700;
}

.form__input {
    padding: 0.5rem 0.75rem;
    border: 0.125rem solid var(--border);
    background-color: var(--white);
    color: var(--black);
}

.form__field:has(> ul) .form__input {
    border-color: var(--error);
}

/* Symfony's default error markup: <ul><li>message</li></ul>, directly inside
   a field or fieldset (e.g. Roles, Positions, the attendance sheet). */
.form__field > ul,
.form__fieldset > ul {
    list-style: none;
    padding: 0;
    margin: 0;
    color: var(--error);
    font-weight: 700;
}

/* Buttons that don't fit side by side go under each other, rather than
   squeeze their words (docs/adr/0108). */
.form__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem 1.5rem;
}

/*
 * Save and Cancel on a long form, on a phone (docs/adr/0098): once
 * anything's changed (form--changed, the unsaved-changes controller), a
 * bar stuck to the bottom of the screen, on the bottom bar, until the
 * form's end scrolls up to meet it. It has the bar's room before then
 * too, so nothing moves when it starts sticking.
 */
@media (max-width: 47.99rem) {
    .form__actions--sticky {
        /* Across the screen, over the container's gutter. */
        margin-inline: -1rem;
        padding: 0.75rem 1rem;
        border-top: 0.125rem solid transparent;
    }

    .form--changed .form__actions--sticky {
        position: sticky;
        bottom: calc(4rem + env(safe-area-inset-bottom));
        z-index: 1;
        border-top-color: var(--black);
        background-color: var(--white);
    }

    /* Whatever's focused scrolls into view above the two bars (4rem, and this one's 4.4rem), not under them (WCAG 2.4.11). */
    html:has(.form--changed .form__actions--sticky) {
        scroll-padding-bottom: calc(9rem + env(safe-area-inset-bottom));
    }
}

.button {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: 0.125rem solid var(--black);
    background-color: var(--tertiary);
    color: var(--black);
    font-weight: 700;
    text-decoration: none;
    box-shadow: var(--box-shadow);
    cursor: pointer;
}

.button:hover,
.button:focus-visible {
    background-color: var(--white);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form__field--narrow .form__input {
    max-width: 6rem;
}

.form__fieldset {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0;
    border: 0;
}

/* A legend sits outside the fieldset's gap: as far from its choices as a label is from its input. */
.form__fieldset > legend {
    margin-bottom: 0.5rem;
}

.form__label--sub {
    font-weight: 400;
}

/* Bulk buttons for a group of choices, e.g. "Mark all attending" (set-all controller). */
.form__bulk {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.form__bulk[hidden] {
    display: none;
}

.form__bulk-button {
    padding: 0.2rem 0.75rem;
    border: 0.125rem solid var(--black);
    background-color: var(--white);
    color: var(--black);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
}

.form__bulk-button:hover,
.form__bulk-button:focus-visible {
    background-color: var(--tertiary);
}

.form__choices {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
}

/* One under another, where the words are long enough to wrap two and one (docs/adr/0120). */
.form__choices--stacked {
    flex-direction: column;
}

.form__choice {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

.form__choice input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--tertiary);
}

/* A row per position, banded white and grey like a table's, with boxes
   twice the size of other choices' (docs/adr/0096). */
.form__choices--positions {
    flex-direction: column;
    gap: 0;
}

.form__choices--positions .form__choice {
    padding: 0.25rem 0.5rem;
}

.form__choices--positions .form__choice:nth-child(even) {
    background-color: var(--row-stripe);
}

.form__choices--positions .form__choice input {
    width: 2.2rem;
    height: 2.2rem;
}

/* The code, then the name in words: "LB  Left Back" (docs/adr/0117). */
.position-choice__code {
    display: inline-block;
    min-width: 2.75rem;
    font-weight: 700;
}

/* Symfony's form_help() */
.form .help-text,
.form [id$="_help"] {
    font-size: 0.875rem;
    opacity: 0.85;
}

/* A choice's help, close under its words rather than spaced like the next choice. */
.form__choice + .help-text {
    margin-top: -0.375rem;
    padding-left: 1.5rem;
}

/* What can't be undone (docs/adr/0111): red, so it isn't taken for a secondary button. */
.button--danger {
    border-color: var(--error);
    background-color: var(--white);
    color: var(--error);
}

.button--danger:hover,
.button--danger:focus-visible {
    background-color: var(--error);
    color: var(--white);
}

.danger-zone {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 0.125rem solid var(--border);
    max-width: 32rem;
}

.danger-zone > p,
.danger-zone > ul {
    margin: 0.5rem 0 1rem;
}

.danger-zone > ul {
    padding-left: 1.25rem;
}

/* A second action beside the main one, e.g. "Add several" (docs/adr/0045). */
.button--secondary {
    background-color: var(--white);
}

.button--secondary:hover,
.button--secondary:focus-visible {
    background-color: var(--tertiary);
}

/* A time of day, e.g. when to meet (docs/adr/0046). */
.form__field--time .form__input {
    max-width: 9rem;
}

.form__field--date .form__input {
    max-width: 12rem;
}
