@use 'ui-design-system/src/styles/semantic' as *;
.ui-table-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  position: relative;

  // Size variants
  &--small {
    gap: 0.125rem;
  }

  &--medium {
    gap: 0.25rem;
  }

  &--large {
    gap: 0.375rem;
  }

  // Layout modifiers
  &--compact {
    gap: 0.125rem;

    .ui-table-action {
      min-width: auto;
    }
  }

  &--with-labels {
    gap: 0.5rem;
  }
}

.ui-table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.375rem;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  background: transparent;
  color: hsl(287, 12%, 47%);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: all 150ms cubic-bezier(0, 0, 0.2, 1);
  min-width: 2rem;
  min-height: 2rem;
  position: relative;
  user-select: none;

  &:hover:not(:disabled) {
    background: hsl(289, 14%, 96%);
    color: hsl(279, 14%, 11%);
    transform: scale(1.05);
  }

  &:active:not(:disabled) {
    transform: scale(0.98);
  }

  &:focus-visible {
    outline: 2px solid hsl(258, 100%, 47%);
    outline-offset: 1px;
  }

  // Action variants
  &--edit {
    color: hsl(207, 90%, 45%);

    &:hover:not(:disabled) {
      background: hsl(207, 90%, 95%);
      color: hsl(207, 90%, 35%);
      border-color: hsl(207, 90%, 80%);
    }
  }

  &--delete {
    color: hsl(0, 84%, 45%);

    &:hover:not(:disabled) {
      background: hsl(0, 84%, 95%);
      color: hsl(0, 84%, 35%);
      border-color: hsl(0, 84%, 80%);
    }
  }

  &--view {
    color: hsl(142, 76%, 45%);

    &:hover:not(:disabled) {
      background: hsl(142, 76%, 95%);
      color: hsl(142, 76%, 35%);
      border-color: hsl(142, 76%, 80%);
    }
  }

  &--download {
    color: hsl(45, 93%, 45%);

    &:hover:not(:disabled) {
      background: hsl(45, 93%, 95%);
      color: hsl(45, 93%, 35%);
      border-color: hsl(45, 93%, 80%);
    }
  }

  &--custom {
    color: hsl(258, 100%, 47%);

    &:hover:not(:disabled) {
      background: hsl(263, 100%, 95%);
      color: hsl(258, 100%, 35%);
      border-color: hsl(263, 100%, 80%);
    }
  }

  // Size variants
  .ui-table-actions--small & {
    padding: 0.25rem;
    min-width: 1.5rem;
    min-height: 1.5rem;
    font-size: 0.75rem;

    .ui-table-action__icon {
      font-size: 0.75rem;
    }
  }

  .ui-table-actions--large & {
    padding: 0.5rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    font-size: 1rem;

    .ui-table-action__icon {
      font-size: 1rem;
    }
  }

  // States
  &--disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
  }

  &--active {
    background: hsl(289, 14%, 90%);
    color: hsl(279, 14%, 11%);
    border-color: hsl(289, 14%, 80%);
  }

  // More button specific styles
  &--more {
    color: hsl(287, 12%, 47%);

    &:hover:not(:disabled) {
      background: hsl(289, 14%, 90%);
      color: hsl(279, 14%, 11%);
    }

    &.ui-table-action--active {
      background: hsl(258, 100%, 95%);
      color: hsl(258, 100%, 47%);
      border-color: hsl(258, 100%, 80%);
    }
  }
}

.ui-table-action__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  line-height: 1;
  flex-shrink: 0;

  // Icon-only adjustments
  .ui-table-actions:not(.ui-table-actions--with-labels) & {
    margin: 0;
  }
}

.ui-table-action__label {
  font-size: 0.8125rem;
  white-space: nowrap;
  flex-shrink: 0;

  // Hide labels by default, show when --with-labels
  .ui-table-actions:not(.ui-table-actions--with-labels) & {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

// Dropdown styles
.ui-table-actions__dropdown {
  position: relative;
  display: inline-flex;
}

.ui-table-actions__dropdown-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  min-width: 10rem;
  background: hsl(286, 20%, 99%);
  border: 1px solid hsl(289, 14%, 80%);
  border-radius: 0.375rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  padding: 0.25rem;
  z-index: 50;
  animation: dropdown-appear 150ms cubic-bezier(0, 0, 0.2, 1);

  // Ensure dropdown is on top
  &::before {
    content: '';
    position: absolute;
    top: -0.25rem;
    right: 0.75rem;
    width: 0;
    height: 0;
    border-left: 0.25rem solid transparent;
    border-right: 0.25rem solid transparent;
    border-bottom: 0.25rem solid hsl(289, 14%, 80%);
  }

  &::after {
    content: '';
    position: absolute;
    top: -0.1875rem;
    right: 0.8125rem;
    width: 0;
    height: 0;
    border-left: 0.1875rem solid transparent;
    border-right: 0.1875rem solid transparent;
    border-bottom: 0.1875rem solid hsl(286, 20%, 99%);
  }
}

.ui-table-actions__dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 0.25rem;
  background: transparent;
  color: hsl(279, 14%, 11%);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms ease;

  &:hover:not(:disabled) {
    background: hsl(289, 14%, 96%);
  }

  &:focus-visible {
    outline: 2px solid hsl(258, 100%, 47%);
    outline-offset: -2px;
  }

  &:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .ui-table-action__icon {
    font-size: 0.875rem;
  }

  .ui-table-action__label {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: none;
  }
}

// Animation for dropdown
@keyframes dropdown-appear {
  0% {
    opacity: 0;
    transform: translateY(-0.25rem) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

// Tooltip support (when labels are hidden)
.ui-table-actions:not(.ui-table-actions--with-labels) {
  .ui-table-action {
    position: relative;

    &[title]:hover::after {
      content: attr(title);
      position: absolute;
      bottom: calc(100% + 0.5rem);
      left: 50%;
      transform: translateX(-50%);
      padding: 0.375rem 0.5rem;
      background: hsl(279, 14%, 11%);
      color: white;
      font-size: 0.75rem;
      white-space: nowrap;
      border-radius: 0.25rem;
      z-index: 100;
      animation: tooltip-appear 150ms ease-out;
    }

    &[title]:hover::before {
      content: '';
      position: absolute;
      bottom: calc(100% + 0.125rem);
      left: 50%;
      transform: translateX(-50%);
      width: 0;
      height: 0;
      border-left: 0.25rem solid transparent;
      border-right: 0.25rem solid transparent;
      border-top: 0.25rem solid hsl(279, 14%, 11%);
      z-index: 100;
    }
  }
}

@keyframes tooltip-appear {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(0.125rem);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

// Responsive design
@media (max-width: 640px) {
  .ui-table-actions {
    &--with-labels .ui-table-action__label {
      display: none;
    }

    &--with-labels {
      gap: 0.25rem;
    }
  }
}

// High contrast mode
@media (prefers-contrast: high) {
  .ui-table-action {
    border: 1px solid;

    &:hover:not(:disabled) {
      border-width: 2px;
    }
  }

  .ui-table-actions__dropdown-menu {
    border-width: 2px;
  }
}

// Reduced motion
@media (prefers-reduced-motion: reduce) {
  .ui-table-action,
  .ui-table-actions__dropdown-menu,
  .ui-table-actions__dropdown-item {
    transition: none;
  }

  .ui-table-actions__dropdown-menu {
    animation: none;
  }
}