// ==========================================================================
// BASE BUTTONS
// ==========================================================================
// Theme-agnostic button structures and behaviors
// Visual styling handled by themes
// ==========================================================================

// BUTTON BASE
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--btn-gap, #{$semantic-spacing-micro-icon-gap});
  padding: var(--btn-padding, #{$semantic-spacing-interactive-button-padding-y} #{$semantic-spacing-interactive-button-padding-x});
  border: var(--btn-border-width, #{$semantic-border-button-width}) solid transparent;
  border-radius: var(--btn-border-radius, #{$semantic-border-button-radius});
  font-family: inherit;
  font-size: var(--btn-font-size, 1rem);
  font-weight: var(--btn-font-weight, 500);
  line-height: var(--btn-line-height, 1.5);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
  user-select: none;
  transition: all var(--btn-transition-duration, 0.2s) var(--btn-transition-easing, ease);
  position: relative;
  overflow: hidden;

  &:focus {
    outline: var(--btn-focus-outline, 2px solid transparent);
    outline-offset: var(--btn-focus-outline-offset, 2px);
  }

  &:disabled,
  &.btn-disabled {
    pointer-events: none;
    opacity: var(--btn-disabled-opacity, 0.6);
    cursor: not-allowed;
  }

  &.btn-loading {
    pointer-events: none;
    
    .btn-text {
      opacity: 0;
    }
    
    .btn-spinner {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }
}

// BUTTON SIZES - Using semantic sizing tokens
.btn-xs {
  --btn-padding: #{$semantic-spacing-component-padding-xs} #{$semantic-spacing-component-padding-sm};
  --btn-font-size: 0.75rem;
  --btn-gap: #{$base-spacing-1};
}

.btn-sm {
  --btn-padding: #{$semantic-spacing-component-padding-sm} #{$semantic-spacing-component-padding-md};
  --btn-font-size: 0.875rem;
  --btn-gap: #{$semantic-spacing-micro-icon-gap};
}

.btn-lg {
  --btn-padding: #{$semantic-spacing-component-padding-md} #{$semantic-spacing-component-padding-xl};
  --btn-font-size: 1.125rem;
  --btn-gap: #{$semantic-spacing-component-padding-sm};
}

.btn-xl {
  --btn-padding: #{$semantic-spacing-component-padding-lg} #{$semantic-spacing-component-padding-xl};
  --btn-font-size: 1.25rem;
  --btn-gap: 16px;
}

// BUTTON SHAPES
.btn-rounded {
  border-radius: var(--btn-rounded-radius, 50px);
}

.btn-square {
  border-radius: 0;
}

.btn-circle {
  border-radius: 50%;
  width: var(--btn-circle-size, 48px);
  height: var(--btn-circle-size, 48px);
  padding: 0;
}

// BUTTON WIDTHS
.btn-block {
  display: flex;
  width: 100%;
}

.btn-auto {
  width: auto;
}

// BUTTON GROUPS
.btn-group {
  display: inline-flex;
  vertical-align: middle;

  > .btn {
    position: relative;
    flex: 1 1 auto;
    border-radius: 0;

    &:first-child {
      border-top-left-radius: var(--btn-border-radius, 4px);
      border-bottom-left-radius: var(--btn-border-radius, 4px);
    }

    &:last-child {
      border-top-right-radius: var(--btn-border-radius, 4px);
      border-bottom-right-radius: var(--btn-border-radius, 4px);
    }

    &:not(:first-child) {
      margin-left: calc(var(--btn-border-width, 1px) * -1);
    }

    &:hover,
    &:focus,
    &.btn-active {
      z-index: 1;
    }
  }

  &.btn-group-vertical {
    flex-direction: column;

    > .btn {
      &:first-child {
        border-radius: var(--btn-border-radius, 4px) var(--btn-border-radius, 4px) 0 0;
      }

      &:last-child {
        border-radius: 0 0 var(--btn-border-radius, 4px) var(--btn-border-radius, 4px);
      }

      &:not(:first-child) {
        margin-left: 0;
        margin-top: calc(var(--btn-border-width, 1px) * -1);
      }
    }
  }
}

// FLOATING ACTION BUTTON (FAB)
.btn-fab {
  position: fixed;
  bottom: var(--fab-bottom, 24px);
  right: var(--fab-right, 24px);
  width: var(--fab-size, 56px);
  height: var(--fab-size, 56px);
  border-radius: 50%;
  padding: 0;
  z-index: var(--z-fab, 1000);
  box-shadow: var(--fab-shadow, 0 4px 12px rgba(0, 0, 0, 0.15));
  transition: all var(--fab-transition-duration, 0.3s) var(--fab-transition-easing, ease);

  &:hover {
    transform: var(--fab-hover-transform, translateY(-2px));
    box-shadow: var(--fab-hover-shadow, 0 6px 20px rgba(0, 0, 0, 0.2));
  }

  &.btn-fab-mini {
    --fab-size: 40px;
    --fab-bottom: 16px;
    --fab-right: 16px;
  }

  &.btn-fab-extended {
    width: auto;
    min-width: var(--fab-extended-min-width, 120px);
    border-radius: var(--fab-extended-radius, 28px);
    padding: var(--fab-extended-padding, 0 20px);
    gap: var(--fab-extended-gap, 8px);
  }
}

// BUTTON ICON HANDLING
.btn-icon {
  width: var(--btn-icon-size, 24px);
  height: var(--btn-icon-size, 24px);
  flex-shrink: 0;

  &.btn-icon-start {
    margin-right: var(--btn-icon-spacing, 8px);
    margin-left: calc(var(--btn-icon-spacing, 8px) * -0.5);
  }

  &.btn-icon-end {
    margin-left: var(--btn-icon-spacing, 8px);
    margin-right: calc(var(--btn-icon-spacing, 8px) * -0.5);
  }
}

.btn-icon-only {
  width: var(--btn-icon-only-size, 40px);
  height: var(--btn-icon-only-size, 40px);
  padding: 0;

  &.btn-sm {
    --btn-icon-only-size: 32px;
  }

  &.btn-lg {
    --btn-icon-only-size: 48px;
  }

  &.btn-xl {
    --btn-icon-only-size: 56px;
  }
}

// BUTTON STATES
.btn-loading-spinner {
  display: inline-block;
  width: var(--spinner-size, 16px);
  height: var(--spinner-size, 16px);
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: btn-spin var(--spinner-duration, 1s) linear infinite;
}

@keyframes btn-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// RIPPLE EFFECT (Structure only)
.btn-ripple {
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    background: var(--btn-ripple-color, rgba(255, 255, 255, 0.3));
  }

  &:active::before {
    width: 300px;
    height: 300px;
  }
}

// TOGGLE BUTTON
.btn-toggle {
  &.btn-toggle-active {
    // Active state handled by theme
  }

  &[aria-pressed="true"] {
    // Pressed state handled by theme
  }
}

// DROPDOWN BUTTON
.btn-dropdown {
  .dropdown-caret {
    margin-left: var(--dropdown-caret-spacing, 8px);
    transition: transform var(--dropdown-transition-duration, 0.2s);
  }

  &.dropdown-open .dropdown-caret {
    transform: rotate(180deg);
  }
}

// RESPONSIVE BUTTON ADJUSTMENTS
@media (max-width: 576px) {
  .btn {
    --btn-padding: 10px 20px;
    --btn-font-size: 0.875rem;
  }

  .btn-block-mobile {
    display: flex;
    width: 100%;
  }

  .btn-fab {
    --fab-size: 48px;
    --fab-bottom: 16px;
    --fab-right: 16px;
  }
}

// ACCESSIBILITY IMPROVEMENTS
@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }

  .btn-fab {
    transition: none;
    
    &:hover {
      transform: none;
    }
  }

  .btn-loading-spinner {
    animation: none;
  }
}

// HIGH CONTRAST MODE
@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }

  .btn:focus {
    outline: 3px solid;
    outline-offset: 3px;
  }
}