/**
 * Table of Contents (TOC) Stylesheet for Squaretype Theme
 * Integrates with the theme's custom properties and dark mode.
 */

/* ==========================================================================
   Common TOC Styles
   ========================================================================== */
.post-toc-link {
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

/* ==========================================================================
   Inline Collapsible TOC Styles (Tablet / Mobile)
   ========================================================================== */
.post-toc-inline {
    background-color: var(--cs-color-contrast-100);
    border: 1px solid var(--cs-color-contrast-200);
    border-radius: 8px;
    padding: 20px;
    margin: 32px 0;
    max-width: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    transition: border-color 0.2s ease;
}

[data-scheme="dark"] .post-toc-inline {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.post-toc-inline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.post-toc-inline-title {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--cs-color-contrast-500);
}

.post-toc-inline-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--cs-color-contrast-200);
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--cs-color-contrast-700);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.post-toc-inline-toggle:hover {
    background-color: var(--cs-color-contrast-300);
    color: var(--cs-color-contrast-900);
}

.post-toc-inline-toggle-icon {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

.post-toc-inline-nav {
    margin-top: 16px;
    max-height: none;
    opacity: 1;
    overflow: visible;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.post-toc-inline-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.post-toc-inline-item {
    margin-bottom: 10px;
    line-height: 1.4;
}

.post-toc-inline-item:last-child {
    margin-bottom: 0;
}

.post-toc-inline-item a {
    color: var(--cs-color-contrast-700);
    font-size: 0.9375rem;
}

.post-toc-inline-item a:hover,
.post-toc-inline-item a.active {
    color: var(--cs-color-primary);
    text-decoration: underline;
}

.post-toc-inline-item-h3 {
    padding-left: 20px;
}

.post-toc-inline-item-h3 a {
    font-size: 0.875rem;
    color: var(--cs-color-contrast-600);
}

/* ==========================================================================
   Centering Layout Styles
   ========================================================================== */

/* 1. Center post content when sidebar is disabled */
.sidebar-disabled .entry-content-wrap,
.post-sidebar-disabled .entry-content-wrap {
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.sidebar-disabled .entry-container,
.post-sidebar-disabled .entry-container {
    justify-content: center;
}

/* 2. Three-column balance layout when sidebar is enabled (Wide Viewports) */
@media (min-width: 1440px) {
    /* Increase maximum container width to fit TOC (220px) + Content (720px) + Sidebar (340px) */
    .single:not(.sidebar-disabled) .cs-container,
    .single:not(.post-sidebar-disabled) .cs-container {
        max-width: 1360px;
    }
    
    /* Right-align content area inside the primary block, leaving 300px left space for TOC */
    .single:not(.sidebar-disabled) .entry-content-wrap,
    .single:not(.post-sidebar-disabled) .entry-content-wrap {
        margin-left: auto;
        margin-right: 0;
        max-width: 720px;
        position: relative;
    }
    
    /* Also right-align the post header to align with the post text vertically */
    .single:not(.sidebar-disabled) .entry-header-standard .entry-header-inner,
    .single:not(.post-sidebar-disabled) .entry-header-standard .entry-header-inner {
        margin-left: auto;
        margin-right: 0;
        max-width: 720px;
    }
}

/* ==========================================================================
   Sticky Left Side TOC Styles (Desktop / Wide Screen)
   ========================================================================== */
.post-toc-sticky {
    display: none; /* Hidden on mobile/tablets by default */
}

@media (min-width: 1200px) {
    /* Show sticky TOC on sidebar-disabled pages above 1200px */
    .sidebar-disabled .post-toc-sticky,
    .post-sidebar-disabled .post-toc-sticky {
        display: block;
        position: absolute;
        top: 0;
        right: 100%;
        margin-right: 48px;
        margin-top: -80px; /* Shift up slightly to align with the single post title */
        width: 220px;
        height: calc(100% + 80px);
        z-index: 10;
    }
    
    .sidebar-disabled .post-toc-inline,
    .post-sidebar-disabled .post-toc-inline {
        display: none !important;
    }
}

@media (min-width: 1440px) {
    /* Show sticky TOC on ALL layouts (including right sidebar pages) above 1440px */
    .post-toc-sticky {
        display: block;
        position: absolute;
        top: 0;
        right: 100%;
        margin-right: 48px;
        margin-top: -80px; /* Shift up slightly to align with the single post title */
        width: 220px;
        height: calc(100% + 80px);
        z-index: 10;
    }
    
    .post-toc-inline {
        display: none !important;
    }
}

.post-toc-inner {
    position: -webkit-sticky;
    position: sticky;
    top: 120px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    padding-bottom: 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--cs-color-contrast-200) transparent;
}

/* Custom Scrollbar for Sticky TOC */
.post-toc-inner::-webkit-scrollbar {
    width: 4px;
}

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

.post-toc-inner::-webkit-scrollbar-thumb {
    background-color: var(--cs-color-contrast-200);
    border-radius: 10px;
}

.post-toc-inner::-webkit-scrollbar-thumb:hover {
    background-color: var(--cs-color-contrast-300);
}

.post-toc-header {
    margin-bottom: 16px;
    padding-bottom: 8px;
}

.post-toc-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--cs-color-contrast-500);
}

/* Continuous timeline style indicator line */
.post-toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border-left: 2px solid var(--cs-color-contrast-200);
}

.post-toc-item {
    margin: 0;
    line-height: 1.4;
}

.post-toc-item a {
    display: block;
    padding: 6px 0 6px 16px;
    font-size: 0.8125rem;
    color: var(--cs-color-contrast-600);
    border-left: 2px solid transparent;
    margin-left: -2px; /* Shift left to overlay the continuous border-left */
    border-bottom: none;
}

.post-toc-item a:hover {
    color: var(--cs-color-contrast-800);
}

.post-toc-item a.active {
    color: var(--cs-color-primary);
    font-weight: 600;
    border-left-color: var(--cs-color-primary);
}

.post-toc-item-h1 a {
    font-weight: 600;
}

.post-toc-item-h3 a {
    padding-left: 28px;
    font-size: 0.75rem;
}
