/* ===== Blog Post Layout (3-column grid, TOC, mobile) ===== */

.post-layout {
    display: flex !important;
    flex-direction: column !important;
    gap: 2rem;
    max-width: 1550px;
    margin: 0 auto;
    padding: 0 1rem;
    box-sizing: border-box;
    width: 100%;
}

.post-center-column,
.post-content-main {
    min-width: 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

@media (min-width: 48rem) {
    .post-layout {
        display: grid !important;
        grid-template-columns: 1fr 300px !important;
        align-items: start;
    }

    .post-center-column {
        grid-row: 1 / span 2;
        grid-column: 1;
    }

    .post-sidebar-left {
        grid-row: 2;
        grid-column: 2;
        margin-top: 2rem;
    }

    .post-sidebar-right {
        grid-row: 1;
        grid-column: 2;
    }
}

@media (min-width: 75rem) {
    .post-layout {
        grid-template-columns: minmax(300px, 1fr) minmax(600px, 2.2fr) minmax(320px, 1.2fr) !important;
        gap: 4rem;
    }

    .post-sidebar-left {
        grid-row: 1;
        grid-column: 1;
        margin-top: 0;
    }

    .post-center-column {
        grid-row: 1;
        grid-column: 2;
    }

    .post-sidebar-right {
        grid-row: 1;
        grid-column: 3;
    }
}

/* Sticky sidebars — no overflow:hidden on ancestors */
.post-sidebar-left,
.post-sidebar-right {
    position: sticky;
    top: 2rem;
    z-index: 5;
    align-self: start;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    border-left: 1px solid transparent !important;
}

.post-sidebar-right {
    border-left: 1px solid var(--border-color) !important;
    padding-left: 1.5rem;
}

.post-sidebar-left::-webkit-scrollbar,
.post-sidebar-right::-webkit-scrollbar {
    width: 5px;
}

.post-sidebar-left::-webkit-scrollbar-track,
.post-sidebar-right::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.post-sidebar-left::-webkit-scrollbar-thumb,
.post-sidebar-right::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

html[data-theme='dark'] .post-sidebar-left::-webkit-scrollbar-track,
html[data-theme='dark'] .post-sidebar-right::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

html[data-theme='dark'] .post-sidebar-left::-webkit-scrollbar-thumb,
html[data-theme='dark'] .post-sidebar-right::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== Table of Contents ===== */
#toc-container {
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.toc-list {
    list-style: none;
    padding-left: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.toc-link {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    line-height: 1.4;
    padding: 0.25rem 0 0.25rem 0.5rem;
    border-left: 2px solid transparent;
    transition: all 0.2s ease-in-out;
    opacity: 0.8;
    word-break: break-word;
}

.toc-link:hover {
    color: var(--link-color, #0077cc);
    opacity: 1;
}

.toc-link.active {
    font-weight: 600;
    color: var(--link-color, #0077cc);
    border-left: 2px solid var(--link-color, #0077cc);
    background-color: rgba(0, 119, 204, 0.05);
    opacity: 1;
}

.toc-link-image {
    font-style: italic;
    font-size: 0.85em;
}

.toc-link i {
    margin-right: 0.4rem;
    color: gray;
}

/* ===== Mobile TOC ===== */
.mobile-toc-toggle {
    display: none;
}

.mobile-toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.mobile-toc-overlay.open {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: tocFadeIn 0.2s ease-out;
}

@keyframes tocFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes tocSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.mobile-toc-panel {
    background: var(--bg-color);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    animation: tocSlideUp 0.3s ease-out;
}

.mobile-toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.mobile-toc-title {
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-toc-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.mobile-toc-close:hover {
    background: var(--card-bg-color);
}

.mobile-toc-container {
    overflow-y: auto;
    padding: 0.75rem 1.25rem 1.5rem;
}

.mobile-toc-container .toc-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.mobile-toc-container .toc-link {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    line-height: 1.4;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border-left: 2px solid transparent;
    border-radius: 0 6px 6px 0;
    transition: all 0.15s ease;
    font-size: 0.95rem;
}

.mobile-toc-container .toc-link:hover,
.mobile-toc-container .toc-link:active {
    background: var(--card-bg-color);
    color: var(--link-color);
    border-left-color: var(--link-color);
}

/* ===== Mobile breakpoint ===== */
@media (max-width: 48rem) {
    .page-content {
        overflow-x: hidden;
    }

    .post-layout {
        max-width: 100% !important;
        width: 100% !important;
        padding: 0 1rem !important;
        min-width: 0;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .post-center-column {
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
    }

    .post-content-main {
        padding: 1rem 0 0 0 !important;
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .post-content-main pre,
    .code-block-wrapper {
        max-width: 100%;
        overflow-x: auto;
        box-sizing: border-box;
    }

    .post-content-main p > code,
    .post-content-main li > code {
        word-break: break-word;
        white-space: pre-wrap;
    }

    .post-content-main img {
        max-width: 100%;
        height: auto;
    }

    .post-sidebar-left {
        display: none !important;
    }

    .mobile-toc-toggle.has-toc {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: 5.5rem;
        right: 1.25rem;
        z-index: 50;
        width: 48px;
        height: 48px;
        border-radius: 50%;
        border: 1px solid var(--border-color);
        background: var(--card-bg-color);
        color: var(--link-color);
        font-size: 1.15rem;
        cursor: pointer;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
        transition: all 0.2s ease;
    }

    .mobile-toc-toggle.has-toc:hover,
    .mobile-toc-toggle.has-toc:active {
        border-color: var(--link-color);
        box-shadow: 0 4px 16px rgba(0, 119, 204, 0.2);
        transform: scale(1.05);
    }

    .post-navigation {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-link {
        width: 100%;
    }

    .next-link {
        text-align: left;
        justify-content: flex-start;
    }

    .post-sidebar-right {
        border-left: none !important;
        padding-left: 0 !important;
        position: static !important;
        max-height: none !important;
        overflow-y: visible !important;
    }

    .post-sidebar-right .competency-item-sidebar {
        padding: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--card-bg-color);
    }

    .post-sidebar-right .competency-title-sidebar {
        font-size: 1rem;
        margin-bottom: 0.25rem;
    }

    .post-sidebar-right .sidebar-button {
        margin-top: 0.75rem;
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .post-sidebar-right .tech-stack {
        gap: 0.35rem;
    }

    .post-sidebar-right .tech-stack .tag {
        font-size: 0.8rem;
        padding: 3px 8px;
        margin-bottom: 0;
    }

    .series-navigation-sidebar {
        padding: 1rem;
        margin-bottom: 1.5rem;
    }
}
