@keyframes focus-bounce {
  0%,
  75%,
  100% {
    outline-offset: var(--magma-outline-focus-offset, 2px);
  }

  50% {
    outline-offset: var(--magma-outline-blur-offset, 6px);
  }
}

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


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


/**
 * @prop --mds-file-preview-icon-color: Sets the color of the file preview icon
 * @prop --mds-file-preview-color: Public. Sets the text color used in the file preview
 * @prop --mds-file-preview-icon-background: Sets the background color of the file preview icon
 */

:host {
  --mds-file-preview-icon-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  --mds-file-preview-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  --mds-file-preview-icon-background: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
  --mds-file-transition-duration: var(--duration-200, 200ms);
  --private-file-transition-duration: var(--mds-file-transition-duration);
  --private-icon-download-offset: 10%;

  @apply focus-bounce;

  align-items: stretch;
  background-color: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));
  border-radius: var(--magma-radius-xl, var(--radius-squircle-xl, 36px));
  box-shadow: var(--shadow-outline-weak, 0 0 0 1px rgb(0 0 0 / 0.05), 0 1px 2px 0 rgb(0 0 0 / 0.05));
  color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  corner-shape: var(--magma-corner-shape, squircle);
  cursor: pointer;
  display: inline-flex;
  overflow: hidden;
  transition-duration: var(--private-file-transition-duration);
  transition-property: box-shadow, outline, outline-offset;
  transition-timing-function: var(--ease-out-cubic, cubic-bezier(0.215, 0.61, 0.355, 1));
  width: 100%;
}

:host(:focus-visible) {
  @apply focus-bounce--focused;
}

:host(:hover) {
  box-shadow: var(--shadow-box-md, rgb(0 0 0 / 0.06) 0px 0px 0px 1px, rgb(0 0 0 / 0.03) 0px 1px 1px -0.5px, rgb(0 0 0 / 0.04) 0px 2px 2px -1px, rgb(0 0 0 / 0.04) 0px 3px 3px -1.5px, rgb(0 0 0 / 0.03) 0px 5px 5px -2.5px, rgb(0 0 0 / 0.03) 0px 10px 10px -5px, rgb(0 0 0 / 0.03) 0px 24px 24px -8px);

  & .download-icon {
    opacity: 1;
    transform: translateY(0);
  }

  & .image-preview,
  & .icon-preview {
    opacity: 0;
    transform: translateY(var(--private-icon-download-offset));
  }
}

.download-icon {
  align-items: center;
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 0;
  position: absolute;
  transform: translateY(calc(var(--private-icon-download-offset) * -1));
  transition-duration: inherit;
  transition-property: opacity, transform;
  transition-timing-function: inherit;
}

.preview {
  align-items: center;
  background-color: var(--mds-file-preview-icon-background);
  color: var(--mds-file-preview-color, rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73))));
  display: flex;
  fill: var(--mds-file-preview-icon-color, rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73))));
  flex-shrink: 0;
  justify-content: center;
  position: relative;
  transition-duration: inherit;
  transition-property: color, background-color, fill;
  transition-timing-function: var(--ease-out-sine, cubic-bezier(0.39, 0.575, 0.565, 1));
  width: --spacing(1400);
}

.image-preview {
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  inset: --spacing(300);
  position: absolute;
}

.image-preview,
.icon-preview {
  transition-duration: inherit;
  transition-property: opacity, transform;
  transition-timing-function: inherit;
}

.info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: --spacing(100);
  height: --spacing(1400);
  justify-content: center;
  min-width: 0px;
  padding: 0 --spacing(300);
}

.filename {
  display: flex;
  min-width: 0px;
}

.name {
  @apply truncate;

  min-width: 0px;
}

.extension {
  flex-shrink: 0;
}

.detail {
  align-items: baseline;
  display: flex;
  gap: --spacing(200);
  min-width: 0px;
}

.suffix {
  flex-shrink: 0;
  pointer-events: none;
}

.description {
  @apply truncate;

  color: rgb(var(--magma-text-disabled, var(--text-neutral-disabled, 119 119 119)));
  min-width: 0px;
}

