/* ============================================================
 * 大宗搜索 — 移动端响应式层 v2 (彻底重写)
 * 
 * 策略:
 *   - 所有规则放在 @media (max-width: 900px) 和 (max-width: 480px) 下
 *     (和 style.css 已有断点对齐)
 *   - 关键覆盖加 !important 确保覆盖 style.css 的旧 @media
 *   - 覆盖所有 6 套 layout: main / home / user / auth / admin
 *   - 不改动 style.css 任何一行
 * ============================================================ */

/* ========== 全局基础 (所有宽度) ========== */
html { -webkit-text-size-adjust: 100%; }
body { min-width: 100%; overflow-x: hidden; }

/* ========== ≤ 900px: 平板 + 大号手机 ========== */
@media (max-width: 900px) {
    
    /* ---- 容器压缩 ---- */
    .container, .wide-container {
        max-width: 100% !important;
        padding: 0 12px !important;
    }
    
    /* ========== main.php: 顶部导航 ========== */
    .topbar { height: 52px !important; }
    .topbar-inner { height: 52px !important; gap: 10px !important; }
    
    /* 汉堡按钮显示, top-nav 隐藏 (点击汉堡才展开) */
    .topbar-inner .mobile-toggle {
        display: block !important;
        background: none; border: none;
        font-size: 22px; cursor: pointer;
        padding: 4px 8px; margin-left: auto;
        color: #1a73e8;
    }
    .topbar-inner .top-nav,
    .topbar-inner .top-user { display: none !important; }
    
    /* 汉堡展开时 */
    .topbar-inner.nav-open .top-nav {
        display: flex !important;
        position: absolute !important;
        top: 52px; left: 0; right: 0;
        flex-direction: column !important;
        background: #fff !important;
        padding: 12px 16px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
        gap: 0 !important;
        z-index: 200;
    }
    .topbar-inner.nav-open .top-nav a {
        padding: 12px 0 !important;
        border-bottom: 1px solid #f0f2f5 !important;
        border-bottom-width: 1px !important;
        font-size: 15px !important;
    }
    .topbar-inner.nav-open .top-user {
        display: flex !important;
        position: absolute !important;
        top: auto; left: 0; right: 0;
        background: #fff;
        padding: 12px 16px !important;
        border-top: 1px solid #f0f2f5;
        top: calc(52px + 260px);  /* 动态估算 */
        z-index: 199;
    }
    
    /* Logo 压缩 */
    .topbar .logo span:first-child { font-size: 20px !important; }
    
    /* ========== 底部 Tab Bar ========== */
    .mobile-tabbar {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 56px;
        background: #fff;
        border-top: 1px solid #e8eaed;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
        z-index: 999;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-tabbar-inner {
        display: flex;
        height: 100%;
        width: 100%;
    }
    .mobile-tabbar .mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none !important;
        color: #5f6368 !important;
        font-size: 11px !important;
        gap: 2px;
        border: none !important;
        background: none !important;
        cursor: pointer;
        padding: 4px 0 !important;
    }
    .mobile-tabbar .mobile-tab.active,
    .mobile-tabbar .mobile-tab:hover {
        color: #1a73e8 !important;
    }
    .mobile-tabbar .mobile-tab svg {
        width: 22px; height: 22px;
        stroke-width: 1.8;
    }
    
    /* main 给 tabbar 留底部空间 */
    main { padding-bottom: 64px !important; }
    
    /* ========== footer 压缩 ========== */
    .footer { padding: 20px 0 60px !important; }
    .footer-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 16px !important;
    }
    
    /* ========== home.php: 百度风首页 ========== */
    .baidu-center { padding: 24px 16px !important; }
    .baidu-logo { font-size: 48px !important; }
    .baidu-search { width: 100% !important; max-width: none !important; }
    .baidu-search-wrap {
        flex-direction: column !important;
        border-radius: 24px !important;
        overflow: hidden;
    }
    .baidu-search-input {
        width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        padding: 12px 18px !important;
        font-size: 15px !important;
        border-right: 1px solid #dfe1e5 !important;
        border-bottom: none !important;
    }
    .baidu-search-btn {
        width: 100% !important;
        border-radius: 0 0 24px 24px !important;
        padding: 12px !important;
        font-size: 15px !important;
    }
    .baidu-toplinks {
        padding: 8px 12px !important;
        gap: 0 !important;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }
    .baidu-toplinks a {
        white-space: nowrap !important;
        padding: 6px 10px !important;
        font-size: 13px !important;
        flex-shrink: 0 !important;
    }
    .baidu-toplinks .toplinks-sep { display: none !important; }
    .baidu-aibar {
        font-size: 12px !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        margin-top: 18px !important;
    }
    
    /* 热搜面板移动端 */
    .baidu-hotboard {
        margin: 20px 12px !important;
        padding: 12px !important;
        border-radius: 12px !important;
    }
    
    /* ========== auth.php: 登录/注册 ========== */
    .auth-card {
        width: calc(100% - 32px) !important;
        margin: 20px 16px !important;
        padding: 24px 20px !important;
        border-radius: 12px !important;
    }
    
    /* ========== admin.php: 后台 ========== */
    .admin-layout .sidebar {
        position: fixed !important;
        left: 0; top: 0; bottom: 0;
        width: 260px !important;
        max-width: 85vw;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    .admin-layout.sidebar-open .sidebar { transform: translateX(0); }
    .admin-layout .main-wrap { margin-left: 0 !important; }
    
    /* ========== 通用 grid 压缩 ========== */
    .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
    .grid-2 { gap: 12px !important; }
    
    /* ========== 表单 ========== */
    .card { padding: 16px !important; border-radius: 10px !important; margin-bottom: 14px !important; }
    
    /* ========== user.php: 顶部 ========== */
    .uc-topbar { height: 50px !important; padding: 0 12px !important; }
    .uc-top-right .uc-top-search,
    .uc-top-right .uc-top-info,
    .uc-logo .uc-logo-sub,
    .uc-top-nav { display: none !important; }
    
    /* user 汉堡按钮 */
    .uc-sidebar-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        color: #fff;
        background: none; border: none;
        font-size: 20px;
        padding: 4px 8px;
        cursor: pointer;
        margin-right: 8px;
    }
}

