.ld-sidenav-back {
  /* layout */
  --ld-sidenav-back-bg-inset: var(--ld-sp-6);
  --ld-sidenav-back-border-radius: var(--ld-br-l);
  --ld-sidenav-back-icon-size: var(--ld-sp-24);

  /* colors */
  --ld-sidenav-back-col: var(--ld-col-neutral-800);
  --ld-sidenav-back-col-active: var(--ld-thm-primary-active);
  --ld-sidenav-back-col-hover: var(--ld-thm-primary);
  --ld-sidenav-back-col-focus: var(--ld-thm-primary);
  --ld-sidenav-back-indicator-col: transparent;
  --ld-sidenav-back-indicator-col-focus: var(--ld-thm-primary-focus);
  --ld-sidenav-back-indicator-col-active: var(--ld-thm-primary);

  outline: none;
  display: block;

  @media (hover: hover) {
    &:where(:hover) {
      --ld-sidenav-back-col: var(--ld-sidenav-back-col-hover);
      --ld-sidenav-back-indicator-col: var(--ld-col-neutral-300);
    }
  }

  &:focus:focus-visible {
    --ld-sidenav-back-col: var(--ld-sidenav-back-col-focus);
    --ld-sidenav-back-indicator-col: var(--ld-sidenav-back-indicator-col-focus);
  }

  &:active {
    --ld-sidenav-back-col: var(--ld-sidenav-back-col-active);
    --ld-sidenav-back-indicator-col: var(
      --ld-sidenav-back-indicator-col-active
    );

    .ld-sidenav-back__bg {
      opacity: 0.3;
    }
  }

  &--rounded {
    --ld-sidenav-back-border-radius: var(--ld-br-full);
  }

  ::slotted(ld-sidenav-navitem) {
    margin-top: var(--ld-sidenav-padding-y);
    margin-bottom: var(--ld-sidenav-padding-y);
  }

  &.ld-sidenav-back--collapsed {
    .ld-sidenav-back__bg {
      transform: translateX(
        calc(var(--ld-sidenav-width) - var(--ld-sidenav-width-collapsed))
      );
    }
  }
}

.ld-sidenav-back__btn-back {
  display: none;
  background-color: transparent;
  position: relative;
  font: var(--ld-typo-body-s);
  border: 0;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  color: var(--ld-sidenav-back, var(--ld-col-neutral-800));
  grid-template-columns: auto 1fr;
  gap: var(--ld-sp-12);
  align-items: center;
  font-weight: 700;
  line-height: 1;
  box-sizing: border-box;
  padding: 0;
  text-align: left;
  outline: none;
  margin: var(--ld-sidenav-padding-y) var(--ld-sidenav-padding-x);
  -webkit-touch-callout: none;
}

.ld-sidenav-back__bg {
  position: absolute;
  inset: calc(-1 * var(--ld-sidenav-back-bg-inset));
  display: block;
  opacity: 0.2;
  transition: transform var(--ld-sidenav-transition-duration-collapse-expand)
    ease;
  pointer-events: none;
}

/*
Using z-index -1 on .ld-sidenav-back__bg results
in .ld-sidenav-back__bg not being clickable.
That's why we set z-index 0 on the following elements.
*/
.ld-sidenav-back__icon,
.ld-sidenav-back__btn-back-label {
  position: relative;
  z-index: 0;
}

.ld-sidenav-back__bg-left,
.ld-sidenav-back__bg-right,
.ld-sidenav-back__bg-center {
  background-color: var(--ld-sidenav-back-indicator-col);
  position: absolute;
  top: 0;
  bottom: 0;
  transition: transform var(--ld-sidenav-transition-duration-collapse-expand)
    ease;
  pointer-events: all;
}

.ld-sidenav-back__bg-left,
.ld-sidenav-back__bg-right {
  width: calc(0.5 * var(--ld-sidenav-navitem-icon-size) + var(--ld-sp-6));
}

.ld-sidenav-back__bg-left {
  left: 0;
  border-bottom-left-radius: calc(
    var(--ld-sidenav-back-border-radius) + var(--ld-sp-6)
  );
  border-top-left-radius: calc(
    var(--ld-sidenav-back-border-radius) + var(--ld-sp-6)
  );
}

.ld-sidenav-back__bg-right {
  right: 0;
  border-bottom-right-radius: calc(
    var(--ld-sidenav-back-border-radius) + var(--ld-sp-6)
  );
  border-top-right-radius: calc(
    var(--ld-sidenav-back-border-radius) + var(--ld-sp-6)
  );

  .ld-sidenav-back--collapsed & {
    transform: translateX(calc(-1 * var(--ld-sidenav-translate-x-delta) - 1px));
  }
}

.ld-sidenav-back__bg-center {
  left: calc(0.5 * var(--ld-sidenav-navitem-icon-size) + var(--ld-sp-6));
  right: calc(0.5 * var(--ld-sidenav-navitem-icon-size) + var(--ld-sp-6));
  transform-origin: left;

  .ld-sidenav-back--collapsed & {
    transform: scaleX(0);
  }
}

.ld-sidenav-back--is-back {
  .ld-sidenav-back__btn-back {
    display: grid;
  }
  .ld-sidenav-back__slot-container {
    display: none;
  }
}

.ld-sidenav-back__icon {
  width: var(--ld-sidenav-navitem-icon-size);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform var(--ld-sidenav-transition-duration-collapse-expand)
    ease;

  .ld-sidenav-back--collapsed & {
    transform: translateX(var(--ld-sidenav-translate-x-delta));
  }

  &::before {
    content: '';
    background-color: var(--ld-thm-primary-active);
    border-radius: var(--ld-br-full);
    height: var(--ld-sidenav-back-icon-size);
    overflow: hidden;
    position: absolute;
    width: var(--ld-sidenav-back-icon-size);
    z-index: -1;
  }
}

.ld-sidenav-back__btn-back-label {
  text-overflow: ellipsis;
  overflow: hidden;
  color: var(--ld-sidenav-back-col);
  white-space: nowrap;
  padding-right: var(--ld-sp-6);
  position: relative;
  transition: opacity var(--ld-sidenav-transition-duration-collapse-expand)
      linear,
    transform var(--ld-sidenav-transition-duration-collapse-expand) ease;

  .ld-sidenav-back--collapsed & {
    opacity: 0;
    transform: translateX(var(--ld-sidenav-translate-x-delta));
  }
}
