/* ============================================================
   mobile.css — 手机端响应式适配（方案 A）
   桌面端 ≤768px 以下触发：底部导航 + 浮动 + 按钮 + 弹窗变底部 sheet + 表格横滑
   不改任何渲染函数逻辑，只在窄屏叠加展示层。
   ============================================================ */

/* 桌面端（>768px）隐藏手机端专用组件：底部导航/浮动按钮/更多sheet/浮动批量条
   这些元素写在 HTML 里但桌面端不该显示；下方 @media 块会在窄屏把它们显示出来。 */
.m-nav, .m-fab, .m-sheet, .m-batchbar { display: none; }

@media (max-width: 768px) {

    /* ===== 基本布局：留出底部导航空间 ===== */
    /* 底部留出固定导航的空间：tab-pending/buyers 在 shop2 里位于 .container 之外，
       所以用 body padding 保证它们的分页器不被底部导航挡住。 */
    body { padding-bottom: 90px; }
    .container { padding-bottom: 0; max-width: 100%; }

    /* ===== 头部紧凑 ===== */
    .header { padding: 8px 12px; gap: 8px; }
    .header-left { gap: 8px; }
    .header-left .brand-logo { width: 32px; height: 32px; }
    .header-left h1 { font-size: 1.05em; }
    .header-sub { font-size: .68em; }
    .header-right .btn { padding: 6px 10px; font-size: .8em; }
    /* 桌面端顶部 tab 条在手机上隐藏，改用底部导航 */
    .tabs { display: none; }

    /* ===== 工具栏回流 ===== */
    .toolbar { gap: 8px; padding: 8px 0; margin-bottom: 12px; }
    .toolbar h2 { font-size: 1em; }
    .toolbar .search-input,
    .toolbar input[type=text] { flex: 1 1 140px; width: auto; min-width: 0; }
    .toolbar .btn,
    .toolbar select { flex: 0 0 auto; }
    .toolbar .btn-sm { padding: 5px 9px; font-size: .78em; }
    .toolbar select { padding: 6px 8px; font-size: .82em; max-width: 100%; }

    /* ===== 卡片 ===== */
    .card { padding: 14px; border-radius: 14px; margin-bottom: 12px; }

    /* ===== 表格：默认横向滚动（shop1 等列多的 admin 表用横滑，不破坏排版） ===== */
    table { width: 100%; }
    .card > table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 7px 8px; font-size: .85em; }
    .row-actions { flex-wrap: wrap; }
    .row-actions .btn { padding: 4px 8px; }

    /* ===== shop2 表格：手机端紧凑高密度模式（保留表格，隐藏次要列+截断长文本，适配窄屏） =====
       卡片化会牺牲密度，1000+ 订单扫不动；改回紧凑表格，靠隐藏低频列让一行一条排下。 ===== */
    .page-shop2 table,
    .page-shop2 .card > table {
        display: table !important; width: 100% !important;
        table-layout: fixed; overflow: hidden;
        font-size: .8em;
    }
    .page-shop2 thead { display: table-header-group; }
    .page-shop2 tbody { display: table-row-group; }
    .page-shop2 tr { display: table-row; }
    .page-shop2 th, .page-shop2 td {
        display: table-cell; padding: 6px 5px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        border: none; vertical-align: middle;
    }
    /* data-label 属性保留在 JS 里但紧凑模式下不显示标签（::before 不生成） */

    /* --- 订单表 #tab-orders：商品与 SKU 合并为一列（商品上/SKU下）；隐藏 闲鱼单号(2)/时间(7) ---
       列序：1勾选 2闲鱼单号 3买家 4商品/SKU 5数量 6状态 7时间 8操作 --- */
    #tab-orders table th:nth-child(2), #tab-orders table td:nth-child(2),
    #tab-orders table th:nth-child(7), #tab-orders table td:nth-child(7) { display: none; }
    #tab-orders table th:nth-child(1), #tab-orders table td:nth-child(1) { width: 28px; }   /* 勾选 */
    #tab-orders table th:nth-child(3), #tab-orders table td:nth-child(3) { width: 60px; white-space: normal; } /* 买家 */
    #tab-orders table th:nth-child(4), #tab-orders table td:nth-child(4) { white-space: normal; } /* 商品/SKU(换行) */
    #tab-orders table th:nth-child(5), #tab-orders table td:nth-child(5) { width: 40px; text-align: center; } /* 数量(加宽防"数...") */
    #tab-orders table th:nth-child(6), #tab-orders table td:nth-child(6) { width: 62px; }   /* 状态 */
    #tab-orders table th:nth-child(8), #tab-orders table td:nth-child(8) { width: 52px; white-space: normal; } /* 操作 */

    /* --- 待发货 #tab-pending：隐藏 闲鱼订单号(1)/CN(2)/导出状态(6) --- */
    #tab-pending table th:nth-child(1), #tab-pending table td:nth-child(1),
    #tab-pending table th:nth-child(2), #tab-pending table td:nth-child(2),
    #tab-pending table th:nth-child(6), #tab-pending table td:nth-child(6) { display: none; }
    #tab-pending table th:nth-child(3), #tab-pending table td:nth-child(3) { width: 70px; } /* 买家昵称 */
    #tab-pending table th:nth-child(4), #tab-pending table td:nth-child(4) { white-space: normal; } /* 已排发商品(换行) */
    #tab-pending table th:nth-child(5), #tab-pending table td:nth-child(5) { width: 62px; } /* 状态 */

    /* --- 买家池 #tab-buyers：隐藏 绑定订单号(3) 和 绑定时间(5) --- */
    #tab-buyers table th:nth-child(3), #tab-buyers table td:nth-child(3),
    #tab-buyers table th:nth-child(5), #tab-buyers table td:nth-child(5) { display: none; }
    #tab-buyers table th:nth-child(2), #tab-buyers table td:nth-child(2) { width: 90px; }   /* 买家ID */

    /* --- 用户管理 #tab-users：隐藏 显示名(2) 和 最近登录(5) --- */
    #tab-users table th:nth-child(2), #tab-users table td:nth-child(2),
    #tab-users table th:nth-child(5), #tab-users table td:nth-child(5) { display: none; }

    /* --- 退款台账 #tab-refunds：隐藏 SKU(3) 和 退款时间(6) --- */
    #tab-refunds table th:nth-child(3), #tab-refunds table td:nth-child(3),
    #tab-refunds table th:nth-child(6), #tab-refunds table td:nth-child(6) { display: none; }

    /* 库存池 #tab-pools：4 列，固定布局让 SKU 列可换行 */
    #tab-pools table th:nth-child(3), #tab-pools table td:nth-child(3) { white-space: normal; }

    /* 操作按钮在窄列里换行不溢出 */
    .page-shop2 .row-actions { flex-wrap: wrap; gap: 4px; }
    .page-shop2 .row-actions .btn { padding: 3px 6px; font-size: .76em; }
    .page-shop2 .row-actions select { width: auto; padding: 3px 4px; font-size: .74em; max-width: 70px; }


    /* ===== shop2 商品折叠行：手机上更紧凑 ===== */
    .product-main { cursor: pointer; }
    .product-detail-row > td { padding: 10px 8px 10px calc(1.2em + 8px); }
    .product-detail-grid { gap: 12px; }
    .product-detail-item { flex: 1 1 100%; min-width: 0; }

    /* ===== 弹窗 → 底部滑出式 sheet ===== */
    .modal { align-items: flex-end !important; padding: 0 !important; }
    .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 22px 22px 0 0 !important;
        padding: 20px 18px 28px !important;
        max-height: 88vh;
        box-shadow: 0 -8px 30px rgba(74,56,42,.25);
    }
    .modal-box.modal-wide { max-width: 100% !important; }
    .modal-box::before {
        content: ''; display: block; width: 44px; height: 5px;
        border-radius: 3px; background: var(--border);
        margin: 0 auto 16px;
    }
    .modal-box h2 { text-align: center; font-size: 1.05em; }
    .modal-box .form-row { gap: 10px; }
    .modal-box .form-row > div { min-width: 0; flex: 1; }
    .modal-box input,
    .modal-box select,
    .modal-box textarea { font-size: 16px; } /* 16px 防 iOS 聚焦放大 */

    /* ===== 底部导航 ===== */
    .m-nav {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
        display: flex; background: var(--card);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 18px rgba(120,80,40,.10);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .m-nav .m-nav-item {
        flex: 1; border: none; background: none; padding: 8px 0 6px;
        text-align: center; cursor: pointer; color: var(--text-soft);
        display: flex; flex-direction: column; align-items: center; gap: 2px;
        min-width: 0;
    }
    .m-nav .m-nav-item svg { width: 21px; height: 21px; display: block; }
    .m-nav .m-nav-item span { font-size: .62em; line-height: 1; }
    .m-nav .m-nav-item.active { color: var(--primary); font-weight: 700; }
    .m-nav .m-nav-item:active { background: var(--bg-soft); }

    /* ===== 浮动 + 按钮（按当前 tab 触发对应"新增"动作） ===== */
    .m-fab {
        position: fixed; right: 16px; bottom: 80px; z-index: 199;
        width: 52px; height: 52px; border-radius: 50%;
        border: none; background: var(--primary); color: #fff;
        font-size: 28px; line-height: 1; cursor: pointer;
        box-shadow: 0 8px 22px rgba(120,80,40,.35);
        display: flex; align-items: center; justify-content: center;
        padding-bottom: 4px;
    }
    .m-fab:active { transform: scale(.94); }

    /* ===== "更多"底部 sheet（shop2 用：库存池/用户/退款） ===== */
    .m-sheet { position: fixed; inset: 0; z-index: 300; background: rgba(74,56,42,.45); display: none; align-items: flex-end; }
    .m-sheet.show { display: flex; }
    .m-sheet-box {
        background: #fff; width: 100%; border-radius: 22px 22px 0 0;
        padding: 18px 18px calc(28px + env(safe-area-inset-bottom,0));
        box-shadow: 0 -8px 30px rgba(74,56,42,.25);
    }
    .m-sheet-box .grip { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
    .m-sheet-box h3 { font-size: 1em; margin-bottom: 12px; text-align: center; }
    .m-sheet-item { display: flex; align-items: center; gap: 12px; padding: 14px 8px; border-bottom: 1px solid var(--border); cursor: pointer; }
    .m-sheet-item:last-child { border-bottom: none; }
    .m-sheet-item:active { background: var(--bg-soft); }
    .m-sheet-item .mi { width: 38px; height: 38px; border-radius: 12px; background: var(--bg-soft); display: flex; align-items: center; justify-content: center; color: var(--primary); flex: none; }
    .m-sheet-item .mt b { display: block; font-size: .95em; }
    .m-sheet-item .mt span { font-size: .74em; color: var(--text-soft); }
    .m-sheet-close { width: 100%; margin-top: 12px; background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-soft); border-radius: 12px; padding: 12px; font-size: .9em; cursor: pointer; }

    /* ===== shop2 订单浮动批量条（手机端，替代底部 toolbar） ===== */
    .m-batchbar {
        position: fixed; left: 12px; right: 12px; bottom: 80px; z-index: 198;
        background: var(--primary-deep); color: #fff; border-radius: 16px;
        padding: 10px 14px; display: none; align-items: center; gap: 8px;
        box-shadow: 0 10px 26px rgba(74,56,42,.35); flex-wrap: wrap;
    }
    .m-batchbar.show { display: flex; }
    .m-batchbar .sel { font-size: .82em; flex: none; }
    .m-batchbar button { border: none; border-radius: 10px; padding: 7px 11px; font-size: .78em; font-weight: 600; cursor: pointer; }
    .m-batchbar .go { background: #fff; color: var(--primary-deep); }
    .m-batchbar .del { background: #DC2626; color: #fff; }
    .m-batchbar .x { margin-left: auto; background: rgba(255,255,255,.2); color: #fff; }

    /* shop2 导出按钮在手机端不挤进 toolbar，放进批量条 */
    .toolbar .btn[onclick*="exportExcel"],
    .toolbar .btn[onclick*="exportShipping"] { flex: 0 0 auto; }

    /* shop1 待发货需求提示行 */
    .recon-note { font-size: .76em; }

    /* 让分页器在手机上贴底但不被导航挡 */
    .pager { gap: 6px; font-size: .82em; margin-top: 12px; }

    /* 表单行在手机上单列堆叠 */
    .form-row { flex-direction: column; gap: 8px; }
    .form-row > div { width: 100%; }

    /* 隐藏桌面端"返回首页/退出登录"在头部的并排，避免拥挤（保留即可，仅缩小） */
}
