* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* 使用动态视口高度 */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 20px;
}

.login-form {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-form h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
}

.login-form input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.3s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    padding: 8px 16px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 使用动态视口高度，适配移动浏览器 */
    background: #f5f5f5;
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 10px;
    padding-top: calc(15px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    flex-shrink: 0; /* 防止压缩 */
    z-index: 100;
    position: relative;
    min-height: 50px; /* 最小高度，防止压缩 */
}

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 10px;
}

.header-info {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0; /* 允许 flex 子元素收缩 */
}

.header-info h2 {
    font-size: 18px;
    margin: 0;
    text-align: center;
    word-wrap: break-word; /* 允许长单词换行 */
    word-break: break-all; /* 允许在任意字符间断行 */
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 15px 15px 15px;
    background: #f5f5f5;
    scroll-padding-top: 20px;
    min-height: 0; /* 重要：允许flex子元素缩小 */
    -webkit-overflow-scrolling: touch; /* iOS平滑滚动 */
}

.message {
    display: flex;
    margin-bottom: 15px;
    animation: fadeIn 0.3s;
}

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

.message.sent {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
    margin: 0 8px;
}

.message-content {
    max-width: 70%;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 15px;
    line-height: 1.5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    white-space: normal;
    word-break: normal;
    overflow-wrap: anywhere;
}

.message.sent .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
    text-align: center;
}

.message-time-center {
    text-align: center;
    font-size: 11px;
    color: #999;
    margin: 10px 0;
}

.message-image, .message-video {
    max-width: 100%;
    border-radius: 8px;
    display: block;
    margin-top: 5px;
}

.message-image {
    max-height: 300px;
    object-fit: cover;
    cursor: pointer;
    transition: opacity 0.3s;
}

.message-image:hover {
    opacity: 0.9;
}

.message-file {
    background: rgba(255,255,255,0.3);
    padding: 10px;
    border-radius: 8px;
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.message-file a {
    color: white;
    text-decoration: none;
    flex: 1;
}

.input-container {
    background: #f5f5f5;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    flex-shrink: 0; /* 防止压缩 */
    z-index: 100;
    position: relative;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f5f5f5;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    transition: background 0.3s;
}

.icon-btn:hover {
    background: #f0f0f0;
}

.message-input {
    flex: 1;
    padding: 12px 15px;
    background: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
}

.send-btn {
    background: rgb(117, 113, 249);
    color: white;
    font-size: 14px;
    font-weight: 500;
    padding: 9px 18px;
    border-radius: 8px;
    min-width: 60px;
    border: none;
}

.emoji-panel {
    display: none;
    background: white;
    border-top: 1px solid #e0e0e0;
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.emoji-panel.show {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
}

.emoji-item {
    font-size: 24px;
    cursor: pointer;
    text-align: center;
    padding: 5px;
    border-radius: 6px;
    transition: background 0.3s;
}

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

.attachment-panel {
    display: none;
    background: white;
    border-top: 1px solid #e0e0e0;
    padding: 20px;
}

.attachment-panel.show {
    display: flex;
    justify-content: space-around;
}

.attachment-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 15px;
    border-radius: 12px;
    transition: background 0.3s;
}

.attachment-item:hover {
    background: #f0f0f0;
}

.attachment-icon {
    font-size: 40px;
}

.attachment-item span {
    font-size: 12px;
    color: #666;
}

/* 底部操作按钮 */
.bottom-actions {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-top: 8px;
    margin-top: 5px;
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: opacity 0.2s;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn img {
    width: 28px;
    height: 28px;
    display: block;
    opacity: 0.8;
}

.action-btn:hover img {
    opacity: 1;
}

.action-btn.muted img {
    opacity: 0.4;
}

/* 滚动条样式 */
.messages-container::-webkit-scrollbar {
    width: 5px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 5px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .login-form {
        padding: 30px 20px;
    }
    
    .messages-container {
        padding: 25px 15px 15px 15px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
    }
    
    .attachment-panel {
        padding: 15px;
    }
    
    .attachment-icon {
        font-size: 35px;
    }
}

/* 加载动画 */
.loading {
    text-align: center;
    padding: 20px;
    color: #999;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

/* 图片预览模态框 */
.image-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    z-index: 10000;
    flex-direction: column;
}

.image-preview-modal.show {
    display: flex;
}

.preview-header {
    background: rgba(0, 0, 0, 0.8);
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
    z-index: 10001;
}

.preview-back-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.preview-back-btn:active {
    opacity: 0.6;
}

.preview-title {
    color: white;
    font-size: 16px;
    font-weight: 500;
}

.preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
}

.preview-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}


