/* 手机端聊天样式 - 仿微信风格 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #07c160;
    --bg-color: #ededed;
    --header-bg: #07c160;
    --message-bg-self: #95ec69;
    --message-bg-other: #ffffff;
    --text-color: #333;
    --text-secondary: #888;
    --border-color: #ddd;
}

html,
body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    background: var(--bg-color);
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
    background: var(--bg-color);
}

/* 头部 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--header-bg);
    color: white;
    flex-shrink: 0;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 500;
}

.header-icon {
    font-size: 24px;
}

.header-status {
    font-size: 12px;
    opacity: 0.9;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.header-status.connected {
    background: rgba(255, 255, 255, 0.3);
}

.header-status.disconnected {
    background: rgba(255, 0, 0, 0.3);
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
}

.message-item {
    display: flex;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-item.self {
    justify-content: flex-end;
}

.message-item.other {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 8px;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-item.self .message-bubble {
    background: var(--message-bg-self);
    border-top-right-radius: 2px;
}

.message-item.other .message-bubble {
    background: var(--message-bg-other);
    border-top-left-radius: 2px;
}

.message-content {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-color);
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 4px;
    cursor: pointer;
    display: block;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

.message-item.other .message-time {
    text-align: left;
}

/* 输入区域 */
.chat-input {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    padding-bottom: max(env(safe-area-inset-bottom), 30px);
    background: #f7f7f7;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 10px;
}

.input-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.input-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.input-btn:active {
    background: rgba(0, 0, 0, 0.1);
}

.message-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 15px;
    outline: none;
    background: white;
    transition: border-color 0.2s;
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
    font-family: inherit;
}

.message-input:focus {
    border-color: var(--primary-color);
}

.send-btn {
    height: 40px;
    padding: 0 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.send-btn:hover {
    opacity: 0.9;
}

.send-btn:active {
    opacity: 0.8;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 图片预览 */
.image-preview {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.image-preview.show {
    display: flex;
}

.image-preview img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
}

.preview-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    color: white;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

/* 日期分隔 */
.date-divider {
    text-align: center;
    margin: 20px 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.date-divider span {
    background: var(--bg-color);
    padding: 0 10px;
}

/* 响应式 */
@media (min-width: 768px) {
    .chat-container {
        max-width: 500px;
        margin: 0 auto;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }

    .message-bubble {
        max-width: 60%;
    }
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

/* 发送中状态 */
.message-item.sending .message-bubble {
    opacity: 0.7;
}

.message-item.sending .message-bubble::after {
    content: '发送中...';
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 5px;
}