/* Filter dropdown: a Polaris combobox with multiple selection. Sizes and colours come
   from the design tokens defined in app.css; see docs/design-system.md. */

.multi-select {
  position: relative;
  /* Line height of small text and of body text (spec: 12/16 and 13/20). Unitless, so they
     follow the font size. */
  --ms-line-height-small: 1.34;
  --ms-line-height-body: 1.54;
  /* Smallest height of a row or button: the control height on desktop, 44 on phones. */
  --ms-tap-target: var(--control-height);
  /* Tallest the scrolling list grows before it scrolls: about nine rows. */
  --ms-list-max-height: calc(var(--control-height) * 9);
}

.ms-field {
  position: relative;
}

.ms-input {
  box-sizing: border-box;
  width: 100%;
  height: var(--ms-tap-target);
  padding-block: 0;
  padding-inline: var(--space-300) calc(var(--space-200) * 2 + var(--space-400));
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-body);
  line-height: var(--ms-line-height-body);
  font-weight: var(--weight-regular);
  text-overflow: ellipsis;
}

/* The placeholder carries the summary of the ticked options, so it reads as a value once
   something is ticked. */
.ms-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 1;
}

.multi-select.has-value .ms-input::placeholder {
  color: var(--color-text);
  font-weight: var(--weight-medium);
}

.ms-input:focus-visible,
.ms-clear:focus-visible,
.ms-done:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
}

.ms-chevron {
  position: absolute;
  inset-block: 0;
  inset-inline-end: var(--space-200);
  display: flex;
  align-items: center;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.ms-chevron svg {
  width: var(--space-400);
  height: var(--space-400);
}

.ms-input[aria-expanded="true"] ~ .ms-chevron svg {
  transform: rotate(180deg);
}

.ms-panel {
  margin-top: var(--space-100);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  overflow: hidden;
}

.ms-scroll {
  max-height: var(--ms-list-max-height);
  overflow-y: auto;
  padding-block: var(--space-100);
}

.ms-group {
  margin: 0;
  padding: var(--space-200) var(--space-200) var(--space-100);
  color: var(--color-text-secondary);
  font-size: var(--text-small);
  line-height: var(--ms-line-height-small);
  font-weight: var(--weight-semibold);
}

.ms-option {
  display: flex;
  align-items: center;
  gap: var(--space-200);
  min-height: var(--ms-tap-target);
  box-sizing: border-box;
  padding: var(--space-100) var(--space-200);
  color: var(--color-text);
  font-size: var(--text-body);
  line-height: var(--ms-line-height-body);
  font-weight: var(--weight-regular);
  cursor: pointer;
}

.ms-option[hidden],
.ms-group-block[hidden],
.ms-selected-group[hidden],
.ms-empty[hidden],
.ms-panel[hidden] {
  display: none;
}

.ms-option.is-active,
.ms-option:hover {
  background: var(--color-surface-secondary);
}

/* The row handles the click; the box only shows the state. */
.ms-option input {
  flex: none;
  margin: 0;
  accent-color: var(--color-fill);
  pointer-events: none;
}

.ms-label {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ms-label mark {
  background: transparent;
  color: inherit;
  font-weight: var(--weight-bold);
}

.ms-count {
  flex: none;
  margin-inline-start: auto;
  color: var(--color-text-secondary);
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
}

.ms-empty {
  margin: 0;
  padding: var(--space-200);
  color: var(--color-text-secondary);
  font-size: var(--text-body);
  line-height: var(--ms-line-height-body);
}

.ms-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-200);
  padding: var(--space-200);
  border-top: 1px solid var(--color-border);
}

.ms-clear,
.ms-done {
  box-sizing: border-box;
  min-height: var(--ms-tap-target);
  padding-inline: var(--space-300);
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.ms-clear:disabled {
  color: var(--color-text-secondary);
  cursor: not-allowed;
}

@media (max-width: 767px) {
  .multi-select {
    /* Phone type steps up: small text is 14/20, body text is 16/24. */
    --ms-line-height-small: 1.43;
    --ms-line-height-body: 1.5;
    /* 44 minimum tap target (WCAG 2.5.5). */
    --ms-tap-target: calc(var(--space-800) + var(--space-300));
  }
}
