/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

/* 聊天容器 */
.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    height: 80vh;
    max-height: 800px;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* 聊天头部 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: #4a6fa5;
    color: white;
    border-bottom: 1px solid #ddd;
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#current-user {
    font-weight: 500;
    background-color: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 20px;
}

#change-name-btn {
    padding: 5px 15px;
    background-color: #fff;
    color: #4a6fa5;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

#change-name-btn:hover {
    background-color: #f0f0f0;
    transform: translateY(-1px);
}

/* 模态框 */
.modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.modal-content h2 {
    margin-bottom: 20px;
    color: #4a6fa5;
}

#nickname-input {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

#nickname-input:focus {
    outline: none;
    border-color: #4a6fa5;
}

#confirm-name-btn {
    padding: 12px 30px;
    background-color: #4a6fa5;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#confirm-name-btn:hover {
    background-color: #3a5a85;
    transform: translateY(-1px);
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fafafa;
    border-bottom: 1px solid #eee;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 消息样式 */
.message {
    margin-bottom: 15px;
    animation: fadeIn 0.3s ease;
}

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

.user-message {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.other-message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-header {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.user-message .message-header {
    color: #4a6fa5;
}

.other-message .message-header {
    color: #666;
}

.message-content {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
}

.user-message .message-content {
    background-color: #4a6fa5;
    color: white;
    border-bottom-right-radius: 5px;
}

.other-message .message-content {
    background-color: #e9e9eb;
    color: #333;
    border-bottom-left-radius: 5px;
}

.system-message {
    text-align: center;
    color: #888;
    font-style: italic;
    margin: 15px 0;
    font-size: 0.9rem;
}

/* 输入区域 */
.chat-input-area {
    padding: 20px;
    background-color: #fff;
}

#message-form {
    display: flex;
    gap: 10px;
}

#message-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

#message-input:focus {
    outline: none;
    border-color: #4a6fa5;
}

#message-input:disabled,
#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#send-btn {
    padding: 12px 25px;
    background-color: #4a6fa5;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

#send-btn:hover:not(:disabled) {
    background-color: #3a5a85;
    transform: translateY(-1px);
}

/* 在线用户列表 */
.online-users {
    position: fixed;
    right: 20px;
    top: 20px;
    width: 200px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.online-users h3 {
    margin-bottom: 15px;
    color: #4a6fa5;
    font-size: 1.1rem;
}

#user-list {
    list-style: none;
}

#user-list li {
    padding: 8px 10px;
    margin-bottom: 5px;
    border-radius: 6px;
    background-color: #f0f4f8;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

#user-list li::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: #4CAF50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .chat-container {
        height: 90vh;
        margin: 0;
        max-width: 100%;
    }
    
    .online-users {
        position: static;
        width: 100%;
        max-height: 20vh;
        border-radius: 0;
        box-shadow: none;
        border-top: 1px solid #eee;
        padding: 15px;
    }
    
    .chat-header h1 {
        font-size: 1.3rem;
    }
    
    .user-info {
        flex-direction: column;
        gap: 5px;
        font-size: 0.9rem;
    }
    
    .message-content {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .chat-container {
        height: 100vh;
        max-height: 100vh;
    }
    
    .chat-header,
    .chat-input-area,
    .chat-messages {
        padding: 15px;
    }
    
    #message-form {
        flex-direction: column;
    }
    
    #send-btn {
        width: 100%;
    }
}