/* ==========================================================================
   33-toc.css
   جدول المحتويات (Table of Contents) — الاتحاد العربي للإعلام السياحي
   مكوّن مشترك يعمل في صفحة المقال والصفحة الثابتة
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. الحاوية الرئيسية (Accordion)
   -------------------------------------------------------------------------- */
.toc {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 5px;
    overflow: hidden;
    transition: box-shadow 0.3s ease;
}

.toc:hover {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.04);
}

/* --------------------------------------------------------------------------
   2. الترويسة (قابلة للنقر)
   -------------------------------------------------------------------------- */
.toc__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: linear-gradient(135deg, rgba(20, 52, 136, 0.03), rgba(204, 98, 30, 0.03));
    transition: background-color 0.3s ease;
}

.toc__header::-webkit-details-marker {
    display: none;
}

.toc__header:hover {
    background: linear-gradient(135deg, rgba(20, 52, 136, 0.06), rgba(204, 98, 30, 0.06));
}

.toc__header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toc__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    background-color: var(--color-primary-light);
}

.toc__icon .ph {
    font-size: 16px;
    color: var(--color-primary);
}

.toc__label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
}

.toc__count {
    font-size: 11px;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    background-color: rgba(0, 0, 0, 0.04);
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 4px;
}

.toc__caret {
    font-size: 16px;
    color: var(--color-text-muted);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* حالة الفتح */
details[open].toc .toc__caret {
    transform: rotate(180deg);
}

details[open].toc .toc__header {
    border-bottom: 1px dashed var(--color-border);
}

/* --------------------------------------------------------------------------
   3. حاوية المحتوى + أنيميشن الفتح والإغلاق باستخدام CSS Grid
   -------------------------------------------------------------------------- */
/* التغليف الخارجي للتحكم بالارتفاع */
.toc__content-grid {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* عندما يكون الأكورديون مفتوحاً */
details[open].toc .toc__content-grid {
    grid-template-rows: 1fr;
}

/* حالة الإغلاق (للسماح بالأنيميشن قبل الإغلاق الفعلي) */
details[open].toc.is-closing .toc__content-grid,
details[open].toc.is-opening .toc__content-grid {
    grid-template-rows: 0fr;
}

/* التغليف الداخلي لإخفاء المحتوى الفائض أثناء الأنيميشن */
.toc__content-inner {
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

details[open].toc .toc__content-inner {
    opacity: 1;
}

details[open].toc.is-closing .toc__content-inner,
details[open].toc.is-opening .toc__content-inner {
    opacity: 0;
}

.toc__body {
    padding: 12px 16px;
}

.toc__list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* --------------------------------------------------------------------------
   4. عنصر TOC (رابط)
   -------------------------------------------------------------------------- */
.toc__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 5px;
    text-decoration: none;
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    line-height: 1.5;
    transition: all 0.25s ease;
    position: relative;
}

/* رقم العنصر */
.toc__item-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 11px;
    font-weight: var(--font-weight-bold);
    color: var(--color-text-muted);
    background-color: rgba(0, 0, 0, 0.04);
    transition: all 0.3s ease;
}

.toc__item-text {
    flex: 1;
    min-width: 0;
    transition: color 0.25s ease;
}

/* عنصر H3 فرعي — مسافة بادئة */
.toc__item--sub {
    padding-right: 46px;
    font-size: 13px;
}

.toc__item--sub .toc__item-num {
    width: 20px;
    height: 20px;
    font-size: 10px;
}

/* --------------------------------------------------------------------------
   5. حالة الهوفر
   -------------------------------------------------------------------------- */
.toc__item:hover {
    background-color: rgba(20, 52, 136, 0.04);
    color: var(--color-primary);
}

.toc__item:hover .toc__item-num {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   6. حالة العنصر النشط (القسم المرئي حالياً)
   -------------------------------------------------------------------------- */
.toc__item.is-active {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: var(--font-weight-semibold);
}

.toc__item.is-active .toc__item-num {
    background-color: var(--color-primary);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 145, 60, 0.25);
}

/* شريط جانبي للعنصر النشط */
.toc__item.is-active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 3px;
    background-color: var(--color-primary);
    animation: tocSlideIn 0.3s ease forwards;
}

@keyframes tocSlideIn {
    from {
        opacity: 0;
        transform: scaleY(0);
    }
    to {
        opacity: 1;
        transform: scaleY(1);
    }
}

/* --------------------------------------------------------------------------
   7. شريط التقدم
   -------------------------------------------------------------------------- */
.toc__progress-wrap {
    padding: 4px 16px 12px;
}

.toc__progress {
    height: 3px;
    background-color: rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.toc__progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* --------------------------------------------------------------------------
   8. أنيميشن الظهور — العناصر تظهر تدريجياً عند فتح الأكورديون
   -------------------------------------------------------------------------- */
details[open].toc .toc__item {
    animation: tocItemReveal 0.4s ease forwards;
    opacity: 0;
    transform: translateX(10px);
}

details[open].toc .toc__item:nth-child(1) { animation-delay: 0.05s; }
details[open].toc .toc__item:nth-child(2) { animation-delay: 0.1s; }
details[open].toc .toc__item:nth-child(3) { animation-delay: 0.15s; }
details[open].toc .toc__item:nth-child(4) { animation-delay: 0.2s; }
details[open].toc .toc__item:nth-child(5) { animation-delay: 0.25s; }
details[open].toc .toc__item:nth-child(6) { animation-delay: 0.3s; }
details[open].toc .toc__item:nth-child(7) { animation-delay: 0.35s; }
details[open].toc .toc__item:nth-child(8) { animation-delay: 0.4s; }

@keyframes tocItemReveal {
    from {
        opacity: 0;
        transform: translateX(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* --------------------------------------------------------------------------
   9. التجاوب (Mobile)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    .toc__header {
        padding: 12px 16px;
    }

    .toc__body {
        padding: 8px 10px;
    }

    .toc__item {
        padding: 9px 10px;
        font-size: 13px;
    }

    .toc__item--sub {
        padding-right: 40px;
        font-size: 12px;
    }

    .toc__label {
        font-size: 13px;
    }
}

/* --------------------------------------------------------------------------
   10. زر TOC العائم (للهاتف فقط) — بنفس أسلوب scroll-top
   -------------------------------------------------------------------------- */
.toc-fab {
    display: none;
}

@media (max-width: 767px) {
    .toc-fab {
        display: flex;
        position: fixed;
        bottom: 70px;
        left: 20px;
        z-index: 998;
        width: 42px;
        height: 42px;
        align-items: center;
        justify-content: center;
        background-color: var(--color-surface);
        color: var(--color-primary);
        border: 1px solid var(--color-border);
        border-radius: 50%;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
        cursor: pointer;
        transition: all 0.4s ease;
        opacity: 0;
        visibility: hidden;
        transform: translateY(20px);
        pointer-events: none;
    }

    .toc-fab.is-visible {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        pointer-events: auto;
    }

    .toc-fab:active {
        background-color: var(--color-primary);
        color: #FFFFFF;
        border-color: var(--color-primary);
        transform: scale(0.92);
    }

    .toc-fab .ph {
        font-size: 18px;
    }
}
