/*
 * User-defined form styling for the front-end.
 *
 * Logical properties throughout (`inline-start`, `margin-inline`) so the
 * same rules serve an RTL Persian site and an LTR translation of it without
 * a mirrored stylesheet.
 */

.bp-form {
  --bp-form-gap: 1rem;
  --bp-form-radius: 8px;
  --bp-form-border: var(--line-strong);
  --bp-form-error: var(--danger);
  --bp-form-success: var(--success);
}

.bp-form__description {
  margin-block-end: 1.25rem;
  color: var(--fg-subtle);
  line-height: 2;
}

.bp-form__grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--bp-form-gap);
}

.bp-form__row { grid-column: span 12; }
.bp-form__row--3 { grid-column: span 3; }
.bp-form__row--4 { grid-column: span 4; }
.bp-form__row--6 { grid-column: span 6; }
.bp-form__row--8 { grid-column: span 8; }
.bp-form__row--9 { grid-column: span 9; }

/* Narrow viewports get one column: a 3-of-12 field on a phone is a field
   nobody can type into. */
@media (max-width: 640px) {
  .bp-form__row,
  .bp-form__row--3,
  .bp-form__row--4,
  .bp-form__row--6,
  .bp-form__row--8,
  .bp-form__row--9 { grid-column: span 12; }
}

.bp-form__label {
  display: block;
  margin-block-end: 0.375rem;
  font-weight: 500;
  font-size: 0.9375rem;
}

.bp-form__required {
  color: var(--bp-form-error);
  margin-inline-start: 0.25rem;
}

/* Every text-like input, by exclusion rather than by list.
 *
 * This used to enumerate `text`, `email`, `tel`, `number`, `time` and `file`
 * — so the first `password` field the product ever rendered came out at the
 * browser's default 228px beside full-width neighbours, and `date`, `search`
 * and `url` would have done the same. An allow-list of input types is a list
 * somebody has to remember to extend, and nobody does; the exclusions below
 * are the types that genuinely must not be stretched, and they do not grow.
 */
.bp-form input:not([type="checkbox"], [type="radio"], [type="range"],
                   [type="color"], [type="submit"], [type="button"],
                   [type="hidden"], [type="image"]),
.bp-form textarea,
.bp-form select {
  inline-size: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--bp-form-border);
  border-radius: var(--bp-form-radius);
  background: var(--bg-raised);
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.bp-form input:focus-visible,
.bp-form textarea:focus-visible,
.bp-form select:focus-visible {
  outline: none;
  border-color: var(--primary, var(--brand));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary, var(--brand)) 20%, transparent);
}

/* aria-invalid, not a class: the attribute is what assistive technology
   reads, so styling from it keeps the two from drifting apart. */
.bp-form [aria-invalid="true"] {
  border-color: var(--bp-form-error);
}

.bp-form textarea { resize: vertical; min-block-size: 6rem; }

.bp-form__check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.bp-form__check input { margin-block-start: 0.25rem; }

.bp-form ul { list-style: none; margin: 0; padding: 0; }
.bp-form ul li { margin-block-end: 0.375rem; }
.bp-form ul li label { margin-inline-start: 0.375rem; }

.bp-form__help {
  display: block;
  margin-block-start: 0.375rem;
  font-size: 0.8125rem;
  color: var(--fg-subtle);
}

.bp-form__error {
  margin-block-start: 0.375rem;
  font-size: 0.8125rem;
  color: var(--bp-form-error);
}

.bp-form__heading {
  margin: 1rem 0 0;
  font-size: 1.125rem;
  padding-block-end: 0.5rem;
  border-block-end: 1px solid var(--line);
}

.bp-form__paragraph { color: var(--fg-subtle); line-height: 2; margin: 0; }

.bp-form__alert {
  margin-block-end: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--bp-form-radius);
  font-size: 0.9375rem;
  line-height: 1.9;
}
.bp-form__alert--error {
  background: color-mix(in oklab, var(--danger) 8%, var(--bg));
  color: var(--danger);
  border: 1px solid color-mix(in oklab, var(--danger) 22%, var(--bg));
}
.bp-form__alert--success {
  background: color-mix(in oklab, var(--success) 8%, var(--bg));
  color: var(--success);
  border: 1px solid color-mix(in oklab, var(--success) 22%, var(--bg));
}

.bp-form__actions { margin-block-start: 1.5rem; }

.bp-form__submit {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6875rem 1.75rem;
  border: none;
  border-radius: var(--bp-form-radius);
  background: var(--primary, var(--brand));
  color: var(--bg-raised);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s;
}
.bp-form__submit:hover:not(:disabled) { filter: brightness(0.92); }
.bp-form__submit:disabled { opacity: 0.65; cursor: progress; }

.bp-form__spinner {
  inline-size: 1rem;
  block-size: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-block-start-color: var(--bg-raised);
  border-radius: 50%;
  animation: bp-form-spin 0.7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .bp-form__spinner { animation-duration: 2s; }
  .bp-form input, .bp-form textarea, .bp-form select,
  .bp-form__submit { transition: none; }
}

/* Honeypot: clipped, not display:none. Some bots skip fields that are
   display:none or visibility:hidden; a clipped field looks real to them and
   is unreachable for everyone else (tabindex=-1 + aria-hidden). */
