/* ==========================================================================
   用户列表区域
   ========================================================================== */
/**
 * 微信风格用户列表样式
 * @selector #middle - 中间用户列表区域
 * @selector .user-list-header - 用户列表头部
 * @selector .header-content - 头部内容容器
 * @selector .header-actions - 头部操作按钮容器
 * @selector .add-friend-btn - 添加好友按钮
 * @selector .user-search - 用户搜索区域
 * @selector .user-sections - 用户分组容器
 * @selector .user-section - 单个用户分组
 * @selector .section-header - 分组头部
 * @selector .section-content - 分组内容区域
 */

#middle {
    width: 260px;
    background: var(--bg-white);
    height: 100vh;
    border-right: 1px solid var(--border-color);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.user-list-header {
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-white);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.add-friend-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
    font-size: 20px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-gray);
}

.add-friend-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    transform: scale(1.1);
}

.add-friend-btn:active {
    transform: scale(0.95);
}

/* 搜索框优化 */
.user-search {
    padding: 8px 16px;
    background: var(--bg-white);
    flex-shrink: 0;
    height: 48px; /* 固定高度，便于计算 */
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

.user-search input {
    width: 100%;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 12px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    background: var(--bg-gray);
    color: var(--text-primary);
}

.user-search input:focus {
    background: white;
    box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.2);
}

.user-search input::placeholder {
    color: var(--text-secondary);
}

/* 用户分组区域 - 优化滚动条显示 */
.user-sections {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-white);
    /* 确保滚动区域正确计算 */
    height: calc(100vh - 104px); /* 56px(header) + 48px(search) = 104px */
    min-height: 0; /* 重要：允许flex子项收缩 */
    width: 100%;
    max-width: 260px;
    box-sizing: border-box;
    position: relative;
    /* 移除内边距，避免错位 */
    padding-right: 0;
}

/* 自定义滚动条 - 微信风格，减少布局影响 */
.user-sections::-webkit-scrollbar {
    width: 6px;
    background: transparent;
}

.user-sections::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
    margin: 0;
}

.user-sections::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    border: none;
    min-height: 10px;
}

.user-sections::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.user-sections::-webkit-scrollbar-thumb:active {
    background: rgba(0, 0, 0, 0.4);
}

/* Firefox滚动条样式 */
.user-sections {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* 确保滚动区域始终显示滚动条轨道 */
.user-sections:hover {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}

/* 添加滚动时显示滚动条的效果 */
.user-sections.scrolling::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.4);
}

/* 确保内容不足时也能滚动 */
.section-content {
    min-height: 0; /* 修复：设置为0，避免折叠时的布局问题 */
}

/* 确保分组内容在折叠状态下完全隐藏 */
.user-section:not(.active) .section-content {
    visibility: hidden;
    opacity: 0;
}

.user-section.active .section-content {
    visibility: visible;
    opacity: 1;
}

.user-section {
    border-bottom: 1px solid #f7f7f7;
    width: 100%;
    max-width: 260px;
    box-sizing: border-box;
}

.user-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
    background: #fafafa;
    position: relative;
}

.section-header:hover {
    background: var(--bg-hover);
}

