/**
 * Anvet Theme — Table of Contents (TOC)
 *
 * Modern Compact Card UI:
 * - Clean rounded container with subtle border & background
 * - Compact header row without excess padding/margin
 * - Full reset on toggle button to eliminate theme button margins
 * - Seamless hover effect covering entire card when collapsed
 * - Divider line between header and content
 * - Custom indigo bullets & underlined links
 *
 * @package Anvet/Extensions/TOC
 */

/* ============================================================
   CSS Variables (defaults — overridden by inline style)
   ============================================================ */
:root {
  --toc-scroll-offset: 80px;
  --toc-bg: #f8faff;
  --toc-border: #edf2f7;
  --toc-title-color: #0f172a;
  --toc-link-color: #1e293b;
  --toc-link-hover: #4f46e5;
  --toc-bullet-color: #4f46e5;
  --toc-icon-color: #4f46e5;
  --toc-chevron-color: #94a3b8;
  --toc-radius: 10px;
  --toc-font-size: 0.93rem;
  --toc-line-height: 1.5;
}

/* ============================================================
   Scroll offset for all TOC-targeted headings
   ============================================================ */
h2[id], h3[id], h4[id], h5[id], h6[id] {
  scroll-margin-top: var(--toc-scroll-offset);
}

/* ============================================================
   Smooth scrolling
   ============================================================ */
html {
  scroll-behavior: smooth;
}

/* ============================================================
   TOC Box wrapper (Card Container)
   ============================================================ */
.theme-toc-box {
  background: var(--toc-bg);
  border: 1px solid var(--toc-border);
  border-radius: var(--toc-radius);
  margin: 24px 0;
  padding: 0 !important;
  overflow: hidden;
  font-size: var(--toc-font-size);
  line-height: var(--toc-line-height);
  max-width: 100%;
  box-sizing: border-box;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

/* ============================================================
   Toggle Button — full-width header row (Reset theme styles)
   ============================================================ */
.theme-toc-toggle {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  margin: 0 !important;
  padding: 10px 16px !important;
  min-height: 0 !important;
  height: auto !important;
  line-height: 1.3 !important;
  text-transform: none !important;
  font-family: inherit !important;
  letter-spacing: normal !important;
  background: transparent;
  border: none !important;
  border-radius: 0;
  box-shadow: none !important;
  outline: none !important;
  cursor: pointer;
  color: var(--toc-title-color);
  text-align: left;
  transition: background-color 0.15s ease;
  box-sizing: border-box !important;
  gap: 10px;
}

.theme-toc-toggle:hover {
  background-color: rgba(79, 70, 229, 0.04);
}

.theme-toc-toggle:focus-visible {
  outline: 2px solid var(--toc-bullet-color) !important;
  outline-offset: -2px;
}

/* When collapsed: toggle button fills entire card with matched corners */
.theme-toc-box.is-collapsed .theme-toc-toggle {
  border-radius: inherit !important;
}

/* Left group: icon + title */
.theme-toc-header-inner {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
}

/* Icon list */
.theme-toc-icon-list {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--toc-icon-color);
}

/* Title text */
.theme-toc-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--toc-title-color);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 !important;
  padding: 0 !important;
}

/* Chevron icon — right side */
.theme-toc-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--toc-chevron-color);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), color 0.15s ease;
  /* Points UP (∧) by default = expanded */
  transform: rotate(0deg);
}

.theme-toc-toggle:hover .theme-toc-chevron {
  color: var(--toc-bullet-color);
}

/* When collapsed: chevron points DOWN (∨) */
.theme-toc-box.is-collapsed .theme-toc-chevron {
  transform: rotate(180deg);
}

/* ============================================================
   TOC Body (list container)
   ============================================================ */
.theme-toc-body {
  padding: 14px 20px 18px 20px;
  background: transparent;
  border-top: 1px solid var(--toc-border);
  box-sizing: border-box;
}

/* Collapsed state */
.theme-toc-box.is-collapsed .theme-toc-body {
  display: none !important;
}

/* ============================================================
   TOC List Styles (Bullets & Links)
   ============================================================ */
.theme-toc-body ul {
  margin: 0 !important;
  padding: 0 !important;
  list-style: none !important;
}

.theme-toc-body li {
  position: relative;
  padding-left: 20px !important;
  margin: 11px 0 !important;
  line-height: var(--toc-line-height);
  list-style: none !important;
}

/* Custom indigo bullet dot */
.theme-toc-body li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.65em;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--toc-bullet-color);
  flex-shrink: 0;
}

/* Link style: dark text with subtle underline */
.theme-toc-body a {
  color: var(--toc-link-color);
  text-decoration: underline;
  text-decoration-color: #94a3b8;
  text-underline-offset: 3px;
  font-size: var(--toc-font-size);
  font-weight: 400;
  display: inline;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
  word-break: break-word;
}

.theme-toc-body a:hover,
.theme-toc-body a:focus-visible {
  color: var(--toc-link-hover);
  text-decoration: underline;
  text-decoration-color: var(--toc-link-hover);
}

/* Nested lists indented */
.theme-toc-body ul ul {
  padding-left: 18px !important;
  margin-top: 6px !important;
  margin-bottom: 6px !important;
}

.theme-toc-body ul ul li {
  margin: 7px 0 !important;
}

.theme-toc-body ul ul li::before {
  width: 5px;
  height: 5px;
  opacity: 0.85;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 767px) {
  .theme-toc-box {
    margin: 18px 0;
  }

  .theme-toc-toggle {
    padding: 9px 14px !important;
  }

  .theme-toc-title {
    font-size: 0.92rem;
  }

  .theme-toc-body {
    padding: 12px 14px 16px 14px;
  }

  .theme-toc-body li {
    padding-left: 18px !important;
    margin: 9px 0 !important;
  }

  .theme-toc-body a {
    font-size: 0.88rem;
  }

  .theme-toc-body ul ul {
    padding-left: 12px !important;
  }
}
