.form-row {
  display: flex;
  align-items: center;
  gap: 1ch;
  margin-bottom: calc(var(--font-size) * 0.5);

  label {
    flex-shrink: 0;
    min-width: 12ch;
    display: block;
  }

  input:not([type="checkbox"]), select, textarea {
    flex: 1;
    min-width: 0;
  }

  input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
  }

  small {
    flex: 1;
    margin-left: 0.5ch;
    color: var(--theme-border);
  }
}

.form-actions {
  display: flex;
  gap: 1ch;
  justify-content: flex-end;
  margin-top: calc(var(--font-size) * var(--theme-line-height-base));
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
textarea,
select {
  background: var(--theme-background-input);
  border: none;
  box-shadow: inset 0 0 0 1px var(--theme-border);
  color: var(--theme-text);
  font-family: var(--font-family-mono);
  font-size: var(--font-size);
  line-height: calc(var(--theme-line-height-base) * 1rem);
  padding: 0 1ch;

  &:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--theme-focused-foreground);
  }

  &::placeholder {
    color: var(--theme-border);
  }
}

textarea {
  resize: vertical;
  min-height: calc(var(--font-size) * var(--theme-line-height-base) * 3);
}

input[type="checkbox"] {
  appearance: none;
  width: 1.5em;
  height: 1.5em;
  background: var(--theme-background-input);
  border: 1px solid var(--theme-border);
  border-radius: 0.25em;
  cursor: pointer;
  vertical-align: middle;
  display: inline-block;
  position: relative;
  transition: background-color 150ms ease, border-color 150ms ease;

  &:hover:not(:disabled) {
    border-color: var(--theme-focused-foreground);
  }

  &:checked {
    background: var(--theme-focused-foreground);
    border-color: var(--theme-focused-foreground);

    &::after {
      content: "✓";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      color: var(--theme-background-input);
      font-size: 0.85em;
      font-weight: bold;
      line-height: 1;
    }
  }

  &:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--theme-background-input), 0 0 0 3px var(--theme-focused-foreground);
  }

  &:disabled {
    cursor: not-allowed;
    opacity: 0.6;
  }
}

input[type="file"] {
  font-family: var(--font-family-mono);
  font-size: var(--font-size);
}

fieldset {
  border: none;
  box-shadow: inset 2px 0 0 0 var(--theme-border);
  padding: 0 0 0 2ch;
  margin-bottom: calc(var(--font-size) * var(--theme-line-height-base));

  legend {
    font-weight: 600;
    margin-left: -2ch;
    padding: 0 1ch 0 0;
  }
}
