/* 聊天系统重构样式 - 微信风格 */

/* 1. 基础容器 */
.chat-widget {
    position: fixed;
    z-index: 9999;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    overflow: hidden;
    border: 1px solid rgba(226, 232, 240, 0.8);
    opacity: 1;
    will-change: transform, width, height, bottom, left;
}

/* 2. 最小化状态：左下角圆泡泡 */
.chat-widget.minimized {
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    justify-content: center;
    align-items: center;
    border: none;
    background: linear-gradient(135deg, #007aff 0%, #0056b3 100%); /* 更加专业的蓝色渐变 */
    box-shadow: 0 8px 25px rgba(0, 122, 255, 0.3);
    transform: scale(1);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: visible;
}

.chat-widget.minimized:hover {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 12px 30px rgba(0, 122, 255, 0.4);
}

.chat-widget.minimized .chat-left-panel,
.chat-widget.minimized .chat-right-panel {
    display: none;
    opacity: 0;
}

.chat-widget.minimized .bubble-icon {
    display: flex;
    font-size: 24px;
    color: white;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    position: relative;
    text-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* 消息气泡（未读数） */
.unread-badge {
    background: #ff3b30; /* iOS风格红 */
    color: white;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    border: 1.5px solid white;
    line-height: 1;
    z-index: 10;
}

/* 悬浮球上的未读数 */
.bubble-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
}

/* 侧边栏按钮上的未读数 */
.sidebar-unread-badge {
    margin-left: 6px;
    display: inline-flex;
    vertical-align: middle;
}

/* 3. 展开状态：屏幕中央双栏布局 */
.chat-widget.maximized {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 950px;
    max-width: 95vw;
    height: 680px;
    max-height: 90vh;
    border-radius: 20px;
    flex-direction: row;
    opacity: 1;
}

/* 移动端自适应增强 */
@media (max-width: 768px) {
    .chat-widget.minimized {
        bottom: 25px;
        left: 25px;
        width: 60px;
        height: 60px;
    }

    .chat-widget.maximized {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        z-index: 2147483647 !important;
        display: block !important;
        transform: none !important;
        box-shadow: none !important;
        overflow: hidden !important;
        background: white !important;
        /* 强制覆盖任何可能的父级限制 */
        max-width: none !important;
        max-height: none !important;
        overscroll-behavior: none !important;
    }

    /* 确保 html 和 body 在全屏模式下不滚动且高度铺满 */
    :root.chat-open,
    :root.chat-open body {
        overflow: hidden !important;
        height: 100% !important;
        width: 100% !important;
        /* 移除 position: fixed 以免干扰 iOS 键盘弹起时的视口表现 */
    }

    .chat-left-panel, 
    .chat-right-panel {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .chat-left-panel {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        z-index: 1 !important;
        background: white !important;
    }

    .chat-right-panel {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 2 !important;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        background: #f8f9fa !important;
    }

    .chat-right-panel.mobile-active {
        transform: translateX(0) !important;
    }

    .chat-window {
        height: 100% !important;
        display: flex; /* Always flex on mobile if in right panel */
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }

    .chat-window-header {
        padding: calc(10px + env(safe-area-inset-top)) 15px 10px;
        height: auto;
        min-height: 50px;
        flex-shrink: 0;
        background: #f5f5f5;
        border-bottom: 1px solid #e2e8f0;
    }

    .messages-container {
        padding: 15px 10px;
        gap: 12px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: #f5f5f5;
        overscroll-behavior: contain;
    }

    /* 输入区域在移动端更紧凑 */
    .chat-input-area {
        height: auto !important;
        min-height: 80px !important;
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        background: #fff;
        flex-shrink: 0;
        border-top: 1px solid #ddd;
        position: relative;
    }

    .chat-toolbar {
        padding: 5px 10px;
        gap: 15px;
    }

    .chat-input-main {
        padding: 0 10px;
        flex: 1;
    }

    .chat-input-main textarea {
        height: 36px !important;
        min-height: 36px !important;
        max-height: 100px !important;
        padding: 8px 12px !important;
        background: #f8f8f8;
        border-radius: 6px;
        border: 1px solid #e8e8e8;
        font-size: 16px !important; /* 防止 iOS 聚焦时自动缩放 */
    }

    .chat-footer {
        padding: 5px 10px;
    }

    .emoji-picker {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        bottom: 0 !important;
        position: fixed !important; /* Use fixed for full control */
        grid-template-columns: repeat(8, 1fr) !important;
        border-radius: 15px 15px 0 0 !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1) !important;
        z-index: 10001 !important;
        padding: 15px 5px !important;
        background: #f8f9fa !important;
        height: 250px !important;
    }

    .mobile-back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        margin-right: 8px;
        cursor: pointer;
        color: #333;
        font-size: 18px;
    }

    /* 当表情选择器打开时，调整消息容器，防止遮挡最新消息 */
    .chat-right-panel.emoji-open .messages-container {
        padding-bottom: 250px;
    }
}

