/* ============================================================
   Smart TOC v2 — Premium Inline Widget
   Clean card design, inspired by reference screenshot
   ============================================================ */

/* ── Custom Properties ── */
#smart-toc-box {
  --toc-accent:      #1e3a6e;
  --toc-blue:        #2563eb;
  --toc-blue-light:  #dbeafe;
  --toc-border:      #e2e8f0;
  --toc-bg:          #ffffff;
  --toc-surface:     #f8fafc;
  --toc-text:        #1e293b;
  --toc-muted:       #64748b;
  --toc-dot:         #2563eb;
  --toc-radius:      12px;
  --toc-width:       320px;
  --toc-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --toc-shadow:      0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.05);
  --toc-shadow-lg:   0 10px 25px -3px rgba(30,58,110,0.12), 0 4px 10px -2px rgba(30,58,110,0.08);
}

/* ── Outer wrapper — sits in the article flow ── */
#smart-toc-box {
  position: relative;
  display: inline-block;        /* shrink-wrap to button width when closed */
  width: 100%;
  margin: 1.75em 0 2em;
  font-family: var(--toc-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--toc-text);
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

/* ── Toggle Button ── */
#smart-toc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--toc-bg);
  color: var(--toc-accent);
  border: 1.5px solid var(--toc-border);
  border-radius: 8px;
  padding: 10px 18px 10px 14px;
  font-family: var(--toc-font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--toc-shadow);
  transition: all 0.18s ease;
  user-select: none;
  white-space: nowrap;
  line-height: 1;
}

#smart-toc-toggle:hover {
  background: var(--toc-surface);
  border-color: var(--toc-blue);
  color: var(--toc-blue);
  box-shadow: var(--toc-shadow-lg);
}

/* Lines icon */
.stoc-lines {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3.5px;
  width: 16px;
  flex-shrink: 0;
}
.stoc-lines i {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: all 0.2s ease;
}
.stoc-lines i:nth-child(2) { width: 75%; }
.stoc-lines i:nth-child(3) { width: 50%; }

/* Arrow chevron */
.stoc-chevron {
  margin-left: 2px;
  font-size: 10px;
  opacity: 0.6;
  transition: transform 0.25s ease;
}
#smart-toc-box.is-open .stoc-chevron {
  transform: rotate(180deg);
  opacity: 1;
}

/* Active button state */
#smart-toc-box.is-open #smart-toc-toggle {
  background: var(--toc-blue);
  color: #fff;
  border-color: var(--toc-blue);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
#smart-toc-box.is-open #smart-toc-toggle:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

/* ── Panel card ── */
#smart-toc-panel {
  display: none;
  width: var(--toc-width);
  background: var(--toc-bg);
  border: 1.5px solid var(--toc-border);
  border-top: none;
  border-radius: 0 var(--toc-radius) var(--toc-radius) var(--toc-radius);
  box-shadow: var(--toc-shadow-lg);
  overflow: hidden;
}

#smart-toc-box.is-open #smart-toc-panel {
  display: block;
  animation: tocFadeIn 0.22s ease both;
}

@keyframes tocFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Reading progress bar at very top of panel */
.stoc-progress {
  height: 3px;
  background: var(--toc-blue-light);
}
.stoc-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--toc-blue), #60a5fa);
  transition: width 0.15s ease;
  border-radius: 0 3px 3px 0;
}

/* Panel header row */
.stoc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px 11px;
  background: var(--toc-surface);
  border-bottom: 1px solid var(--toc-border);
}
.stoc-head-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--toc-accent);
}
.stoc-head-title svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.stoc-x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--toc-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.stoc-x:hover {
  background: var(--toc-border);
  color: var(--toc-accent);
}

/* ── Navigation list ── */
#smart-toc-nav {
  padding: 8px 0 10px;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--toc-border) transparent;
}
#smart-toc-nav::-webkit-scrollbar { width: 4px; }
#smart-toc-nav::-webkit-scrollbar-thumb {
  background: var(--toc-border);
  border-radius: 4px;
}

#smart-toc-nav ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
#smart-toc-nav li { margin: 0; padding: 0; }

/* Every link */
#smart-toc-nav a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 16px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--toc-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  line-height: 1.45;
}
#smart-toc-nav a:hover {
  background: var(--toc-blue-light);
  color: var(--toc-blue);
  border-left-color: var(--toc-blue);
}
#smart-toc-nav a.stoc-active {
  background: var(--toc-blue-light);
  color: var(--toc-blue);
  border-left-color: var(--toc-blue);
  font-weight: 600;
}

/* Bullet dot */
.stoc-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  background: var(--toc-blue);
  border-radius: 50%;
  margin-top: 6px;
  transition: background 0.12s;
}
#smart-toc-nav a:hover .stoc-dot,
#smart-toc-nav a.stoc-active .stoc-dot {
  background: var(--toc-blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

/* Link text */
.stoc-link-text { flex: 1; }

/* Indent for sub-levels */
#smart-toc-nav li[data-level="h3"] > a {
  padding-left: 28px;
  font-size: 13px;
}
#smart-toc-nav li[data-level="h3"] > a .stoc-dot { width: 5px; height: 5px; background: #94a3b8; }
#smart-toc-nav li[data-level="h4"] > a {
  padding-left: 40px;
  font-size: 12.5px;
  color: var(--toc-muted);
}
#smart-toc-nav li[data-level="h4"] > a .stoc-dot { width: 4px; height: 4px; background: #cbd5e1; }
#smart-toc-nav li[data-level="h5"] > a,
#smart-toc-nav li[data-level="h6"] > a {
  padding-left: 52px;
  font-size: 12px;
  color: var(--toc-muted);
}

/* Divider between H2 groups */
#smart-toc-nav li[data-level="h2"]:not(:first-child) {
  border-top: 1px solid var(--toc-border);
  margin-top: 4px;
  padding-top: 4px;
}

/* ── Footer ── */
.stoc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  border-top: 1px solid var(--toc-border);
  background: var(--toc-surface);
  font-size: 11px;
  color: var(--toc-muted);
  gap: 8px;
}
.stoc-count {
  display: flex;
  align-items: center;
  gap: 5px;
}
.stoc-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--toc-blue-light);
  color: var(--toc-blue);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  min-width: 22px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #smart-toc-box {
    --toc-width: calc(100vw - 32px);
  }
  #smart-toc-panel {
    border-radius: 0 8px 8px 8px;
  }
}
