/* Forms, design system §4 "Champ & étiquettes": the letter sheet, ruled fields, errors and
   status lines. Shared by the contact form (index.html) and the diagnostic (diagnostic.html). */

/* The form is a letter: a sheet of paper with its corner folded back, and ruled lines to write
   on in place of boxes. */
.form {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
}

.form .h3 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
}

.form__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: var(--space-4) var(--space-5);
}

/* The label line carries the field's error, set against its right edge, so a message to correct
   never makes the letter taller (a long one wraps within the line). */
.field {
  display: grid;
  grid-template-areas:
    "label error"
    "control control";
  grid-template-columns: auto minmax(0, 1fr);
  align-content: start;
  align-items: baseline;
  gap: 2px var(--space-3);
}

.field input,
.field textarea {
  grid-area: control;
}

.field label {
  grid-area: label;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  transition: color var(--duration-hover) ease;
}

.field:focus-within label {
  color: var(--color-primary);
}

.field__optional {
  font-weight: 400;
}

/* A ruled line to write on: no box, the line thickens to fern while the field is in use. */
.field input,
.field textarea {
  --rule: var(--color-border-strong);
  width: 100%;
  min-height: var(--size-touch);
  padding: 10px 0 6px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: inset 0 -1px 0 var(--rule);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
  caret-color: var(--color-primary);
  transition: box-shadow var(--duration-hover) ease;
}

/* Letter paper: every line of the message box is ruled, and the rules scroll with the text. */
.field textarea {
  --line: 1.75rem;
  height: calc(3 * var(--line) + 6px);
  min-height: calc(2 * var(--line) + 6px);
  padding: 0 0 6px;
  line-height: var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0 calc(var(--line) - 1px), var(--color-border) calc(var(--line) - 1px) var(--line));
  background-attachment: local;
  resize: vertical;
}

.field input:hover,
.field textarea:hover {
  --rule: var(--color-text-secondary);
}

/* Focus: the rule doubles in fern (and the label turns fern), in place of a ring around a box
   the field no longer has. */
.field input:focus-visible,
.field textarea:focus-visible {
  --rule: var(--color-primary);
  outline: none;
  box-shadow: inset 0 -2px 0 var(--rule);
}

.field [aria-invalid="true"] {
  --rule: var(--color-error);
  box-shadow: inset 0 -2px 0 var(--rule);
}

.field__error {
  grid-area: error;
  justify-self: end;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.35;
  text-align: right;
  color: var(--color-error);
}

.form__summary {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-error-subtle);
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* The send line: the button and what it does, side by side. */
.form__send {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-2);
}

.form__submit {
  flex: none;
}

.form__note {
  flex: 1 1 14rem;
  max-width: 34ch;
  line-height: 1.45;
}

.form__status {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-primary-subtle);
  font-size: var(--text-sm);
}
