/* ==========================================================================
   Gama Table of Contents — سازگار با استایل قالب گاما
   ========================================================================== */

.gama-toc {
    display: block;
    clear: both;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
    padding: 15px;
    margin: 0;
    box-sizing: border-box;
    direction: rtl;
    text-align: right;
    line-height: 2;
    flex: 0 0 auto;
}

/* --- سربرگ / دکمه باز و بسته کردن --- */
.gama-toc .gama-toc-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
    padding: 0 0 12px 0;
    margin: 0;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
}

.gama-toc .gama-toc-title {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-size: 17px;
    font-weight: bold;
    word-spacing: -2px;
    color: #111;
    /* بازنویسی استایل سراسری h2 قالب (در موبایل فهرست داخل .post-content قرار می‌گیرد) */
    font-size: 17px !important;
    margin: 0;
    padding: 0 !important;
    border: 0;
    line-height: 2;
    text-align: right;
}

/* متن مخصوص صفحه‌خوان‌ها */
.gama-toc .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.gama-toc .gama-toc-title i {
    font-size: 18px;
    color: var(--custom-primary-color, #0634d2);
    position: relative;
    top: -1px;
}

.gama-toc .gama-toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 100%;
    background: #f5f6fa;
    color: var(--custom-primary-color, #0634d2);
    font-size: 13px;
    flex: 0 0 auto;
    cursor: pointer;
    position: relative;
    transition: 0.3s all;
}

.gama-toc .gama-toc-toggle:hover,
.gama-toc .gama-toc-toggle:focus-visible {
    background: var(--custom-primary-color, #0634d2);
    color: #fff;
}

.gama-toc .gama-toc-toggle i {
    transition: 0.3s transform;
}

.gama-toc.is-collapsed .gama-toc-toggle i {
    transform: rotate(-90deg);
}

/* --- لیست --- */
.gama-toc .gama-toc-list {
    list-style: none;
    margin: 12px 0 0 0;
    padding: 0 2px 0 0;
    counter-reset: gama-toc-counter;
    /* برای اینکه باکس‌های بعدی سایدبار در دسترس بمانند، فهرست بلند
       خودش اسکرول می‌خورد. */
    max-height: 60vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    transition: 0.3s all;
}

.gama-toc .gama-toc-list::-webkit-scrollbar {
    width: 4px;
}

.gama-toc .gama-toc-list::-webkit-scrollbar-track {
    background: transparent;
}

.gama-toc .gama-toc-list::-webkit-scrollbar-thumb {
    background: #d6d9e4;
    border-radius: 10px;
}

.gama-toc.is-collapsed .gama-toc-list {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
    overflow: hidden;
}

.gama-toc .gama-toc-item {
    list-style: none;
    margin: 0;
    padding: 0;
}

.gama-toc .gama-toc-item > a {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    padding: 7px 8px;
    border-radius: 10px;
    color: #2b2b2b;
    font-weight: 500;
    font-size: 15px;
    line-height: 1.9;
    text-decoration: none;
    transition: 0.3s all;
    word-spacing: -1px;
}

.gama-toc .gama-toc-item > a:hover {
    background: #f5f6fa;
    color: var(--custom-primary-color, #0634d2);
}

/* شماره‌گذاری سطح اول */
.gama-toc .gama-toc-level-0 {
    counter-increment: gama-toc-counter;
}

.gama-toc .gama-toc-level-0 > a .gama-toc-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 24px;
    height: 24px;
    margin-top: 4px;
    border-radius: 8px;
    background: #f0f2f9;
    color: var(--custom-primary-color, #0634d2);
    font-size: 12px;
    font-weight: bold;
    transition: 0.3s all;
}

.gama-toc .gama-toc-level-0 > a .gama-toc-marker::before {
    content: counter(gama-toc-counter);
}

/* نقطه برای سطوح تودرتو */
.gama-toc .gama-toc-item:not(.gama-toc-level-0) > a .gama-toc-marker {
    display: block;
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    margin-top: 13px;
    border-radius: 100%;
    background: #c9cee0;
    transition: 0.3s all;
}

.gama-toc .gama-toc-item:not(.gama-toc-level-0) > a {
    font-size: 14px;
    font-weight: normal;
    color: #555;
}

.gama-toc .gama-toc-level-1 {
    padding-right: 20px;
}

.gama-toc .gama-toc-level-2 {
    padding-right: 40px;
}

.gama-toc .gama-toc-level-3 {
    padding-right: 60px;
}

/* --- بخش فعال هنگام اسکرول --- */
.gama-toc .gama-toc-item.is-active > a {
    background: #f0f2f9;
    color: var(--custom-primary-color, #0634d2);
    font-weight: bold;
}

.gama-toc .gama-toc-item.is-active > a .gama-toc-marker {
    background: var(--custom-primary-color, #0634d2);
    color: #fff;
}

/* --- هدف اسکرول در متن --- */
.post-content h1[id],
.post-content h2[id],
.post-content h3[id],
.post-content h4[id] {
    scroll-margin-top: 100px;
}

.post-content .gama-toc-highlight {
    animation: gama-toc-flash 1.4s ease-out 1;
}

@keyframes gama-toc-flash {
    0% {
        background: rgba(6, 52, 210, 0.10);
    }
    100% {
        background: transparent;
    }
}

/* --- موبایل --- */
@media screen and (max-width: 768px) {
    .gama-toc {
        border-radius: 14px;
        padding: 12px 15px 15px 15px;
        margin-bottom: 20px;
    }

    .gama-toc .gama-toc-title {
        font-size: 16px !important;
    }

    .gama-toc .gama-toc-item > a {
        font-size: 14px;
    }

    .gama-toc .gama-toc-level-1 {
        padding-right: 14px;
    }

    .gama-toc .gama-toc-level-2 {
        padding-right: 28px;
    }
}

/* کاهش انیمیشن برای کاربرانی که آن را غیرفعال کرده‌اند */
@media (prefers-reduced-motion: reduce) {
    .gama-toc *,
    .post-content .gama-toc-highlight {
        transition: none !important;
        animation: none !important;
    }
}