/* ========== ≤ 480px: 手机竖屏 ========== */
@media (max-width: 480px) {
    
    /* 底部 Tab Bar 更紧凑 */
    .mobile-tabbar { height: 54px !important; }
    main { padding-bottom: 62px !important; }
    
    /* Logo / 标题 */
    .baidu-logo { font-size: 42px !important; margin-bottom: 16px !important; }
    .baidu-logo-char { margin: 0 3px !important; }
    
    /* 热搜面板 */
    .baidu-hotboard-list li { padding: 10px 0 !important; }
    .hboard-rank { width: 22px !important; height: 22px !important; font-size: 11px !important; }
    .hboard-link { font-size: 13px !important; padding-left: 30px !important; }
    
    /* 分榜 */
    .bdhot-tabs { gap: 8px !important; overflow-x: auto !important; flex-wrap: nowrap !important; }
    .bdhot-tabs a { white-space: nowrap !important; padding: 8px 14px !important; font-size: 13px !important; flex-shrink: 0 !important; }
    
    /* 搜索结果 */
    .baidu-result-body article { padding: 14px 0 !important; }
    .baidu-result-body h3 { font-size: 16px !important; line-height: 1.4 !important; }
    .baidu-result-body .snippet { font-size: 13px !important; line-height: 1.6 !important; }
    
    /* grid 全部单列 */
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr !important; }
    .grid-2 > div, .grid-3 > div, .grid-4 > div { grid-column: auto !important; }
    
    /* 表格 → 卡片隐藏 */
    table.admin-table, table:not(.no-mobiles) { min-width: 100% !important; font-size: 13px !important; }
    table.admin-table th, table.admin-table td { padding: 8px 6px !important; }
    
    /* user.php 侧栏 → 抽屉 (覆盖 style.css 的 900px 单列) */
    .uc-wrap { flex-direction: row !important; flex-wrap: nowrap !important; }
    .uc-sidebar {
        position: fixed !important;
        left: 0; top: 50px; bottom: 0 !important;
        width: 260px !important;
        max-width: 80vw;
        background: #f1f4f9;
        z-index: 200 !important;
        transform: translateX(-100%);
        transition: transform .25s ease;
        order: 0 !important;
        height: calc(100vh - 50px) !important;
        overflow-y: auto !important;
    }
    .uc-wrap.sidebar-open .uc-sidebar { transform: translateX(0); }
    .uc-sidebar-mask {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 199;
    }
    .uc-sidebar-mask.show { display: block !important; }
    .uc-main {
        width: 100% !important;
        margin-left: 0 !important;
        padding: 12px !important;
        padding-bottom: 80px !important;
    }
    
    /* user 底部 Tab Bar */
    .uc-tabbar {
        display: flex !important;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 56px;
        background: #fff;
        border-top: 1px solid #e8eaed;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
        z-index: 999;
    }
    .uc-tabbar a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        color: #5f6368;
        font-size: 10px !important;
        padding: 4px 0;
    }
    .uc-tabbar a.active,
    .uc-tabbar a:hover { color: #1a237e !important; }
    .uc-tabbar svg { width: 22px; height: 22px; stroke-width: 2; }
    
    /* user 统计卡片 */
    .uc-stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    
    /* 表单 */
    .form-group { margin-bottom: 12px !important; }
    .form-group label { font-size: 13px !important; margin-bottom: 4px !important; }
    .form-group input, .form-group select, .form-group textarea {
        font-size: 15px !important;
        padding: 10px 12px !important;
    }
    
    /* 按钮触摸目标 */
    .btn { min-height: 44px; padding: 10px 20px; font-size: 15px; }
    .btn-block-phone { display: block; width: 100%; }
    .card-title { font-size: 15px !important; margin-bottom: 12px !important; }
    
    /* 页脚压缩 */
    .footer-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
    .footer-grid > div { text-align: left !important; }
}

/* ========== ≤ 360px: 小屏 ========== */
@media (max-width: 360px) {
    .baidu-logo { font-size: 36px !important; }
    .baidu-aibar { font-size: 11px !important; }
    .grid-4, .grid-3, .grid-2 { gap: 8px !important; }
    .uc-stat-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }
}

/* ========== 触摸优化 (Apple HIG) ========== */
@media (pointer: coarse) {
    .mobile-tab, .uc-tabbar a, .top-nav a,
    .btn, button, a, select {
        min-height: 44px; min-width: 44px;
    }
    .btn-sm { min-height: 32px; min-width: auto; }
}
