/* Sidebar Layout Optimization */

/* Sidebar container */
.sidebar-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Optimize sidebar height to prevent overlapping footer */
.latest-section .col-lg-4 {
    max-height: fit-content;
}

/* Ensure sidebar doesn't exceed main content height */
.latest-section .row {
    align-items: flex-start;
}

/* Compact sidebar styling */
@media (min-width: 992px) {
    .latest-section {
        min-height: auto;
    }
    
    .latest-section .col-lg-4 {
        max-height: 80vh;
        overflow-y: auto;
    }
    
    /* Compact scrollbar */
    .latest-section .col-lg-4::-webkit-scrollbar {
        width: 4px;
    }
    
    .latest-section .col-lg-4::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .latest-section .col-lg-4::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.2);
        border-radius: 2px;
    }
    
    .latest-section .col-lg-4::-webkit-scrollbar-thumb:hover {
        background: rgba(0,0,0,0.4);
    }
}

/* Desktop optimizations for sidebar */
@media (min-width: 992px) {
    .latest-section .container {
        max-width: 1200px;
    }
    
    .latest-section .col-lg-8 {
        padding-right: 2rem;
    }
    
    .latest-section .col-lg-4 {
        padding-left: 1rem;
        position: static;
        align-self: flex-start;
    }
    
    /* Latest Articles Section - Desktop image sizing */
    .latest-section .card-img-top {
        height: 180px !important;
        width: 100% !important;
        object-fit: cover !important;
        object-position: center !important;
        max-width: 100% !important;
        border-radius: 8px 8px 0 0;
    }
    
    .latest-section .card-img-wrapper {
        overflow: hidden;
        border-radius: 8px 8px 0 0;
        max-height: 180px;
    }
    
    /* Sidebar widgets spacing */
    .latest-section .col-lg-4 .card {
        margin-bottom: 1.25rem;
        transition: all 0.3s ease;
    }
    
    .latest-section .col-lg-4 .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    }
    
    .latest-section .col-lg-4 .card:last-child {
        margin-bottom: 0;
    }
    
    /* Reduce padding in sidebar cards */
    .latest-section .col-lg-4 .card-body {
        padding: 1.25rem !important;
    }
    
    /* Optimize popular posts to show fewer items */
    .latest-section .popular-posts-item {
        margin-bottom: 0.75rem;
    }
    
    .latest-section .popular-posts-item:last-child {
        margin-bottom: 0;
    }
    
    /* Popular Posts Widget image sizing for desktop */
    .latest-section .popular-posts-item img,
    .latest-section .popular-posts-item .flex-shrink-0 img,
    .latest-section .popular-posts-item img[style],
    .latest-section .popular-posts-item img.me-3,
    .latest-section .popular-posts-item img.rounded-custom {
        width: 60px !important;
        height: 45px !important;
        margin-right: 0.75rem !important;
        border-radius: 6px !important;
        object-fit: cover !important;
        max-width: 60px !important;
    }
    
    /* Optimize article grid */
    .latest-section .col-lg-8 .row {
        margin-left: -0.75rem;
        margin-right: -0.75rem;
    }
    
    .latest-section .col-lg-8 .col-md-6 {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        margin-bottom: 1.5rem;
    }
}

/* Large desktop optimizations */
@media (min-width: 1200px) {
    .latest-section .container {
        max-width: 1140px;
    }
    
    .latest-section .col-lg-8 {
        padding-right: 2.5rem;
    }
    
    .latest-section .col-lg-4 {
        padding-left: 1.5rem;
    }
    
    /* Latest Articles Section - Large desktop image sizing */
    .latest-section .card-img-top {
        height: 200px !important;
    }
    
    .latest-section .card-img-wrapper {
        max-height: 200px;
    }
}

/* Extra large desktop optimizations */
@media (min-width: 1400px) {
    .latest-section .container {
        max-width: 1320px;
    }
    
    .latest-section .col-lg-8 {
        padding-right: 3rem;
    }
    
    .latest-section .col-lg-4 {
        padding-left: 2rem;
    }
    
    /* Latest Articles Section - Extra large desktop image sizing */
    .latest-section .card-img-top {
        height: 220px !important;
    }
    
    .latest-section .card-img-wrapper {
        max-height: 220px;
    }
}

/* Newsletter widget optimization */
.latest-section .col-lg-4 .bg-primary.text-white {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%) !important;
}

