/**
 * 无限滚动通用样式
 * 适用于：三栏布局、两栏布局、单栏布局
 * @version 2.0.0
 */

/* ============================================
   0. 层叠上下文修复（解决动态加载内容的 dropdown 被遮挡问题）
   ============================================ */

/* 内容列表容器：创建独立层叠上下文，确保所有卡片在同一层级 */
.question-list,
.answer-list,
.column-list,
[data-scroll-container] {
    isolation: isolate;
}

/* 内容卡片：统一层级 */
.question-item,
.answer-item,
.column-item,
.list-group-item {
    position: relative;
    z-index: 1;
}

/* 三点菜单 dropdown：确保显示时始终在最顶层 */
.content-actions {
    position: relative;
    z-index: 10;
}

/* dropdown-menu 显示时的高层级 */
.content-actions .dropdown-menu.show {
    z-index: 1050;
}

/* 卡片激活时提升层级（纯 CSS 方案，不抦动） */
.question-item:has(.dropdown-menu.show),
.answer-item:has(.dropdown-menu.show),
.column-item:has(.dropdown-menu.show),
.list-group-item:has(.dropdown-menu.show) {
    z-index: 100 !important;
}

/* ============================================
   1. CSS 变量定义（便于主题定制）
   ============================================ */
:root {
    --header-height: 70px;
    --sidebar-top-offset: 90px;      /* 导航栏高度 + 间距 */
    --sidebar-bottom-margin: 20px;
    --back-to-top-size: 48px;
    --back-to-top-bottom: 30px;
    --back-to-top-right: 30px;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

/* ============================================
   2. 智能 Sticky 侧边栏
   ============================================ */

/* 侧边栏包装器 - 用于定位计算 */
.sidebar-wrapper {
    position: relative;
}

/* 通用智能 Sticky 侧边栏 */
.sidebar-sticky {
    /* 默认不启用 sticky，由 JS 控制 */
    will-change: transform;
}

/* 左侧边栏 */
.sidebar-left-sticky {
    will-change: transform;
}

/* 右侧边栏 */
.sidebar-right-sticky {
    will-change: transform;
}

/* JS 控制的 sticky 状态 - 固定在顶部 */
.sidebar-sticky.sticky-top,
.sidebar-left-sticky.sticky-top,
.sidebar-right-sticky.sticky-top {
    position: sticky;
    top: var(--sidebar-top-offset);
}

/* JS 控制的 sticky 状态 - 固定在底部 */
.sidebar-sticky.sticky-bottom,
.sidebar-left-sticky.sticky-bottom,
.sidebar-right-sticky.sticky-bottom {
    position: sticky;
    /* top 值由 JS 动态计算 */
}

/* 确保没有滚动条 */
.sidebar-sticky,
.sidebar-left-sticky,
.sidebar-right-sticky {
    overflow: visible;
    scrollbar-width: none;  /* Firefox */
    -ms-overflow-style: none;  /* IE/Edge */
}

/* 隐藏 Webkit 滚动条 */
.sidebar-sticky::-webkit-scrollbar,
.sidebar-left-sticky::-webkit-scrollbar,
.sidebar-right-sticky::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* ============================================
   3. 回到顶部按钮
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: var(--back-to-top-bottom);
    right: var(--back-to-top-right);
    width: var(--back-to-top-size);
    height: var(--back-to-top-size);
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    /* 初始隐藏 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all var(--transition-normal);
}

/* 显示状态 */
.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Hover 效果 */
.back-to-top:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

/* 点击效果 */
.back-to-top:active {
    transform: translateY(0);
}

/* 箭头图标 */
.back-to-top-icon {
    font-size: 20px;
    color: #64748b;
    transition: color var(--transition-fast);
}
.back-to-top:hover .back-to-top-icon {
    color: #3b82f6;
}

/* 进度环（可选） */
.back-to-top-progress {
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 48px;
    pointer-events: none;
    overflow: hidden;
}
.back-to-top-progress circle {
    fill: none;
    stroke: #3b82f6;
    stroke-width: 2;
    stroke-dasharray: 144;
    stroke-dashoffset: 144;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 0.1s linear;
}

/* ============================================
   4. 加载指示器
   ============================================ */
.infinite-scroll-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    color: #64748b;
}

