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

// Tokens available globally via main application styles

// ==========================================================================
// CHECKBOX COMPONENT STYLES
// ==========================================================================
// Modern checkbox implementation using design tokens
// Follows Material Design 3 principles with semantic token system
// ==========================================================================

.checkbox-wrapper {
  display: flex;
  align-items: flex-start;
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: all $semantic-duration-fast $semantic-easing-standard;

  &:hover:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      border-color: $semantic-color-border-focus;
      box-shadow: $semantic-shadow-input-focus;
    }
  }

  &:focus-within:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      border-color: $semantic-color-brand-primary;
      box-shadow: $semantic-shadow-button-focus;
    }
  }

  // Disabled state
  &.checkbox-wrapper--disabled {
    cursor: not-allowed;
    opacity: 0.6;

    .checkbox-control {
      border-color: $semantic-color-border-disabled;
      background-color: $semantic-color-surface-disabled;
    }

    .checkbox-content {
      color: $semantic-color-text-disabled;
    }
  }

  // Checked state
  &.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-brand-primary;
      border-color: $semantic-color-brand-primary;
    }

    .checkbox-icon {
      color: $semantic-color-on-brand-primary;
    }
  }

  // Size variants with proper spacing and alignment
  &.checkbox-wrapper--sm {
    gap: $semantic-spacing-component-sm; // 8px spacing
    align-items: center; // Center align for single line content
    
    .checkbox-control {
      height: 20px;
      width: 20px;
    }
    
    .checkbox-label {
      font-size: $semantic-typography-font-size-sm;
      line-height: $semantic-typography-line-height-normal;
    }
    
    .checkbox-description {
      font-size: $semantic-typography-font-size-xs;
      line-height: $semantic-typography-line-height-tight;
    }
    
    // If description exists, align to flex-start for multi-line content
    &.checkbox-wrapper--with-description {
      align-items: flex-start;
    }
  }

  &.checkbox-wrapper--md {
    gap: $semantic-spacing-component-md; // 12px spacing
    align-items: center; // Center align for single line content
    
    .checkbox-control {
      height: 24px;
      width: 24px;
    }
    
    .checkbox-label {
      font-size: $semantic-typography-font-size-md;
      line-height: $semantic-typography-line-height-relaxed;
    }
    
    .checkbox-description {
      font-size: $semantic-typography-font-size-sm;
      line-height: $semantic-typography-line-height-normal;
    }
    
    // If description exists, align to flex-start for multi-line content
    &.checkbox-wrapper--with-description {
      align-items: flex-start;
    }
  }

  &.checkbox-wrapper--lg {
    gap: $semantic-spacing-component-md; // 12px spacing (within range)
    align-items: center; // Center align for single line content
    
    .checkbox-control {
      height: 28px;
      width: 28px;
    }
    
    .checkbox-label {
      font-size: $semantic-typography-font-size-lg;
      line-height: $semantic-typography-line-height-relaxed;
    }
    
    .checkbox-description {
      font-size: $semantic-typography-font-size-md;
      line-height: $semantic-typography-line-height-relaxed;
    }
    
    // If description exists, align to flex-start for multi-line content
    &.checkbox-wrapper--with-description {
      align-items: flex-start;
    }
  }

  // Variant colors
  &.checkbox-wrapper--primary.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-brand-primary;
      border-color: $semantic-color-brand-primary;
    }
  }

  &.checkbox-wrapper--secondary.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-brand-secondary;
      border-color: $semantic-color-brand-secondary;
    }
  }

  &.checkbox-wrapper--success.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-success;
      border-color: $semantic-color-success;
    }
    
    .checkbox-icon {
      color: $semantic-color-on-success;
    }
  }

  &.checkbox-wrapper--warning.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-warning;
      border-color: $semantic-color-warning;
    }
    
    .checkbox-icon {
      color: $semantic-color-on-warning;
    }
  }

  &.checkbox-wrapper--danger.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      background-color: $semantic-color-danger;
      border-color: $semantic-color-danger;
    }
    
    .checkbox-icon {
      color: $semantic-color-on-danger;
    }
  }

  // Error state
  &.checkbox-wrapper--error:not(.checkbox-wrapper--disabled) {
    .checkbox-control {
      border-color: $semantic-color-danger;
    }

    .checkbox-label {
      color: $semantic-color-danger;
    }
  }
}

.checkbox-input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
  margin: 0;
  padding: 0;
}

.checkbox-control {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-color: $semantic-color-surface-primary;
  border: $semantic-border-width-2 solid $semantic-color-border-primary;
  border-radius: $semantic-border-radius-sm;
  transition: all $semantic-duration-fast $semantic-easing-standard;

  // Base sizes (overridden by wrapper variants)
  height: 24px;
  width: 24px;
}

.checkbox-checkmark {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.8);
  transition: all $semantic-duration-fast $semantic-easing-spring;

  &.checkbox-checkmark--checked {
    opacity: 1;
    transform: scale(1);
  }
}

.checkbox-icon {
  width: 60%;
  height: 60%;
  color: transparent;
  transition: color $semantic-duration-fast $semantic-easing-standard;
}

.checkbox-content {
  display: flex;
  flex-direction: column;
  gap: $semantic-spacing-component-xs;
  // Removed margin-left as it's now handled by wrapper gap
}

.checkbox-label {
  color: $semantic-color-text-primary;
  font-weight: $semantic-typography-font-weight-medium;
  transition: color $semantic-duration-fast $semantic-easing-standard;

  &.checkbox-label--required {
    .checkbox-required-indicator {
      color: $semantic-color-danger;
      margin-left: 2px;
    }
  }
}

.checkbox-description {
  color: $semantic-color-text-secondary;
  margin-top: $semantic-spacing-component-xs;
  transition: color $semantic-duration-fast $semantic-easing-standard;
}

// Content disabled state
.checkbox-content--disabled {
  .checkbox-label,
  .checkbox-description {
    color: $semantic-color-text-disabled;
  }
}

// ==========================================================================
// RESPONSIVE DESIGN
// ==========================================================================

@media (max-width: $semantic-breakpoint-md - 1) {
  .checkbox-wrapper {
    // Slightly larger touch targets on mobile
    &.checkbox-wrapper--sm .checkbox-control {
      height: calc(#{20px} + 4px);
      width: calc(#{20px} + 4px);
    }
    
    &.checkbox-wrapper--md .checkbox-control {
      height: calc(#{24px} + 4px);
      width: calc(#{24px} + 4px);
    }
    
    &.checkbox-wrapper--lg .checkbox-control {
      height: calc(#{28px} + 4px);
      width: calc(#{28px} + 4px);
    }
  }
}

// ==========================================================================
// ACCESSIBILITY ENHANCEMENTS
// ==========================================================================

// Reduced motion preference
@media (prefers-reduced-motion: reduce) {
  .checkbox-wrapper,
  .checkbox-control,
  .checkbox-checkmark,
  .checkbox-icon,
  .checkbox-label,
  .checkbox-description {
    transition: none !important;
    animation: none !important;
  }
}

// High contrast mode
@media (prefers-contrast: high) {
  .checkbox-wrapper {
    .checkbox-control {
      border-width: $semantic-border-width-3;
    }
    
    &.checkbox-wrapper--checked:not(.checkbox-wrapper--disabled) {
      .checkbox-control {
        border-width: $semantic-border-width-3;
      }
    }
  }
}