/*
 * forms.css: form controls, fields, checkboxes, switches, form layout, and the Tom Select (autocomplete) theme.
 *
 * Part of the new stylesheet stack (redesign Step 3). Loaded by
 * templates/base.html.twig in this order, one <link> each: tokens.css,
 * base.css, layout.css, components.css, forms.css, admin.css, parent.css.
 * Never use @import here: every file is linked on its own so that
 * FileModifiedVersionStrategy versions each one by its modification time.
 *
 * Ported from the portal's original stylesheet, in its source order. Two kinds of markup reach this file:
 *  - Symfony forms, rendered through templates/form/theme.html.twig, which adds
 *    field, field__label, input, field__help and field__error. `.input` is
 *    also copied by Tom Select onto its wrapper, so it never carries a text
 *    box's look by itself: the text-box look is on the control elements
 *    (input.input, select.input, textarea.input) and on the old container
 *    selectors (.form-card input[type="text"] ...), which keep matching.
 *  - Hand-written markup (login, parent sign-up, config pages), which names
 *    its container (.form-card, .form-row, .login-form, .section form).
 */

/* ------------------------------------------------------------------ the card */

/* A form's measure is 680px; the card is the same flat surface as .card. */
.form-card {
    max-width: 680px;
    margin-top: var(--space-4);
    margin-bottom: var(--space-4);
    padding: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--card);
}

.form-card--wide { max-width: 760px; }

/* In a container that spaces its children with a gap, the card adds no margin. */
.stack > .form-card,
.detail-grid > .form-card,
.card-grid > .form-card { margin-top: 0; }

/* A card holding a table takes the page's width. 680px is a form's measure; a
   five- or six-column table squeezed into it either spills through the card's
   edge or scrolls its action buttons out of sight. */
.form-card:has(> .table-wrap) { max-width: none; }

.form-grid {
    display: grid;
    gap: 0 var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* form_row() emits a bare <div> (now with .field), so a hand-written row or a
   nested wrapper inside a card is spaced here. :where() keeps this at the
   lowest specificity, so .field, .field__help and the like can set their own. */
.form-card :where(div:not(.form-grid):not(.form-actions)),
.form-row {
    margin-bottom: var(--space-4);
}

/* ------------------------------------------------------------ fields, labels */

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0 0 var(--space-4);
}

/* Wrappers a field holds (the help div, an expanded choice) are spaced by the
   field's own gap, not by the card's blanket row margin. */
.field > div:not(.field) { margin-bottom: 0; }

/* Every label inside a form container; :where() so .field__label,
   .checkbox-row and the toggle chips can set their own look. */
:where(.form-card, .form-row, .login-form, .section form) label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--text-label);
    line-height: var(--leading-label);
    font-weight: var(--weight-semibold);
}

.field__label {
    margin: 0;
    font-size: var(--text-label);
    line-height: var(--leading-label);
    font-weight: var(--weight-semibold);
    color: var(--ink);
}

.field__optional { font-weight: var(--weight-regular); color: var(--muted); }

/* A group of checkboxes or radios (the rooms a person covers) is a real
   <fieldset> with a <legend> as its label, laid out like any other field.
   templates/admin/_form_fields.html.twig renders it; the options sit side by
   side in a .check-group and wrap. */
fieldset.field {
    min-width: 0;
    padding: 0;
    border: 0;
}

fieldset.field > legend.field__label {
    float: none;
    width: auto;
    margin: 0 0 var(--space-1);
    padding: 0;
}

/* The options of an expanded choice are <input><label> pairs: they flow
   inline and wrap, rather than being flex items (a flex gap would also open
   up between each box and its own label). */
fieldset.field > .check-group { display: block; }

/* A checkbox or radio is a flex item that would otherwise stretch. */
.field > input[type="checkbox"],
.field > input[type="radio"] { align-self: flex-start; }

/* An expanded choice renders <input><label> pairs: the label sits beside its box. */
.field input[type="checkbox"] + label,
.field input[type="radio"] + label,
.form-card input[type="checkbox"] + label,
.form-card input[type="radio"] + label {
    display: inline;
    margin: 0 var(--space-4) 0 0;
    font-size: var(--text-table);
    line-height: var(--leading-table);
    font-weight: var(--weight-regular);
}

