/**
 * Botcrawl Table of Contents Styles
 * Matches the Botcrawl Posts Widget styling
 * Version: 1.0.2
 */

/* ==========================================================================
   Widget Container - Matches Posts Widget
   ========================================================================== */

.bctoc-widget {
    margin-bottom: 2rem;
}

.bctoc-wrapper {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Sticky behavior - contained within sidebar */
.bctoc-wrapper--sticky {
    position: sticky;
    top: var(--bctoc-offset, 80px);
    max-height: calc(100vh - var(--bctoc-offset, 80px) - 2rem);
    overflow-y: auto;
}

/* Smooth scrollbar for sticky overflow */
.bctoc-wrapper--sticky::-webkit-scrollbar {
    width: 4px;
}

.bctoc-wrapper--sticky::-webkit-scrollbar-track {
    background: transparent;
}

.bctoc-wrapper--sticky::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 4px;
}

.bctoc-wrapper--sticky::-webkit-scrollbar-thumb:hover {
    background-color: #999;
}

/* ==========================================================================
   Header - Matches Posts Widget Title Style
   ========================================================================== */

.bctoc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--bc-accent, #14e21c);
}

.bctoc-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0;
    color: #1a1a1a;
    /* Normal case - not uppercase */
}

/* Collapse toggle button */
.bctoc-collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.bctoc-collapse-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.bctoc-collapse-icon {
    display: block;
    width: 10px;
    height: 10px;
    border-right: 2px solid #666;
    border-bottom: 2px solid #666;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -3px;
}

.bctoc-collapse-toggle[aria-expanded="false"] .bctoc-collapse-icon {
    transform: rotate(-45deg);
    margin-top: 3px;
}

/* ==========================================================================
   Content Area
   ========================================================================== */

.bctoc-content {
    transition: max-height 0.3s ease, opacity 0.2s ease;
    overflow: hidden;
}

.bctoc-wrapper--collapsed .bctoc-content {
    max-height: 0;
    opacity: 0;
}

/* ==========================================================================
   Navigation
   ========================================================================== */

.bctoc-nav {
    /* Container for the TOC */
}

.bctoc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bctoc-sublist {
    list-style: none;
    margin: 0.5rem 0 0 0;
    padding: 0 0 0 1rem;
    border-left: 1px solid #e5e5e5;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
}

/* Collapsed sublist */
.bctoc-item--h2.bctoc-collapsed .bctoc-sublist {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

/* ==========================================================================
   TOC Items - Matches Posts Widget Items
   ========================================================================== */

.bctoc-item {
    position: relative;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e5e5e5;
}

.bctoc-item:first-child {
    padding-top: 0;
}

.bctoc-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.bctoc-item--h3 {
    padding: 0.375rem 0;
    border-bottom: none;
}

.bctoc-item--h3:last-child {
    padding-bottom: 0;
}

/* ==========================================================================
   Links - Matches Posts Widget Link Style
   ========================================================================== */

.bctoc-link {
    display: block;
    color: #1a1a1a;
    text-decoration: none;
    transition: color 0.2s ease;
}

.bctoc-link:hover {
    color: var(--bc-accent, #14e21c);
}

/* H2 links - same as post titles */
.bctoc-item--h2 > .bctoc-link {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.4;
    color: #1a1a1a;
}

/* H3 links - slightly smaller */
.bctoc-item--h3 > .bctoc-link {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    color: #555;
}

/* Active state */
.bctoc-link.bctoc-active {
    color: var(--bc-accent, #14e21c);
}

.bctoc-item--h2 > .bctoc-link.bctoc-active {
    font-weight: 700;
}

/* ==========================================================================
   Toggle Button for H3 Sections
   ========================================================================== */

.bctoc-toggle {
    position: absolute;
    right: 0;
    top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.bctoc-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.bctoc-toggle-icon {
    display: block;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid #666;
    border-bottom: 1.5px solid #666;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -2px;
}

.bctoc-toggle[aria-expanded="false"] .bctoc-toggle-icon {
    transform: rotate(-45deg);
    margin-top: 2px;
}

/* Adjust H2 link padding when toggle exists */
.bctoc-item--h2.bctoc-item--has-toggle > .bctoc-link {
    padding-right: 1.5rem;
}

/* ==========================================================================
   Numbered Variant
   ========================================================================== */

.bctoc-wrapper--numbered .bctoc-list {
    counter-reset: toc-h2;
}

.bctoc-wrapper--numbered .bctoc-item--h2 {
    counter-increment: toc-h2;
}

.bctoc-wrapper--numbered .bctoc-item--h2 > .bctoc-link::before {
    content: counter(toc-h2) ". ";
    font-weight: 700;
    color: var(--bc-accent, #14e21c);
}

.bctoc-wrapper--numbered .bctoc-sublist {
    counter-reset: toc-h3;
}

.bctoc-wrapper--numbered .bctoc-item--h3 {
    counter-increment: toc-h3;
}

.bctoc-wrapper--numbered .bctoc-item--h3 > .bctoc-link::before {
    content: counter(toc-h2) "." counter(toc-h3) " ";
    font-weight: 600;
    color: #888;
}

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

@media (max-width: 1024px) {
    .bctoc-wrapper--sticky {
        position: relative;
        top: 0;
        max-height: none;
    }
}

@media (max-width: 768px) {
    .bctoc-title {
        font-size: 0.9375rem;
    }
    
    .bctoc-item--h2 > .bctoc-link {
        font-size: 0.875rem;
    }
    
    .bctoc-item--h3 > .bctoc-link {
        font-size: 0.75rem;
    }
}

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

@media print {
    .bctoc-widget {
        display: none;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.bctoc-link:focus,
.bctoc-toggle:focus,
.bctoc-collapse-toggle:focus {
    outline: 2px solid var(--bc-accent, #14e21c);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .bctoc-link,
    .bctoc-toggle-icon,
    .bctoc-collapse-icon,
    .bctoc-content,
    .bctoc-sublist {
        transition: none;
    }
}
