/* Blog Navigation Sidebar Styles */
.blog-sidebar {
    position: fixed;
    top: 300px; /* Default position when header is expanded */
    right: 15px;
    width: 250px;
    max-width: calc(20vw - 20px); /* More conservative width to prevent overlap */
    max-height: calc(100vh - 320px);
    background: var(--container-bg, white);
    border: 1px solid var(--container-shadow, rgba(0, 0, 0, 0.1));
    border-radius: var(--border-radius, 8px);
    box-shadow: var(--shadow-intensity, 0 2px 5px rgba(0, 0, 0, 0.1));
    z-index: 999;
    overflow-y: auto;
    font-family: Arial, sans-serif;
    transition: top 0.3s ease, max-height 0.3s ease;
}

/* When header is scrolled (collapsed), move sidebar up - DESKTOP ONLY */
@media (min-width: 1025px) {
    .blog-sidebar.header-scrolled {
        top: 80px;
        max-height: calc(100vh - 100px);
    }
}

.sidebar-header {
    padding: 15px 20px 10px;
    border-bottom: 1px solid var(--container-shadow, rgba(0, 0, 0, 0.1));
    background: var(--primary-bg, #BAD5EC);
}

.sidebar-header h3 {
    margin: 0;
    color: var(--primary-text, #23570B);
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-nav-list {
    list-style: none;
    margin: 0;
    padding: 10px 0;
    max-height: 400px;
    overflow-y: auto;
}

.sidebar-nav-item {
    margin: 0;
    border-bottom: 1px solid #f0f0f0;
}

.sidebar-nav-item:last-child {
    border-bottom: none;
}

.sidebar-nav-link {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: var(--primary-text, #23570B);
    font-size: 0.85rem;
    line-height: 1.2;
    transition: background-color 0.2s ease, color 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav-link .post-title {
    font-weight: 600;
    display: block;
    margin-bottom: 3px;
    font-size: 0.9rem;
}

.sidebar-nav-link .post-location {
    font-size: 0.75rem;
    color: var(--subheading-text, #91b6c7);
    display: block;
    margin-bottom: 2px;
    font-style: italic;
}

.sidebar-nav-link:hover {
    background-color: var(--primary-bg, #BAD5EC);
    color: var(--heading-text, #ac5b20);
    border-left-color: var(--heading-text, #ac5b20);
}

.sidebar-nav-link.active {
    background-color: var(--heading-text, #ac5b20);
    color: white;
    border-left-color: var(--footer-bg, #367C28);
    font-weight: 600;
}

/* Mobile toggle button */
.sidebar-toggle {
    position: fixed;
    top: 310px; /* Default position when header is expanded */
    right: 20px;
    width: 50px;
    height: 50px;
    background: var(--footer-bg, #367C28);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1001;
    box-shadow: var(--shadow-intensity, 0 2px 5px rgba(0, 0, 0, 0.1));
    transition: background-color 0.3s ease, transform 0.3s ease, top 0.3s ease;
    display: none;
}

/* SVG icon styling */
.sidebar-toggle svg,
.back-to-top-button svg {
    display: block;
    margin: auto;
    pointer-events: none;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Ensure buttons display properly */
.sidebar-toggle,
.back-to-top-button {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile display fix */
@media (max-width: 1024px) {
    .sidebar-toggle {
        display: flex !important;
    }

    .sidebar-nav-list {
        max-height: 100%;
        overflow-y: auto;
    }
}

/* Desktop - hide toggle button and ensure sidebar is always visible */
@media (min-width: 1025px) {
    .sidebar-toggle {
        display: none !important;
    }
    
    .blog-sidebar {
        right: 15px; /* Always visible on desktop */
    }
    
    .sidebar-overlay {
        display: none !important; /* No overlay needed on desktop */
    }
}

/* When header is scrolled (collapsed), move toggle button up */
.sidebar-toggle.header-scrolled {
    top: 90px;
}

.sidebar-toggle:hover {
    background: var(--heading-text, #ac5b20);
    transform: scale(1.1);
}

.sidebar-toggle.toggle-active {
    background: var(--heading-text, #ac5b20);
}

/* Back to Top Button */
.back-to-top-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: var(--footer-bg, #367C28);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow-intensity, 0 2px 5px rgba(0, 0, 0, 0.1));
    transition: background-color 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
    opacity: 0.8;
}

.back-to-top-button:hover {
    background: var(--heading-text, #ac5b20);
    transform: scale(1.1);
    opacity: 1;
}

.back-to-top-button:active {
    transform: scale(0.95);
}

/* Responsive Design */
@media (max-width: 1400px) {
    .blog-sidebar {
        width: 220px;
        max-width: calc(18vw - 15px);
    }
}

@media (max-width: 1200px) {
    .blog-sidebar {
        width: 200px;
        max-width: calc(16vw - 15px);
    }
    
    .sidebar-nav-link {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .sidebar-nav-link .post-title {
        font-size: 0.85rem;
    }
    
    .sidebar-nav-link .post-location {
        font-size: 0.7rem;
    }
}

@media (max-width: 1024px) {
    .blog-sidebar {
        position: fixed;
        top: 0;
        right: -280px; /* Hidden by default */
        width: 280px;
        height: 100vh;
        max-height: none;
        max-width: none;
        transition: right 0.3s ease;
        z-index: 1002;
        border-radius: 0;
    }

    .blog-sidebar.sidebar-open {
        right: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-header {
        padding-top: 80px; /* Account for mobile header */
    }

    .back-to-top-button {
        bottom: 80px; /* Move higher to avoid sidebar toggle */
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
    
    /* Reset font sizes for mobile */
    .sidebar-nav-link {
        padding: 10px 15px;
        font-size: 0.85rem;
    }
    
    .sidebar-nav-link .post-title {
        font-size: 0.9rem;
    }
    
    .sidebar-nav-link .post-location {
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .blog-sidebar {
        width: 100vw;
        right: -100vw;
    }

    .blog-sidebar.sidebar-open {
        right: 0;
    }

    .sidebar-nav-link {
        padding: 15px 20px;
        font-size: 1rem;
    }
}

/* Large screens - adjust sidebar position */
@media (min-width: 1400px) {
    /*.blog-sidebar {
        right: calc((100vw - 1200px) / 2 - 320px);
    }*/
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1199px) {
    .blog-sidebar {
        width: 280px;
        right: 15px;
    }
}

/* Custom scrollbar for sidebar */
.sidebar-nav-list::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar-nav-list::-webkit-scrollbar-thumb {
    background: var(--subheading-text, #91b6c7);
    border-radius: 3px;
}

.sidebar-nav-list::-webkit-scrollbar-thumb:hover {
    background: var(--heading-text, #ac5b20);
}

/* Accessibility improvements */
.sidebar-nav-link:focus,
.sidebar-toggle:focus,
.back-to-top-button:focus {
    outline: 2px solid var(--footer-bg, #367C28);
    outline-offset: 2px;
}

/* Animation for sidebar entry */
@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.blog-sidebar {
    animation: slideInFromRight 0.3s ease-out;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    display: none;
}

.sidebar-overlay.overlay-active {
    display: block;
}

/* Specific handling for tablet/medium screens */
@media (min-width: 768px) and (max-width: 1024px) {
    .blog-sidebar {
        position: fixed;
        top: 0;
        right: -280px; /* Hidden by default - same as mobile */
        width: 280px;
        height: 100vh;
        max-height: none;
        max-width: none;
        transition: right 0.3s ease;
        z-index: 1002;
        border-radius: 0;
    }
    
    .blog-sidebar.sidebar-open {
        right: 0;
    }
    
    .sidebar-toggle {
        display: block; /* Show toggle button */
    }
    
    .sidebar-header {
        padding-top: 80px; /* Account for header */
    }
}

/* Better positioning for very large screens */
@media (min-width: 1400px) {
    /*.blog-sidebar {
        right: calc((100vw - 1200px) / 2 - 270px);
    }*/
}

/* Hide sidebar completely on very small screens initially */
@media (max-width: 480px) {
    .sidebar-toggle {
        right: 15px;
        width: 45px;
        height: 45px;
    }
}