/* =============================================================================
   @elements/style — form

   All form styling is CLASS-based, not element+attribute-based. This avoids
   the classic (0,0,1,1) specificity trap where `input[type="text"]` silently
   beats a consumer `.field-input` class.

   Usage:
     <div class="field">
       <label>Email</label>
       <input type="email" class="input">
     </div>

   Sizes:
     .input-sm  — 32px (dashboard density)
     .input     — 44px (default; comfortable for landing / signup / purchase)
     .input-lg  — 48px (hero density)

   Focus:
     Crisp border darkens to ink (no blurry halo), plus a subtle 3px ink wash
     for extra signal. Matches the purchase / signin mocks.
============================================================================= */

/* ─── Label ────────────────────────────────────────────────────────── */

.label-field {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.84375rem;             /* 13.5px */
  font-weight: var(--font-medium);
  color: var(--ink);
  margin-bottom: 0.375rem;           /* 6px */
}

/* Convenience: a bare <label> inside .field gets the field label treatment */
.field > label,
.field > .label-row > label {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.84375rem;
  font-weight: var(--font-medium);
  color: var(--ink);
  margin-bottom: 0.375rem;
}

/* Label row: label on left, hint / forgot-link on right */
.field > .label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.375rem;
}
.field > .label-row > label { margin-bottom: 0; }

/* ─── Input / textarea / select ──────────────────────────────────── */

.input {
  display: block;
  width: 100%;
  height: var(--input-height);
  padding: var(--input-padding-y) var(--input-padding-x);
  font-family: var(--font-mono);
  font-size: var(--input-font-size);
  line-height: 1.4;
  color: var(--ink);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--input-radius);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.input::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}

.input:hover:not(:disabled):not(:focus) {
  border-color: var(--ink-faint);
}

/* Focus: crisp border-color change only. No halo, no box-shadow. */
.input:focus,
.input:focus-visible {
  outline: none;
  border-color: var(--input-border-focus);
}

.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-soft);
}

/* Textarea */
textarea.input {
  height: auto;
  min-height: 5rem;
  resize: vertical;
  line-height: var(--leading-snug);
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

/* Select */
select.input {
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2392939a' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.625rem center;
  background-repeat: no-repeat;
  background-size: 1.125em 1.125em;
  appearance: none;
  cursor: pointer;
}

/* ─── Sizes ────────────────────────────────────────────────────── */

.input-sm {
  height: var(--input-height-sm);
  padding: 0.25rem 0.625rem;
  font-size: var(--text-xs);
}
textarea.input-sm { height: auto; min-height: 4rem; }

.input-lg {
  height: var(--input-height-lg);
  padding: 0.6875rem 0.875rem;
  font-size: var(--text-md);
}
textarea.input-lg { height: auto; min-height: 6rem; }

/* ─── Checkbox / radio ──────────────────────────────────────────── */

.checkbox,
.radio {
  width: 1rem;
  height: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink-faint);
  cursor: pointer;
  appearance: none;
  flex-shrink: 0;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}
.checkbox { border-radius: var(--radius-xs); }
.radio    { border-radius: var(--radius-full); }

.checkbox:hover,
.radio:hover { border-color: var(--ink); }

.checkbox:checked,
.radio:checked {
  background-color: var(--ink);
  border-color: var(--ink);
}

.checkbox:checked {
  background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}
.radio:checked {
  background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.checkbox:focus,
.radio:focus { outline: none; }
/* Border darkens on keyboard focus — no outer ring, follows the control shape. */
.checkbox:focus-visible,
.radio:focus-visible {
  outline: none;
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

/* ─── Toggle / switch ───────────────────────────────────────────────
   Rust ON, ink-faint OFF. Used on auto-renew, feature toggles, etc. */

.toggle {
  width: 2.375rem;       /* 38px */
  height: 1.375rem;      /* 22px */
  background: var(--ink-faint);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
  padding: 0;
  transition: background-color 200ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.125rem;       /* 18px */
  height: 1.125rem;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition:
    transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
    width 80ms var(--ease-out);
}

/* Off → On: nub slides 16px. Using transform for GPU-accelerated motion. */
.toggle.is-on                { background: var(--accent); }
.toggle.is-on::after         { transform: translateX(1rem); }     /* 16px */

/* Hover: track darkens one step. */
.toggle:hover:not(:disabled)       { background: var(--ink-dim); }
.toggle.is-on:hover:not(:disabled) { background: var(--accent-deep); }

/* Active / pressed: nub elongates to feel tactile. */
.toggle:active:not(:disabled)::after        { width: 1.375rem; }           /* 22px */
.toggle.is-on:active:not(:disabled)::after  { transform: translateX(0.75rem); width: 1.375rem; }  /* slide back so right edge stays anchored */

/* Focus: outer cornflower ring with 2px white gap. Keyboard only. */
.toggle:focus { outline: none; }
.toggle:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--bg),
    0 0 0 4px var(--accent-deep);
}

.toggle:disabled {
  background: var(--rule);
  cursor: not-allowed;
  opacity: 0.6;
}
.toggle:disabled::after {
  background: var(--bg-soft);
  box-shadow: none;
}

/* Small variant (20x14 nub at 14) */
.toggle-sm {
  width: 1.75rem;
  height: 1.125rem;
}
.toggle-sm::after {
  width: 0.875rem;
  height: 0.875rem;
}
.toggle-sm.is-on::after { left: calc(100% - 0.875rem - 2px); }

/* ─── Stepper ───────────────────────────────────────────────────────
   Quantity increment/decrement. Used on purchase license counter and
   account license quantity. */

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--bg);
  overflow: hidden;
  font-family: var(--font-mono);
}
.stepper-btn {
  background: var(--bg);
  border: none;
  color: var(--ink);
  width: 2rem;
  height: 2rem;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}
.stepper-btn:hover:not(:disabled) { background: var(--bg-panel); }
.stepper-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.stepper-btn:focus,
.stepper-btn:focus-visible { outline: none; }
.stepper-val {
  padding: 0 0.875rem;
  min-width: 2.5rem;
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  line-height: 2rem;
  font-variant-numeric: tabular-nums;
}

/* Typable stepper value: <input type="number" class="stepper-val stepper-input">
   matches the span variant, no default browser chrome, no spinner arrows. */
.stepper-input {
  height: 2rem;
  line-height: 2rem;
  font-family: var(--font-mono);
  color: var(--ink);
  background: transparent;
  border-top: none;
  border-bottom: none;
  border-radius: 0;
  outline: none;
  -moz-appearance: textfield;        /* Firefox: no spinner */
  appearance: none;
}
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;          /* Chrome/Safari: no spinner */
  margin: 0;
}
.stepper-input:focus,
.stepper-input:focus-visible { outline: none; }
.stepper-input::selection {
  background: var(--bg-panel);
  color: var(--ink);
}

/* ─── Form structure ────────────────────────────────────────────── */

.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem 0.75rem;
  margin-bottom: 0.625rem;
}
.form-grid > .field { margin-bottom: 0; }
.field-full { grid-column: 1 / -1; }

.form-hint {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--ink-dim);
  margin-top: 0.375rem;
  line-height: 1.5;
}

/* ─── Validation states ────────────────────────────────────────── */

.input.is-error            { border-color: var(--danger); }
.input.is-error:focus      { border-color: var(--danger); }

.input.is-ok               { border-color: var(--green); }
.input.is-ok:focus         { border-color: var(--green); }

.form-error {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: 0.25rem;
}

/* ─── Fieldset / legend ─────────────────────────────────────────── */

fieldset {
  padding: var(--space-4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
}
legend {
  padding: 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--ink-dim);
}
