/**
 * TagInput styles
 * @countermeasure/web-components/form/tag-input
 */

/* ==========================================================================
   TagInput Root
   ========================================================================== */

.cmm-tag-input {
  position: relative;
  display: inline-block;
  width: 100%;
}

/* ==========================================================================
   Container - looks like a single input field
   ========================================================================== */

.cmm-tag-input__container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.5rem;
  padding: 0.375rem 0.5rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  cursor: text;
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cmm-tag-input__container:focus-within {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.2);
}

/* ==========================================================================
   Inline input
   ========================================================================== */

.cmm-tag-input__input {
  flex: 1;
  min-width: 80px;
  padding: 0.125rem 0.25rem;
  border: none;
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  outline: none;
}

.cmm-tag-input__input::placeholder {
  color: hsl(var(--foreground) / 0.72);
}

.cmm-tag-input__input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ==========================================================================
   Tag chips
   ========================================================================== */

.cmm-tag-input__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  background-color: hsl(var(--muted));
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: hsl(var(--foreground));
  max-width: 100%;
  animation: cmm-tag-enter var(--transition-fast) ease-out;
}

.cmm-tag-input__tag--colored {
  background-color: color-mix(in srgb, var(--tag-color) 15%, hsl(var(--background)));
  border: 1px solid color-mix(in srgb, var(--tag-color) 30%, transparent);
}

.cmm-tag-input__tag-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmm-tag-input__tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background-color: transparent;
  color: hsl(var(--foreground) / 0.7);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--transition-fast),
    color var(--transition-fast);
}

.cmm-tag-input__tag-remove:hover {
  background-color: hsl(var(--muted));
  color: hsl(var(--foreground));
}

.cmm-tag-input__tag--colored .cmm-tag-input__tag-remove:hover {
  background-color: color-mix(in srgb, var(--tag-color) 25%, transparent);
}

.cmm-tag-input__tag-remove:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 1px;
}

@keyframes cmm-tag-enter {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==========================================================================
   Suggestions dropdown
   ========================================================================== */

.cmm-tag-input__dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: var(--z-dropdown);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 12rem;
  overflow-y: auto;
  padding: 0.25rem;
}

.cmm-tag-input__option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.cmm-tag-input__option:hover {
  background-color: hsl(var(--accent));
}

.cmm-tag-input__option--highlighted {
  background-color: hsl(var(--accent));
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -2px;
}

.cmm-tag-input__option-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.cmm-tag-input__option-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmm-tag-input__option-category {
  font-size: 0.75rem;
  color: hsl(var(--foreground) / 0.78);
  flex-shrink: 0;
}

/* ==========================================================================
   Loading state
   ========================================================================== */

.cmm-tag-input__loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  font-size: 0.8125rem;
  color: hsl(var(--foreground) / 0.78);
}

.cmm-tag-input__spinner {
  animation: cmm-tag-spin 0.8s linear infinite;
}

@keyframes cmm-tag-spin {
  to {
    transform: rotate(360deg);
  }
}
