/* =========================================================================
   Component — forms
   Every input has a <label>; errors are associated with aria-describedby.
   ========================================================================= */

.field {
  margin-bottom: 16px;
}

/* The SIDES field (ADR-0167): a caption label 4px above a 42px control. */
.field > label {
  display: block;
  font-size: var(--text-caption);
  line-height: var(--text-caption-lh);
  font-weight: 400;
  margin-bottom: var(--space-xs);
  color: var(--doc-ink);
}

/* A checkbox or radio is not a text field and keeps the choice size below
   (U-1693). `:where` holds this selector at (0,1,1), so the readonly, focus and
   invalid rules after it still win; a `:not` would have outranked them. */
.field input:where(:not([type="checkbox"], [type="radio"])),
.field select,
.field textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 10px var(--space-sm);
  border: var(--border-w) solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--sd-surface);
  color: var(--sd-text);
  font: inherit;
  font-size: var(--text-body);
  line-height: var(--text-body-lh);
}

.field input:where(:not([type="checkbox"], [type="radio"], [readonly], :disabled)):hover,
.field select:where(:not(:disabled)):hover,
.field textarea:where(:not([readonly], :disabled)):hover {
  border-color: var(--sd-border-strong);
}

/* A text field starts with room to write in, grows with its text and then
   scrolls (U-2016): five lines at first, sixteen at most, `field-sizing` doing
   the growing where the browser has it and the five lines standing where it
   does not. Height only, never width: a dragged width breaks the form's column.
   20px is the padding and the border around the lines. A field whose text is
   one short line by nature says so with `textarea-short`. */
.field textarea {
  /* The line before stands for a browser without `lh`, which drops the next. */
  min-height: calc(var(--control-h) * 2.5);
  min-height: calc(5lh + 20px);
  max-height: calc(16lh + 20px);
  field-sizing: content;
  overflow-y: auto;
  resize: vertical;
}

.field textarea.textarea-short {
  min-height: calc(2lh + 20px);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--sd-muted);
}

/* A field the role may read but not change (`readonly`, set from the WRITE scope
   — profile, app editor). It must not look like one that takes input: on the
   white of an editable field it promised a permission the page does not grant
   (U-1086). The sunk surface is the one `.form-message` already uses for
   "this is information, not a control". */
.field input[readonly],
.field textarea[readonly] {
  background: var(--sd-sunk);
  border-style: dashed;
  cursor: default;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  border-color: var(--sd-secondary);
  outline: 3px solid color-mix(in srgb, var(--sd-secondary) 45%, transparent);
  outline-offset: 0;
}

.field-hint {
  margin: var(--space-xs) 0 0;
  font-size: var(--text-caption);
  line-height: var(--text-caption-lh);
  color: var(--doc-ink-soft);
}

/* The „i“ beside a label and the box it opens (`fieldInfo` in forms.js, U-1856).
   The label shares its line with the button only when one follows it. The box is
   anchored to the FIELD, not to the button, so it spans the field's width and
   stays inside the screen's width at 320 px. `top` assumes a one-line label; a
   label that wraps puts the button below the box's top edge. It opens on hover
   and while the button has focus: Tab reaches it, and a touch screen emulates
   the hover on a tap (Safari does not focus a tapped button). */
.field:has(> .field-info) {
  position: relative;
}

.field > label:has(+ .field-info) {
  display: inline-block;
}

.field-info-button {
  width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0;
  border: 1px solid var(--sd-border);
  border-radius: var(--radius-pill);
  background: var(--sd-surface);
  color: var(--doc-ink-soft);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  cursor: help;
}

.field-info-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--sd-secondary) 45%, transparent);
  outline-offset: 0;
}

.field-info-box {
  display: none;
  position: absolute;
  z-index: 10;
  top: 26px;
  left: 0;
  right: 0;
  padding: 10px 12px;
  border: 1px solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--doc-panel);
  box-shadow: var(--shadow-pop);
  color: var(--doc-ink);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
}

