/* 全局移动端适配修复 - 彻底解决手机端布局问题 */

/* 确保 viewport 生效 */
@viewport {
    width: device-width;
    zoom: 1.0;
}

/* 禁止页面缩放 */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* 基础移动端样式 - 针对聊天室 */
@media screen and (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
    }
    
    body {
        font-size: 16px !important;
        overflow: hidden;
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    /* 主聊天区域 */
    .main-chat {
        width: 100%;
    }
    
    /* 顶部标题栏修复 */
    .chat-header {
        padding: 0.75rem 1rem !important;
        min-height: 60px;
        flex-wrap: nowrap;
    }
    
    .chat-header-info {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        min-width: 0;
    }
    
    .chat-header-info h1 {
        font-size: 1.1rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .chat-header-info span {
        font-size: 0.75rem !important;
        display: block !important;
    }
    
    .header-actions {
        gap: 0.375rem;
        flex-shrink: 0;
    }
    
    .header-btn {
        width: 36px !important;
        height: 36px !important;
        border-radius: 10px;
    }
    
    .auth-btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
        min-height: 36px;
    }
    
    .user-menu-btn {
        padding: 0.375rem 0.75rem !important;
        font-size: 0.8rem !important;
    }
    
    .user-avatar {
        width: 28px !important;
        height: 28px !important;
    }
    
    /* 聊天容器 */
    #chat-container {
        padding: 0.75rem !important;
    }
    
    /* 消息区域 */
    #chat-messages {
        padding: 0.5rem 0 !important;
    }
    
    .message {
        gap: 0.625rem;
        margin-bottom: 0.875rem;
    }
    
    .message-avatar {
        width: 36px !important;
        height: 36px !important;
        border-radius: 10px;
        font-size: 0.9rem;
    }
    
    .message-bubble {
        max-width: 75% !important;
        padding: 0.625rem 0.875rem !important;
        font-size: 0.95rem;
        border-radius: 14px;
    }
    
    .message-media {
        max-width: 200px !important;
        max-height: 200px !important;
    }
    
    /* 输入框区域 - 关键修复 */
    #message-form-container {
        padding: 0.75rem !important;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    #message-form {
        gap: 0.375rem;
    }
    
    #input-wrapper {
        padding: 0.375rem !important;
        border-radius: 14px;
    }
    
    #message-input {
        font-size: 16px !important;
        padding: 0.5rem !important;
        min-height: 44px;
        max-height: 120px;
    }
    
    .action-button {
        width: 32px !important;
        height: 32px !important;
        font-size: 1rem;
    }
    
    #send-button {
        width: 36px !important;
        height: 36px !important;
        border-radius: 10px;
    }
    
    /* 表情选择器 */
    #emoji-picker {
        width: calc(100% - 2rem) !important;
        right: 1rem !important;
        left: 1rem !important;
        max-height: 280px;
        bottom: 90px !important;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr) !important;
    }
    
    .emoji-item {
        width: 40px !important;
        height: 40px !important;
    }
    
    /* 下拉菜单 */
    .theme-dropdown, .user-dropdown {
        right: 0 !important;
        left: auto !important;
        min-width: 160px;
    }
    
    /* 上传进度 */
    .upload-progress-overlay {
        min-width: auto !important;
        width: calc(100% - 2rem) !important;
        left: 1rem !important;
        right: 1rem !important;
        transform: none !important;
        bottom: 100px !important;
    }
    
    /* 图片查看器 */
    .lightbox-content {
        max-width: 95% !important;
        max-height: 80% !important;
    }
    
    .close-lightbox {
        width: 48px !important;
        height: 48px !important;
        top: 15px !important;
        right: 15px !important;
    }
}

