/**
 * 手机端显示修复样式
 * 修复底部输入框、发送按钮不显示的问题
 */

/* 移动端样式 */
@media (max-width: 767px) {
    html, body {
        height: 100%;
        height: -webkit-fill-available;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    body {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
}

/* 聊天区域占据剩余空间 */
.mk-chat-box {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 底部输入区域固定显示 */
.write {
    position: relative;
    flex-shrink: 0;
    width: 100%;
    min-height: 50px;
    background: #f7f7f7;
    border-top: 1px solid #dcdcdc;
    padding: 8px 12px;
    display: flex !important;
    align-items: center;
    gap: 8px;
    z-index: 100;
    box-sizing: border-box;
    /* iOS 安全区域适配 */
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

/* 隐藏登录界面时的聊天输入区域 */
.write.login ~ .write:not(.login) {
    display: none !important;
}

/* 登录界面样式修复 */
.write.login {
    position: relative;
    flex: 1;
    min-height: auto;
    padding: 40px 20px;
    background: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-top: none;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
}

/* 输入框样式 */
.write:not(.login) input#msg {
    flex: 1;
    height: 36px;
    min-width: 0;
    font-size: 16px;
    padding: 0 12px;
    border: 1px solid #dcdcdc;
    border-radius: 5px;
    background: white;
    -webkit-appearance: none;
    appearance: none;
}

/* 发送按钮样式 */
.write:not(.login) .send {
    flex-shrink: 0;
    min-width: 60px;
    height: 36px;
    line-height: 36px;
    padding: 0 16px;
    font-size: 15px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

/* 上传按钮样式 */
.write:not(.login) .upload-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #dcdcdc;
    border-radius: 5px;
    font-size: 20px;
    cursor: pointer;
}

/* 移动端特殊处理 */
@media screen and (max-width: 768px) {
    body {
        height: 100%;
        height: 100dvh; /* 动态视口高度 */
    }
    
    .top {
        flex-shrink: 0;
        height: 44px;
        min-height: 44px;
    }
    
    .mk-chat-box {
        flex: 1;
        min-height: 0;
        padding-bottom: 10px;
    }
    
    .write:not(.login) {
        padding: 8px 10px;
        gap: 6px;
        min-height: 52px;
    }
    
    .write:not(.login) input#msg {
        height: 38px;
        font-size: 16px; /* 防止 iOS 缩放 */
    }
    
    .write:not(.login) .send {
        height: 38px;
        line-height: 38px;
        min-width: 55px;
        padding: 0 12px;
        font-size: 14px;
    }
    
    .write:not(.login) .upload-btn {
        width: 38px;
        height: 38px;
    }
}

/* 小屏幕手机优化 */
@media screen and (max-width: 375px) {
    .write:not(.login) {
        padding: 6px 8px;
        gap: 4px;
    }
    
    .write:not(.login) .send {
        min-width: 50px;
        padding: 0 10px;
        font-size: 13px;
    }
    
    .write:not(.login) .upload-btn {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }
}

/* iOS 虚拟键盘弹出时的处理 */
@supports (-webkit-touch-callout: none) {
    body {
        height: -webkit-fill-available;
    }
    
    .write:not(.login) {
        /* iOS 键盘弹出时保持可见 */
        transform: translateZ(0);
    }
}

/* 确保登录按钮在禁用状态下的样式 */
.write.login .send:disabled,
.write.login .send.disabled {
    background: #ccc !important;
    color: #666 !important;
    cursor: not-allowed;
}

/* 登录/注册按钮加载状态 */
.write.login .send {
    transition: background 0.2s, opacity 0.2s;
}

/* 防止输入框被遮挡 */
.write input:focus {
    outline: none;
}

/* 确保 talk 区域正确显示 */
.talk {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* 隐藏时的处理 */
.talk[style*="display: none"],
.talk[style*="display:none"] {
    display: none !important;
}

/* 强制登出弹窗样式 */
.force-logout-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.force-logout-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    max-width: 300px;
    margin: 20px;
}

.force-logout-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.force-logout-message {
    font-size: 16px;
    color: #333;
    margin-bottom: 24px;
    line-height: 1.5;
}

.force-logout-btn {
    width: 100%;
    height: 44px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
}
