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


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


/**
 * @prop --mds-notification-color: Public. The text/icon color of the notification component.
 * @prop --mds-notification-dot-background: The background color of the notification dot.
 * @prop --mds-notification-dot-padding: The padding around the notification dot.
 * @prop --mds-notification-min-width: The minimum width of the notification component.
 * @prop --mds-notification-pulse-duration: Duration of one beat of the pulse.
 * @prop --mds-notification-pulse-spread: How far the ring of the pulse grows past the ring of the dot.
 * @prop --mds-notification-ring-color: The color of the notification ring.
 * @prop --mds-notification-ring-size: The thickness of the notification ring.
 * @prop --mds-notification-size: Public. The base size of the notification element.
 * @prop --mds-notification-transition-duration: Duration of notification transitions.
 * @prop --mds-notification-transition-timing-function: Timing function for notification transitions.
 * @prop --mds-notification-translate-offset-x: X-axis offset factor for notification translation.
 * @prop --mds-notification-translate-offset-y: Y-axis offset factor for notification translation.
 * @prop --mds-notification-translate: The CSS transform applied for notification positioning.
 */

/* ❌ Not supported
@property --mds-notification-transition-timing-function {
  inherits: false;
  initial-value: var(--ease-out-cubic);
  syntax: "<timing-function>";
}
*/

:host {
  --mds-notification-color: rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-dot-background: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
  --mds-notification-dot-padding: --spacing(150);
  --mds-notification-min-width: var(--mds-notification-size, --spacing(500));
  --mds-notification-ring-color: rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-ring-size: --spacing(50);
  --mds-notification-size: --spacing(500);
  --mds-notification-transition-duration: var(--duration-200, 200ms);
  --private-notification-transition-duration: var(--mds-notification-transition-duration, var(--duration-200, 200ms));
  --mds-notification-dot-transition-duration: var(--duration-300, 300ms);
  --private-notification-dot-transition-duration: var(--mds-notification-dot-transition-duration);
  --mds-notification-transition-timing-function: var(--ease-out-cubic, cubic-bezier(0.215, 0.61, 0.355, 1));
  --mds-notification-pulse-duration: var(--duration-1000, 1000ms);
  --private-notification-pulse-duration: var(--mds-notification-pulse-duration);
  --mds-notification-pulse-spread: --spacing(200);
  --mds-notification-translate-offset-x: -1.75;
  --mds-notification-translate-offset-y: -2;
  --mds-notification-translate: translate(
    calc(var(--mds-notification-size, --spacing(500)) / var(--mds-notification-translate-offset-x, -1.75)),
    calc(var(--mds-notification-size, --spacing(500)) / var(--mds-notification-translate-offset-y, -2))
  );

  align-items: center;
  border-radius: var(--magma-radius-full, var(--radius-full, 1000px));
  bottom: 100%;
  color: var(--mds-notification-color, rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255))));
  display: inline-flex;
  height: var(--mds-notification-size, --spacing(500));
  justify-content: flex-end;
  min-width: max-content;
  pointer-events: none;
  width: var(--mds-notification-size, --spacing(500));
  z-index: 10;
}

:host([strategy='absolute']),
:host([strategy='fixed']) {
  opacity: 0;
  right: 100%;
  transform: var(--mds-notification-translate, translate( calc(--spacing(500) / -1.75), calc(--spacing(500) / -2) )) scale(0);
  transform-origin: calc(100% - calc(var(--mds-notification-size, --spacing(500)) / 2)) 50%;
  transition-duration: var(--private-notification-transition-duration);
  transition-property: color, height, opacity, transform, width;
  transition-timing-function: var(--mds-notification-transition-timing-function);
}

:host([strategy='absolute']) {
  position: absolute;
}

:host([strategy='fixed']) {
  position: fixed;
}

.dot {
  @apply ease-in-out;

  align-items: center;
  background-color: var(--mds-notification-dot-background, rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65))));
  border-radius: var(--magma-radius-full, var(--radius-full, 1000px));
  box-shadow: 0 0 0 var(--mds-notification-ring-size, --spacing(50)) var(--mds-notification-ring-color, rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255))));
  box-sizing: border-box;
  display: inline-flex;
  justify-content: center;
  line-height: var(--mds-notification-size, --spacing(500));
  min-height: var(--mds-notification-size, --spacing(500));
  min-width: var(--mds-notification-min-width, --spacing(500));
  padding-left: var(--mds-notification-dot-padding, --spacing(150));
  padding-right: var(--mds-notification-dot-padding, --spacing(150));
  position: static;
  transition-duration: var(--private-notification-dot-transition-duration);
  transition-property: background-color, color, box-shadow;
  white-space: nowrap;
}

