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


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


/**
 * @prop --mds-avatar-background-color-pending: The background-color when an image is loading
 * @prop --mds-avatar-background-color: Public. The background-color of the component
 * @prop --mds-avatar-color: Public. The color of the placeholder icon
 * @prop --mds-avatar-initials-padding: Sets the padding of the initials inside the avatar
 * @prop --mds-avatar-radius: Public. The border-radius of the element
 */

:host {
  --mds-avatar-background-color-pending: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  --mds-avatar-background-color: rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)));
  --mds-avatar-color: rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)));
  --mds-avatar-radius: var(--magma-radius-full, var(--radius-full, 1000px));
  --mds-avatar-initials-padding: 20%;
  --mds-avatar-transition-duration: var(--duration-200, 200ms);
  --private-avatar-transition-duration: var(--mds-avatar-transition-duration);

  aspect-ratio: 1/1;
  border-radius: var(--mds-avatar-radius, var(--magma-radius-full, var(--radius-full, 1000px)));
  container-name: mds-avatar;
  container-type: inline-size;
  display: inline-flex;
  overflow: hidden;
  width: --spacing(1200);
}

/* the inner boxes repeat the radius of the host, so they take its corner shape too: round for
   the default pill, the shape of the axis where a parent gives the host a step and that shape
   (mds-entity) */

.avatar {
  aspect-ratio: 1/1;
  border-radius: var(--mds-avatar-radius, var(--magma-radius-full, var(--radius-full, 1000px)));
  color: transparent;
  corner-shape: inherit;
  display: inline-flex;
  overflow: hidden;
  transition-duration: var(--private-avatar-transition-duration);
  transition-property: color, background-color, box-shadow, fill;
  width: 100%;
}

.avatar--pending {
  background-color: var(--mds-avatar-background-color-pending, rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208))));
}

.avatar--loaded {
  animation: none;
}

.avatar--count,
.avatar--icon,
.avatar--fallback,
.avatar--initials {
  background-color: var(--mds-avatar-background-color, rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211))));
  box-shadow: none;
}

.avatar--count,
.avatar--fallback,
.avatar--initials {
  align-items: stretch;
  display: flex;
  justify-items: stretch;
}

.avatar--count,
.avatar--icon,
.avatar--fallback {
  padding: 20%;
}

.avatar--initials {
  padding: 30% var(--mds-avatar-initials-padding, 20%) 25%;
}

.image {
  aspect-ratio: 1/1;
  border-radius: var(--mds-avatar-radius, var(--magma-radius-full, var(--radius-full, 1000px)));
  corner-shape: inherit;
}

.fallback-icon {
  @apply svg;

  aspect-ratio: 1/1;
  fill: var(--mds-avatar-color, rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248))));
  width: 100%;
}

.initials-text {
  @apply font-bold
    font-title;

  align-items: center;
  color: var(--mds-avatar-color, rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248))));
  display: flex;
  height: 100%;
  justify-content: center;
  text-transform: uppercase;
  -webkit-user-select: none;
          user-select: none;
  width: 100%;
}

.fit {
  display: inline-block;
  white-space: nowrap !important;
}

.icon {
  fill: var(--mds-avatar-color, rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248))));
  height: 100%;
  transition-duration: var(--private-avatar-transition-duration);
  transition-property: fill;
  transition-timing-function: var(--ease-in-out-expo, cubic-bezier(1, 0, 0, 1));
  width: 100%;
}

@container (max-width: 24px) {
  .avatar--initials {
    padding: 0 var(--mds-avatar-initials-padding, 20%);
  }

  .initials-text {
    @apply font-black;
  }
}

:host,
:host([variant='primary']) {
  --mds-avatar-background-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  --mds-avatar-color: rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--magma-accent-surface, var(--variant-primary-09, 213 224 245)));
    --mds-avatar-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  }
}

:host([variant='red']) {
  --mds-avatar-background-color: rgb(var(--label-red-05, 230 66 66));
  --mds-avatar-color: rgb(var(--label-red-10, 252 233 233));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-red-09, 250 215 215));
    --mds-avatar-color: rgb(var(--label-red-05, 230 66 66));
  }
}

:host([variant='amaranth']) {
  --mds-avatar-background-color: rgb(var(--label-amaranth-05, 232 60 89));
  --mds-avatar-color: rgb(var(--label-amaranth-10, 255 232 233));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-amaranth-09, 255 214 215));
    --mds-avatar-color: rgb(var(--label-amaranth-05, 232 60 89));
  }
}