/* 移动端返回按钮默认隐藏 */
.mobile-back-btn {
    display: none;
}

/* 移动端左侧面板关闭按钮默认隐藏 */
.mobile-close-btn {
    display: none;
}

@media (max-width: 768px) {
    .mobile-close-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        cursor: pointer;
        color: #94a3b8;
        font-size: 20px;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 50%;
        background: rgba(0, 0, 0, 0.03);
    }
    
    .mobile-close-btn:active {
        background: rgba(239, 68, 68, 0.1);
        color: #ef4444;
        transform: scale(0.9);
    }
}



.chat-widget.maximized .bubble-icon {
    display: none;
}

/* 4. 左侧栏：好友列表/搜索/请求 */
.chat-left-panel {
    width: 280px;
    background: #f0f0f0; /* 类似微信的浅灰色 */
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.chat-user-profile {
    padding: calc(15px + env(safe-area-inset-top)) 20px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.chat-tabs {
    display: flex;
    background: #e5e5e5;
    padding: 2px;
}

.chat-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 13px;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s;
}

.chat-tab.active {
    background: white;
    color: #3b82f6;
    font-weight: 600;
}

.chat-list-container {
    flex: 1;
    overflow-y: auto;
}

/* 5. 右侧栏：聊天窗口 */
.chat-right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
}

.chat-window-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}

.chat-window-placeholder i {
    font-size: 60px;
    margin-bottom: 20px;
    opacity: 0.2;
}

.chat-window {
    display: none; /* 默认隐藏，选中好友后显示 */
    flex-direction: column;
    height: 100%;
}

.chat-window-header {
    padding: 15px 25px;
    background: #f5f5f5;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-chat-btn {
    cursor: pointer;
    color: #64748b;
    padding: 5px;
}

.close-chat-btn:hover {
    color: #ef4444;
}

/* 消息容器 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #fdfaf5; /* 暖色背景 */
}

/* 居中时间条 */
.chat-time-divider {
    text-align: center;
    margin: 15px 0;
    position: relative;
}

.chat-time-divider span {
    background-color: rgba(0, 0, 0, 0.05);
    color: #999;
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 10px;
    display: inline-block;
}

.message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14.5px;
    line-height: 1.6;
    position: relative;
    animation: messageFadeIn 0.3s cubic-bezier(0.1, 0.5, 0.1, 1);
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    min-width: 60px;
}

@keyframes messageFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble.sent {
    align-self: flex-end;
    background: #ffcc80; /* 暖橙色 */
    color: #5d4037; /* 深褐文字 */
    border-bottom-right-radius: 4px;
}

.message-bubble.received {
    align-self: flex-start;
    background: #ffffff;
    color: #333;
    border-bottom-left-radius: 4px;
    border: 1px solid #ffe0b2;
}

/* 气泡内时间显示 */
.message-time-inner {
    font-size: 10px;
    color: inherit;
    opacity: 0.6;
    align-self: flex-end;
    margin-top: 4px;
    margin-left: 10px;
}

/* 交流群发送者样式 */
.message-sender {
    font-size: 11px;
    color: #a1887f;
    margin-bottom: 2px;
    padding-left: 10px;
}

.message-bubble.sent .message-sender {
    display: none; /* 自己发送的不显示名字，或者靠右 */
}

.message-content {
    white-space: pre-wrap; /* 支持换行 */
}

