/**
 * Custom Table of Contents Styles
 */

/* ========================================
   Toggle Button
   ======================================== */
.custom-toc-toggle {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%) translateX(-100%);
  background: #2277aa;
  color: white;
  border: none;
  padding: 12px 8px;
  cursor: pointer;
  z-index: 99998;
  border-radius: 0 8px 8px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.3s ease, background-color 0.2s ease;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
}

.custom-toc-toggle.visible {
  transform: translateY(-50%) translateX(0);
}

.custom-toc-toggle:hover {
  background: #2277ff;
}

.custom-toc-toggle-arrow {
  font-size: 18px;
  line-height: 1;
}

.custom-toc-toggle-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
}

/* ========================================
   Panel - vertically centered, grows to content up to 90vh
   ======================================== */
.custom-toc-panel {
  position: fixed !important;
  left: 0 !important;
  top: 50% !important;
  transform: translateY(-50%) translateX(-110%) !important;
  width: 350px !important;
  max-width: 90vw !important;
  max-height: 90vh !important;
  background: lightskyblue !important;
  z-index: 99999 !important;
  border-radius: 0 30px 30px 0 !important;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3) !important;
  display: flex !important;
  flex-direction: column !important;
  transition: transform 0.3s ease !important;
  overflow: hidden !important;
}

.custom-toc-panel.open {
  transform: translateY(-50%) translateX(0) !important;
}

/* ========================================
   Header - rounded top-right corner
   ======================================== */
.custom-toc-header {
  flex: 0 0 auto !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  padding: 15px 20px !important;
  background: #2277aa !important;
  color: white !important;
  border-radius: 0 30px 0 0 !important;
}

.custom-toc-title {
  font-size: 18px !important;
  font-weight: 700 !important;
  color: white !important;
}

.custom-toc-close {
  background: none !important;
  border: none !important;
  color: white !important;
  font-size: 28px !important;
  cursor: pointer !important;
  padding: 0 5px !important;
  line-height: 1 !important;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.custom-toc-close:hover {
  opacity: 1;
}

/* ========================================
   Navigation / Content Area - scrollable
   ======================================== */
.custom-toc-nav {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 10px 15px 20px 15px !important;
  -webkit-overflow-scrolling: touch !important;
  min-height: 0 !important;
  background: lightskyblue !important;
}

/* Scrollbar styling */
.custom-toc-nav::-webkit-scrollbar {
  width: 8px;
}

.custom-toc-nav::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

.custom-toc-nav::-webkit-scrollbar-thumb {
  background: #2277aa;
  border-radius: 4px;
}

.custom-toc-nav {
  scrollbar-width: thin;
  scrollbar-color: #2277aa rgba(255, 255, 255, 0.3);
}

/* ========================================
   List & Links
   ======================================== */
.custom-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.custom-toc-list li {
  margin: 0;
  padding: 0;
}

.custom-toc-list li::before {
  content: "▼ ";
  color: #2277aa;
  font-size: 10px;
  margin-right: 4px;
}

.custom-toc-link {
  display: inline;
  padding: 8px 10px;
  color: #333;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
  font-size: 14px;
  line-height: 1.8;
}

.custom-toc-link:hover {
  background: rgba(255, 255, 255, 0.5);
  color: #1a5a80;
}

/* Active item - matches original styling */
.custom-toc-link.active {
  background: white;
  color: #333;
  font-weight: 600;
  display: inline;
  padding: 4px 8px;
  border-radius: 4px;
}

.custom-toc-link:visited {
  color: #444;
}

.custom-toc-link.active:visited {
  color: #333;
}

/* ========================================
   Overlay
   ======================================== */
.custom-toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99997;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.custom-toc-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* ========================================
   Body Lock
   ======================================== */
body.custom-toc-body-locked {
  overflow: hidden;
}

/* ========================================
   Mobile Adjustments
   ======================================== */
@media (max-width: 500px) {
  .custom-toc-panel {
    width: calc(100vw - 40px);
    max-width: none;
  }

  .custom-toc-toggle-text {
    display: none;
  }

  .custom-toc-toggle {
    padding: 15px 10px;
  }

  .custom-toc-toggle-arrow {
    font-size: 22px;
  }
}
