/* ============================================================================
 * Form system — enterprise, minimal, accessible.
 *
 *   .wb-form                  → form wrapper (grid of fields)
 *   .wb-form-field            → label + control + helper/error stack
 *   .wb-label                 → text label
 *   .wb-label__required       → asterisk
 *   .wb-input | wb-textarea | wb-select  → control surfaces (override _base.css forms)
 *   .wb-checkbox | wb-radio   → bespoke control containers
 *   .wb-form-help             → muted helper text
 *   .wb-form-error            → validation error text
 *
 * States: .is-invalid, .is-valid set on the wrapper or control.
 * ========================================================================== */

.wb-form {
  display: grid;
  gap: var(--wb-space-5);
}
.wb-form--inline {
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: end;
}
@media (max-width: 768px) {
  .wb-form--inline {
    grid-auto-flow: row;
    grid-auto-columns: auto;
  }
}

.wb-form-row {
  display: grid;
  gap: var(--wb-space-5);
}
@media (min-width: 768px) {
  .wb-form-row--2 { grid-template-columns: 1fr 1fr; }
  .wb-form-row--3 { grid-template-columns: repeat(3, 1fr); }
}

.wb-form-field {
  display: flex;
  flex-direction: column;
  gap: var(--wb-space-2);
  min-width: 0;
}

.wb-label {
  font-size: var(--wb-text-sm);
  font-weight: var(--wb-fw-medium);
  color: var(--wb-color-ink-2);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--wb-space-1);
}
.wb-label__required {
  color: var(--wb-color-danger);
  font-weight: var(--wb-fw-semibold);
}

/* Controls ----------------------------------------------------------------- */
.wb-input,
.wb-textarea,
.wb-select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--wb-font-sans);
  font-size: var(--wb-text-base);
  line-height: var(--wb-lh-snug);
  color: var(--wb-color-ink);
  background: var(--wb-color-surface);
  border: var(--wb-border-width) solid var(--wb-color-border);
  border-radius: var(--wb-radius-md);
  appearance: none;
  -webkit-appearance: none;
  transition:
    border-color var(--wb-duration-base) var(--wb-ease),
    box-shadow var(--wb-duration-base) var(--wb-ease),
    background-color var(--wb-duration-base) var(--wb-ease);
}
.wb-input::placeholder,
.wb-textarea::placeholder { color: var(--wb-color-text-soft); }

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

.wb-input:focus,
.wb-textarea:focus,
.wb-select:focus {
  outline: 0;
  border-color: var(--wb-color-brand);
  box-shadow: 0 0 0 4px var(--wb-color-focus-ring);
}

.wb-input:disabled,
.wb-textarea:disabled,
.wb-select:disabled {
  background: var(--wb-color-bg-soft);
  color: var(--wb-color-text-muted);
  cursor: not-allowed;
}

.wb-textarea { min-height: 7.5rem; resize: vertical; }

/* Select caret */
.wb-select {
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.5rem;
}

/* Input with leading/trailing slot ----------------------------------------- */
.wb-input-group {
  position: relative;
  display: flex;
  align-items: stretch;
}
.wb-input-group .wb-input { flex: 1 1 0; }
.wb-input-group__addon {
  display: inline-flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--wb-color-bg-soft);
  border: var(--wb-border-width) solid var(--wb-color-border);
  color: var(--wb-color-text-muted);
  font-size: var(--wb-text-sm);
}
.wb-input-group__addon:first-child {
  border-right: 0;
  border-radius: var(--wb-radius-md) 0 0 var(--wb-radius-md);
}
.wb-input-group__addon:last-child {
  border-left: 0;
  border-radius: 0 var(--wb-radius-md) var(--wb-radius-md) 0;
}
.wb-input-group .wb-input:not(:first-child) {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.wb-input-group .wb-input:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

/* Checkbox / Radio --------------------------------------------------------- */
.wb-check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--wb-space-3);
  cursor: pointer;
  font-size: var(--wb-text-sm);
  color: var(--wb-color-text);
}
.wb-check input[type="checkbox"],
.wb-check input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin: 1px 0 0;
  padding: 0;
  background: var(--wb-color-surface);
  border: var(--wb-border-width) solid var(--wb-color-border-strong);
  border-radius: var(--wb-radius-xs);
  transition:
    background-color var(--wb-duration-fast) var(--wb-ease),
    border-color var(--wb-duration-fast) var(--wb-ease);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}
.wb-check input[type="radio"] { border-radius: 50%; }

.wb-check input[type="checkbox"]:checked,
.wb-check input[type="radio"]:checked {
  background: var(--wb-color-brand);
  border-color: var(--wb-color-brand);
}
.wb-check input[type="checkbox"]:checked::before {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
}
.wb-check input[type="radio"]:checked::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}
.wb-check input:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 4px var(--wb-color-focus-ring);
}

/* Helper + error ----------------------------------------------------------- */
.wb-form-help {
  font-size: var(--wb-text-xs);
  color: var(--wb-color-text-muted);
  margin: 0;
}
.wb-form-error {
  font-size: var(--wb-text-xs);
  color: var(--wb-color-danger);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--wb-space-1);
}

/* States ------------------------------------------------------------------- */
.wb-form-field.is-invalid .wb-input,
.wb-form-field.is-invalid .wb-textarea,
.wb-form-field.is-invalid .wb-select,
.wb-input.is-invalid,
.wb-textarea.is-invalid,
.wb-select.is-invalid {
  border-color: var(--wb-color-danger);
}
.wb-form-field.is-invalid .wb-input:focus,
.wb-input.is-invalid:focus {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--wb-color-danger) 25%, transparent);
}

.wb-form-field.is-valid .wb-input,
.wb-input.is-valid { border-color: var(--wb-color-success); }

/* Fieldset / legend -------------------------------------------------------- */
.wb-fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--wb-space-3);
}
.wb-fieldset__legend {
  font-size: var(--wb-text-sm);
  font-weight: var(--wb-fw-semibold);
  color: var(--wb-color-ink);
  padding: 0;
}
