@reference './css/animate/utilities.css';
:host(:not(:is([hydrated], .hydrated))) {
  @apply not-hydrated;
}


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


/**
 * @prop --mds-toast-background: Public. Background color of the toast component.
 * @prop --mds-toast-color: Public. Text color inside the toast.
 * @prop --mds-toast-duration: Duration of the transition that shows and hides the toast; `mdsToastClose` is emitted when the hiding one is over. How long the toast stays visible is the `duration` prop.
 * @prop --mds-toast-icon-color: Color of the icon inside the toast.
 * @prop --mds-toast-shadow: Public. Shadow applied to the toast container.
 * @prop --mds-toast-width: Public. Width of the toast component.
 */

/* ❌ Not supported

@property --mds-toast-shadow {
  inherits: false;
  initial-value: var(--shadow-xl);
  syntax: "<box-shadow>";
}

*/

:host {
  --mds-toast-background: rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42)));
  --mds-toast-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
  --mds-toast-duration: var(--duration-300, 300ms);
  --mds-toast-icon-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
  --mds-toast-shadow: var(--shadow-xl, 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1));
  --mds-toast-width: auto;

  /* private */
  --private-toast-transition-duration: var(--mds-toast-duration, var(--duration-300, 300ms));
  --private-toast-transition-duration-intro: var(--duration-500, 500ms);
  --private-toast-transition-duration-icon: var(--duration-200, 200ms);

  color: var(--mds-toast-color, rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255))));
  display: flex;
  left: 0;
  pointer-events: none;
  position: fixed;
  right: 0;
  z-index: var(--magma-modal-z-index, 3000);
}

.dialog {
  @apply ease-in-cubic;

  align-items: center;
  background-color: var(--mds-toast-background, rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42))));
  border-radius: var(--magma-radius-xl, var(--radius-squircle-xl, 36px));
  box-shadow: var(--mds-toast-shadow);
  corner-shape: var(--magma-corner-shape, squircle);
  display: inline-flex;
  gap: --spacing(400);
  margin-inline: --spacing(400);
  max-width: 100%;
  padding: --spacing(400);
  pointer-events: none;
  transition-duration: var(--private-toast-transition-duration);

  /* a hidden toast is only moved out of the viewport: visibility keeps its message out of the
     accessibility tree until it shows, which is when the status region announces it. As a
     transition it turns visible at the start of the entrance and hidden at the end of the exit */
  transition-property: box-shadow, background-color, color, transform, visibility;
  visibility: hidden;
  width: var(--mds-toast-width, auto);
}

:host([visible]:not([visible='false'])) .dialog {
  pointer-events: auto;
  visibility: visible;
}

:host([position^='top']) {
  top: 0;
}

:host([position='top-left']) {
  justify-content: flex-start;
}

:host([position='top-center']) {
  justify-content: center;
}

:host([position='top-right']) {
  justify-content: flex-end;
}

:host([position^='bottom']) {
  bottom: 0;
}

:host([position='bottom-left']) {
  justify-content: flex-start;
}

:host([position='bottom-center']) {
  justify-content: center;
}

:host([position='bottom-right']) {
  justify-content: flex-end;
}

.actions {
  display: flex;
  gap: --spacing(200);
}

.actions--hidden {
  display: none;
}

.hide {
  flex-shrink: 0;
}

::slotted([slot='icon']) {
  @apply ease-out;

  fill: var(--mds-toast-icon-color, rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255))));
  flex-shrink: 0;
  transition-duration: var(--private-toast-transition-duration-icon);
  transition-property: fill;
}

:host([variant='dark']),
:host([variant='dark'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42)));
  --mds-toast-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
}

:host([variant='dark'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-surface-inverse-muted, var(--tone-neutral-03, 73 73 73)));
  --mds-toast-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-on-inverse, var(--tone-neutral-seed, 255 255 255)));
}

:host([variant='error']),
:host([variant='error'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
  --mds-toast-color: rgb(var(--magma-danger-text-muted, var(--text-error-muted, 132 0 11)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-danger-text-default, var(--text-error-default, 89 0 0)));
}

:host([variant='error'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-danger-wash-soft, var(--status-error-10, 255 232 230)));
  --mds-toast-color: rgb(var(--magma-danger-text-subtle, var(--text-error-subtle, 165 33 40)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-danger-text-default, var(--text-error-default, 89 0 0)));
}