/* 小屏手机适配 */
@media screen and (max-width: 480px) {
    body {
        font-size: 15px !important;
    }
    
    .chat-header {
        padding: 0.625rem 0.875rem !important;
        min-height: 56px;
    }
    
    .chat-header-info h1 {
        font-size: 1rem !important;
    }
    
    .chat-header-info span {
        font-size: 0.7rem !important;
    }
    
    .header-btn {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.9rem;
    }
    
    .auth-btn {
        padding: 0.375rem 0.625rem !important;
        font-size: 0.8rem !important;
    }
    
    #chat-container {
        padding: 0.5rem !important;
    }
    
    .message {
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    
    .message-avatar {
        width: 32px !important;
        height: 32px !important;
        border-radius: 8px;
        font-size: 0.8rem;
    }
    
    .message-bubble {
        max-width: 80% !important;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.9rem;
        border-radius: 12px;
    }
    
    .message-media {
        max-width: 160px !important;
        max-height: 160px !important;
    }
    
    #message-form-container {
        padding: 0.625rem !important;
        padding-bottom: calc(0.625rem + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    #input-wrapper {
        padding: 0.25rem !important;
        border-radius: 12px;
    }
    
    #message-input {
        font-size: 16px !important;
        padding: 0.375rem !important;
        min-height: 44px;
    }
    
    .action-button {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.95rem;
    }
    
    #send-button {
        width: 34px !important;
        height: 34px !important;
        border-radius: 10px;
    }
    
    #emoji-picker {
        width: calc(100% - 1rem) !important;
        right: 0.5rem !important;
        left: 0.5rem !important;
        max-height: 260px;
        bottom: 85px !important;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 0.25rem;
        padding: 0.375rem;
    }
    
    .emoji-item {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.4rem;
    }
    
    .empty-state i {
        font-size: 3rem !important;
    }
    
    .empty-state h3 {
        font-size: 1.1rem !important;
    }
    
    .time-label {
        font-size: 0.7rem !important;
        padding: 0.2rem 0.625rem !important;
    }
}

/* 超小屏手机 */
@media screen and (max-width: 360px) {
    .chat-header-info h1 {
        font-size: 0.9rem !important;
    }
    
    .header-btn {
        width: 32px !important;
        height: 32px !important;
    }
    
    .message-bubble {
        max-width: 85% !important;
        font-size: 0.875rem;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(5, 1fr) !important;
    }
    
    .emoji-item {
        width: 40px !important;
        height: 40px !important;
    }
}

/* 横屏适配 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .chat-header {
        padding: 0.5rem 0.875rem !important;
        min-height: 50px;
    }
    
    .chat-header-info h1 {
        font-size: 1rem !important;
    }
    
    #chat-container {
        padding: 0.375rem !important;
    }
    
    .message {
        margin-bottom: 0.5rem;
        gap: 0.5rem;
    }
    
    .message-avatar {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem;
    }
    
    .message-bubble {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.9rem;
        max-width: 70% !important;
    }
    
    #message-form-container {
        padding: 0.5rem !important;
    }
    
    #message-input {
        min-height: 40px;
    }
    
    .action-button {
        width: 36px !important;
        height: 36px !important;
    }
    
    #send-button {
        width: 40px !important;
        height: 40px !important;
    }
    
    #emoji-picker {
        max-height: 200px;
        bottom: 75px !important;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .header-btn, .action-button, #send-button, .auth-btn, .user-menu-btn, .dropdown-item, .theme-option, .emoji-item {
        -webkit-tap-highlight-color: transparent;
    }
    
    .header-btn:active, .action-button:active, #send-button:active {
        transform: scale(0.95);
    }
    
    #message-input {
        -webkit-appearance: none;
        border-radius: 12px;
    }
    
    /* 禁用hover效果 */
    .header-btn:hover, .action-button:hover, #send-button:hover {
        transform: none;
    }
}

/* iPhone安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #message-form-container {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
    }
}

/* 防止输入框被底部导航栏遮挡 */
@media screen and (max-width: 768px) {
    .main-chat {
        padding-bottom: 0;
    }
    
    /* 确保输入框始终在可视区域 */
    #message-form-container {
        position: relative;
        z-index: 100;
    }
}
