/**
 * @file
 * FlowDrop Plugin Selector Component Styles
 *
 * A grid-based plugin selector with provider grouping.
 * Uses FlowDrop design tokens for consistent styling.
 */

/* ========================================================================
 * CONTAINER
 * ======================================================================== */

.fd-plugin-selector {
  display: flex;
  flex-direction: column;
  gap: var(--fd-space-4);
}

/* ========================================================================
 * SEARCH
 * ======================================================================== */

.fd-plugin-selector__search {
  position: sticky;
  top: 0;
  z-index: 1;
  padding-block: var(--fd-space-2);
  background-color: var(--fd-background);
}

.fd-plugin-selector__search-input {
  width: 100%;
  padding: var(--fd-space-3) var(--fd-space-4);
  border: var(--fd-border-width) solid var(--fd-border);
  border-radius: var(--fd-radius-lg);
  background-color: var(--fd-card);
  color: var(--fd-foreground);
  font-size: var(--fd-text-base);
}

.fd-plugin-selector__search-input:focus {
  outline: none;
  border-color: var(--fd-primary);
  box-shadow: 0 0 0 1px var(--fd-primary);
}

.fd-plugin-selector__no-results {
  padding: var(--fd-space-6);
  text-align: center;
  color: var(--fd-muted-foreground);
  font-size: var(--fd-text-sm);
}

/* ========================================================================
 * PROVIDER GROUP
 * ======================================================================== */

.fd-plugin-selector__group {
  overflow: hidden;
  border: var(--fd-border-width) solid var(--fd-border);
  border-radius: var(--fd-radius-xl);
  background-color: var(--fd-card);
}

.fd-plugin-selector__group-header {
  display: flex;
  width: 100%;
  align-items: center;
  gap: var(--fd-space-3);
  padding: var(--fd-space-4) var(--fd-space-5);
  border: 0;
  border-block-end: var(--fd-border-width) solid var(--fd-border);
  background-color: var(--fd-muted);
  cursor: pointer;
  text-align: start;
  font: inherit;
  appearance: none;
}

.fd-plugin-selector__group-header:hover {
  background-color: var(--fd-subtle);
}

.fd-plugin-selector__group-header:focus-visible {
  outline: 2px solid var(--fd-ring);
  outline-offset: -2px;
}

/* Collapsed group: header is the only visible element, so drop its border. */
.fd-plugin-selector__group-header[aria-expanded="false"] {
  border-block-end-color: transparent;
}

.fd-plugin-selector__group-chevron {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-inline-end: 2px solid var(--fd-muted-foreground);
  border-block-end: 2px solid var(--fd-muted-foreground);
  transform: rotate(-45deg);
  transition: transform var(--fd-transition-fast);
}

.fd-plugin-selector__group-header[aria-expanded="true"] .fd-plugin-selector__group-chevron {
  transform: rotate(45deg);
}

.fd-plugin-selector__group-title {
  flex: 1;
  margin: 0;
  color: var(--fd-primary);
  font-size: var(--fd-text-base);
  font-weight: var(--fd-font-weight-semibold);
}

.fd-plugin-selector__group-count {
  padding: var(--fd-space-1) var(--fd-space-2);
  color: var(--fd-muted-foreground);
  border-radius: var(--fd-radius-full);
  background-color: var(--fd-subtle);
  font-size: var(--fd-text-sm);
}

.fd-plugin-selector__group-content {
  padding: var(--fd-space-4);
}

/* ========================================================================
 * PLUGIN GRID
 * ======================================================================== */

.fd-plugin-selector__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--fd-space-4);
  align-items: stretch;
}

/* Grid cell wrapping a selectable card + its (non-selectable) usage summary. */
.fd-plugin-selector__item {
  display: flex;
  flex-direction: column;
}

.fd-plugin-selector__item[hidden] {
  display: none;
}

/* Let the card fill the cell so usage summaries line up across the row. */
.fd-plugin-selector__item .fd-plugin-selector__card {
  flex: 1;
}

/* ========================================================================
 * PLUGIN CARD
 * ======================================================================== */

.fd-plugin-selector__card {
  position: relative;
  display: flex;
  align-items: stretch;
  padding: var(--fd-space-4);
  cursor: pointer;
  transition:
    border-color var(--fd-transition-fast),
    box-shadow var(--fd-transition-fast),
    background-color var(--fd-transition-fast);
  border: var(--fd-border-width) solid var(--fd-border);
  border-radius: var(--fd-radius-lg);
  background-color: var(--fd-background);
  gap: var(--fd-space-3);
}

.fd-plugin-selector__card:hover {
  border-color: var(--fd-primary);
  box-shadow: var(--fd-shadow-sm);
}

/* Selected state */
.fd-plugin-selector__card--selected {
  border-color: var(--fd-primary);
  background-color: var(--fd-primary-muted);
  box-shadow: 0 0 0 1px var(--fd-primary);
}

/* Focus state for accessibility */
.fd-plugin-selector__card:focus-within {
  outline: 2px solid var(--fd-ring);
  outline-offset: 2px;
}

/* ========================================================================
 * RADIO INPUT
 * ======================================================================== */

.fd-plugin-selector__radio {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  opacity: 0;
}

/* ========================================================================
 * RADIO INDICATOR
 * ======================================================================== */

.fd-plugin-selector__indicator {
  display: flex;
  flex-shrink: 0;
  align-self: flex-start;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-block-start: 0.125rem;
  transition:
    border-color var(--fd-transition-fast),
    background-color var(--fd-transition-fast);
  border: 2px solid var(--fd-border-strong);
  border-radius: var(--fd-radius-full);
  background-color: var(--fd-background);
}

