/*
 * sd-field — form fields of the reference field set (Blueprint 5.30.1): text, email, tel, select, textarea,
 *            checkbox, radio, consent checkbox, file upload; form layout and error summary (sd-form)
 * Core sample Session 2.2; complete Session 2.3.
 * States: default, hover, focus-visible, disabled, error (colour + icon + text; Blueprint 3.13), success via sd-notice
 * Visible label; required marker in text; help and error tied with aria-describedby (WCAG 3.3.1, 3.3.2).
 */

.sd-field {
  display: grid;
  align-content: start;  /* a taller neighbour in sd-form__row (help text) must not stretch the control (Session 4.1b) */
  gap: var(--sd-space-2);
  max-width: 32rem;
}

.sd-field__label {
  font-size: var(--sd-font-size-ui);
  font-weight: var(--sd-font-weight-medium);
  line-height: var(--sd-line-height-ui);
  color: var(--sd-color-text-default);
}

.sd-field__required {
  margin-left: var(--sd-space-1);
  font-weight: var(--sd-font-weight-regular);
  color: var(--sd-color-text-muted);
}

.sd-field__help {
  font-size: var(--sd-font-size-small);
  line-height: var(--sd-line-height-small);
  color: var(--sd-color-text-muted);
}

.sd-field__control {
  width: 100%;
  min-height: 3rem;  /* 48 */
  padding: 0.75rem var(--sd-space-3);
  border: var(--sd-border-width) solid var(--sd-color-border-control);
  border-radius: var(--sd-radius-sm);
  background: var(--sd-color-surface);
  color: var(--sd-color-text-default);
  font-size: 1rem;   /* ≥ 16px: no zoom on iOS focus */
  line-height: var(--sd-line-height-ui);
  transition: border-color var(--sd-transition-feedback), box-shadow var(--sd-transition-feedback);
}

.sd-field__control::placeholder { color: var(--sd-color-text-muted); opacity: 1; }

.sd-field__control:hover,
.sd-field__control[data-state="hover"] { border-color: var(--sd-color-text-default); }

/* Focus: copper ring + blue border (two signals) */
.sd-field__control:focus-visible,
.sd-field__control[data-state="focus"] {
  outline: var(--sd-focus-ring-width) solid var(--sd-focus-ring-color);
  outline-offset: var(--sd-focus-ring-offset);
  border-color: var(--sd-color-border-strong);
}

.sd-field__control:disabled {
  background: var(--sd-color-surface-disabled);
  border-color: var(--sd-color-border-subtle);
  color: var(--sd-color-text-disabled);
  cursor: not-allowed;
}

/* Error: red border (2px) + icon + message text */
.sd-field--error .sd-field__control {
  border-color: var(--sd-color-error-text);
  box-shadow: inset 0 0 0 1px var(--sd-color-error-text);
}

.sd-field__error {
  display: flex;
  align-items: flex-start;
  gap: var(--sd-space-2);
  font-size: var(--sd-font-size-small);
  line-height: var(--sd-line-height-small);
  font-weight: var(--sd-font-weight-medium);
  color: var(--sd-color-error-text);
}

.sd-field__error svg {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  margin-top: 0.1em;
}


/* ---------- Select (native element, custom chevron) ---------- */

.sd-field__select {
  appearance: none;
  padding-right: 2.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23002F6C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  background-size: 1.25rem;
  cursor: pointer;
}

