:host(:not(:is([hydrated], .hydrated))) {
  @apply not-hydrated;
}


mds-input-tip,
mds-input-tip-item {
  &:not(:is([hydrated], .hydrated)) {
    @apply not-hydrated;
  }
}


/**
 * @prop --mds-input-select-variant-color-rgb: Public. Base color used to derive all select component visual states
 * @prop --mds-input-select-ring: Public. Ring applied around the select at rest; hover and focus draw a 3px ring in the variant color
 * @prop --mds-input-select-shadow: Public. Shadow applied to the select component
 * @prop --mds-input-select-arrow-icon-background-color: Background color behind the arrow icon
 * @prop --mds-input-select-arrow-icon-blur-background-color: Transparent background used for blurred states of the arrow icon
 * @prop --mds-input-select-arrow-icon-blur-color: Color applied to the arrow icon in blurred states
 * @prop --mds-input-select-arrow-icon-color: Default arrow icon color
 * @prop --mds-input-select-arrow-icon-hover-background-color: Background color of the arrow icon when hovered
 * @prop --mds-input-select-arrow-icon-hover-color: Color of the arrow icon when hovered
 */

/* ❌ Not supported
@property --mds-input-select-ring {
  inherits: false;
  initial-value: 0 0 0 1px rgb(var(--mds-input-select-variant-color-rgb) / 0.1);
  syntax: "<box-shadow>";
}

@property --mds-input-select-shadow {
  inherits: false;
  initial-value: 0 1px 3px 0 rgb(var(--mds-input-select-variant-color-rgb) / 0.1), 0 1px 2px 0 rgb(var(--mds-input-select-variant-color-rgb) / 0.06);
  syntax: "<box-shadow>";
}
*/

:host {
  --mds-input-select-variant-color-rgb: var(--magma-text-default, var(--text-neutral-default, 5 5 5));
  --mds-input-select-ring: 0 0 0 1px rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.1);
  --mds-input-select-shadow:
    0 1px --spacing(75) 0 rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.1),
    0 1px --spacing(50) 0 rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.06);
  --mds-input-select-arrow-icon-background-color: var(--mds-input-select-arrow-icon-blur-background-color, transparent);
  --mds-input-select-arrow-icon-blur-background-color: rgb(
    var(--mds-input-select-variant-color-rgb, 0 0 0) / 0
  );
  --mds-input-select-arrow-icon-blur-color: rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.5);
  --mds-input-select-arrow-icon-color: var(--mds-input-select-arrow-icon-blur-color, rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255))));
  --mds-input-select-arrow-icon-hover-background-color: rgb(
    var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.5
  );
  --mds-input-select-arrow-icon-hover-color: rgb(var(--mds-input-select-variant-color-rgb, 0 0 0));
  --mds-input-tip-background: rgb(var(--magma-surface-inverse-muted, var(--tone-neutral-03, 73 73 73)));
  --mds-input-select-transition-duration: var(--duration-300, 300ms);
  --mds-input-select-icon-transition-duration: var(--duration-200, 200ms);

  /* private */
  --private-input-select-transition-duration: var(--mds-input-select-transition-duration);
  --private-input-select-icon-transition-duration: var(--mds-input-select-icon-transition-duration);

  /* the size of the field, lg by default: its height, its padding and the box of the arrow */
  --private-input-select-height: --spacing(1200);
  --private-input-select-padding-inline: --spacing(400);
  --private-input-select-arrow-area: --spacing(1200);

  /* the radius of mds-input, capped at a part of the height of the field like it (#913, #995);
     the top tip keeps clear of the corner by it (#1368) */
  --private-input-select-radius: min(
    var(--magma-radius-xl, var(--radius-squircle-xl, 36px)),
    var(--magma-corner-cap, 0.5) * var(--private-input-select-height)
  );

  @apply text-info-detail;

  border-radius: var(--private-input-select-radius);
  color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  corner-shape: var(--magma-corner-shape, squircle);
  display: flex;
  position: relative;
  -webkit-user-select: none;
          user-select: none;
}