/* Help text: under the control, muted. [id$="_help"] is Symfony's own id. */
.field__help,
.help-text,
.form-help,
.form-card [id$="_help"],
.login-form [id$="_help"],
.section form [id$="_help"] {
    display: block;
    margin: var(--space-1) 0 0;
    font-size: var(--text-small);
    line-height: var(--leading-small);
    font-weight: var(--weight-regular);
    color: var(--muted);
}

.field > .field__help { margin-top: 0; }

/* Errors: Symfony renders them as a <ul class="field__error">; keep them close
   to the field. The old container selectors stay for hand-written error lists,
   but only for a bare <ul>: a classed list (availability-list, task-list) is
   not an error and used to turn red and bold. */
.field__error,
.form-card ul:not([class]),
.login-form ul:not([class]),
.section form ul:not([class]) {
    list-style: none;
    margin: var(--space-1) 0;
    padding: 0;
    font-size: var(--text-small);
    line-height: var(--leading-small);
    font-weight: var(--weight-semibold);
    color: var(--danger);
}

.field > .field__error { margin: 0; }

/* A line a script fills in (a failed check, a card error); empty it is gone. */
.form-error {
    margin: var(--space-2) 0 0;
    font-size: var(--text-small);
    line-height: var(--leading-small);
    font-weight: var(--weight-semibold);
    color: var(--danger);
}

.form-error:empty { display: none; }

/* A to-do list in a card, such as the digital app queue. `.form-card ul` is
   styled as a form's error list (red, bold), which made every waiting child
   look like an error. */
.form-card .task-list {
    margin: var(--space-2) 0 0;
    padding: 0;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
    font-weight: inherit;
}

.form-card .task-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    padding: var(--space-2) 0;
}

.form-card .task-list li + li { border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ controls
   The text-box look: card fill, a 1px control border (3:1 against the card),
   radius-md, table-size text. Focus keeps base.css's ring; invalid is a danger
   border. */

input.input,
select.input,
textarea.input,
.form-card input[type="text"],
.form-card input[type="email"],
.form-card input[type="tel"],
.form-card input[type="password"],
.form-card input[type="date"],
.form-card input[type="number"],
.form-card input[type="url"],
.form-card input[type="time"],
.form-card select,
.form-card textarea,
.login-form input[type="text"],
.login-form input[type="email"],
.login-form input[type="tel"],
.login-form input[type="password"],
.login-form input[type="number"],
.login-form select,
.login-form textarea,
.section form input[type="text"],
.section form input[type="email"],
.section form input[type="tel"],
.section form input[type="password"],
.section form input[type="date"],
.section form input[type="number"],
.section form input[type="url"],
.section form input[type="time"],
.section form select,
.section form textarea,
.data-table select,
.data-table input[type="text"],
.form-row input:not([type="checkbox"]):not([type="radio"]) {
    width: 100%;
    min-height: 40px;
    padding: 0 var(--space-3);
    border: 1px solid var(--line-control);
    border-radius: var(--radius-md);
    background: var(--card);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--text-table);
    line-height: var(--leading-button);
}

textarea.input,
.form-card textarea,
.login-form textarea,
.section form textarea {
    min-height: 96px;
    padding: var(--space-2) var(--space-3);
    line-height: var(--leading-table);
    resize: vertical;
}

input.input::placeholder,
select.input::placeholder,
textarea.input::placeholder,
.form-card input[type="text"]::placeholder,
.form-card input[type="email"]::placeholder,
.form-card input[type="tel"]::placeholder,
.form-card input[type="password"]::placeholder,
.form-card input[type="date"]::placeholder,
.form-card input[type="number"]::placeholder,
.form-card input[type="url"]::placeholder,
.form-card input[type="time"]::placeholder,
.form-card select::placeholder,
.form-card textarea::placeholder,
.login-form input[type="text"]::placeholder,
.login-form input[type="email"]::placeholder,
.login-form input[type="tel"]::placeholder,
.login-form input[type="password"]::placeholder,
.login-form input[type="number"]::placeholder,
.login-form select::placeholder,
.login-form textarea::placeholder,
.section form input[type="text"]::placeholder,
.section form input[type="email"]::placeholder,
.section form input[type="tel"]::placeholder,
.section form input[type="password"]::placeholder,
.section form input[type="date"]::placeholder,
.section form input[type="number"]::placeholder,
.section form input[type="url"]::placeholder,
.section form input[type="time"]::placeholder,
.section form select::placeholder,
.section form textarea::placeholder,
.data-table select::placeholder,
.data-table input[type="text"]::placeholder,
.form-row input:not([type="checkbox"]):not([type="radio"])::placeholder { color: var(--muted); }

