/* ==========================================================================
   Component: Listings
   .listing-item, .listing__price, .listing__avatar, interactive states.
   For NFT/token listing rows in the main content area.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Scale levels for listings (applied via data-scale on #listingsContainer)
   --------------------------------------------------------------------------- */
#listingsContainer[data-scale="0"] { --listing-thumb: 20px; }
#listingsContainer[data-scale="1"] { --listing-thumb: 32px; }
#listingsContainer[data-scale="2"] { --listing-thumb: 48px; }
#listingsContainer[data-scale="3"] { --listing-thumb: 64px; }

#listingsContainer .nft-avatar {
  width: var(--listing-thumb, 32px);
  height: var(--listing-thumb, 32px);
}

/* ---------------------------------------------------------------------------
   Listings Container
   --------------------------------------------------------------------------- */
.listings {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background-color: var(--border-muted);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ---------------------------------------------------------------------------
   Listing Item — individual row
   --------------------------------------------------------------------------- */
.listing-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background-color: var(--bg-surface);
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast);
  position: relative;
  min-height: 56px;
}

.listing-item:hover {
  background-color: var(--bg-elevated);
}

.listing-item:active {
  background-color: var(--bg-overlay);
}

/* ---------------------------------------------------------------------------
   Avatar / Image
   --------------------------------------------------------------------------- */
.listing__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  overflow: hidden;
  flex-shrink: 0;
  background-color: var(--bg-elevated);
  position: relative;
}

.listing__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.listing__avatar--sm {
  width: 32px;
  height: 32px;
}

/* Rarity border ring on avatar */
.listing__avatar--rare {
  box-shadow: 0 0 0 2px hsl(210, 70%, 56%);
}

.listing__avatar--epic {
  box-shadow: 0 0 0 2px hsl(270, 60%, 60%);
}

.listing__avatar--legendary {
  box-shadow: 0 0 0 2px hsl(40, 90%, 60%);
}

/* ---------------------------------------------------------------------------
   Listing Info (name, collection, metadata)
   --------------------------------------------------------------------------- */
.listing__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.listing__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listing__collection {
  font-size: var(--text-xs);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listing__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 2px;
}

/* ---------------------------------------------------------------------------
   Price
   --------------------------------------------------------------------------- */
.listing__price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.listing__price-value {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  white-space: nowrap;
}

.listing__price-usd {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Price change indicator */
.listing__price-change {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.listing__price-change--up {
  color: var(--color-success);
}

.listing__price-change--down {
  color: var(--color-error);
}

/* ---------------------------------------------------------------------------
   Buy Button — transparent with teal glow on hover
   --------------------------------------------------------------------------- */
.buy-button {
  flex-shrink: 0;
  width: 60px;
  padding: 4px 0;
  border: 1px solid hsla(170, 80%, 50%, 0.2);
  border-radius: 6px;
  background: hsla(170, 80%, 50%, 0.08);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all 0.15s ease;
}

.buy-button:hover {
  background: var(--accent);
  color: var(--bg-base);
  border-color: var(--accent);
  box-shadow: 0 0 12px hsla(170, 80%, 50%, 0.25);
}

.buy-button:active {
  transform: scale(0.95);
}

.buy-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

/* ---------------------------------------------------------------------------
   Action / Buy button area
   --------------------------------------------------------------------------- */
.listing__action {
  flex-shrink: 0;
  margin-left: var(--space-2);
}

/* ---------------------------------------------------------------------------
   Interactive States
   --------------------------------------------------------------------------- */

/* Selected — user clicked to select */
.listing-item.is-selected {
  background-color: var(--accent-subtle);
  box-shadow: inset 3px 0 0 var(--accent);
}

.listing-item.is-selected .listing__name {
  color: var(--accent);
}

/* Buying — purchase in progress */
.listing-item.is-buying {
  position: relative;
  background: linear-gradient(135deg, hsl(32, 30%, 10%) 0%, hsl(32, 20%, 8%) 100%);
  box-shadow:
    inset 3px 0 0 hsl(32, 85%, 56%),
    0 0 12px hsla(32, 80%, 50%, 0.1);
  pointer-events: none;
  border: 1px solid hsla(32, 60%, 40%, 0.3);
  border-left: none;
}

.listing-item.is-buying .price-value {
  color: hsl(32, 85%, 65%);
}

.listing-item.is-buying .buy-button {
  background: hsla(32, 40%, 18%, 0.9);
  color: hsl(32, 80%, 65%);
  border-color: hsla(32, 50%, 40%, 0.5);
  cursor: wait;
}

.listing-item.is-buying::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, hsla(32, 80%, 50%, 0.08), hsla(32, 80%, 50%, 0.03));
  animation: buying-progress 8s ease-out forwards;
  pointer-events: none;
  z-index: 0;
}

.listing-item.is-buying::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    hsla(32, 80%, 50%, 0.06) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: buying-shimmer 1.8s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes buying-progress {
  0%   { width: 0%; }
  100% { width: 100%; }
}

@keyframes buying-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Bought — successfully purchased */
.listing-item.is-bought {
  background-color: var(--color-success-bg);
  box-shadow: inset 3px 0 0 var(--color-success);
  opacity: 0.65;
  pointer-events: none;
}

/* Failed */
.listing-item.is-failed {
  background-color: var(--color-error-bg);
  box-shadow: inset 3px 0 0 var(--color-error);
}

/* New listing highlight — fade in */
.listing-item.is-new {
  animation: listing-fade-in var(--duration-slow) var(--ease-out);
}

@keyframes listing-fade-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
    background-color: var(--accent-subtle);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    background-color: var(--bg-surface);
  }
}

/* ---------------------------------------------------------------------------
   Listings Grid (card layout alternative)
   --------------------------------------------------------------------------- */
.listings--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-3);
  background: transparent;
}

.listings--grid .listing-item {
  flex-direction: column;
  align-items: stretch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-muted);
  padding: var(--space-3);
}

.listings--grid .listing__avatar {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
}

.listings--grid .listing__price {
  align-items: flex-start;
  margin-top: var(--space-2);
}

/* ---------------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------------- */
.listings__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-4);
  color: var(--text-muted);
  text-align: center;
  gap: var(--space-2);
}

.listings__empty-icon {
  font-size: var(--text-2xl);
  opacity: 0.4;
}

.listings__empty-text {
  font-size: var(--text-sm);
}

/* ---------------------------------------------------------------------------
   Reduced motion
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .listing-item,
  .listing-item.is-new {
    transition: none;
    animation: none;
  }

  .listing-item.is-buying::before,
  .listing-item.is-buying::after {
    animation: none;
  }
}
