/* Core Layout Container (Merged & Cleaned) */
.toc-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 99999;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  {% if module.style_overrides.custom_font.font %}
    
  {% else %}
    font-family: ;
  {% endif %}
}

/* Hidden & Visible Scroll States */
.toc-container.toc-hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

.toc-container.toc-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Floating Circle Button Layout */
.toc-circle-btn {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  background-color: {% if module.style_overrides.button_background_color.color %}{% else %}{% endif %};
  color: {% if module.style_overrides.button_text_color.color %}{% else %}{% endif %};
}

.toc-circle-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.toc-icon-svg {
  width: 24px;
  height: 24px;
}

/* Expanded Card Design */
.toc-card {
  width: 260px;
  max-width: calc(100vw - 32px); /* Prevents horizontal overflow on tiny screens */
  max-height: 70vh; /* Prevents card from clipping off the top of the viewport */
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  border: 1px solid #e2e8f0;
  overflow: hidden;
  transform-origin: bottom right;
}

/* Card Header Configuration */
#toc-toggle-header {
  width: 100%;
  flex-shrink: 0; /* Keeps header pinned while links scroll */
  padding: 14px 16px;
  background-color: #f8fafc;
  border: none;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
  font-size: 15px;
  color: #435a6a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

#toc-close-x {
  font-size: 20px;
  color: #435a6a;
  line-height: 1;
}

/* Scrollable Links Layout */
.toc-content {
  overflow-y: auto;
  overscroll-behavior: contain; /* Prevents background page scroll when reaching bottom of TOC */
}

.toc-content ul {
  list-style: none;
  padding: 8px 0;
  margin: 0;
}

.toc-link {
  display: block;
  padding: 8px 20px; /* Slightly taller touch target */
  color:  !important;
  text-decoration: none;
  font-size: 14px;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: all 0.2s ease;
}

.toc-link:hover {
  background-color: #f6f8f9;
}

/* Contextual Scrollspy Highlight */
.toc-link.active-section {
  font-weight: 600;
  color: #e40050 !important;
  background-color: transparent !important;
  border-left-color: #e40050;
}

/* Toggling CSS States */
.toc-container.collapsed .toc-card {
  display: none;
}

.toc-container:not(.collapsed) .toc-circle-btn {
  display: none;
}

/* Screen Reader & Focus Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toc-circle-btn:focus-visible,
#toc-toggle-header:focus-visible,
.toc-link:focus-visible {
  outline: 3px solid #e40050;
  outline-offset: -3px; /* Inset outline prevents clipping inside overflow:hidden containers */
}

/* =========================================
   Narrow Screen / Mobile Adjustments
   ========================================= */
@media (max-width: 600px) {
  .toc-container {
    bottom: 16px;
    right: 16px;
  }

  .toc-circle-btn {
    width: 48px;
    height: 48px;
  }

  .toc-card {
    width: calc(100vw - 32px); /* Spans cleanly across mobile width with 16px margins */
    max-height: 55vh; /* Leaves room for mobile address bars and content */
  }

  .toc-link {
    padding: 10px 16px; /* Better thumb-tap target size (WCAG minimum recommendation) */
  }
}
