/* Forms (Figma 06 Forms: Form/Intent 254:717, Form/Field 254:799, Form/Check 285:1427, Form/Alert 346:4717). */

.rform {
  display: block;
}

.rform__trap {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.rform__main {
  display: grid;
  gap: var(--space-24);
}

.rform__body {
  display: grid;
  grid-template-columns: repeat(var(--layout-columns), minmax(0, 1fr));
  column-gap: var(--layout-gutter);
  align-items: start;
}

.rform__intents {
  grid-column: 1 / span 4;
  align-self: start;
  display: grid;
  /* The four reasons are always one size (the tallest card's content, as the
     Form/Intent component hugs it), whatever the fields beside them do
     (review; DESIGN-NOTES 60). */
  grid-auto-rows: 1fr;
  gap: var(--space-12);
  margin: 0;
  padding: 0;
  border: 0;
}

.rform__step {
  grid-column: 5 / -1;
  display: grid;
  align-content: start; /* the room kept for a taller reason stays below the button (form.js) */
  gap: var(--space-32);
}

.rform__body--single .rform__step {
  grid-column: 1 / -1;
}

.rform__progress,
.rform__chosen {
  display: none;
}

/* Fields: 6-track grid so halves and thirds share one rhythm */
.rform__fields {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--space-16);
  margin: 0;
  padding: 0;
  border: 0;
}

.rform__fields[hidden] {
  display: none;
}

.field--half { grid-column: span 3; }
.field--third { grid-column: span 2; }
.field--full,
.rform__fields > .check,
.rform__more { grid-column: 1 / -1; }

.rform__more {
  display: none;
  justify-self: start;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* ---------- Field ---------- */

.field__box {
  position: relative;
  display: grid;
  gap: var(--space-4);
  padding: var(--space-12) var(--space-16);
  background: var(--field-fill);
  color: var(--field-text);
  cursor: text;
  transition: box-shadow 0.15s var(--motion-easing-standard);
}

.field__labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  font-size: var(--font-size-label);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field__error {
  display: none;
  align-items: center;
  gap: var(--space-8);
  margin-left: auto;
  color: var(--color-base-white);
}

.field__error i {
  width: var(--space-8);
  height: var(--space-8);
  background: var(--field-error);
}

.field__input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--field-text);
  font: inherit;
  font-size: var(--font-size-body-m);
  line-height: 1.6;
  appearance: none;
}

.field__input::placeholder {
  color: var(--field-hint);
  opacity: 1;
}

.field__input:focus {
  outline: 0;
}

textarea.field__input {
  height: calc(var(--space-64) + var(--space-24) + var(--stroke-focus)); /* box 132 tall in Figma */
  resize: none;
}

.field__control {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

select.field__input {
  cursor: pointer;
}

select.field__input:invalid,
select.field__input option[value=""] {
  color: var(--field-hint);
}

select.field__input option {
  color: var(--color-neutral-950);
}

.field__icon {
  width: calc(var(--space-16) + var(--space-4));
  height: calc(var(--space-16) + var(--space-4));
  flex: none;
  pointer-events: none;
}

.field--select .field__icon {
  transform: rotate(-90deg);
}

.field__file {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.field__filename {
  color: var(--field-hint);
}

.field.is-filled .field__filename {
  color: var(--field-text);
}

output.field__input {
  display: block;
  color: var(--field-text);
}

/* Locked field (Service total): read only, so no text cursor. */
.field--locked {
  position: relative;
}

.field--locked .field__box {
  cursor: default;
}

/* Its tooltip (Figma Awards form states 316:6157, state 3): paper box 300
   wide above the field, Body/M message and the Go to Plans link, a 12px
   caret at 24 from the left. Shown on hover, keyboard focus or tap. */
.field__tip {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--space-12));
  z-index: 5;
  display: grid;
  justify-items: start;
  gap: var(--space-8);
  width: calc(var(--space-96) * 3 + var(--space-12));
  max-width: calc(100vw - var(--page-margin) * 2);
  padding: var(--space-16);
  background: var(--color-base-white);
  color: var(--color-neutral-950);
  font-size: var(--font-size-body-m);
  line-height: 1.6;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s var(--motion-easing-standard), visibility 0s linear 0.2s;
}

.field__tip .link {
  color: var(--color-neutral-950);
}

