/* Базовые стили для контейнера навигации */
#anchorlinks-toc {
  position: relative;
  z-index: 5;
  transition: all 0.3s ease;
  margin-bottom: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  background-color: #f9f9f9;
  padding: 15px;
}

/* Заголовок оглавления */
.anchorlinks-title {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 18px;
  color: #333;
  display: inline-block;
}

/* Основной стиль для списков */
#anchorlinks-toc ul {
  padding: 0 0 0 20px;
  margin: 0;
  list-style-type: disc;
}

/* Вложенные списки */
#anchorlinks-toc ul ul {
  margin-top: 5px;
  margin-left: 20px;
  padding-left: 15px;
  border-left: 2px solid #ddd;
}

/* Различные стили для разных уровней вложенности */
#anchorlinks-toc ul.anchorlinks-level-0 {
  /* Верхний уровень */
  padding-left: 20px;
}

#anchorlinks-toc ul.anchorlinks-level-1 {
  /* Второй уровень */
  list-style-type: circle;
}

#anchorlinks-toc ul.anchorlinks-level-2 {
  /* Третий уровень */
  list-style-type: square;
}

#anchorlinks-toc ul.anchorlinks-level-3,
#anchorlinks-toc ul.anchorlinks-level-4 {
  /* Глубокие уровни */
  list-style-type: none;
}

/* Элементы списка */
#anchorlinks-toc ul li {
  margin-bottom: 8px;
}

/* Ссылки в списке */
#anchorlinks-toc ul li a {
  color: #2980b9;
  text-decoration: none;
  transition: color 0.2s;
  display: inline-block;
}

#anchorlinks-toc ul li a:hover {
  color: #e74c3c;
}

/* Активная ссылка */
#anchorlinks-toc ul li a.active {
  font-weight: bold;
  color: #e74c3c;
}

/* Состояние блока навигации после отлипания */
#anchorlinks-toc.detached {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 250px;
  background-color: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  animation: anchorlinks-fadeIn 0.3s;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 5;
}

/* Стили для сворачиваемого оглавления */
.anchorlinks-toggle-container {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  width: 100%;
}

.anchorlinks-toggle-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  margin-right: 10px;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #f0f0f0;
  transition: background-color 0.3s;
}

.anchorlinks-toggle-button:hover {
  background-color: #e0e0e0;
}

.anchorlinks-toggle-icon {
  position: relative;
  width: 14px;
  height: 14px;
}

.anchorlinks-toggle-icon:before,
.anchorlinks-toggle-icon:after {
  content: '';
  position: absolute;
  background-color: #555;
  transition: transform 0.3s;
}

/* Горизонтальная линия */
.anchorlinks-toggle-icon:before {
  width: 14px;
  height: 2px;
  top: 6px;
  left: 0;
}

/* Вертикальная линия */
.anchorlinks-toggle-icon:after {
  width: 2px;
  height: 14px;
  top: 0;
  left: 6px;
}

/* Когда оглавление свернуто, вертикальная линия видна (знак +) */
.anchorlinks-collapsed .anchorlinks-toggle-icon:after {
  transform: scaleY(1);
}

/* Когда оглавление развернуто, вертикальная линия скрыта (знак -) */
#anchorlinks-toc:not(.anchorlinks-collapsed) .anchorlinks-toggle-icon:after {
  transform: scaleY(0);
}

/* Скрытие контента при свернутом оглавлении */
.anchorlinks-collapsible .anchorlinks-content {
  overflow: hidden;
  transition: max-height 0.5s;
  max-height: 2000px; /* Достаточно большое значение для любого оглавления */
}

.anchorlinks-collapsed .anchorlinks-content {
  max-height: 0;
}

/* Анимация появления */
@keyframes anchorlinks-fadeIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Кнопка "Наверх" */
.anchorlinks-back-to-top {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 10px 15px;
  border-radius: 5px;
  text-decoration: none;
  transition: background 0.3s;
  z-index: 5;
}

.anchorlinks-back-to-top.visible {
  display: block;
  animation: anchorlinks-fadeIn 0.3s;
}

.anchorlinks-back-to-top:hover {
  background: rgba(0, 0, 0, 0.9);
}

/* Адаптивные стили для мобильных устройств */
@media (max-width: 768px) {
  #anchorlinks-toc {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
  }
  
  #anchorlinks-toc.detached {
    position: static;
    width: 100%;
    box-shadow: none;
    animation: none;
    margin-bottom: 15px;
    top: auto;
    left: auto;
    right: auto;
  }
  
  .anchorlinks-toggle-container {
    margin-bottom: 5px;
  }
}