input.input:hover,
select.input:hover,
textarea.input:hover,
.form-card input[type="text"]:hover,
.form-card input[type="email"]:hover,
.form-card input[type="tel"]:hover,
.form-card input[type="password"]:hover,
.form-card input[type="date"]:hover,
.form-card input[type="number"]:hover,
.form-card input[type="url"]:hover,
.form-card input[type="time"]:hover,
.form-card select:hover,
.form-card textarea:hover,
.login-form input[type="text"]:hover,
.login-form input[type="email"]:hover,
.login-form input[type="tel"]:hover,
.login-form input[type="password"]:hover,
.login-form input[type="number"]:hover,
.login-form select:hover,
.login-form textarea:hover,
.section form input[type="text"]:hover,
.section form input[type="email"]:hover,
.section form input[type="tel"]:hover,
.section form input[type="password"]:hover,
.section form input[type="date"]:hover,
.section form input[type="number"]:hover,
.section form input[type="url"]:hover,
.section form input[type="time"]:hover,
.section form select:hover,
.section form textarea:hover,
.data-table select:hover,
.data-table input[type="text"]:hover,
.form-row input:not([type="checkbox"]):not([type="radio"]):hover { border-color: var(--plum); }

input.input:focus,
select.input:focus,
textarea.input:focus,
.form-card input[type="text"]:focus,
.form-card input[type="email"]:focus,
.form-card input[type="tel"]:focus,
.form-card input[type="password"]:focus,
.form-card input[type="date"]:focus,
.form-card input[type="number"]:focus,
.form-card input[type="url"]:focus,
.form-card input[type="time"]:focus,
.form-card select:focus,
.form-card textarea:focus,
.login-form input[type="text"]:focus,
.login-form input[type="email"]:focus,
.login-form input[type="tel"]:focus,
.login-form input[type="password"]:focus,
.login-form input[type="number"]:focus,
.login-form select:focus,
.login-form textarea:focus,
.section form input[type="text"]:focus,
.section form input[type="email"]:focus,
.section form input[type="tel"]:focus,
.section form input[type="password"]:focus,
.section form input[type="date"]:focus,
.section form input[type="number"]:focus,
.section form input[type="url"]:focus,
.section form input[type="time"]:focus,
.section form select:focus,
.section form textarea:focus,
.data-table select:focus,
.data-table input[type="text"]:focus,
.form-row input:not([type="checkbox"]):not([type="radio"]):focus { border-color: var(--plum); }

/* base.css gives every focus ring a small radius; a control keeps its own. */
input.input:focus-visible,
select.input:focus-visible,
textarea.input:focus-visible,
.form-card input[type="text"]:focus-visible,
.form-card input[type="email"]:focus-visible,
.form-card input[type="tel"]:focus-visible,
.form-card input[type="password"]:focus-visible,
.form-card input[type="date"]:focus-visible,
.form-card input[type="number"]:focus-visible,
.form-card input[type="url"]:focus-visible,
.form-card input[type="time"]:focus-visible,
.form-card select:focus-visible,
.form-card textarea:focus-visible,
.login-form input[type="text"]:focus-visible,
.login-form input[type="email"]:focus-visible,
.login-form input[type="tel"]:focus-visible,
.login-form input[type="password"]:focus-visible,
.login-form input[type="number"]:focus-visible,
.login-form select:focus-visible,
.login-form textarea:focus-visible,
.section form input[type="text"]:focus-visible,
.section form input[type="email"]:focus-visible,
.section form input[type="tel"]:focus-visible,
.section form input[type="password"]:focus-visible,
.section form input[type="date"]:focus-visible,
.section form input[type="number"]:focus-visible,
.section form input[type="url"]:focus-visible,
.section form input[type="time"]:focus-visible,
.section form select:focus-visible,
.section form textarea:focus-visible,
.data-table select:focus-visible,
.data-table input[type="text"]:focus-visible,
.form-row input:not([type="checkbox"]):not([type="radio"]):focus-visible {
    outline-offset: 1px;
    border-radius: var(--radius-md);
}

