/**
 * 移动端适配样式
 * 优化手机和平板的显示效果
 */

/* ==================== 通用移动端优化 ==================== */

/* 禁止文本选择（移动端体验更好） */
@media (max-width: 768px) {
    body {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /* 但允许输入框选择 */
    }
    
    input, textarea {
        -webkit-user-select: auto;
        -moz-user-select: auto;
        -ms-user-select: auto;
        user-select: auto;
    }
}

/* 触摸反馈优化 */
@media (max-width: 768px) {
    button, .btn, .option-card, .card, a {
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
        touch-action: manipulation;
    }
    
    /* 防止双击放大 */
    * {
        touch-action: pan-y;
    }
    
    input, textarea, select {
        touch-action: auto;
    }
}

/* ==================== 平板适配 (768px - 1024px) ==================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .params-container {
        margin: 20px;
        padding: 30px;
    }
    
    .options-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .params-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .nav-center h1 {
        font-size: 1.3rem;
    }
}

/* ==================== 手机适配 (max-width: 768px) ==================== */

@media (max-width: 768px) {
    /* 导航栏优化 */
    .navbar {
        padding: 12px 15px;
        min-height: 56px;
    }
    
    .nav-brand {
        font-size: 1.3rem;
    }
    
    .nav-center h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .step-indicator {
        font-size: 0.9rem;
        padding: 6px 12px;
    }
    
    /* 主容器优化 */
    .params-container {
        margin: 8px;
        padding: 15px;
        height: calc(100vh - 140px);
        border-radius: 15px;
    }
    
    /* 步骤容器优化 */
    .step-container {
        padding: 15px;
        border-radius: 12px;
    }
    
    /* 标题优化 */
    .step-title {
        font-size: 1.2rem;
        margin-bottom: 12px;
    }
    
    .step-subtitle {
        font-size: 0.85rem;
        margin-bottom: 15px;
    }
    
    /* 选项网格 - 单列布局 */
    .options-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* 选项卡片优化 */
    .option-card {
        padding: 15px;
        border-radius: 12px;
        min-height: auto;
    }
    
    .option-card .option-text {
        font-size: 0.95rem;
    }
    
    .option-card .option-label {
        font-size: 0.85rem;
    }
    
    /* 参数网格 - 单列布局 */
    .params-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* 参数卡片优化 */
    .param-card {
        padding: 15px;
        border-radius: 12px;
    }
    
    .param-label {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }
    
    /* 输入框优化 */
    input[type="text"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* 防止iOS自动放大 */
        padding: 12px 15px;
        border-radius: 10px;
    }
    
    textarea {
        min-height: 100px;
    }
    
    /* 按钮优化 - 更大的触摸区域 */
    button, .btn {
        min-height: 44px; /* iOS推荐的最小触摸区域 */
        padding: 12px 20px;
        font-size: 1rem;
        border-radius: 12px;
    }
    
    /* 底部配置按钮优化 - 移动端更紧凑 */
    .btn-apply-config,
    .btn-save-config,
    .btn-generate,
    .right-buttons button {
        min-height: 40px !important;
        padding: 8px 14px !important;
        font-size: 0.88rem !important;
        margin-bottom: 6px !important;
        line-height: 1.3 !important;
    }
    
    /* 按钮中的SVG图标更小 */
    .btn-generate svg {
        width: 16px !important;
        height: 16px !important;
        margin-left: 4px !important;
    }
    
    /* 返回按钮也适当缩小 */
    .btn-cancel {
        min-height: 40px !important;
        padding: 8px 14px !important;
        font-size: 0.88rem !important;
    }
    
    /* 底部操作栏优化 */
    .action-bar {
        height: auto;
        min-height: 65px;
        padding: 10px 0;
    }
    
    .action-bar-content {
        padding: 0 12px;
        flex-direction: column;
        gap: 8px;
    }
    
    .left-info {
        width: 100%;
        justify-content: center;
        margin-bottom: 3px;
    }
    
    .right-buttons {
        width: 100%;
        justify-content: stretch;
        gap: 6px;
    }
    
    .right-buttons button {
        flex: 1;
        min-width: 0;
    }
    
    /* 用户信息卡片 */
    .user-info {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
    
    .credits-display {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
}

/* ==================== 小屏手机适配 (max-width: 480px) ==================== */

@media (max-width: 480px) {
    /* 更紧凑的导航栏 */
    .navbar {
        padding: 10px 12px;
    }
    
    .nav-brand {
        font-size: 1.2rem;
    }
    
    .nav-center h1 {
        font-size: 1rem;
    }
    
    .step-indicator {
        font-size: 0.8rem;
        padding: 5px 10px;
    }
    
    /* 更紧凑的容器 */
    .params-container {
        margin: 5px;
        padding: 12px;
        border-radius: 12px;
    }
    
    .step-container {
        padding: 12px;
    }
    
    /* 更小的字体 */
    .step-title {
        font-size: 1.1rem;
    }
    
    .step-subtitle {
        font-size: 0.8rem;
    }
    
    .option-card .option-text {
        font-size: 0.9rem;
    }
    
    .param-label {
        font-size: 0.85rem;
    }
    
    /* 按钮文字可能需要换行 */
    .right-buttons {
        flex-direction: column;
    }
    
    .right-buttons button {
        width: 100%;
    }
    
    /* 小屏手机上按钮更紧凑 */
    .btn-apply-config,
    .btn-save-config,
    .btn-generate,
    .right-buttons button {
        min-height: 36px !important;
        padding: 6px 12px !important;
        font-size: 0.82rem !important;
        margin-bottom: 5px !important;
        line-height: 1.2 !important;
    }
    
    /* SVG图标更小 */
    .btn-generate svg {
        width: 14px !important;
        height: 14px !important;
        margin-left: 3px !important;
    }
    
    /* 返回按钮 */
    .btn-cancel {
        min-height: 36px !important;
        padding: 6px 12px !important;
        font-size: 0.82rem !important;
    }
    
    /* 操作栏更紧凑 */
    .action-bar {
        min-height: 60px;
        padding: 8px 0;
    }
    
    .action-bar-content {
        padding: 0 10px;
        gap: 6px;
    }
}

/* ==================== 模态框移动端优化 ==================== */

@media (max-width: 768px) {
    /* 模态框占满屏幕 */
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        margin: 5vh auto;
        border-radius: 15px;
        padding: 20px;
    }
    
    .modal-header {
        padding: 15px;
        border-radius: 12px 12px 0 0;
    }
    
    .modal-header h2 {
        font-size: 1.2rem;
    }
    
    .modal-body {
        padding: 15px;
        max-height: calc(90vh - 140px);
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-footer button {
        width: 100%;
    }
    
    /* 配置管理弹窗 */
    #configModal .modal-content {
        width: 98%;
        max-height: 85vh;
    }
    
    #configList {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .config-item {
        padding: 15px;
        border-radius: 12px;
    }
    
    /* 配置编辑弹窗 */
    #configEditModal .modal-content {
        width: 95%;
    }
    
    #configEditModal input,
    #configEditModal textarea {
        font-size: 16px !important;
    }
}