/* 输入区域 */
.chat-input-area {
    height: 180px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.chat-toolbar {
    padding: 10px 20px;
    display: flex;
    gap: 15px;
    color: #64748b;
}

.chat-toolbar i {
    cursor: pointer;
    font-size: 18px;
}

.chat-toolbar i:hover {
    color: #3b82f6;
}

.chat-input-main {
    flex: 1;
    padding: 0 20px;
}

.chat-input-main textarea {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    padding: 10px 0;
    font-family: inherit;
}

.chat-footer {
    padding: 10px 20px;
    display: flex;
    justify-content: flex-end;
}

.send-btn {
    padding: 6px 20px;
    background: #f2f2f2;
    color: #07c160;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.send-btn.active {
    background: #07c160;
    color: white;
}

.send-btn.active:hover {
    background: #06ae56;
}

.send-btn:not(.active):hover {
    background: #e5e5e5;
}

/* 好友项 */
.friend-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.friend-item:hover {
    background: #e2e2e2;
}

.friend-item.active {
    background: #c9c9c9;
}

/* 聊天气泡布局 */
.message-bubble {
    display: flex !important;
    margin-bottom: 15px;
    align-items: flex-start;
    max-width: 85%;
}

.message-bubble.sent {
    margin-left: auto;
    justify-content: flex-end;
}

.message-bubble.received {
    margin-right: auto;
    justify-content: flex-start;
}

.message-body {
    max-width: 100%;
    display: flex;
    flex-direction: column;
}

.message-bubble.sent .message-body {
    align-items: flex-end;
}

.message-bubble.received .message-body {
    align-items: flex-start;
}

.message-bubble.sent .message-content {
    background-color: #95ec69; /* 微信绿 */
    color: #000;
}

.message-bubble.received .message-content {
    background-color: #fff;
    color: #000;
}

.message-content {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-break: break-all;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message-time {
    font-size: 11px;
    color: #b2b2b2;
    margin-top: 4px;
}

.message-bubble.sent .message-time {
    text-align: right;
}

.message-sender {
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
}

.message-bubble.sent .message-sender {
    text-align: right;
}

.friend-avatar {
    width: 45px;
    height: 45px;
    border-radius: 4px;
    background: #3b82f6;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

.friend-info {
    flex: 1;
    min-width: 0;
}

/* 铭牌样式 */
.user-badge-pink, .user-badge-author, .user-badge-grey, .user-badge-official, .user-badge-invited {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: normal;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    line-height: 1.2;
    flex-shrink: 0;
}

.user-badge-pink {
    background: #ff85a2;
    color: white;
    box-shadow: 0 2px 4px rgba(255, 133, 162, 0.2);
}

.user-badge-author {
    background: #8b5cf6;
    color: white;
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.2);
}

.user-badge-grey {
    background: #94a3b8;
    color: white;
    box-shadow: 0 2px 4px rgba(148, 163, 184, 0.2);
}

.user-badge-official {
    background: #000000;
    color: #ffffff;
    font-size: 9px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.user-badge-official::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.user-badge-official:hover::before {
    left: 100%;
}

.user-badge-official:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transform: translateY(-1px);
    transition: all 0.3s ease;
}

.user-badge-invited {
    background: #000000;
    color: #FFD700;
    font-size: 9px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid #FFD700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
    animation: gold-glow 2s infinite alternate;
}

@keyframes gold-glow {
    from {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.3);
    }
    to {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.3);
    }
}

.user-badge-invited::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.3), transparent);
    transition: left 0.5s ease;
}

.user-badge-invited:hover::before {
    left: 100%;
}

.user-badge-invited:hover {
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
    transform: translateY(-1px);
    transition: all 0.3s ease;
}

.friend-name {
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
    gap: 4px;
    min-width: 0; /* 允许 flex 子元素收缩 */
}

.friend-name-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    flex-shrink: 1; /* 允许名称收缩以给徽章留出空间 */
}

.friend-motto {
    font-size: 9px;
    color: #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0px;
    letter-spacing: 0.2px;
}

/* 发现/搜索结果样式优化 */
.search-results .friend-item {
    border-bottom: 1px solid #f0f0f0;
    background: white;
    padding: 12px 15px;
}

.search-results .friend-item:hover {
    background: #f9fafb;
}

.search-results .friend-item:last-child {
    border-bottom: none;
}

.search-results .section-header {
    padding: 10px 15px;
    font-size: 12px;
    color: #64748b;
    background: #f8fafc;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 6. 其他辅助样式 */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-action-btn {
    cursor: pointer;
    color: #64748b;
    padding: 8px;
    font-size: 18px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

.header-action-btn:hover {
    background: #f1f5f9;
    color: #3b82f6;
}

.header-action-btn:active {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    transform: scale(0.9);
}

.header-action-btn.close-chat-btn:hover {
    background: #fee2e2;
    color: #ef4444;
}

.header-action-btn.close-chat-btn:active {
    background: rgba(239, 68, 68, 0.2);
    color: #dc2626;
}

.chat-right-panel {
    position: relative;
}

/* 适配移动端关闭按钮 */
@media (max-width: 768px) {
    .chat-header-actions {
        gap: 4px;
    }
    
    .header-action-btn {
        padding: 6px;
        font-size: 16px;
    }
}
.search-bar-container {
    padding: 10px 15px;
}

.search-bar {
    background: #dbdbdb;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 5px 10px;
}

.search-bar input {
    background: transparent;
    border: none;
    outline: none;
    flex: 1;
    font-size: 12px;
    padding: 2px 5px;
}

.search-bar i {
    font-size: 12px;
    color: #66748b;
}

/* 遮罩层 */
.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 9998;
    display: none;
}

.chat-overlay.show {
    display: block;
}

/* 表情包 */
.emoji-picker {
    position: absolute;
    bottom: 190px;
    left: 300px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    padding: 10px;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    z-index: 10001;
}

.emoji-item {
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
}

.emoji-item:hover {
    background: #f1f5f9;
}
