/* ============================================================
   components/field.css — .dd-field (branded form fields)
   Floating-label text/email/number/tel inputs + textarea, a mono
   hint slot, and inline validation (error/success) with an icon.
   Select chrome lives here too; the listbox behavior is select.css.

   Markup (see partials/_form_field.html): the control comes BEFORE
   the label so the floating-label adjacency (control + label) works
   with the empty `placeholder=" "` the DdFormMixin sets.

   Token-only; focus ring via --focus-ring; all motion gated by
   prefers-reduced-motion.
   ============================================================ */

.dd-field {
  position: relative;
  margin-bottom: var(--space-6);
  text-align: left;
}
.dd-field:last-child { margin-bottom: 0; }

/* ---- honeypot decoy (HoneypotMixin) ------------------------------- */
/* Pulled off-screen rather than display:none so simple bots still see &
   fill it; the wrapper is aria-hidden + the input is tabindex=-1, so real
   users (incl. screen-reader / keyboard) never reach it. */
.dd-hp {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- radio / checkbox group (fieldset) ---------------------------- */
/* Strip the UA <fieldset> chrome (groove border + legend notch) that
   otherwise makes a radio group look like a 2000s form, and give the
   group real breathing room. */
.dd-field--radio {
  border: 0;
  padding: 0;
  margin-block: 0 var(--space-6);
  min-inline-size: 0;
}

.dd-field__legend {
  display: block;
  float: none;
  width: 100%;
  padding: 0;
  margin-bottom: var(--space-4);
  font-size: var(--fs-small);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--text-soft);
}

/* Roomier stack than the default choice group, and a little vertical
   padding per option so the controls aren't cramped together. */
.dd-field--radio .dd-choice-group {
  gap: var(--space-4);
}
.dd-field--radio .dd-choice {
  padding-block: var(--space-1);
}

/* The control wraps the input + its floating label so the label can
   be positioned relative to the input it describes. */
.dd-field__control {
  position: relative;
}

/* ---- the input / textarea / select face --------------------------- */
.dd-field__input {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--fs-body);
  color: var(--text);
  background: var(--surface-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  /* extra top padding leaves room for the floated label */
  padding: calc(var(--space-5) + 2px) var(--space-5) var(--space-3);
  line-height: var(--lh-snug);
  transition: border-color var(--dur-base) var(--ease-soft),
              background-color var(--dur-base) var(--ease-soft),
              box-shadow var(--dur-base) var(--ease-soft);
  appearance: none;
  -webkit-appearance: none;
}

.dd-field__input::placeholder {
  /* The placeholder is the floating-label trick's empty space — keep it
     invisible so only the <label> reads as the field name. */
  color: transparent;
}

.dd-field__input:hover {
  border-color: var(--coral-200);
}

.dd-field__input:focus {
  outline: none;
  border-color: var(--focus-ring);
  background: var(--paper);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus-ring) 22%, transparent);
}

/* textarea sizing */
textarea.dd-field__input {
  min-height: 7.5em;
  resize: vertical;
}

/* ---- floating label ----------------------------------------------- */
.dd-field__label {
  position: absolute;
  left: var(--space-5);
  top: 50%;
  transform: translateY(-50%);
  transform-origin: left center;
  max-width: calc(100% - var(--space-8));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  color: var(--text-muted);
  font-size: var(--fs-body);
  /* Matches the input's line-height, for two reasons. `overflow: hidden`
     is load-bearing here (it is what makes text-overflow: ellipsis work
     on a long label), and it clips the padding box — so at line-height 1
     the line box is shorter than Inter's content area and every
     descender loses its tail: "messa_g_e." and "_p_hone." came out
     shaved (#119). It also lines the resting textarea label up with the
     textarea's own first line, which carries the same leading. */
  line-height: var(--lh-snug);
  padding-inline: var(--space-1);
  background: transparent;
  transition: top var(--dur-base) var(--ease-dreamy),
              color var(--dur-base) var(--ease-soft),
              font-size var(--dur-base) var(--ease-dreamy),
              transform var(--dur-base) var(--ease-dreamy);
}

/* textarea label anchors to the top, not the vertical centre */
textarea.dd-field__input + .dd-field__label {
  top: calc(var(--space-5) + 2px);
  transform: none;
}

/* Float the label up on focus or when the control has content.
   `:not(:placeholder-shown)` is true once the user types (the empty
   placeholder=" " makes an untouched field read as placeholder-shown). */
.dd-field__input:focus + .dd-field__label,
.dd-field__input:not(:placeholder-shown) + .dd-field__label,
.dd-field--filled .dd-field__label {
  top: 0;
  transform: translateY(-50%) scale(0.82);
  font-size: var(--fs-body);
  color: var(--text-muted);
  background: var(--surface-tint);
  border-radius: var(--radius-pill);
}
.dd-field__input:focus + .dd-field__label {
  color: var(--link);
}

/* Selects always hold a value → keep the label floated. */
.dd-field--select .dd-field__label {
  top: 0;
  transform: translateY(-50%) scale(0.82);
  background: var(--surface-tint);
  border-radius: var(--radius-pill);
}

/* required marker */
.dd-field__req {
  color: var(--accent-strong);
}

/* ---- select chrome ------------------------------------------------- */
/* A standalone native <select> (no JS enhancement) still gets a chevron
   and hides the default OS arrow. */
.dd-field--select .dd-field__control { position: relative; }
.dd-field__chevron {
  position: absolute;
  right: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  pointer-events: none;
  display: inline-flex;
}
select.dd-field__input {
  padding-right: var(--space-9);
  cursor: pointer;
}
/* leave room for the chevron on the select face */
.dd-field--select .dd-field__input { padding-right: var(--space-9); }

/* ---- file input ---------------------------------------------------- */
/* Used by the P7 mix/master intake. The native control is restyled with
   ::file-selector-button so it reads as a branded chip. */
.dd-field__input[type="file"] {
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
}
.dd-field__input[type="file"]::file-selector-button {
  font-family: var(--font-body);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-on-coral);
  background: var(--grad-coral);
  border: none;
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-5);
  margin-right: var(--space-4);
  cursor: pointer;
  transition: filter var(--dur-base) var(--ease-soft);
}
.dd-field__input[type="file"]::file-selector-button:hover { filter: brightness(0.97); }
/* file inputs have no floating label — pair with a static label above */
.dd-field--file .dd-field__label {
  position: static;
  transform: none;
  display: block;
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-2);
  background: none;
  max-width: none;
  padding-inline: 0;
}

/* ---- hint (mono tape-label micro-copy) ---------------------------- */
.dd-field__hint {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  color: var(--text-muted);
}

/* ---- inline validation -------------------------------------------- */
.dd-field__error,
.dd-field__success {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--fs-small);
  line-height: var(--lh-snug);
}
.dd-field__error { color: var(--danger); }
.dd-field__success { color: var(--success); }
.dd-field__error .dd-icon,
.dd-field__success .dd-icon {
  flex-shrink: 0;
  margin-top: 0.1em;
}

.dd-field.has-error .dd-field__input {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 5%, var(--paper));
}
.dd-field.has-error .dd-field__input:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}
.dd-field.has-error .dd-field__input:focus + .dd-field__label,
.dd-field.has-error .dd-field__input:not(:placeholder-shown) + .dd-field__label,
.dd-field.has-error.dd-field--select .dd-field__label { color: var(--danger); }

.dd-field.has-success .dd-field__input {
  border-color: var(--success);
}
.dd-field.has-success .dd-field__input:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent);
}

@media (prefers-reduced-motion: reduce) {
  .dd-field__input,
  .dd-field__label { transition: none; }
}