input.input[aria-invalid="true"],
select.input[aria-invalid="true"],
textarea.input[aria-invalid="true"],
.form-card input[type="text"][aria-invalid="true"],
.form-card input[type="email"][aria-invalid="true"],
.form-card input[type="tel"][aria-invalid="true"],
.form-card input[type="password"][aria-invalid="true"],
.form-card input[type="date"][aria-invalid="true"],
.form-card input[type="number"][aria-invalid="true"],
.form-card input[type="url"][aria-invalid="true"],
.form-card input[type="time"][aria-invalid="true"],
.form-card select[aria-invalid="true"],
.form-card textarea[aria-invalid="true"],
.login-form input[type="text"][aria-invalid="true"],
.login-form input[type="email"][aria-invalid="true"],
.login-form input[type="tel"][aria-invalid="true"],
.login-form input[type="password"][aria-invalid="true"],
.login-form input[type="number"][aria-invalid="true"],
.login-form select[aria-invalid="true"],
.login-form textarea[aria-invalid="true"],
.section form input[type="text"][aria-invalid="true"],
.section form input[type="email"][aria-invalid="true"],
.section form input[type="tel"][aria-invalid="true"],
.section form input[type="password"][aria-invalid="true"],
.section form input[type="date"][aria-invalid="true"],
.section form input[type="number"][aria-invalid="true"],
.section form input[type="url"][aria-invalid="true"],
.section form input[type="time"][aria-invalid="true"],
.section form select[aria-invalid="true"],
.section form textarea[aria-invalid="true"],
.data-table select[aria-invalid="true"],
.data-table input[type="text"][aria-invalid="true"],
.form-row input:not([type="checkbox"]):not([type="radio"])[aria-invalid="true"] { border-color: var(--danger); }

/* A field that Symfony rendered with errors marks its own control. */
.field:has(> .field__error) > input.input,
.field:has(> .field__error) > select.input,
.field:has(> .field__error) > textarea.input { border-color: var(--danger); }

input.input:disabled,
select.input:disabled,
textarea.input:disabled,
.form-card input[type="text"]:disabled,
.form-card input[type="email"]:disabled,
.form-card input[type="tel"]:disabled,
.form-card input[type="password"]:disabled,
.form-card input[type="date"]:disabled,
.form-card input[type="number"]:disabled,
.form-card input[type="url"]:disabled,
.form-card input[type="time"]:disabled,
.form-card select:disabled,
.form-card textarea:disabled,
.login-form input[type="text"]:disabled,
.login-form input[type="email"]:disabled,
.login-form input[type="tel"]:disabled,
.login-form input[type="password"]:disabled,
.login-form input[type="number"]:disabled,
.login-form select:disabled,
.login-form textarea:disabled,
.section form input[type="text"]:disabled,
.section form input[type="email"]:disabled,
.section form input[type="tel"]:disabled,
.section form input[type="password"]:disabled,
.section form input[type="date"]:disabled,
.section form input[type="number"]:disabled,
.section form input[type="url"]:disabled,
.section form input[type="time"]:disabled,
.section form select:disabled,
.section form textarea:disabled,
.data-table select:disabled,
.data-table input[type="text"]:disabled,
.form-row input:not([type="checkbox"]):not([type="radio"]):disabled {
    background: var(--sunken);
    color: var(--muted);
    cursor: not-allowed;
}

/* Controls sitting inside a data table (a room picker on a queue row): full
   width is right in a form column and wrong in a table cell, where it would
   stretch the column to whatever the widest option is. */
table.data-table select,
table.data-table input[type="text"],
table.data-table select.input,
table.data-table input.input {
    width: auto;
    max-width: 14rem;
    min-height: 32px;
    padding: 0 var(--space-2);
    font-size: var(--text-label);
    line-height: var(--leading-label);
}

/* A short numeric control beside a button (an allowance of children): a form
   column's full width would crowd the button off the row. */
input.input.input--narrow { width: 5rem; }

