/* Modern Table of Contents - Built from Scratch */
/* Clean, professional design with no legacy code */

.toc-sidebar {
  position: fixed;
  top: 90px;
  right: 30px;
  width: 350px;
  max-width: 350px;
  max-height: calc(100vh - 140px);
  background: rgba(20, 20, 25, 0.95);
  border: 1px solid rgba(249, 196, 65, 0.2);
  border-radius: 20px;
  box-shadow: 
    0 25px 50px rgba(0, 0, 0, 0.5),
    0 10px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  z-index: 1000;
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  box-sizing: border-box;
}

/* Collapsed State - HIDE the container, only show the button */
.toc-sidebar.collapsed {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: transparent !important; /* Remove dark background */
  border: none !important; /* Remove any borders */
  box-shadow: none !important; /* Remove container shadow */
  /* Ensure button can be seen */
  overflow: visible !important;
}

/* Hidden elements when collapsed */
.toc-sidebar.collapsed .toc-header h3,
.toc-sidebar.collapsed .toc-list {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Keep header visible but transparent so button works */
.toc-sidebar.collapsed .toc-header {
  opacity: 0;
  visibility: hidden;
}

/* But ensure toggle button is always clickable */
.toc-sidebar.collapsed .toc-toggle {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Toggle Button */
.toc-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #f9c441, #ffdb70);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(249, 196, 65, 0.3);
  z-index: 9999;
  pointer-events: auto;
}

.toc-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(249, 196, 65, 0.4);
}

.toc-toggle:active {
  transform: scale(0.95);
}

.toc-toggle svg {
  width: 18px;
  height: 18px;
  color: #1a1a1a;
  transition: transform 0.3s ease;
  pointer-events: none;
}

/* FORCE the collapsed button to be yellow - maximum specificity */
.toc-sidebar.collapsed .toc-toggle,
.toc-sidebar.collapsed .toc-toggle:before,
.toc-sidebar.collapsed .toc-toggle:after,
#toc-sidebar.collapsed .toc-toggle {
  position: absolute !important;
  top: 7px !important;
  right: 7px !important;
  left: auto !important;
  width: 36px !important;
  height: 36px !important;
  background: #f9c441 !important;
  background-color: #f9c441 !important;
  background-image: linear-gradient(135deg, #f9c441, #ffdb70) !important;
  border: none !important;
  border-radius: 12px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 4px 12px rgba(249, 196, 65, 0.3) !important;
  z-index: 99999 !important;
  pointer-events: auto !important;
  transform: none !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.toc-sidebar.collapsed .toc-toggle:hover,
#toc-sidebar.collapsed .toc-toggle:hover {
  transform: scale(1.1) !important;
  box-shadow: 0 6px 20px rgba(249, 196, 65, 0.4) !important;
  background: #f9c441 !important;
  background-image: linear-gradient(135deg, #f9c441, #ffdb70) !important;
}

.toc-sidebar.collapsed .toc-toggle:active,
#toc-sidebar.collapsed .toc-toggle:active {
  transform: scale(0.95) !important;
  background: #f9c441 !important;
  background-image: linear-gradient(135deg, #f9c441, #ffdb70) !important;
}

.toc-sidebar.collapsed .toc-toggle svg,
#toc-sidebar.collapsed .toc-toggle svg {
  width: 16px !important;
  height: 16px !important;
  color: #1a1a1a !important;
  stroke: #1a1a1a !important;
  fill: none !important;
  transition: transform 0.3s ease !important;
  pointer-events: none !important;
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.toc-sidebar.collapsed .toc-toggle:hover {
  transform: scale(1.1);
}

.toc-sidebar.collapsed .toc-toggle:active {
  transform: scale(0.95);
}

/* Header */
.toc-header {
  padding: 25px 25px 20px 25px;
  border-bottom: 1px solid rgba(249, 196, 65, 0.15);
  background: linear-gradient(135deg, 
    rgba(249, 196, 65, 0.05), 
    rgba(249, 196, 65, 0.02));
  border-radius: 20px 20px 0 0;
  position: relative;
}

.toc-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.5px;
}

/* Toggle Button */
.toc-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #f9c441, #ffdb70);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(249, 196, 65, 0.3);
  z-index: 9999;
  pointer-events: auto;
}

.toc-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(249, 196, 65, 0.4);
}

.toc-toggle:active {
  transform: scale(0.95);
}

.toc-toggle svg {
  width: 18px;
  height: 18px;
  color: #1a1a1a;
  transition: transform 0.3s ease;
  pointer-events: none;
}

/* Content List */
.toc-list {
  list-style: none;
  margin: 0;
  padding: 20px 0;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  box-sizing: border-box;
}

/* Custom Scrollbar */
.toc-list::-webkit-scrollbar {
  width: 4px;
}

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

.toc-list::-webkit-scrollbar-thumb {
  background: rgba(249, 196, 65, 0.3);
  border-radius: 2px;
}

.toc-list::-webkit-scrollbar-thumb:hover {
  background: rgba(249, 196, 65, 0.5);
}

/* TOC Items */
.toc-list li {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.toc-list a {
  display: block;
  padding: 12px 25px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  transition: all 0.3s ease;
  border-radius: 0 15px 15px 0;
  margin: 2px 0;
  position: relative;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.toc-list a:hover {
  color: #ffffff;
  background: rgba(249, 196, 65, 0.1);
  transform: translateX(8px);
}

.toc-list a.active {
  color: #f9c441;
  background: rgba(249, 196, 65, 0.15);
  font-weight: 500;
  transform: translateX(12px);
}

.toc-list a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #f9c441, #ffdb70);
  border-radius: 0 2px 2px 0;
}

/* Hierarchy Levels */
.toc-level-1 {
  font-size: 16px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  padding-left: 25px !important;
}

.toc-level-2 {
  font-size: 15px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  padding-left: 45px !important;
}

.toc-level-3 {
  font-size: 14px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.75);
  padding-left: 65px !important;
}

.toc-level-4 {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.65);
  padding-left: 85px !important;
}

/* Hidden elements when collapsed */
.toc-sidebar.collapsed .toc-header,
.toc-sidebar.collapsed .toc-list {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Empty state */
.toc-placeholder {
  padding: 40px 25px;
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
  font-size: 14px;
}

/* Responsive Design */
@media (max-width: 1200px) {
  .toc-sidebar {
    right: 20px;
    width: 320px;
  }
}

@media (max-width: 768px) {
  .toc-sidebar {
    right: 15px;
    width: 280px;
    top: 80px;
  }
  
  .toc-sidebar.collapsed {
    bottom: 30px;
    top: auto;
    right: 15px;
  }
}

@media (max-width: 480px) {
  .toc-sidebar {
    right: 10px;
    width: 260px;
    max-width: calc(100vw - 20px);
  }
}
