/* 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);
  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 {
  right: 15px !important; /* Move closer to edge when 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),
    0 0 30px rgba(249, 196, 65, 0.3),
    0 0 60px rgba(249, 196, 65, 0.1);
}

.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;
  }
}

/* CRITICAL: Force floating button to bottom-right on mobile */
.toc-toggle-floating {
  position: fixed !important;
  z-index: 99999 !important;
  width: 44px !important;
  height: 44px !important;
  background: linear-gradient(135deg, #f9c441, #ffdb70) !important;
  border: none !important;
  border-radius: 12px !important; /* Square with rounded corners, not circle */
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 4px 12px rgba(249, 196, 65, 0.3) !important;
  transition: all 0.3s ease !important;
}

/* Toggle button inside TOC container - keep it in same position */
.toc-toggle {
  position: fixed !important; /* Change from absolute to fixed */
  z-index: 99999 !important;
  width: 44px !important;
  height: 44px !important;
  background: linear-gradient(135deg, #f9c441, #ffdb70) !important;
  border: none !important;
  border-radius: 12px !important; /* Square with rounded corners, not circle */
  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;
  pointer-events: auto !important;
}

/* Hover effects for both toggle buttons */
.toc-toggle,
.toc-toggle-floating {
  position: relative;
  overflow: hidden;
}

.toc-toggle::before,
.toc-toggle-floating::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  transition: left 0.5s ease;
}

.toc-toggle:hover::before,
.toc-toggle-floating:hover::before {
  left: 100%;
}

.toc-toggle:hover,
.toc-toggle-floating:hover {
  transform: scale(1.05) !important;
}

.toc-toggle:active,
.toc-toggle-floating:active {
  transform: scale(0.95) !important;
}

/* Rotating icon animation */
.toc-toggle svg,
.toc-toggle-floating svg {
  width: 20px !important;
  height: 20px !important;
  color: #1a1a1a !important;
  transition: transform 0.3s ease !important;
}

/* Rotate icon when TOC is open - target the floating button when sidebar is not collapsed */
.toc-toggle-floating.toc-open svg,
body:has(.toc-sidebar:not(.collapsed)) .toc-toggle-floating svg {
  transform: rotate(180deg) !important;
}

/* Hide the inner toggle button when TOC is open - we only want the outer floating button */
.toc-sidebar:not(.collapsed) .toc-toggle {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Always hide the inner button on mobile since we use floating button */
@media (max-width: 768px) {
  .toc-toggle {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .toc-toggle-floating,
  .toc-toggle {
    bottom: 20px !important;
    right: 20px !important;
    top: auto !important;
    left: auto !important;
  }
  
  /* Position TOC container above the button */
  .toc-sidebar {
    bottom: 76px !important; /* Button height (44px) + margin (20px) + spacing (12px) = appears above button */
    right: 20px !important; /* Align with button right edge */
    top: auto !important;
    width: 280px !important; /* Can be wider since we use the right side space */
    max-width: calc(100% - 50px) !important; /* Use available right space - fixed from 100vw */
    max-height: calc(100vh - 140px) !important; /* Leave space for button below */
    border-radius: 16px 16px 4px 16px !important; /* Sharp corner at bottom-right where it connects to button */
  }
  
  .toc-sidebar.collapsed {
    bottom: auto !important;
    right: auto !important;
    top: auto !important;
    left: auto !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
  }
}

@media (min-width: 769px) {
  .toc-toggle-floating,
  .toc-toggle {
    top: 50% !important;
    right: 20px !important;
    bottom: auto !important;
    left: auto !important;
    transform: translateY(-50%) !important;
  }
  
  /* Desktop hover effects - preserve translateY(-50%) */
  .toc-toggle:hover,
  .toc-toggle-floating:hover {
    transform: translateY(-50%) scale(1.05) !important;
  }
  
  .toc-toggle:active,
  .toc-toggle-floating:active {
    transform: translateY(-50%) scale(0.95) !important;
  }
  
  /* Desktop TOC positioning - align with button */
  .toc-sidebar {
    top: 50% !important;
    right: 76px !important; /* Button width (44px) + margin (20px) + spacing (12px) */
    bottom: auto !important;
    transform: translateY(-50%) !important;
    max-height: calc(100vh - 140px) !important;
    border-radius: 16px 4px 16px 16px !important; /* Rounded except corner touching button */
  }
  
  .toc-sidebar.collapsed {
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transform: none !important;
  }
}