.section-header:active {
    background: #f0f0f0;
    transform: scale(0.98);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.section-arrow {
    font-size: 10px;
    color: var(--text-light);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-block;
    transform-origin: center;
}

.user-section.active .section-arrow {
    transform: rotate(180deg);
}

.user-section.active .section-header {
    background: #f5f5f5;
}

.section-content {
    padding: 0;
    background: var(--bg-white);
    max-height: 500px; /* 增加最大高度以容纳更多用户 */
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    width: 100%;
    max-width: 260px;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

.user-section:not(.active) .section-content {
    max-height: 0;
    padding: 0;
}

/* ==========================================================================
   用户列表项
   ========================================================================== */
/**
 * 微信风格用户列表项样式
 * @selector .u_container - 用户容器
 * @selector .status-indicator - 在线状态指示器
 * @selector .user-avatar - 用户头像
 * @selector .u_info - 用户信息容器
 * @selector .u_name - 用户名样式
 * @selector .u_location - 用户位置信息
 * @selector .unread-count - 未读消息计数
 * @selector .voice-call-btn - 语音通话按钮
 * @selector .empty-list-tip - 空列表提示
 */

.u_container {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    margin: 0;
    border-radius: 0;
    /* 确保用户项不会被截断 */
    min-height: 60px;
    /* 修复布局错位 */
    box-sizing: border-box;
    width: 100%;
    max-width: 260px;
}

.u_container:hover {
    background: #f7f7f7;
}

.u_container.selected {
    background: #ececec;
}

.u_container.selected:hover {
    background: #ececec;
}

/* 在线状态指示器 */
.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    box-shadow: 0 0 0 2px white;
}

.u_container.online .status-indicator {
    background: var(--primary-color);
}

/* 用户头像 */
.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    margin-right: 12px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-gray);
    /* 修复布局稳定性 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
}

.u_info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    /* 修复文本溢出和布局稳定性 */
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-word;
}

.u_name {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.u_location {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* 未读消息强调 */
.u_container.new_msg .u_name {
    font-weight: 600;
    color: var(--text-primary);
}

/* 有未读消息的用户容器 */
.u_container.has-unread {
    background-color: rgba(244, 53, 48, 0.05);
    border-left: 3px solid #f43530;
}

/* 未读数徽章 */
.unread-count {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #f43530;
    color: white;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 24px;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(244, 53, 48, 0.3);
}

/* 语音通话按钮 */
.voice-call-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    font-size: 16px;
    color: var(--primary-color);
    flex-shrink: 0;
    margin-left: 8px;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.u_container:hover .voice-call-btn {
    opacity: 1;
    transform: scale(1);
}

.voice-call-btn:hover {
    background: var(--primary-light);
    transform: scale(1.1) !important;
}

.voice-call-btn:active {
    transform: scale(0.9) !important;
}

/* 空列表提示 */
.empty-list-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 180px;        /* 保证有足够高度 */
    padding: 24px 12px;
    color: var(--text-secondary); /* 文本颜色 */
    box-sizing: border-box;
    text-align: center;
    overflow: visible;        /* 避免被父容器裁切 */
    user-select: none;
    pointer-events: none;
    position: relative;
    z-index: 1;
    max-width: 200px;
    margin: 0 auto;
}

.empty-list-tip i {
    /* 用 emoji 专用字体回退，保证彩色表情或形状一致 */
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
    font-style: normal; /* 避免被设置成 italic */
    display: block;
    font-size: 52px;       /* 图标大小，可按需调整 */
    line-height: 1;
    color: #bfbfbf;        /* 图标灰色 */
    margin-bottom: 12px;
}

.empty-list-tip > div {
    font-size: 13px;
    color: var(--text-light);
    opacity: 0.95;
    letter-spacing: 0.2px;
}

/* 用户状态相关样式 */
.u_container.hidden {
    display: none;
}

.u_container.blocked {
    opacity: 0.5;
    pointer-events: none;
}

/* 修复用户列表项的层级问题 */
.u_container {
    z-index: 2;
}

/* 确保用户列表项在分组中的正确显示 */
.section-content .u_container {
    width: 100%;
    max-width: 100%;
}

/* 修复滚动时的显示问题 */
.user-sections {
    -webkit-overflow-scrolling: touch;
}

/* 移动端用户列表面板 */
#user-list-panel {
    display: none;
}

