/* Form v2 Component — UI Comprehensive Refactor v2
 * Requires: tokens.css, spacing.css
 *
 * Usage:
 *   <div class="form-group-v2">
 *     <label class="form-label-v2" for="email">
 *       Email <span class="form-label-v2__hint">(обязательное)</span>
 *     </label>
 *     <div class="form-input-with-icon">
 *       <svg class="icon form-input-icon"><use href="#i-mail"/></svg>
 *       <input id="email" type="email" class="form-input-v2" placeholder="you@example.com">
 *     </div>
 *     <p class="form-helper-v2">Мы никому не передадим ваш email.</p>
 *     <p class="form-error-v2" role="alert">Введите корректный email.</p>
 *   </div>
 *
 * Error state: add .form-input-v2--error to <input>.
 */

/* ── Form group (vertical stack per field) ── */
.form-group-v2 {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-4);   /* 16px */
}

/* ── Label ── */
.form-label-v2 {
  display: block;
  font-size: var(--font-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
  line-height: 1;
}

/* ── Label hint (secondary inline annotation) ── */
.form-label-v2__hint {
  font-size: var(--font-xs);
  color: var(--text-muted);
  font-weight: var(--weight-regular);
  margin-left: var(--space-2);
}

/* ── Base input ── */
.form-input-v2 {
  width: 100%;
  height: var(--control-h-md);          /* 36px — CANONICAL field height (control-sizing-standard) */
  padding: 0 var(--control-px-md);      /* horizontal only; the fixed height controls vertical */
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-base);
  font-size: var(--control-font-md);    /* matches the canonical control font */
  font-family: inherit;
  color: var(--text-primary);
  line-height: normal;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  box-sizing: border-box;
}

/* Multi-line fields grow vertically — height is the only exception to the 36px rule. */
textarea.form-input-v2 {
  height: auto;
  min-height: var(--control-h-lg);
  padding: var(--space-2) var(--control-px-md);
  line-height: var(--line-base);
}

/* Range sliders are not boxed inputs — drop the field chrome and fixed height. */
.form-input-v2[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;            /* hit area; the visible track is drawn below */
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}
/* Visible track (the line the thumb rides) — was missing, thumb floated alone */
.form-input-v2[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong, rgba(255, 255, 255, 0.20));
}
.form-input-v2[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong, rgba(255, 255, 255, 0.20));
}
.form-input-v2[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--color-brand-500, #3b82f6);
}
.form-input-v2[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;        /* center the 16px thumb on the 4px track */
  border-radius: 50%;
  background: var(--color-brand-500, #3b82f6);
  cursor: pointer;
}
.form-input-v2[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--color-brand-500, #3b82f6);
  cursor: pointer;
}

.form-input-v2::placeholder {
  color: var(--text-muted);
}

.form-input-v2:hover:not(:disabled):not(:focus) {
  border-color: var(--border-strong);
}

.form-input-v2:focus,
.form-input-v2:focus-visible {
  outline: none;
  border-color: var(--color-brand-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input-v2:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface-page);
}

/* ── Error state ── */
.form-input-v2--error {
  border-color: var(--color-error-500);
}

.form-input-v2--error:focus,
.form-input-v2--error:focus-visible {
  border-color: var(--color-error-500);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* ── Input with leading icon wrapper ── */
.form-input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

/* ── Icon inside input (absolute left) ── */
.form-input-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-muted);
  pointer-events: none;
  font-size: var(--font-base);
  flex-shrink: 0;
}

/* ── Push input text right when icon is present ── */
.form-input-with-icon .form-input-v2 {
  padding-left: 36px;
}

/* ── Helper text (neutral) ── */
.form-helper-v2 {
  font-size: var(--font-xs);        /* 12px */
  color: var(--text-muted);
  margin-top: var(--space-1);
  line-height: var(--line-base);
}

/* ── Error message ── */
.form-error-v2 {
  font-size: var(--font-xs);
  color: var(--color-error-500);
  margin-top: var(--space-1);
  line-height: var(--line-base);
}

/* ── Textarea inherits input styles ── */
textarea.form-input-v2 {
  resize: vertical;
  min-height: 80px;
  line-height: var(--line-base);
}

/* ── Custom checkbox ── */
.form-checkbox-v2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--font-sm);
  color: var(--text-primary);
  user-select: none;
}

.form-checkbox-v2 input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xs);
  background: var(--surface-input);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  position: relative;
}

.form-checkbox-v2 input[type="checkbox"]:checked {
  background: var(--color-brand-500);
  border-color: var(--color-brand-500);
}

.form-checkbox-v2 input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  inset: 3px 3px 4px 3px;
  border: 2px solid var(--text-on-brand);
  border-top: none;
  border-right: none;
  transform: rotate(-45deg);
}

.form-checkbox-v2 input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.20);
}
