/* 手机端适配 - 奶白风格 */
@media (max-width: 768px) {
    /* 防止模态框打开时背景滚动 */
    body.modal-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    .header {
        padding: 1.2rem 1rem;
        background: linear-gradient(135deg, var(--ivory-color) 0%, var(--cream-color) 100%);
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .main-container {
        flex-direction: column;
        height: calc(100vh - 70px);
    }
    
    
    
    
    
    
    
    
    .chat-section {
        flex: 1;
    }
    
    .input-section {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 0.75rem 1rem;
        background: linear-gradient(to top, var(--cream-color), var(--milk-color));
        border-top: 1px solid var(--border-color);
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        min-height: 80px; /* 固定输入区高度 */
    }
    
    .chat-container {
        padding: 0.75rem;
        padding-bottom: 100px; /* 为固定底部输入区域留出空间 */
        height: calc(100vh - 70px - 80px); /* 减去头部和输入区高度 */
        overflow-y: auto;
    }
    
    .chat-input {
        flex-direction: row;
        gap: 0.5rem;
        align-items: flex-end;
        max-width: none;
        margin: 0;
    }
    
    .chat-input > div {
        display: flex;
        gap: 0.5rem;
        align-items: flex-end;
        width: 100%;
    }
    
    .input-field {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 0.75rem 1rem;
        border-radius: 16px;
        flex: 1;
        min-height: 48px;
        max-height: 48px; /* 限制最大高度保持一致 */
        resize: none; /* 移动端禁用手动调整大小 */
        line-height: 1.2;
    }
    
    .voice-record-btn {
        padding: 0.75rem;
        min-width: 48px;
        min-height: 48px;
        max-height: 48px; /* 与输入框保持一致 */
        border-radius: 16px;
        flex-shrink: 0;
    }
    
    #send-btn {
        padding: 0.75rem 1rem;
        min-height: 48px;
        max-height: 48px; /* 与输入框保持一致 */
        border-radius: 16px;
        flex-shrink: 0;
    }
    
    .btn {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        min-height: 48px;
        max-height: 48px;
        border-radius: 16px;
    }
    
    .message {
        margin-left: 5% !important;
        margin-right: 5% !important;
        padding: 1rem;
        border-radius: 16px;
    }
    
    .message.user {
        margin-left: 30% !important;
    }
    
    .message.assistant {
        margin-right: 15% !important;
    }
    
    .message-avatar {
        width: 10px;
        height: 10px;
        font-size: 0.6rem;
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .btn-icon {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }
    
    .modal-content {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        overflow-y: auto;
        position: relative;
        display: flex;
        flex-direction: column;
    }
    
    /* 模态框头部固定 */
    .modal-content > h2 {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding: 1.5rem 1rem 1rem;
        margin: 0;
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    /* 关闭按钮优化 */
    .modal-content .close {
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 20;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        color: var(--text-color);
        cursor: pointer;
        backdrop-filter: blur(10px);
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    /* 模态框内容区域可滚动 */
    .modal-content > *:not(h2):not(.close) {
        padding-left: 1rem;
        padding-right: 1rem;
        flex-shrink: 0;
    }
    
    /* 确保内容区域有足够的底部间距 */
    .modal-content::after {
        content: '';
        height: 2rem;
        flex-shrink: 0;
    }
}

/* 小屏手机适配 */
@media (max-width: 480px) {
    .header {
        padding: 0.75rem;
    }
    
    .header h1 {
        font-size: 1.1rem;
    }
    
    .main-container {
        height: calc(100vh - 60px); /* 适应小屏头部高度 */
    }
    
    
    
    
    
    
    
    .chat-container {
        padding: 0.75rem;
        padding-bottom: 80px; /* 为小屏手机调整底部间距 */
        height: calc(100vh - 60px - 70px); /* 减去头部和输入区高度 */
        overflow-y: auto;
    }
    
    .messages {
        gap: 0.75rem;
        padding-bottom: 1rem; /* 为最后一条消息添加底部间距 */
    }
    
    .message {
        padding: 0.75rem; /* 增加内边距使消息更易阅读 */
        font-size: 0.95rem; /* 稍微增大字体 */
        line-height: 1.4;
        border-radius: 18px; /* 更圆润的边角 */
    }
    
    .input-section {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 0.5rem 0.75rem;
        background: linear-gradient(to top, var(--cream-color), var(--milk-color));
        border-top: 1px solid var(--border-color);
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        min-height: 70px; /* 小屏输入区高度 */
    }
    
    .btn {
        padding: 0.6rem;
        font-size: 0.9rem;
        min-height: 44px;
        max-height: 44px; /* 限制最大高度 */
        border-radius: 12px; /* 小屏适应更小的圆角 */
    }
    
    .input-field {
        padding: 0.6rem 0.8rem;
        min-height: 44px;
        max-height: 44px; /* 限制最大高度 */
        border-radius: 12px;
        font-size: 16px;
        resize: none;
        line-height: 1.2;
    }
    
    .voice-record-btn {
        padding: 0.6rem;
        min-width: 44px;
        min-height: 44px;
        max-height: 44px;
        border-radius: 12px;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .modal-content {
        padding: 0;
    }
    
    .modal-content > h2 {
        padding: 1rem 0.75rem 0.75rem;
        font-size: 1.1rem;
    }
    
    .modal-content .close {
        top: 0.75rem;
        right: 0.75rem;
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
    }
    
    .modal-content > *:not(h2):not(.close) {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    
    
    
    
    
}

/* 横屏适配 */
@media (max-width: 768px) and (orientation: landscape) {
    .main-container {
        flex-direction: row;
    }
    
    
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
        box-shadow: none;
    }
    
    .btn:active {
        transform: scale(0.95);
    }
    
    .message-actions {
        opacity: 1;
    }
    
    .action-btn:hover {
        background: none;
        border-color: var(--border-color);
    }
    
    .action-btn:active {
        background: var(--light-color);
        border-color: var(--primary-color);
    }
}

/* 高DPI屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    
    .message {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
}

/* 移动端聊天背景优化 */
@media (max-width: 768px) {
    .background-preview {
        height: 80px;
    }
    
    .chat-background {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        z-index: 0 !important;
    }
    
    .chat-background img,
    .chat-background video {
        object-fit: cover;
    }
    
    .chat-container.has-background::before {
        background: rgba(255, 255, 255, 0.4) !important;
    }
    
    .background-upload-input {
        font-size: 0.85rem;
        padding: 0.75rem !important;
    }
    
    .setting-group h3 {
        font-size: 1rem;
    }
    
    .background-preview .preview-placeholder {
        font-size: 0.8rem;
    }
    
    /* 移动端头部透明效果 */
    body.has-chat-background .header {
        background: rgba(255, 255, 255, 0.9) !important;
        backdrop-filter: blur(10px);
    }
    
    /* 移动端输入区域透明效果 */
    body.has-chat-background .input-section {
        background: rgba(255, 255, 255, 0.85) !important;
        backdrop-filter: blur(10px);
    }
}