.field-info:hover > .field-info-box,
.field-info-button:focus + .field-info-box {
  display: block;
}

/* A hint that is one sentence about a whole card, at the hint's own size (U-1167):
   as a card's direct child it is matched by
   `.card > p` (0,1,1), which sets 14 px and beat `.field-hint`'s 12.5 px (0,1,0)
   — before U-1130 as well. This selector is (0,2,0), and only this hint carries the
   class. */
.card > .field-hint-wide {
  font-size: 12.5px;
}

.field-error {
  margin: 6px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--sd-error);
}

.field input[aria-invalid="true"],
.field select[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: var(--sd-error);
}

/* A checkbox has no border to colour, so a refused consent is outlined
   (U-2241); the message under it says why. */
.consent-check[aria-invalid="true"] {
  outline: 2px solid var(--sd-error);
  outline-offset: 2px;
}

/* A fixed prefix the control's value does not contain (`https://`, U-915). */
.field-affix {
  display: flex;
  align-items: stretch;
}

.field-prefix {
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--sd-border);
  border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--sd-surface-alt);
  color: var(--sd-text-soft);
  font-size: 14px;
  white-space: nowrap;
}

.field-affix input {
  min-width: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* --- Search / filter bar: parameters go to the server -------------------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}

.filter-bar[hidden] {
  display: none;
}

.filter-bar .field {
  margin-bottom: 0;
  flex: 1 1 200px;
}

/* THE LIST FILTER (U-1715), the bar `filter-bar.js` builds: each field takes the
   width of its CONTENT, not of the list. `.filter-bar .field` above grows, which
   is how one select stretched across ~950 px over an empty FAQ list. It is kept
   for the forms that borrow the bar's layout and are no list filter — the
   upload and invitation forms — so they do not change with this. */
.list-filter .field {
  flex: 0 1 auto;
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

/* `display: flex` above outranks `[hidden]` in base.css: a field hidden by the
   attribute would render anyway (L-FE-11). */
.list-filter .field[hidden] {
  display: none;
}

.list-filter .field > label,
.list-filter .field .field-hint {
  flex-basis: 100%;
}

.list-filter .field select,
.list-filter .field input:where(:not([type="checkbox"], [type="radio"])) {
  width: auto;
  max-width: 100%;
}

/* A filter's choice is as wide as its longest option, up to 16rem (U-1880): an
   option list that is DATA — a tier's name — has no length a page can promise,
   and one long name stretched the partner list's tier field across the bar.
   16rem holds the longest fixed choice here, „Wartet auf E-Mail-Bestätigung";
   a longer name is cut in the closed field and whole in the open list. AFTER
   the rule above, which has the same weight and would otherwise lift the cap. */
.list-filter .field select {
  max-width: min(100%, 16rem);
}

/* A search field has no option to size it, so it gets a reading width. */
.list-filter .field input[type="search"],
.list-filter .field input[type="text"] {
  min-width: min(16em, 100%);
}

/* „Filter zurücksetzen" lines up with the controls, not with their labels. */
.list-filter .filter-actions {
  display: flex;
  align-items: flex-end;
  flex: 0 0 auto;
}

/* A DROPDOWN OF CHECKBOXES (U-2153), `multi-select.js`: a filter that takes
   several values. The summary looks like the select beside it; the panel opens
   over the list below rather than pushing it down. */
.multi-select {
  position: relative;
}

.multi-select-button {
  display: flex;
  align-items: center;
  list-style: none;
  cursor: pointer;
  min-height: var(--control-h);
  padding: 0 32px 0 12px;
  min-width: 10rem;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--sd-surface);
  color: var(--sd-text);
  font-size: 14px;
}

.multi-select-button::-webkit-details-marker {
  display: none;
}

.multi-select-button::after {
  content: "▾";
  position: absolute;
  right: 12px;
  color: var(--sd-text-soft);
}

