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


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


/**
 * @prop --mds-tab-direction-vertical-columns: Public. Defines the column layout for vertical tabs.
 * @prop --mds-tab-item-default-background: Background color for default tab items.
 * @prop --mds-tab-item-default-color: Text color for default tab items.
 * @prop --mds-tab-item-default-shadow: Shadow for default tab items.
 * @prop --mds-tab-item-hover-background: Background color for hovered tab items.
 * @prop --mds-tab-item-hover-color: Text color for hovered tab items.
 * @prop --mds-tab-item-hover-shadow: Shadow for hovered tab items, the default shadow when not set.
 * @prop --mds-tab-item-radius: Border radius for tab items.
 * @prop --mds-tab-item-selected-background: Background color for selected tab items.
 * @prop --mds-tab-item-selected-color: Text color for selected tab items.
 * @prop --mds-tab-item-selected-shadow: Shadow for selected tab items.
 * @prop --mds-tab-scroll-behavior: Scroll behavior for tab container.
 * @prop --mds-tab-scroll-scrollbar-margin: Margin for scrollbar.
 * @prop --mds-tab-scroll-scrollbar-radius: Radius of scrollbar.
 * @prop --mds-tab-scroll-scrollbar-size: Size of scrollbar.
 * @prop --mds-tab-scroll-scrollbar-thumb-background: Background color of scrollbar thumb.
 * @prop --mds-tab-scroll-scrollbar-track-background: Background color of scrollbar track.
 * @prop --mds-tab-slide-delay: Delay before tab slide animation.
 * @prop --mds-tab-tabs-background: Public. Background color of the tabs container.
 * @prop --mds-tab-tabs-gap: Gap between tabs.
 * @prop --mds-tab-tabs-overflow-shadow-size: Size of the overflow shadow.
 * @prop --mds-tab-tabs-overflow-shadow: Shadow applied to overflowed tabs.
 * @prop --mds-tab-tabs-padding: Padding inside the tabs container.
 * @prop --mds-tab-tabs-radius: Border radius of the tabs container.
 * @prop --mds-tab-tabs-wrapper-margin: Public. Margin for the tabs wrapper.
 * @prop --mds-tab-tabs-wrapper-outline-opacity: Opacity of the wrapper outline.
 * @prop --mds-tab-tabs-wrapper-shadow-color: Color of the wrapper shadow.
 * @prop --mds-tab-tabs-wrapper-shadow: Public. Shadow for the tabs wrapper.
 * @prop --mds-tab-transition-duration: Duration of tab transition animation.
 * @prop --mds-tab-transition-timing-function: Timing function for tab transition animation.
 */

/* ❌ Not supported

@property --mds-tab-item-default-shadow {
  inherits: false;
  initial-value: transparent;
  syntax: '<box-shadow>';
}

*/

/* ❌ Not supported
@property --mds-tab-item-hover-shadow {
  inherits: false;
  initial-value: transparent;
  syntax: '<box-shadow>';
}
*/

/* ❌ Not supported

@property --mds-tab-item-selected-shadow {
  inherits: false;
  initial-value: var(--shadow);
  syntax: '<box-shadow>';
}

@property --mds-tab-scroll-behavior {
  inherits: false;
  initial-value: smooth;
  syntax: '<scroll-behavior>';
}
*/

/* ❌ Not supported
@property --mds-tab-tabs-wrapper-shadow {
  inherits: false;
  initial-value: 0 0 0 2px var(--mds-tab-tabs-wrapper-shadow-color) inset;
  syntax: "<box-shadow>";
}

@property --mds-tab-transition-timing-function {
  inherits: false;
  initial-value: var(--ease-out-expo);
  syntax: "<timing-function>";
}

@property --mds-tab-tabs-overflow-shadow {
  inherits: false;
  initial-value: 0 0 var(--mds-tab-tabs-overflow-shadow-size) -2px rgb(0 0 0 / 0.375);
  syntax: "<box-shadow>";
}
*/

