.categories {
  width: 100%;
}

.categories__list {
  list-style: none;
  padding: 15px 0;
  margin: 0;
  display: grid;
  position: relative;
}

.categories__list-item {
}

.categories__list-item-content {
  display: grid;
  grid-template-columns: auto 16px;
  align-items: center;
  padding: 6px 12px;
  border-radius: 12px;
  transition: background-color 0.2s ease, color 0.2s ease;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: #212b36;
  width: calc(100% - 3px);
  position: relative;
  z-index: 2;
}

.categories__list-item-content:hover {
  background-color: #eceef6;
}

.categories__list-item.is-active > .categories__list-item-content,
.categories__list-item.open > .categories__list-item-content {
  background-color: #e6e9ff;
  color: #3a19a8;
}

.categories__list-item-icon {
  color: #999;
  transition: transform 0.3s ease;
}

.categories__list-item.open > .categories__list-item-content .categories__list-item-icon,
.categories__list-item.open > .categories__list-item-content .categories__toggle-btn {
  transform: rotate(45deg);
}

.categories__toggle-btn {
  width: 16px;
  height: 16px;
  padding: 0;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.3s ease;
  z-index: 3;
}

/* Ссылка внутри контента */
.categories__list-item-link {
  display: block;
  color: inherit;
  text-decoration: none;
  grid-column: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.categories__list-item-link:hover {
  color: inherit;
  text-decoration: none;
}

/* submenu */
.categories__list-sub {
  max-height: 0;
  overflow: hidden;
  display: grid;
  height: 100%;
  z-index: 10;
  position: absolute;
  top: 0; 
  left: 100%; 
  margin-left: 10px;
  min-width: 220px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(6px);
  transition: max-height 0.3s ease, opacity 0.3s ease,
              transform 0.3s ease, visibility 0.3s ease;
  max-width: calc(25vw - 40px);
  width: 100%;
}

.categories__list-item.has-children > .categories__list-sub::before {
  content: "";
  position: absolute;
  top: 0;
  left: -10px;
  width: 10px;
  height: 100%;
}

.categories__list-sub-content {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(58, 25, 168, 0.12);
  height: fit-content;
  padding: 8px;
}

/* Состояния открытого подменю */
.categories__list-item.open > .categories__list-sub {
  overflow: visible;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
  max-height: 1000px;
}

.categories__list-sub li {
  width: 100%;
}

.categories__list-sub .categories__list-item-content {
  background: transparent;
  padding: 6px 12px;

}

.categories__list-sub .categories__list-item-content:hover {
  background-color: #f8f9ff;
}

.categories__list-sub .categories__list-item.is-active > .categories__list-item-content,
.categories__list-sub .categories__list-item.open > .categories__list-item-content {
  background-color: #f0f2ff;
}

.categories__list-sub span,
.categories__list-sub a {
  display: block;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s ease;
  color: #212b36;
  text-decoration: none;
}

.categories__list-sub span:hover,
.categories__list-sub a:hover {
  background: #f0f0f8;
  text-decoration: none;
}

/* Вложенные подменю */
.categories__list-sub .categories__list-item.open > .categories__list-sub {
  top: 0;
  left: 100%;
  transform: translateX(6px);
  position: absolute;
  z-index: 11;
}

/* mobile */
@media (max-width: 1023px) {
  .categories {
    display: none;
  }

  .categories__list-sub {
    left: auto;
    top: auto;
    transform: none;
    max-height: 0;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    padding: 0;
    margin-left: 0;
    position: static;
    max-width: 100%;
    width: 100%;
  }

  .categories__list-item.open > .categories__list-sub {
    max-height: 1000px;
    padding: 12px 0 0;
    transition: max-height 0.3s ease;
  }
    
  .categories__list-item.has-children > .categories__list-sub {
    max-width: unset;
    position: relative;
    left: 15px;
    width: calc(100% - 15px);
    height: fit-content;
  }

  .categories__list-item.has-children > .categories__list-sub::before {
    display: none;
  }

  /* Для мобильной версии убираем абсолютное позиционирование */
  .categories__list-sub .categories__list-item.open > .categories__list-sub {
    position: static;
    transform: none;
    left: auto;
    top: auto;
    margin-left: 15px;
    width: calc(100% - 30px);
  }
}

/* Анимация для плавного открытия/закрытия */
.categories__list-sub {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Для предотвращения наложения кликов */
.categories__list-item-content > * {
  pointer-events: auto;
}

.categories__list-item-content {
  pointer-events: auto;
}

