/**
 * @file
 * Select input elements.
 */

@import "../base/media-queries.pcss.css";

:root {
  --form-element-select-icon: url("../../images/chevron-down.svg");
}

select {
  max-width: 100%;
  height: var(--sp3);
  padding-block: 0;
  padding-inline-start: var(--sp);
  padding-inline-end: var(--sp3);
  color: var(--color-text-neutral-loud);
  border: 1px solid var(--color--gray-60);
  border-radius: var(--border-radius);
  background-color: var(--color--white);
  background-image: var(--form-element-select-icon);
  background-repeat: no-repeat;
  background-position: right var(--sp) center; /* LTR */
  font-family: inherit;
  font-size: inherit;
  appearance: none;

  &:focus {
    border: solid 2px var(--color--primary-50);
    outline: solid 2px var(--color--primary-50);

    @supports (outline-style: double) {
      border-width: 1px;
      outline-width: 6px;
      outline-style: double;
      outline-offset: -1px;
    }
  }

  &[disabled] {
    color: var(--color--gray-60);
    background-color: var(--color--gray-100);
  }

  &.error {
    border: solid 2px var(--color--red);

    &:focus {
      outline-color: var(--color--red);
    }
  }

  &[multiple] {
    height: auto;
    padding: var(--sp0-5);
    background-image: none;
    line-height: 1; /* Needed by non-Chromium based MS Edge browsers. */

    & option {
      padding: var(--sp0-5);
    }
  }

  &.form-element--small {
    height: var(--sp2-5);
  }

  /* Necessary to show chevron in forced colors mode in modern browsers. */
  @media (forced-colors: active) {
    padding-inline-end: var(--sp);
    background-image: none;
    appearance: listbox; /* Default <select> appearance value for modern browsers. */

    /* Lets browser set <select> appearance to whatever the browser's default is. */
    @supports (appearance: revert) {
      appearance: revert;
    }
  }
}

[dir="rtl"] select {
  background-position: left var(--sp) center;
}
