/* ==========================================================================
   FORM CONTROLS
   Inputs, textareas, selects, search, checkboxes, radios, switches.
   Share height/radius/border/type tokens with buttons for baseline parity.
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
}

.field__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

.field__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

.field__error {
  font-size: var(--font-size-xs);
  color: var(--color-error-600);
}

/* ---- Base control shell shared by input / select / textarea ---- */
.input,
.select,
.textarea {
  width: 100%;
  background: var(--color-bg-surface);
  border: var(--border-width) solid var(--color-border-default);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-sm);
  transition: border-color var(--duration-base) var(--ease-standard),
    box-shadow var(--duration-base) var(--ease-standard);
}

.input,
.select {
  height: var(--control-height-md);
  padding-inline: var(--space-4);
}

.input--sm, .select--sm { height: var(--control-height-sm); padding-inline: var(--space-3); font-size: var(--font-size-xs); }
.input--lg, .select--lg { height: var(--control-height-lg); padding-inline: var(--space-4); font-size: var(--font-size-md); }

.textarea {
  min-height: calc(var(--control-height-md) * 2);
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder { color: var(--color-text-tertiary); }

.input:hover:not(:disabled),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) { border-color: var(--color-border-strong); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus-ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--color-bg-subtle);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}

.field--error .input,
.field--error .select,
.field--error .textarea {
  border-color: var(--color-error-500);
}
.field--error .input:focus,
.field--error .select:focus,
.field--error .textarea:focus {
  box-shadow: var(--shadow-focus-ring-error);
}

.field--success .input,
.field--success .select {
  border-color: var(--color-success-500);
}

/* ---- Input with leading/trailing icon (search, etc.) ---- */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.input-group .input { padding-inline-start: calc(var(--icon-size-md) + var(--space-3) + var(--space-2)); }
.input-group .input-group__icon {
  position: absolute;
  left: var(--space-3);
  width: var(--icon-size-md);
  height: var(--icon-size-md);
  color: var(--color-text-tertiary);
  pointer-events: none;
}
.input-group .input-group__clear {
  position: absolute;
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--space-6);
  height: var(--space-6);
  border: none;
  background: transparent;
  color: var(--color-text-tertiary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.input-group .input-group__clear:hover { background: var(--color-bg-subtle); }

/* ---- Select chevron ---- */
.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='%23495057' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-inline-end: var(--space-8);
  cursor: pointer;
}

/* ---- Dropdown menu (used by select-like custom components) ---- */
.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  min-width: 12rem;
  background: var(--color-bg-surface);
  border: var(--border-width) solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: 20;
}
.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--icon-text-gap);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  min-height: var(--control-height-sm);
}
.dropdown__item:hover,
.dropdown__item[aria-selected="true"] { background: var(--color-bg-subtle); }

/* ---- Checkbox ---- */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height-md);
  cursor: pointer;
  font-size: var(--font-size-sm);
}
.checkbox input[type="checkbox"] {
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-bg-surface);
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.checkbox input[type="checkbox"]::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  transform: scale(0);
  transition: transform var(--duration-fast) var(--ease-standard);
  background: var(--color-text-inverse);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.checkbox input[type="checkbox"]:checked {
  background: var(--color-primary-600);
  border-color: var(--color-primary-600);
}
.checkbox input[type="checkbox"]:checked::before { transform: scale(1); }
.checkbox input[type="checkbox"]:focus-visible { box-shadow: var(--shadow-focus-ring); outline: none; }
.checkbox input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.5; }

/* ---- Radio ---- */
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height-md);
  cursor: pointer;
  font-size: var(--font-size-sm);
}
.radio input[type="radio"] {
  appearance: none;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-full);
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: border-color var(--duration-fast);
}
.radio input[type="radio"]::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: var(--radius-full);
  transform: scale(0);
  transition: transform var(--duration-fast) var(--ease-standard);
  background: var(--color-primary-600);
}
.radio input[type="radio"]:checked { border-color: var(--color-primary-600); }
.radio input[type="radio"]:checked::before { transform: scale(1); }
.radio input[type="radio"]:focus-visible { box-shadow: var(--shadow-focus-ring); outline: none; }
.radio input[type="radio"]:disabled { cursor: not-allowed; opacity: 0.5; }

/* ---- Switch ---- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--font-size-sm);
}
.switch input { appearance: none; position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch__track {
  position: relative;
  width: 2.5rem;
  height: 1.5rem;
  border-radius: var(--radius-full);
  background: var(--color-neutral-300);
  transition: background var(--duration-base) var(--ease-standard);
  flex-shrink: 0;
}
.switch__track::before {
  content: "";
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-full);
  background: var(--color-bg-surface);
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-base) var(--ease-standard);
}
.switch input:checked + .switch__track { background: var(--color-primary-600); }
.switch input:checked + .switch__track::before { transform: translateX(1rem); }
.switch input:focus-visible + .switch__track { box-shadow: var(--shadow-focus-ring); }
.switch input:disabled + .switch__track { opacity: 0.5; cursor: not-allowed; }