/* caret, and an invisible bridge so the pointer can move from the field onto the tip */
.field__tip::after {
  content: "";
  position: absolute;
  left: var(--space-24);
  bottom: calc(var(--space-12) / -2);
  width: var(--space-12);
  height: var(--space-12);
  background: inherit;
  transform: rotate(45deg);
}

.field__tip::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: var(--space-12);
}

.field--locked:hover .field__tip,
.field--locked:focus-within .field__tip,
.field--locked.is-tip-open .field__tip {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s var(--motion-easing-standard), visibility 0s;
}

/* After Go to Plans the tip is gone, also while the pointer is still over it. */
.field--locked.is-tip-closed .field__tip {
  opacity: 0;
  visibility: hidden;
}

/* ---------- Dropdown (no Figma frame for the open list yet; DESIGN-NOTES 56) ----------
   form.js turns each select into a combobox button and a listbox (WAI-ARIA
   select-only combobox). The list is part of the field: it hangs 4 under the
   box (or 4 above it when there is no room below), the box's width, and moves
   with the form. A paper panel, Body/M rows, the active row on neutral-100
   and the chosen row marked with the red square used across the site. It
   scrolls inside itself and never scrolls the page. Without JS the system
   select stays. */
.field--select {
  position: relative;
}

.field--select .field__box {
  cursor: pointer;
}

.field__native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.field__choice {
  display: block;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.field__choice.is-placeholder {
  color: var(--field-hint);
}

.field__choice:disabled {
  cursor: default;
}

.field--select .field__icon {
  transition: transform 0.15s var(--motion-easing-standard);
}

.field--select.is-open .field__icon {
  transform: rotate(90deg);
}

.field__list {
  position: absolute;
  top: calc(100% + var(--space-4));
  left: 0;
  right: 0;
  z-index: 6;
  max-height: var(--list-max, calc(var(--space-96) * 3));
  margin: 0;
  padding: var(--space-8) 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  background: var(--color-base-white);
  color: var(--color-neutral-950);
  box-shadow: var(--effect-elevation-raised);
  scrollbar-width: thin;
  animation: field-list-in 0.15s var(--motion-easing-standard);
}

.field__list[hidden] {
  display: none;
}

.field--select.is-above .field__list {
  top: auto;
  bottom: calc(100% + var(--space-4));
}

@keyframes field-list-in {
  from { opacity: 0; translate: 0 calc(var(--space-4) * -1); }
}

.field--select.is-above .field__list {
  animation-name: field-list-in-above;
}

@keyframes field-list-in-above {
  from { opacity: 0; translate: 0 var(--space-4); }
}

.field__option {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  font-size: var(--font-size-body-m);
  line-height: 1.6;
  cursor: pointer;
  user-select: none;
}

.field__option::before {
  content: "";
  flex: none;
  width: calc(var(--space-8) + var(--stroke-focus));
  height: calc(var(--space-8) + var(--stroke-focus));
}

.field__option[aria-selected="true"]::before {
  background: var(--color-red-500);
}

.field__option.is-active {
  background: var(--color-neutral-100);
}

/* Focus: 2px border/strong (Figma State=Focus) */
.field__box:focus-within {
  box-shadow: inset 0 0 0 var(--stroke-focus) var(--border-strong);
}

/* Error: 4px bar on the left, short caps message in the label row; nothing below moves */
.field.is-error .field__box {
  box-shadow: inset var(--space-4) 0 0 0 var(--field-error);
}

.field.is-error .field__box:focus-within {
  box-shadow: inset var(--space-4) 0 0 0 var(--field-error), inset 0 0 0 var(--stroke-focus) var(--border-strong);
}

.field.is-error .field__error {
  display: inline-flex;
}

.field.is-error .field__aside {
  display: none;
}

/* ---------- Intent (radio card) ---------- */

.intent {
  display: grid;
  gap: var(--space-8);
  padding: var(--space-16) var(--space-24);
  border: var(--stroke-control) solid var(--color-base-white);
  color: var(--color-base-white);
  cursor: pointer;
  transition: background-color 0.2s var(--motion-easing-standard), color 0.2s var(--motion-easing-standard);
}

.intent__top {
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.intent__number,
.intent__line {
  font-size: var(--font-size-button);
  font-weight: 600;
  line-height: 1.4;
}

.intent__label {
  flex: 1;
  font-size: var(--font-size-heading-3);
  font-weight: 600;
  line-height: 1.2;
}

.intent__check {
  width: var(--space-16);
  height: var(--space-16);
  border: var(--stroke-control) solid currentColor;
}

.intent:hover {
  background: color-mix(in srgb, var(--color-base-white) 12%, transparent);
}

.intent:has(input:checked) {
  background: var(--color-base-white);
  color: var(--color-red-500);
}

.intent:has(input:checked) .intent__check {
  background: var(--color-red-500);
}

.intent:has(input:focus-visible) {
  outline: var(--stroke-focus) solid var(--color-base-white);
  outline-offset: var(--space-4);
}

/* ---------- Check (285:1427) ---------- */

.check__row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  cursor: pointer;
}

.check__box {
  position: relative;
  flex: none;
  width: var(--space-24);
  height: var(--space-24);
  border: var(--stroke-control) solid var(--border-strong);
}

.check__row:has(input:checked) .check__box {
  background: var(--text-primary);
}

.check__row:has(input:checked) .check__box::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: calc(var(--space-8) + var(--stroke-focus));
  height: calc(var(--space-8) + var(--stroke-focus));
  background: var(--color-red-500);
  transform: translate(-50%, -50%);
}