/* 移动端适配 */
@media (max-width: 768px) {
    /* 在移动端显示用户列表面板 */
    #user-list-panel {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 80vw;
        height: 100vh;
        background: white;
        z-index: 1000;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        flex-direction: column;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        overflow: hidden;
    }
    
    #user-list-panel.show {
        transform: translateX(0);
    }
    
    /* 用户列表面板头部 */
    .user-list-panel-header {
        height: 50px;
        display: flex;
        align-items: center;
        padding: 0 15px;
        padding-left: calc(15px + env(safe-area-inset-left));
        padding-right: calc(15px + env(safe-area-inset-right));
        border-bottom: 1px solid #e0e0e0;
        background: white;
        flex-shrink: 0;
    }
    
    .user-list-panel-title {
        font-size: 16px;
        font-weight: 500;
        color: #333;
        flex: 1;
        text-align: center;
    }
    
    .close-user-list-btn {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border-radius: 50%;
        transition: background 0.2s;
        position: relative;
        min-width: 44px;
        min-height: 44px;
    }
    
    .close-user-list-btn:hover {
        background: #f0f0f0;
    }
    
    .close-user-list-btn::before,
    .close-user-list-btn::after {
        content: "";
        display: block;
        width: 14px;
        height: 2px;
        background: #666;
        position: absolute;
    }
    
    .close-user-list-btn::before {
        transform: rotate(45deg);
    }
    
    .close-user-list-btn::after {
        transform: rotate(-45deg);
    }
    
    /* 遮罩层 */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
    }
    
    .overlay.show {
        display: block;
    }
    
    /* 用户列表面板内容区域 */
    .user-list-content {
        flex: 1;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        max-height: calc(100vh - 50px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }
    
    #user-list-panel .user-search {
        padding: 10px 15px;
        border-bottom: 1px solid #e0e0e0;
        background: white;
        flex-shrink: 0;
    }
    
    #user-list-panel .user-search input {
        width: 100%;
        height: 30px;
        border: 1px solid #e0e0e0;
        border-radius: 4px;
        padding: 0 10px;
        font-size: 14px;
        outline: none;
        transition: border 0.2s;
        background: #f5f5f5;
    }
    
    #user-list-panel .user-search input:focus {
        background: white;
        border-color: #07c160;
        box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.2);
    }
    
    #user-list-panel .user-sections {
        flex: 1;
        overflow-y: auto;
        background: white;
        padding-bottom: 20px;
        height: calc(100vh - 130px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
        position: relative;
        scrollbar-width: none;
        -ms-overflow-style: none;
        z-index: 1;
        width: 100%;
        max-width: 80vw;
        box-sizing: border-box;
    }
    
    #user-list-panel .user-sections::-webkit-scrollbar {
        display: none;
    }
    
    #user-list-panel .user-section {
        border-bottom: 1px solid #f0f0f0;
        width: 100%;
        max-width: 80vw;
        box-sizing: border-box;
    }
    
    #user-list-panel .user-section:last-child {
        border-bottom: none;
    }
    
    #user-list-panel .section-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 15px;
        cursor: pointer;
        transition: background 0.2s;
        user-select: none;
        position: relative;
    }
    
    #user-list-panel .section-header:hover {
        background: #f5f5f5;
    }
    
    #user-list-panel .section-header:active {
        background: #eeeeee;
        transform: scale(0.98);
    }
    
    #user-list-panel .section-title {
        font-size: 14px;
        font-weight: 500;
        color: #333;
    }
    
    #user-list-panel .section-arrow {
        font-size: 12px;
        color: #999;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: inline-block;
        transform-origin: center;
    }
    
    #user-list-panel .user-section.active .section-arrow {
        transform: rotate(180deg);
    }
    
    #user-list-panel .section-content {
        padding: 0 15px;
        background: white;
        padding-bottom: 10px;
        max-height: 500px; /* 增加最大高度 */
        overflow: hidden;
        transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
        width: 100%;
        max-width: 80vw;
        box-sizing: border-box;
        position: relative;
        z-index: 1;
    }
    
    #user-list-panel .user-section:not(.active) .section-content {
        max-height: 0;
        padding: 0 15px;
    }
    
    #user-list-panel .u_container {
        padding: 12px 0;
        min-height: 50px;
        width: 100%;
        max-width: 80vw;
        box-sizing: border-box;
    }
    
    #user-list-panel .u_container:hover {
        background: #f7f7f7;
    }
    
    #user-list-panel .u_container.selected {
        background: #ececec;
    }
    
    #user-list-panel .u_container.online .status-indicator {
        background: var(--primary-color);
    }
    
    #user-list-panel .status-indicator {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #ccc;
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        box-shadow: 0 0 0 2px white;
    }
    
    #user-list-panel .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 6px;
        margin-right: 12px;
        object-fit: cover;
        flex-shrink: 0;
        background: var(--bg-gray);
    }
    
    #user-list-panel .u_container:hover .user-avatar {
        transform: scale(1.05);
    }
    
    #user-list-panel .u_info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 2px;
        overflow: hidden;
    }
    
    #user-list-panel .u_name {
        font-size: 15px;
        color: #333;
        font-weight: 400;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.3;
    }
    
    #user-list-panel .u_location {
        font-size: 12px;
        color: #999;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.3;
    }
    
    #user-list-panel .u_container.new_msg .u_name {
        font-weight: 600;
        color: #333;
    }
    
    #user-list-panel .unread-count {
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: #f43530;
        color: white;
        font-size: 11px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        margin-left: auto;
        margin-right: 20px;
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(244, 53, 48, 0.3);
    }
    
    #user-list-panel .voice-call-btn {
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border-radius: 50%;
        font-size: 16px;
        color: var(--primary-color);
        flex-shrink: 0;
        margin-left: 8px;
        opacity: 0;
        transform: scale(0.8);
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    #user-list-panel .u_container:hover .voice-call-btn {
        opacity: 1;
        transform: scale(1);
    }
    
    #user-list-panel .empty-list-tip {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 120px;
        padding: 20px;
        color: #999;
        box-sizing: border-box;
        text-align: center;
        overflow: visible;
        user-select: none;
        pointer-events: none;
        position: relative;
        z-index: 1;
        max-width: 200px;
        margin: 0 auto;
    }
    
    #user-list-panel .empty-list-tip i {
        font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
        font-style: normal;
        display: block;
        font-size: 48px;
        line-height: 1;
        color: #bfbfbf;
        margin-bottom: 12px;
    }
    
    #user-list-panel .empty-list-tip > div {
        font-size: 13px;
        color: #999;
        opacity: 0.95;
        letter-spacing: 0.2px;
    }
    
    /* 移动端用户列表调整 - 隐藏桌面端用户列表 */
    #middle {
        display: none; /* 移动端隐藏桌面端用户列表 */
    }
    
    .user-sections {
        height: auto;
        max-height: 300px;
    }
    
    .u_container {
        padding: 10px 12px;
        min-height: 50px;
    }
    
    .user-avatar {
        width: 36px;
        height: 36px;
    }
    
    .u_name {
        font-size: 14px;
    }
    
    .u_location {
        font-size: 11px;
    }
    
    /* 触摸反馈样式 */
    .touch-active {
        background: #f0f0f0 !important;
        transition: background 0.1s ease !important;
    }
    
    /* iOS和Safari特定优化 */
    .ios-device #user-list-panel .u_container,
    .safari-browser #user-list-panel .u_container {
        -webkit-tap-highlight-color: rgba(7, 193, 96, 0.1);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    .ios-device #user-list-panel .user-avatar,
    .safari-browser #user-list-panel .user-avatar {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    .ios-device #user-list-panel .u_name,
    .safari-browser #user-list-panel .u_name {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .ios-device #user-list-panel .u_location,
    .safari-browser #user-list-panel .u_location {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .ios-device .user-sections .u_container,
    .safari-browser .user-sections .u_container {
        -webkit-tap-highlight-color: rgba(7, 193, 96, 0.1);
    }
    
    .ios-device .user-sections .user-avatar,
    .safari-browser .user-sections .user-avatar {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    .ios-device .user-sections .u_name,
    .safari-browser .user-sections .u_name {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    
    .ios-device .user-sections .u_location,
    .safari-browser .user-sections .u_location {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}