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


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


/**
 * @prop --mds-header-bar-hamburger-color: The color of the hamburger icon used in the header bar; inside an `mds-header` it defaults to the `--mds-header-icon-color` or `--mds-header-color` set on it.
 */

:host {
  --mds-header-bar-hamburger-color: var(
    --mds-header-icon-color,
    var(--mds-header-color, rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73))))
  );
  --mds-header-bar-transition-duration: var(--duration-500, 500ms);
  --private-header-bar-transition-duration: var(--mds-header-bar-transition-duration);

  background-color: rgb(var(--magma-surface-raised, var(--surface-neutral-raised, 248 248 248)));
  box-shadow: var(--shadow-md-sharp, 0 0 1px 1px rgb(0 0 0 / 0.06), 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -1px rgb(0 0 0 / 0.06));
  display: flex;
  interpolate-size: allow-keywords; /* not supported yet https://youtu.be/JN-nme9oF10 */
  justify-content: center;
  margin-left: auto;
  margin-right: auto;
  max-width: 100%;

  /* the gutter of the page outside the content, its frame inside (#1189, widths/page): the content
     of the bar starts where the content of a page-frame does, and a theme that moves the page moves
     the bar with it */
  padding: --spacing(400) var(--magma-width-page-gutter, 24px);

  /* in the flow of mds-header, which stays put while the page scrolls (#1189, surfaces/band) */
  position: relative;
  transition-duration: var(--private-header-bar-transition-duration);
  transition-property: background-color, border-radius, margin, max-width, transform, width;
  transition-timing-function: var(--ease-out-expo, cubic-bezier(0.19, 1, 0.22, 1));
  width: auto;
  z-index: var(--mds-header-z-index, 1000);
}

.logo {
  color: inherit;
  display: flex;
}

.content {
  align-items: center;
  display: flex;
  flex-grow: 1;
  gap: --spacing(400);
  justify-content: space-between;
  max-width: var(--magma-width-page, 1280px);
}

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

.nav {
  display: inline-flex;
  flex-shrink: 0;
  gap: --spacing(400);
}

.nav--hidden {
  display: none;
}

.menu {
  --mds-button-border-opacity: 0;

  fill: var(--mds-header-bar-hamburger-color, rgb(var(--magma-text-muted, var(--text-neutral-muted, 73 73 73))));
  padding: 0;
}

.menu::part(icon) {
  width: --spacing(800);
}

:host([menu='desktop']) .menu,
:host([nav='desktop']) .nav {
  @apply max-tablet:hidden;
}

:host([menu='mobile']) .menu,
:host([nav='mobile']) .nav {
  @apply desktop:hidden;
}

:host([menu='none']) .menu,
:host([nav='none']) .nav {
  display: none;
}

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

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

/* Theme preference. Background and elevation now come from the semantic surface
 * layer (--magma-surface-*, spec 6.1): it flips per mode at :root and inherits
 * into the shadow DOM, so this component needs no per-mode dark refinement. The
 * former dark override (a wash background re-set plus a ring that faked elevation
 * on the old flat-black canvas) is intentionally gone. */

/* 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-header-bar-hamburger-color: var(
    --mds-header-icon-color,
    var(--mds-header-color, rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5))))
  );

  box-shadow: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6)), var(--shadow-2xl, 0 25px 50px -12px rgb(0 0 0 / 0.25));
}

@media (prefers-contrast: more) {
  :host([pref-contrast='system']),
  :host(:not([pref-contrast])) {
    --mds-header-bar-hamburger-color: var(
      --mds-header-icon-color,
      var(--mds-header-color, rgb(var(--magma-text-default, var(--text-neutral-default, 5 5 5))))
    );

    box-shadow: var(--shadow-ring-strong-2, 0 0 0 2px rgb(var(--tone-neutral-01, 5 5 5) / 0.6)), var(--shadow-2xl, 0 25px 50px -12px rgb(0 0 0 / 0.25));
  }
}