.multi-select-panel {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border: 1px solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--sd-surface);
  box-shadow: var(--shadow-pop);
  white-space: nowrap;
}

/* --- Form-level message (error summary, notice) -------------------------- */

/* --- THE NEUTRAL FORM MESSAGE IS A ROLE, AND U-507 GAVE IT ITS GROUND ------ *
 * U-725 left this open: *".form-message needs a role the token set does not
 * have"*. It does have one, and eleven callers had already found it — every
 * bare `.form-message` in this frontend carries `role="status"` and says some
 * version of *"you may only read here"* or *"this state does not allow that"*.
 * That is not an error, not a success and not a warning: it is **a note that
 * explains a state which is not a failure**, and `--sd-sunk` is exactly its
 * ground — a recess inside a surface (DESIGN_TOKENS §9.1).
 *
 * It was `--sd-surface-alt`, and that token INVERTS its role between the themes
 * (L-FE-44): measured, it is 1.10:1 BELOW the panel in light and 1.14:1 ABOVE it
 * in dark, so the same note read as "set back" in one theme and "raised" in the
 * other. `--sd-sunk` is 1.10:1 below in both.
 *
 * **In light nothing changes at all** — both tokens are `#F4F4F4` — which is
 * what a correct fix to a one-theme defect looks like, and the same shape
 * `badge.css` records for the same token. Ink is unaffected: `--sd-text`
 * measures 13.76:1 light and 12.82:1 dark on the new ground, up from 10.16:1.
 * -------------------------------------------------------------------------- */

.form-message {
  /* The SIDES alert (ADR-0167): body text, 8px by 16px inside. */
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-body);
  line-height: var(--text-body-lh);
  border: var(--border-w) solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--sd-sunk);
  color: var(--sd-text);
}

.form-message[hidden] {
  display: none;
}

/* A status line built before it has anything to say draws no empty frame
   (U-2046); it shows once a save or a refusal writes into it. */
.form-message:empty {
  display: none;
}

/* A reason SIDES wrote, shown as it was typed (U-1777). The review forms promise
   the partner reads it verbatim; a reviewer's line break survives the textarea,
   the API and the DOM, and the layout collapsed it into a space. `pre-wrap` keeps
   the breaks and still wraps a long line. The text stays a text node. */
.reason-as-typed {
  white-space: pre-wrap;
}

.form-message-error {
  background: var(--sd-error-bg);
  border-color: var(--sd-error-bd);
}

.form-message-success {
  background: var(--sd-success-bg);
  border-color: var(--sd-success-bd);
}

/* A notice the reader can close (U-1368): the sentence, and the "×" beside it. */
.form-message-dismissible {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.form-message-close {
  flex: none;
  margin: -2px -4px 0 0;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--sd-text-soft);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.form-message-close:hover {
  color: var(--sd-text);
}

/* Done, and something the reader must still act on: a partner decision whose
   notice to the company was not mailed (U-980). */
.form-message-warning {
  background: var(--sd-warning-bg);
  border-color: var(--sd-warning-bd);
}

/* --- A grid of fields, for a form with more than a handful ---------------- */

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 0 20px;
}

/* --- Grouped sections ----------------------------------------------------- */

.form-section {
  margin: 0 0 24px;
  padding: 0;
  border: 0;
}

.form-section > legend {
  padding: 0;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--doc-ink);
}

/* --- The error summary ---------------------------------------------------- */
/* A failed submit moves focus here, so it needs a visible ring of its own —
   `:focus-visible` in base.css does that, and the outline offset keeps it clear
   of the panel's border. What this file adds is the list of failed fields, each
   a link into its control, so the summary is a way in and not a report. */

.error-summary-title {
  margin: 0;
  font-weight: 600;
}

.error-summary-list {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 13px;
}

.error-summary-list li + li {
  margin-top: 4px;
}

