/* Table of Contents Block Frontend Styles */
.wp-block-crates-table-of-contents {
    margin: 0;
}

/* Common container styles */
.crates-toc__container {
    background-color: #0D1D1A; /* bg-[#0D1D1A] from React */
    border-radius: 0.5rem; /* rounded-lg */
    padding: 1rem; /* p-4 */
}

.crates-toc__title {
    font-weight: 500; /* font-medium */
    margin-bottom: 1rem; /* mb-4 */
    color: #ffffff;
    font-size: 1rem;
    margin-top: 0;
}

.crates-toc__nav {
    /* Base nav styles */
}

.crates-toc__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem; /* space-y-2 */
}

.crates-toc__item {
    margin: 0;
}

.crates-toc__item--nested {
    margin-left: 1rem; /* ml-4 from React for level 3 headings */
}

.crates-toc__link {
    color: #D1D5DB; /* text-gray-300 */
    text-decoration: none;
    font-size: 0.875rem; /* text-sm */
    display: block;
    padding: 0.25rem 0; /* py-1 */
    transition: color 0.2s ease-in-out;
    border-radius: 0.25rem;
}

.crates-toc__link:hover {
    color: #F97052; /* hover:text-[#F97052] */
    text-decoration: none;
}

.crates-toc__link--active {
    color: #F97052;
    font-weight: 500;
}

/* Desktop Version (Default - Hidden on Mobile) */
.crates-toc__desktop {
    display: none; /* Hidden by default, shown on larger screens */
}

@media (min-width: 1024px) {
    .crates-toc__desktop {
        display: block;
        position: sticky;
        top: 2rem; /* sticky top-8 from React */
        width: 16rem; /* w-64 */
        flex-shrink: 0;
        align-self: flex-start; /* Ensure sticky behavior works properly */
    }
}

/* Mobile Version (Default - Shown on Mobile) */
.crates-toc__mobile {
    display: block;
    margin-bottom: 1.5rem; /* mb-6 from React */
}

@media (min-width: 1024px) {
    .crates-toc__mobile {
        display: none; /* Hidden on desktop */
    }
}

/* Mobile Toggle Button */
.crates-toc__toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    font-weight: 500;
}

.crates-toc__toggle:hover {
    color: #D1D5DB;
}

.crates-toc__toggle:focus {
    outline: 2px solid #F97052;
    outline-offset: 2px;
    border-radius: 0.25rem;
}

.crates-toc__toggle-text {
    font-weight: 500;
}

.crates-toc__toggle-icon {
    width: 1.25rem; /* h-5 w-5 */
    height: 1.25rem;
    transition: transform 0.3s ease-in-out;
    flex-shrink: 0;
}

/* Mobile Navigation */
.crates-toc__nav--mobile {
    margin-top: 1rem; /* mt-4 */
    animation: slideDown 0.2s ease-in-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.crates-toc__link--mobile {
    /* Mobile-specific link styles if needed */
}

/* Focus states for accessibility */
.crates-toc__link:focus {
    outline: 2px solid #F97052;
    outline-offset: 2px;
    border-radius: 0.25rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .crates-toc__container {
        padding: 0.75rem;
    }

    .crates-toc__title {
        font-size: 0.875rem;
    }

    .crates-toc__link {
        font-size: 0.8125rem;
        padding: 0.1875rem 0;
    }
}

/* Layout integration styles - these will be used when TOC is in sidebar */
.article-with-toc {
    display: block;
    position: relative;
}

@media (min-width: 1024px) {
    .article-with-toc {
        display: grid;
        grid-template-columns: 16rem 1fr; /* w-64 sidebar + flexible content */
        gap: 2rem;
        align-items: start;
    }

    /* TOC positioning in grid */
    .article-with-toc .wp-block-crates-table-of-contents {
        grid-column: 1;
        grid-row: 1;
        position: sticky;
        top: 2rem; /* sticky top-8 from React */
        align-self: flex-start;
        height: fit-content;
    }

    /* Main content positioning in grid */
    .article-with-toc .article-main-content {
        grid-column: 2;
        grid-row: 1;
        max-width: 48rem; /* max-w-3xl from React */
        width: 100%;
    }

    /* Ensure proper spacing within content area */
    .article-with-toc .article-main-content .wp-block-group {
        width: 100%;
    }
}

/* Mobile-first: stack vertically */
@media (max-width: 1023px) {
    .article-with-toc .wp-block-crates-table-of-contents {
        margin-bottom: 2rem;
    }

    .article-with-toc .article-main-content {
        width: 100%;
    }
}