/* =================================================================
   Forms — labels, inputs, selects, textareas, file uploads, signature pads
   ================================================================= */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.form-row {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.form-section {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--elev-1);
}
.form-section + .form-section { margin-top: var(--sp-6); }

.form-section__title {
  font-family: var(--font-display);
  font-size: var(--fs-20);
  margin: 0 0 var(--sp-1);
  color: var(--text-primary);
}
.form-section__subtitle {
  color: var(--text-muted);
  font-size: var(--fs-14);
  margin: 0 0 var(--sp-5);
}

.form-label {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-weight: 600;
  font-size: var(--fs-14);
  color: var(--text-primary);
}
.form-label__hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: var(--fs-12);
}
.form-label--required::after {
  content: "*";
  color: var(--danger-500);
  margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: var(--fs-16);
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  transition:
    border-color var(--motion-fast) var(--ease-standard),
    box-shadow var(--motion-fast) var(--ease-standard),
    background var(--motion-fast) var(--ease-standard);
  appearance: none;
  -webkit-appearance: none;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: var(--border-strong);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: 0;
  border-color: var(--rose-500);
  box-shadow: 0 0 0 4px rgba(201, 104, 90, 0.14);
  background: #fff;
}

.form-input[aria-invalid="true"],
.form-select[aria-invalid="true"],
.form-textarea[aria-invalid="true"] {
  border-color: var(--danger-500);
  background: var(--danger-50);
}
.form-input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.14); }

.form-textarea { min-height: 100px; resize: vertical; line-height: var(--lh-normal); }

.form-select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.5rem;
}

.form-help {
  color: var(--text-muted);
  font-size: var(--fs-12);
}

.form-error {
  color: var(--danger-700);
  font-size: var(--fs-12);
  font-weight: 600;
}

.form-actions {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-6);
}

/* Checkbox + radio */
.checkbox, .radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  cursor: pointer;
  padding: var(--sp-1) 0;
  user-select: none;
}
.checkbox input[type="checkbox"],
.radio input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--rose-600);
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}
.checkbox span, .radio span { font-size: var(--fs-14); line-height: 1.4; }

/* Categorical multi-select chips */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.5rem 0.85rem;
  font-size: var(--fs-14);
  font-weight: 500;
  background: var(--surface-card);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: all var(--motion-fast) var(--ease-standard);
}
.chip:hover { border-color: var(--rose-300); background: var(--rose-50); }
.chip input { display: none; }
.chip:has(input:checked) {
  background: linear-gradient(135deg, var(--mauve-800), var(--berry-600));
  color: var(--text-inverse);
  border-color: var(--mauve-800);
  box-shadow: var(--elev-1);
}

/* File / drag-drop dropzone */
.dropzone {
  border: 2px dashed var(--border-default);
  border-radius: var(--r-lg);
  padding: var(--sp-8) var(--sp-6);
  text-align: center;
  background: var(--surface-sunken);
  transition: all var(--motion-fast) var(--ease-standard);
}
.dropzone:hover, .dropzone--active {
  border-color: var(--rose-400);
  background: var(--rose-50);
}

/* Signature pad */
.signature-pad {
  position: relative;
  border: 2px solid var(--border-default);
  border-radius: var(--r-lg);
  background: var(--surface-card);
  height: 180px;
  overflow: hidden;
}
.signature-pad canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}
.signature-pad__hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  pointer-events: none;
  font-size: var(--fs-14);
  font-style: italic;
}
.signature-pad--has-content .signature-pad__hint { display: none; }
.signature-pad__clear {
  position: absolute;
  bottom: var(--sp-2);
  right: var(--sp-2);
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  padding: 0.25rem 0.5rem;
  font-size: var(--fs-12);
  cursor: pointer;
}

/* Inline group — search + button */
.input-group {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.input-group .form-input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}
.input-group .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* =================================================================
   Radio-card grid error state — used by the public requirements wizard.
   Replaces the previous native alert(). Three pieces:
   1) Inline error text (uses .form-error tokens) with icon-aligned layout.
   2) A soft danger ring around the grid so the cause is obvious.
   3) A short shake on first render of the error, gated for reduced-motion.
   ================================================================= */
.wizard-step__error {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-3) 0 0;
  padding: var(--sp-2) var(--sp-3);
  background: var(--danger-50);
  border: 1px solid rgba(220, 38, 38, 0.18);
  border-radius: var(--r-md);
}
.wizard-step__error svg { flex-shrink: 0; color: var(--danger-700); }

.option-grid[data-error="true"] {
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
  animation: option-grid-shake var(--motion-medium) var(--ease-emphasized);
}
@keyframes option-grid-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .option-grid[data-error="true"] { animation: none; }
}
