/* Style.css - 移动端优化的聊天室样式
 * 针对iOS和Android进行了全面优化
 * 最后更新: 2026-02-11
 */
/* ====== 基础重置 ====== */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: rgba(0,0,0,0);
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
html {
    height: 100%;
    overflow: hidden;
}
body, html { 
    height: 100%; 
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", STHeiti, "Microsoft YaHei", sans-serif;
    background: #f2f2f7;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-touch-callout: none;
}
/* ====== 主容器 ====== */
.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: -webkit-fill-available;
    max-width: 800px;
    margin: 0 auto;
    background: #ffffff;
    position: relative;
    overflow: hidden;
}
/* ====== 网络状态指示器 ====== */
.connection-status {
    position: fixed;
    top: max(15px, env(safe-area-inset-top, 15px));
    right: max(15px, env(safe-area-inset-right, 15px));
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #34c759;
    z-index: 9999;
    display: none;
    box-shadow: 0 0 10px #34c759;
}
.connection-status.offline {
    background: #ff3b30;
    box-shadow: 0 0 10px #ff3b30;
}
/* ====== 新消息提示 ====== */
.new-message-alert {
    position: fixed;
    top: max(50px, calc(env(safe-area-inset-top, 0px) + 50px));
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 24px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 500;
    z-index: 10001;
    display: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
    border: none;
    touch-action: manipulation;
    user-select: none;
}
/* ====== 聊天区域 - 关键修复 ====== */
.chat-area { 
    flex: 1;
    flex-basis: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 15px 15px calc(80px + env(safe-area-inset-bottom, 0px)) 15px;
    height: auto;
    min-height: 0;
    overflow-anchor: auto;
    -webkit-overflow-scrolling: touch;
}
.chat-area.is-loading {
    overflow: hidden;
}
/* ====== 输入区域 - 关键修复 ====== */
.input-area { 
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-end;
    padding: max(10px, env(safe-area-inset-bottom, 10px)) 12px 12px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 12px));
    padding-right: max(12px, env(safe-area-inset-right, 12px));
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    gap: 10px;
    max-width: 800px;
    margin: 0 auto;
    z-index: 1000;
    box-shadow: 0 -2px 20px rgba(0,0,0,0.1);
}
/* ====== 输入框 - 移动端优化 ====== */
#messageInput { 
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e1e5e9;
    border-radius: 22px;
    font-size: 17px;
    outline: none;
    background: #f8f9fa;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
    resize: none;
    touch-action: manipulation;
}
#messageInput:focus { 
    border-color: #667eea;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}
