/* ═══════════════════════════════════════════════════
   MULTI-SELECT.CSS — toggleselect component
   Requires base.css variables to be loaded first.
   MineMev gaming/editorial aesthetic.
   ═══════════════════════════════════════════════════ */

/* ── Outer wrapper ───────────────────────────────── */
.custom-select-wrapper {
  position: relative;   /* ← scopes the absolute dropdown to THIS instance */
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  font-family: var(--font-body);
}

.custom-select-wrapper.ts-disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* ── Top row: tags area + toggle button ──────────── */
.ts-top-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

/* ── Selected items area ────────────────────────── */
.ts-selected-items {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: 38px;
  padding: 4px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.custom-select-wrapper:not(.ts-disabled) .ts-selected-items:hover {
  border-color: var(--border-focus);
  background: var(--bg-overlay);
}

/* Highlight the tags area when dropdown is open */
.custom-select-wrapper:has(.ts-toggle-button.ts-open) .ts-selected-items {
  border-color: var(--accent-dim);
}

/* ── Placeholder ─────────────────────────────────── */
.ts-placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  user-select: none;
}

/* ── Selected tag ────────────────────────────────── */
.ts-selected-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 9px;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-primary);
  letter-spacing: 0.02em;
  line-height: 1.6;
  transition: border-color var(--transition), background var(--transition);
  /* sharp left accent stripe */
  border-left: 2px solid var(--accent-dim);
}

.ts-selected-item.ts-custom-tag {
  border-left-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
}

.ts-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  font-size: 0.6rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 2px;
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}

.ts-remove:hover {
  color: var(--danger);
  background: rgba(255,64,64,0.12);
}

/* ── Count badge ─────────────────────────────────── */
.ts-count-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--accent);
  letter-spacing: 0.06em;
  font-weight: 500;
}

/* ── Toggle button ───────────────────────────────── */
.ts-toggle-button {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition);
  color: var(--text-secondary);
}

.ts-toggle-button svg {
  fill: currentColor;
  transition: transform var(--transition);
}

.ts-toggle-button:hover {
  background: var(--bg-overlay);
  border-color: var(--border-focus);
  color: var(--accent);
}

.ts-toggle-button.ts-open {
  border-color: var(--accent-dim);
  background: var(--accent-subtle);
  color: var(--accent);
}

.ts-toggle-button.ts-open svg {
  transform: rotate(180deg);
}

/* ── Dropdown wrapper ────────────────────────────── */
/*
 * State is controlled by the --closed modifier class ONLY.
 * Never toggle display on child elements to avoid state confusion
 * across multiple instances on the same page.
 */
.ts-dropdown-wrapper {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.5),
    0 0 0 1px rgba(127,255,0,0.04),
    inset 0 1px 0 rgba(255,255,255,0.03);
  animation: ts-dropdown-in 0.14s ease;
}

/* CLOSED state — hidden but not removed from the DOM */
.ts-dropdown-wrapper--closed {
  display: none;
  /* Using display:none (not visibility:hidden) so it takes no space
     and cannot intercept pointer events from adjacent instances */
}

@keyframes ts-dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Search bar ──────────────────────────────────── */
.ts-search-bar {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-raised);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  outline: none;
  transition: background var(--transition);
}

.ts-search-bar::placeholder { color: var(--text-muted); }

.ts-search-bar:focus {
  background: var(--bg-overlay);
  border-bottom-color: var(--accent-dim);
}

/* ── Bulk actions bar ────────────────────────────── */
.ts-bulk-actions {
  display: flex;
  gap: 1px;
  padding: 5px 8px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border);
}

.ts-bulk-btn {
  flex: 1;
  padding: 4px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}

.ts-bulk-btn:hover {
  color: var(--accent);
  background: var(--accent-subtle);
  border-color: var(--accent-dim);
}

/* ── Options list ────────────────────────────────── */
.ts-options-list {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  gap: 1px;
}

/* ── Option item ─────────────────────────────────── */
.ts-option-item {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-family: var(--font-body);
  color: var(--text-secondary);
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition),
    padding-left var(--transition);
  letter-spacing: 0.01em;
}

.ts-option-item:hover {
  background: var(--bg-raised);
  border-color: var(--border);
  color: var(--text-primary);
  padding-left: 14px;
}

.ts-option-item.ts-focused {
  background: var(--bg-overlay);
  border-color: var(--border-focus);
  color: var(--text-primary);
  outline: none;
}

.ts-option-disabled {
  color: var(--text-muted) !important;
  cursor: not-allowed !important;
  pointer-events: none;
}

/* ── Custom option in list ───────────────────────── */
.ts-custom-option {
  color: var(--accent-dim);
}

.ts-custom-option::before {
  content: '✦';
  font-size: 0.55rem;
  margin-right: 7px;
  opacity: 0.7;
  color: var(--accent-dim);
}

/* ── Add custom row ──────────────────────────────── */
.ts-add-custom {
  border-style: dashed !important;
  border-color: var(--border) !important;
  color: var(--accent-dim) !important;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  gap: 6px;
}

.ts-add-custom:hover {
  background: var(--accent-subtle) !important;
  border-color: var(--accent-dim) !important;
  color: var(--accent) !important;
}

.ts-add-custom em {
  font-style: normal;
  font-weight: 500;
  color: inherit;
}

.ts-add-icon {
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
  font-style: normal;
}

/* ── Empty / loading / error states ─────────────── */
.ts-empty,
.ts-loading {
  padding: 12px 14px;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-align: center;
}

.ts-loading::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: ts-pulse 0.8s ease-in-out infinite alternate;
  vertical-align: middle;
}

@keyframes ts-pulse {
  from { opacity: 0.2; transform: scale(0.8); }
  to   { opacity: 1;   transform: scale(1.2); }
}

.ts-error { color: var(--danger) !important; }

/* ── Inline validation error ─────────────────────── */
.ts-custom-error {
  padding: 6px 10px;
  background: rgba(255,64,64,0.08);
  border: 1px solid rgba(255,64,64,0.25);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--danger);
  letter-spacing: 0.03em;
  margin: 4px;
  animation: ts-shake 0.25s ease;
}

@keyframes ts-shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}