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


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


/**
 * @prop --mds-kpi-item-icon-color: Set the fill color of the icon element
 * @prop --mds-kpi-item-info-background: Set the `background-color` of the text area element
 * @prop --mds-kpi-item-text-animation-placeholder-char: Sets the animation placeholder char of the text
 * @prop --mds-kpi-item-text-animation-speed: Sets the animation speed of the text
 */

:host {
  --mds-kpi-item-icon-color: rgb(var(--magma-accent-emphasis, var(--variant-primary-04, 11 96 255)));
  --mds-kpi-item-info-background: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));
  --mds-kpi-item-text-animation-placeholder-char: var(
    --mds-kpi-text-animation-placeholder-char,
    ' '
  );
  --mds-kpi-item-text-animation-speed: var(--mds-kpi-text-animation-speed, 0.15);
  --mds-kpi-item-transition-duration: var(--duration-300, 300ms);
  --private-kpi-item-padding: --spacing(400);
  --private-kpi-item-radius: var(--magma-radius-4xl, var(--radius-squircle-4xl, 80px));
  --private-kpi-item-transition-duration: var(--mds-kpi-item-transition-duration);

  @apply ease-out;

  aspect-ratio: 1;
  background-color: rgb(var(--magma-accent-surface-subtle, var(--variant-primary-10, 231 237 248)));
  border-radius: var(--private-kpi-item-radius);
  corner-shape: var(--magma-corner-shape, squircle);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  padding: var(--private-kpi-item-padding);
  transition-duration: var(--private-kpi-item-transition-duration);
  transition-property: background-color, box-shadow;
}

.icon-container {
  @apply ease-out;

  align-items: center;
  display: flex;
  flex-grow: 1;
  justify-content: center;
  transition-duration: var(--private-kpi-item-transition-duration);
  transition-property: background-color;
}

.icon {
  @apply ease-out;

  fill: var(--mds-kpi-item-icon-color);
  transition-duration: var(--private-kpi-item-transition-duration);
  transition-property: fill;
  width: 40%;
}

/* Concentric corners: the panel sits in the corner of the card, so its radius is the card's
   minus the gap between them - the two read the same variables and cannot drift. A fixed
   step could not: the card radius follows the corner shape, the gap does not, so the one
   step that fitted `round` was already wrong on the squircle scale.

   The bottom pair is what the rule is about; the top two face nothing but the icon. They
   carry the same value for the simple reason that a box reads as one shape, and where the
   panel is too short to hold it the global clamp scales all four down together - the same
   mechanism every pill in the system leans on. */

.info {
  @apply ease-out;

  background-color: var(--mds-kpi-item-info-background);
  border-radius: max(
    0px,
    calc(var(--private-kpi-item-radius) - var(--private-kpi-item-padding))
  );
  box-shadow: var(--shadow-sm, 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1));
  corner-shape: inherit;
  display: grid;
  flex-shrink: 0;
  gap: 0;
  justify-content: center;
  padding: --spacing(400);
  text-align: center;
  transition-duration: var(--private-kpi-item-transition-duration);
  transition-property: background-color, border-radius, box-shadow;
}

/* The value carries class="value", not class="label": spelled the old way these two
   variables reached the description only, so the number animated at the mds-text default
   of 0.5 while the line under it ran at the 0.15 the KPI asks for. */

.value,
.description {
  @apply ease-out;

  --mds-text-animation-speed: var(--mds-kpi-item-text-animation-speed);
  --mds-text-animation-placeholder-char: var(--mds-kpi-item-text-animation-placeholder-char);

  transition-duration: var(--private-kpi-item-transition-duration);
  transition-property: fill;
}

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

@media (prefers-reduced-motion: reduce) {
  :host([pref-animation='system']),
  :host(:not([pref-animation])) {
    --private-kpi-item-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']) {
  --mds-kpi-item-info-background: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));

  background-color: rgb(var(--magma-accent-surface, var(--variant-primary-09, 213 224 245)));
  box-shadow: var(--shadow-ring, 0 0 0 1px 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'])) {
    --mds-kpi-item-info-background: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));

    background-color: rgb(var(--magma-accent-surface, var(--variant-primary-09, 213 224 245)));
    box-shadow: var(--shadow-ring, 0 0 0 1px 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-lg, 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)), var(--shadow-ring, 0 0 0 1px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
  color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));

  .info {
    box-shadow: var(--shadow-ring, 0 0 0 1px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
  }
}

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

    .info {
      box-shadow: var(--shadow-ring, 0 0 0 1px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
    }
  }
}

/* In dark the pref-mode sheet moves the info panel to a wash; high contrast puts
 * it back on its base role, --magma-surface-raised, so it stands off the paper
 * page the layer promotes under pref-contrast-more (spec 9.3). */

:host([pref-contrast='more'][pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-contrast='more'][pref-theme-scheme='dark']) {
  --mds-kpi-item-info-background: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));

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

@media (prefers-contrast: more) {
  :host([pref-contrast='system'][pref-mode='dark']:not([pref-theme-scheme='light'])),
  :host([pref-contrast='system'][pref-theme-scheme='dark']) {
    --mds-kpi-item-info-background: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));

    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-contrast='more'][pref-mode='system']:not([pref-theme-scheme='light'])) {
    --mds-kpi-item-info-background: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));

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

@media (prefers-contrast: more) {

  @media (prefers-color-scheme: dark) {
    :host([pref-contrast='system'][pref-mode='system']:not([pref-theme-scheme='light'])) {
      --mds-kpi-item-info-background: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));

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

