/**
 * Lightweight TOC Plugin Styles
 * Optimized for performance and correctness
 * Version 1.5.0
 */

/* Inline TOC version */
.lightweight-toc-inline {
    display: block !important;
    margin: 20px 0 30px 0 !important;
    max-width: 700px !important;
    margin-left: 0 !important;
    margin-right: auto !important;
    border: 1px solid #e9ecef !important;
    border-radius: 4px !important;
    background-color: #f8f9fa !important;
    padding: 15px !important;
}

/* Collapsible header */
.lightweight-toc-inline-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    cursor: pointer !important;
    margin-bottom: 0 !important;
}

.lightweight-toc-inline-header h4 {
    margin: 0 !important;
    font-size: 16px !important;
    font-weight: bold !important;
}

.lightweight-toc-inline-expand {
    display: inline-block !important;
    width: 20px !important;
    height: 20px !important;
    text-align: center !important;
    line-height: 20px !important;
    font-weight: bold !important;
    cursor: pointer !important;
}

.lightweight-toc-inline.active .lightweight-toc-inline-expand {
    content: "-" !important;
}

.lightweight-toc-inline-content {
    display: none !important;
    margin-top: 15px !important;
}

.lightweight-toc-inline.active .lightweight-toc-inline-content {
    display: block !important;
}

/* Sticky TOC container */
.lightweight-toc-container {
    position: fixed !important;
    top: 100px !important;
    right: 0 !important;
    left: auto !important;
    z-index: 999 !important;
    font-size: 14px !important;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    max-width: 320px !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

.lightweight-toc-container.sticky-active {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Toggle button */
.lightweight-toc-toggle {
    background-color: #f8f9fa !important;
    border: 1px solid #e9ecef !important;
    border-right: none !important;
    border-left: 1px solid #e9ecef !important;
    border-radius: 4px 0 0 4px !important;
    padding: 8px 12px !important;
    cursor: pointer !important;
    box-shadow: 2px 2px 10px rgba(0,0,0,0.1) !important;
    display: inline-block !important;
    font-weight: bold !important;
}

.lightweight-toc-toggle:hover {
    background-color: #e9ecef !important;
}

/* Content area */
.lightweight-toc-content {
    background-color: #f8f9fa !important;
    border: 1px solid #e9ecef !important;
    border-right: none !important;
    border-left: 1px solid #e9ecef !important;
    border-radius: 4px 0 0 4px !important;
    padding: 15px !important;
    padding-top: 45px !important; /* Make room for close button */
    box-shadow: 2px 2px 10px rgba(0,0,0,0.1) !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    display: none !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s ease !important;
    width: 280px !important;
    max-width: 80vw !important;
    position: relative !important; /* Ensure the close button positions correctly */
}

/* Close button - explicitly in top right */
.lightweight-toc-close {
    position: absolute !important;
    top: 5px !important;
    right: 5px !important;
    cursor: pointer !important;
    font-size: 24px !important;
    font-weight: bold !important;
    z-index: 9999 !important;
    background: transparent !important;
    border: none !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    text-align: center !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0.9 !important;
    border-radius: 50% !important;
    transition: all 0.2s ease !important;
    display: block !important;
    color: #333 !important;
}

.lightweight-toc-close:hover {
    opacity: 1 !important;
    background-color: rgba(0,0,0,0.1) !important;
    transform: scale(1.1) !important;
    color: #000 !important;
}

.lightweight-toc-close:focus {
    outline: none !important;
}

/* When TOC is open */
.lightweight-toc-container.open .lightweight-toc-content {
    display: block !important;
    transform: translateX(0) !important;
}

.lightweight-toc-container.open .lightweight-toc-toggle {
    display: none !important;
}

/* Lists - explicitly no bullets and proper margins */
.lightweight-toc-list, 
.lightweight-toc-sublist {
    list-style: none !important;
    list-style-type: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.lightweight-toc-list li {
    list-style: none !important;
    list-style-type: none !important;
    margin-bottom: 8px !important;
    line-height: 1.4 !important;
    position: relative !important;
    padding-left: 0 !important;
    padding-right: 20px !important; /* Make room for the + icon */
    display: block !important;
}

.lightweight-toc-sublist {
    list-style: none !important;
    list-style-type: none !important;
    margin-left: 12px !important;
    margin-top: 5px !important;
    display: none !important;
    border-left: 1px solid #e9ecef !important;
    padding-left: 8px !important;
}

.lightweight-toc-sublist li {
    list-style: none !important;
    list-style-type: none !important;
    margin-bottom: 5px !important;
}

/* Links */
.lightweight-toc-list a, 
.lightweight-toc-sublist a {
    color: #444 !important;
    text-decoration: none !important;
    display: block !important;
    padding: 2px 0 !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
    hyphens: auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
    line-height: 1.4 !important;
}

.lightweight-toc-list a:hover, 
.lightweight-toc-sublist a:hover {
    color: #0073aa !important;
    text-decoration: underline !important;
}

/* Expand/collapse indicator */
.lightweight-toc-expand {
    display: inline-block !important;
    width: 16px !important;
    height: 16px !important;
    text-align: center !important;
    line-height: 16px !important;
    font-weight: bold !important;
    cursor: pointer !important;
    position: absolute !important;
    right: 0 !important;
    top: 2px !important;
}

/* Active state for expanded items */
.lightweight-toc-expandable.active .lightweight-toc-expand {
    content: "-" !important;
}

.lightweight-toc-expandable.active .lightweight-toc-sublist {
    display: block !important;
}

/* Adjust for mobile devices */
@media (max-width: 768px) {
    .lightweight-toc-container {
        max-width: 260px !important;
    }
    
    .lightweight-toc-content {
        max-height: 70vh !important;
        padding: 10px !important;
        padding-top: 40px !important;
    }
}
