@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;
}


/**
 * @prop --mds-details-duration: Sets the transition duration for details component
 * @prop --mds-details-icon-color: Sets the color of the details icon
 * @prop --mds-details-helper-icon-color: Sets the color of the helper icon in the details component
 */

:host {
  --mds-details-duration: var(--duration-300, 300ms);
  --private-details-duration: var(--mds-details-duration, var(--duration-300, 300ms));
  --mds-details-icon-color: rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)));
  --mds-details-helper-icon-color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));

  align-items: flex-start;
  display: flex;
  gap: --spacing(200);
}

.content {
  @apply focus-bounce;

  display: grid;
}

.details {
  display: grid;
  gap: --spacing(400);
  grid-template-rows: 0fr;
  opacity: 0;
  overflow: hidden;
  padding-top: 0;
  pointer-events: none;
  transition-duration: var(--private-details-duration);

  /* visibility leaves the closed content out of the tab order and of the accessibility tree, and
     the slotted content inherits it; as a transition it turns visible at the start of the opening
     and hidden at the end of the closing, so the content is seen for the whole animation */
  transition-property: grid-template-rows, opacity, padding, visibility;
  visibility: hidden;
}

.content-expander {
  display: grid;
  gap: --spacing(500);
  min-height: 0;
}

.details.opened {
  grid-template-rows: 1fr;
  opacity: 1;
  overflow: visible;
  padding-top: --spacing(300);
  pointer-events: auto;

  /* inherit, not visible: the open content of a details inside a closed one stays hidden */
  visibility: inherit;
}

.header {
  @apply focus-bounce;

  align-items: center;

  /* a control one line tall, 24px as its icon: capped at a part of that height, as mds-button's
     radius is (#913) */
  border-radius: min(var(--magma-radius-xs, var(--radius-squircle-xs, 14px)), var(--magma-corner-cap, 0.5) * --spacing(600));
  corner-shape: var(--magma-corner-shape, squircle);
  display: inline-flex;
  gap: --spacing(200);
}

.header:focus-visible {
  @apply focus-bounce--focused;
}

.icon {
  cursor: pointer;
  fill: var(--mds-details-icon-color, rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255))));
}

.icon--hidden {
  display: none;
}

.title {
  cursor: pointer;
}

.helper-icon {
  @apply svg;

  cursor: pointer;
  fill: var(--mds-details-helper-icon-color, rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73))));
  flex-shrink: 0;
  rotate: 0deg;
  transition-duration: var(--duration-300, 300ms);
  transition-property: rotate;
  transition-timing-function: var(--ease-in-out-expo, cubic-bezier(1, 0, 0, 1));
}

.helper-icon.opened {
  rotate: 90deg;
}

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

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

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-details-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']) {
  --mds-details-icon-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-details-icon-color: rgb(var(--magma-accent-fg, var(--variant-primary-03, 0 73 211)));
  }
}

