/* ========================================
   移动端响应式适配 - 不影响桌面端布局
   断点：≤768px 为移动端
   ======================================== */

/* ========================================
   1. 全局导航栏适配
   ======================================== */
@media (max-width: 768px) {
    /* 导航栏容器 */
    .navbar .container-fluid {
        padding: 0.5rem 1rem;
    }

    /* 导航栏高度压缩 */
    .navbar {
        min-height: 50px;
    }

    /* Logo 字体缩小 */
    .navbar-brand {
        font-size: 1rem !important;
    }

    /* 核心导航链接 - 横向滚动 */
    #navCoreLinks {
        gap: 0 2px !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex: 1;
        min-width: 0;
    }
    #navCoreLinks::-webkit-scrollbar {
        display: none;
    }

    .nav-core-link {
        font-size: 0.75rem !important;
        padding: 2px 6px !important;
        white-space: nowrap;
    }

    /* 隐藏 slogan */
    #navSlogan {
        display: none !important;
    }

    /* 主题按钮缩小 */
    .theme-dropdown .btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.75rem !important;
    }

    /* 主题菜单全宽 */
    .theme-menu {
        width: 100vw !important;
        right: -10px !important;
        left: auto !important;
        max-width: 100vw;
    }

    /* 导航菜单区域 */
    #navMenuLeft, #navMenuCenter, #navMenuRight {
        gap: 0 6px !important;
    }

    /* 导航菜单项字体 */
    .nav-menu-item {
        font-size: 0.75rem !important;
    }

    /* 下拉菜单宽度限制 */
    .nav-dropdown-menu {
        max-width: 200px;
        white-space: normal;
    }
}

/* ========================================
   2. AI 设计页面适配（四栏 → 单栏）
   ======================================== */
