/**
 * BNO Core - Sidebar Layout Styles
 * 
 * Three-column layout for single posts:
 * - Left sidebar: Table of Contents
 * - Main content: Post content
 * - Right sidebar: Future features
 *
 * @package BNO_Core
 * @version 1.0.0
 */

/* ============================================================================
   Base TOC Styles
   ========================================================================= */

.bno-toc {
    background: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 2rem;
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, sans-serif;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.bno-toc-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #f5f5f5;
}

.bno-toc-title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: #1a1a1a;
    letter-spacing: -0.02em;
}

/* ============================================================================
   TOC List Styles
   ========================================================================= */

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

.bno-toc-item {
    margin: 0;
    padding: 0;
    position: relative;
}

.bno-toc-link {
    display: block;
    padding: 0.6rem 0;
    color: #333;
    text-decoration: none;
    font-size: 1.4rem;
    line-height: 1.5;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    padding-left: 1rem;
    margin-left: -1rem;
}

.bno-toc-link:hover {
    color: #cd2653;
    background-color: #f9f9f9;
    border-left-color: #cd2653;
}

.bno-toc-link:focus {
    outline: 2px solid #cd2653;
    outline-offset: 2px;
}

/* Active state */
.bno-toc-link.bno-toc-active {
    color: #cd2653;
    font-weight: 600;
    border-left-color: #cd2653;
    background-color: #fef5f8;
}

/* ============================================================================
   Nested List Styles (Hierarchy)
   ========================================================================= */

.bno-toc-sublist {
    list-style: none;
    margin: 0.3rem 0 0.3rem 0;
    padding: 0;
}

/* Level 2 (H2) - Base level */
.bno-toc-level-2 .bno-toc-link {
    font-size: 1.4rem;
    font-weight: 500;
    padding-left: 1rem;
    margin-left: -1rem;
}

/* Level 3 (H3) - First nested level */
.bno-toc-level-3 .bno-toc-link {
    font-size: 1.3rem;
    font-weight: 400;
    padding-left: 2rem;
    margin-left: 0;
    color: #555;
}

/* Level 4 (H4) - Second nested level */
.bno-toc-level-4 .bno-toc-link {
    font-size: 1.2rem;
    font-weight: 400;
    padding-left: 3rem;
    margin-left: 0;
    color: #666;
}

/* Level 5 (H5) - Third nested level */
.bno-toc-level-5 .bno-toc-link {
    font-size: 1.2rem;
    font-weight: 400;
    padding-left: 4rem;
    margin-left: 0;
    color: #777;
}

/* Level 6 (H6) - Fourth nested level */
.bno-toc-level-6 .bno-toc-link {
    font-size: 1.1rem;
    font-weight: 400;
    padding-left: 5rem;
    margin-left: 0;
    color: #888;
}

/* ============================================================================
   Mobile Inline TOC (Default - Below 1280px)
   ========================================================================= */

.bno-toc-inline-wrapper {
    display: block;
    margin: 2rem 0 3rem;
    max-width: 100%;
}

/* Hide sidebars on mobile */
.bno-left-sidebar,
.bno-right-sidebar {
    display: none;
}

/* ============================================================================
   Desktop Three-Column Layout (1280px and above)
   ========================================================================= */

@media (min-width: 1280px) {

    /* Hide inline TOC on desktop */
    .bno-toc-inline-wrapper {
        display: none;
    }

    /* Three-column grid layout */
    .bno-core-layout {
        display: grid;
        grid-template-columns: 280px 1fr 280px;
        gap: 4rem;
        max-width: 1400px;
        margin: 0 auto;
        padding: 0 2rem;
    }

    /* Left sidebar */
    .bno-left-sidebar {
        display: block;
        grid-column: 1;
    }

    /* Main content */
    .bno-main-content {
        grid-column: 2;
        min-width: 0;
        /* Prevent grid blowout */
    }

    /* Right sidebar */
    .bno-right-sidebar {
        display: block;
        grid-column: 3;
    }

    /* Sticky positioning for sidebar content */
    .bno-sidebar-sticky {
        position: -webkit-sticky;
        /* Safari */
        position: sticky;
        top: 2rem;
        /* Distance from top when sticky */
        max-height: calc(100vh - 4rem);
        /* Full viewport height minus padding */
        overflow-y: auto;
        overflow-x: hidden;
        will-change: transform;
        /* Performance optimization */
    }

    /* Scrollbar styling */
    .bno-sidebar-sticky::-webkit-scrollbar {
        width: 6px;
    }

    .bno-sidebar-sticky::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    .bno-sidebar-sticky::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 3px;
    }

    .bno-sidebar-sticky::-webkit-scrollbar-thumb:hover {
        background: #999;
    }
}

