/* ==========================================================================
   Table of Contents Component
   ========================================================================== */

/* --------------------------------------------------------------------------
   Button (inside the sticky reading header)
   -------------------------------------------------------------------------- */

.toc-button {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.12);

    background: transparent;
    color: #333;
    cursor: pointer;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease;
}

.toc-button:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.2);
}

.toc-button:active {
    background: rgba(0, 0, 0, 0.08);
}

.toc-button.is-active {
    background: rgba(150, 0, 12, 0.08);
    border-color: rgba(150, 0, 12, 0.3);
    color: #96000c;
}

.toc-button-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

/* --------------------------------------------------------------------------
   Panel (drops down from the sticky header)
   -------------------------------------------------------------------------- */

.toc-panel {
    position: absolute;
    top: 100%; /* sits directly below the sticky header */
    right: 0;
    z-index: 998;

    width: 340px;
    max-height: 60vh;

    background: white;
    border-radius: 0 0 8px 8px;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.12),
        0 8px 40px rgba(0, 0, 0, 0.08);

    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition:
        opacity 0.2s ease,
        visibility 0.2s ease,
        transform 0.2s ease;

    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toc-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Panel Header
   -------------------------------------------------------------------------- */

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-s) var(--space-m);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.toc-title {
    font-family: var(--font-sans);
    font-size: var(--step-0);
    font-weight: 600;
    color: #333;
}

.toc-close {
    display: none; /* Hidden on desktop, shown on mobile */
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #666;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.toc-close:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* --------------------------------------------------------------------------
   TOC List
   -------------------------------------------------------------------------- */

.toc-list {
    list-style: none;
    margin: 0;
    padding: var(--space-s) 0;
    overflow-y: auto;
    flex: 1;

    /* Subtle scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

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

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

.toc-list::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.toc-item {
    margin: 0;
    padding: 0;
}

.toc-item a {
    display: block;
    padding: 8px var(--space-m);

    font-family: var(--font-sans);
    font-size: var(--step--1);
    line-height: 1.4;
    color: #444;
    text-decoration: none;

    transition:
        background-color 0.15s ease,
        color 0.15s ease;
}

.toc-item a:hover {
    background: rgba(0, 0, 0, 0.03);
    color: #96000c;
}

.toc-item.is-active a {
    color: #96000c;
    background: rgba(150, 0, 12, 0.05);
    font-weight: 500;
}

/* Hierarchical indentation */
.toc-level-2 a {
    padding-left: var(--space-m);
}

.toc-level-3 a {
    padding-left: calc(var(--space-m) + var(--space-s));
    font-size: var(--step--1);
}

.toc-level-4 a {
    padding-left: calc(var(--space-m) + var(--space-m));
    font-size: var(--step--2);
    color: #666;
}

.toc-level-4.is-active a {
    color: #96000c;
}

/* --------------------------------------------------------------------------
   Mobile Styles
   -------------------------------------------------------------------------- */

@media (width < 600px) {
    .toc-panel {
        /* Full width on mobile */
        left: 0;
        right: 0;
        width: auto;
        max-height: 50vh;
        border-radius: 0;
    }

    .toc-close {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .toc-item a {
        padding: 12px var(--space-m);
    }

    /* Slightly less indentation on mobile */
    .toc-level-3 a {
        padding-left: calc(var(--space-m) + 12px);
    }

    .toc-level-4 a {
        padding-left: calc(var(--space-m) + 24px);
    }
}

/* Tablet adjustments */
@media (width >= 600px) and (width < 800px) {
    .toc-panel {
        width: 300px;
    }
}