/* 加载动画（三个跳动的点） */
.loader-dots {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.loader-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3b82f6;
    animation: loader-bounce 1.4s infinite ease-in-out both;
}
.loader-dots span:nth-child(1) { animation-delay: -0.32s; }
.loader-dots span:nth-child(2) { animation-delay: -0.16s; }
.loader-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes loader-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* 加载文字 */
.loader-text {
    font-size: 14px;
    color: #94a3b8;
}

/* 加载结束状态 */
.infinite-scroll-end {
    text-align: center !important;
    padding: 40px 20px !important;
    color: #9ca3af !important;
    font-size: 14px;
    background: #f9fafb !important;
    border-radius: 8px;
    margin: 20px auto !important;
    border: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
}
/* list-group 内的结束提示 */
.list-group .infinite-scroll-end,
.list-group-flush .infinite-scroll-end {
    border-top: 1px solid #e5e7eb !important;
    border-radius: 0 !important;
    margin: 0 !important;
}
.infinite-scroll-end .end-icon {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: #e5e7eb;
    border-radius: 50%;
    margin-bottom: 12px;
}
.infinite-scroll-end .end-icon i {
    font-size: 24px;
    color: #9ca3af;
}
.infinite-scroll-end .end-text {
    font-size: 14px;
    color: #9ca3af;
}
/* 兼容旧版结构 */
.infinite-scroll-end > i {
    display: none !important;
}
.infinite-scroll-end > span {
    display: none !important;
}

/* ============================================
   5. 列表项进入动画
   ============================================ */
.scroll-item-enter {
    opacity: 0;
    transform: translateY(20px);
    animation: scroll-item-fade-in 0.3s ease forwards;
}

@keyframes scroll-item-fade-in {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 批量加载时错开动画 */
.scroll-item-enter:nth-child(1) { animation-delay: 0ms; }
.scroll-item-enter:nth-child(2) { animation-delay: 50ms; }
.scroll-item-enter:nth-child(3) { animation-delay: 100ms; }
.scroll-item-enter:nth-child(4) { animation-delay: 150ms; }
.scroll-item-enter:nth-child(5) { animation-delay: 200ms; }

/* ============================================
   6. 错误状态
   ============================================ */
.infinite-scroll-error {
    text-align: center;
    padding: 30px 20px;
    color: #ef4444;
}
.infinite-scroll-error button {
    margin-top: 10px;
}

/* ============================================
   7. 响应式适配
   ============================================ */

/* 平板及以下：取消 sticky */
@media (max-width: 991.98px) {
    .sidebar-sticky,
    .sidebar-left-sticky,
    .sidebar-right-sticky {
        position: relative;
        top: 0;
        max-height: none;
        overflow: visible;
    }
    
    /* 回到顶部按钮位置调整 */
    .back-to-top {
        --back-to-top-bottom: 20px;
        --back-to-top-right: 20px;
        --back-to-top-size: 44px;
    }
}

/* 手机端 */
@media (max-width: 575.98px) {
    .back-to-top {
        --back-to-top-bottom: 16px;
        --back-to-top-right: 16px;
        --back-to-top-size: 40px;
    }
    
    .infinite-scroll-loader,
    .infinite-scroll-end {
        padding: 20px 15px;
    }
}

/* ============================================
   8. 深色模式支持（可选）
   ============================================ */
@media (prefers-color-scheme: dark) {
    .back-to-top {
        background: #1e293b;
        border-color: #334155;
    }
    .back-to-top:hover {
        background: #334155;
    }
    .back-to-top-icon {
        color: #94a3b8;
    }
}
