/**
 * 在线聊天系统样式
 */

/* 聊天入口按钮容器 - 在导航栏外部，移动端固定显示 */
.chat-entry-wrapper {
    display: none; /* PC端隐藏，使用导航栏内的按钮 */
    vertical-align: top;
    margin-left: 10px;
    float: right;
}

/* PC端：导航栏内的聊天按钮 */
.chat-entry-nav-item {
    display: inline-block;
}

/* 聊天入口按钮 - 与其他导航项对齐 */
.chat-entry-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    height: 55px;
    line-height: 55px;
    background: #ff7f00;
    color: #fff;
    border: none;
    border-radius: 0;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: none;
    position: relative;
    overflow: visible;
    vertical-align: top;
    text-decoration: none;
}

.chat-entry-btn:hover {
    background: #ff7f00;
    color: #fff;
    transform: none;
    box-shadow: none;
}

/* 确保按钮在导航栏中垂直对齐 */
.nav-login-item .chat-entry-btn {
    margin: 0;
    vertical-align: top;
}

/* 确保按钮与其他导航项在同一行 */
.nav .nav-login-item {
    display: inline-block;
    vertical-align: top;
}

.chat-entry-btn:active {
    transform: none;
}

.chat-entry-btn i {
    font-size: 16px;
}

/* 在线人数徽章 */
.chat-online-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ff7f00;
    color: #fff;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    margin-left: 4px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* 聊天窗口遮罩层 */
.chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

