/* =========================================================================
   forms.css — form controls (spec 3.12, 4.7)
   Inline validation, server-error display, required indicator, sections.
   ========================================================================= */

.field { display: grid; gap: var(--space-2); min-width: 0; }
.field__label { font-size: var(--font-size-sm); font-weight: 750; color: var(--ink-soft); display: flex; align-items: center; gap: var(--space-1); }
.field__req { color: var(--status-danger); font-weight: 900; }
.field__help { font-size: var(--font-size-xs); color: var(--muted); }
.field__error { font-size: var(--font-size-xs); color: var(--status-danger-ink); font-weight: 700; display: none; }

.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: #fff; color: var(--ink); font: inherit; font-size: var(--control-font);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.textarea { height: auto; min-height: 6rem; padding: var(--space-3); resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 0; border-color: var(--status-info); box-shadow: 0 0 0 3px rgba(47,117,224,.14); }
.input::placeholder { color: var(--muted-2); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2374849a' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--space-3) center; padding-right: var(--space-8); }

/* Invalid state — toggled by the JS validator or server render */
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--status-danger); box-shadow: 0 0 0 3px rgba(224,79,95,.14); }
.field.is-invalid .field__error { display: block; }

/* Number / quantity input with steppers */
.qty-input { display: grid; grid-template-columns: var(--control-h) 1fr var(--control-h); align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--radius-md); overflow: hidden; background: #fff; }
.qty-input button { border: 0; background: var(--surface-muted); color: var(--ink-soft); font-size: 1.25rem; font-weight: 800; }
.qty-input button:hover { background: var(--surface-sunken); }
.qty-input input { border: 0; outline: 0; text-align: center; font: inherit; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Checkbox + switch */
.checkbox { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border-color); border-radius: var(--radius-md); background: #fff; cursor: pointer; }
.checkbox--fill { flex: 1 1 9rem; min-width: 9rem; }
.checkbox input { width: 1.3rem; height: 1.3rem; margin-top: 1px; accent-color: var(--brand); flex: none; }
.checkbox__text b { display: block; font-size: var(--font-size-sm); }
.checkbox__text span { font-size: var(--font-size-xs); color: var(--muted); }
/* Anti-tampering checkbox highlight (spec 3.8) */
.checkbox--critical { border-color: rgba(47,117,224,.35); background: var(--status-info-soft); }

.switch { width: 2.6rem; height: 1.5rem; border-radius: var(--radius-pill); background: var(--border-strong); position: relative; flex: none; border: 0; padding: 0; transition: background .15s ease; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s ease; }
.switch[aria-checked="true"] { background: var(--brand); }
.switch[aria-checked="true"]::after { transform: translateX(1.1rem); }

/* Form sections (spec 4.7) */
.form-section { border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.form-section__head { padding: var(--space-3) var(--space-4); background: var(--surface-muted); border-bottom: 1px solid var(--border-color); font-weight: 800; font-size: var(--font-size-sm); display: flex; align-items: center; gap: var(--space-2); }
.form-section__head svg { width: 1.1rem; height: 1.1rem; color: var(--muted); flex: none; }
.form-section__body { padding: var(--space-4); }

/* Form-level error summary */
.form-errors { border: 1px solid rgba(224,79,95,.3); background: var(--status-danger-soft); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); color: var(--status-danger-ink); font-size: var(--font-size-sm); }
.form-errors ul { margin-top: var(--space-1); padding-left: var(--space-4); list-style: disc; }
