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


mds-table-body,
mds-table-footer,
mds-table-header {
  &:not(:is([hydrated], .hydrated)) {
    @apply not-hydrated;
  }
}


/**
 * @prop --mds-table-actions-gap: Gap between table action elements.
 * @prop --mds-table-background-alt: Background color of the rows while a column sorts the table, and of the table behind them.
 * @prop --mds-table-background: Public. Default background color of the table.
 * @prop --mds-table-border-color: Color of the frame of the table; the lines inside it take --mds-table-separator-color.
 * @prop --mds-table-border-width: Width of the table border.
 * @prop --mds-table-cell-padding: Public. Padding inside table cells.
 * @prop --mds-table-color-alt: Text color of the rows while a column sorts the table.
 * @prop --mds-table-color: Public. Default text color of the table.
 * @prop --mds-table-separator-color: Color of the lines inside the table: between the rows, under the header, above the footer and at the edge of the batch actions panel.
 */

:host {
  --mds-table-transition-duration: var(--duration-300, 300ms);
  --private-table-transition-duration: var(--mds-table-transition-duration);
  --mds-table-actions-gap: --spacing(200);
  --mds-table-background-alt: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));
  --mds-table-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));

  /* overlay: the fields inside take the step below (#1193) */
  --magma-field-fill: var(--magma-surface-default, var(--surface-neutral-default, 242 242 242));
  --mds-table-border-color: rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206)));
  --mds-table-border-width: --spacing(50);
  --mds-table-cell-padding: --spacing(400);
  --mds-table-color-alt: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
  --mds-table-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  --mds-table-separator-color: rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206)));
  --mds-table-batch-actions-width: --spacing(4800);

  /* internal: the cells draw with the separator colour, which a consumer can set apart from
     the frame; by default both are border-muted, so frame and grid read as one */
  --private-cell-border-color: var(--mds-table-separator-color, rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206))));
  --private-cell-border-width: var(--mds-table-border-width);

  @apply ease-out;

  background-color: var(--mds-table-background-alt);
  border: var(--mds-table-border-width) solid var(--mds-table-border-color, rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206)))) !important;
  border-color: var(--mds-table-border-color, rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206))));
  border-radius: var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px));
  corner-shape: var(--magma-corner-shape, squircle);
  display: flex;
  overflow: hidden;
  transition-duration: var(--duration-200, 200ms);
  transition-property: background-color, border-color, color;
}

/* The wrapper is the scroll container: its background shows only where the table does not
   cover it, as in the strip a trackpad uncovers when it bounces the table past its first or
   last column. That strip is behind the rows, so it takes the sunken surface. Every cell
   paints a full colour of its own (the body and the footer give one to their rows, the header
   cells paint theirs), so nothing in the table lets this colour through, not even halfway
   through a transition. */

.table-wrapper {
  background-color: rgb(var(--magma-surface-sunken, var(--surface-neutral-sunken, 235 235 235)));
  corner-shape: inherit;
  display: flex;
  overflow: auto;
  width: 100%;
}

.table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.batch-actions-wrapper {
  corner-shape: inherit;
  display: flex;
  flex-shrink: 0;
  max-width: 0px;
  transition-duration: var(--private-table-transition-duration);
  transition-property: max-width;
  transition-timing-function: var(--ease-in-out-circ, cubic-bezier(0.785, 0.135, 0.15, 0.86));
  width: 100%;
}

.batch-actions-wrapper--has-selected-rows {
  max-width: var(--mds-table-batch-actions-width);
}

.batch-actions-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: --spacing(300);
}

.batch-actions {
  @apply grid-cols-full auto-rows-min;

  background-color: var(--mds-table-background);
  border-left: var(--mds-table-border-width) solid var(--mds-table-separator-color, rgb(var(--magma-border-muted, var(--border-neutral-muted, 206 206 206))));
  box-sizing: border-box;
  display: grid;
  flex-grow: 1;
  gap: --spacing(50);
  min-width: var(--mds-table-batch-actions-width);
  padding: calc(var(--mds-table-cell-padding) / 2);
  width: 100%;
}

::slotted([slot='batch-action']) {
  justify-content: start;
  width: 100%;
}

:host([selection]:not([selection='false'])) {
  --mds-table-body-background: var(--mds-table-body-background-hover);
}

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

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

/* Theme preference. Surface, border and text now come from the semantic layer
 * (--magma-surface-* / --magma-border-* / --magma-text-*, spec 6.1/6.2/6.3):
 * they flip per mode at :root and inherit into the shadow DOM, so this component
 * needs no per-mode dark refinement. The former dark override (a --tone-*
 * background, border and text re-set that darkened the table on the old
 * flat-black canvas) is intentionally gone. The high-contrast axis is orthogonal
 * and still refined in mds-table-pref-contrast(-dark).css. */

/* The hovered row is the paper of the mode: --magma-surface-default, which the
 * layer promotes to the seed 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-table-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  --mds-table-body-background-hover: rgb(var(--magma-surface-default, var(--surface-neutral-default, 242 242 242)));
  --mds-table-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
}

@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-table-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
    --mds-table-body-background-hover: rgb(var(--magma-surface-default, var(--surface-neutral-default, 242 242 242)));
    --mds-table-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

@media (prefers-color-scheme: dark) {
  :host([pref-contrast='more'][pref-mode='system']:not([pref-theme-scheme='light'])) {
    --mds-table-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
    --mds-table-body-background-hover: rgb(var(--magma-surface-default, var(--surface-neutral-default, 242 242 242)));
    --mds-table-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :host([pref-contrast='system'][pref-mode='system']:not([pref-theme-scheme='light'])) {
    --mds-table-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
    --mds-table-body-background-hover: rgb(var(--magma-surface-default, var(--surface-neutral-default, 242 242 242)));
    --mds-table-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  }
}

