/*
 * Purpose: Form controls. Every field has a real label; placeholders are never
 * used as the only label.
 */

.rh-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-20);
  max-width: 720px;
}

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

.rh-field__label {
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  color: var(--rh-text-primary);
}

.rh-field__required {
  color: var(--rh-error-text);
  margin-left: var(--space-4);
}

/*
 * Marks a field that can be left empty. Saying so is worth the space on a form
 * where everything else is required - otherwise an optional box reads as one
 * more thing standing between the applicant and the button.
 */
.rh-field__optional {
  margin-left: var(--space-8);
  font-size: var(--fs-caption);
  font-weight: var(--fw-regular);
  color: var(--rh-text-secondary);
}

.rh-field__hint {
  font-size: var(--fs-caption);
  color: var(--rh-text-secondary);
}

.rh-input,
.rh-select,
.rh-textarea {
  width: 100%;
  min-height: var(--input-height);
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--rh-border-input);
  border-radius: var(--r-input);
  background-color: var(--rh-white);
  font-size: var(--fs-body);
  color: var(--rh-text-primary);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.rh-textarea {
  min-height: 128px;
  resize: vertical;
  line-height: var(--lh-normal);
}

/*
 * For an optional aside rather than a main answer. A 128px box invites a long
 * reply and takes up the room to match, which is wrong when the field is a
 * footnote to the rest of the form.
 */
.rh-textarea--short {
  min-height: 88px;
}

/* ---------------------------------------------------------- THEMED SELECT */

/*
 * A browser styles the closed <select> but draws the open list itself, in the
 * operating system's own chrome - it cannot be themed with CSS at any level.
 * assets/js/select.js therefore draws the list, and the real select stays
 * underneath as the control the form submits.
 *
 * Everything below only applies once that script has run. Without JavaScript
 * .rh-select keeps the styling above and behaves as a normal native select.
 */
.rh-select-ui {
  position: relative;
  width: 100%;
}

.rh-select.rh-select--enhanced {
  /*
   * Hidden without display:none, so the select is still a submitting form
   * control and validation can still focus it.
   */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
  min-height: 0;
}

.rh-select-ui__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  width: 100%;
  min-height: var(--input-height);
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--rh-border-input);
  border-radius: var(--r-input);
  background-color: var(--rh-white);
  font-size: var(--fs-body);
  font-family: inherit;
  color: var(--rh-text-primary);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out);
}

.rh-select-ui__trigger:hover {
  border-color: var(--rh-text-secondary);
}

/*
 * A small select keeps its size once it is enhanced. The modifier lives on the
 * hidden <select>, so the trigger has to inherit it through a sibling selector -
 * without this the sort control stood at the full 48px next to the 36px view
 * toggle and Save this search buttons beside it.
 */
.rh-select--sm ~ .rh-select-ui__trigger {
  min-height: 36px;
  padding-block: var(--space-4);
  font-size: var(--fs-small);
}

.rh-select-ui__trigger:focus-visible {
  outline: none;
  border-color: var(--rh-teal);
  box-shadow: 0 0 0 3px var(--rh-teal-light);
}

.rh-select-ui__trigger:disabled {
  background-color: var(--rh-surface);
  color: var(--rh-text-secondary);
  cursor: not-allowed;
}

.rh-select-ui__value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Chevron drawn in CSS, so it needs no icon request. */
.rh-select-ui__caret {
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--rh-teal);
  border-bottom: 2px solid var(--rh-teal);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--dur-fast) var(--ease-out);
}

.rh-select-ui.is-open .rh-select-ui__caret {
  transform: translateY(2px) rotate(225deg);
}

.rh-select-ui__list {
  position: absolute;
  top: calc(100% + var(--space-4));
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  max-height: 264px;
  overflow-y: auto;
  padding: var(--space-4);
  border: 1px solid var(--rh-border);
  border-radius: var(--r-input);
  background-color: var(--rh-white);
  box-shadow: var(--shadow-md);
}


.rh-select-ui__option {
  padding: var(--space-8) var(--space-12);
  border-radius: var(--r-button);
  font-size: var(--fs-body);
  color: var(--rh-text-primary);
  cursor: pointer;
}

.rh-select-ui__option:hover,
.rh-select-ui__option.is-active {
  background-color: var(--rh-surface);
}

.rh-select-ui__option[aria-selected="true"] {
  background-color: var(--rh-teal-light);
  color: var(--rh-teal);
  font-weight: var(--fw-semibold);
}

.rh-select-ui__option[aria-disabled="true"] {
  color: var(--rh-text-secondary);
  cursor: not-allowed;
}