/* Phones: a control under 16px makes iOS zoom into it on focus. */
@media (max-width: 640px) {
input.input,
select.input,
textarea.input,
.form-card input[type="text"],
.form-card input[type="email"],
.form-card input[type="tel"],
.form-card input[type="password"],
.form-card input[type="date"],
.form-card input[type="number"],
.form-card input[type="url"],
.form-card input[type="time"],
.form-card select,
.form-card textarea,
.login-form input[type="text"],
.login-form input[type="email"],
.login-form input[type="tel"],
.login-form input[type="password"],
.login-form input[type="number"],
.login-form select,
.login-form textarea,
.section form input[type="text"],
.section form input[type="email"],
.section form input[type="tel"],
.section form input[type="password"],
.section form input[type="date"],
.section form input[type="number"],
.section form input[type="url"],
.section form input[type="time"],
.section form select,
.section form textarea,
.data-table select,
.data-table input[type="text"],
.form-row input:not([type="checkbox"]):not([type="radio"]) { font-size: var(--text-body); }
}

/* --------------------------------------- checkboxes, radios, rows, switches */

.form-card input[type="checkbox"],
.form-card input[type="radio"] {
    width: 18px;
    height: 18px;
    margin: 0 var(--space-2) 0 0;
    accent-color: var(--plum);
    vertical-align: middle;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin: 0 0 var(--space-3);
    font-size: var(--text-table);
    line-height: var(--leading-table);
    font-weight: var(--weight-regular);
    cursor: pointer;
}

.checkbox-row input:is([type="checkbox"], [type="radio"]) {
    flex: none;
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--plum);
}

.check-group { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); }
.check-group .checkbox-row { margin: 0; }

.switch {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-table);
    line-height: var(--leading-button);
    font-weight: var(--weight-semibold);
    cursor: pointer;
}

.switch input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    flex: none;
    width: 40px;
    height: 24px;
    margin: 0;
    border-radius: var(--radius-pill);
    background: var(--line-control);
    cursor: pointer;
    transition: background 0.15s;
}

.switch input[type="checkbox"]::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--card);
    transition: transform 0.15s;
}

.switch input[type="checkbox"]:checked { background: var(--plum); }
.switch input[type="checkbox"]:checked::after { transform: translateX(16px); }
.switch input[type="checkbox"]:focus-visible { border-radius: var(--radius-pill); }

@media (prefers-reduced-motion: reduce) {
    .switch input[type="checkbox"],
    .switch input[type="checkbox"]::after { transition: none; }
}

/* The select-all and per-row checkboxes in a table: big enough to hit, aligned
   with the text beside them. */
.data-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--plum);
    vertical-align: middle;
}

/* --------------------------------------------------------- notes and fixtures */

/* The "your card never reaches us" note under the Stripe field. Says it where
   somebody is about to type a card number rather than leaving it to the
   privacy policy. The icon sits on the first line of the text. */
.card-assurance {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin-top: var(--space-3);
    font-size: var(--text-small);
    line-height: var(--leading-small);
}

.card-assurance .icon {
    flex: none;
    margin-top: 2px;
    color: var(--plum);
}

/* The Stripe card field's frame: a control, so it has a control border. */
.card-element {
    margin-bottom: var(--space-4);
    padding: var(--space-3);
    border: 1px solid var(--line-control);
    border-radius: var(--radius-md);
    background: var(--card);
}

/* A life insurance election: read in full before signing, and kept as signed. */
.election-document {
    max-width: 46rem;
    line-height: var(--leading-body-ratio);
    white-space: pre-wrap;
}

details > .election-document { margin-top: var(--space-3); }

/* Authenticator setup: a phone only scans a QR code that is dark on light, so
   it keeps a light backing in every theme. The tokens have no pure white, and
   --card is light enough to scan. */
.qr-code {
    display: inline-block;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: var(--card);
    line-height: 0;
}

.qr-code svg {
    width: 220px;
    max-width: 100%;
    height: auto;
}

/* ------------------------------------------------------------ form layouts */

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--line);
}

/* The bar that ends a form page: the one primary action, any secondary one,
   then Cancel as a quiet link. It sits below the sections, or below the one
   card of a short form (.form-card + .form-bar), never inside a card. */
.form-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-5);
    border-top: 1px solid var(--line);
}

.form-card + .form-bar { margin-top: var(--space-6); }

/* A block that follows the form on the same page (a room's "Remove this room",
   in a form of its own): room for the bar's rule before the next section's. */