.bp-form__hp {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Rating renders as a horizontal row of radios rather than a vertical list.
   `RadioSelect` puts its widget attrs on the *container* it renders, not on
   each radio — so `.bp-rating-input` is the row itself. The old rule looked
   for a <ul> holding it, which never existed, and every rating on the site
   rendered as a stacked list of bare numbers. */
.bp-form .bp-rating-input {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  border: none;
  padding: 0;
}
.bp-form .bp-rating-input > div { display: inline-flex; }

/* ── Studio-laid-out fields ────────────────────────────────────────────────
   A form composed on the Studio canvas emits the classes above, so it looks
   identical to a whole-form render. Only the controls that have no
   form-builder equivalent need anything extra. */

.bp-form__range { inline-size: 100%; accent-color: var(--brand); }

.bp-form__color {
  inline-size: 3rem;
  block-size: 2.25rem;
  padding: 2px;
  cursor: pointer;
}

/* A checkbox presented as a switch. Still a checkbox to the accessibility
   tree and to the server — only the paint changes, so nothing about how the
   value is validated or announced depends on which widget the author picked. */
.bp-form__switch {
  inline-size: 2.5rem;
  block-size: 1.375rem;
  appearance: none;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
  transition: background .15s ease;
}
.bp-form__switch::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  inline-size: 1.125rem;
  block-size: 1.125rem;
  border-radius: 50%;
  background: var(--bg);
  transition: inset-inline-start .15s ease;
}
.bp-form__switch:checked { background: var(--brand); }
.bp-form__switch:checked::after { inset-inline-start: calc(100% - 1.25rem); }

/* A unit that belongs to the field, not to the value. Rendered as a
   pseudo-element so it can never be typed into or submitted. */
[data-bp-affix] { padding-inline-end: 3rem; }

@media (prefers-reduced-motion: reduce) {
  .bp-form__switch,
  .bp-form__switch::after { transition: none; }
}

/* ═══════════════════════════════════ doc 14.4 controls — the enhancements
   Every rule here decorates a control that already worked. Nothing below
   hides the underlying element: with `form-controls.js` blocked the select is
   a select, the tag field is a text box and the signature is a file input. */

.bp-combobox { display: grid; gap: .25rem; }
.bp-combobox__search { inline-size: 100%; }
.bp-combobox.is-empty .bp-combobox__search { border-color: #b45309; }

.bp-tags { display: grid; gap: .375rem; }
.bp-tags__list { display: flex; flex-wrap: wrap; gap: .25rem; }
.bp-tags__list:empty { display: none; }

.bp-strength {
  block-size: .3125rem;
  border-radius: 999px;
  background: rgba(127, 127, 127, .2);
  overflow: hidden;
  margin-block-start: .375rem;
}
.bp-strength span { display: block; block-size: 100%; inline-size: 0; }
.bp-strength[data-level="0"] span { background: #dc2626; }
.bp-strength[data-level="1"] span { background: #ea580c; }
.bp-strength[data-level="2"] span { background: #d97706; }
.bp-strength[data-level="3"] span { background: #65a30d; }
.bp-strength[data-level="4"] span { background: #16a34a; }
.bp-strength__word { display: block; font-size: .75rem; opacity: .8; }

/* Wide-spaced digits, because a one-time code is read back character by
   character and a proportional font makes 1 and 7 the same width. */
.bp-form__otp {
  font-family: ui-monospace, "Courier New", monospace;
  letter-spacing: .5em;
  text-align: center;
  font-size: 1.25rem;
}

.bp-upload__preview {
  display: block;
  max-inline-size: 12rem;
  max-block-size: 9rem;
  margin-block-start: .5rem;
  border-radius: .5rem;
  object-fit: cover;
}

.bp-signature {
  display: block;
  inline-size: 100%;
  max-inline-size: 32rem;
  aspect-ratio: 3 / 1;
  border: 1px dashed rgba(127, 127, 127, .5);
  border-radius: .5rem;
  background: #fff;
  touch-action: none;   /* or a finger scrolls the page instead of drawing */
  cursor: crosshair;
}
.bp-signature__clear {
  margin-block: .375rem;
  border: 0;
  background: none;
  color: inherit;
  font-size: .8125rem;
  text-decoration: underline;
  cursor: pointer;
}

/* The composites the engine renders as a `MultiWidget`: two or five inputs
   that belong together and must not read as unrelated fields stacked. Keyed
   off a class the field puts there, never off `name$="_0"` — that suffix is
   also a perfectly ordinary field key somebody may have chosen. */
/* The row becomes a flex line *because* it holds parts. Setting a width on
   the part alone loses: `.form-control` from the theme is loaded after this
   file and sets `inline-size: 100%` at the same specificity, so every half of
   a range stacked full-width — which is exactly what the first browser run
   showed. Laying them out from the row sidesteps the fight entirely. */
.bp-form__row:has(.bp-form__part) {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
  align-items: flex-end;
}
.bp-form__row:has(.bp-form__part) > label,
.bp-form__row:has(.bp-form__part) > .bp-form__help,
.bp-form__row:has(.bp-form__part) > .bp-form__error { flex: 1 0 100%; }
.bp-form__part { flex: 1 1 8rem; min-inline-size: 6rem; }