:host([strategy='absolute']) .dot,
:host([strategy='fixed']) .dot {
  position: absolute;
}

/* The pulse (#1216): a ring that grows from the edge of the dot and fades, three beats and then
   still. A beat is the longest step of --duration-*, so the three end after 3s, under the 5s
   after which WCAG 2.2.2 wants a way to stop what moves; --ease-out-cubic leaves fast and
   settles, as a ripple does. The ring is a second shadow under the dot's own ring: it needs no
   element and moves nothing around the dot, and a forced-colours mode, which drops shadows,
   drops it too. The component sets the class when the value grows and takes it off at the end. */

.pulse {
  animation-duration: var(--private-notification-pulse-duration);
  animation-iteration-count: 3;
  animation-name: notification-pulse;
  animation-timing-function: var(--ease-out-cubic, cubic-bezier(0.215, 0.61, 0.355, 1));
}

@keyframes notification-pulse {
  from {
    box-shadow:
      0 0 0 var(--mds-notification-ring-size, --spacing(50)) var(--mds-notification-ring-color, rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)))),
      0 0 0 var(--mds-notification-ring-size, --spacing(50)) var(--mds-notification-dot-background, rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65))));
  }

  to {
    box-shadow:
      0 0 0 var(--mds-notification-ring-size, --spacing(50)) var(--mds-notification-ring-color, rgb(var(--magma-text-on-emphasis, var(--tone-neutral-seed, 255 255 255)))),
      0 0 0 calc(var(--mds-notification-ring-size, --spacing(50)) + var(--mds-notification-pulse-spread))
        transparent;
  }
}

.spacer {
  box-sizing: border-box;
  display: inline-flex;
  height: var(--mds-notification-size, --spacing(500));
  width: var(--mds-notification-min-width, --spacing(500));
}

:host([dismissed]:not([dismissed='false'])[strategy='absolute']),
:host([dismissed]:not([dismissed='false'])[strategy='fixed']) {
  @apply ease-in-cubic
    opacity-100;

  opacity: 1;
  transform: var(--mds-notification-translate, translate( calc(--spacing(500) / -1.75), calc(--spacing(500) / -2) )) scale(0);
}

:host([strategy='absolute']:not([dismissed])),
:host([strategy='absolute'][dismissed='false']),
:host([strategy='fixed']:not([dismissed])),
:host([strategy='fixed'][dismissed='false']) {
  @apply ease-out-cubic
    opacity-100;

  opacity: 1;
  transform: var(--mds-notification-translate, translate( calc(--spacing(500) / -1.75), calc(--spacing(500) / -2) )) scale(1);
}

:host([strategy='disabled']),
:host(:not([target])) {
  opacity: 1;
  position: static;
  transform: scale(1);
  transform-origin: unset;
  transition-duration: 0ms;
}

:host([strategy='disabled']) .dot,
:host(:not([target])) .dot {
  position: static;
}

/* a badge placed by its container has no transition to play: dismissed, it is just not there */

:host([dismissed]:not([dismissed='false'])[strategy='disabled']),
:host([dismissed]:not([dismissed='false']):not([target])) {
  display: none;
}

/* The variant paints the dot with the solid fill of its status and its ink with the ink measured
   on that fill (docs/agents/color.md, Pairing rules: -on-emphasis on the fill). The family is
   the status one of docs/agents/variants.md, for a notification says that something waits: a
   state. `error` is the danger hue, and the colour the dot had before it had a variant. */

:host([variant='error']) {
  --mds-notification-color: rgb(var(--magma-danger-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-dot-background: rgb(var(--magma-danger-emphasis, var(--status-error-04, 196 64 65)));
}

:host([variant='info']) {
  --mds-notification-color: rgb(var(--magma-info-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-dot-background: rgb(var(--magma-info-emphasis, var(--status-info-04, 0 119 164)));
}

:host([variant='success']) {
  --mds-notification-color: rgb(var(--magma-success-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-dot-background: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
}

:host([variant='warning']) {
  --mds-notification-color: rgb(var(--magma-warning-on-emphasis, var(--tone-neutral-seed, 255 255 255)));
  --mds-notification-dot-background: rgb(var(--magma-warning-emphasis, var(--status-warning-04, 142 106 0)));
}

/* 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).
 *
 * The pulse is held back the same way, by its duration: the component starts none with a
 * reduced animation, and a pulse that is playing when the preference changes ends at once
 * with a duration of 0s, firing the animationend that takes its class off. Three beats are
 * finite, so 0s cannot spin out of control as it would on a loader. */

:host([pref-animation='reduce']) {
  --private-notification-transition-duration: 0s;
  --private-notification-dot-transition-duration: 0s;
  --private-notification-pulse-duration: 0s;
}

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

