/**
 * Sticky Sidebar Styles
 * Makes sidebar sticky while scrolling - CSS Only Solution
 */

/* Universal sticky sidebar - works with any sidebar */
.hsj-blog-sidebar.top-sticky,
.tour-sidebar,
.sticky-sidebar,
aside.sidebar,
.sidebar-wrapper,
[class*="sidebar"][class*="sticky"],
.col-md-4 .sidebar,
.col-lg-4 .sidebar {
    position: sticky !important;
    top: 10px;
    align-self: flex-start !important;
    transition: all 0.3s ease;
    z-index: 100;
}

/* Alternative selectors for common sidebar patterns */
.row .col-md-4:has(.widget),
.row .col-lg-4:has(.widget),
.row .col-md-3:has(.widget),
.row .col-lg-3:has(.widget) {
    position: sticky;
    top: 100px;
    align-self: flex-start;
}

/* Make sure parent row uses flexbox */
.row:has([class*="sidebar"]),
.row:has(.widget) {
    display: flex;
    flex-wrap: wrap;
}

/* Sticky state */
.hsj-blog-sidebar.is-sticky,
.tour-sidebar.is-sticky,
.sticky-sidebar.is-sticky {
    position: fixed !important;
    animation: slideDown 0.3s ease;
}

/* Bottom state */
.hsj-blog-sidebar.is-bottom,
.tour-sidebar.is-bottom,
.sticky-sidebar.is-bottom {
    position: absolute !important;
}

/* Slide down animation */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar container positioning */
.sidebar-container {
    position: relative;
}

/* Ensure parent has relative positioning */
.row:has(.hsj-blog-sidebar.top-sticky),
.row:has(.tour-sidebar),
.row:has(.sticky-sidebar) {
    position: relative;
}

/* Sidebar content styling */
.hsj-blog-sidebar .widget,
.tour-sidebar .widget,
.sticky-sidebar .widget {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s ease;
}

.hsj-blog-sidebar.is-sticky .widget,
.tour-sidebar.is-sticky .widget,
.sticky-sidebar.is-sticky .widget {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Widget titles */
.hsj-blog-sidebar .widget-title,
.tour-sidebar .widget-title,
.sticky-sidebar .widget-title {
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e5e7eb;
}

/* Widget lists */
.hsj-blog-sidebar .widget ul,
.tour-sidebar .widget ul,
.sticky-sidebar .widget ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.hsj-blog-sidebar .widget li,
.tour-sidebar .widget li,
.sticky-sidebar .widget li {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}

.hsj-blog-sidebar .widget li:last-child,
.tour-sidebar .widget li:last-child,
.sticky-sidebar .widget li:last-child {
    border-bottom: none;
}

.hsj-blog-sidebar .widget a,
.tour-sidebar .widget a,
.sticky-sidebar .widget a {
    color: #4b5563;
    text-decoration: none;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.hsj-blog-sidebar .widget a:hover,
.tour-sidebar .widget a:hover,
.sticky-sidebar .widget a:hover {
    color: #2563eb;
}

/* Search widget */
.hsj-blog-sidebar .widget-search,
.tour-sidebar .widget-search,
.sticky-sidebar .widget-search {
    position: relative;
}

.hsj-blog-sidebar .widget-search input,
.tour-sidebar .widget-search input,
.sticky-sidebar .widget-search input {
    width: 100%;
    padding: 10px 40px 10px 15px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.hsj-blog-sidebar .widget-search input:focus,
.tour-sidebar .widget-search input:focus,
.sticky-sidebar .widget-search input:focus {
    outline: none;
    border-color: #2563eb;
}

.hsj-blog-sidebar .widget-search button,
.tour-sidebar .widget-search button,
.sticky-sidebar .widget-search button {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: #2563eb;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.hsj-blog-sidebar .widget-search button:hover,
.tour-sidebar .widget-search button:hover,
.sticky-sidebar .widget-search button:hover {
    background: #1d4ed8;
}

/* Categories widget */
.hsj-blog-sidebar .widget-categories .category-item,
.tour-sidebar .widget-categories .category-item,
.sticky-sidebar .widget-categories .category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hsj-blog-sidebar .widget-categories .category-count,
.tour-sidebar .widget-categories .category-count,
.sticky-sidebar .widget-categories .category-count {
    background: #f3f4f6;
    color: #6b7280;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

/* Tags widget */
.hsj-blog-sidebar .widget-tags,
.tour-sidebar .widget-tags,
.sticky-sidebar .widget-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hsj-blog-sidebar .widget-tags a,
.tour-sidebar .widget-tags a,
.sticky-sidebar .widget-tags a {
    background: #f3f4f6;
    color: #4b5563;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.hsj-blog-sidebar .widget-tags a:hover,
.tour-sidebar .widget-tags a:hover,
.sticky-sidebar .widget-tags a:hover {
    background: #2563eb;
    color: white;
}

/* Recent posts widget */
.hsj-blog-sidebar .widget-recent-posts .post-item,
.tour-sidebar .widget-recent-posts .post-item,
.sticky-sidebar .widget-recent-posts .post-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
}

.hsj-blog-sidebar .widget-recent-posts .post-thumbnail,
.tour-sidebar .widget-recent-posts .post-thumbnail,
.sticky-sidebar .widget-recent-posts .post-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.hsj-blog-sidebar .widget-recent-posts .post-thumbnail img,
.tour-sidebar .widget-recent-posts .post-thumbnail img,
.sticky-sidebar .widget-recent-posts .post-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hsj-blog-sidebar .widget-recent-posts .post-content,
.tour-sidebar .widget-recent-posts .post-content,
.sticky-sidebar .widget-recent-posts .post-content {
    flex: 1;
}

.hsj-blog-sidebar .widget-recent-posts .post-title,
.tour-sidebar .widget-recent-posts .post-title,
.sticky-sidebar .widget-recent-posts .post-title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    line-height: 1.4;
}

.hsj-blog-sidebar .widget-recent-posts .post-date,
.tour-sidebar .widget-recent-posts .post-date,
.sticky-sidebar .widget-recent-posts .post-date {
    font-size: 12px;
    color: #9ca3af;
}

/* Mobile responsive */
@media (max-width: 991px) {
    .hsj-blog-sidebar.top-sticky,
    .tour-sidebar,
    .sticky-sidebar {
        position: static !important;
        width: 100% !important;
        margin-top: 40px;
    }
    
    .hsj-blog-sidebar.is-sticky,
    .tour-sidebar.is-sticky,
    .sticky-sidebar.is-sticky {
        position: static !important;
        top: auto !important;
        width: 100% !important;
    }
}

/* Smooth scroll behavior */
html {
    scroll-behavior: smooth;
}

/* Prevent layout shift */
.sidebar-wrapper {
    min-height: 100px;
}

/* Loading state */
.hsj-blog-sidebar.loading,
.tour-sidebar.loading,
.sticky-sidebar.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Sticky indicator (optional, for debugging) */
.hsj-blog-sidebar.is-sticky::before, 
.sticky-sidebar.is-sticky::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--hsj-theme-primary), var(--hsj-theme-secondary));
    border-radius: 3px 3px 0 0;
    opacity: 0;
    animation: fadeIn 0.3s ease 0.2s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}
