/**
 * Chapter Menu Styles
 *
 * All classes prefixed with 'chapter-menu-' to avoid collisions with
 * existing theme styles.
 *
 * This stylesheet provides:
 * 1. Chapter navigation header (collapsible)
 * 2. Previous/Current/Next quick navigation
 * 3. Full chapter list (expandable)
 * 4. Current chapter highlighting
 */

/* ============================================
   Chapter Navigation Container
   ============================================ */

.chapter-menu-nav {
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    border-radius: 0 0 0 0;
    /* Fixed positioning within the sidebar */
    position: sticky;
    top: 0;
    z-index: 100;
    /* Remove margin since it's now sticky */
    margin-bottom: 0;
}

/* Adjust the docs-nav to account for sticky chapter menu */
.chapter-menu-nav + .docs-nav {
    /* The scrollspy menu scrolls independently */
    padding-top: 0.5rem;
}

/* ============================================
   Chapter Header (Clickable to expand list)
   ============================================ */

.chapter-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: #4550e6;
    color: #fff;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.chapter-menu-header:hover {
    background-color: #3a45d1;
}

.chapter-menu-title {
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chapter-menu-icon {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}

.chapter-menu-nav.chapter-menu-expanded .chapter-menu-icon {
    transform: rotate(180deg);
}

/* ============================================
   Quick Navigation (Prev / Current / Next)
   ============================================ */

.chapter-menu-quick-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background-color: #fff;
    border-bottom: 1px solid #e9ecef;
    gap: 0.5rem;
}

.chapter-menu-prev,
.chapter-menu-next {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem;
    font-size: 1rem;
    color: #4550e6;
    text-decoration: none;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease, color 0.2s ease;
    white-space: nowrap;
    min-width: 40px;
    width: 40px;
}

.chapter-menu-prev:hover,
.chapter-menu-next:hover {
    background-color: #e9ecef;
    color: #3a45d1;
    text-decoration: none;
}

/* Hide text labels on prev/next buttons, show icon only */
.chapter-menu-prev i,
.chapter-menu-next i {
    margin: 0;
}

.chapter-menu-disabled {
    visibility: hidden;
}

.chapter-menu-current {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: #252930;
    padding: 0.25rem 0.5rem;
    background-color: #e7e9fd;
    border-radius: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Allow more room for the title by removing max-width constraint */
    min-width: 0;
}

/* ============================================
   Chapter List (Full list, collapsed by default)
   ============================================ */

.chapter-menu-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background-color: #fff;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    /* Add shadow when expanded to show it's above content */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 0 0 0.375rem 0.375rem;
}

.chapter-menu-list.chapter-menu-collapsed {
    max-height: 0;
    box-shadow: none;
}

.chapter-menu-list.chapter-menu-expanded {
    max-height: 60vh; /* Limit to viewport height */
    overflow-y: auto;
    transition: max-height 0.5s ease-in;
}

.chapter-menu-item {
    border-bottom: 1px solid #f0f0f0;
}

.chapter-menu-item:last-child {
    border-bottom: none;
}

.chapter-menu-item a {
    display: flex;
    flex-direction: column;
    padding: 0.625rem 1rem;
    text-decoration: none;
    color: #5d6778;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.chapter-menu-item a:hover {
    background-color: #f5f6fe;
    color: #4550e6;
    text-decoration: none;
}

.chapter-menu-item-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
    margin-bottom: 0.125rem;
}

.chapter-menu-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.3;
    /* Truncate long titles */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   Current Chapter Highlighting
   ============================================ */

.chapter-menu-item-current {
    background-color: #f5f6fe;
    border-left: 3px solid #4550e6;
}

.chapter-menu-item-current a {
    color: #4550e6;
    font-weight: 600;
}

.chapter-menu-item-current .chapter-menu-item-label {
    color: #4550e6;
}

.chapter-menu-item-current .chapter-menu-item-title {
    font-size: 0.9rem;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 767.98px) {
    .chapter-menu-quick-nav {
        flex-wrap: wrap;
    }

    .chapter-menu-current {
        order: -1;
        width: 100%;
        max-width: none;
        margin-bottom: 0.5rem;
    }

    .chapter-menu-prev,
    .chapter-menu-next {
        flex: 1;
    }
}

@media (max-width: 575.98px) {
    .chapter-menu-header {
        padding: 0.625rem 0.75rem;
    }

    .chapter-menu-quick-nav {
        padding: 0.5rem 0.75rem;
    }

    .chapter-menu-item a {
        padding: 0.5rem 0.75rem;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .chapter-menu-nav {
        display: none !important;
    }
}
