// =============================================================================
// Color Field — Color picker with swatch, hex input, and preset colors
// =============================================================================

@use '../variables' as *;
@use '../mixins' as *;

.color-field {
  position: relative;
}

.color-field__row {
  display: flex;
  align-items: center;
}

// Swatch button (left)
.color-field__swatch-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 1px solid $neutral-300;
  border-right: 0;
  border-radius: $radius 0 0 $radius;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  background: transparent;

  &:disabled {
    cursor: not-allowed;
  }

  .dark & {
    border-color: $neutral-600;
  }
}

.color-field__swatch {
  width: 24px;
  height: 24px;
  border-radius: $radius-sm;
  border: 1px solid $neutral-200;

  .dark & {
    border-color: $neutral-500;
  }
}

// Hex input (middle)
.color-field__input {
  flex: 1;
  height: 38px;
  padding: 0.5rem 0.75rem;
  border: 1px solid $neutral-300;
  background: #fff;
  font-family: $font-mono;
  font-size: $font-size-sm;
  color: $neutral-900;
  @include transition-fast(color, background-color, border-color, box-shadow);

  &::placeholder {
    color: $neutral-400;
  }

  &:focus {
    outline: none;
    border-color: $primary-500;
    box-shadow: 0 0 0 2px rgba($primary-500, 0.2);
  }

  &:disabled {
    background: $neutral-100;
    cursor: not-allowed;
  }

  .dark & {
    border-color: $neutral-600;
    background: $neutral-900;
    color: $neutral-50;

    &::placeholder {
      color: $neutral-500;
    }

    &:focus {
      border-color: $primary-500;
      box-shadow: 0 0 0 2px rgba($primary-500, 0.2);
    }

    &:disabled {
      background: $neutral-800;
    }
  }
}

.color-field__input--rounded-right {
  border-radius: 0 $radius $radius 0;
}

.color-field__input--error {
  border-color: $error-500;

  &:focus {
    border-color: $error-500;
    box-shadow: 0 0 0 2px rgba($error-500, 0.2);
  }

  .dark & {
    border-color: $error-500;

    &:focus {
      border-color: $error-500;
      box-shadow: 0 0 0 2px rgba($error-500, 0.2);
    }
  }
}

// Clear button (right)
.color-field__clear-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 1px solid $neutral-300;
  border-left: 0;
  border-radius: 0 $radius $radius 0;
  background: $neutral-50;
  display: flex;
  align-items: center;
  justify-content: center;
  color: $neutral-400;
  cursor: pointer;
  @include transition-fast(color);

  &:hover {
    color: $neutral-600;
  }

  &:disabled {
    cursor: not-allowed;
  }

  .dark & {
    border-color: $neutral-600;
    background: $neutral-700;

    &:hover {
      color: $neutral-300;
    }
  }
}

// Dropdown
.color-field__dropdown {
  position: absolute;
  z-index: $z-dropdown;
  margin-top: 0.25rem;
  width: 100%;
  background: #fff;
  border: 1px solid $neutral-200;
  border-radius: $radius;
  box-shadow: $shadow-md;
  padding: 0.75rem;

  .dark & {
    background: $neutral-800;
    border-color: $neutral-700;
  }
}

// Native color input inside dropdown
.color-field__native-input {
  width: 100%;
  height: 2.5rem;
  border-radius: $radius;
  border: 1px solid $neutral-200;
  cursor: pointer;
  background: transparent;
  margin-bottom: 0.75rem;

  .dark & {
    border-color: $neutral-600;
  }
}

// Presets section
.color-field__presets {
  margin-bottom: 0.5rem;
}

.color-field__presets-label {
  font-size: $font-size-xs;
  color: $neutral-500;
  margin-bottom: 0.375rem;
}

.color-field__presets-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.color-field__preset {
  width: 28px;
  height: 28px;
  border-radius: $radius;
  border: 2px solid $neutral-200;
  cursor: pointer;
  @include transition-fast(border-color, transform);

  &:hover {
    transform: scale(1.1);
    border-color: $neutral-400;
  }

  .dark & {
    border-color: $neutral-600;

    &:hover {
      border-color: $neutral-400;
    }
  }
}

.color-field__preset--active {
  border-color: $primary-500;
  box-shadow: 0 0 0 2px rgba($primary-500, 0.3);
}

// Current value display at bottom of dropdown
.color-field__current {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid $neutral-200;

  .dark & {
    border-color: $neutral-700;
  }
}

.color-field__current-swatch {
  width: 20px;
  height: 20px;
  border-radius: $radius-sm;
  border: 1px solid $neutral-200;

  .dark & {
    border-color: $neutral-600;
  }
}

.color-field__current-value {
  font-size: $font-size-xs;
  font-family: $font-mono;
  color: $neutral-600;

  .dark & {
    color: $neutral-300;
  }
}

.color-field__invalid {
  font-size: $font-size-xs;
  color: $error-500;
}
