/*
 * Shared form components (test-gate; style-guide.md, Forms and Chip): field, text input, text area
 * (writing-sample), chip group and chip, checkbox row, field and form messages, and the inactive primary
 * button. Linked after the head region by every page with a form, the gate first; every value comes from
 * tokens.css.
 */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--field-gap);
}

.field__label,
.chip-group__legend {
  font-size: var(--field-label-font-size);
  font-weight: 600;
}

.text-input {
  width: 100%;
  min-height: var(--input-height);
  padding: 0 var(--input-padding-inline);
  border: var(--input-border-width) solid var(--input-border);
  border-radius: var(--input-radius);
  background: var(--input-bg);
  color: var(--input-text);
  font: inherit;
  font-size: var(--input-font-size);
}

.text-input[aria-invalid="true"] {
  border-color: var(--input-border-invalid);
}

/* Text area (writing-sample; style guide, Forms): TEXTAREA_MIN_LINES lines at --fs-body-lg on phones,
   230 px from BREAKPOINT_DESKTOP; read-only while sending keeps the same look */
.text-area {
  display: block;
  width: 100%;
  min-height: var(--text-area-min-height);
  margin: 0;
  padding: var(--text-area-padding);
  border: var(--input-border-width) solid var(--text-area-border);
  border-radius: var(--text-area-radius);
  background: var(--text-area-bg);
  color: var(--text-area-text);
  font: inherit;
  font-size: var(--text-area-font-size);
  line-height: var(--text-area-line-height);
  resize: none;
}

.text-area:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

@media (min-width: 64rem) {
  .text-area {
    min-height: var(--text-area-min-height-desktop);
  }
}

.chip-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.chip-group__legend {
  margin-bottom: var(--chip-legend-gap);
  padding: 0;
}

.chip-group__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--chip-gap);
}

/* A native radio over the whole pill: one tap selects, the group keeps arrow keys and one tab stop */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--chip-height);
  padding: 0 var(--chip-padding-inline);
  border: var(--chip-border-width) solid var(--chip-border);
  border-radius: var(--chip-radius);
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: var(--chip-font-size);
  font-weight: 600;
  cursor: pointer;
}

.chip:has(:checked) {
  border-color: var(--chip-border-selected);
  background: var(--chip-bg-selected);
  color: var(--chip-text-selected);
}

/* The radio itself is invisible, so the pill draws the keyboard focus ring (ux.md, Navigation) */
.chip:has(:focus-visible) {
  outline: var(--focus-ring-width) solid var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

.chip__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--checkbox-gap);
}

.checkbox-row__input {
  flex: none;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  margin: var(--checkbox-offset-top) 0 0;
  accent-color: var(--checkbox-accent);
}

.checkbox-row__label {
  min-height: var(--checkbox-row-min-height);
  color: var(--checkbox-label-color);
  font-size: var(--checkbox-label-font-size);
  line-height: var(--message-line-height);
}

/* The whole label is the target of the box (ux.md, Touch Targets); the link inside it reaches TAP_MIN */
.checkbox-row__label a {
  padding-block: var(--checkbox-link-padding-block);
  color: var(--checkbox-link-color);
}

/* Field and form messages: the icon and the sentence, so colour is never the only cue */
.form-message {
  display: flex;
  align-items: flex-start;
  gap: var(--message-gap);
  margin: 0;
  color: var(--message-color);
  font-size: var(--message-font-size);
  line-height: var(--message-line-height);
}

.form-message__icon {
  flex: none;
  width: var(--message-icon-size);
  height: var(--message-icon-size);
  margin-top: var(--message-icon-offset-top);
}

/* Inactive, not disabled: the button stays focusable and described by its hint (CHK021) */
.button--primary[aria-disabled="true"] {
  background: var(--button-bg-inactive);
  color: var(--button-text-inactive);
}