form + .form-section { margin-top: var(--space-6); }

/* The same room where the next section is the first of the next tab panel (My profile: "Save changes" then
   "Authenticator app", "Change password" then "Payment method"). The tabs script shows one panel at a time,
   so this only applies where every panel is drawn (scripts off, or failed): the section is not a sibling of
   the form, and `.is-first` has taken its rule and its room away. */
.tabs__panel:not([hidden]) + .tabs__panel > .form-section.is-first {
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--line);
}

/* A line under the bar that says what a secondary action does (the email page's
   "Save and send me a test email"). */
.form-bar + .help-text { margin-top: var(--space-3); }

/* A "saved" note straight in a card, under the field it is about. components.css
   `.card > p` (0,1,1) is stronger than `.help-text` (0,1,0), so without this the
   note takes the table text size and the card's paragraph gap instead of the
   small size and the close spacing of the field help above it. */
.card > p.help-text {
    margin: calc(var(--space-3) * -1) 0 var(--space-4);
    font-size: var(--text-small);
    line-height: var(--leading-small);
}

.card > p.help-text:last-child { margin-bottom: 0; }

/* A second form on a page that opens with a section, right under the first
   form's bar (social login's Apple after Google): room for the bar's rule. */
.form-after-bar > .form-section { margin-top: var(--space-6); }

/* A small heading inside a section's card, for a card that holds more than
   fields (the values to give a provider, then the credentials it gives back). */
.form-section__heading {
    margin: var(--space-5) 0 var(--space-2);
    font-family: var(--font-body);
    font-size: var(--text-table);
    line-height: var(--leading-table);
    font-weight: var(--weight-bold);
}

.form-section__heading:first-child { margin-top: 0; }

/* A list of terms (.dl) with a paragraph after it in a card (the accounting
   page's webhook events, then "Leave the rest unticked"): room between them. */
.form-section .card > .dl + p { margin-top: var(--space-3); }

/* Two actions that are each a form of their own, one under the other (the
   accounting page's Reconnect and Disconnect, and its list of businesses to
   pick from): room between the rows. */
.form-card > .inline-form + .inline-form { margin-top: var(--space-4); }

/* A form page: a title and one line on the left, a card of fields on the right,
   capped at 720px (templates/admin/_form_section.html.twig).

   Beside a 232px sidebar the content column is far narrower than the window
   (718px at a 1024px window), so the sections stack by the width of the
   column they are in, not of the window: a page with sections makes its
   <main> a size container (the :has() rule below), and below 872px (the 280px
   title column, the 32px gap and a 560px card, the least that holds two
   fields side by side) the title and description sit above the card. At a
   1280px window the column is 976px and they sit beside it; at 1024px it is
   718px and they stack. */
.form-section {
    display: grid;
    grid-template-columns: 280px minmax(0, 720px);
    gap: var(--space-8);
    padding: var(--space-6) 0;
    border-top: 1px solid var(--line);
}

.form-section.is-first { border-top: none; padding-top: 0; }
.form-section.is-stacked { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }

.form-section__title {
    margin: 0 0 var(--space-1);
    font-family: var(--font-display);
    font-size: var(--text-display-card);
    line-height: var(--leading-display-card);
    font-weight: var(--weight-semibold);
}

.form-section__sub {
    margin: 0;
    font-size: var(--text-label);
    line-height: var(--leading-label);
    color: var(--muted);
}

/* The card is .card form-card, so the field, checkbox and hand-written
   control rules written for .form-card apply inside it; this puts back the
   .card look (no page measure, no margins of its own). */
.form-section > .form-card {
    max-width: none;
    margin: 0;
}

/* Rows of fields are spaced by the grid, in one column or two, so a stacked
   row never touches the next; the last thing in a card has no margin below. */