#messageInput::placeholder {
    color: #999;
}
/* ====== 发送按钮 - 移动端优化 ====== */
#sendButton { 
    padding: 0 20px;
    height: 44px;
    min-width: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 22px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: manipulation;
}
#sendButton:active { 
    opacity: 0.8;
}
#sendButton:disabled { 
    background: #d1d5db;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none;
}
/* ====== 消息布局 - 移动端优化 ====== */
.message { 
    margin: 12px 0;
    display: flex;
    align-items: flex-start;
    width: 100%;
    clear: both;
    transform: translateZ(0);
}
/* 他人消息 */
.message.other { 
    justify-content: flex-start;
}
/* 自己消息 */
.message.mine { 
    justify-content: flex-end;
}
/* ====== 消息气泡 - 移动端优化 ====== */
.message-bubble { 
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.4;
    position: relative;
    overflow-wrap: anywhere;
    hyphens: auto;
    font-size: 16px;
}
/* 他人消息气泡 */
.message.other .message-bubble { 
    background: #f0f2f5;
    margin-left: 8px;
    margin-right: 0;
    border-bottom-left-radius: 4px;
}
/* 自己消息气泡 */
.message.mine .message-bubble { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-right: 8px;
    margin-left: 0;
    border-bottom-right-radius: 4px;
}
/* ====== 头像 - 移动端优化 ====== */
.avatar { 
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    font-size: 15px;
    flex: 0 0 36px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
/* 他人头像 */
.message.other .avatar {
    order: 1;
}
.message.other .message-bubble {
    order: 2;
}
/* 自己头像 */
.message.mine .avatar {
    order: 2;
}
.message.mine .message-bubble {
    order: 1;
}
/* ====== 消息内容 - 移动端优化 ====== */
.message-text {
    font-size: 16px;
    line-height: 1.4;
}
/* ====== 发送者信息 ====== */
.message-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    font-size: 12px;
}
.message-sender { 
    font-weight: 600;
    opacity: 0.9;
    font-size: 12px;
}
.message-time { 
    opacity: 0.7;
    font-size: 11px;
    white-space: nowrap;
    margin-left: 8px;
}
.message.other .message-time {
    color: #666;
}
.message.mine .message-time {
    color: rgba(255, 255, 255, 0.85);
}
/* ====== 图片样式 - 移动端优化 ====== */
.message-text img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 12px;
    margin-top: 8px;
    cursor: pointer;
    display: block;
    background: #f0f0f0;
    touch-action: manipulation;
}
/* ====== 加载指示器 ====== */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #f0f0f0;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* ====== 空状态 ====== */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: #999;
}
.empty-state-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.6;
}
/* ====== 模态框 - 移动端优化 ====== */
.modal { 
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.98);
    z-index: 10002;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.25s ease;
    touch-action: none;
    padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    object-fit: contain;
}
/* ====== Toast提示 - 移动端优化 ====== */
.toast { 
    position: fixed;
    top: max(60px, calc(env(safe-area-inset-top, 0px) + 60px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    z-index: 10003;
    font-size: 14px;
    display: none;
    animation: toastSlideIn 0.3s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    max-width: 85%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
@keyframes toastSlideIn {
    from { 
        transform: translate(-50%, -20px); 
        opacity: 0; 
    }
    to { 
        transform: translate(-50%, 0); 
        opacity: 1; 
    }
}
/* ====== 调试面板 ====== */
.debug-panel {
    position: fixed;
    top: max(10px, env(safe-area-inset-top, 10px));
    left: max(10px, env(safe-area-inset-left, 10px));
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px;
    border-radius: 8px;
    z-index: 10004;
    font-size: 12px;
    max-width: 280px;
    display: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.debug-panel div {
    margin: 4px 0;
}
.debug-close-btn {
    margin-top: 8px;
    padding: 4px 10px;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
/* ====== 暗色模式 - 移动端优化 ====== */
@media (prefers-color-scheme: dark) {
    body, html {
        background: #1c1c1e;
        color: #ffffff;
    }
    
    .container {
        background: #000000;
    }
    
    .input-area {
        background: rgba(28, 28, 30, 0.95);
        border-top-color: rgba(255, 255, 255, 0.1);
    }
    
    #messageInput {
        background: #2c2c2e;
        color: #ffffff;
        border-color: #3a3a3c;
    }
    
    #messageInput:focus {
        background: #3a3a3c;
        border-color: #667eea;
    }
    
    .message.other .message-bubble {
        background: #2c2c2e;
        color: #ffffff;
    }
    
    .loading {
        color: #8e8e93;
    }
    
    .loading-spinner {
        border-color: #3a3a3c;
        border-top-color: #667eea;
    }
}
/* ====== 移动端专用样式 (< 768px) ====== */
@media screen and (max-width: 768px) {
    .container {
        height: 100%;
        height: -webkit-fill-available;
    }
    .chat-area {
        padding: 12px 12px calc(70px + env(safe-area-inset-bottom, 0px)) 12px;
    }
    .new-message-alert {
        top: max(60px, calc(env(safe-area-inset-top, 0px) + 60px));
        font-size: 14px;
        padding: 10px 20px;
    }
    #messageInput {
        font-size: 16px;
        padding: 10px 14px;
        min-height: 40px;
        border-radius: 20px;
    }
    #sendButton {
        height: 40px;
        min-width: 60px;
        padding: 0 16px;
        font-size: 15px;
        border-radius: 20px;
    }
    .message-bubble {
        max-width: 82%;
        padding: 10px 13px;
        font-size: 15px;
    }
    .avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
        flex: 0 0 32px;
    }
    .message {
        margin: 10px 0;
    }
    .toast {
        top: max(70px, calc(env(safe-area-inset-top, 0px) + 70px));
        font-size: 13px;
        padding: 10px 20px;
    }
}
/* ====== iPhone X及以上设备专用 ====== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    .chat-area {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}
/* ====== 小屏幕设备优化 ====== */
@media screen and (max-width: 480px) {
    .message-bubble {
        max-width: 85%;
        padding: 8px 12px;
        font-size: 15px;
    }
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
        flex: 0 0 28px;
    }
    .message {
        margin: 8px 0;
    }
    .new-message-alert {
        font-size: 13px;
        padding: 8px 16px;
    }
}
/* ====== 滚动条美化 - 移动端隐藏 ====== */
.chat-area {
    scrollbar-width: none;
    -ms-overflow-style: none;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.chat-area::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
.chat-area::-webkit-scrollbar-track {
    background: transparent;
}
.chat-area::-webkit-scrollbar-thumb {
    background: transparent;
}
/* ====== 防止iOS橡皮筋效果 ====== */
@supports (-webkit-touch-callout: none) {
    html, body {
        position: relative !important;
        height: 100% !important;
        overflow: hidden !important;
        touch-action: pan-y !important;
    }
    .container {
        height: 100% !important;
        height: -webkit-fill-available !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    .chat-area {
        flex: 1 !important;
        overflow-y: scroll !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        height: auto !important;
        min-height: 0 !important;
    }
    .input-area {
        flex-shrink: 0 !important;
    }
}