/* Wider screens - increase content width */
@media (min-width: 1600px) {
    .bno-core-layout {
        grid-template-columns: 320px 1fr 320px;
        max-width: 1600px;
        gap: 5rem;
    }
}

/* ============================================================================
   Smooth Scroll Offset for Anchors
   ========================================================================= */

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Offset for sticky header and smooth scrolling */
.entry-content h2[id],
.entry-content h3[id],
.entry-content h4[id],
.entry-content h5[id],
.entry-content h6[id] {
    scroll-margin-top: 3rem;
    /* Matches sticky top + padding */
}

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

@media print {

    .bno-left-sidebar,
    .bno-right-sidebar {
        display: none;
    }

    .bno-toc-inline-wrapper {
        display: block;
        page-break-inside: avoid;
    }

    .bno-core-layout {
        display: block;
    }
}

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

/* Focus visible for keyboard navigation */
.bno-toc-link:focus-visible {
    outline: 3px solid #cd2653;
    outline-offset: 3px;
    border-radius: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bno-toc-link {
        border-left-width: 4px;
    }

    .bno-toc-link.bno-toc-active {
        font-weight: 700;
    }
}

/* ============================================================================
   Dark Mode Support
   ========================================================================= */

@media (prefers-color-scheme: dark) {
    .bno-toc {
        background: #1a1a1a;
        color: #e0e0e0;
    }

    .bno-toc-title {
        color: #ffffff;
    }

    .bno-toc-link {
        color: #d0d0d0;
    }

    .bno-toc-link:hover {
        background-color: #2a2a2a;
        color: #ff6b9d;
    }

    .bno-toc-link.bno-toc-active {
        color: #ff6b9d;
        background-color: #2a1a1f;
    }

    .bno-toc-header {
        border-bottom-color: #333;
    }
}

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

/* Tablets in portrait */
@media (max-width: 1279px) and (min-width: 768px) {
    .bno-toc-inline-wrapper {
        max-width: 600px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* Mobile phones */
@media (max-width: 767px) {
    .bno-toc {
        padding: 1.5rem;
        border-radius: 6px;
    }

    .bno-toc-title {
        font-size: 1.4rem;
    }

    .bno-toc-link {
        font-size: 1.3rem;
        padding: 0.5rem 0;
    }

    .bno-toc-level-2 .bno-toc-link {
        font-size: 1.3rem;
    }

    .bno-toc-level-3 .bno-toc-link {
        font-size: 1.2rem;
        padding-left: 1.5rem;
    }

    .bno-toc-level-4 .bno-toc-link {
        font-size: 1.1rem;
        padding-left: 2.5rem;
    }

    .bno-toc-level-5 .bno-toc-link,
    .bno-toc-level-6 .bno-toc-link {
        font-size: 1.1rem;
        padding-left: 3.5rem;
    }
}

/* ============================================================================
   Animation for Active State Changes
   ========================================================================= */

.bno-toc-link {
    position: relative;
}

.bno-toc-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: #cd2653;
    transform: scaleY(0);
    transition: transform 0.2s ease;
    transform-origin: top;
}

.bno-toc-link.bno-toc-active::before {
    transform: scaleY(1);
}

/* ============================================================================
   Compatibility with BNO Theme
   ========================================================================= */

/* Ensure TOC works well with BNO theme's color scheme */
.bno-toc {
    font-family: "Inter var", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, sans-serif;
}

/* Match BNO theme's accent color */
.bno-toc-link:hover,
.bno-toc-link.bno-toc-active {
    color: var(--accent-color, #cd2653);
    border-left-color: var(--accent-color, #cd2653);
}

.bno-toc-link:focus-visible {
    outline-color: var(--accent-color, #cd2653);
}