:host([variant='info']),
:host([variant='info'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-info-wash-base, var(--status-info-09, 193 230 246)));
  --mds-toast-color: rgb(var(--magma-info-text-muted, var(--text-info-muted, 0 71 114)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-info-text-default, var(--text-info-default, 0 45 86)));
}

:host([variant='info'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-info-wash-soft, var(--status-info-10, 220 240 250)));
  --mds-toast-color: rgb(var(--magma-info-text-subtle, var(--text-info-subtle, 0 94 137)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-info-text-default, var(--text-info-default, 0 45 86)));
}

:host([variant='light']),
:host([variant='light'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));
  --mds-toast-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
}

:host([variant='light'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));
  --mds-toast-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
}

:host([variant='success']),
:host([variant='success'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
  --mds-toast-color: rgb(var(--magma-success-text-muted, var(--text-success-muted, 0 80 7)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-success-text-default, var(--text-success-default, 0 53 0)));
}

:host([variant='success'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-success-wash-soft, var(--status-success-10, 220 243 227)));
  --mds-toast-color: rgb(var(--magma-success-text-subtle, var(--text-success-subtle, 0 102 32)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-success-text-default, var(--text-success-default, 0 53 0)));
}

:host([variant='warning']),
:host([variant='warning'][tone='strong']) {
  --mds-toast-background: rgb(var(--magma-warning-wash-base, var(--status-warning-09, 255 220 117)));
  --mds-toast-color: rgb(var(--magma-warning-text-muted, var(--text-warning-muted, 88 66 0)));
  --mds-toast-shadow: var(--shadow-lg-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05));
  --mds-toast-icon-color: rgb(var(--magma-warning-text-default, var(--text-warning-default, 58 44 0)));
}

:host([variant='warning'][tone='weak']) {
  --mds-toast-background: rgb(var(--magma-warning-wash-soft, var(--status-warning-10, 255 237 181)));
  --mds-toast-color: rgb(var(--magma-warning-text-subtle, var(--text-warning-subtle, 113 85 0)));
  --mds-toast-shadow: var(--shadow-sm-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 1px 3px 0 rgb(0 0 0 / 0.1));
  --mds-toast-icon-color: rgb(var(--magma-warning-text-default, var(--text-warning-default, 58 44 0)));
}

.to-top-left,
.to-top-center,
.to-top-right {
  @apply animate-outro
    animate-top-outro;
}

.to-top-left.dialog--visible,
.to-top-center.dialog--visible,
.to-top-right.dialog--visible {
  @apply animate-intro
    animate-top-intro;
}

.to-bottom-left,
.to-bottom-center,
.to-bottom-right {
  @apply animate-outro
    animate-bottom-outro;
}

.to-bottom-left.dialog--visible,
.to-bottom-center.dialog--visible,
.to-bottom-right.dialog--visible {
  @apply animate-intro
    animate-bottom-intro;
}

/* Inside an mds-toast-region. The region holds the place at the edge of the viewport and lines
   its toasts up in a column, so the toast is in its flow instead of fixed on its own, and the
   region gives it its `position`. A hidden toast leaves no room in the column once its exit is
   over: display is held for the exit, then drops. It fades a short way towards its edge
   instead of travelling over the toasts between it and the edge */

:host([stacked]) {
  bottom: auto;
  left: auto;
  position: relative;
  right: auto;
  top: auto;
  transition-behavior: allow-discrete;
  transition-duration: var(--private-toast-transition-duration);
  transition-property: display;
  z-index: auto;
}

:host([stacked]:not([visible])),
:host([stacked][visible='false']) {
  display: none;
}

:host([stacked]) .dialog:not(.dialog--visible) {
  opacity: 0;
  transform: none;
}

/* a toast that turns visible comes from display: none, which leaves no style for a transition
   to start from: the entrance starts from the hidden state above */

@starting-style {
  :host([stacked]) .dialog--visible {
    opacity: 0;
    transform: none;
  }
}

/* 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-toast-transition-duration: 0s;
  --private-toast-transition-duration-intro: 0s;
  --private-toast-transition-duration-icon: 0s;
}

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

/* Theme preference. Background and elevation now come from the semantic surface
 * layer (--magma-surface-*, spec 6.1): it flips per mode at :root and inherits
 * into the shadow DOM, so this component needs no per-mode dark refinement. The
 * former dark override (a --tone-* background re-set and/or a fake outline / glow
 * that faked elevation on the old flat-black canvas) is intentionally gone. The
 * base --shadow-xl already carries the toast elevation in both modes. */

/* 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-toast-shadow: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6)) !important;
}

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

