/* ============================================================
   BASE — forms.css
   Bare element defaults for all form controls.
   Opinionated enough to look good with zero classes —
   Rails form helpers and Bridgetown forms work unstyled.
   ============================================================ */

/* ── Fieldset & Legend ───────────────────────────────────── */

fieldset {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: var(--space-m);
  margin: 0;
}

legend {
  font-weight: var(--font-weight-bold);
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-muted);
  padding-inline: var(--space-xs);
}

/* ── Labels ──────────────────────────────────────────────── */

label {
  display: block;
  font-size: var(--step--1);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-block-end: var(--space-2xs);
}

/* Inline label (checkbox, radio) */
label:has(input[type="checkbox"]),
label:has(input[type="radio"]) {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-weight: var(--font-weight-regular);
  cursor: pointer;
}

/* ── Text Inputs, Textarea, Select ──────────────────────── */

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):not([type="submit"]):not([type="reset"]):not([type="button"]),
textarea,
select {
  display: block;
  width: 100%;
  padding: var(--space-xs) var(--space-s);
  font-family: var(--font-base);
  font-size: var(--step-0);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-surface-base);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):not([type="submit"]):not([type="reset"]):not([type="button"]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]):not([type="submit"]):not([type="reset"]):not([type="button"]):disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--color-surface-raised);
}

/* Placeholder */
::placeholder {
  color: var(--color-text-subtle);
  opacity: 1;
}

/* ── Select arrow ────────────────────────────────────────── */

select {
  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='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-s) center;
  padding-inline-end: var(--space-2xl);
}

/* ── Checkbox & Radio ────────────────────────────────────── */

input[type="checkbox"],
input[type="radio"] {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  accent-color: var(--color-brand);
  cursor: pointer;
}

input[type="radio"] {
  border-radius: 50%;
}

/* ── Range ───────────────────────────────────────────────── */

input[type="range"] {
  width: 100%;
  accent-color: var(--color-brand);
}

/* ── File input ──────────────────────────────────────────── */

input[type="file"] {
  font-size: var(--step--1);
  color: var(--color-text-muted);
  cursor: pointer;
}

/* ── Invalid state ───────────────────────────────────────── */

input:not([type="checkbox"]):not([type="radio"]):user-invalid,
textarea:user-invalid,
select:user-invalid {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px oklch(from var(--color-error) l c h / 0.20);
}