:host(:hover),
:host(:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-accent-fg, var(--variant-primary-03, 0 73 211));
  --mds-input-select-shadow:
    0 --spacing(100) --spacing(150) -1px rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.1),
    0 --spacing(50) --spacing(100) -1px rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 0.06);
  --mds-input-select-arrow-icon-background-color: var(--mds-input-select-arrow-icon-hover-background-color, transparent);
  --mds-input-select-arrow-icon-color: var(--mds-input-select-arrow-icon-hover-color, rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211))));
}

/* The hover and focus ring sits on the select itself, as the focus ring of mds-input does.
   The dark and contrast blocks set the ring on the host, with selectors as specific as the
   ones above or more: declared there, the focus ring lost to them and the select showed no
   focus at all. A declaration on the element beats the value it inherits from the host, so
   those blocks only change the ring at rest. */

:host(:hover) .input,
:host(:focus-within) .input {
  --mds-input-select-ring: 0 0 0 --spacing(75) rgb(var(--mds-input-select-variant-color-rgb, 0 0 0) / 1);
}

.input {
  @apply text-info-detail;

  appearance: none;

  /* a field stands a step off its surface: overlay on a page, the step below inside an overlay
     surface, which passes it as --magma-field-fill (#1193) */
  background-color: rgb(var(--magma-field-fill, var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255))));
  border: 0;
  border-radius: inherit;
  box-shadow: var(--mds-input-select-ring), var(--mds-input-select-shadow);
  box-sizing: border-box;
  color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  corner-shape: inherit;
  cursor: pointer;
  margin: 0;
  min-height: var(--private-input-select-height);
  overflow: hidden;
  padding-left: var(--private-input-select-padding-inline);
  padding-right: var(--private-input-select-arrow-area);
  text-overflow: ellipsis;
  transition-duration: var(--private-input-select-transition-duration);
  transition-property: background-color, border-color, box-shadow, color, fill;
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  width: 100%;
}

.input:hover,
.input:focus {
  @apply outline-hidden;

  color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
  transition-duration: var(--private-input-select-transition-duration);
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
}

:host([value]:not([value=''])) .input {
  color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
}

:host([required]:not([required='false'])) .input {
  color: rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)));
}

.input:disabled {
  background-color: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));
  opacity: 1;
}

:host([disabled]:not([disabled='false'])) {
  pointer-events: none;
}

:host([disabled]:not([disabled='false'])) .input {
  pointer-events: none;
}

:host([disabled]:not([disabled='false'])) .icon {
  fill: rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)));
}

.icon-container {
  align-items: center;
  color: inherit;
  display: flex;
  height: var(--private-input-select-height);
  pointer-events: none;
  position: absolute;
  right: var(--private-input-select-padding-inline);
}

.icon {
  @apply svg;

  background-color: var(--mds-input-select-arrow-icon-background-color, transparent);
  border-radius: var(--magma-radius-full, var(--radius-full, 1000px));
  fill: var(--mds-input-select-arrow-icon-color, rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255))));
  transition-duration: var(--private-input-select-icon-transition-duration);
  transition-property: background-color, fill;
}

.option-container {
  display: none;
}

mds-input-tip {
  --mds-input-tip-field-radius: var(--private-input-select-radius);
  --mds-input-tip-background: inherit;
}

@container (max-width: 210px) {
  :host .tip__content,
  :host(:focus-within) .tip__content {
    grid-template-columns: 0fr;
    opacity: 0;
  }

  :host .tip {
    padding-left: 0;
    padding-right: 0;
  }
}

/* The size of the field, with the heights of mds-button: md 36px and sm 28px here, lg 48px in
 * the base sheet. The arrow keeps its distance from the edge in proportion. A number in `size` (the deprecated row count, now
 * `rows`) matches neither, so the field stays lg. */

