@use '../variables' as v;
@use '../mixins' as m;

// ─────────────────────────────────────────────
// Form group
// ─────────────────────────────────────────────
.form-group {
  margin-bottom: 18px;

  &:last-child { margin-bottom: 0; }
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;

  @include m.max-sm { grid-template-columns: 1fr; }
}

// ─────────────────────────────────────────────
// Label
// ─────────────────────────────────────────────
.form-label {
  display: block;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-700;
  margin-bottom: 6px;

  .required {
    color: v.$danger;
    margin-left: 3px;
  }
}

.form-hint {
  font-size: v.$font-size-xs;
  color: v.$gray-400;
  margin-top: 5px;
  line-height: 1.5;
}

.form-error {
  font-size: v.$font-size-xs;
  color: v.$danger;
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;

  svg { width: 13px; height: 13px; }
}

// ─────────────────────────────────────────────
// Input
// ─────────────────────────────────────────────
.form-input {
  display: block;
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid v.$border-color;
  border-radius: v.$radius;
  font-size: v.$font-size-sm;
  font-family: v.$font-family;
  color: v.$gray-800;
  background: v.$white;
  transition: border-color v.$transition-base, box-shadow v.$transition-base;

  &::placeholder { color: v.$gray-400; }

  &:focus {
    outline: none;
    border-color: v.$primary-border;
    @include m.focus-ring;
  }

  &.has-error {
    border-color: v.$danger-border;
    background: v.$danger-light;
  }

  &:disabled {
    background: v.$gray-50;
    color: v.$gray-400;
    cursor: not-allowed;
  }
}

// Textarea
.form-textarea {
  @extend .form-input;
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

// Select
.form-select {
  @extend .form-input;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%239ca3af'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.17l3.71-3.94a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
  cursor: pointer;
}

// Input with icon
.input-with-icon {
  position: relative;

  .input-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: v.$gray-400;
    pointer-events: none;

    svg { width: 16px; height: 16px; }

    &--left  { left: 11px;  + .form-input { padding-left: 34px; } }
    &--right { right: 11px; }
  }
}

// ─────────────────────────────────────────────
// Checkbox & Radio
// ─────────────────────────────────────────────
.form-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: v.$font-size-sm;
  color: v.$gray-700;
  line-height: 1.4;

  input[type="checkbox"],
  input[type="radio"] {
    width: 16px;
    height: 16px;
    margin-top: 1px;
    accent-color: v.$primary;
    flex-shrink: 0;
    cursor: pointer;
  }
}

// Toggle switch
.form-toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;

  input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;

    &:checked + .toggle-track {
      background: v.$primary;

      &::after { transform: translateX(16px); }
    }

    &:focus + .toggle-track { @include m.focus-ring; }
  }

  .toggle-track {
    position: absolute;
    inset: 0;
    background: v.$gray-300;
    border-radius: v.$radius-full;
    transition: background v.$transition-base;
    cursor: pointer;

    &::after {
      content: '';
      position: absolute;
      left: 3px;
      top: 3px;
      width: 16px;
      height: 16px;
      background: v.$white;
      border-radius: v.$radius-full;
      transition: transform v.$transition-base;
      box-shadow: v.$shadow-xs;
    }
  }
}

// ─────────────────────────────────────────────
// File upload zone
// ─────────────────────────────────────────────
.upload-zone {
  border: 2px dashed v.$border-color;
  border-radius: v.$radius-lg;
  padding: 40px 24px;
  text-align: center;
  background: v.$gray-50;
  cursor: pointer;
  transition: border-color v.$transition-base, background v.$transition-base;

  &:hover,
  &.is-dragover {
    border-color: v.$primary-border;
    background: v.$primary-light;
  }

  &-icon {
    @include m.flex-center;
    width: 52px;
    height: 52px;
    background: v.$white;
    border: 1px solid v.$border-color;
    border-radius: v.$radius-lg;
    margin: 0 auto 16px;

    svg { width: 24px; height: 24px; color: v.$gray-400; }
  }

  &-title {
    font-size: v.$font-size-base;
    font-weight: 600;
    color: v.$gray-700;
    margin-bottom: 6px;

    span { color: v.$primary; }
  }

  &-sub {
    font-size: v.$font-size-xs;
    color: v.$gray-400;
  }
}

// ─────────────────────────────────────────────
// Color picker swatch
// ─────────────────────────────────────────────
.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: v.$radius-full;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform v.$transition-base;

  &:hover     { transform: scale(1.15); }
  &.is-active { border-color: v.$gray-800; }
}
