/* Luxurious Floating Table of Contents Component */

.floating-toc {
  position: fixed;
  top: 50%;
  right: 2rem;
  transform: translateY(-50%);
  width: 280px;
  max-height: 70vh;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1), 0 8px 16px rgba(0, 0, 0, 0.06);
  z-index: 100;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.toc-header {
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toc-title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin: 0;
  color: white;
}

.toc-toggle {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toc-toggle:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.toc-nav {
  max-height: calc(70vh - 80px);
  overflow-y: auto;
  padding: 0.5rem 0;
}

.toc-nav::-webkit-scrollbar {
  width: 4px;
}

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

.toc-nav::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

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

.toc-item {
  margin: 0;
}

.toc-link {
  display: block;
  padding: 0.75rem 1.5rem;
  color: #4a5568;
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  font-weight: 400;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 3px solid transparent;
  position: relative;
}

.toc-link:hover {
  color: #000000;
  background: rgba(0, 0, 0, 0.04);
  border-left-color: rgba(0, 0, 0, 0.2);
}

.toc-link.active {
  color: #000000;
  background: rgba(0, 0, 0, 0.06);
  border-left-color: #000000;
  font-weight: 500;
}

.toc-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(135deg, #000000 0%, #333333 100%);
}

/* Chevron icon */
.chevron-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

/* Mobile - Convert to bottom sheet */
@media (max-width: 1024px) {
  .floating-toc {
    position: fixed;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 50vh;
    transform: translateY(calc(100% - 60px));
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
  }
  
  .floating-toc.expanded {
    transform: translateY(0);
  }
  
  .toc-header {
    cursor: pointer;
    padding: 1rem 1.5rem;
  }
  
  .toc-title {
    font-size: 0.8rem;
  }
  
  .toc-nav {
    max-height: calc(50vh - 60px);
  }
  
  .toc-link {
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
  }
  
  .floating-toc:not(.expanded) .chevron-icon {
    transform: rotate(-90deg);
  }
  
  .floating-toc.expanded .chevron-icon {
    transform: rotate(90deg);
  }
}

/* Adjust for very small screens */
@media (max-width: 480px) {
  .floating-toc {
    transform: translateY(calc(100% - 50px));
  }
  
  .toc-header {
    padding: 0.75rem 1rem;
  }
  
  .toc-title {
    font-size: 0.75rem;
  }
  
  .toc-link {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
  }
}

/* Smooth scrolling for TOC navigation */
html.toc-smooth-scroll {
  scroll-behavior: smooth;
}

/* Add scroll margin for headings when TOC is active */
.toc-active .post-content h2,
.toc-active .blog-post h2,
.toc-active article h2 {
  scroll-margin-top: 2rem;
}

/* Loading state */
.floating-toc.loading {
  opacity: 0.7;
  pointer-events: none;
}

.floating-toc.loading .toc-nav::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #000000;
  border-radius: 50%;
  animation: toc-spin 1s linear infinite;
}

@keyframes toc-spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}
