/* ========================================
   mobile.css — 前台移动端通用适配
   断点：≤576px (xs) / 576-768px (sm) / 768-992px (md) / ≥992px (lg)
   ======================================== */

/* ---- 1. 基础重置 ---- */
@media (max-width: 768px) {
    :root {
        --spacing-xs: 0.25rem;
        --spacing-sm: 0.5rem;
        --spacing-md: 0.75rem;
        --spacing-lg: 1rem;
        --spacing-xl: 1.5rem;
        --spacing-xxl: 2rem;
    }

    body {
        font-size: 14px;
        line-height: 1.6;
    }

    .container,
    .container-fluid,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

@media (max-width: 576px) {
    body {
        font-size: 13px;
    }
}

/* ---- 2. 导航适配 ---- */
@media (max-width: 768px) {
    /* 隐藏底部导航，使用顶部汉堡菜单方案 */
    .cg-bottom-nav {
        display: none !important;
    }
    .cg-main.has-bottom-nav {
        padding-bottom: 0;
    }

    /* 侧边栏抽屉优化 */
    .cg-sidebar {
        width: 260px;
        max-width: 80vw;
        z-index: 1100;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    }

    /* 移动端菜单按钮固定在顶部 */
    .cg-mobile-menu-btn,
    #mobileMenuToggle {
        position: fixed;
        top: 0.75rem;
        left: 0.75rem;
        z-index: 1051;
        background: var(--primary-color, #5961f9);
        color: white;
        border: none;
        border-radius: var(--radius-lg, 8px);
        padding: 0.5rem 0.75rem;
        font-size: 1.25rem;
        line-height: 1;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    }

    /* 顶部导航栏适配 */
    .navbar {
        padding: 0.5rem 0;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    .navbar-brand img {
        height: 28px;
    }

    /* 导航栏折叠后的菜单 */
    .navbar-collapse {
        background: white;
        border-radius: 0 0 12px 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        margin: 0 -1rem;
        padding: 0.5rem 1rem;
    }

    .navbar-nav {
        gap: 0;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 0.5rem;
        border-bottom: 1px solid var(--border-light, #eee);
    }

    .navbar-nav .nav-link:last-child {
        border-bottom: none;
    }

    /* 侧边栏遮罩层 */
    .cg-sidebar-overlay {
        z-index: 1099;
    }
}

@media (max-width: 576px) {
    .cg-sidebar {
        width: 240px;
    }
}

/* ---- 3. 布局栅格 ---- */
@media (max-width: 768px) {
    /* 双栏布局变单列堆叠 */
    .row > [class*="col-md-"],
    .row > [class*="col-lg-"] {
        width: 100%;
    }

    /* CSS Grid 双栏变单列 */
    [style*="grid-template-columns"][style*="2fr"][style*="1fr"],
    [style*="grid-template-columns"][style*="1fr"][style*="1fr"][style*="1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* 主内容区域全宽 */
    .cg-main,
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .content-wrapper {
        padding: 1rem !important;
    }

    /* 内容区域内边距统一 */
    .cg-content,
    .cg-main {
        padding: 1rem;
    }
}

/* ---- 4. 卡片网格 ---- */
@media (max-width: 768px) {
    /* 卡片网格默认 2 列 */
    .row.g-3 > [class*="col-"],
    .row.g-4 > [class*="col-"] {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* 自定义网格组件 2 列 */
    .tools-grid,
    .categories-grid,
    .tutorial-grid,
    .video-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }

    /* 工具卡片内容优化 */
    .tool-card,
    .cg-card {
        padding: 0.875rem !important;
    }

    .tool-logo {
        width: 40px !important;
        height: 40px !important;
    }

    .tool-name,
    .cg-card h3,
    .cg-card h5 {
        font-size: 0.9rem !important;
    }

    .tool-description {
        font-size: 0.8rem !important;
        -webkit-line-clamp: 2;
    }
}

@media (max-width: 576px) {
    /* 小手机单列 */
    .tools-grid,
    .categories-grid,
    .tutorial-grid,
    .video-grid {
        grid-template-columns: 1fr !important;
    }

    .row.g-3 > [class*="col-"],
    .row.g-4 > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ---- 5. 排版优化 ---- */
@media (max-width: 768px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }

    .hero-title,
    .section-title {
        font-size: 1.5rem !important;
    }

    .hero-subtitle {
        font-size: 0.95rem !important;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    /* 段落间距 */
    p {
        margin-bottom: 0.75rem;
    }

    /* 长文本截断 */
    .text-truncate-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}

/* ---- 6. 触摸优化 ---- */
@media (max-width: 768px) {
    /* 按钮最小触摸区域 44px */
    .btn,
    .cg-btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .btn-sm,
    .cg-btn-sm {
        min-height: 36px;
        padding: 0.375rem 0.75rem;
    }

    /* 表单输入框 */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px; /* 防止 iOS 缩放 */
    }

    /* 搜索框全宽 */
    .search-box,
    .cg-search {
        width: 100% !important;
        max-width: 100% !important;
    }

    .search-input {
        padding: 0.625rem 1rem;
        font-size: 16px;
    }

    /* checkbox/radio 放大触摸区域 */
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }

    .form-check-label {
        padding-left: 0.25rem;
    }

    /* 链接间距 */
    .nav-link,
    .cg-sidebar-link {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    /* 分页简化 */
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .pagination .page-link {
        padding: 0.375rem 0.625rem;
        min-height: 36px;
    }

    /* 隐藏分页中间页码，只保留首尾和前后 */
    .pagination .page-item:not(:first-child):not(:last-child):not(.active) {
        display: none;
    }

    /* 模态框适配 */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100vw - 1rem);
    }

    .modal-body {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    /* 标签云横向滚动 */
    .tags-cloud {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .tag-item {
        scroll-snap-align: start;
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* ---- 表格适配 ---- */
@media (max-width: 768px) {
    /* 宽表格默认横向滚动 */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.85rem;
    }

    /* 图片和视频自适应 */
    img,
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }

    .ratio {
        max-width: 100%;
    }
}

/* ---- 7. 工具类 ---- */
@media (max-width: 768px) {
    .d-mobile-none { display: none !important; }
    .d-mobile-block { display: block !important; }
    .d-mobile-flex { display: flex !important; }
    .d-mobile-inline { display: inline !important; }
    .d-mobile-grid { display: grid !important; }

    .text-mobile-center { text-align: center !important; }
    .text-mobile-left { text-align: left !important; }

    .w-mobile-100 { width: 100% !important; }
    .mx-mobile-0 { margin-left: 0 !important; margin-right: 0 !important; }
    .px-mobile-0 { padding-left: 0 !important; padding-right: 0 !important; }
}

@media (min-width: 769px) {
    .d-mobile-only { display: none !important; }
}

/* ========================================
   8. 方案五通用化：渐变头部 + 白色面板 + 双列卡片
   （≤768px 生效，桌面端零影响）
   ======================================== */
@media (max-width: 768px) {
    /* 渐变头部背景（cyber-glass 前台页面通用） */
    body.cyber-glass {
        background: linear-gradient(160deg, #5b7cff 0%, #7c5cff 46%, #9d7bff 100%);
    }

    body.cyber-glass .cg-wrapper,
    body.cyber-glass main.cg-main {
        background: transparent;
    }

    /* 顶栏透明化 + 紧凑内边距 */
    body.cyber-glass .cg-topbar {
        background: transparent;
        box-shadow: none;
        padding: 14px 16px 0;
    }

    /* 汉堡按钮回归行内（覆盖上文 position:fixed）；
       默认（白底页面）浅底品牌色图标，渐变页见下方覆盖 */
    .cg-topbar .cg-mobile-menu-btn,
    .cg-topbar #mobileMenuToggle {
        position: static;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: none;
        width: 40px;
        height: 40px;
        padding: 0;
        border-radius: 12px;
        background: #eef1fb;
        color: #5b7cff;
        font-size: 1.25rem;
        box-shadow: none;
    }

    body.cyber-glass .cg-topbar .cg-mobile-menu-btn,
    body.cyber-glass .cg-topbar #mobileMenuToggle {
        background: rgba(255, 255, 255, .16);
        color: #fff;
    }

    /* 搜索框：默认灰底胶囊（白底页面），渐变页白底见下方覆盖 */
    .cg-topbar .cg-search-input {
        height: 46px;
        min-height: 46px;
        padding: 0 46px 0 16px;
        border-radius: 999px;
        border-color: transparent;
        background: #f1f3f9;
        color: #111827;
        font-size: 16px;
        box-shadow: none;
    }

    .cg-topbar .cg-search-input::placeholder {
        color: #94a3b8;
    }

    .cg-topbar .cg-search-input:focus {
        border-color: rgba(91, 124, 255, .35);
        background: #fff;
        transform: none;
    }

    /* 渐变头部页：白色胶囊搜索 + 阴影 */
    body.cyber-glass .cg-topbar .cg-search-input {
        background: #fff;
        box-shadow: 0 10px 24px rgba(15, 23, 42, .14);
    }

    body.cyber-glass .cg-topbar .cg-search-input:focus {
        border-color: transparent;
    }

    .cg-topbar .cg-search-icon {
        right: 16px;
        width: 20px;
        height: 20px;
    }

    .cg-topbar .cg-search-icon svg {
        stroke: #5b7cff;
    }

    /* 白色内容面板上浮 */
    body.cyber-glass .cg-content {
        margin-top: 14px;
        padding: 16px 14px 24px;
        background: #f6f7fc;
        border-radius: 26px 26px 0 0;
        box-shadow: 0 -12px 30px rgba(15, 23, 42, .12);
    }

    /* 列表卡片一行两个（课程/工具/视频/模型/机器人） */
    .row > .col-6.col-md-3,
    .row > .col-sm-6.col-lg-4.col-xl-3,
    .row > .col-md-6.col-lg-4,
    .row > .col-12.col-md-6.col-xl-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* 首页推荐工具卡片两列（配合 .homeCardGrid 的 gap:10px，列宽减去半间隙防换行） */
    #home-grid .home-card-col {
        width: calc(50% - 5px) !important;
        flex: 0 0 calc(50% - 5px) !important;
        max-width: calc(50% - 5px) !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* 首页内容区锁宽，防止卡片行溢出视口 */
    body.cyber-glass .cg-content {
        overflow-x: hidden;
    }

    #home-grid,
    #home-grid .homeCardGrid {
        max-width: 100%;
    }

    /* 课程页网格一行两个（覆盖页内联 ≤768px 单列） */
    .learn-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    /* 窄列紧凑化：标题截断防撑高 */
    .video-card h3,
    .video-card h5,
    .video-card .video-title,
    .tutorial-card .tutorial-title {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* 工具列表卡片（智能体/机器人/办公/编程/模型页共用）：
       紧凑内边距 + 文本截断，避免窄列长文本撑高 */
    .tool-grid-card .card-body {
        padding: 14px !important;
    }

    .tool-grid-card img {
        width: 44px !important;
        height: 44px !important;
        border-radius: 12px !important;
    }

    .tool-grid-card h3,
    .tool-grid-card .h6 {
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        margin-bottom: 0.35rem;
    }

    .tool-grid-card p {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        min-height: 0;
    }

    /* 分页器横滑防溢出（模型页 386px > 375px 问题） */
    .tool-pagination-wrap {
        margin-top: 2rem;
    }

    .tool-pagination {
        max-width: 100%;
    }

    .tool-pagination-group {
        max-width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .tool-pagination-group::-webkit-scrollbar { display: none; }

    .tool-page-link {
        flex: none;
    }
}
