/* 
 * 移动端优化样式表
 * 适用于安卓、iOS、鸿蒙系统及微信浏览器
 * ===================================
 */

/* 基础移动端优化 */
@media screen and (max-width: 768px) {
    /* 应用容器优化 */
    .app-container {
        flex-direction: column;
        height: 100%;
        width: 100%;
        overflow: hidden;
    }
    
    /* 侧边栏优化 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        background-color: #fff;
        box-shadow: none;
    }
    
    .app-container.sidebar-visible .sidebar {
        transform: translateX(0);
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
    }
    
    /* 主内容区优化 */
    .main-content {
        width: 100%;
        height: 100%;
        padding-bottom: 70px; /* 为底部输入框留出空间 */
        margin-left: 0;
    }
    
    /* 聊天消息区域优化 */
    .chat-messages {
        padding: 10px;
        height: calc(100% - 120px);
    }
    
    /* 消息容器优化 */
    .message-container {
        margin-bottom: 15px;
    }
    
    .message-content {
        max-width: 85%;
        padding: 10px 12px;
    }
    
    /* 输入区域优化 */
    .chat-input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        padding: 10px;
        background-color: var(--white, #fff);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        display: flex;
        align-items: center;
    }
    
    /* 优化聊天输入框和按钮排列 */
    .chat-input {
        font-size: 16px; /* 防止iOS缩放 */
        flex: 1;
        margin-right: 8px;
    }
    
    /* 优化右侧按钮组，改为水平排列 */
    .input-action-buttons {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }
    
    /* 确保按钮大小合适 */
    .input-tool-btn, .chat-send-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 头部优化 */
    .chat-header {
        padding: 10px;
        height: 60px;
    }
    
    .chat-title {
        font-size: 16px;
    }
    
    .header-actions {
        gap: 5px;
    }
    
    /* 移动端菜单按钮 */
    .mobile-menu-btn {
        display: flex;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        width: 40px;
        height: 40px;
        background: rgba(255, 255, 255, 0.9);
        border: none;
        border-radius: 5px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        cursor: pointer;
        padding: 8px;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
    }
    
    .mobile-menu-btn span {
        display: block;
        width: 100%;
        height: 3px;
        background: var(--primary-color, #4a6cf7);
        border-radius: 3px;
        transition: all 0.3s ease;
    }
    
    /* 侧边栏可见状态下的按钮样式 */
    .app-container.sidebar-visible .mobile-menu-btn span:nth-child(1) {
        transform: translateY(10px) rotate(45deg);
    }
    
    .app-container.sidebar-visible .mobile-menu-btn span:nth-child(2) {
        opacity: 0;
    }
    
    .app-container.sidebar-visible .mobile-menu-btn span:nth-child(3) {
        transform: translateY(-10px) rotate(-45deg);
    }
    
    /* 侧边栏可见时添加遮罩 */
    .app-container.sidebar-visible::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
    
    /* 修复文件上传对话框问题 */
    .file-upload-prompt {
        z-index: 2000;
        display: none; /* 默认隐藏，通过JS控制显示 */
    }
    
    /* 确保取消按钮可点击 */
    .file-actions {
        display: flex;
        gap: 10px;
        margin-top: 15px;
    }
    
    .file-actions .btn {
        flex: 1;
        min-height: 44px; /* 确保触摸区域足够大 */
        font-size: 16px;
    }
    
    #cancel-upload-btn {
        z-index: 2001; /* 确保在最上层 */
    }
}

/* 小屏幕手机优化 */
@media screen and (max-width: 375px) {
    .message-content {
        max-width: 90%;
        padding: 8px 10px;
        font-size: 14px;
    }
    
    .chat-input {
        padding: 8px 10px;
    }
    
    .chat-send-btn {
        width: 36px;
        height: 36px;
    }
    
    /* 在小屏幕上进一步优化按钮间距 */
    .input-action-buttons {
        gap: 6px;
    }
}

/* 微信浏览器特殊优化 */
@supports (-webkit-overflow-scrolling: touch) {
    .chat-messages {
        -webkit-overflow-scrolling: touch;
    }
    
    input, textarea, select {
        font-size: 16px; /* 防止iOS自动缩放 */
    }
}

/* 鸿蒙系统适配 */
@media screen and (device-type: mobile) {
    body {
        -webkit-text-size-adjust: 100%;
    }
    
    .chat-input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
}

/* 安全区域适配（适用于iPhone X及以上机型） */
@supports (padding: max(0px)) {
    .chat-input-container {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .sidebar {
        padding-top: env(safe-area-inset-top);
    }
}

/* 修复微信内置浏览器的滚动问题 */
.wechat-browser .chat-messages {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
}

/* 修复移动端点击延迟 */
* {
    touch-action: manipulation;
}

/* 优化移动端字体大小 */
@media screen and (max-width: 768px) {
    html {
        font-size: 15px;
    }
}

/* 优化移动端文件上传区域 */
@media screen and (max-width: 768px) {
    .upload-area {
        padding: 15px;
    }
    
    .file-upload-content h3 {
        font-size: 16px;
    }
}

/* 优化移动端按钮和交互元素 */
@media screen and (max-width: 768px) {
    .btn, .input-tool-btn, .chat-send-btn {
        min-height: 44px; /* 确保触摸区域足够大 */
    }
    
    .suggestion-chip {
        padding: 8px 12px;
        margin: 4px;
    }
}

/* 修复安卓WebView中的一些渲染问题 */
@media screen and (-webkit-min-device-pixel-ratio:0) {
    .chat-messages {
        will-change: transform;
    }
    
    .message-container {
        backface-visibility: hidden;
    }
}

/* 优化移动端动画效果，减少资源消耗 */
@media screen and (max-width: 768px) {
    .message-container {
        animation: none;
    }
}

/* 页面加载动画样式 */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.page-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(74, 108, 247, 0.2);
    border-top: 5px solid var(--primary-color, #4a6cf7);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader-text {
    margin-top: 20px;
    font-size: 18px;
    font-weight: 600;
    color: var(--primary-color, #4a6cf7);
    letter-spacing: 2px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
} 