/* Content Tree — two-column section: sticky sidebar index + navigable content */

.content-tree-section {
    --ct-text: rgba(255, 255, 255, 0.70);
    --ct-text-strong: #ffffff;
    --ct-muted: rgba(255, 255, 255, 0.45);
    --ct-border: rgba(255, 255, 255, 0.12);
    --ct-hover-bg: rgba(255, 255, 255, 0.06);
    --ct-accent: var(--bs-primary, #6366f1);
    --ct-active-bg: rgba(99, 102, 241, 0.16);
    --ct-sticky-top: 105px;

    position: relative;
    padding: 2.5rem 0;
}

[data-bs-theme="light"] .content-tree-section,
.content-tree-section[data-bs-theme="light"] {
    --ct-text: rgba(15, 23, 42, 0.70);
    --ct-text-strong: #0f172a;
    --ct-muted: rgba(15, 23, 42, 0.45);
    --ct-border: rgba(15, 23, 42, 0.10);
    --ct-hover-bg: rgba(15, 23, 42, 0.05);
    --ct-active-bg: rgba(99, 102, 241, 0.10);
}

.content-tree-section *,
.content-tree-section *::before,
.content-tree-section *::after {
    box-sizing: border-box;
}

/* ---- Ambient backdrop: faded engineering grid + soft light beam ---- */
/* No overflow:hidden here (it would break the sticky sidebar) — the pseudos
   stay inset:0 and the grid is faded with a radial mask so it stays subtle. */
.content-tree-section::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
    background-size: 46px 46px;
    -webkit-mask-image: radial-gradient(100% 80% at 50% 42%, #000 0%, transparent 78%);
    mask-image: radial-gradient(100% 80% at 50% 42%, #000 0%, transparent 78%);
}

.content-tree-section::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(48% 40% at 50% 32%, rgba(99, 102, 241, 0.10), transparent 72%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 16%);
    mask-image: linear-gradient(to bottom, transparent 0%, #000 16%);
}

.content-tree-section > .container {
    position: relative;
    z-index: 1;
}

[data-bs-theme="light"] .content-tree-section::before,
.content-tree-section[data-bs-theme="light"]::before {
    background-image:
        linear-gradient(rgba(15, 23, 42, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px);
}

[data-bs-theme="light"] .content-tree-section::after,
.content-tree-section[data-bs-theme="light"]::after {
    background: radial-gradient(48% 40% at 50% 32%, rgba(99, 102, 241, 0.06), transparent 72%);
}

/* ---- Section heading (full-width intro above the columns) ---- */
.content-tree-section__head {
    margin-bottom: 2.5rem;
}

.content-tree-section__title {
    margin: 0 0 0.75rem;
    font-size: clamp(1.9rem, 1.3rem + 2.2vw, 2.75rem);
    line-height: 1.15;
}

.content-tree-section__subtitle {
    margin: 0;
    max-width: 720px;
    font-size: 1.05rem;
    color: var(--ct-muted);
}

/* ---- Two-column grid ---- */
.content-tree-section__grid {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 3.25rem;
    align-items: start;
}

.content-tree-section--right .content-tree-section__grid {
    grid-template-columns: minmax(0, 1fr) 280px;
}

.content-tree-section--right .content-tree {
    order: 2;
}

.content-tree-section--right .content-tree-content {
    order: 1;
}

.content-tree-content__heading {
    margin-top: 1.75rem;
}

.content-tree-content__heading:first-child {
    margin-top: 0;
}

/* Image gallery — space splits evenly by image count, keeping proportion */
.content-tree-content__gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 1.25rem 0;
}

.content-tree-content__gallery .content-tree-content__img {
    flex: 1 1 0;
    min-width: 140px;
    margin: 0;
}

.content-tree-content__gallery img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

/* Bulleted list */
.content-tree-content__bullets {
    margin: 1rem 0;
    padding-left: 1.25rem;
}

.content-tree-content__bullets li {
    margin: 0.35rem 0;
}

/* Link row */
.content-tree-content__links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 1.25rem 0;
}

/* Keep media responsive within the column */
.content-tree-content img,
.content-tree-content video,
.content-tree-content iframe,
.content-tree-content table {
    max-width: 100%;
}

.content-tree-content img {
    height: auto;
    border-radius: 8px;
}

.content-tree-content figure {
    margin: 1.25rem 0;
}

.content-tree-content figure img {
    display: block;
}

.content-tree-content figcaption {
    margin-top: 6px;
    font-size: 13px;
    color: var(--ct-muted);
}

/* ---- Sidebar (sticky within the section) ---- */
.content-tree {
    position: sticky;
    top: var(--ct-sticky-top);
    align-self: start;
}

.content-tree__inner {
    max-height: calc(100vh - var(--ct-sticky-top) - 1.5rem);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--ct-border) transparent;
}

