/* Базовые стили для контейнера */
.toc-wrapper {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
}

/* Основной блок содержания - для десктопа */
.toc {
  position: fixed;
  top: 104px;
  padding: 24px;
  background: #fff;
  border: 1px solid rgba(142, 57, 57, 0.18);
  max-width: 800px;
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease, top 0.3s ease, bottom 0.3s ease;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-20px);
  z-index: 1000;
  width: 280px;
  left: calc(50% - 600px + 20px);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  margin: 0;
}

/* Показываем блок */
.toc:not(.hidden) {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

/* Блок зафиксирован внизу - прижимаем к низу экрана */
.toc.bottom {
  top: auto !important;
  bottom: 20px !important;
  transform: translateY(0) !important;
}

/* Скрываем блок, когда он вне зоны видимости */
.toc.hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(-20px) !important;
  top: 104px !important;
  bottom: auto !important;
}

/* Стилизация скроллбара */
.toc::-webkit-scrollbar {
  width: 4px;
}

.toc::-webkit-scrollbar-track {
  background: transparent;
}

.toc::-webkit-scrollbar-thumb {
  background: #8e3939;
  border-radius: 4px;
}

.toc-title {
  margin: 0 0 16px;
  color: rgb(142, 57, 57);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  font-family: 'Roboto',Arial,sans-serif;
}

.toc a {
  display: block;
  padding: 10px 0;
  color: rgb(36, 24, 24) !important;
  text-decoration: none;
  font-size: 15px;
  line-height: 1.35;
  border-top: 1px solid rgba(142, 57, 57, 0.12);
  transition: color 0.2s ease;
  font-family: 'Roboto',Arial,sans-serif;
}

.toc a:hover {
  color: #8e3939 !important;
}

.toc a:first-of-type {
  border-top: none;
}

/* Активная ссылка при скролле */
.toc a.active {
  color: #8e3939;
  font-weight: 600;
}

/* Адаптив для планшетов и мобильных */
@media (max-width: 1024px) {
  .toc {
    position: relative !important;
    top: 0 !important;
    bottom: auto !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 800px !important;
    margin: 0 auto 40px !important;
    max-height: none !important;
    overflow-y: visible !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    padding: 24px !important;
    border: 1px solid rgba(142, 57, 57, 0.18) !important;
    background: #fff !important;
  }
  
  .toc.hidden {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: none !important;
    position: relative !important;
    top: 103px !important;
    bottom: auto !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 800px !important;
    margin: 0 auto 40px !important;
    max-height: none !important;
    overflow-y: visible !important;
    padding: 24px !important;
    border: 1px solid rgba(142, 57, 57, 0.18) !important;
    background: #fff !important;
  }
  
  .toc.bottom {
    bottom: auto !important;
    top: 0 !important;
  }
}

/* Адаптив для мобильных */
@media (max-width: 600px) {
  .toc-wrapper {
      padding: 0px !important;
      max-width: 100%;
  }
  .toc {
    padding: 16px !important;
    margin-bottom: 30px !important;
  }
  
  .toc.hidden {
    padding: 16px !important;
    margin-bottom: 30px !important;
  }
  
  .toc a {
    font-size: 14px;
    padding: 8px 0;
  }
}