/* ========================================
   移动端增强优化样式 (Mobile Enhanced Styles)
   优化日期: 2025-11-28
   ======================================== */

/* ==================== 基础移动端优化 (小屏手机 ≤480px) ==================== */
@media (max-width: 480px) {

    /* ===== 1. 表格优化 - 横向滚动容器 ===== */
    .table-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 16px;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .table-container table {
        min-width: 640px; /* 确保表格有最小宽度，允许横向滚动 */
    }

    /* 表格单元格优化 */
    table th,
    table td {
        padding: 12px 8px !important;
        font-size: 14px !important;
    }

    /* 缩略图列优化 */
    table td img {
        max-width: 60px !important;
        max-height: 60px !important;
    }

    /* 操作按钮列优化 */
    table .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        min-width: 120px;
    }

    table .action-buttons .btn {
        min-width: 36px;
        min-height: 36px;
        padding: 6px 10px;
        font-size: 13px;
    }

    /* ===== 2. 按钮和触控优化 ===== */
    /* 所有可点击元素最小触控区域 44x44px (Apple HIG标准) */
    button,
    .btn,
    a.btn,
    input[type="button"],
    input[type="submit"],
    .clickable {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 16px;
        font-size: 15px;
        touch-action: manipulation; /* 防止双击缩放 */
    }

    /* 小型图标按钮 */
    .btn-icon-only {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }

    /* 按钮组间距 */
    .btn-group button + button,
    .action-buttons button + button {
        margin-left: 8px;
    }

    /* ===== 3. 导航栏优化 ===== */
    .navbar,
    .header {
        padding: 12px 16px !important;
        min-height: 56px;
    }

    .header h1 {
        font-size: 20px !important;
        margin: 0;
    }

    /* 统计徽章优化 - 缩小并横向排列 */
    .stats-badges {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 4px 0;
    }

    .stat-badge {
        flex-shrink: 0;
        min-width: 70px;
        padding: 6px 10px !important;
        font-size: 12px !important;
    }

    .stat-badge .stat-value {
        font-size: 16px !important;
    }

    .stat-badge .stat-label {
        font-size: 11px !important;
    }

    /* ===== 4. 工具栏和操作栏优化 ===== */
    .toolbar {
        flex-direction: column;
        gap: 12px;
        padding: 12px !important;
    }

    .toolbar-group {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }

    .toolbar-group .btn {
        width: 100%;
        justify-content: center;
    }

    /* 批量操作下拉菜单 */
    .dropdown-menu {
        width: 100%;
        max-height: 60vh;
        overflow-y: auto;
    }

    /* ===== 5. 模态框和对话框优化 ===== */
    .modal {
        padding: 8px !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 95vh;
        margin: 0 !important;
        border-radius: 12px;
        overflow-y: auto;
    }

    .modal-header {
        padding: 16px !important;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        border-bottom: 1px solid #e0e0e0;
    }

    .modal-body {
        padding: 16px !important;
        max-height: calc(95vh - 140px);
        overflow-y: auto;
    }

    .modal-footer {
        padding: 12px 16px !important;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e0e0e0;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 100px;
    }

    /* ===== 6. 表单输入优化 ===== */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px !important; /* 防止iOS自动缩放 */
        padding: 10px 12px;
        border-radius: 8px;
    }

    textarea {
        min-height: 120px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 14px;
        margin-bottom: 6px;
        display: block;
    }

    /* 负面提示词预设按钮优化 */
    .form-group div[style*="flex-wrap"] {
        gap: 6px !important;
    }

    .form-group div[style*="flex-wrap"] small {
        width: 100% !important;
        margin-bottom: 4px !important;
    }

    .form-group div[style*="flex-wrap"] button.btn-sm {
        flex: 1 1 calc(50% - 6px) !important;
        min-height: 38px !important;
        white-space: nowrap !important;
        padding: 8px 12px !important;
        font-size: 12px !important;
    }

    /* 负面提示词显示优化 */
    td div[style*="border-left: 3px solid #ff9800"] {
        font-size: 11px !important;
        padding: 4px 6px !important;
        margin-top: 4px !important;
        line-height: 1.4 !important;
    }

    /* ===== 7. 卡片/网格视图优化 ===== */
    .grid-list {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .grid-item,
    .grid-card-enhanced {
        min-height: 200px;
        padding: 12px;
    }

    .grid-item img {
        max-height: 180px;
        object-fit: cover;
    }

    /* 卡片操作按钮 */
    .grid-item .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin-top: 12px;
    }

    .grid-item .btn {
        flex: 1;
        min-width: 80px;
        font-size: 13px;
        padding: 8px 12px;
    }

    /* ===== 8. 侧边栏优化 ===== */
    .sidebar {
        position: fixed;
        top: 56px;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: calc(100vh - 56px);
        background: white;
        z-index: 1100;
        transition: left 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.open {
        left: 0;
    }

    /* 侧边栏遮罩层 */
    .sidebar-overlay {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1050;
        display: none;
        backdrop-filter: blur(2px);
    }

    /* 侧边栏面板 */
    .sidebar .panel {
        margin-bottom: 12px;
    }

    .sidebar .panel-header {
        padding: 12px;
        cursor: pointer;
        user-select: none;
    }

    .sidebar .panel-content {
        padding: 12px;
    }

    /* ===== 9. 工作区优化 ===== */
    .workspace {
        padding: 12px !important;
        width: 100%;
    }

    /* ===== 10. 进度条和状态指示器 ===== */
    .progress-container {
        margin: 12px 0;
    }

    .progress-bar {
        height: 8px;
        border-radius: 4px;
    }

    .status-badge {
        font-size: 12px;
        padding: 4px 8px;
    }

    /* ===== 11. 图片预览优化 ===== */
    .image-preview {
        max-width: 100%;
        max-height: 50vh;
        object-fit: contain;
    }

    /* ===== 12. 选择框和复选框优化 ===== */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
        cursor: pointer;
    }

    /* ===== 13. Tab标签页优化 ===== */
    .tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid #e0e0e0;
    }

    .tab-btn {
        flex-shrink: 0;
        min-width: 100px;
        padding: 12px 16px;
        font-size: 14px;
        white-space: nowrap;
    }

    /* ===== 14. 提示和帮助文本 ===== */
    .hint-text,
    .help-text {
        font-size: 13px;
        line-height: 1.5;
        margin-top: 6px;
    }

    /* ===== 15. 滚动优化 ===== */
    .scrollable {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* ===== 16. 避免文本选择干扰触控 ===== */
    .no-select {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* ==================== 中等尺寸移动设备 (481px - 768px) ==================== */
@media (max-width: 768px) and (min-width: 481px) {

    /* 表格优化 */
    .table-container table {
        min-width: 100%;
    }

    table th,
    table td {
        padding: 10px !important;
        font-size: 14px !important;
    }

    /* 按钮优化 */
    button,
    .btn {
        min-height: 40px;
        padding: 8px 14px;
        font-size: 14px;
    }

    /* 负面提示词预设按钮 - 平板优化 (3列) */
    .form-group div[style*="flex-wrap"] button.btn-sm {
        flex: 1 1 calc(33.33% - 6px) !important;
        min-height: 36px !important;
    }

    /* 网格视图 - 2列 */
    .grid-list {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }

    /* 模态框 */
    .modal-content {
        width: 95%;
        max-width: 600px;
    }

    /* 侧边栏 */
    .sidebar {
        width: 300px;
    }

    /* 导航栏 */
    .header h1 {
        font-size: 24px !important;
    }
}

/* ==================== 横屏模式优化 ==================== */
@media (max-width: 768px) and (orientation: landscape) {

    /* 模态框在横屏时优化 */
    .modal-content {
        max-height: 90vh;
    }

    .modal-body {
        max-height: calc(90vh - 120px);
    }

    /* 侧边栏在横屏时宽度调整 */
    .sidebar {
        width: 60%;
        max-width: 400px;
    }
}

/* ==================== 触控设备通用优化 ==================== */
@media (hover: none) and (pointer: coarse) {

    /* 增加所有可点击元素的触控反馈 */
    button:active,
    .btn:active,
    a:active {
        transform: scale(0.98);
        opacity: 0.8;
    }

    /* 移除hover效果，避免点击后的粘滞 */
    button:hover,
    .btn:hover {
        transform: none;
    }
}

/* ==================== 模型管理器优化 ==================== */
@media (max-width: 768px) {
    /* 手动添加模型区域 - 垂直布局 */
    #modelManager .modal-content > div > div:nth-child(4) > div:first-child {
        flex-direction: column !important;
    }

    #modelManager .modal-content > div > div:nth-child(4) > div:first-child input,
    #modelManager .modal-content > div > div:nth-child(4) > div:first-child button {
        width: 100% !important;
        flex: none !important;
    }

    /* 批量添加区域 */
    #modelManager .modal-content > div > div:nth-child(4) > div:nth-child(2) {
        flex-direction: column !important;
    }

    #modelManager .modal-content > div > div:nth-child(4) > div:nth-child(2) textarea {
        width: 100% !important;
        flex: none !important;
        margin-bottom: 10px;
    }

    #modelManager .modal-content > div > div:nth-child(4) > div:nth-child(2) button {
        width: 100% !important;
    }

    /* 测试API按钮区域 */
    #modelManager button.btn {
        min-width: 120px;
    }

    /* 发现的模型操作按钮 */
    #discoveredActions {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    #discoveredActions button {
        flex: 1 1 45% !important;
        min-width: 100px !important;
    }

    /* 搜索框操作按钮组 */
    #discoveredSearchBox > div {
        flex-direction: column !important;
    }

    #discoveredSearchBox input {
        width: 100% !important;
        margin-bottom: 8px !important;
    }

    #discoveredSearchBox button {
        width: 100% !important;
    }

    /* 提示框优化 */
    #modelManager [style*="border-left"] {
        font-size: 12px !important;
        padding: 12px 14px !important;
    }

    /* 模型列表项 */
    #discoveredModels > div,
    #customModelsList > div {
        padding: 12px !important;
        font-size: 13px !important;
    }

    /* 已添加模型标题栏 - 新布局 */
    #modelManager > div > div:last-child > div:first-child {
        padding: 12px 14px !important;
    }

    #modelManager > div > div:last-child > div:first-child > div {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    #modelManager > div > div:last-child > div:first-child button {
        width: 100% !important;
        margin-top: 12px !important;
    }

    /* 搜索框图标和输入框 */
    #modelManager input[id*="Search"] {
        padding-left: 42px !important;
        font-size: 14px !important;
    }

    /* 模型列表容器 */
    #customModelsList {
        max-height: 250px !important;
        padding: 8px !important;
    }

    /* 模型网格布局 - 移动端单列 */
    #customModelsList > div {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* 模型卡片优化 */
    .model-card {
        padding: 14px !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .model-card button {
        padding: 10px 14px !important;
        font-size: 14px !important;
    }

    .model-card div[style*="Courier"] {
        font-size: 11px !important;
        padding: 5px 8px !important;
        max-width: 100% !important;
        word-break: break-all !important;
    }
}

/* 平板设备优化 */
@media (min-width: 481px) and (max-width: 768px) {
    #discoveredActions button {
        flex: 1 1 22% !important;
    }

    #discoveredSearchBox > div {
        flex-direction: row !important;
    }

    #discoveredSearchBox input {
        margin-bottom: 0 !important;
    }

    #discoveredSearchBox button {
        width: auto !important;
        flex: 0 0 auto !important;
    }

    /* 模型网格布局 - 平板2列 */
    #customModelsList > div {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .model-card {
        min-width: 0 !important;
    }
}

/* 中等屏幕优化 */
@media (min-width: 769px) and (max-width: 1199px) {
    /* 模型网格布局 - 2列或3列自适应 */
    #customModelsList > div {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)) !important;
        gap: 14px !important;
    }
}

/* 大屏设备优化 */
@media (min-width: 1200px) {
    /* 模型网格布局 - 大屏3列 */
    #customModelsList > div {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 16px !important;
    }
}

/* ==================== 辅助功能优化 ==================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