@media (max-width: 768px) {
    /* 主布局容器 */
    .design-layout {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* 侧边栏 - 顶部横向滚动 */
    .design-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        max-height: 120px;
        border-right: none !important;
        border-bottom: 2px solid var(--panel-border-color, #dee2e6);
        flex-shrink: 0;
    }

    .design-sidebar .sidebar-border {
        border: none !important;
        border-radius: 0 !important;
    }

    .design-sidebar .sidebar-inner {
        flex-direction: row !important;
        align-items: center !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        padding: 4px 8px !important;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .design-sidebar .sidebar-inner::-webkit-scrollbar {
        display: none;
    }

    .design-sidebar .sidebar-tools {
        flex-direction: row !important;
        flex: 0 0 auto !important;
        gap: 4px !important;
        padding: 0 !important;
    }

    /* 分类项横向排列 */
    .category-item {
        flex: 0 0 auto !important;
        flex-direction: column !important;
        padding: 4px 8px !important;
        min-width: 44px !important;
        gap: 2px !important;
    }
    .category-item .category-name {
        font-size: 0.6rem !important;
    }

    /* 模型网格保持3列但缩小 */
    .model-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 3px !important;
        max-height: 80px !important;
    }
    .model-grid-item {
        padding: 3px 2px !important;
    }
    .model-grid-icon,
    .model-grid-icon-placeholder {
        width: 20px !important;
        height: 20px !important;
    }
    .model-grid-name {
        font-size: 0.5rem !important;
    }

    /* 侧边栏底部操作区 */
    .design-sidebar .sidebar-footer {
        flex-direction: row !important;
        height: auto !important;
        padding: 4px !important;
        gap: 4px !important;
        flex-shrink: 0;
        border-top: none !important;
        border-left: 1px solid var(--panel-border-color, #dee2e6);
    }
    .design-sidebar .sidebar-divider {
        width: 1px !important;
        height: 24px !important;
        margin: 0 2px !important;
    }
    .design-sidebar .sidebar-footer-item {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.75rem !important;
    }

    /* 参数面板 - 全宽 */
    .design-param-panel {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        max-height: 300px;
        border-bottom: 2px solid var(--panel-border-color, #dee2e6);
    }

    /* 结果面板 - 主区域 */
    .design-result-panel {
        width: 100% !important;
        min-height: 300px;
        height: auto !important;
        border-bottom: 2px solid var(--panel-border-color, #dee2e6);
    }

    /* 历史记录面板 - 底部 */
    .design-history-panel {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        max-height: 200px;
    }

    /* 历史记录网格 */
    .history-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* 参数面板内容 */
    .param-tool-list {
        flex-wrap: wrap !important;
    }

    /* 工具列表项 */
    .param-tool-item {
        font-size: 0.65rem !important;
        padding: 3px 6px !important;
    }

    /* 上传区域 */
    .upload-area {
        padding: 8px !important;
    }

    /* 参考图网格 */
    .reference-preview-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 结果图片 */
    .result-image {
        max-height: 50vh !important;
    }

    /* 收藏网格 */
    .favorites-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 侧边栏弹出菜单 */
    .sidebar-popup {
        left: auto !important;
        right: 8px !important;
        bottom: auto !important;
        top: 130px !important;
        width: 180px !important;
    }

    /* 隐藏积分显示，使用移动端积分 */
    .sidebar-credits {
        display: none !important;
    }
    .mobile-credits {
        display: flex !important;
    }
}

/* ========================================
   3. 批量工作台适配（三栏 → 单栏）
   ======================================== */
@media (max-width: 768px) {
    /* 顶部栏 */
    .batch-topbar {
        padding: 8px 12px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .batch-topbar h5 {
        font-size: 0.8rem !important;
    }
    .batch-topbar .badge {
        font-size: 0.5rem !important;
        padding: 2px 5px !important;
    }
    .batch-topbar .btn {
        font-size: 0.7rem !important;
        padding: 3px 8px !important;
    }

    /* 三栏变单栏 */
    .batch-layout {
        flex-direction: column !important;
        overflow-y: auto !important;
    }

    /* 左侧面板 - 顶部 */
    .batch-left-panel {
        width: 100% !important;
        min-width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid #e9ecef;
        padding: 8px !important;
        max-height: 150px;
        overflow-y: auto;
    }

    /* 中间面板 */
    .batch-center-panel {
        border-right: none !important;
        border-bottom: 1px solid #e9ecef;
        padding: 8px !important;
    }

    /* 右侧面板 */
    .batch-right-panel {
        width: 100% !important;
        min-width: 100% !important;
        padding: 8px !important;
    }

    /* 区块通用 */
    .batch-section {
        padding: 8px !important;
        margin-bottom: 8px !important;
    }

    /* 工具列表横向滚动 */
    .batch-tool-list {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .batch-tool-list::-webkit-scrollbar {
        display: none;
    }

    /* 结果网格 */
    .batch-result-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 参考图网格 */
    .batch-ref-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* 模型网格 */
    .batch-model-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 模板列表横向滚动 */
    .batch-template-list {
        display: flex !important;
        gap: 6px !important;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .batch-template-list::-webkit-scrollbar {
        display: none;
    }
    .batch-template-card {
        min-width: 140px !important;
        flex-shrink: 0 !important;
    }

    /* 弹窗宽度 */
    .batch-wide-modal {
        max-width: 95vw !important;
        min-width: auto !important;
    }

    /* 生成预览吸顶栏 */
    .batch-generate-bar {
        position: static !important;
    }
}

/* ========================================
   4. 登录弹窗适配
   ======================================== */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .modal-dialog-custom {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        padding: 20px 16px 30px !important;
        animation: slideUp 0.3s ease !important;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .modal-close {
        top: 12px !important;
        right: 12px !important;
        font-size: 20px !important;
    }

    .modal-title-custom {
        font-size: 18px !important;
        margin-bottom: 15px !important;
    }

    .modal-tab-btn {
        font-size: 14px !important;
        padding: 8px !important;
    }

    .modal-form-group input {
        padding: 10px 12px !important;
        font-size: 16px !important; /* 防止 iOS 缩放 */
    }

    .modal-submit-btn {
        padding: 12px !important;
        font-size: 16px !important;
    }

    .login-type-btn {
        font-size: 12px !important;
        padding: 5px 6px !important;
    }
}

/* ========================================
   5. 案例页面适配
   ======================================== */
@media (max-width: 768px) {
    /* 案例卡片网格 */
    .case-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    /* 案例卡片内容 */
    .case-card-content {
        padding: 0.5rem !important;
    }

    /* 案例卡片标题 */
    .case-card-title {
        font-size: 0.75rem !important;
    }

    /* 案例卡片描述 */
    .case-card-desc {
        font-size: 0.65rem !important;
    }

    /* 顶部导航栏 */
    #navbar {
        height: 50px !important;
    }

    #navbar .container {
        padding: 0 12px !important;
    }

    /* 移动端菜单按钮 */
    #mobile-menu-button {
        display: block !important;
    }

    /* 移动端菜单 */
    #mobile-menu {
        position: fixed;
        top: 50px;
        left: 0;
        right: 0;
        z-index: 999;
        max-height: calc(100vh - 50px);
        overflow-y: auto;
    }

    /* 轮播按钮 */
    .carousel-btn {
        width: 2rem !important;
        height: 2rem !important;
    }

    /* 轮播指示器 */
    .carousel-indicators {
        bottom: 8px !important;
    }
}

/* ========================================
   6. 其他页面通用适配
   ======================================== */
@media (max-width: 768px) {
    /* 主内容区 */
    main.container-fluid {
        padding: 8px !important;
    }

    /* 卡片 */
    .card {
        margin-bottom: 8px !important;
    }

    /* 表单控件 */
    .form-control, .form-select {
        font-size: 16px !important; /* 防止 iOS 缩放 */
    }

    /* 按钮 */
    .btn {
        font-size: 0.8rem !important;
    }

    /* 表格 */
    .table {
        font-size: 0.75rem !important;
    }

    /* 分页 */
    .pagination {
        font-size: 0.75rem !important;
    }

    /* 模态框 */
    .modal-dialog {
        margin: 0.5rem !important;
    }

    .modal-body {
        padding: 12px !important;
    }

    /* 下拉菜单 */
    .dropdown-menu {
        font-size: 0.8rem !important;
    }

    /* 提示框 */
    .alert {
        font-size: 0.8rem !important;
        padding: 8px 12px !important;
    }

    /* 徽章 */
    .badge {
        font-size: 0.65rem !important;
    }

    /* 进度条 */
    .progress {
        height: 6px !important;
    }

    /* 图片预览 */
    .image-preview {
        max-width: 100% !important;
    }

    /* 工具栏 */
    .toolbar {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }

    /* 搜索框 */
    .search-box {
        width: 100% !important;
        margin-bottom: 8px !important;
    }

    /* 筛选器 */
    .filter-group {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }

    /* 列表项 */
    .list-group-item {
        padding: 8px 12px !important;
    }

    /* 标签页 */
    .nav-tabs .nav-link {
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
    }

    /* 折叠面板 */
    .accordion-button {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
    }

    /* 弹出框 */
    .popover {
        max-width: 200px !important;
    }

    /* 工具提示 */
    .tooltip {
        font-size: 0.75rem !important;
    }
}

/* ========================================
   7. 小屏手机适配（≤480px）
   ======================================== */
@media (max-width: 480px) {
    /* 导航栏 */
    .navbar-brand {
        font-size: 0.9rem !important;
    }

    .nav-core-link {
        font-size: 0.7rem !important;
        padding: 2px 4px !important;
    }

    /* AI 设计页面 */
    .design-sidebar {
        max-height: 100px;
    }

    .category-item {
        min-width: 36px !important;
        padding: 3px 6px !important;
    }

    .model-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 批量工作台 */
    .batch-result-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .batch-ref-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 案例页面 */
    .case-grid {
        grid-template-columns: 1fr !important;
    }

    /* 登录弹窗 */
    .modal-dialog-custom {
        padding: 16px 12px 24px !important;
    }

    .modal-title-custom {
        font-size: 16px !important;
    }

    .modal-tab-btn {
        font-size: 13px !important;
        padding: 6px !important;
    }

    .modal-form-group input {
        padding: 8px 10px !important;
        font-size: 14px !important;
    }

    .modal-submit-btn {
        padding: 10px !important;
        font-size: 14px !important;
    }

    /* 历史记录网格 */
    .history-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 收藏网格 */
    .favorites-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   8. 横屏模式适配
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    /* AI 设计页面横屏 */
    .design-layout {
        flex-direction: row !important;
        flex-wrap: wrap !important;
    }

    .design-sidebar {
        width: 200px !important;
        min-width: 200px !important;
        max-height: none !important;
        border-right: 2px solid var(--panel-border-color, #dee2e6) !important;
        border-bottom: none !important;
    }

    .design-sidebar .sidebar-inner {
        flex-direction: column !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    .design-sidebar .sidebar-tools {
        flex-direction: column !important;
    }

    .design-param-panel {
        width: calc(50% - 100px) !important;
        min-width: 200px !important;
        max-height: none !important;
    }

    .design-result-panel {
        width: calc(50% - 100px) !important;
        min-width: 200px !important;
    }

    .design-history-panel {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 150px !important;
    }

    /* 登录弹窗横屏 */
    .modal-overlay {
        align-items: center !important;
        padding: 20px !important;
    }

    .modal-dialog-custom {
        max-width: 400px !important;
        border-radius: 12px !important;
        animation: modalSlideIn 0.3s ease !important;
    }
}

/* ========================================
   9. 触摸设备优化
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* 增大触摸目标 */
    .btn, .nav-link, .dropdown-item {
        min-height: 44px;
        min-width: 44px;
    }

    /* 移除 hover 效果 */
    .case-card:hover {
        transform: none !important;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important;
    }

    /* 增大滑块 */
    .weight-slider::-webkit-slider-thumb {
        width: 24px !important;
        height: 24px !important;
    }

    .history-size-slider::-webkit-slider-thumb {
        width: 20px !important;
        height: 20px !important;
    }

    /* 增大复选框 */
    .form-check-input {
        width: 1.2em !important;
        height: 1.2em !important;
    }
}

/* ========================================
   10. 安全区域适配（iPhone X+）
   ======================================== */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .navbar {
            padding-top: max(0.5rem, env(safe-area-inset-top)) !important;
        }

        .modal-dialog-custom {
            padding-bottom: max(30px, env(safe-area-inset-bottom)) !important;
        }

        footer {
            padding-bottom: max(0.75rem, env(safe-area-inset-bottom)) !important;
        }
    }
}