.check__row:has(input:focus-visible) .check__box {
  outline: var(--stroke-focus) solid var(--border-focus);
  outline-offset: var(--stroke-focus);
}

.check__error {
  display: none;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-8);
  padding-left: calc(var(--space-24) + var(--space-12));
}

.check__error i {
  width: calc(var(--space-8) + var(--stroke-focus));
  height: calc(var(--space-8) + var(--stroke-focus));
  background: var(--field-error);
}

.check.is-error .check__box {
  border-width: 3px; /* Figma: thick outline on error */
  border-color: var(--field-error);
}

.check.is-error .check__error {
  display: flex;
}

/* ---------- Alert (send failed) ---------- */

.form-alert {
  display: flex;
  gap: var(--space-12);
  padding: var(--space-16) var(--space-24);
  background: var(--color-base-white);
  color: var(--color-neutral-950);
}

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

.form-alert > span:last-child {
  display: grid;
  gap: var(--space-4);
}

.form-alert__square {
  flex: none;
  width: var(--space-12);
  height: var(--space-12);
  margin-top: var(--space-8);
  background: var(--color-red-500);
}

/* ---------- Send row and sending state ---------- */

.rform__send {
  display: flex;
  align-items: center;
  gap: var(--space-24);
}

.rform .button__spinner {
  display: none;
}

.rform.is-sending .button__spinner {
  display: block;
}

.rform.is-sending .rform__main {
  pointer-events: none;
}

.rform.is-sending .button[data-submit] {
  pointer-events: none;
}

/* ---------- Sent ---------- */

.rform__sent {
  display: grid;
  justify-items: start;
  gap: var(--space-32);
}

.rform__sent[hidden],
.rform.is-sent .rform__main {
  display: none;
}

/* ---------- Tablet: two steps ---------- */

@media (max-width: 1199px) {
  .rform__intents {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rform__progress {
    display: block;
    grid-column: 1 / -1;
    margin-top: var(--space-12);
  }

  .rform__step {
    grid-column: 1 / -1;
  }

  .rform__chosen {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: calc(var(--space-96) + var(--space-4));
  }

  .rform__back {
    display: inline-flex;
    align-items: center;
    gap: var(--space-8);
  }

  .rform[data-step="choose"] .rform__step,
  .rform[data-step="fields"] .rform__intents {
    display: none;
  }

  .rform[data-step="fields"] .rform__question {
    display: none;
  }

  .rform__fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field--half,
  .field--third { grid-column: span 1; }
}

/* ---------- Mobile: one column, optional fields folded ---------- */

@media (max-width: 767px) {
  .rform__intents {
    grid-template-columns: minmax(0, 1fr);
  }

  .rform__step {
    gap: var(--space-24);
  }

  .rform__fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .field--half,
  .field--third { grid-column: 1 / -1; }

  .rform__fields:not(.is-more) .field.is-optional {
    display: none;
  }

  .rform__fields:not(.is-more) .rform__more {
    display: inline-flex;
  }

  .rform__send p {
    display: none;
  }
}