/* --- Consent checkboxes, and any other list of choices -------------------- */
/* Each consent names the document AND the version it is recorded against,
   because that is what the consent ledger stores and a person is entitled to
   see what they are agreeing to. The `choice-*` names share the rules: the
   portal's language control (U-808) is a list of radios with the same layout. */

.consent-list,
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.consent-option,
.choice-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  cursor: pointer;
}

.consent-check,
.choice-input,
.field input:is([type="checkbox"], [type="radio"]) {
  flex: 0 0 auto;
  margin-top: 3px;
  width: 18px;
  height: 18px;
}

/* A list of choices in a row that wraps (U-1695): each choice a chip, its
   picture before its name, as the changelog's API filter draws them. */
.choice-list--wrap {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-list--wrap > .choice-option {
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--sd-border);
  border-radius: var(--radius);
  background: var(--doc-panel);
}

.choice-list--wrap > .choice-option:has(> .choice-input:checked) {
  border-color: var(--sd-primary);
}

.choice-list--wrap .choice-input {
  margin-top: 0;
}

.choice-list--wrap .connection-logo {
  width: 24px;
  height: 24px;
}

/* A box inside a `.field` without the `choice-*` classes sits beside its label
   as well (U-1693). Two shapes reach here: the box inside the label, and
   `buildField`'s label over a box, which this lays out beside it. */
.field > label:has(> input:is([type="checkbox"], [type="radio"])) {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.field:has(> input:is([type="checkbox"], [type="radio"])) {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "check label" ".     hint" ".     error";
  gap: 4px 10px;
  align-items: start;
}

.field:has(> input:is([type="checkbox"], [type="radio"])) > label {
  grid-area: label;
  margin-bottom: 0;
}

.field:has(> input:is([type="checkbox"], [type="radio"])) > input {
  grid-area: check;
  margin-top: 0;
}

.field:has(> input:is([type="checkbox"], [type="radio"])) > .field-hint {
  grid-area: hint;
  margin-top: 0;
}

.field:has(> input:is([type="checkbox"], [type="radio"])) > .field-error {
  grid-area: error;
  margin-top: 0;
}

.consent-version {
  display: block;
  font-size: 12px;
  color: var(--doc-ink-soft);
}

.consent-row .field-error {
  margin-left: 28px;
}

/* --- The honeypot --------------------------------------------------------- */
/* Off the page rather than `display: none`: it must stay a control a script
   fills, and only be out of a person's sight (`buildHoneypot`, U-1037). The
   compound selector outranks `.field`, whatever order the two are read in. */

.field.field-trap {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --- Compact inline forms (invite, upload) -------------------------------- */

.invite-form,
.upload-form {
  margin: 0 0 20px;
}

.invite-form .filter-bar .btn,
.upload-form .filter-bar .btn {
  flex: 0 0 auto;
}

/* --- File input ----------------------------------------------------------- */
/* Left as the browser's own control. A styled replacement is a label plus a
   visually-hidden input, and every such construct in the wild loses either the
   keyboard or the file name; the native control has both. */

.field input[type="file"] {
  padding: 8px 12px;
}

/* --- A form's own buttons ------------------------------------------------- */
/* The submit and its cancel, side by side. Here and not in a page sheet, because
   the form that carries it is drawn on portal pages and admin pages alike, and a
   rule in `admin.css` left the portal's two buttons touching (U-1290). */

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* --- „Übersetzen" beside a field (U-2209) --------------------------------- */
/* The button, its way back and its line under a field of a language tab
   (`translate-button.js`). The line is a status: a hint, the machine-translation
   note asking for a review, or a refusal. */

.translate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.translate-line {
  flex: 1 1 100%;
  margin: 0;
  font-size: 12.5px;
  color: var(--doc-ink-soft);
}

.translate-line-note {
  font-weight: 600;
}

.translate-line-error {
  font-weight: 600;
  color: var(--sd-error);
}
