.wd-multi-select {
  position: relative;
  width: 100%;
  --wd-multi-panel-max-height: 20rem;
}

.wd-multi-select-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--wd-control-text);
  gap: 0.5rem;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--wd-control-border);
  border-radius: 0.375rem;
  background: var(--wd-control-bg);
  min-height: 2.25rem;
}

.wd-multi-select-toggle:hover {
  border-color: var(--wd-control-border-strong);
}

.wd-multi-select-summary {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--wd-text-secondary);
}

.wd-multi-select-caret {
  font-size: 0.75rem;
  color: var(--wd-text-muted);
}

.wd-multi-select-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.35rem);
  left: 0;
  width: 100%;
  min-width: 12rem;
  max-height: min(var(--wd-multi-panel-max-height), 70vh);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--wd-control-border);
  border-radius: 0.5rem;
  background: var(--wd-color-surface);
  box-shadow: var(--wd-shadow-strong);
  resize: vertical;
  overflow: auto;
}

.wd-multi-select-panel[hidden] {
  display: none;
}

.wd-multi-select-search {
  padding: 0.5rem;
  border-bottom: 1px solid var(--wd-border-muted);
  background: var(--wd-panel-muted);
}

.wd-multi-select-search input {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--wd-control-border);
  border-radius: 0.375rem;
  font: inherit;
  background: var(--wd-control-bg);
  color: var(--wd-control-text);
}

.wd-multi-select-search input::placeholder {
  color: var(--wd-control-placeholder);
}

.wd-multi-select-search input:focus-visible {
  border-color: var(--wd-control-border-strong);
  outline: 2px solid var(--wd-accent-soft);
  outline-offset: 1px;
}

.wd-multi-select-hint {
  margin: 0;
  padding: 0.35rem 0.65rem 0;
  color: var(--wd-text-muted);
  font-size: 0.75rem;
}

.wd-multi-select-options {
  margin: 0;
  padding: 0.25rem 0.5rem 0.5rem;
  list-style: none;
  overflow: auto;
  flex: 1;
}

.wd-multi-select-option label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.25rem;
  border-radius: 0.35rem;
  cursor: pointer;
}

.wd-multi-select-option label:hover {
  background: var(--wd-accent-soft);
}

.wd-multi-select-option input {
  accent-color: var(--wd-accent);
}

.wd-multi-select-actions {
  padding: 0.45rem 0.65rem;
  border-top: 1px solid var(--wd-border-muted);
  display: flex;
  justify-content: flex-end;
  background: var(--wd-panel-muted);
}

.wd-multi-select-clear {
  border: none;
  background: none;
  color: var(--wd-accent);
  font: inherit;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.35rem;
}

.wd-multi-select-clear:hover {
  background: var(--wd-accent-soft);
}

.wd-multi-select-input {
  display: none;
}

@media (max-width: 720px) {
  .wd-multi-select-panel {
    position: fixed;
    left: 1rem;
    right: 1rem;
    top: auto;
    bottom: 1.5rem;
    max-height: min(60vh, var(--wd-multi-panel-max-height));
  }

  .wd-multi-select {
    width: 100%;
  }
}
