/**
 * 12Zodiacs Unified Sticky TOC
 * Version: 2.0
 *
 * Usage in any page:
 *   [zy_toc]
 *     [zy_toc_item id="section-1" label="Section One"]
 *     [zy_toc_item id="section-2" label="Section Two"]
 *   [/zy_toc]
 *
 * Or raw HTML:
 *   <nav class="zy-sticky-toc" aria-label="Table of Contents">
 *     <div class="zy-toc-header">
 *       <span class="zy-toc-title">On This Page</span>
 *       <button class="zy-toc-toggle" aria-label="Toggle TOC"></button>
 *     </div>
 *     <ul class="zy-toc-list">
 *       <li><a href="#section-1" data-toc>Section One</a></li>
 *       <li><a href="#section-2" data-toc>Section Two</a></li>
 *     </ul>
 *   </nav>
 */

/* ===== Core Container ===== */
.zy-sticky-toc {
  position: fixed;
  top: 90px;
  left: 10px;
  width: 200px;
  max-width: 200px !important;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e8e0f0;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(94, 53, 177, 0.08);
  z-index: 100;
  font-size: 0.8rem;
  display: none;
}

/* Show on desktop only */
@media (min-width: 1200px) {
  .zy-sticky-toc { display: block; }
}

/* ===== Header (clickable to collapse) ===== */
.zy-toc-header,
.zy-sticky-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  cursor: pointer;
  user-select: none;
}

.zy-toc-title,
.zy-sticky-toc-title {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #1a1a2e;
}

/* ===== Toggle Button ===== */
.zy-toc-toggle,
.zy-sticky-toc-toggle {
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  transition: transform 0.2s ease;
}

.zy-toc-toggle::after,
.zy-sticky-toc-toggle::after {
  content: "";
  font-size: 0.6rem;
}

.zy-sticky-toc.collapsed .zy-toc-toggle::after,
.zy-sticky-toc.collapsed .zy-sticky-toc-toggle::after {
  content: "";
}

.zy-sticky-toc.collapsed .zy-toc-toggle,
.zy-sticky-toc.collapsed .zy-sticky-toc-toggle {
  transform: none;
}

/* Collapsed state: reduce padding, hide list */
.zy-sticky-toc.collapsed {
  padding-bottom: 4px;
}

.zy-sticky-toc.collapsed .zy-toc-list,
.zy-sticky-toc.collapsed .zy-sticky-toc-list {
  display: none;
}

/* ===== TOC List ===== */
.zy-toc-list,
.zy-sticky-toc-list {
  list-style: none;
  padding: 0 8px 10px;
  margin: 0;
  border-top: 2px solid #ede7f6;
  padding-top: 8px;
}

.zy-toc-list li,
.zy-sticky-toc-list li {
  margin: 0;
}

.zy-toc-list a,
.zy-sticky-toc-list a {
  display: block;
  padding: 5px 10px;
  color: #555;
  text-decoration: none;
  border-radius: 6px;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.35;
}

.zy-toc-list a:hover,
.zy-sticky-toc-list a:hover {
  background: #f5f0fa;
  color: #5e35b1;
}

.zy-toc-list a.active,
.zy-sticky-toc-list a.active {
  background: #ede7f6;
  color: #5e35b1;
  border-left-color: #5e35b1;
  font-weight: 600;
}

/* ===== Scrollbar styling ===== */
.zy-sticky-toc::-webkit-scrollbar {
  width: 4px;
}

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

.zy-sticky-toc::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.zy-sticky-toc::-webkit-scrollbar-thumb:hover {
  background: #ccc;
}

/* ===== Backward compatibility: legacy TOCs still work ===== */
/* le-toc, zc-toc, zy-toc(old) → inherit all styles from zy-sticky-toc */
.le-toc,
.zc-toc {
  position: fixed;
  top: 90px;
  left: 10px;
  width: 200px;
  max-width: 200px !important;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e8e0f0;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(94, 53, 177, 0.08);
  z-index: 100;
  font-size: 0.8rem;
  display: none;
}

@media (min-width: 1200px) {
  .le-toc,
  .zc-toc { display: block; }
}

.le-toc-title,
.zc-toc-title {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #1a1a2e;
  margin: 0 0 8px;
  padding: 12px 14px 8px;
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.le-toc ul,
.zc-toc ul {
  list-style: none;
  padding: 0 8px 10px;
  margin: 0;
  border-top: 2px solid #ede7f6;
  padding-top: 8px;
}

.le-toc a,
.zc-toc a {
  display: block;
  padding: 5px 10px;
  color: #555;
  text-decoration: none;
  border-radius: 6px;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.35;
}

.le-toc a:hover,
.zc-toc a:hover { background: #f5f0fa; color: #5e35b1; }
.le-toc a.active,
.zc-toc a.active {
  background: #ede7f6;
  color: #5e35b1;
  border-left-color: #5e35b1;
  font-weight: 600;
}

/* v2.1 fix: toggle arrow from inner text, not ::after */
.zy-toc-toggle,
.zy-sticky-toc-toggle {
  font-size: 0.6rem;
  color: #999;
  min-width: 14px;
  text-align: center;
}

.zy-sticky-toc.collapsed .zy-toc-toggle,
.zy-sticky-toc.collapsed .zy-sticky-toc-toggle {
  /* Will show ▼ from innerHTML via JS */
}
