/* =============================================================================
   GLASS — forms.css
   Text input, textarea, select, checkbox, radio, switch. Every declaration
   reads from src/tokens.css; this file introduces no colour, no radius, no
   duration and no font of its own — the same rule primitives.css obeys.

   .field (primitives.css) already covers <input> and is reused here for
   <textarea> and <select> rather than duplicated: same recessed plane, same
   focus ring, same :invalid → --bad border. This file adds the three controls
   that are not text — checkbox, radio, switch — plus the field-group layout
   that gives all of them a consistent label/hint/error stack.

   Requires src/tokens.css and src/primitives.css (for .field, .field-label).
   Verified by: node scripts/contrast.mjs
   ============================================================================= */

/* =============================================================================
   1. TEXTAREA & SELECT — .field, extended.
   ============================================================================= */

textarea.field {
  resize: vertical;
  min-height: calc(var(--target-min) * 3);
  line-height: var(--lh-3);
  font-family: inherit;
}

select.field {
  appearance: none;
  padding-right: calc(var(--sp-4) + var(--sp-4));
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% - 3px), calc(100% - 15px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* =============================================================================
   2. THE FIELD GROUP — label, control, hint or error, as one stack.

   .field-error is the one state a form control needs beyond what .field
   already has (:hover, :focus, :disabled). It carries the same four channels
   a .state chip does: the border goes --bad (graphic, 3:1 already asserted for
   --bad on --bg/--surface by primitives.css's ladder checks), and the message
   is read from a real text node — never colour alone.
   ============================================================================= */

.field-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.field-hint {
  margin: 0;
  font-size: var(--fs-0);
  line-height: var(--lh-2);
  color: var(--ink-2);
}

.field-error-text {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin: 0;
  font-size: var(--fs-0);
  line-height: var(--lh-2);
  color: var(--bad);
  font-weight: 550;
}

.field-error-text::before {
  content: "\2715";
  font-family: var(--font-mono);
}

.field-group:has(.field:disabled) .field-label,
.field-group:has(.field:disabled) .field-hint {
  color: var(--ink-3);
}

/* =============================================================================
   3. CHECKBOX & RADIO — one shape each, native input styled in place. Both
   use accent-color so the browser's own high-contrast/forced-colors handling
   keeps working (contrast.mjs's forced-colors block in tokens.css assumes
   this); the visible ring and hover are layered on top of that, not instead.
   ============================================================================= */

.checkbox,
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--target-min);
  font-size: var(--fs-1);
  line-height: var(--lh-2);
  color: var(--ink);
  cursor: pointer;
}

.checkbox input,
.radio input {
  appearance: none;
  margin: 0;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1px solid var(--line);
  background: var(--bg);
  accent-color: var(--accent);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  display: inline-grid;
  place-content: center;
}

.checkbox input { border-radius: 4px; }
.radio input { border-radius: var(--r-pill); }

.checkbox input::before,
.radio input::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transition: transform var(--t-fast) var(--ease);
  box-shadow: inset 1em 1em var(--on-accent);
}

.checkbox input::before { border-radius: 2px; clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 45% 62%); }
.radio input::before { border-radius: var(--r-pill); }

.checkbox input:checked,
.radio input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox input:checked::before,
.radio input:checked::before { transform: scale(1); }

.checkbox input:hover,
.radio input:hover { border-color: var(--accent); }

.checkbox input:focus-visible,
.radio input:focus-visible {
  outline: var(--focus-w) solid var(--focus);
  outline-offset: var(--focus-off);
}

.checkbox input:disabled,
.radio input:disabled {
  border-color: var(--line);
  background: var(--surface);
  accent-color: var(--ink-3);
  cursor: not-allowed;
}

.checkbox:has(input:disabled),
.radio:has(input:disabled) {
  color: var(--ink-3);
  cursor: not-allowed;
}

/* =============================================================================
   4. SWITCH — a toggle, not a checkbox with different chrome: the track is
   the graphic (3:1 --line/--accent already cleared on both grounds by the
   ladder), the thumb travels, and the state is echoed by position, not colour
   alone — off is left+track, on is right+accent, so it survives greyscale.
   ============================================================================= */

.switch {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  gap: var(--sp-2);
  cursor: pointer;
  font-size: var(--fs-1);
  color: var(--ink);
}

.switch input {
  appearance: none;
  margin: 0;
  width: 40px;
  height: 22px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--line);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}

.switch input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-pill);
  background: var(--ink);
  transition: transform var(--t-base) var(--ease), background var(--t-base) var(--ease);
}

.switch input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked::before {
  transform: translateX(18px);
  background: var(--on-accent);
}

.switch input:focus-visible {
  outline: var(--focus-w) solid var(--focus);
  outline-offset: var(--focus-off);
}

.switch input:disabled {
  background: var(--surface);
  border-color: var(--line);
  cursor: not-allowed;
}

.switch input:disabled::before { background: var(--ink-3); }
.switch:has(input:disabled) { color: var(--ink-3); cursor: not-allowed; }