/* 移动端：遮罩层全屏 */
@media (max-width: 768px) {
    .chat-overlay {
        background: rgba(0, 0, 0, 0.8);
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
}

.chat-overlay.active {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* 聊天窗口 */
.chat-window {
    position: relative;
    width: 420px;
    height: 600px;
    max-height: calc(90vh - 40px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    transition: all 0.3s ease;
    animation: chatModalFadeIn 0.3s ease;
    margin: auto;
    flex-shrink: 0;
}

.chat-window.active {
    display: flex !important;
}

@keyframes chatModalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* 聊天窗口头部 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #ff7f00;
    color: #fff;
    border-radius: 8px 8px 0 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-online-count {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.25);
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-leave-btn,
.chat-minimize-btn,
.chat-close-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 16px;
}

.chat-leave-btn:hover {
    background: rgba(255, 100, 100, 0.4);
    transform: scale(1.1);
}

.chat-minimize-btn:hover,
.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.chat-leave-btn:active,
.chat-minimize-btn:active,
.chat-close-btn:active {
    transform: scale(0.95);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* 优化渲染性能，减少闪烁 */
    will-change: scroll-position;
    transform: translateZ(0); /* 启用硬件加速 */
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 空消息提示 */
.chat-empty-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
}

/* 消息项 */
.chat-message {
    display: flex;
    gap: 10px;
    /* 移除动画，避免闪烁 */
    /* animation: fadeIn 0.3s ease; */
}

/* 自己的消息：右对齐 */
.chat-message-own {
    flex-direction: row-reverse; /* 反转顺序：内容在左，头像在右 */
    justify-content: flex-end; /* 从右边开始对齐 */
    align-self: flex-end; /* 让整个消息容器右对齐 */
    margin-left: auto; /* 推送到右边 */
    max-width: 85%; /* 限制最大宽度，避免消息过宽 */
}

.chat-message-own .chat-message-content {
    align-items: flex-end; /* 内容右对齐 */
    display: flex;
    flex-direction: column;
}

.chat-message-own .chat-message-header {
    flex-direction: row-reverse; /* 时间在左，用户名在右 */
    justify-content: flex-end;
}

.chat-message-own .chat-message-text {
    background: #ff7f00; /* 自己的消息使用主题色背景 */
    color: #fff;
    border-radius: 12px 12px 4px 12px; /* 右上角圆角更大 */
    padding: 8px 12px;
    max-width: 70%; /* 限制最大宽度 */
    word-wrap: break-word;
    word-break: break-word;
    text-align: left; /* 文本内容左对齐（在气泡内） */
}

/* 其他用户的消息：左对齐（默认） */
.chat-message:not(.chat-message-own) .chat-message-text {
    background: #fff;
    color: #333;
    border-radius: 12px 12px 12px 4px; /* 左下角圆角更大 */
    padding: 8px 12px;
    max-width: 70%; /* 限制最大宽度 */
    word-wrap: break-word;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* 只在需要时使用动画（已禁用） */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid #e0e0e0;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: contain; /* SVG动图使用contain，保持完整显示 */
    display: block;
}

.chat-message-content {
    flex: 1;
    min-width: 0;
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.chat-message-username {
    font-size: 13px;
    font-weight: 600;
    color: #333;
}

.chat-message-time {
    font-size: 11px;
    color: #999;
}

.chat-message-text {
    font-size: 14px;
    color: #555;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
}

/* 输入区域 */
.chat-input-area {
    padding: 16px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.5;
}

.chat-input:focus {
    border-color: #ff7f00;
    box-shadow: 0 0 0 3px rgba(255, 127, 0, 0.1);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ff7f00;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    font-size: 16px;
}

.chat-send-btn:hover {
    background: #ff9500;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 127, 0, 0.3);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-input-hint {
    font-size: 12px;
    color: #999;
    text-align: right;
}

/* 最小化状态 */
.chat-window.minimized {
    height: 60px;
}

.chat-window.minimized .chat-messages,
.chat-window.minimized .chat-input-area {
    display: none;
}

/* 加载状态 */
.chat-loading {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

.chat-empty {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}

/* 响应式：中等屏幕（1200px以下） */
@media (max-width: 1200px) {
    .chat-entry-btn {
        padding: 0 8px;
        font-size: 12px;
        height: 48px;
        line-height: 48px;
    }
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-window {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
    }
    
    /* 移动端：隐藏最小化按钮，禁用最小化功能 */
    .chat-minimize-btn {
        display: none !important;
    }
    
    /* 移动端：确保聊天窗口始终完整显示，不能被最小化 */
    .chat-window.active {
        height: 100vh !important;
        max-height: 100vh !important;
    }
    
    .chat-messages {
        display: flex !important;
        padding-bottom: 10px;
        /* 为输入框留出空间，避免被键盘遮挡 */
        padding-bottom: env(safe-area-inset-bottom, 10px);
    }
    
    .chat-input-area {
        display: flex !important;
        flex-direction: column;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #e0e0e0;
        /* 固定在底部 */
        position: sticky;
        bottom: 0;
        z-index: 10;
    }
    
    /* 移动端：输入框容器优化 */
    .chat-input-wrapper {
        display: flex;
        gap: 10px;
        align-items: flex-end;
        width: 100%;
    }
    
    /* 移动端：输入框优化 - 与PC端保持一致 */
    .chat-input {
        flex: 1 !important;
        min-height: 40px !important; /* 与PC端一致 */
        max-height: 120px !important;
        padding: 10px 12px !important; /* 与PC端一致 */
        border: 1px solid #e0e0e0 !important;
        border-radius: 20px !important; /* 与PC端一致 */
        font-size: 14px !important; /* 与PC端一致 */
        line-height: 1.5 !important;
        resize: none !important;
        outline: none !important;
        transition: all 0.2s !important;
        font-family: inherit !important;
        /* 优化移动端输入体验 */
        -webkit-appearance: none !important;
        appearance: none !important;
        touch-action: manipulation;
    }
    
    .chat-input:focus {
        border-color: #ff7f00 !important;
        box-shadow: 0 0 0 3px rgba(255, 127, 0, 0.1) !important;
        outline: none !important;
    }
    
    /* 移动端：发送按钮优化 - 与PC端保持一致 */
    .chat-send-btn {
        width: 40px !important; /* 与PC端一致 */
        height: 40px !important; /* 与PC端一致 */
        min-width: 40px !important;
        min-height: 40px !important;
        background: #ff7f00 !important;
        color: #fff !important;
        border: none !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        transition: all 0.3s !important;
        flex-shrink: 0 !important;
        font-size: 16px !important; /* 与PC端一致 */
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        /* 优化触摸反馈 */
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 127, 0, 0.3);
    }
    
    .chat-send-btn:hover {
        background: #ff9500 !important;
        transform: scale(1.1) !important;
        box-shadow: 0 4px 12px rgba(255, 127, 0, 0.3) !important;
    }
    
    .chat-send-btn:active {
        background: #ff9500 !important;
        transform: scale(0.95) !important;
    }
    
    .chat-send-btn:disabled {
        opacity: 0.5 !important;
        cursor: not-allowed !important;
        transform: none !important;
    }
    
    /* 移动端：字符计数提示优化 */
    .chat-input-hint {
        font-size: 12px;
        color: #999;
        text-align: right;
        padding-right: 4px;
        margin-top: 4px;
    }
    
    /* 移动端：隐藏导航栏内的聊天按钮 */
    .chat-entry-nav-item {
        display: none !important;
    }
    
    /* 移动端：聊天入口按钮容器始终显示，在主题切换按钮左侧 */
    .chat-entry-wrapper {
        display: flex !important;
        position: absolute;
        top: 0;
        right: 90px; /* 主题切换按钮宽度 + 间距 */
        height: 50px;
        line-height: 50px;
        margin: 0;
        z-index: 1001;
        align-items: center;
    }
    
    /* 移动端：聊天入口按钮样式，与主题切换按钮对齐 */
    .chat-entry-btn {
        padding: 0 10px;
        font-size: 12px;
        height: 34px;
        line-height: 34px;
        border-radius: 4px;
        white-space: nowrap;
    }
    
    .chat-entry-btn i {
        font-size: 14px;
    }
    
    .chat-entry-btn span {
        display: inline;
    }
    
    .chat-online-badge {
        min-width: 18px;
        height: 18px;
        font-size: 10px;
        padding: 0 5px;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .chat-entry-btn {
        padding: 12px 20px;
        font-size: 14px;
        gap: 6px;
        height: auto;
        line-height: 1.5;
    }
    
    .chat-entry-btn span {
        display: inline; /* 显示文字，与其他导航项保持一致 */
    }
    
    .chat-online-badge {
        position: absolute;
        top: -4px;
        right: -4px;
    }
    
    /* 小屏手机：与PC端保持一致 */
    .chat-input {
        min-height: 40px !important;
        padding: 10px 12px !important;
        font-size: 14px !important;
    }
    
    .chat-send-btn {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        font-size: 16px !important;
    }
    
    .chat-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