.sd-field__select:disabled {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A7AEB4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* ---------- Textarea ---------- */

.sd-field__textarea {
  min-height: 9rem;
  resize: vertical;
  line-height: var(--sd-line-height-body);
}

/* ---------- Checkbox and radio (native input, custom box; label is the target) ---------- */

.sd-check {
  position: relative;
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  align-items: start;
  gap: var(--sd-space-3);
  min-height: var(--sd-target-min);
  padding-block: 0.625rem;
  font-size: var(--sd-font-size-ui);
  line-height: var(--sd-line-height-small);
  cursor: pointer;
}

.sd-check__input {
  appearance: none;
  display: grid;
  place-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  border: var(--sd-border-width-strong) solid var(--sd-color-border-control);
  border-radius: var(--sd-radius-sm);
  background: var(--sd-color-surface);
  cursor: pointer;
  transition: background-color var(--sd-transition-feedback), border-color var(--sd-transition-feedback);
}

/* Radio: round box (the whole label row, min 44px high, is the target) */
.sd-check__input[type="radio"] { border-radius: 50%; }

.sd-check__input::before {
  content: "";
  width: 0.875rem;
  height: 0.875rem;
  transform: scale(0);
  transition: transform var(--sd-transition-feedback);
  background: var(--sd-color-white);
  clip-path: polygon(14% 52%, 0 66%, 38% 100%, 100% 22%, 86% 8%, 37% 70%);
}

.sd-check__input[type="radio"]::before {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  clip-path: none;
}

.sd-check:hover .sd-check__input,
.sd-check[data-state="hover"] .sd-check__input { border-color: var(--sd-color-text-default); }

.sd-check__input:checked {
  border-color: var(--sd-color-action-primary);
  background: var(--sd-color-action-primary);
}

.sd-check__input:checked::before { transform: scale(1); }

.sd-check__input:focus-visible,
.sd-check[data-state="focus"] .sd-check__input {
  outline: var(--sd-focus-ring-width) solid var(--sd-focus-ring-color);
  outline-offset: var(--sd-focus-ring-offset);
}

.sd-check__input:disabled {
  border-color: var(--sd-color-border-subtle);
  background: var(--sd-color-surface-disabled);
  cursor: not-allowed;
}

.sd-check:has(.sd-check__input:disabled) {
  color: var(--sd-color-text-disabled);
  cursor: not-allowed;
}

.sd-check__input:disabled:checked { background: var(--sd-color-gray-400); border-color: var(--sd-color-gray-400); }

.sd-check__text { padding-top: 0.0625rem; }

/* Group of options: fieldset + legend (WCAG 1.3.1) */
.sd-fieldset {
  display: grid;
  gap: var(--sd-space-1);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.sd-fieldset__legend {
  margin-bottom: var(--sd-space-1);
  padding: 0;
  font-size: var(--sd-font-size-ui);
  font-weight: var(--sd-font-weight-medium);
  color: var(--sd-color-text-default);
}

.sd-fieldset--inline .sd-fieldset__options {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--sd-space-5);
}

.sd-field--error .sd-check__input { border-color: var(--sd-color-error-text); }

/* Consent checkbox: required, not pre-checked, links to the Privacy Policy (Blueprint 5.30.1, 18.33) */
.sd-check--consent {
  max-width: 40rem;
  padding: var(--sd-space-3);
  border: var(--sd-border-width) solid var(--sd-color-border-subtle);
  border-radius: var(--sd-radius-sm);
  background: var(--sd-color-surface-subtle);
}

.sd-check--consent a { position: relative; z-index: 1; }

/* ---------- File upload (warranty claim photos, if confirmed in 8.1b) ---------- */

.sd-file {
  display: grid;
  gap: var(--sd-space-2);
  justify-items: start;
  max-width: 32rem;
  padding: var(--sd-space-4);
  border: var(--sd-border-width) dashed var(--sd-color-border-control);
  border-radius: var(--sd-radius-sm);
  background: var(--sd-color-surface);
}

.sd-file__input {
  width: 100%;       /* no intrinsic overflow at 320px (WCAG 1.4.10) */
  max-width: 100%;
  font-size: var(--sd-font-size-small);
  color: var(--sd-color-text-muted);
}

.sd-file__input::file-selector-button {
  min-height: var(--sd-target-min);
  margin-right: var(--sd-space-3);
  padding: 0 var(--sd-space-4);
  border: var(--sd-border-width-strong) solid var(--sd-color-action-primary);
  border-radius: var(--sd-radius-md);
  background: var(--sd-color-surface);
  color: var(--sd-color-action-primary);
  font: inherit;
  font-weight: var(--sd-font-weight-medium);
  cursor: pointer;
}

.sd-file__input::file-selector-button:hover { background: var(--sd-color-action-secondary-hover-bg); }

/* ---------- Form layout ---------- */

.sd-form {
  display: grid;
  gap: var(--sd-space-5);
  max-width: 48rem;
}

.sd-form__row {
  display: grid;
  gap: var(--sd-space-5);
}

@media (min-width: 640px) {
  .sd-form__row { grid-template-columns: 1fr 1fr; }
}

.sd-form__row .sd-field { max-width: none; }
.sd-field--wide { max-width: none; }  /* full form width: long text areas (Session 4.1b) */

.sd-form__group-title {
  padding-top: var(--sd-space-3);
  border-top: var(--sd-border-width) solid var(--sd-color-border-subtle);
  font-size: var(--sd-font-size-h4);
  line-height: var(--sd-line-height-h4);
  font-weight: var(--sd-font-weight-medium);
  color: var(--sd-color-text-heading);
}

.sd-form__note {
  font-size: var(--sd-font-size-small);
  color: var(--sd-color-text-muted);
}

/* Attached service or product (sd-notice inside the form; moved here from the prototype pages, Session 6.3) */
.sd-form__context { margin-bottom: var(--sd-space-5); }

/* Error summary: shown at the top after a failed submit; receives focus; links to each field */
.sd-error-summary {
  display: grid;
  gap: var(--sd-space-2);
  max-width: 40rem;
  padding: var(--sd-space-4);
  border: var(--sd-border-width-strong) solid var(--sd-color-error-text);
  border-radius: var(--sd-radius-sm);
  background: var(--sd-color-error-bg);
}

.sd-error-summary:focus-visible { outline-offset: 3px; }

.sd-error-summary__title {
  display: flex;
  align-items: center;
  gap: var(--sd-space-2);
  font-size: var(--sd-font-size-body);
  font-weight: var(--sd-font-weight-semibold);
  color: var(--sd-color-error-text);
}

.sd-error-summary__title svg { width: 1.25rem; height: 1.25rem; flex: none; }

.sd-error-summary ul { margin: 0; padding-left: 1.25rem; }
.sd-error-summary a { color: var(--sd-color-error-text); font-weight: var(--sd-font-weight-medium); }