.indicator {
  align-items: center;
  display: flex;
  justify-content: center;
  padding-right: --spacing(400);
}

.downloaded {
  @apply svg;

  fill: rgb(var(--magma-success-emphasis, var(--status-success-04, 0 128 57)));
}

:host([format='archive']),
:host([format='executable']) {
  --mds-file-preview-icon-color: rgb(var(--label-amaranth-04, 202 51 77));
  --mds-file-preview-color: rgb(var(--label-amaranth-04, 202 51 77));
  --mds-file-preview-icon-background: rgb(var(--label-amaranth-10, 255 232 233));
}

:host([format='attachment']) {
  --mds-file-preview-icon-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  --mds-file-preview-color: rgb(var(--magma-text-subtle, var(--text-neutral-subtle, 99 99 99)));
  --mds-file-preview-icon-background: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
}

:host([format='audio']),
:host([format='video']) {
  --mds-file-preview-icon-color: rgb(var(--label-violet-04, 128 78 232));
  --mds-file-preview-color: rgb(var(--label-violet-04, 128 78 232));
  --mds-file-preview-icon-background: rgb(var(--label-violet-10, 238 235 255));
}

:host([format='code']),
:host([format='data']),
:host([format='markup']) {
  --mds-file-preview-icon-color: rgb(var(--label-yellow-04, 140 107 22));
  --mds-file-preview-color: rgb(var(--label-yellow-04, 140 107 22));
  --mds-file-preview-icon-background: rgb(var(--label-yellow-10, 255 235 200));
}

:host([format='certificate']),
:host([format='document']) {
  --mds-file-preview-icon-color: rgb(var(--label-orange-04, 181 82 13));
  --mds-file-preview-color: rgb(var(--label-orange-04, 181 82 13));
  --mds-file-preview-icon-background: rgb(var(--label-orange-10, 255 233 222));
}

:host([format='email']),
:host([format='text']) {
  --mds-file-preview-icon-color: rgb(var(--label-blue-04, 44 96 250));
  --mds-file-preview-color: rgb(var(--label-blue-04, 44 96 250));
  --mds-file-preview-icon-background: rgb(var(--label-blue-10, 228 238 255));
}

:host([format='image']) {
  --mds-file-preview-icon-color: rgb(var(--label-green-04, 21 128 61));
  --mds-file-preview-color: rgb(var(--label-green-04, 21 128 61));
  --mds-file-preview-icon-background: rgb(var(--label-green-10, 201 248 218));
}

:host([format='slide']) {
  --mds-file-preview-icon-color: rgb(var(--label-orchid-04, 202 34 125));
  --mds-file-preview-color: rgb(var(--label-orchid-04, 202 34 125));
  --mds-file-preview-icon-background: rgb(var(--label-orchid-10, 255 231 240));
}

:host([format='spreadsheet']) {
  --mds-file-preview-icon-color: rgb(var(--label-lime-04, 81 124 12));
  --mds-file-preview-color: rgb(var(--label-lime-04, 81 124 12));
  --mds-file-preview-icon-background: rgb(var(--label-lime-10, 214 249 159));
}

:host([format='vector']) {
  --mds-file-preview-icon-color: rgb(var(--label-aqua-04, 4 122 143));
  --mds-file-preview-color: rgb(var(--label-aqua-04, 4 122 143));
  --mds-file-preview-icon-background: rgb(var(--label-aqua-10, 199 245 253));
}

/* 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-file-transition-duration: 0s;
}

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-file-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. */

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

  &:host(:hover) {
    box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
  }
}

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

    &:host(:hover) {
      box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
    }
  }
}

/* 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']) {
  box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
  color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));

  &:host(:hover) {
    box-shadow: var(--shadow-ring-strong-4, 0 0 0 4px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
  }
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    box-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
    color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));

    &:host(:hover) {
      box-shadow: var(--shadow-ring-strong-4, 0 0 0 4px rgb(var(--tone-neutral-01, 5 5 5) / 0.6));
    }
  }
}