.fd-plugin-selector__indicator::after {
  width: 0.5rem;
  height: 0.5rem;
  content: "";
  transition: background-color var(--fd-transition-fast);
  border-radius: var(--fd-radius-full);
  background-color: transparent;
}

/* Hover state */
.fd-plugin-selector__card:hover .fd-plugin-selector__indicator {
  border-color: var(--fd-primary);
}

/* Selected state */
.fd-plugin-selector__card--selected .fd-plugin-selector__indicator {
  border-color: var(--fd-primary);
}

.fd-plugin-selector__card--selected .fd-plugin-selector__indicator::after {
  background-color: var(--fd-primary);
}

/* ========================================================================
 * CARD CONTENT
 * ======================================================================== */

.fd-plugin-selector__content {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.fd-plugin-selector__title {
  margin: 0;
  color: var(--fd-foreground);
  font-size: var(--fd-text-sm);
  font-weight: var(--fd-font-weight-semibold);
  line-height: var(--fd-line-height-normal);
}

/* Capability tags row, pinned to the bottom of the card for consistency. */
.fd-plugin-selector__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--fd-space-1);
  margin-block-start: auto;
  padding-block-start: var(--fd-space-3);
}

/* Capability tag (gateway, trigger, …) marking non-default node processors. */
.fd-plugin-selector__tag {
  display: inline-block;
  padding: 0 var(--fd-space-2);
  border-radius: var(--fd-radius-full);
  background-color: var(--fd-subtle);
  color: var(--fd-muted-foreground);
  font-size: var(--fd-text-xs);
  font-weight: var(--fd-font-weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
}

/* Gateway is a structural type, not a caution — keep the neutral base style. */

.fd-plugin-selector__tag--trigger {
  background-color: var(--fd-primary-muted);
  color: var(--fd-primary);
}

/* Side effects mutate external state, so flag them with a caution color. */
.fd-plugin-selector__tag--side-effects {
  background-color: var(--fd-warning-muted, var(--fd-primary-muted));
  color: var(--fd-warning, var(--fd-primary));
}

.fd-plugin-selector__description {
  display: -webkit-box;
  overflow: hidden;
  margin: var(--fd-space-1) 0 0;
  color: var(--fd-muted-foreground);
  font-size: var(--fd-text-xs);
  line-height: var(--fd-line-height-normal);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ========================================================================
 * USAGE SUMMARY (outside the card click area, attached below it)
 * ======================================================================== */

.fd-plugin-selector__usage {
  padding: var(--fd-space-1) var(--fd-space-2) 0;
  font-size: var(--fd-text-xs);
}

.fd-plugin-selector__usage-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--fd-space-1);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--fd-foreground);
  font: inherit;
  font-weight: var(--fd-font-weight-semibold);
}

.fd-plugin-selector__usage-toggle:hover {
  color: var(--fd-primary);
}

.fd-plugin-selector__usage-toggle:focus-visible {
  outline: 2px solid var(--fd-ring);
  outline-offset: 2px;
  border-radius: var(--fd-radius-sm);
}

.fd-plugin-selector__usage-chevron {
  width: 0.4rem;
  height: 0.4rem;
  border-inline-end: 1.5px solid currentColor;
  border-block-end: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--fd-transition-fast);
}

.fd-plugin-selector__usage-toggle[aria-expanded="true"] .fd-plugin-selector__usage-chevron {
  transform: rotate(45deg);
}

.fd-plugin-selector__usage-list {
  margin: var(--fd-space-1) 0 0;
  padding-inline-start: var(--fd-space-5);
  color: var(--fd-muted-foreground);
}

.fd-plugin-selector__usage-list li {
  line-height: var(--fd-line-height-normal);
}

.fd-plugin-selector__usage-link {
  color: var(--fd-muted-foreground);
  text-decoration: underline;
}

.fd-plugin-selector__usage-link:hover {
  color: var(--fd-primary);
}

/* ========================================================================
 * STAGGER ANIMATION
 * ======================================================================== */

@keyframes fd-plugin-fade-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.fd-plugin-selector--stagger .fd-plugin-selector__item {
  animation: fd-plugin-fade-in var(--fd-transition-normal) ease-out backwards;
}

.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(1) {
  animation-delay: 0ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(2) {
  animation-delay: 30ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(3) {
  animation-delay: 60ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(4) {
  animation-delay: 90ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(5) {
  animation-delay: 120ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(6) {
  animation-delay: 150ms;
}
.fd-plugin-selector--stagger .fd-plugin-selector__item:nth-child(n + 7) {
  animation-delay: 180ms;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .fd-plugin-selector--stagger .fd-plugin-selector__item {
    animation: none;
  }
}

/* ========================================================================
 * RESPONSIVE ADJUSTMENTS
 * ======================================================================== */

@media (max-width: 640px) {
  .fd-plugin-selector__grid {
    grid-template-columns: 1fr;
    gap: var(--fd-space-3);
  }

  .fd-plugin-selector__group-header {
    padding: var(--fd-space-3) var(--fd-space-4);
  }

  .fd-plugin-selector__group-content {
    padding: var(--fd-space-3);
  }

  .fd-plugin-selector__card {
    padding: var(--fd-space-3);
  }

  .fd-plugin-selector__description {
    -webkit-line-clamp: 3;
  }
}

/* ========================================================================
 * EMPTY STATE
 * ======================================================================== */

.fd-plugin-selector__empty {
  padding: var(--fd-space-8);
  text-align: center;
  color: var(--fd-muted-foreground);
  font-size: var(--fd-text-sm);
}
