/* ============================================================
   移动端适配层  ·  2026-11-01
   ------------------------------------------------------------
   设计原则：
   1. 所有规则都包在 @media 里，桌面（>1024px）渲染逐像素不变
   2. 本文件必须在 style.css 之后引入（同优先级后者胜）
   3. 不改任何业务逻辑，只做布局与触控尺寸
   ============================================================ */

/* 移动端专属组件：桌面上彻底不参与布局 */
.m-topbar, .m-tabbar, .m-sheet, .m-mask { display: none; }
/* 折叠开关按钮只在手机卡片里出现，桌面上必须彻底消失，否则会多出一列 */
table.m-cards td.m-fold-toggle { display: none; }

/* 宽表横向滚动容器：只在 <=1024px 生效，桌面不受影响 */
@media (max-width: 1024px) {
    .m-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ========== 平板 / 窄窗口 ========== */
@media (max-width: 1024px) {
    .app-layout { display: block; min-height: 0; }
    .sidebar { width: 180px; }
    .main-content { margin-left: 180px; padding: 18px; }
    .card { padding: 18px; }
    .card-grid,
    .dashboard-stats,
    .dashboard-quick-actions {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
    .form-row { grid-template-columns: 1fr; }
    .salary-summary { grid-template-columns: repeat(2, 1fr); }
    /* 平板：列多时靠压缩内边距换出空间，仍放不下就在卡片内横滚 */
    .card table th, .card table td { padding: 9px 8px; }
    .badge { white-space: nowrap; }
}

/* ========== 手机 ========== */
@media (max-width: 600px) {

    /* ---------- 基础 ---------- */
    html { -webkit-text-size-adjust: 100%; }
    body { font-size: 15px; }
    .app-layout { display: block; min-height: 0; }
    .sidebar { display: none; }

    .main-content {
        margin-left: 0;
        padding: 12px;
        padding-top: calc(56px + 14px + env(safe-area-inset-top));
        padding-bottom: calc(58px + 28px + env(safe-area-inset-bottom));
        min-height: 100vh;
    }

    /* ---------- 顶部条 ---------- */
    .m-topbar {
        display: flex;
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 120;
        height: calc(56px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 14px 0;
        align-items: center;
        justify-content: space-between;
        background: var(--bg-white);
        border-bottom: 1px solid var(--border);
    }
    .m-brand { font-size: 15px; font-weight: 600; color: var(--text); }
    .m-brand small { font-size: 11px; font-weight: 400; color: var(--text-secondary); margin-left: 6px; }
    .m-topbar-right { display: flex; align-items: center; gap: 8px; }
    .m-icon-btn {
        width: 40px; height: 40px;
        border: none; background: var(--surface-soft-2); border-radius: 10px;
        display: flex; align-items: center; justify-content: center;
        cursor: pointer; padding: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .m-icon-btn:active { background: #E2E8F0; }
    .m-burger { display: flex; flex-direction: column; gap: 4px; align-items: center; }
    .m-burger i { display: block; width: 17px; height: 1.5px; background: var(--text); border-radius: 1px; }

    /* ---------- 底部标签栏 ---------- */
    .m-tabbar {
        display: flex;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 120;
        background: var(--bg-white);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .m-tabbar button {
        flex: 1;
        min-height: 56px;
        border: none;
        background: none;
        cursor: pointer;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 10.5px;
        font-family: inherit;
        color: var(--text-secondary);
        padding: 6px 0;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .m-tabbar button > span:last-child { white-space: nowrap; }
    .m-tabbar button.active { color: var(--primary); font-weight: 500; }
    .m-tab-ico { font-size: 19px; line-height: 1; display: block; }

    /* ---------- 抽屉菜单 ---------- */
    .m-mask {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 130;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }
    .m-mask.show { opacity: 1; pointer-events: auto; }
    .m-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0; right: 0; bottom: 0;
        z-index: 140;
        width: 78%;
        max-width: 320px;
        background: var(--bg-white);
        transform: translateX(102%);
        transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
        padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .m-sheet.show { transform: translateX(0); }
    .m-sheet-head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        padding-bottom: 14px;
        margin-bottom: 6px;
        border-bottom: 1px solid var(--border);
    }
    .m-sheet-name { font-size: 16px; font-weight: 600; color: var(--text); }
    .m-sheet-role { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
    .m-sheet-sec { font-size: 11px; color: var(--text-secondary); margin: 14px 0 6px; }
    /* 抽屉里按「概览 / 人员管理 / 工资管理 / 系统管理」分组，页面多了才找得到 */
    .m-sheet-group {
        font-size: 11px;
        color: var(--text-muted);
        margin: 12px 0 4px 10px;
        letter-spacing: 0.3px;
    }
    .m-sheet-group:first-of-type { margin-top: 4px; }
    .m-sheet-list { display: flex; flex-direction: column; gap: 2px; }
    .m-sheet-list button {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 46px;
        padding: 10px 10px;
        border: none;
        background: none;
        border-radius: 10px;
        font-size: 14px;
        font-family: inherit;
        color: var(--text);
        text-align: left;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    .m-sheet-list button:active { background: var(--surface-soft-2); }
    .m-sheet-list button.active { background: var(--primary-light, #EEF1FE); color: var(--primary); font-weight: 500; }
    .m-sheet-list .m-ico { font-size: 17px; line-height: 1; width: 22px; text-align: center; flex-shrink: 0; }
    .m-sheet-foot { margin-top: auto; padding-top: 16px; }
    .m-sheet-foot .logout-btn { min-height: 44px; font-size: 14px; }

    /* ---------- 页头 ---------- */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 14px;
    }
    .page-header h1 { font-size: 19px; }
    .page-header > .btn { align-self: flex-start; }

    /* ---------- 卡片 ---------- */
    .card {
        padding: 14px;
        border-radius: 12px;
        margin-bottom: 12px;
    }
    .card-header {
        flex-wrap: wrap;
        gap: 8px;
        padding-bottom: 12px;
        margin-bottom: 12px;
    }
    .card-header h3 { font-size: 15px; }

    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .dashboard-quick-actions { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 14px; }

    .stat-card { padding: 13px 12px; border-radius: 10px; }
    .stat-card .stat-info h4 { font-size: 12px; }
    .stat-card .stat-value { font-size: 21px; line-height: 1.25; }
    .stat-card .stat-icon { width: 34px; height: 34px; font-size: 16px; border-radius: 9px; }

    /* ---------- 仪表盘头部 ---------- */
    .dashboard-page { padding-bottom: 8px; }
    .dashboard-hero { padding: 18px 16px; border-radius: 12px; margin-bottom: 14px; }
    .hero-glow, .hero-waves { display: none; }
    .hero-content { gap: 12px; }
    .hero-icon { font-size: 38px; filter: none; animation: none; }
    .hero-content h1 { font-size: 18px; line-height: 1.4; margin-bottom: 4px; }
    .hero-content p { font-size: 12px; }
    .hero-badges { margin-top: 12px; gap: 8px; }
    .hero-badge { font-size: 12px; padding: 5px 10px; }
    .quick-card { padding: 14px; gap: 10px; }
    .quick-card strong { font-size: 14px; }
    .quick-card p { font-size: 12px; }

    /* ---------- 表单与筛选 ---------- */
    .form-input, .form-select, .form-textarea,
    input[type="text"], input[type="password"], input[type="number"],
    input[type="date"], input[type="tel"], input[type="email"], textarea, select {
        font-size: 16px;
        min-height: 42px;
    }
    .form-select { padding-right: 28px; }
    /* 少数下拉框写了内联 font-size:12px，优先级高过上面这条 —— 手机上必须抬回 16px，
       否则 iOS 一聚焦就会把整页放大。宽度一起放开，免得 16px 字被 90px 的框截断。 */
    select[style*="font-size:12px"],
    select[style*="font-size: 12px"] {
        font-size: 16px !important;
        width: auto !important;
        min-width: 104px;
    }
    .form-group { margin-bottom: 14px; }
    .filter-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        align-items: center;
    }
    .filter-bar > * { min-width: 0; width: 100%; }
    .filter-bar > *:first-child { grid-column: 1 / -1; }
    .filter-bar > .btn { grid-column: 1 / -1; }
    .filter-bar .form-input,
    .filter-bar .form-select { width: 100%; min-width: 0; }
    .input-row { flex-wrap: wrap; }

    /* ---------- 按钮与触控 ---------- */
    .btn { min-height: 40px; touch-action: manipulation; }
    .btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
    .btn-lg { min-height: 48px; }

    /* ---------- 标签页 ---------- */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab { white-space: nowrap; padding: 10px 14px; }

    /* ---------- 分页 ---------- */
    .pagination { flex-wrap: wrap; gap: 6px; }
    .pagination button { min-width: 40px; min-height: 40px; }

    /* ---------- 弹窗：底部浮层 ---------- */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal, .modal-lg {
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        border-radius: 16px 16px 0 0;
    }
    .modal-header { padding: 14px 16px; border-radius: 16px 16px 0 0; }
    .modal-header h3 { font-size: 16px; }
    .modal-close { width: 36px; height: 36px; font-size: 20px; flex-shrink: 0; }
    .modal-body { padding: 16px; }
    .modal-footer {
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
        flex-wrap: wrap;
    }
    .modal-footer .btn { flex: 1 1 auto; min-width: 96px; min-height: 44px; }

    /* 弹窗内容里的内联横排（下拉+输入+按钮）允许换行，别把按钮挤到屏幕外 */
    .modal-body [style*="display:flex"] { flex-wrap: wrap; }
    .modal-body [style*="display:flex"] > .btn { flex: 0 0 auto; }
    /* 人员详情这类两列字段在手机上一列更清楚 */
    .modal-body [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

    /* ---------- 登录页 ---------- */
    .login-container { padding: 16px; min-height: 100vh; }
    .login-card { padding: 28px 20px; border-radius: 16px; max-width: 100%; }
    .login-card h1 { font-size: 21px; }
    .login-card .subtitle { margin-bottom: 22px; }

    /* ============================================================
       表格：两种策略
       - .m-cards 窄表/单行表 → 每行一张卡，不再左右滑
       - .m-wide  宽表       → 横滚 + 首列吸左
       ============================================================ */
    table.m-cards { display: block; width: 100%; box-sizing: border-box; }
    table.m-cards thead { display: none; }
    table.m-cards tbody { display: block; }
    table.m-cards tr {
        display: flex;
        flex-direction: column;
        background: var(--bg-white);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 10px 12px;
        margin-bottom: 10px;
    }
    table.m-cards tr:last-child { margin-bottom: 0; }
    table.m-cards tr:hover td { background: transparent; }
    table.m-cards td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        padding: 4px 0;
        border: none;
        font-size: 14px;
        text-align: right;
        word-break: break-word;
    }
    table.m-cards td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 46%;
        color: var(--text-secondary);
        font-size: 13px;
        text-align: left;
        font-weight: 400;
    }
    /* 标题列：优先用姓名/批次号这类有意义的列，而不是 ID 或序号 */
    table.m-cards td.m-title {
        order: -2;
        display: block;
        text-align: left;
        font-size: 15px;
        font-weight: 600;
        color: var(--text);
        padding: 0 0 8px;
        margin-bottom: 6px;
        border-bottom: 1px solid var(--border);
        word-break: break-word;
    }
    table.m-cards td.m-title::before { display: none; }
    table.m-cards td.table-actions {
        order: 3;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 8px;
        margin-top: 6px;
        border-top: 1px solid var(--border);
    }
    table.m-cards td.table-actions::before { display: none; }
    table.m-cards tr.m-empty-row { border: none; padding: 18px 0; background: none; }
    table.m-cards tr.m-empty-row td { display: block; text-align: center; padding: 0; }
    table.m-cards tr.m-empty-row td::before { display: none; }

    /* 折叠：默认只显示前几项，其余点开才出现 */
    table.m-cards td.m-fold { display: none; }
    table.m-cards tr.m-expanded td.m-fold { display: flex; }
    table.m-cards td.m-dim { display: none; }
    table.m-cards td.m-fold-toggle {
        order: 2;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 9px 0 1px;
        margin-top: 7px;
        border: none;
        border-top: 1px dashed var(--border);
        color: var(--primary);
        font-size: 13px;
        text-align: center;
    }
    table.m-cards td.m-fold-toggle::before { display: none; }

    /* 空表：只留提示语，别让表头把整页撑宽 */
    table.m-empty-table { display: block; width: 100%; }
    table.m-empty-table thead { display: none; }
    table.m-empty-table tbody, table.m-empty-table tr { display: block; }
    table.m-empty-table td {
        display: block;
        width: auto;
        border: none;
        padding: 26px 12px;
        text-align: center;
        color: var(--text-secondary);
        font-size: 14px;
    }

    /* ============================================================
       数字宽表卡片（流水/时长看板）：一行一块，2 列网格
       标签在上、数值在下，比「左标签右数值」省一半竖向空间，
       也不用再横向滑动 —— 原来 12 列表只露出 42% 的列
       ============================================================ */
    table.m-cards.m-num tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
        gap: 10px 12px;
        padding: 11px 12px;
    }
    table.m-cards.m-num tr.m-empty-row { display: block; }
    table.m-cards.m-num td {
        display: block;
        text-align: left;
        padding: 0;
        font-size: 14px;
        font-variant-numeric: tabular-nums;
        overflow-wrap: anywhere;
    }
    table.m-cards.m-num td::before {
        display: block;
        max-width: none;
        margin-bottom: 2px;
        font-size: 11.5px;
        line-height: 1.3;
        color: var(--text-secondary);
        text-align: left;
        white-space: normal;
    }
    table.m-cards.m-num td.m-title {
        grid-column: 1 / -1;
        margin: 0;
        padding: 0 0 7px;
        font-size: 15px;
    }
    table.m-cards.m-num td.m-fold { display: none; }
    table.m-cards.m-num tr.m-expanded td.m-fold { display: block; }
    table.m-cards.m-num td.m-fold-toggle {
        grid-column: 1 / -1;
        padding: 8px 0 0;
        margin-top: 1px;
        font-size: 12.5px;
    }
    table.m-cards.m-num td.table-actions {
        grid-column: 1 / -1;
        padding-top: 8px;
        margin-top: 2px;
    }

    /* 长表默认只显示前 12 行 */
    table.m-cards tr.m-clip { display: none !important; }
    .m-more-row {
        display: block;
        width: 100%;
        margin: 0 0 8px;
        padding: 9px 10px;
        border: 1px dashed var(--border);
        border-radius: 10px;
        background: var(--surface-soft);
        color: var(--primary);
        font-size: 12.5px;
        text-align: center;
        font-family: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .m-more-row:active { background: var(--surface-soft-2); }

    /* 仍有横滚的表：给一句提示，滑过就消失 */
    .m-swipe-hint {
        display: block;
        margin: -2px 0 8px;
        font-size: 11.5px;
        color: var(--primary);
        text-align: right;
    }
    .m-swipe-hint.hide { display: none; }

    /* 新人跟进页的状态徽标原来内联写死 10px，手机上太糊 */
    #mainContent .badge[style*="font-size:10px"] {
        font-size: 11.5px !important;
        padding: 2px 8px;
    }

    .m-scroll {
        margin: 0 -14px;
        padding: 0 14px;
    }
    table.m-wide { min-width: 620px; }
    table.m-wide th, table.m-wide td { white-space: nowrap; }
    table.m-wide th:first-child,
    table.m-wide td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--bg-white);
        box-shadow: 1px 0 0 var(--border);
    }
    table.m-wide thead th:first-child { background: var(--surface-soft); }

    /* ---------- 其他 ---------- */
    .empty-state { padding: 32px 16px; }
    .badge { font-size: 12px; }
    .salary-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .profile-hero { flex-direction: column; align-items: flex-start; gap: 12px; }

    /* ---------- 管理端：新人跟进左右两栏改上下 ---------- */
    .onb-side, .onb-main {
        flex: 1 1 100% !important;
        min-width: 0 !important;
        width: 100%;
    }
    .onb-side #onbList { max-height: none; }
    .onb-main { scroll-margin-top: 72px; }
    .onb-side .onb-list-item { padding: 10px 12px !important; }
    .onb-cand { padding: 10px 8px !important; }
    /* 新人任务的勾选项：原来 13px 方框 + 19px 高的标签，手指点不准 */
    #mainContent .onb-act { width: 20px; height: 20px; flex-shrink: 0; }
    #mainContent label:has(> .onb-act) {
        min-height: 40px;
        padding: 9px 4px;
        font-size: 13px !important;
        margin-right: 4px !important;
    }

    /* ---------- 管理端：权限矩阵触控区 ---------- */
    .perm-item { min-height: 42px; }
    .perm-item input[type="checkbox"] { width: 18px; height: 18px; }
    .perm-select-all label { min-height: 42px; display: inline-flex; align-items: center; gap: 6px; }

    /* ---------- 管理端：系统设置顶部页签 ---------- */
    .tabs { scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }

    /* ---------- 管理端：弹窗里的选人清单 ---------- */
    #genEmployeeList label {
        min-height: 42px;
        padding: 8px 0 !important;
        font-size: 14px;
    }
    #genEmployeeList input[type="checkbox"] { width: 18px; height: 18px; flex-shrink: 0; }
    .modal-body .m-scroll { margin: 0; padding: 0; }
}

/* ========== 超小屏 ========== */
@media (max-width: 360px) {
    .main-content { padding-left: 10px; padding-right: 10px; }
    .card { padding: 12px; }
    .stat-card .stat-value { font-size: 19px; }
    .hero-content h1 { font-size: 16px; }
    .m-brand { font-size: 14px; }
    table.m-cards td { font-size: 13.5px; }
}

/* ========== 每周有效时长（移动） ========== */
@media (max-width: 768px) {
    .dur-toolbar { width: 100%; gap: 6px; }
    .dur-toolbar .btn { padding: 5px 10px; font-size: 13px; }
    .dur-pick { flex: 1 1 42%; min-width: 0; font-size: 11.5px; }
    .dur-pick .form-select { flex: 1; min-width: 0; height: 34px; font-size: 16px; }
    .dur-legend { font-size: 11.5px; gap: 10px; }
    .dur-head { display: none; }
    .dur-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "name cur"
            "bars bars"
            "mline mline";
        row-gap: 6px; column-gap: 10px;
        padding: 12px 2px;
    }
    .dur-name { grid-area: name; font-size: 14px; }
    .dur-cur { grid-area: cur; font-size: 15px; }
    .dur-bars { grid-area: bars; }
    .dur-bar { height: 8px; }
    .dur-mline { grid-area: mline; display: block; font-size: 11.5px; color: var(--text-muted); }
    .dur-prev, .dur-delta, .dur-days { display: none; }
    .dur-row:hover { background: transparent; }
    .dur-foot { font-size: 11px; line-height: 1.65; }
}

/* ===== 数据更新时间条（窄屏压缩成两行，别占地方） ===== */
@media (max-width: 768px) {
    .upd-bar { padding: 7px 10px; font-size: 12px; gap: 6px; margin-bottom: 10px; border-radius: 9px; }
    .upd-main { flex: 1 1 auto; order: 1; min-width: 0; }
    .upd-ago { margin-left: 4px; font-size: 11px; }
    .upd-sub { order: 3; flex: 1 1 100%; font-size: 11.5px; gap: 4px; color: var(--text-muted); }
    .upd-refresh { order: 2; font-size: 11.5px; padding: 1px 9px; }
}

/* 厅管规则：手机上「选择厅」单独占一行，下拉占满 */
@media (max-width: 768px) {
    .hall-pick { flex: 1 1 100%; justify-content: space-between; margin-top: 2px; }
    .hall-pick .form-select { width: auto; flex: 1 1 auto; max-width: 62%; }
}