/* ==================== 图片上传页面移动端优化 ==================== */

@media (max-width: 768px) {
    .upload-container {
        margin: 10px;
        padding: 20px;
    }
    
    .upload-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .image-slot {
        min-height: 200px;
    }
    
    .upload-tips {
        padding: 15px;
        font-size: 0.85rem;
    }
    
    .upload-tips li {
        margin-bottom: 8px;
    }
}

/* ==================== 视频历史页面移动端优化 ==================== */

@media (max-width: 768px) {
    .video-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 10px;
    }
    
    .video-card {
        border-radius: 12px;
    }
    
    .video-thumbnail {
        height: 200px;
        border-radius: 12px 12px 0 0;
    }
    
    .video-info {
        padding: 15px;
    }
    
    .video-title {
        font-size: 1rem;
    }
    
    .video-meta {
        font-size: 0.8rem;
    }
}

/* ==================== 管理员面板移动端优化 ==================== */

@media (max-width: 768px) {
    .admin-panel {
        padding: 10px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
        border-radius: 12px;
    }
    
    .data-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .data-table {
        min-width: 600px;
        font-size: 0.85rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
    }
}

/* ==================== 主页移动端优化 ==================== */

@media (max-width: 768px) {
    /* 全屏英雄区 */
    .hero-fullscreen {
        height: 100vh;
    }
    
    .hero-title-large {
        font-size: 2.5rem;
        line-height: 1.2;
    }
    
    .hero-subtitle {
        font-size: 1rem;
        margin: 20px 0;
    }
    
    .cta-buttons {
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }
    
    .cta-buttons .btn {
        width: 100%;
        padding: 15px 30px;
    }
    
    /* 特色卡片 */
    .featured-cards {
        position: static;
        display: grid;
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 20px;
        margin-top: 30px;
    }
    
    .featured-card {
        width: 100%;
        border-radius: 15px;
    }
    
    /* 顶部导航 */
    .top-navbar {
        padding: 15px 20px;
    }
    
    .navbar-menu {
        display: none; /* 移动端隐藏菜单 */
    }
    
    .navbar-brand {
        font-size: 1.5rem;
    }
}

/* ==================== 横屏手机优化 ==================== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero-fullscreen {
        height: 100vh;
    }
    
    .hero-title-large {
        font-size: 2rem;
    }
    
    .hero-subtitle {
        font-size: 0.9rem;
        margin: 15px 0;
    }
    
    .params-container {
        height: calc(100vh - 120px);
    }
    
    .modal-content {
        max-height: 80vh;
    }
}

/* ==================== 触摸设备优化 ==================== */

@media (hover: none) and (pointer: coarse) {
    /* 移除hover效果，使用active效果 */
    .option-card:hover,
    .param-card:hover,
    button:hover {
        transform: none;
    }
    
    .option-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    button:active {
        transform: scale(0.97);
        opacity: 0.85;
    }
    
    /* 更大的触摸区域 */
    .option-card,
    .param-card {
        min-height: 60px;
    }
    
    /* 更明显的选中状态 */
    .option-card.selected {
        border-width: 3px;
    }
}

/* ==================== 安全区域适配 (iPhone X+) ==================== */

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        body {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
        
        .navbar {
            padding-top: max(12px, env(safe-area-inset-top));
        }
        
        .action-bar {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* ==================== 禁用缩放 (可选) ==================== */

@media (max-width: 768px) {
    /* 已在HTML的viewport meta中设置 */
    /* <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> */
}

/* ==================== 滚动优化 ==================== */

@media (max-width: 768px) {
    /* 平滑滚动 */
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 自定义滚动条（移动端可能不显示） */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(102, 126, 234, 0.5);
        border-radius: 2px;
    }
}

/* ==================== 性能优化 ==================== */

@media (max-width: 768px) {
    /* 减少动画以提升性能 */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* GPU加速 */
    .option-card,
    .param-card,
    .modal-content,
    button {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}
