.pm-toc {
  --bg: #ffffff;
  --tx: #111827;
  --hov: #16a34a;
  --bd: #e5e7eb;
  --hov-soft: rgba(22, 163, 74, .10);
  --hov-strong: rgba(22, 163, 74, .18);
  --sticky: 100px;
  --scrollh: 120px;
  --indent: 18px;

  box-sizing: border-box;
  direction: rtl;
  text-align: right;
  background: var(--bg);
  color: var(--tx);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.9;
}

.pm-toc *,
.pm-toc *::before,
.pm-toc *::after { box-sizing: inherit; }

/* ---------- Head ---------- */
.pm-toc__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bd);
}

.pm-toc__title {
  margin: 0;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--hov);
  border: 0;
}

.pm-toc__toggle {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--hov-soft);
  color: var(--hov);
  border: 1px solid var(--bd);
  border-radius: 999px;
  padding: 4px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.pm-toc__caret {
  width: 0; height: 0;
  border-inline: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform .2s ease;
}

.pm-toc.is-open .pm-toc__caret { transform: rotate(180deg); }

/* ---------- List ---------- */
.pm-toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: pmtoc;
}

.pm-toc li {
  counter-increment: pmtoc;
  margin: 0;
}

/* تورفتگی: سطح اول یک واحد، هر سطح تودرتو یک واحد بیشتر */
.pm-toc__body > ol { padding-right: var(--indent); }
.pm-toc ol ol      { padding-right: var(--indent); }

.pm-toc[dir="ltr"] .pm-toc__body > ol,
.pm-toc[dir="ltr"] ol ol {
  padding-right: 0;
  padding-left: var(--indent);
}

.pm-toc a {
  display: block;
  padding: 5px 8px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  border-inline-start: 3px solid transparent;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.pm-toc a::before {
  content: counters(pmtoc, ".") ". ";
  color: var(--hov);
  font-variant-numeric: tabular-nums;
  opacity: .85;
}

.pm-toc a:hover,
.pm-toc a:focus-visible,
.pm-toc a.is-hover {
  background: var(--hov-soft);
  color: var(--hov);
  border-inline-start-color: var(--hov);
  outline: none;
}

.pm-toc a.is-active {
  background: var(--hov-soft);
  color: var(--hov);
  font-weight: 700;
  border-inline-start-color: var(--hov);
}

.pm-toc__empty {
  margin: 6px 0 0;
  font-size: 14px;
  opacity: .75;
}

/* هایلایت تیتر متن هنگام هاور روی لینک */
.pm-toc-hl {
  background: var(--pm-toc-hl, rgba(22, 163, 74, .12));
  border-radius: 6px;
  transition: background .15s ease;
}

/* ---------- Mobile: collapsible ---------- */
@media (max-width: 999px) {
  .pm-toc {
    width: 100%;
    margin: 0 0 20px;
    float: none;
    position: static;
  }
  .pm-toc__toggle { display: inline-flex; }
  .pm-toc__body { display: none; }
  .pm-toc.is-open .pm-toc__body { display: block; }
}

/* ---------- Desktop: sticky right sidebar ---------- */
@media (min-width: 1000px) {
  .pm-toc--right {
    float: right;
    width: 300px;
    max-width: 40%;
    margin: 0 0 20px 24px;
    position: sticky;
    top: var(--sticky);
  }

  .pm-toc--scroll .pm-toc__body {
    max-height: calc(100vh - var(--scrollh));
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .pm-toc:not(.pm-toc--scroll) .pm-toc__body {
    max-height: none;
    overflow: visible;
  }

  .pm-toc--scroll .pm-toc__body::-webkit-scrollbar { width: 8px; }
  .pm-toc--scroll .pm-toc__body::-webkit-scrollbar-thumb {
    background: var(--hov-strong);
    border-radius: 8px;
  }
}

@media print {
  .pm-toc { display: none; }
}

/* === v1.2.9 — consolidated === */

.pm-toc{
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  float: none;
  margin-inline: 0;
}

@media (min-width: 1000px){
  /* غلبه بر width:300px/max-width:40% و بر --w اگر inline نبود */
  .pm-toc.pm-toc--right,
  .pm-toc.pm-toc--left{
    float: none;
    width: 100%;
    max-width: 100%;
  }
}

.pm-toc__body,
.pm-toc__list{ width: 100%; max-width: 100%; min-width: 0; }

/* حذف شماره‌گذاری بومی (شماره‌ها از counters می‌آید) */
.pm-toc__list,
.pm-toc__list ol,
.pm-toc__list li{ list-style: none; }
.pm-toc__list li::marker{ content: none; }

/* هاور فقط تا عرض متن */
.pm-toc .pm-toc__list a{
  display: inline-block;
  width: auto;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: break-word;
}
