@layer base {
[data-autocomplete] {
  position: relative;
}

.autocomplete-filters {
  display: flex;
  gap: 0.4rem;
}

.autocomplete-text-wrap {
  flex: 1;
  min-width: 0;
}

.autocomplete-text-wrap [data-autocomplete-text] {
  width: 100%;
}

.autocomplete-type-select {
  width: auto !important;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  flex-shrink: 0;
}

[data-autocomplete-text] {
  width: 100%;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

[data-autocomplete-text]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 var(--focus-ring-width) var(--focus-halo);
}

/* Positioned in viewport coordinates by crm/js/autocomplete.js — `left`,
   `top`/`bottom`, `width` and `max-height` are all set there, per open.

   Do not put this back to `position: absolute`. Absolute laid it out inside
   the picker's own box, so on any screen whose picker sits in a scroll
   container — the bulk bar stuck to the bottom of the Candidates list, a side
   panel, the app's own `.main` — the menu opened into the clipped region and
   the results below the fold were simply never painted (issue #317). Fixed is
   what escapes those clips, and it is why the JS owns the geometry. */
[data-autocomplete-menu] {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--elev-2);
}

/* Flipped above the field when there is no room below: the seam moves to the
   other edge, so the menu still reads as attached to the input. */
[data-autocomplete-menu].is-above {
  border-top: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.autocomplete-option {
  display: block;
  width: 100%;
  padding: 0.45rem 0.5rem;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.autocomplete-option:hover,
.autocomplete-option.is-active {
  background: var(--border-light);
}

/* ── A result row, told apart ──────────────────────────────────────────
   Name, type, parent used to be one run of text at one size ("Name @ Parent
   (Type)"), which made the name — the thing being chosen — the least
   distinguishable fact in the row. Same three facts, three weights. */
.autocomplete-option__top {
  display: flex;
  /* Not `center`: the name wraps to two lines and the type chip belongs
     against its first line, not floating beside the middle of it. */
  align-items: flex-start;
  gap: var(--space-2);
  min-width: 0;
}

/* Two lines, then stop. Single-line ellipsis cut real holon names at about
   thirty characters — before the first word that told two of them apart, on a
   list where names run past a hundred. Two lines at the menu's width holds
   every name on record; the cap is what stops one result filling the menu. */
.autocomplete-option__name {
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
}

.autocomplete-option__parent {
  display: block;
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Waiting, as distinct from finding nothing ─────────────────────────
   A request in flight and a search that matched nothing both rendered as an
   empty menu, so a slow answer was indistinguishable from no answer. */
.autocomplete-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.45rem 0.5rem;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.autocomplete-spinner {
  width: 0.85em;
  height: 0.85em;
  flex-shrink: 0;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: autocomplete-spin var(--dur-slow) linear infinite;
}

@keyframes autocomplete-spin {
  to { transform: rotate(1turn); }
}

/* One use, so it lives with its one caller rather than being graduated to
   components/ on spec. A second caller is the trigger to move it. */
@media (prefers-reduced-motion: reduce) {
  .autocomplete-spinner { animation: none; }
}

.autocomplete-group-label {
  padding: 0.35rem 0.5rem 0.15rem;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ── What is currently chosen ──────────────────────────────────────────
   The same name / chip / parent shape the dropdown row just used. Reviving
   the flattened string here would put the ambiguity back at the moment it
   matters most — after the choice, when nothing else on screen says which of
   two same-named holons was picked. */
.autocomplete-selected {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}

.autocomplete-selected[hidden] { display: none; }

.autocomplete-selected__body {
  flex: 1;
  min-width: 0;
}

.autocomplete-selected__clear {
  flex-shrink: 0;
  padding: 0 var(--space-1);
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.autocomplete-selected__clear:hover { color: var(--text); }

[data-autocomplete].has-selection [data-autocomplete-text] {
  border-color: var(--accent);
}

.autocomplete-type-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.ac-type-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity var(--dur-base) var(--ease-out);
}

.ac-type-btn img {
  width: 18px;
  height: 18px;
}

.ac-type-btn:hover {
  opacity: 0.7;
}

.ac-type-btn.ac-type-active {
  opacity: 1;
  border-color: var(--text-muted);
}
}
