@use 'ui-design-system/src/styles/semantic' as *;

.ui-color-picker {
  display: flex;
  flex-direction: column;
  position: relative;
  font-family: map-get($semantic-typography-body-medium, font-family);
  font-size: map-get($semantic-typography-body-medium, font-size);
  font-weight: map-get($semantic-typography-body-medium, font-weight);
  line-height: map-get($semantic-typography-body-medium, line-height);
  color: $semantic-color-text-primary;

  &__label {
    display: block;
    margin-bottom: $semantic-spacing-form-field-gap;
    font-family: map-get($semantic-typography-label, font-family);
    font-size: map-get($semantic-typography-label, font-size);
    font-weight: map-get($semantic-typography-label, font-weight);
    line-height: map-get($semantic-typography-label, line-height);
    color: $semantic-color-text-primary;
  }

  &__required {
    color: $semantic-color-danger;
    margin-left: $semantic-spacing-component-xs;
  }

  &__container {
    display: flex;
    flex-direction: column;
    gap: $semantic-spacing-component-md;
    padding: $semantic-spacing-component-md;
    background: $semantic-color-surface-primary;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-md;
    box-shadow: $semantic-shadow-elevation-1;
  }

  &__wheel-container {
    position: relative;
    align-self: center;
  }

  &__wheel {
    display: block;
    border-radius: $semantic-border-radius-full;
    cursor: crosshair;
    border: $semantic-border-width-1 solid $semantic-color-border-subtle;
    box-shadow: $semantic-shadow-elevation-1;
    transition: box-shadow $semantic-motion-duration-fast $semantic-motion-easing-ease;

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
      box-shadow: $semantic-shadow-elevation-2;
    }
  }

  &__wheel-indicator {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 2px solid $semantic-color-surface-primary;
    border-radius: $semantic-border-radius-full;
    background: transparent;
    pointer-events: none;
    box-shadow: $semantic-shadow-elevation-2;
    z-index: 1;
  }

  &__hue-container {
    position: relative;
    align-self: center;
  }

  &__hue-bar {
    display: block;
    border-radius: $semantic-border-radius-sm;
    cursor: pointer;
    border: $semantic-border-width-1 solid $semantic-color-border-subtle;
    box-shadow: $semantic-shadow-elevation-1;
    transition: box-shadow $semantic-motion-duration-fast $semantic-motion-easing-ease;

    &:focus-visible {
      outline: 2px solid $semantic-color-focus;
      outline-offset: 2px;
      box-shadow: $semantic-shadow-elevation-2;
    }
  }

  &__hue-indicator {
    position: absolute;
    top: -2px;
    width: 12px;
    height: calc(100% + 4px);
    border: 2px solid $semantic-color-surface-primary;
    border-radius: $semantic-border-radius-sm;
    background: transparent;
    pointer-events: none;
    box-shadow: $semantic-shadow-elevation-2;
    z-index: 1;
  }

  &__preview-container {
    align-self: center;
  }

  &__preview {
    width: 48px;
    height: 32px;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-radius-sm;
    box-shadow: $semantic-shadow-elevation-1;
    cursor: pointer;
  }

  &__hex-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: $semantic-spacing-component-xs;
  }

  &__hex-label {
    font-family: map-get($semantic-typography-caption, font-family);
    font-size: map-get($semantic-typography-caption, font-size);
    font-weight: map-get($semantic-typography-caption, font-weight);
    line-height: map-get($semantic-typography-caption, line-height);
    color: $semantic-color-text-secondary;
    text-transform: uppercase;
  }

  &__hex-input {
    width: 80px;
    padding: $semantic-spacing-interactive-input-padding-y $semantic-spacing-interactive-input-padding-x;
    background: $semantic-color-surface-secondary;
    border: $semantic-border-width-1 solid $semantic-color-border-primary;
    border-radius: $semantic-border-input-radius;
    font-family: map-get($semantic-typography-input, font-family);
    font-size: map-get($semantic-typography-input, font-size);
    font-weight: map-get($semantic-typography-input, font-weight);
    line-height: map-get($semantic-typography-input, line-height);
    color: $semantic-color-text-primary;
    text-align: center;
    text-transform: uppercase;
    transition: all $semantic-motion-duration-fast $semantic-motion-easing-ease;

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

    &:disabled {
      background: $semantic-color-surface-container;
      color: $semantic-color-text-disabled;
      cursor: not-allowed;
      opacity: $semantic-opacity-disabled;
    }
  }

  &__description {
    margin-top: $semantic-spacing-component-xs;
    font-family: map-get($semantic-typography-caption, font-family);
    font-size: map-get($semantic-typography-caption, font-size);
    font-weight: map-get($semantic-typography-caption, font-weight);
    line-height: map-get($semantic-typography-caption, line-height);
    color: $semantic-color-text-tertiary;
  }

  // Size variants
  &--sm {
    font-family: map-get($semantic-typography-body-small, font-family);
    font-size: map-get($semantic-typography-body-small, font-size);
    font-weight: map-get($semantic-typography-body-small, font-weight);
    line-height: map-get($semantic-typography-body-small, line-height);

    .ui-color-picker__container {
      padding: $semantic-spacing-component-sm;
      gap: $semantic-spacing-component-sm;
    }

    .ui-color-picker__preview {
      width: 32px;
      height: 24px;
    }

    .ui-color-picker__hex-input {
      width: 70px;
      padding: $semantic-spacing-component-xs;
    }

    .ui-color-picker__wheel-indicator {
      width: 8px;
      height: 8px;
    }

    .ui-color-picker__hue-indicator {
      width: 8px;
      height: calc(100% + 4px);
    }
  }

  &--lg {
    font-family: map-get($semantic-typography-body-large, font-family);
    font-size: map-get($semantic-typography-body-large, font-size);
    font-weight: map-get($semantic-typography-body-large, font-weight);
    line-height: map-get($semantic-typography-body-large, line-height);

    .ui-color-picker__container {
      padding: $semantic-spacing-component-lg;
      gap: $semantic-spacing-component-lg;
    }

    .ui-color-picker__preview {
      width: 64px;
      height: 40px;
    }

    .ui-color-picker__hex-input {
      width: 90px;
      padding: $semantic-spacing-component-sm;
    }

    .ui-color-picker__wheel-indicator {
      width: 16px;
      height: 16px;
    }

    .ui-color-picker__hue-indicator {
      width: 16px;
      height: calc(100% + 4px);
    }
  }

  // Color variants
  &--primary {
    .ui-color-picker__container {
      border-color: $semantic-color-primary;
    }

    .ui-color-picker__hex-input:focus {
      border-color: $semantic-color-primary;
    }
  }

  &--secondary {
    .ui-color-picker__container {
      border-color: $semantic-color-secondary;
    }

    .ui-color-picker__hex-input:focus {
      border-color: $semantic-color-secondary;
    }
  }

  &--success {
    .ui-color-picker__container {
      border-color: $semantic-color-success;
    }

    .ui-color-picker__hex-input:focus {
      border-color: $semantic-color-success;
    }
  }

  &--danger {
    .ui-color-picker__container {
      border-color: $semantic-color-danger;
    }

    .ui-color-picker__hex-input:focus {
      border-color: $semantic-color-danger;
    }
  }

  // State variants
  &--error {
    .ui-color-picker__container {
      border-color: $semantic-color-border-error;
    }

    .ui-color-picker__label {
      color: $semantic-color-danger;
    }

    .ui-color-picker__hex-input {
      border-color: $semantic-color-border-error;
    }
  }

  &--disabled {
    opacity: $semantic-opacity-disabled;
    pointer-events: none;

    .ui-color-picker__container {
      background: $semantic-color-surface-container;
      border-color: $semantic-color-border-subtle;
    }

    .ui-color-picker__wheel,
    .ui-color-picker__hue-bar {
      cursor: not-allowed;
      opacity: $semantic-opacity-disabled;
    }

    .ui-color-picker__label {
      color: $semantic-color-text-disabled;
    }
  }

  // Responsive design
  @media (max-width: calc(#{$semantic-breakpoint-md} - 1px)) {
    .ui-color-picker__container {
      padding: $semantic-spacing-component-sm;
      gap: $semantic-spacing-component-sm;
    }
  }

  @media (max-width: calc(#{$semantic-breakpoint-sm} - 1px)) {
    font-family: map-get($semantic-typography-body-small, font-family);
    font-size: map-get($semantic-typography-body-small, font-size);
    font-weight: map-get($semantic-typography-body-small, font-weight);
    line-height: map-get($semantic-typography-body-small, line-height);

    .ui-color-picker__container {
      padding: $semantic-spacing-component-xs;
      gap: $semantic-spacing-component-xs;
    }

    .ui-color-picker__preview {
      width: 40px;
      height: 28px;
    }

    .ui-color-picker__hex-input {
      width: 75px;
    }
  }

  // High contrast mode
  @media (prefers-contrast: high) {
    .ui-color-picker__wheel,
    .ui-color-picker__hue-bar {
      border-width: $semantic-border-width-2;
    }

    .ui-color-picker__wheel-indicator,
    .ui-color-picker__hue-indicator {
      border-width: 3px;
    }
  }

  // Reduced motion
  @media (prefers-reduced-motion: reduce) {
    .ui-color-picker__wheel,
    .ui-color-picker__hue-bar,
    .ui-color-picker__hex-input {
      transition: none;
    }
  }
}