:host([variant='orchid']) {
  --mds-avatar-background-color: rgb(var(--label-orchid-05, 225 60 143));
  --mds-avatar-color: rgb(var(--label-orchid-10, 255 231 240));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-orchid-09, 255 212 229));
    --mds-avatar-color: rgb(var(--label-orchid-05, 225 60 143));
  }
}

:host([variant='violet']) {
  --mds-avatar-background-color: rgb(var(--label-violet-05, 143 101 247));
  --mds-avatar-color: rgb(var(--label-violet-10, 238 235 255));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-violet-09, 225 219 255));
    --mds-avatar-color: rgb(var(--label-violet-05, 143 101 247));
  }
}

:host([variant='purple']) {
  --mds-avatar-background-color: rgb(var(--label-purple-05, 168 86 247));
  --mds-avatar-color: rgb(var(--label-purple-10, 243 233 255));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-purple-09, 233 217 255));
    --mds-avatar-color: rgb(var(--label-purple-05, 168 86 247));
  }
}

:host([variant='blue']) {
  --mds-avatar-background-color: rgb(var(--label-blue-05, 69 120 254));
  --mds-avatar-color: rgb(var(--label-blue-10, 228 238 255));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-blue-09, 209 224 254));
    --mds-avatar-color: rgb(var(--label-blue-05, 69 120 254));
  }
}

:host([variant='sky']) {
  --mds-avatar-background-color: rgb(var(--label-sky-05, 10 137 194));
  --mds-avatar-color: rgb(var(--label-sky-10, 222 240 252));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-sky-09, 196 229 250));
    --mds-avatar-color: rgb(var(--label-sky-05, 10 137 194));
  }
}

:host([variant='aqua']) {
  --mds-avatar-background-color: rgb(var(--label-aqua-05, 5 141 165));
  --mds-avatar-color: rgb(var(--label-aqua-10, 199 245 253));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-aqua-09, 151 237 252));
    --mds-avatar-color: rgb(var(--label-aqua-05, 5 141 165));
  }
}

:host([variant='green']) {
  --mds-avatar-background-color: rgb(var(--label-green-05, 26 148 71));
  --mds-avatar-color: rgb(var(--label-green-10, 201 248 218));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-green-09, 154 242 188));
    --mds-avatar-color: rgb(var(--label-green-05, 26 148 71));
  }
}

:host([variant='lime']) {
  --mds-avatar-background-color: rgb(var(--label-lime-05, 93 143 15));
  --mds-avatar-color: rgb(var(--label-lime-10, 214 249 159));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-lime-09, 186 240 97));
    --mds-avatar-color: rgb(var(--label-lime-05, 93 143 15));
  }
}

:host([variant='yellow']) {
  --mds-avatar-background-color: rgb(var(--label-yellow-05, 161 124 22));
  --mds-avatar-color: rgb(var(--label-yellow-10, 255 235 200));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-yellow-09, 254 219 157));
    --mds-avatar-color: rgb(var(--label-yellow-05, 161 124 22));
  }
}

:host([variant='orange']) {
  --mds-avatar-background-color: rgb(var(--label-orange-05, 208 95 16));
  --mds-avatar-color: rgb(var(--label-orange-10, 255 233 222));

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--label-orange-09, 255 215 194));
    --mds-avatar-color: rgb(var(--label-orange-05, 208 95 16));
  }
}

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

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--magma-danger-wash-base, var(--status-error-09, 255 214 211)));
    --mds-avatar-color: rgb(var(--magma-danger-text-default, var(--text-error-default, 89 0 0)));
  }
}

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

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--magma-warning-wash-base, var(--status-warning-09, 255 220 117)));
    --mds-avatar-color: rgb(var(--magma-warning-text-default, var(--text-warning-default, 58 44 0)));
  }
}

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

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--magma-info-wash-base, var(--status-info-09, 193 230 246)));
    --mds-avatar-color: rgb(var(--magma-info-text-default, var(--text-info-default, 0 45 86)));
  }
}

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

  &:host([tone='weak']) {
    --mds-avatar-background-color: rgb(var(--magma-success-wash-base, var(--status-success-09, 191 233 205)));
    --mds-avatar-color: rgb(var(--magma-success-text-default, var(--text-success-default, 0 53 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). */

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

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

/* 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']) {
  .avatar--count,
  .avatar--icon,
  .avatar--fallback,
  .avatar--initials {
    box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3)) inset;
  }
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    .avatar--count,
    .avatar--icon,
    .avatar--fallback,
    .avatar--initials {
      box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3)), var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1));
    }
  }
}

