/* ============================================================================
 * form.css — shared form-widget styling for the 3 owned forms (contatti,
 * farmacovigilanza, lavora-con-noi). Targets the BEM classes already on the
 * form markup (`.contact-form__input`, `__textarea`, `__consent`, `__submit`, …
 * — see src/pages/contatti.php) rather than re-deriving new class names, so the
 * same stylesheet styles all three forms' fields without per-page overrides.
 *
 * PROVENANCE: docs/design-baseline/contatti-body.demo.html's <form> inputs —
 * STYLING only (rounded-lg border-border bg-card px-4 py-3 text-[13px], focus
 * ring, primary submit button). The demo's own field set (Nome completo/
 * Oggetto) is wrong and NOT reproduced — our forms keep their real CF7 fields;
 * this file only restyles them. base.css must load before this file (tokens,
 * preflight); loads after content.css (form cards live inside content cards).
 * ============================================================================ */

.contact-form {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.contact-form__row {
  display: grid;
  gap: 1rem;
}

.contact-form__field {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

/* Visually-hidden label: the demo's inputs carry no visible label (placeholder-
 * driven), but our markup keeps a real <label> for accessibility/autofill —
 * matched to the demo look without losing the association. */
.contact-form__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.contact-form__input,
.contact-form__textarea,
select.contact-form__input,
input[type="file"].contact-form__input {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  padding: .75rem 1rem;
  font-family: var(--font-body);
  font-size: 13px;
  color: hsl(var(--foreground));
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.contact-form__input::placeholder,
.contact-form__textarea::placeholder {
  color: hsl(var(--muted-foreground) / .5);
}
.contact-form__input:focus,
.contact-form__textarea:focus,
select.contact-form__input:focus,
input[type="file"].contact-form__input:focus {
  border-color: hsl(var(--primary));
  box-shadow: 0 0 0 2px hsl(var(--primary) / .2);
}

.contact-form__textarea {
  resize: none;
}

/* select carries its own affordance; keep the same field chrome as inputs */
select.contact-form__input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23949cb8' 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 1rem center;
  background-size: 1rem;
  padding-right: 2.5rem;
}

/* file input (CV upload, lavora-con-noi): keep the same field chrome, style
 * the native chooser button to match the primary submit's weight */
input[type="file"].contact-form__input {
  padding: .625rem 1rem;
  font-size: 12px;
}
input[type="file"].contact-form__input::file-selector-button {
  margin-right: .75rem;
  border: 0;
  border-radius: calc(var(--radius) - .25rem);
  background: hsl(var(--primary) / .1);
  padding: .5rem .875rem;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: hsl(var(--primary));
  cursor: pointer;
  transition: background-color .15s;
}
input[type="file"].contact-form__input::file-selector-button:hover {
  background: hsl(var(--primary) / .15);
}

.contact-form__field--consent {
  margin-top: .25rem;
}

.contact-form__consent {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  cursor: pointer;
  user-select: none;
}
.contact-form__consent input[type="checkbox"] {
  margin-top: .125rem;
  height: 1rem;
  width: 1rem;
  flex-shrink: 0;
  border-radius: .25rem;
  border: 1px solid hsl(var(--border));
  accent-color: hsl(var(--primary));
}
.contact-form__consent span {
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.6;
  color: hsl(var(--muted-foreground));
}
.contact-form__privacy-link {
  font-weight: 500;
  color: hsl(var(--primary));
  text-decoration: none;
}
.contact-form__privacy-link:hover {
  text-decoration: underline;
}

.contact-form__note {
  margin: 0;
  font-family: var(--font-body);
  font-size: 11px;
  color: hsl(var(--muted-foreground));
}

.contact-form__actions {
  margin-top: .25rem;
}

.contact-form__submit {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border-radius: var(--radius);
  background: hsl(var(--primary));
  padding: .875rem 1.5rem;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: hsl(var(--primary-foreground));
  box-shadow: var(--shadow-md);
  transition: box-shadow .15s, filter .15s;
}
.contact-form__submit:hover {
  box-shadow: var(--shadow-lg);
  filter: brightness(1.1);
}
.contact-form__submit:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.contact-form__submit svg {
  height: .875rem;
  width: .875rem;
}

/* sm: >= 640px — paired fields (nome/cognome, email/telefono) go side by side */
@media (min-width: 640px) {
  .contact-form__row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ============================================================================
 * Multi-step + AJAX enhancement states (src/assets/form.js, Trello tLQv9qfM).
 * All of these only take effect once form.js runs; the no-JS baseline never
 * carries these hooks (every step stays visible, nothing is marked invalid).
 * Colours are literal here — base.css ships no destructive/success token.
 * ============================================================================ */

/* Stepper: form.js toggles the `hidden` attribute on each step fieldset. The UA
 * default already hides [hidden]; this just guarantees it against any later
 * `fieldset { display: … }` rule and resets the fieldset's own box. */
.contact-form__step[hidden] {
  display: none;
}
.contact-form__step {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0; /* fieldset default min-width:min-content breaks the grid rows */
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
/* The step fieldset gets tabindex=-1 so focus can land on it after a step change;
 * suppress the focus ring since it's a programmatic, non-interactive target. */
.contact-form__step:focus {
  outline: none;
}

/* Feedback region: hidden until form.js reveals it with a success/error message. */
.contact-form__feedback {
  border-radius: var(--radius);
  padding: .875rem 1rem;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
}
.contact-form__feedback[hidden] {
  display: none;
}
.contact-form__feedback:focus {
  outline: none;
}
.contact-form__feedback--success {
  border: 1px solid hsl(152 45% 42% / .35);
  background: hsl(152 55% 96%);
  color: hsl(152 60% 24%);
}
.contact-form__feedback--error {
  border: 1px solid hsl(0 72% 51% / .35);
  background: hsl(0 80% 97%);
  color: hsl(0 65% 40%);
}

/* On a successful submit form.js adds this class and disables every control; hide
 * all the form's own children except the feedback banner (which is a direct child
 * of the <form>, sibling to the step fieldsets/actions) so the confirmation stands
 * alone with no re-submittable fields left. */
.contact-form--sent > *:not(.contact-form__feedback) {
  display: none;
}

/* Inline per-field validation (server `errors` map): mark the control and show its
 * message beneath it. */
.contact-form__input.is-invalid,
.contact-form__textarea.is-invalid,
select.contact-form__input.is-invalid,
input[type="file"].contact-form__input.is-invalid {
  border-color: hsl(0 72% 51%);
  box-shadow: 0 0 0 2px hsl(0 72% 51% / .18);
}
.contact-form__error {
  margin: 0;
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.4;
  color: hsl(0 65% 45%);
}

/* Sending state: form.js sets aria-busy + "Invio in corso…" and disables the
 * button (the :disabled rule above already dims it); nudge the cursor to match. */
.contact-form__submit[aria-busy="true"] {
  cursor: progress;
}
