/* "On this page" for long pages (slms/utils/page_contents.py) and their back-to-top button.
   Loaded by public/custom_page.html only when the page has the list. On a phone it's a
   folded box above the text; from 1200px it stays open beside the text as you scroll, with
   the section you're reading marked. */

.cp-page--contents .cp-content-area { padding-top: 0; }
.cp-toc { margin: 0 0 1.75rem; }
.cp-toc__fold {
    background: var(--cp-surface);
    border: 1px solid var(--cp-border);
    border-radius: var(--slms-card-radius, var(--cp-r));
}
.cp-toc__summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 3rem;
    padding: 0.7rem 1rem;
    cursor: pointer;
    list-style: none;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--cp-heading);
}
.cp-toc__summary::-webkit-details-marker { display: none; }
.cp-toc__summary > .ph-list-bullets { font-size: 1.15rem; color: var(--cp-accent); }
.cp-toc__count { margin-left: auto; font-size: 0.8rem; font-weight: 600; color: var(--cp-muted); }
.cp-toc__caret { color: var(--cp-muted); transition: transform 0.2s ease; }
.cp-toc__fold[open] .cp-toc__caret { transform: rotate(180deg); }
.cp-toc__list {
    list-style: none;
    margin: 0;
    padding: 0.35rem 0.5rem 0.6rem;
    border-top: 1px solid var(--cp-border);
}
.cp-toc__list li { margin: 0; }
.cp-toc__list a {
    display: block;
    padding: 0.55rem 0.55rem;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.35;
    color: var(--cp-text);
    text-decoration: none;
    overflow-wrap: anywhere;
}
.cp-toc__list a:hover,
.cp-toc__list a:focus-visible {
    background: color-mix(in srgb, var(--cp-accent) 8%, transparent);
    color: var(--cp-heading);
}
.cp-toc__list a[aria-current="true"] { font-weight: 700; color: var(--cp-heading); }

/* A section jumped to lands below the sticky header, not under it. */
.cp-page--contents .cp-content [id^="content-"] {
    scroll-margin-top: calc(var(--navbar-real-height, var(--navbar-height, 72px)) + 1rem);
}

@media (min-width: 992px) {
    body.nav-style-centered .cp-page--contents .cp-content [id^="content-"] {
        scroll-margin-top: calc(var(--centered-compact-height, 58px) + 1rem);
    }
}

/* Wide screens: the list stays open beside the text. The line on the left of the section
   being read marks where you are (a marker, not decoration). */
@media (min-width: 1200px) {
    .cp-doc {
        display: grid;
        grid-template-columns: minmax(0, 780px) 16rem;
        column-gap: 3rem;
        align-items: start;
        max-width: calc(780px + 19rem);
    }
    .cp-doc > .cp-content { grid-column: 1; grid-row: 1; min-width: 0; }
    .cp-doc > .cp-toc--beside {
        grid-column: 2;
        grid-row: 1;
        position: sticky;
        top: calc(var(--navbar-real-height, var(--navbar-height, 72px)) + 1.25rem);
        margin: 0;
    }
    body.nav-style-centered .cp-doc > .cp-toc--beside { top: calc(var(--centered-compact-height, 58px) + 1.25rem); }
    .cp-toc--beside .cp-toc__fold { background: transparent; border: 0; border-radius: 0; }
    .cp-toc--beside .cp-toc__summary {
        min-height: 0;
        padding: 0 0 0.65rem;
        pointer-events: none;
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: var(--cp-muted);
    }
    .cp-toc--beside .cp-toc__summary > .ph-list-bullets,
    .cp-toc--beside .cp-toc__count,
    .cp-toc--beside .cp-toc__caret { display: none; }
    .cp-toc--beside .cp-toc__list {
        max-height: calc(100vh - 9rem);
        overflow-y: auto;
        padding: 0;
        border-top: 0;
        border-left: 1px solid var(--cp-border);
    }
    .cp-toc--beside .cp-toc__list a {
        margin-left: -1px;
        padding: 0.38rem 0.9rem;
        border-left: 2px solid transparent;
        border-radius: 0;
        font-size: 0.84rem;
        color: var(--cp-muted);
    }
    .cp-toc--beside .cp-toc__list a:hover,
    .cp-toc--beside .cp-toc__list a:focus-visible { background: transparent; color: var(--cp-heading); }
    .cp-toc--beside .cp-toc__list a[aria-current="true"] { border-left-color: var(--cp-accent); color: var(--cp-heading); }
}

/* Back to top: shows once you're well down the page. */
.cp-top {
    position: fixed;
    right: max(1rem, env(safe-area-inset-right));
    bottom: calc(1rem + env(safe-area-inset-bottom));
    z-index: 1020;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.875rem;
    height: 2.875rem;
    padding: 0;
    border: 1px solid var(--cp-border);
    border-radius: 50%;
    background: var(--cp-surface);
    color: var(--cp-heading);
    box-shadow: var(--shadow-soft, 0 6px 18px rgba(15, 23, 42, 0.14));
    font-size: 1.1rem;
    cursor: pointer;
    visibility: hidden;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}
.cp-top[hidden] { display: none; }
.cp-top.is-shown {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
}
.cp-top:hover,
.cp-top:focus-visible { color: var(--cp-accent); }

@media (prefers-reduced-motion: reduce) {
    .cp-toc__caret, .cp-top, .cp-top.is-shown { transition: none; }
}