.latest-section .col-lg-4 .bg-primary.text-white:hover {
    background: linear-gradient(135deg, #0056b3 0%, #004085 100%) !important;
}

/* Popular posts optimization */
.latest-section .hover-bg-light:hover {
    background-color: #f8f9fa !important;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.latest-section .hover-bg-light img {
    transition: transform 0.2s ease;
}

.latest-section .hover-bg-light:hover img {
    transform: scale(1.05);
}

/* Categories widget optimization */
.latest-section .list-group-item {
    transition: all 0.2s ease;
}

.latest-section .list-group-item:hover {
    background-color: #f8f9fa;
    padding-left: 1rem;
    border-left: 3px solid #007bff;
}

/* Mobile responsive styles for Popular Posts Widget */
@media (max-width: 768px) {
    /* Mobile Navigation - Ensure only one menu system shows */
    .mobile-menu-toggle {
        display: none !important;
    }
    
    #mobileNavigation {
        display: none !important;
    }
    
    /* Ensure main navigation works properly */
    .navbar-toggler {
        display: block !important;
    }
    
    #mainNavigation {
        display: block !important;
    }
    
    /* Latest Articles Section - Fix image size inconsistency */
    .latest-section .card-img-top {
        height: 150px !important;
        width: 100% !important;
        object-fit: cover !important;
        object-position: center !important;
        border-radius: 8px 8px 0 0;
        transition: transform 0.3s ease;
    }
    
    .latest-section .card-img-wrapper {
        overflow: hidden;
        border-radius: 8px 8px 0 0;
    }
    
    /* Popular Posts Widget container optimization */
    .popular-posts-item {
        padding: var(--mobile-padding, 0.75rem) !important;
        margin-bottom: 1rem !important;
        border-radius: 8px;
        transition: background-color 0.2s ease;
    }
    
    /* Improve touch interaction */
    .popular-posts-item:hover,
    .popular-posts-item:active {
        background-color: #f8f9fa !important;
    }
    
    /* Optimize image sizing for mobile - Override inline styles */
    .popular-posts-item img,
    .popular-posts-item .flex-shrink-0 img,
    .popular-posts-item img[style],
    .popular-posts-item img.me-3,
    .popular-posts-item img.rounded-custom {
        width: 50px !important;
        height: 38px !important;
        margin-right: 0.75rem !important;
        border-radius: 6px !important;
        object-fit: cover !important;
        max-width: 50px !important;
    }
    
    /* Typography optimization for mobile */
    .popular-posts-item h6 {
        font-size: 0.9rem !important;
        line-height: 1.3 !important;
        margin-bottom: 0.25rem !important;
        font-weight: 600;
    }
    
    .popular-posts-item h6 a {
        color: #333 !important;
        text-decoration: none;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    
    .popular-posts-item h6 a:hover,
    .popular-posts-item h6 a:active {
        color: #007bff !important;
    }
    
    /* Date styling for mobile */
    .popular-posts-item small {
        font-size: 0.75rem !important;
        color: #666 !important;
    }
    
    .popular-posts-item small i {
        font-size: 0.7rem !important;
    }
    
    /* Container spacing optimization */
    .popular-posts-item .flex-grow-1 {
        min-width: 0; /* Allow text to wrap properly */
    }
    
    /* Popular Posts Widget card optimization */
    .card-body h5 {
        font-size: 1.1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .card-body h5 i.fas {
        font-size: 1rem !important;
    }
    
    /* Final override for any stubborn inline styles */
    .popular-posts-item img[style*="width"],
    .popular-posts-item img[style*="height"] {
        width: 50px !important;
        height: 38px !important;
        max-width: 50px !important;
        min-width: 50px !important;
        min-height: 38px !important;
    }
}

/* Mobile small screens optimization */
@media (max-width: 480px) {
    /* Latest Articles Section - Smaller image size for small screens */
    .latest-section .card-img-top {
        height: 120px !important;
    }
    
    .popular-posts-item {
        padding: 0.5rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    .popular-posts-item img,
    .popular-posts-item .flex-shrink-0 img,
    .popular-posts-item img[style],
    .popular-posts-item img.me-3,
    .popular-posts-item img.rounded-custom {
        width: 45px !important;
        height: 34px !important;
        margin-right: 0.5rem !important;
        max-width: 45px !important;
    }
    
    .popular-posts-item h6 {
        font-size: 0.85rem !important;
        line-height: 1.25 !important;
    }
    
    .popular-posts-item small {
        font-size: 0.7rem !important;
    }
}

/* Mobile extra small screens optimization */
@media (max-width: 320px) {
    /* Latest Articles Section - Very small image for extra small screens */
    .latest-section .card-img-top {
        height: 100px !important;
    }
    
    .popular-posts-item {
        padding: 0.4rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .popular-posts-item img,
    .popular-posts-item .flex-shrink-0 img,
    .popular-posts-item img[style],
    .popular-posts-item img.me-3,
    .popular-posts-item img.rounded-custom {
        width: 40px !important;
        height: 30px !important;
        max-width: 40px !important;
    }
    
    .popular-posts-item h6 {
        font-size: 0.8rem !important;
    }
    
    .popular-posts-item small {
        font-size: 0.65rem !important;
    }
}