.rh-input::placeholder,
.rh-textarea::placeholder {
  color: var(--rh-text-secondary);
}

.rh-input:hover,
.rh-select:hover,
.rh-textarea:hover {
  border-color: var(--rh-text-secondary);
}

.rh-input:focus,
.rh-select:focus,
.rh-textarea:focus {
  outline: none;
  border-color: var(--rh-teal);
  box-shadow: 0 0 0 3px var(--rh-teal-light);
}

.rh-input:disabled,
.rh-select:disabled,
.rh-textarea:disabled {
  background-color: var(--rh-surface);
  color: var(--rh-text-secondary);
  cursor: not-allowed;
}

/* Error state */
.rh-field--error .rh-input,
.rh-field--error .rh-select,
.rh-field--error .rh-textarea {
  border-color: var(--rh-error);
}

.rh-field__error {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--rh-error-text);
}

.rh-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2368716E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-12) center;
  padding-right: var(--space-40);
}

/* Checkbox and radio */
.rh-choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  min-height: var(--touch-target);
  padding-block: var(--space-8);
  cursor: pointer;
}

.rh-choice input[type="checkbox"],
.rh-choice input[type="radio"] {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--rh-teal);
  cursor: pointer;
}

.rh-choice__label {
  font-size: var(--fs-small);
  line-height: var(--lh-normal);
  color: var(--rh-text-primary);
}

/*
 * A choice whose answer is already settled elsewhere. The control is genuinely
 * disabled rather than merely styled that way, and it states why.
 */
.rh-choice--settled,
.rh-choice--settled input {
  cursor: default;
}

.rh-choice--settled .rh-choice__label {
  color: var(--rh-text-secondary);
}

.rh-choice__reason {
  display: block;
  font-size: var(--fs-caption);
  color: var(--rh-text-secondary);
}

/* Form-level feedback */
.rh-form__message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-16);
  border-radius: var(--r-input);
  font-size: var(--fs-small);
  line-height: var(--lh-relaxed);
}

.rh-form__message .rh-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.rh-form__message--success {
  background-color: rgba(25, 134, 92, 0.08);
  color: var(--rh-success);
}

.rh-form__message--error {
  background-color: rgba(217, 75, 75, 0.08);
  color: var(--rh-error-text);
}


/* Busy state on a submitting button. */
.rh-btn[data-loading="true"] {
  pointer-events: none;
  opacity: 0.7;
}

.rh-btn[data-loading="true"]::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--r-pill);
  animation: rh-spin 0.7s linear infinite;
}

@keyframes rh-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rh-btn[data-loading="true"]::after {
    animation: none;
  }
}

/* Honeypot field - hidden from people, visible to naive bots. */
.rh-honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ------------------------------------------------------------- FILE FIELD

   A native <input type="file"> with the browser's grey "Choose File" chrome is
   the one control on the site that ignores the design system, so it is themed
   here rather than replaced: the real input stays the input, keyboard and
   screen-reader behaviour is untouched, and ::file-selector-button carries the
   button styling. Nothing depends on JavaScript.
   ------------------------------------------------------------------------ */

.rh-file {
  display: block;
  width: 100%;
  padding: var(--space-12);
  border: 1px dashed var(--rh-border-strong);
  border-radius: var(--r-input);
  background-color: var(--rh-surface);
  font-family: inherit;
  font-size: var(--fs-small);
  color: var(--rh-text-secondary);
  cursor: pointer;
}

.rh-file:hover {
  border-color: var(--rh-teal);
  background-color: var(--rh-teal-light);
}

.rh-file:focus-visible {
  outline: 2px solid var(--rh-teal);
  outline-offset: 2px;
}

.rh-file::file-selector-button {
  margin-right: var(--space-12);
  padding: var(--space-8) var(--space-16);
  min-height: var(--touch-target);
  border: 1px solid var(--rh-teal);
  border-radius: var(--r-button);
  background-color: var(--rh-white);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: var(--fw-semibold);
  color: var(--rh-teal);
  cursor: pointer;
}

.rh-file:hover::file-selector-button {
  background-color: var(--rh-teal);
  color: var(--rh-white);
}

/* What was actually picked. Written by JavaScript, so it starts hidden. */
.rh-file__chosen {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-8);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semibold);
  color: var(--rh-success);
}

.rh-file__chosen .rh-icon {
  flex-shrink: 0;
}

.rh-file__chosen--error {
  color: var(--rh-error-text);
}

.rh-file[aria-invalid="true"] {
  border-style: solid;
  border-color: var(--rh-error);
}
