/* ─ Live Search ─ */
.live-search {
  position: relative;
  min-width: 240px;
  max-width: 420px;
  flex: 1 1 320px;
}

/* JS-computed collapse mode (budget-based, with hysteresis) */
.live-search[data-collapsed] {
  min-width: 34px;
  max-width: 34px;
  flex: 0 0 34px;
}

.live-search[data-collapsed]:not([data-active]) .live-search-input-wrap {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-card) 84%, transparent);
  cursor: text;
}

.live-search[data-collapsed]:not([data-active]) .live-search-field-cluster {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  justify-content: center;
  padding: 0;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  opacity: 1;
  pointer-events: auto;
}

.live-search[data-collapsed]:not([data-active]) .live-search-field,
.live-search[data-collapsed]:not([data-active]) .live-search-scope-badge {
  display: none;
}

.live-search[data-collapsed]:not([data-active]) .live-search-leading-icon {
  margin: 0;
}

.live-search[data-collapsed][data-active] {
  min-width: 34px;
  max-width: 34px;
  flex: 0 0 34px;
}

.live-search[data-collapsed][data-active] .live-search-input-wrap {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: min(420px, calc(100vw - 2 * var(--space-4)));
  z-index: 25;
}

.live-search[data-collapsed][data-active] .live-search-field-cluster {
  width: 100%;
  opacity: 1;
  pointer-events: auto;
}

.live-search[data-collapsed][data-active] .live-search-field {
  width: 100%;
  opacity: 1;
  pointer-events: auto;
}

.live-search[data-collapsed]:not([data-active]) .live-search-adv-btn {
  opacity: 0;
  pointer-events: none;
}

.live-search[data-collapsed][data-active] .live-search-dropdown {
  left: 0;
  right: auto;
  width: min(420px, calc(100vw - 2 * var(--space-4)));
}

.live-search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.live-search-field-cluster {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.live-search-field-cluster:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.live-search-leading-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  margin-left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.live-search-scope-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-left: 6px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  cursor: pointer;
  user-select: none;
}

.live-search-scope-badge--ghost {
  opacity: 0.42;
  border-style: dashed;
  cursor: pointer;
  transition: opacity var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

.live-search-scope-badge--ghost:hover {
  opacity: 0.9;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.live-search-field {
  padding: var(--space-3) var(--space-4) !important;
  padding-left: 8px !important;
  padding-right: 58px !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: var(--radius-md) !important;
  flex: 1;
  min-width: 0;
}

.live-search-field:focus {
  border-color: transparent !important;
  box-shadow: none !important;
  /* The cluster shows the focus ring (:focus-within); suppress the input's own
     ring so there isn't a second inner pill inside it. */
  outline: none;
}

.live-search-adv-btn {
  position: absolute;
  right: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0.55;
  transition: opacity var(--transition-fast), color var(--transition-fast);
  border-radius: var(--radius-sm);
  padding: 0;
}

.live-search-adv-btn:hover {
  opacity: 1;
  color: var(--accent);
}

.live-search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 420px;
  overflow-y: auto;
  z-index: 1000;
  animation: fadeIn 150ms ease both;
}

.live-search-index-incomplete {
  padding: 8px var(--space-4);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-subtle);
}

.live-search-source {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px var(--space-4);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-subtle);
}

.live-search-source--local {
  color: var(--accent);
}

.live-search-source--network {
  color: var(--text-secondary);
}

.search-section {
  padding: var(--space-2) 0;
}

.search-section+.search-section {
  border-top: 1px solid var(--border-subtle);
}

.search-section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-2) var(--space-4);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-4);
  text-align: left;
  transition: background var(--transition-fast);
  border-radius: 0;
}

.search-result-item:hover,
.search-result-item.active,
.search-result-item.context-active {
  background: var(--bg-hover);
}

.search-result-item:disabled {
  opacity: 0.65;
  cursor: wait;
}

.search-result-item--muted {
  cursor: default;
  color: var(--text-muted);
}

.search-result-item--muted:hover {
  background: transparent;
}

.search-result-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-result-thumb {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.search-result-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.search-result-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.search-empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
