/* Enhanced TOC Navigation Styles for PyAutoDoc */
/* Advanced TOC styling with sticky behavior and better nesting */

/* Main TOC Container Enhancements */
.sidebar-scroll {
  position: sticky !important;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-brand-primary) var(--color-background-secondary);
}

/* WebKit scrollbar styling */
.sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}

.sidebar-scroll::-webkit-scrollbar-track {
  background: var(--color-background-secondary);
}

.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--color-brand-primary);
  border-radius: 3px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--color-brand-content);
}

/* TOC Tree Styling */
.toctree-wrapper {
  padding: 0.5rem 0;
}

.toctree-l1,
.toctree-l2,
.toctree-l3,
.toctree-l4 {
  position: relative;
  margin: 0;
  padding: 0;
}

/* Nested TOC Indentation without repetition */
.toctree-l1 > a {
  display: block;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--color-sidebar-foreground);
  text-decoration: none;
  transition: all 0.2s ease;
  border-radius: 6px;
  margin: 0.25rem 0;
}

.toctree-l2 > a {
  padding: 0.5rem 1rem 0.5rem 2rem;
  font-size: 0.9rem;
  font-weight: 400;
}

.toctree-l3 > a {
  padding: 0.4rem 1rem 0.4rem 3rem;
  font-size: 0.85rem;
  font-weight: 400;
  opacity: 0.9;
}

.toctree-l4 > a {
  padding: 0.3rem 1rem 0.3rem 4rem;
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.8;
}

/* Active and Hover States */
.toctree-l1 > a:hover,
.toctree-l2 > a:hover,
.toctree-l3 > a:hover,
.toctree-l4 > a:hover {
  background: var(--color-sidebar-item-background--hover);
  color: var(--color-brand-primary);
  transform: translateX(4px);
}

.toctree-l1.current > a,
.toctree-l2.current > a,
.toctree-l3.current > a,
.toctree-l4.current > a {
  background: var(--color-sidebar-item-background--current);
  color: white;
  font-weight: 600;
}

/* Collapsible TOC Sections */
.toctree-collapse {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--color-background-secondary);
  transition: all 0.2s ease;
}

.toctree-collapse:hover {
  background: var(--color-brand-primary);
  color: white;
}

.toctree-collapse::before {
  content: "▶";
  font-size: 0.8rem;
  transition: transform 0.2s ease;
}

.toctree-collapse.expanded::before {
  transform: rotate(90deg);
}

/* Collapsible sections for L1 items with children */
.toctree-l1.has-children > a {
  padding-left: 2rem;
}

.toctree-l1.collapsed > ul {
  display: none;
}

/* Mini TOC for current page */
.page-toc {
  position: fixed;
  right: 2rem;
  top: 5rem;
  width: 250px;
  max-height: calc(100vh - 10rem);
  overflow-y: auto;
  background: var(--color-background-secondary);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

.page-toc-title {
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-brand-primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-background-border);
}

.page-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.page-toc li {
  margin: 0.25rem 0;
}

.page-toc a {
  display: block;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-foreground-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.page-toc a:hover {
  background: var(--color-background-hover);
  color: var(--color-brand-primary);
  transform: translateX(4px);
}

.page-toc a.active {
  background: var(--color-brand-primary);
  color: white;
  font-weight: 600;
}

/* Progress indicator for sections */
.toc-progress {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 0%;
  background: linear-gradient(
    180deg,
    var(--color-brand-primary),
    var(--color-brand-content)
  );
  transition: height 0.3s ease;
  border-radius: 3px;
}

/* Breadcrumb-style current location */
.toc-breadcrumb {
  background: var(--color-background-secondary);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--color-foreground-secondary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toc-breadcrumb-separator {
  color: var(--color-foreground-border);
  margin: 0 0.25rem;
}

.toc-breadcrumb-item {
  color: var(--color-brand-primary);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.toc-breadcrumb-item:hover {
  opacity: 0.8;
}

.toc-breadcrumb-current {
  font-weight: 600;
  color: var(--color-foreground-primary);
}

/* Search within TOC */
.toc-search {
  margin-bottom: 1rem;
  position: relative;
}

.toc-search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  border: 2px solid var(--color-background-border);
  border-radius: 6px;
  background: var(--color-background-primary);
  color: var(--color-foreground-primary);
  font-size: 0.875rem;
  transition: all 0.2s ease;
}

.toc-search input:focus {
  border-color: var(--color-brand-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.toc-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-foreground-secondary);
  pointer-events: none;
}

/* TOC item badges */
.toc-badge {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.toc-badge-new {
  background: #10b981;
  color: white;
}

.toc-badge-updated {
  background: #3b82f6;
  color: white;
}

.toc-badge-deprecated {
  background: #ef4444;
  color: white;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .page-toc {
    display: none;
  }
}

@media (max-width: 768px) {
  .toctree-l2 > a {
    padding-left: 1.5rem;
  }

  .toctree-l3 > a {
    padding-left: 2rem;
  }

  .toctree-l4 > a {
    padding-left: 2.5rem;
  }

  .toc-breadcrumb {
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }
}

/* Animation for TOC expansion */
@keyframes tocExpand {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toctree-expand {
  animation: tocExpand 0.3s ease-out;
}

/* Highlight current section in viewport */
.toc-in-viewport {
  position: relative;
}

.toc-in-viewport::before {
  content: "";
  position: absolute;
  left: -1rem;
  top: 0;
  width: 4px;
  height: 100%;
  background: var(--color-brand-primary);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.toc-in-viewport.active::before {
  opacity: 1;
}

/* Floating TOC toggle button for mobile */
.toc-toggle-mobile {
  display: none;
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--color-brand-primary);
  color: white;
  border: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.toc-toggle-mobile:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
  .toc-toggle-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Smooth transitions for all TOC elements */
.toctree-wrapper * {
  transition: all 0.2s ease;
}