.content-tree__inner::-webkit-scrollbar {
    width: 8px;
}

.content-tree__inner::-webkit-scrollbar-track {
    background: transparent;
}

.content-tree__inner::-webkit-scrollbar-thumb {
    background: var(--ct-border);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.content-tree__inner::-webkit-scrollbar-thumb:hover {
    background: var(--ct-muted);
    background-clip: content-box;
}

.content-tree__panel {
    position: relative;
}

/* Sliding active indicator — glides between sections as you scroll */
.content-tree__marker {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    border-radius: 2px;
    background: var(--ct-accent);
    box-shadow: 0 0 8px var(--ct-accent);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease;
}

.content-tree__marker--on {
    opacity: 0.9;
}

.content-tree__title {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ct-muted);
    margin-bottom: 10px;
}

/* Reading progress */
.content-tree__progress {
    height: 2px;
    margin-bottom: 12px;
    border-radius: 2px;
    background: var(--ct-border);
    overflow: hidden;
}

.content-tree__progress > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--ct-accent);
    transition: width 0.12s linear;
}

/* ---- Tree ---- */
.content-tree__list,
.content-tree__sublist {
    list-style: none;
    margin: 0;
    padding: 0;
}

.content-tree__sublist {
    position: relative;
    padding-left: 22px;
}

.content-tree__sublist::before {
    content: "";
    position: absolute;
    left: 9px;
    top: 2px;
    bottom: 2px;
    width: 1px;
    background: var(--ct-border);
}

.content-tree__item {
    margin: 1px 0;
}

.content-tree__item--collapsed > .content-tree__sublist {
    display: none;
}

.content-tree__row {
    display: flex;
    align-items: flex-start;
    gap: 2px;
}

/* Caret */
.content-tree__caret {
    flex: 0 0 18px;
    width: 18px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: 0;
    cursor: pointer;
    color: var(--ct-muted);
}

.content-tree__caret::before {
    content: "";
    width: 6px;
    height: 6px;
    margin-top: -2px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.18s ease;
}

.content-tree__item--collapsed > .content-tree__row > .content-tree__caret::before {
    transform: rotate(-45deg);
}

.content-tree__caret--empty {
    visibility: hidden;
    cursor: default;
}

/* Links */
.content-tree__link {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    padding: 5px 8px;
    border-radius: 6px;
    border-left: 2px solid transparent;
    color: var(--ct-text);
    font-size: 13.5px;
    line-height: 1.4;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.content-tree__link:hover {
    color: var(--ct-text-strong);
    background: var(--ct-hover-bg);
}

.content-tree__link--lvl2 {
    font-weight: 500;
    color: var(--ct-text-strong);
}

.content-tree__link--lvl3 {
    font-size: 13px;
}

.content-tree__link--lvl4 {
    font-size: 12.5px;
    opacity: 0.9;
}

.content-tree__link--active {
    color: var(--ct-text-strong);
    background: var(--ct-active-bg);
    font-weight: 500;
}

/* ---- Mobile disclosure toggle (hidden on desktop) ---- */
.content-tree__toggle {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--ct-border);
    border-radius: 10px;
    background: var(--ct-hover-bg);
    color: var(--ct-text-strong);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.content-tree__toggle-label i {
    color: var(--ct-accent);
    margin-right: 6px;
}

.content-tree__toggle-caret {
    color: var(--ct-muted);
    transition: transform 0.2s ease;
}

.content-tree--open .content-tree__toggle-caret {
    transform: rotate(180deg);
}

/* ---- Responsive: stack below Bootstrap's lg breakpoint ---- */
@media (max-width: 991.98px) {
    .content-tree-section__grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .content-tree,
    .content-tree-content {
        order: 0 !important;
    }

    .content-tree {
        position: static;
    }

    .content-tree__inner {
        max-height: none;
        overflow: visible;
    }

    .content-tree__toggle {
        display: flex;
    }

    .content-tree__title {
        display: none;
    }

    .content-tree__panel {
        display: none;
        margin-top: 10px;
    }

    .content-tree--open .content-tree__panel {
        display: block;
    }
}

@media (prefers-reduced-motion: reduce) {
    .content-tree__caret::before,
    .content-tree__progress > span,
    .content-tree__toggle-caret,
    .content-tree__marker {
        transition: none;
    }
}
