/**
 * Block Sticky Header – frontend styles
 * Applied when body has .bsh-enabled; header receives .bsh-header from JS.
 */

/* Base sticky positioning – JS sets --bsh-top for admin bar offset */
.bsh-enabled .bsh-header.bsh-stuck {
  position: sticky;
  top: var(--bsh-top, 0);
  z-index: var(--bsh-z-index, 999);
  transition:
    transform var(--bsh-transition-duration, 300ms) ease,
    box-shadow var(--bsh-transition-duration, 300ms) ease,
    background-color var(--bsh-transition-duration, 300ms) ease,
    transform-origin var(--bsh-transition-duration, 300ms) ease,
    margin-bottom var(--bsh-transition-duration, 300ms) ease;
}

/* Hide on scroll down: move up off-screen */
.bsh-enabled .bsh-header.bsh-stuck.bsh-hidden {
  transform: translateY(-100%);
}

/* Header background, per state (Background style Solid). --bsh-bg-top is the resting state and
   --bsh-bg the docked one; the Swiss theme sets both (theme.json settings.custom.header), and JS
   switches the .bsh-docked class. Unset, both are transparent. */
.bsh-enabled .bsh-header.bsh-stuck:not(.bsh-docked).bsh-custom-bg {
  background-color: var(--bsh-bg-top, transparent) !important;
}
.bsh-enabled .bsh-header.bsh-stuck.bsh-docked.bsh-custom-bg {
  background-color: var(--bsh-bg, transparent) !important;
}

/* Theme wrappers (e.g. .has-background) are neutralized in both states, so the color — or a
   deliberate transparency — is the only thing visible. */
.bsh-enabled .bsh-header.bsh-stuck.bsh-custom-bg > .has-background,
.bsh-enabled
  .bsh-header.bsh-stuck.bsh-custom-bg
  > [class*="has-"][class*="-background"],
.bsh-enabled .bsh-header.bsh-stuck.bsh-blur > .has-background,
.bsh-enabled
  .bsh-header.bsh-stuck.bsh-blur
  > [class*="has-"][class*="-background"] {
  background-color: transparent !important;
  background-image: none !important;
}

/* Frosted blur: a pseudo-element carries the blur and the state's color, so the header itself can
   stay transparent and the layer cross-fades with the docked state. */
.bsh-enabled .bsh-header.bsh-stuck.bsh-blur {
  background-color: transparent !important;
}
.bsh-enabled .bsh-header.bsh-stuck.bsh-blur::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  -webkit-backdrop-filter: blur(var(--bsh-blur-px, 10px));
  backdrop-filter: blur(var(--bsh-blur-px, 10px));
  background-color: var(--bsh-bg-top, transparent);
  transition: background-color var(--bsh-transition-duration, 300ms) ease;
}
.bsh-enabled .bsh-header.bsh-stuck.bsh-docked.bsh-blur::before {
  background-color: var(--bsh-bg, transparent);
}

/* Shadow while docked, to separate the bar from the content sliding under it */
.bsh-enabled .bsh-header.bsh-stuck.bsh-docked.bsh-custom-bg,
.bsh-enabled .bsh-header.bsh-stuck.bsh-docked.bsh-blur {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* -------------------------------------------------------------------------
   Shrink on sticky: shorter header and smaller logo once the header is stuck.
   JS adds .bsh-shrink-ready plus .bsh-shrink-target / .bsh-shrink-logo to the
   matched elements, and sets --bsh-shrink-header-height / --bsh-shrink-logo-height (the
   compact sizes); each logo gets --bsh-shrink-logo-height-full (its own measured full-size height).
   Without JS everything keeps its full size.
   ------------------------------------------------------------------------- */
.bsh-enabled .bsh-header.bsh-shrink-ready.bsh-shrink-target,
.bsh-enabled .bsh-header.bsh-shrink-ready .bsh-shrink-target {
  transition:
    height var(--bsh-transition-duration, 300ms) ease,
    min-height var(--bsh-transition-duration, 300ms) ease;
}

/* Armed: pin the logo to its measured full height so the shrink has an explicit start
   value. `height: auto` and `max-height: none` are not interpolable, which made the logo
   jump to its new size instead of shrinking with the header. */
.bsh-enabled .bsh-header.bsh-shrink-ready.bsh-has-shrink-logo .bsh-shrink-logo {
  height: var(--bsh-shrink-logo-height-full, auto) !important;
  max-height: var(--bsh-shrink-logo-height-full, none) !important;
  width: auto !important;
  object-fit: contain;
  transition:
    height var(--bsh-transition-duration, 300ms) ease,
    max-height var(--bsh-transition-duration, 300ms) ease;
}

/* Reduced header height while stuck */
.bsh-enabled
  .bsh-header.bsh-stuck.bsh-docked.bsh-has-shrink-height.bsh-shrink-target,
.bsh-enabled
  .bsh-header.bsh-stuck.bsh-docked.bsh-has-shrink-height
  .bsh-shrink-target {
  height: var(--bsh-shrink-header-height, 64px) !important;
  min-height: var(--bsh-shrink-header-height, 64px) !important;
}

/* Reserve the space the compact header gives up with a spacer right after the header (JS adds
   .bsh-reserve), so everything below it keeps its position. The spacer and the header change height
   over the same duration and easing, so at every frame they add up to the full height. A theme
   paints it with --bsh-reserve-bg (the docked colour), so no page background shows under the bar. */
.bsh-enabled .bsh-reserve {
  display: block;
  height: 0;
  margin: 0 !important;
  padding: 0;
  pointer-events: none;
  background: var(--bsh-reserve-bg, transparent);
  transition: height var(--bsh-transition-duration, 300ms) ease;
}
.bsh-enabled .bsh-header.bsh-stuck.bsh-docked.bsh-has-reserve + .bsh-reserve {
  height: var(--bsh-shrink-offset, 0px);
}

/* Reduced logo height while stuck; width follows the logo's aspect ratio */
.bsh-enabled
  .bsh-header.bsh-stuck.bsh-docked.bsh-has-shrink-logo
  .bsh-shrink-logo {
  height: var(--bsh-shrink-logo-height, 40px) !important;
  max-height: var(--bsh-shrink-logo-height, 40px) !important;
  width: auto !important;
  object-fit: contain;
}

/* Crossfade keeps the original image in flow, with a decorative alternate overlaid.
   Shrinking changes the original box; the alternate follows without changing navigation layout. */
.bsh-logo-stage {
  position: relative;
  display: grid;
  width: max-content;
  max-width: 100%;
}
.bsh-logo-stage > :first-child {
  grid-area: 1 / 1;
  min-width: 0;
}
.bsh-logo-stage picture,
.bsh-logo-stage img {
  display: block;
}
.bsh-enabled .bsh-header .bsh-logo-stage > img.bsh-crossfade-layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  max-width: none !important;
  max-height: none !important;
  margin: 0;
  object-fit: contain;
  object-position: left center;
  opacity: 0;
  pointer-events: none;
  transition: none;
}

/* Respect reduced motion: disable transitions */
@media (prefers-reduced-motion: reduce) {
  .bsh-enabled .bsh-header.bsh-stuck,
  .bsh-enabled .bsh-shrink-target,
  .bsh-enabled .bsh-shrink-logo {
    transition: none;
  }
}
