/**
 * iNKPPL Design System — .ds-listbox primitive
 * Custom combobox/listbox (WAI-ARIA 1.2 pattern) with mono-caps typography.
 *
 * SPEC: docs/specs/.1-impl.md §19 (Founder decision B1, 2026-05-11)
 * Pairs with: inked/assets/js/design-system/ds-listbox.js
 * Initial consumer: Afisha v2.1 filter rail (country / city / type / price).
 * retrofit candidate: tattoos-v2 / studios-v2 / masters-v2 .filter-bar__select.
 *
 * Anatomy (§19.2 / §19.3):
 *   .ds-listbox (host, data-ds-listbox)
 *     .ds-listbox__trigger  (button role=combobox)
 *       .ds-listbox__bullet (•)
 *       .ds-listbox__label  (e.g. "COUNTRY")
 *       .ds-listbox__value  (e.g. "All · 89")
 *       .ds-listbox__caret  (▾)
 *     .ds-listbox__list     (ul role=listbox, hidden when closed)
 *       .ds-listbox__option (li role=option)
 *     .ds-listbox__native   (progressive-enhancement <select>, hidden)
 *     .ds-listbox__empty    (no-match state)
 *
 * Tokens-only. Dark theme default + light theme override.
 * Mobile <640px: trigger remains; JS swaps popover for ds-sheet (§19.6).
 */

/* ============================================================================
   Host
   ============================================================================ */
.ds-listbox {
  position: relative;
  display: inline-block;
  font-family: var(--font-mono);
}

/* ============================================================================
   Trigger — mono caps button with bullet + label + value + caret
   ============================================================================ */
.ds-listbox__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 44px; /* a11y touch target */
  padding: var(--space-2) var(--space-3);
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-caps);
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: border-color var(--transition-fast), color var(--transition-fast), background-color var(--transition-fast);
}
.ds-listbox__trigger:hover {
  border-color: var(--color-border-hover);
}
.ds-listbox__trigger:focus-visible {
  outline: 2px solid var(--color-brand-accent);
  outline-offset: 2px;
}
.ds-listbox__trigger[aria-expanded="true"] {
  border-color: var(--color-brand-accent);
  color: var(--color-brand-accent);
}

.ds-listbox__bullet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 8px;
  color: var(--color-brand-accent);
  font-size: var(--text-xs);
  line-height: 1;
  flex-shrink: 0;
}
.ds-listbox__label {
  color: inherit;
  flex-shrink: 0;
}
.ds-listbox__value {
  color: var(--color-text-secondary);
  margin-left: var(--space-1);
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: none; /* counts like "All · 89" not all-caps */
  letter-spacing: 0;
  font-weight: var(--font-weight-normal);
}
.ds-listbox__caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  line-height: 1;
  flex-shrink: 0;
  transition: transform var(--transition-fast), color var(--transition-fast);
}
.ds-listbox__trigger[aria-expanded="true"] .ds-listbox__caret {
  transform: rotate(180deg);
  color: var(--color-brand-accent);
}

/* ============================================================================
   Popover list — positioned below (or above via .is-above)
   ============================================================================ */
.ds-listbox__list {
  position: absolute;
  left: 0;
  top: calc(100% + var(--space-1));
  z-index: var(--z-dropdown);
  min-width: 100%;
  max-height: 360px;
  margin: 0;
  padding: var(--space-1) 0;
  list-style: none;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.ds-listbox__list[hidden] {
  display: none;
}
/* Flip above when not enough room below (JS toggles .is-above) */
.ds-listbox__list.is-above {
  top: auto;
  bottom: calc(100% + var(--space-1));
}

/* ============================================================================
   Option
   ============================================================================ */
.ds-listbox__option {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 44px; /* touch target */
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-caps);
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.ds-listbox__option:hover {
  background: var(--color-bg-hover);
}
.ds-listbox__option.is-focused {
  background: var(--color-bg-hover);
  color: var(--color-brand-accent);
  outline: none;
}
.ds-listbox__option[aria-selected="true"] {
  color: var(--color-brand-accent);
}
.ds-listbox__option[aria-selected="true"]::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 60%;
  background: var(--color-brand-accent);
}

/* ============================================================================
   Native select (progressive enhancement fallback) — visually hidden
   ============================================================================ */
.ds-listbox__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================================
   Empty state — "No matches" centered
   ============================================================================ */
.ds-listbox__empty {
  padding: var(--space-4) var(--space-3);
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-caps);
  color: var(--color-text-muted);
}

/* ============================================================================
   Mobile (<640px) — hide popover; JS opens via ds-sheet instead
   ============================================================================ */
@media (max-width: 639.98px) {
  .ds-listbox__list {
    display: none !important;
  }
}

/* ============================================================================
   Light theme
   ============================================================================ */
[data-theme="light"] .ds-listbox__list,
:root.light-theme .ds-listbox__list {
  background: var(--color-bg-card);
}

/* ============================================================================
   Reduced motion
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
  .ds-listbox__caret,
  .ds-listbox__option,
  .ds-listbox__trigger {
    transition: none;
  }
}
