.tree {
  position: relative;
  list-style: none;
  padding: 0;
  margin: 0 0 12px;

  .tree__item & {
    padding-left: 8px;
    margin-top: 6px;
  }
}

.tree:not(:last-child) {
  margin-bottom: 3px;
}

.tree__item {
  @extend %first-last-no-margin;

  position: relative;
  margin: 4px 0;
  @include rounded($rounded);

  &.active {
    background-color: $color-primary-100;
  }

  &.tree__item--loading::after {
    content: ' ';

    @include loading(14px);
    @include absolute(9px, 9px, auto, auto);
  }
}

%tree__size {
  line-height: 32px;
}

.tree__action {
  @extend %tree__size;

  padding: 0 6px;
  @include rounded($rounded);

  .layout--collapsed & {
    height: 32px;
    justify-content: center;
    @include flex-align-items();
  }

  &.tree__action--disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  &:has(.tree__progress_percentage) {
    padding-right: 72px;
  }

  &:not(.tree__action--disabled):hover {
    background-color: $color-neutral-100;
  }

  .tree__item.active &:hover {
    background-color: transparent;
  }

  &.tree__action--has-options,
  &.tree__action--has-counter,
  &.tree__action--has-right-icon {
    padding-right: 32px;
  }

  &.tree__action--has-notification {
    padding-right: 48px;
  }
}

.tree__link {
  @extend %tree__size;

  color: $color-neutral-900;
  font-size: 14px;

  @include flex-align-items(4px);

  .tree__action--deactivated & {
    color: $color-neutral-500;
  }

  &:hover {
    text-decoration: none;
  }

  &.tree__link--group {
    font-weight: 600;
  }

  .tree__action--disabled &:hover {
    cursor: inherit;
  }
}

.tree__link-text {
  @extend %ellipsis;

  min-width: 0;
}

.tree__progress_percentage {
  display: inline-block;
  position: absolute;
  right: 35px;
  color: $color-primary-500;
}

.tree__icon {
  @extend %tree__size;

  text-align: center;
  color: $color-neutral-900;

  &.tree__icon--type {
    color: $color-neutral-500;
  }
}

%tree_sub-size {
  line-height: 28px;
  height: 28px;
}

.tree__subs {
  position: relative;
  list-style: none;
  padding: 0 0 2px 0;
  margin: 0;
}

.tree__sub {
  @extend %tree_sub-size;

  position: relative;
  padding: 0 34px;

  &::before,
  &::after {
    content: '';
    position: absolute;
    left: 12px;
  }

  &::before {
    top: 0;
    height: 28px;
    border-left: 1px solid $color-neutral-200;
  }

  &::after {
    top: 14px;
    width: 12px;
    border-bottom: 1px solid $color-neutral-200;
  }

  &:last-child::before {
    height: 15px;
  }
}

.tree__subs:not(:last-of-type) {
  padding: 0;

  & .tree__sub:last-child::before {
    height: 28px;
  }
}

.tree__sub-link {
  @extend %tree_sub-size;
  @extend %ellipsis;

  color: $color-neutral-900;
  display: block;

  &:hover {
    cursor: pointer;
    text-decoration: none;
    color: $color-primary-500;
  }

  .active > & {
    font-weight: 600;
    color: $color-primary-600;
  }
}

.tree__sub-link--loading {
  @include loading(14px);
  @include absolute(9px, 9px, auto, auto);
}

.tree__sub-link--disabled {
  opacity: 0.6;
  cursor: not-allowed;

  &:hover {
    color: $color-neutral-900;
    opacity: 0.6;
    text-decoration: none;
    cursor: not-allowed;
  }
}

.tree__sub-add {
  display: inline-block;
  margin: 0 0 10px 10px;
  font-size: 12px;
  color: $color-neutral-400;

  &:hover {
    text-decoration: none;
    color: $color-neutral-500;
  }
}

.tree__right-icon {
  position: absolute;
  z-index: 1;
  right: 0;
  top: 0;
  bottom: 0;
  max-height: 32px;
  width: 32px;
  color: $color-neutral-700;
  font-size: 16px;
  display: none;
  align-items: center;
  justify-content: center;

  :hover > & {
    display: flex;
  }

  .tree__item--loading > .tree__action > & {
    display: none;
  }
}

.tree__options {
  @extend .tree__right-icon;

  color: $color-neutral-500;
  cursor: pointer;

  &:hover {
    color: $color-neutral-900;
  }
}

.tree__counter {
  position: absolute;
  top: 8px;
  right: 8px;
}
