/* ═══════════════════════════════════════════════════════════════════════════
   @nobul/ui — SearchableSelect styles (v2026.18.12)

   Adapted from recruitment/public/css/searchable-select.css (the portal
   fork's stylesheet), made token-driven:
     • accent resolves through var(--primary, var(--brand-accent)) — apps
       keep their exact colour
     • trigger is 40px by default per .docs/nobul-select-standards.md
       ("Height: 40px for normal forms; 32px for dense filters") — add
       .ss-compact on the wrapper (or pass compact: true) for 32px
     • portal dropdown layers on var(--z-dropdown) per the select standard
     • + .ss-group-header (grouped options) and .ss-error (async search
       failure state) carried over from people's Gen-1

   Requires tokens.css. Load alongside ui.css.
   ═══════════════════════════════════════════════════════════════════════ */

.ss-wrap {
  position: relative;
  display: inline-block;
  min-width: 140px;
  width: 100%;
  /* component-scoped accent resolution */
  --ss-accent: var(--primary, var(--brand-accent, var(--brand-ink)));
  --ss-ring: var(--focus-ring-rgba, rgba(15,23,42,.12));
}

/* ── Trigger (a real <button>) ──────────────── */

.ss-trigger {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font);
  font-size: var(--fs-lg);
  color: var(--text);
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  transition: border-color var(--motion-med) var(--ease), box-shadow var(--motion-med) var(--ease);
}

/* Compact — dense filters and table toolbars */
.ss-compact .ss-trigger {
  height: 32px;
  padding: 0 var(--space-2);
  font-size: var(--fs-md);
}

.ss-trigger:hover {
  border-color: var(--gray-300);
}

.ss-trigger:disabled,
.ss-disabled .ss-trigger {
  cursor: not-allowed;
  opacity: 0.5;
}

.ss-trigger:disabled:hover,
.ss-disabled .ss-trigger:hover {
  border-color: var(--gray-200);
}

.ss-trigger:focus-visible,
.ss-trigger:focus,
.ss-open .ss-trigger {
  outline: none;
  border-color: var(--ss-accent);
  box-shadow: 0 0 0 2px var(--ss-ring);
}

/* ── Display text ───────────────────────────── */

.ss-display {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  color: var(--text-muted);
}

.ss-display.ss-has-value {
  color: var(--text);
}

/* ── Pills (multi) ──────────────────────────── */

.ss-pills {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  min-width: 0;
}

.ss-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 6px;
  background: var(--gray-100);
  border-radius: 10px;
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: var(--font);
  color: var(--text);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

.ss-pill-x {
  background: none;
  border: none;
  padding: 0 1px;
  color: var(--gray-400);
  font-size: var(--fs-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color var(--motion-fast) var(--ease);
}

.ss-pill-x:hover { color: var(--danger); }

/* ── Arrow ──────────────────────────────────── */

.ss-arrow {
  flex-shrink: 0;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  transition: transform var(--motion-med) var(--ease);
  pointer-events: none;
}

.ss-open .ss-arrow {
  transform: rotate(180deg);
}

/* ── Clear affordance ───────────────────────── */

.ss-clear {
  background: none;
  border: none;
  padding: 0 2px;
  color: var(--gray-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  font-size: var(--fs-lg);
  line-height: 1;
  flex-shrink: 0;
  transition: color var(--motion-fast) var(--ease);
}

.ss-clear:hover {
  color: var(--text);
}

/* ── Dropdown panel ─────────────────────────── */

@keyframes ss-fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ss-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  /* Grows past the trigger when the options need the room (subtitles), never
     narrower than it, and never wider than the viewport allows. */
  min-width: max(180px, 100%);
  width: max-content;
  max-width: min(520px, calc(100vw - 32px));
  max-height: 260px;
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown, 1800);
  display: flex;
  flex-direction: column;
  animation: ss-fadeIn 0.12s var(--ease);
}

/* Portal mode — JS sets position:fixed + coordinates from the trigger rect;
   the class pins the layer per the select standard's z-index table. */
.ss-portal-dropdown {
  min-width: 0;
  z-index: var(--z-dropdown, 1800);
}

.ss-dropdown.ss-above {
  top: auto;
  bottom: calc(100% + 4px);
  animation: none;
}

/* ── Search input ───────────────────────────── */

.ss-search-wrap {
  position: relative;
  margin: 6px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ss-search-wrap .ss-search { margin: 0; width: 100%; padding-right: 24px; }

.ss-search {
  padding: 6px 8px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--surface-alt);
  box-sizing: border-box;
  transition: border-color var(--motion-fast) var(--ease);
}

.ss-search:focus {
  outline: none;
  border-color: var(--ss-accent);
}

.ss-search-clear {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: var(--fs-lg);
  cursor: pointer;
  display: none;
  align-items: center;
  padding: 0 2px;
  line-height: 1;
  transition: color var(--motion-fast) var(--ease);
}

.ss-search-clear:hover { color: var(--text); }

/* ── Options list ───────────────────────────── */

.ss-options {
  overflow-y: auto;
  padding: 4px 0;
  flex: 1;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--gray-300) transparent;
}

.ss-options::-webkit-scrollbar { width: 5px; }
.ss-options::-webkit-scrollbar-track { background: transparent; margin: 4px 0; }
.ss-options::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 9999px; }
.ss-options::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ── Single option row ──────────────────────── */

.ss-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: var(--fs-md);
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease);
}

.ss-option:hover { background: var(--surface-hover); }
.ss-option.selected { color: var(--ss-accent, var(--text)); font-weight: 500; }
.ss-option.ss-focused { background: var(--surface-hover); }
.ss-option-disabled { cursor: not-allowed; opacity: .58; }
.ss-option-disabled:hover { background: transparent; }
.ss-option.ss-unavailable { color: var(--text-muted); }

/* Dropdown is portaled outside .ss-wrap, so re-anchor the accent vars. */
.ss-dropdown {
  --ss-accent: var(--primary, var(--brand-accent, var(--brand-ink)));
}

/* ── Option text (label + subtitle wrapper) ─── */

.ss-option-text {
  flex: 1;
  min-width: 0;
}

.ss-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 1px;
  /* Subtitles may carry their own line breaks and must stay readable in
     full — truncating them defeats the point of having them. */
  overflow: hidden;
  white-space: pre-line;
}

.ss-meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}

/* ── Group headers (grouped select) ─────────── */

.ss-group-header {
  padding: 6px 10px 2px;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}

/* ── Checkbox (multi) ───────────────────────── */

.ss-check {
  width: 16px;
  height: 16px;
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--fs-xs);
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}

.ss-option.selected .ss-check {
  background: var(--ss-accent);
  border-color: var(--ss-accent);
  color: #fff;
}

/* ── Search highlight ───────────────────────── */

.ss-label mark {
  background: color-mix(in srgb, var(--ss-accent) 15%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Empty / error states ───────────────────── */

.ss-empty {
  padding: 12px;
  text-align: center;
  font-size: var(--fs-md);
  color: var(--gray-400);
  font-family: var(--font);
}

/* Async search failure — must read differently from "No matches". */
.ss-empty.ss-error {
  color: var(--danger);
  font-weight: 500;
}

/* ── Select All / Divider ───────────────────── */

.ss-select-all .ss-label { font-style: italic; color: var(--text-muted); }
.ss-divider { height: 1px; background: var(--gray-200); margin: 2px 10px; flex-shrink: 0; }