:host([size='md']) {
  --private-input-select-height: --spacing(900);
  --private-input-select-padding-inline: --spacing(300);
  --private-input-select-arrow-area: --spacing(1000);
}

:host([size='sm']) {
  --private-input-select-height: --spacing(700);
  --private-input-select-padding-inline: --spacing(200);
  --private-input-select-arrow-area: --spacing(800);

  .icon {
    height: --spacing(400);
    width: --spacing(400);
  }
}

/* The arrow follows mds-input-date: the same role for the same state, bare, with
 * no fill behind it. The background knobs stay documented so a consumer can bring
 * the old pill back, but they default to nothing. */

:host {
  --mds-input-select-variant-color-rgb: 0 0 0;
  --mds-input-select-arrow-icon-blur-background-color: transparent;
  --mds-input-select-arrow-icon-hover-background-color: transparent;
  --mds-input-select-arrow-icon-blur-color: rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)));
  --mds-input-select-arrow-icon-hover-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
}

:host(:hover),
:host(:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255));
}

:host([variant='info']) {
  --mds-input-tip-background: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-select-arrow-icon-blur-background-color: transparent;
  --mds-input-select-arrow-icon-hover-background-color: transparent;
  --mds-input-select-arrow-icon-blur-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-select-arrow-icon-hover-color: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
  --mds-input-select-variant-color-rgb: 0 0 0;
}

:host([variant='info']:hover),
:host([variant='info']:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-info-emphasis, var(--status-info-04, 0 119 164));
}

:host([variant='success']) {
  --mds-input-tip-background: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-select-arrow-icon-blur-background-color: transparent;
  --mds-input-select-arrow-icon-hover-background-color: transparent;
  --mds-input-select-arrow-icon-blur-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-select-arrow-icon-hover-color: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
  --mds-input-select-variant-color-rgb: 0 0 0;
}

:host([variant='success']:hover),
:host([variant='success']:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-success-emphasis, var(--status-success-04, 0 128 57));
}

:host([variant='warning']) {
  --mds-input-tip-background: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-select-arrow-icon-blur-background-color: transparent;
  --mds-input-select-arrow-icon-hover-background-color: transparent;
  --mds-input-select-arrow-icon-blur-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-select-arrow-icon-hover-color: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
  --mds-input-select-variant-color-rgb: 0 0 0;
}

:host([variant='warning']:hover),
:host([variant='warning']:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0));
}

:host([variant='error']) {
  --mds-input-tip-background: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-select-arrow-icon-blur-background-color: transparent;
  --mds-input-select-arrow-icon-hover-background-color: transparent;
  --mds-input-select-arrow-icon-blur-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-select-arrow-icon-hover-color: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-input-select-variant-color-rgb: 0 0 0;
}

:host([variant='error']:hover),
:host([variant='error']:focus-within) {
  --mds-input-select-variant-color-rgb: var(--magma-danger-emphasis, var(--status-error-04, 196 64 65));
}

/* Motion, held back.
 *
 * Every component zeroes the private durations its own base CSS reads, which composes
 * with the public knobs - but that only reaches the declarations that read them. An audit
 * of the 52 sheets found 21 transitions in 15 components that did not: the host's own
 * transition in mds-button and mds-table, the focus ring of the input family, the tab
 * slider, the close button of mds-note. This reset reaches the whole shadow tree, which is
 * what the preference promises, and keeps reaching it when a declaration is added.
 *
 * Transitions only, on purpose. A keyframe animation is usually a loader, and a loader has
 * to keep saying "working": mds-spinner slows to 8s under reduced motion instead of
 * freezing, and a duration of nearly zero on an infinite animation would spin it out of
 * control instead of stopping it.
 *
 * 0.01ms rather than 0s, so a component that waits for its own transitionend still gets
 * one: mds-modal, mds-push-notification and mds-tree-item all listen for it, and a
 * transition of zero never fires it. */

/* stylelint-disable time-min-milliseconds -- the floor is there to keep a transition
   perceivable; the point of these two is that it is not. */