:host {
  --mds-tab-direction-vertical-columns: auto auto;
  --mds-tab-item-default-background: transparent;
  --mds-tab-item-default-color: rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73)));
  --mds-tab-item-default-shadow: none;
  --mds-tab-item-hover-background: transparent;
  --mds-tab-item-hover-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));

  /* the items are buttons: their radius is capped at a part of their height like mds-button's
     (#913), and the strip, one row of them, at that radius plus its padding */
  --mds-tab-item-radius: min(
    calc(var(--mds-tab-tabs-radius, var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px))) - var(--mds-tab-tabs-padding, --spacing(200))),
    var(--magma-corner-cap, 0.5) * var(--private-tab-item-height)
  );
  --mds-tab-item-selected-background: rgb(var(--magma-surface-overlay, var(--surface-neutral-overlay, 255 255 255)));
  --mds-tab-item-selected-color: rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5)));
  --mds-tab-item-selected-shadow: var(--shadow-sm, 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1));
  --mds-tab-scroll-behavior: smooth;
  --mds-tab-scroll-scrollbar-margin: 0;
  --mds-tab-scroll-scrollbar-radius: 0;
  --mds-tab-scroll-scrollbar-size: --spacing(200);
  --mds-tab-scroll-scrollbar-thumb-background: rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42)) / 0.3);
  --mds-tab-scroll-scrollbar-track-background: rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225)));

  /* stylelint-disable-next-line magma/token-values -- 125ms no --duration-* step says it */
  --mds-tab-slide-delay: 0.125s;
  --mds-tab-tabs-background: rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)));
  --mds-tab-tabs-gap: --spacing(200);
  --mds-tab-tabs-overflow-shadow-size: --spacing(600);
  --mds-tab-tabs-overflow-shadow: 0 0 var(--mds-tab-tabs-overflow-shadow-size, --spacing(600)) --spacing(-50)
    rgb(var(--magma-shadow-ink, var(--tone-neutral-01, 5 5 5)) / 0.375);
  --mds-tab-tabs-padding: --spacing(200);
  --mds-tab-tabs-radius: min(
    var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px)),
    var(--magma-corner-cap, 0.5) * var(--private-tab-item-height) + var(--mds-tab-tabs-padding, --spacing(200))
  );
  --mds-tab-tabs-wrapper-margin: 0;
  --mds-tab-tabs-wrapper-outline-opacity: 0.7;
  --mds-tab-tabs-wrapper-shadow-color: var(--mds-tab-tabs-background, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237))));
  --mds-tab-tabs-wrapper-shadow: 0 0 0 --spacing(50) var(--mds-tab-tabs-wrapper-shadow-color, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)))) inset;
  --mds-tab-transition-duration: var(--duration-500, 500ms);
  --private-tab-transition-duration: var(--mds-tab-transition-duration, var(--duration-500, 500ms));

  /* the height of an item, an mds-button md unless the tab sets size="sm" */
  --private-tab-item-height: --spacing(900);
  --mds-tab-transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  --mds-tab-corner-shape: var(--magma-corner-shape, squircle);

  border-radius: var(--mds-tab-tabs-radius, var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px)));
  corner-shape: var(--mds-tab-corner-shape, round);
  display: grid;
  gap: 0 --spacing(600);
  grid-template-rows: min-content auto;
  position: relative;
}

/* Animation preference: scroll-behavior is a keyword, so its reduced-motion state
 * is handled here, cross-browser, via @media. This follows the OS preference
 * (the in-app explicit override does not reach a keyword). The transition
 * durations are reduced separately through the flag in
 * css/mds-tab-pref-animation.css. */

@media (prefers-reduced-motion: reduce) {
  :host {
    --mds-tab-scroll-behavior: auto;
  }
}

:host([size='sm']) {
  --private-tab-item-height: --spacing(700);
}

:host([animation='slide']) ::slotted(mds-tab-item) {
  --mds-tab-item-hover-background: transparent;
  --mds-tab-item-hover-shadow: none;
  --mds-tab-item-selected-background: transparent;
  --mds-tab-item-selected-shadow: transparent;
  --mds-tab-item-default-background: transparent;
  --mds-tab-item-default-shadow: none;
}

.tabs {
  align-items: flex-start;
  background-color: var(--mds-tab-tabs-background, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237))));
  border-radius: inherit;
  box-sizing: border-box;
  corner-shape: inherit;
  display: flex;
  gap: var(--mds-tab-tabs-gap, --spacing(200));
  overflow: auto;
  padding: var(--mds-tab-tabs-padding, --spacing(200));
  scroll-behavior: var(--mds-tab-scroll-behavior);
  scroll-snap-type: x mandatory;
  transition-duration: var(--private-tab-transition-duration);
  transition-property: background-color;
  transition-timing-function: var(--mds-tab-transition-timing-function);
  z-index: 0;
}

.tabs-wrapper {
  border-radius: inherit;
  corner-shape: inherit;
  display: grid;
  flex-shrink: 0;
  margin: var(--mds-tab-tabs-wrapper-margin, 0);
  max-width: max-content;
  overflow: hidden;
  position: relative;
}

