/* ============================================
   TOC Schema - by الجيوشي
   ============================================ */

/* ---- الصندوق الرئيسي ---- */
.toc-schema-box {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 24px 0 28px;
    max-width: 100%;
    font-size: 15px;
    line-height: 1.7;
}

/* RTL */
.toc-schema-box[dir="rtl"] {
    border: none;
    text-align: right;
}

/* LTR */
.toc-schema-box[dir="ltr"] {
    border: none;
    text-align: left;
}

/* ---- الهيدر ---- */
.toc-schema-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border-bottom: none;
    cursor: pointer;
    user-select: none;
}

/* الخط الجانبي على الهيدر فقط */
/* اللون بيجي من الـ inline style الديناميكي - القيمة هنا fallback فقط */
.toc-schema-box[dir="rtl"] .toc-schema-header {
    border-right: 3px solid var(--toc-accent, #2271b1);
    padding-right: 13px;
}

.toc-schema-box[dir="ltr"] .toc-schema-header {
    border-left: 3px solid var(--toc-accent, #2271b1);
    padding-left: 13px;
}

.toc-schema-icon {
    font-size: 15px;
    flex-shrink: 0;
}

.toc-schema-title {
    font-weight: 700;
    color: inherit;
    font-size: 15px;
    flex: 1;
}

.toc-schema-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 11px;
    color: #999;
    padding: 2px 6px;
    border-radius: 3px;
    transition: color .2s;
    flex-shrink: 0;
}

.toc-schema-toggle:hover {
    color: #2271b1;
}

/* ---- قائمة المحتويات ---- */
.toc-schema-nav {
    padding: 6px 16px 10px;
}

.toc-schema-list {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: toc-counter;
}

/* ---- عناصر H2 ---- */
.toc-item.toc-h2 {
    margin: 5px 0;
    counter-increment: toc-counter;
}

.toc-item.toc-h2 > .toc-link::before {
    content: counter(toc-counter) ". ";
    color: #2271b1;
    font-weight: 700;
    font-size: 13px;
}

/* ---- عناصر H3 ---- */
.toc-sublist {
    margin: 3px 0 3px 0;
    padding-right: 18px;
    padding-left: 0;
    list-style: none;
    border-right: 2px solid #e0e8f4;
}

[dir="ltr"] .toc-sublist {
    padding-left: 18px;
    padding-right: 0;
    border-left: 2px solid #e0e8f4;
    border-right: none;
}

.toc-item.toc-h3 {
    margin: 2px 0;
}

/* ---- الروابط ---- */
.toc-link {
    color: #2c3e50;
    text-decoration: none;
    display: inline-block;
    padding: 1px 3px;
    border-radius: 3px;
    transition: color .15s, background .15s;
    font-size: 14px;
}

.toc-link:hover {
    color: #2271b1;
    background: rgba(34, 113, 177, 0.06);
    text-decoration: none;
}

.toc-link-h3 {
    font-size: 13px;
    color: #666;
}

.toc-link-h3:hover {
    color: #2271b1;
}

/* ---- الرابط النشط عند التمرير ---- */
.toc-link-active {
    color: #2271b1 !important;
    font-weight: 600;
}

/* ---- تمييز العنوان عند النقر ---- */
.toc-highlight {
    animation: toc-flash .6s ease-in-out 2;
}

@keyframes toc-flash {
    0%, 100% { background: transparent; }
    50%       { background: #fff3cd; }
}

/* ---- زر العودة للأعلى ---- */
.toc-back-top {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: rgba(34, 113, 177, 0.1);
    color: #2271b1;
    border-radius: 50%;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
    margin-right: 7px;
    margin-left: 0;
    vertical-align: middle;
    transition: background .2s, color .2s;
    opacity: 0.6;
}

[dir="ltr"] .toc-back-top {
    margin-left: 7px;
    margin-right: 0;
}

.toc-back-top:hover {
    background: #2271b1;
    color: #fff;
    opacity: 1;
    text-decoration: none;
}

/* ---- تحسين العناوين داخل المقال ---- */
.toc-heading-anchor {
    scroll-margin-top: 80px;
}

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

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .toc-schema-box {
        font-size: 14px;
        margin: 18px 0 22px;
    }

    .toc-schema-nav {
        padding: 6px 12px 8px;
    }

    .toc-link {
        font-size: 13px;
    }
}