:host([pref-animation='reduce']),
:host([pref-animation='reduce']) *,
:host([pref-animation='reduce']) *::before,
:host([pref-animation='reduce']) *::after {
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host([pref-animation='system']) *,
  :host([pref-animation='system']) *::before,
  :host([pref-animation='system']) *::after,
  :host(:not([pref-animation])),
  :host(:not([pref-animation])) *,
  :host(:not([pref-animation])) *::before,
  :host(:not([pref-animation])) *::after {
    transition-duration: 0.01ms !important;
  }
}

/* stylelint-enable time-min-milliseconds */


/* Animation preference. The component mirrors the resolved mode from <html>
 * onto its host as pref-animation (see subscribePreference in @common/preference);
 * these plain shadow selectors then zero the private duration(s) the base CSS
 * reads. `reduce` always stops; `system` and no controller follow the OS via
 * @media; `no-preference` keeps the base value. Customization composes (the base
 * sets --private from the public token, this only overrides it when reduced). */

:host([pref-animation='reduce']) {
  --private-input-select-transition-duration: 0s;
  --private-input-select-icon-transition-duration: 0s;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-input-select-transition-duration: 0s;
    --private-input-select-icon-transition-duration: 0s;
  }
}

/* Theme preference. The component reflects the resolved theme mode and scheme
 * from <html> onto its host as pref-mode + pref-theme-scheme (see
 * subscribePreference in @common/preference); these plain shadow selectors refine
 * for dark. `dark` is the explicit choice; `system` and no controller follow the
 * OS via @media; the scheme axis gates it. Cross-browser, no :host-context.
 *
 * The arrow is not listed here: its roles (accent-emphasis at rest, accent-fg on hover)
 * flip with the palette on their own, exactly as the icon of mds-input-date does. The dark
 * block used to repaint it from the raw ramp and to restore the pill behind it, and its
 * blur colour named --mds-input-select-variant-color, a variable that does not exist:
 * invalid at computed-value time, so the icon fell back to the registration's literal. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  --mds-input-select-ring: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));

  .input {
    color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-input-select-ring: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));

    .input {
      color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
    }
  }
}

/* Contrast preference. The component reflects the resolved mode from <html> onto
 * its host as pref-contrast (see subscribePreference in @common/preference); these
 * plain shadow selectors refine for high contrast. `more` is the explicit choice;
 * `system` and no controller follow the OS via @media. Cross-browser, no :host-context. */

:host([pref-contrast='more']) {
  --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));

  .input {
    color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));

    .input {
      color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
    }
  }
}

/* Contrast over dark. The dark block sets the ring at rest with selectors as specific as
 * :host([pref-mode='dark']:not([pref-theme-scheme='light'])), more than the contrast ones, so
 * with both preferences the select lost the strong ring. These selectors name both axes, are
 * as specific as the dark ones and come after them, so the contrast ring wins. The text needs
 * nothing here: under pref-contrast-more the semantic layer promotes text-muted, the colour
 * the dark block sets, to the default step. */

:host([pref-contrast='more'][pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-contrast='more'][pref-theme-scheme='dark']) {
  --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system'][pref-mode='dark']:not([pref-theme-scheme='light'])),
  :host([pref-contrast='system'][pref-theme-scheme='dark']),
  :host([pref-mode='dark']:not([pref-theme-scheme='light']):not([pref-contrast])),
  :host([pref-theme-scheme='dark']:not([pref-contrast])) {
    --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-contrast='more'][pref-mode='system']:not([pref-theme-scheme='light'])),
  :host([pref-contrast='more']:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :host([pref-contrast='system'][pref-mode='system']:not([pref-theme-scheme='light'])),
  :host([pref-contrast='system']:not([pref-mode]):not([pref-theme-scheme='light'])),
  :host([pref-mode='system']:not([pref-theme-scheme='light']):not([pref-contrast])),
  :host(:not([pref-contrast]):not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-input-select-ring: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
  }
}