.form-section .form-grid {
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

/* Three short numbers in one row (the waitlist's distance groups): auto-fit's
   220px minimum would wrap the third onto a row of its own. */
.form-section .form-grid--bands { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.form-section .form-grid > .field { margin-bottom: 0; }

/* A grid cell that is a wrapper, not a field: a field with a line of its own
   under it (the child form's age under the date of birth). The wrapper and its
   field leave the spacing to the grid, and the line sits close under the box. */
.form-section .form-grid > div:not(.field) { margin-bottom: 0; }
.form-section .form-grid > div:not(.field) > .field { margin-bottom: 0; }
.form-section .form-grid > div:not(.field) > .help-text { margin: var(--space-1) 0 0; }
.form-section .card > :last-child { margin-bottom: 0; }

.app-shell > main:has(.form-section) { container: form-page / inline-size; }

@container form-page (max-width: 871px) {
    .form-section { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
}

/* -------------------------------------------------------- Tom Select theme
   Tom Select (Symfony UX Autocomplete) ships its own DOM and its own
   stylesheet, loaded after this one and unlayered, so a rule here needs the
   specificity to win outright, not just the order. These apply wherever an
   autocomplete renders (the guardians and families pickers), not only inside
   .form-card. */

.ts-wrapper { font-family: var(--font-body); font-size: var(--text-table); }

/* `.form-card div` gives every nested div a 16px bottom margin, so the control,
   the dropdown and each option were 16px taller than they look and the
   dropdown opened a hand's width below the box. Plain specificity here beats
   that :where() rule; the chips (div.item) set their own margin and win over
   this in turn. */
.ts-wrapper div { margin-bottom: 0; }

.ts-wrapper .ts-control {
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--line-control);
    border-radius: var(--radius-md);
    background: var(--card);
    box-shadow: none;
    color: var(--ink);
    font-size: var(--text-table);
    line-height: var(--leading-button);
}

.ts-wrapper.full .ts-control { background: var(--card); }

.ts-wrapper.multi.has-items .ts-control { padding: var(--space-1) var(--space-3) 0; }

/* Tom Select takes the inner input's outline away, so the wrapper carries the
   same ring base.css draws on every other focusable element. */
.ts-wrapper.focus .ts-control {
    border-color: var(--plum);
    outline: 2px solid var(--oak-deep);
    outline-offset: 1px;
    box-shadow: none;
}

.ts-wrapper .ts-control > input {
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--text-table);
}

.ts-wrapper .ts-control > input::placeholder { color: var(--muted); }

/* Selected-item chips in multi-select fields. Tom Select styles
   `.ts-wrapper.multi .ts-control > div` (0,3,1) and the same with .active
   (0,4,1); .item adds the specificity to beat both. */
.ts-wrapper.multi .ts-control > div.item {
    margin: 0 var(--space-1) var(--space-1) 0;
    padding: 0 var(--space-3);
    border: 1px solid var(--plum);
    border-radius: var(--radius-pill);
    background: var(--plum-tint);
    background-image: none;
    color: var(--plum-dark);
    font-size: var(--text-label);
    line-height: var(--leading-small);
    text-shadow: none;
    box-shadow: none;
}

.ts-wrapper.multi .ts-control > div.item.active {
    border-color: var(--plum-dark);
    background: var(--plum);
    background-image: none;
    color: var(--on-plum);
}

/* The chip's remove button draws its divider in Tom Select's blue. */
.ts-wrapper.multi.plugin-remove_button .ts-control .item .remove { border-left-color: var(--plum-soft); }
.ts-wrapper.multi.plugin-remove_button .ts-control .item.active .remove { border-left-color: var(--plum-soft); }

.ts-wrapper .ts-dropdown {
    margin-top: var(--space-1);
    border: 1px solid var(--line-control);
    border-radius: var(--radius-md);
    background: var(--card);
    box-shadow: var(--shadow-raised);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--text-table);
    line-height: var(--leading-table);
}

.ts-wrapper .ts-dropdown .option,
.ts-wrapper .ts-dropdown .optgroup-header,
.ts-wrapper .ts-dropdown .no-results,
.ts-wrapper .ts-dropdown .create {
    padding: var(--space-2) var(--space-3);
    color: var(--ink);
}

.ts-wrapper .ts-dropdown .optgroup-header { background: var(--sunken); color: var(--muted); }

.ts-wrapper .ts-dropdown [data-selectable] .highlight {
    background: var(--oak-tint);
    color: var(--ink);
    border-radius: 2px;
}

.ts-wrapper .ts-dropdown .active {
    background-color: var(--plum-tint);
    color: var(--plum-dark);
}

.ts-wrapper .ts-dropdown .create { color: var(--muted); }
.ts-wrapper .ts-dropdown .active.create { color: var(--plum-dark); }