.tabs-wrapper--fill {
  max-width: 100%;
}

.tabs-wrapper::after {
  border-radius: inherit;
  box-shadow: var(--mds-tab-tabs-wrapper-shadow);
  content: '';
  corner-shape: inherit;
  inset: 0;
  opacity: var(--mds-tab-tabs-wrapper-outline-opacity, 0.7);
  pointer-events: none;
  position: absolute;
  transition-duration: var(--private-tab-transition-duration);
  transition-property: box-shadow, opacity;
  transition-timing-function: var(--mds-tab-transition-timing-function);
}

.contents {
  --mds-tab-contents-height: auto;

  @apply hide-scrollbar;

  align-items: stretch;
  box-sizing: border-box;
  display: flex;
  flex-grow: 1;
  gap: --spacing(600);
  height: var(--mds-tab-contents-height);
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  scroll-behavior: var(--mds-tab-scroll-behavior);
  scroll-snap-type: x mandatory;
  transition-duration: var(--private-tab-transition-duration);
  transition-property: height;
  transition-timing-function: var(--mds-tab-transition-timing-function);
}

/* a strip without panels: the slot is still there, waiting for them, so :empty never matched */

.contents--empty {
  display: none;
}

::slotted([slot='content']) {
  flex-basis: 0;
  flex-grow: 1;
  min-width: 100%;
  scroll-snap-align: start;
  width: 100%;
}

::slotted([slot='content'][mds-tab-content-hidden]) {
  display: none !important;
}

.tabs {
  position: relative;
}

.slider {
  --mds-tab-slider-offset-x: 0;
  --mds-tab-slider-offset-y: 0;
  --mds-tab-slider-width: 0;
  --mds-tab-slider-height: 0;

  background-color: var(--mds-tab-item-selected-background);
  border-radius: var(--mds-tab-item-radius);
  box-shadow: var(--mds-tab-item-selected-shadow);
  corner-shape: var(--mds-tab-corner-shape);
  height: var(--mds-tab-slider-height);
  inset: 0 auto auto 0;
  pointer-events: none;
  position: absolute;
  transform: translate(var(--mds-tab-slider-offset-x), var(--mds-tab-slider-offset-y));
  transition-duration: var(--mds-tab-transition-duration, var(--duration-500, 500ms));
  transition-property: background-color, box-shadow, transform, width;
  transition-timing-function: var(--mds-tab-transition-timing-function);
  width: var(--mds-tab-slider-width);
  will-change: height, transform, width;
  z-index: -1;
}

/* Drawn in place, not slid there: on load, after a change of the layout, when the strip is
   shown again (#924). Only the geometry stops, a change of theme still fades the colours. */

.slider--still {
  transition-property: background-color, box-shadow;
}

::slotted(mds-tab-item) {
  position: relative;
  z-index: 1;
}

/* a column of items is tall: the browser does not clamp the radius of the strip, nor does
   the cap */

:host([direction='vertical']) {
  --mds-tab-tabs-radius: var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px));

  grid-template-columns: var(--mds-tab-direction-vertical-columns, auto auto);
  grid-template-rows: 1fr;
}

:host([direction='vertical']) .tabs {
  align-self: start;
  flex-direction: column;
}

:host([direction='vertical']) .tabs-wrapper {
  align-self: start;
  max-width: none;
}

:host([direction='vertical'][fill]) .tabs-wrapper,
:host([direction='vertical'][fill]) .tabs {
  align-self: auto;
}

/* without panels the column of the contents is empty, but it still takes its share of the
   width: the strip spans it too */

:host([direction='vertical']) .tabs-wrapper--no-content {
  grid-column: 1 / -1;
}

:host([direction='vertical'])::slotted(mds-tab-item) {
  width: 100%;
}

:host(:not([scrollbar])) .tabs {
  @apply hide-scrollbar;
}

:host(:not([scrollbar])) .tabs::-webkit-scrollbar {
  display: none;
}

:host([scrollbar]) .tabs::-webkit-scrollbar {
  height: var(--mds-tab-scroll-scrollbar-size, --spacing(200));
  width: var(--mds-tab-scroll-scrollbar-size, --spacing(200));
}

