/* Shared native selects: forms, filters, drawers and settings use one treatment. */
:root {
  --select-border: #aaa5b5;
  --select-hover: #f5f2fc;
  --select-shadow: 0 8px 24px rgb(24 21 31 / 14%);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23626675' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

:root[data-theme="dark"] {
  --select-border: var(--control-line);
  --select-hover: var(--surface-hover);
  --select-shadow: 0 8px 24px rgb(0 0 0 / 32%);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23aaa6b5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

:root select:not([multiple]) {
  appearance: none;
  box-sizing: border-box;
  min-block-size: 40px;
  min-inline-size: 0;
  max-inline-size: 100%;
  padding: 9px 36px 9px 12px;
  border: 1px solid var(--select-border);
  border-radius: 7px;
  background-color: var(--surface);
  background-image: var(--select-arrow);
  background-position: right 12px center;
  background-size: 16px;
  background-repeat: no-repeat;
  color: var(--ink);
  font: 400 12px/1.5 Inter, 'Segoe UI', sans-serif;
  text-align: start;
  text-overflow: ellipsis;
  cursor: pointer;
}

:root select:not([multiple]):enabled:hover {
  border-color: var(--brand);
}

:root select:not([multiple]):focus-visible {
  border-color: var(--brand);
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

:root select:not([multiple]):disabled {
  color: var(--muted);
  background-color: var(--canvas);
  border-color: var(--line);
  cursor: not-allowed;
}

:root select[aria-invalid="true"] {
  border-color: var(--danger);
}

:root select option,
:root select optgroup {
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

:root select option:disabled {
  color: var(--muted);
}

/* Keep the same field width for the two settings pickers. */
.settings-language-controls > select {
  max-width: none;
}

/*
 * Style the browser's actual picker where supported, retaining native values,
 * keyboard navigation, labels and change events. Older browsers keep the themed
 * control above and their platform picker. No duplicated form or focus state.
 * https://developer.chrome.com/blog/a-customizable-select
 */
@supports (appearance: base-select) {
  :root select:not([multiple]):not([size]),
  :root select:not([multiple]):not([size])::picker(select) {
    appearance: base-select;
  }

  :root select:not([multiple]):not([size]) {
    background-image: none;
    padding-inline-end: 12px;
    align-items: center;
    gap: 12px;
  }

  :root select::picker-icon {
    content: "";
    inline-size: 16px;
    block-size: 16px;
    flex: 0 0 16px;
    margin-inline-start: auto;
    background: var(--select-arrow) center / 16px no-repeat;
  }

  :root select:open::picker-icon {
    rotate: 180deg;
  }

  :root select::picker(select) {
    box-sizing: border-box;
    inline-size: anchor-size(self-inline);
    min-inline-size: min(240px, calc(100vw - 24px));
    max-inline-size: min(620px, calc(100vw - 24px));
    max-block-size: min(320px, 50dvh);
    margin-block: 6px;
    padding: 5px;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--select-shadow);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--select-border) var(--surface);
    font: 400 12px/1.5 Inter, 'Segoe UI', sans-serif;
  }

  :root select option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-block-size: 40px;
    padding: 10px 12px;
    border-radius: 7px;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
  }

  :root select option:checked {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 500;
  }

  :root select option:enabled:hover,
  :root select option:enabled:focus {
    background: var(--select-hover);
    color: var(--ink);
  }

  :root select option:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
  }

  :root select option::checkmark {
    order: 1;
    margin-inline-start: auto;
    flex-shrink: 0;
    color: var(--brand);
  }

  :root select option:disabled {
    cursor: not-allowed;
  }
}

@media (max-width: 600px), (pointer: coarse) {
  :root select:not([multiple]),
  :root select option {
    min-block-size: 44px;
    font-size: 14px;
  }
  :root select::picker(select) {
    font-size: 14px;
  }
}

@media (forced-colors: active) {
  :root select:not([multiple]):not([size]),
  :root select:not([multiple]):not([size])::picker(select) {
    appearance: auto;
    background-image: none;
  }
  :root select:focus-visible {
    outline-color: Highlight;
  }
}