:host([scrollbar]) .tabs::-webkit-scrollbar-track {
  background-color: var(--mds-tab-scroll-scrollbar-track-background, rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225))));
  border-radius: var(--mds-tab-scroll-scrollbar-radius, 0);
  margin-block: var(--mds-tab-scroll-scrollbar-margin, 0);
  margin-inline: var(--mds-tab-scroll-scrollbar-margin, 0);
}

:host([scrollbar]) .tabs::-webkit-scrollbar-thumb {
  background-color: var(--mds-tab-scroll-scrollbar-thumb-background, rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42)) / 0.3));
  border-radius: var(--mds-tab-scroll-scrollbar-radius, 0);
}

@supports (scrollbar-color: transparent transparent) {
  .tabs {
    scrollbar-color: var(--mds-tab-scroll-scrollbar-thumb-background, rgb(var(--magma-surface-inverse, var(--tone-neutral-02, 42 42 42)) / 0.3))
      var(--mds-tab-scroll-scrollbar-track-background, rgb(var(--magma-wash-base, var(--tone-neutral-09, 225 225 225))));
    scrollbar-width: thin;
  }
}

.tabs-wrapper-overflow-left,
.tabs-wrapper-overflow-right {
  --size: calc(var(--mds-tab-tabs-padding, --spacing(200)) * 2);
  --offset-outside: calc(var(--size) + var(--mds-tab-tabs-overflow-shadow-size, --spacing(600)));

  background-color: var(--mds-tab-tabs-background, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237))));
  border-radius: 100%;
  box-shadow: var(--mds-tab-tabs-overflow-shadow);
  content: '';
  display: inline-flex;
  height: auto;
  pointer-events: none;
  position: absolute;
  transition-duration: var(--duration-500, 500ms);
  transition-property: transform;
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  width: var(--size);
  z-index: 2;
}

.tabs-wrapper-overflow-left {
  inset: 0 auto 0 0;
  transform: translateX(calc(var(--offset-outside) * -1));
}

.tabs-wrapper-overflow-right {
  inset: 0 0 0 auto;
  transform: translateX(var(--offset-outside));
}

.tabs-wrapper-overflow-left--show {
  transform: translateX(-100%);
}

.tabs-wrapper-overflow-right--show {
  transform: translateX(100%);
}

.tabs-wrapper::after {
  border-radius: var(--mds-tab-tabs-radius, var(--magma-radius-2xl, var(--radius-squircle-2xl, 40px)));
  box-shadow: var(--mds-tab-tabs-wrapper-shadow);
  content: '';
  inset: 0;
  opacity: var(--mds-tab-tabs-wrapper-outline-opacity, 0.7);
  pointer-events: none;
  position: absolute;
  transition-duration: var(--mds-tab-transition-duration, var(--duration-500, 500ms));
  transition-property: box-shadow, opacity;
  transition-timing-function: var(--mds-tab-transition-timing-function);
  z-index: 1;
}

/* 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.
 *
 * The track needs no dark value: --magma-wash-soft flips per mode. Only the
 * selected thumb is refined, lifted to wash-strong because the overlay surface
 * sits too close to the dark track to read as selected. */

:host([pref-mode='dark']:not([pref-theme-scheme='light'])),
:host([pref-theme-scheme='dark']) {
  --mds-tab-item-selected-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
}

@media (prefers-color-scheme: dark) {
  :host([pref-mode='system']:not([pref-theme-scheme='light'])),
  :host(:not([pref-mode]):not([pref-theme-scheme='light'])) {
    --mds-tab-item-selected-background: rgb(var(--magma-wash-strong, var(--tone-neutral-08, 208 208 208)));
  }
}

/* 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-tab-item-selected-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
  --mds-tab-tabs-wrapper-shadow: 0 0 0 --spacing(50) var(--mds-tab-tabs-wrapper-shadow-color, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237)))) inset;
  --mds-tab-tabs-wrapper-shadow-color: rgb(var(--magma-border-strong, var(--border-neutral-strong, 140 140 140)));
  --mds-tab-tabs-wrapper-outline-opacity: 0.3;
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-tab-item-selected-shadow: var(--shadow-ring-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.3));
    --mds-tab-tabs-wrapper-shadow: 0 0 0 --spacing(50) var(--mds-tab-tabs-wrapper-shadow-color, rgb(var(--magma-wash-soft, var(--tone-neutral-10, 237 237 237))))
      inset;
    --mds-tab-tabs-wrapper-shadow-color: rgb(var(--magma-border-strong, var(--border-neutral-strong, 140 140 140)));
    --mds-tab-tabs-wrapper-outline-opacity: 0.3;
  }
}

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

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

