/* ============================================================
   移动端适配层（≤760px）
   桌面端完全不受影响：除底部标签栏的默认隐藏外，
   所有规则都在媒体查询内。
   表格形态由 mobile.js 打类名决定：
     .m-cards   字段少 → 单列「标签 + 值」
     .m-cards2  字段多 → 双列小格子
     .m-scroll  超宽矩阵或录入表格 → 保留横向滚动
   ============================================================ */

.tabbar{display:none}

@media (max-width:760px){

  /* ---------- 外壳 ---------- */
  html,body{overflow:auto;height:auto}
  body{font-size:14px;-webkit-text-size-adjust:100%}

  .app{display:block;height:auto;min-height:100vh;overflow:visible}
  .sidebar{display:none}
  .main{display:block;height:auto;min-height:100vh}

  .topbar{position:sticky;top:0;z-index:30;height:50px;flex:0 0 50px;padding:0 12px}
  .crumb{font-size:15px;font-weight:600;color:var(--text)}
  .demo-date,.company-switch,.user-role,.user-name,#logoutBtn{display:none}
  .top-right{gap:10px}
  .avatar{width:28px;height:28px;font-size:11px}

  .view{
    padding:12px 12px calc(74px + env(safe-area-inset-bottom));
    overflow:visible;flex:none;
  }
  .view::-webkit-scrollbar{width:0}

  /* ---------- 底部标签栏 ---------- */
  .tabbar{
    position:fixed;left:0;right:0;bottom:0;z-index:50;
    display:flex;background:#fff;border-top:1px solid var(--line);
    padding-bottom:env(safe-area-inset-bottom);
    box-shadow:0 -2px 14px rgba(20,29,43,.07);
  }
  .tb-item{
    flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;
    padding:7px 0 5px;border:none;background:none;font-family:inherit;
    color:var(--muted);font-size:10.5px;position:relative;cursor:pointer;
    -webkit-tap-highlight-color:transparent;
  }
  .tb-ico{font-size:17px;line-height:1}
  .tb-item.active{color:var(--primary);font-weight:600}
  .tb-badge{
    position:absolute;top:2px;left:50%;margin-left:5px;
    background:var(--red);color:#fff;font-size:9.5px;font-weight:600;
    min-width:15px;height:15px;line-height:15px;border-radius:8px;padding:0 3px;
  }
  .tb-badge[data-zero="1"]{display:none}

  /* ---------- 更多面板 ---------- */
  .m-sheet{position:fixed;inset:0;z-index:80;display:none}
  .m-sheet.on{display:block}
  .m-sheet-mask{position:absolute;inset:0;background:rgba(20,29,43,.45)}
  .m-sheet-panel{
    position:absolute;left:0;right:0;bottom:0;background:#fff;
    border-radius:16px 16px 0 0;
    padding:16px 14px calc(20px + env(safe-area-inset-bottom));
    transform:translateY(100%);transition:transform .22s ease;
  }
  .m-sheet.on .m-sheet-panel{transform:none}
  .m-sheet-title{font-size:12.5px;color:var(--muted);margin-bottom:12px;padding-left:2px}
  .m-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:9px}
  .m-grid a{
    display:flex;flex-direction:column;align-items:center;gap:6px;
    padding:13px 4px;border-radius:11px;background:#f5f7fb;
    color:var(--text-2);font-size:11.5px;text-align:center;
  }
  .m-grid a i{font-style:normal;font-size:18px;line-height:1}
  .m-grid a.active{background:var(--primary-soft);color:var(--primary);font-weight:600}

  /* ---------- 页头 / 栅格 ---------- */
  .page-head{flex-direction:column;gap:10px;margin-bottom:12px}
  /* 顶部栏已显示当前页名，页头不再重复大标题 */
  .page-title{display:none}
  .page-desc{font-size:12px;line-height:1.5;margin-top:0}
  .page-actions{width:100%;flex-wrap:wrap;gap:6px}
  .page-actions .btn{flex:1 1 auto;min-width:0;justify-content:center}

  .kpi-grid{grid-template-columns:repeat(2,1fr) !important;gap:9px;margin-bottom:12px}
  .kpi{padding:11px 12px 10px;border-radius:9px}
  .kpi-label{font-size:11px}
  .kpi-value{font-size:18px;letter-spacing:-.3px;margin-top:4px}
  .kpi-foot{font-size:10.5px}

  .grid-2,.grid-3,.grid-73{grid-template-columns:1fr !important;gap:12px}
  /* 栅格子项默认 min-width:auto，图表这类宽内容会把卡片撑出屏幕 */
  .grid-2 > *,.grid-3 > *,.grid-73 > *,.kpi-grid > *{min-width:0}
  .card{border-radius:9px}
  .card-head{padding:11px 12px;flex-wrap:wrap;gap:5px}
  .card-title{font-size:13px}
  .card-body{padding:12px}
  .mb14{margin-bottom:12px}

  /* ---------- 工具条 / 标签页 ---------- */
  .toolbar{gap:6px;margin-bottom:10px}
  .toolbar .input,.toolbar select{flex:1 1 120px;min-width:0;width:auto}
  .toolbar .btn{flex:0 0 auto}
  .tabs{overflow-x:auto;flex-wrap:nowrap;-webkit-overflow-scrolling:touch;scrollbar-width:none}
  .tabs::-webkit-scrollbar{display:none}
  .tab{white-space:nowrap;flex:0 0 auto;padding:8px 12px}

  /* ---------- 表格：卡片化 ---------- */
  .tbl-wrap.m-carded{
    max-height:none !important;border:none;border-radius:0;
    background:transparent;overflow:visible;
  }

  .tbl.m-cards,.tbl.m-cards2{display:block;font-size:13px;border-collapse:separate}
  .tbl.m-cards thead,.tbl.m-cards2 thead{display:none}
  .tbl.m-cards tbody,.tbl.m-cards tfoot,
  .tbl.m-cards2 tbody,.tbl.m-cards2 tfoot{display:block}

  .tbl.m-cards tbody tr,.tbl.m-cards2 tbody tr{
    display:block;background:#fff;border:1px solid var(--line);
    border-radius:10px;padding:10px 12px 11px;margin-bottom:9px;
    box-shadow:0 1px 2px rgba(20,29,43,.05);
  }
  .tbl.m-cards tbody tr:hover,.tbl.m-cards2 tbody tr:hover{
    background:#fff;border-color:#cfd9ea;
  }

  /* 首列作为卡片标题（录入表格除外，那里首列是「日期」这样的字段） */
  .tbl.m-cards:not(.m-input) td:first-child,
  .tbl.m-cards2 td:first-child{
    display:block;font-size:13.5px;font-weight:600;color:var(--text);
    padding:0 0 7px;margin-bottom:5px;
    border-bottom:1px solid var(--line-soft);
  }
  .tbl.m-cards:not(.m-input) td:first-child::before,
  .tbl.m-cards2 td:first-child::before{display:none}

  /* 无表头的列（删除按钮之类）靠右，不占标签位 */
  .tbl.m-cards td.m-act,.tbl.m-cards2 td.m-act{
    justify-content:flex-end;grid-column:1 / -1;
  }
  .tbl.m-cards td.m-act::before,.tbl.m-cards2 td.m-act::before{display:none}

  /* 录入表格竖排：标签在左，输入框占满剩余宽度 */
  .tbl.m-cards.m-input td{padding:4px 0}
  .tbl.m-cards.m-input td > .input,
  .tbl.m-cards.m-input td > input,
  .tbl.m-cards.m-input td > select,
  .tbl.m-cards.m-input td > textarea{
    flex:1 1 auto;min-width:0;width:auto;
  }

  .tbl.m-cards td.m-empty,.tbl.m-cards2 td.m-empty{display:none}

  .tbl.m-cards td[colspan],.tbl.m-cards2 td[colspan]{
    display:block;text-align:center;padding:8px 0;
  }
  .tbl.m-cards td[colspan]::before,
  .tbl.m-cards2 td[colspan]::before{display:none}

  /* 卡片模式下取消冻结列 */
  .tbl.m-cards .stick-1,.tbl.m-cards .stick-2,.tbl.m-cards .stick-end,
  .tbl.m-cards2 .stick-1,.tbl.m-cards2 .stick-2,.tbl.m-cards2 .stick-end{
    position:static;box-shadow:none;background:transparent;
  }

  /* 合计行转汇总条 */
  .tbl.m-cards tfoot tr,.tbl.m-cards2 tfoot tr{
    display:flex;flex-wrap:wrap;gap:3px 16px;
    background:#eef2f9;border-radius:10px;padding:10px 12px;
  }
  .tbl.m-cards tfoot td,.tbl.m-cards2 tfoot td{
    display:inline-flex;align-items:baseline;
    padding:0;border:none;font-weight:600;font-size:12.5px;
  }
  .tbl.m-cards tfoot td::before,.tbl.m-cards2 tfoot td::before{
    content:attr(data-label) " ";flex:none;
    color:var(--muted);font-weight:400;
  }

  /* 形态 A：字段少，标签左、值右 */
  .tbl.m-cards td{
    display:flex;align-items:baseline;gap:10px;
    padding:2.5px 0;border:none;white-space:normal;text-align:left;
    font-size:12.5px;line-height:1.55;color:var(--text);
  }
  .tbl.m-cards td::before{
    content:attr(data-label);
    flex:0 0 70px;color:var(--muted);font-size:11.5px;line-height:1.55;
  }
  .tbl.m-cards td.num{justify-content:space-between}
  .tbl.m-cards td.num::before{flex:0 0 auto}

  /* 形态 B：字段多，双列小格子，标签在上 */
  .tbl.m-cards2 tbody tr{
    display:grid;grid-template-columns:1fr 1fr;
    gap:7px 12px;align-items:start;
  }
  .tbl.m-cards2 td:first-child,
  .tbl.m-cards2 td[colspan]{grid-column:1 / -1}
  .tbl.m-cards2 td{
    display:block;min-width:0;border:none;padding:0;margin:0;
    font-size:12.5px;line-height:1.45;color:var(--text);
    overflow-wrap:anywhere;
  }
  .tbl.m-cards2 td::before{
    content:attr(data-label);display:block;
    font-size:10.5px;line-height:1.35;color:var(--muted);margin-bottom:1px;
  }
  .tbl.m-cards2 td.num{text-align:left}

  /* 横向滚动：宽矩阵 + 录入表格 */
  .tbl.m-scroll{min-width:max-content}
  .tbl.m-scroll th,.tbl.m-scroll td{white-space:nowrap}
  .tbl.m-scroll .stick-2{position:static}
  .tbl-wrap.m-scrollwrap{overflow-x:auto;-webkit-overflow-scrolling:touch;
    background-image:
      linear-gradient(90deg,#fff 30%,rgba(255,255,255,0)),
      linear-gradient(90deg,rgba(255,255,255,0),#fff 70%),
      radial-gradient(farthest-side at 0 50%,rgba(20,29,43,.16),rgba(20,29,43,0)),
      radial-gradient(farthest-side at 100% 50%,rgba(20,29,43,.16),rgba(20,29,43,0));
    background-position:left center,right center,left center,right center;
    background-repeat:no-repeat;
    background-size:26px 100%,26px 100%,11px 100%,11px 100%;
    background-attachment:local,local,scroll,scroll;
  }

  /* 录入表格：允许压缩，但不至于压成一条缝 */
  .modal .tbl.m-scroll,.drawer .tbl.m-scroll{min-width:460px}
  .modal .tbl th[style],.drawer .tbl th[style]{width:auto !important}

  /* ---------- 抽屉：全屏化 ---------- */
  .drawer-mask{justify-content:stretch}
  .drawer{
    width:100% !important;max-width:100% !important;height:100%;
    box-shadow:none;animation:none;overflow:auto;
  }
  .drawer-head{padding:13px 14px}
  .drawer-title{font-size:14.5px;line-height:1.4}
  .drawer-body{padding:12px 14px calc(96px + env(safe-area-inset-bottom))}
  .drawer-foot{
    position:fixed;left:0;right:0;bottom:0;z-index:5;
    padding:10px 14px calc(10px + env(safe-area-inset-bottom));
    justify-content:stretch;gap:8px;
  }
  .drawer-foot .btn{flex:1;justify-content:center}

  /* ---------- 弹窗：底部弹出 ---------- */
  .modal-mask{align-items:flex-end;padding-top:0}
  .modal{
    width:100% !important;max-width:100% !important;
    max-height:92vh;border-radius:16px 16px 0 0;
  }
  .modal-head{padding:13px 14px 10px}
  .modal-title{font-size:14.5px}
  .modal-body{padding:14px}
  .modal-foot{padding:10px 14px calc(10px + env(safe-area-inset-bottom));gap:8px}
  .modal-foot .btn{flex:1;justify-content:center}

  /* ---------- 表单 ---------- */
  .form-grid{grid-template-columns:1fr !important;gap:11px}
  .field.full,.full{grid-column:auto !important}
  /* 结算等表单把字段用 span 2 排成两列，窄屏一律铺满一行 */
  .form-grid > .field{grid-column:auto !important}
  .field label{font-size:12.5px}
  /* iOS：输入框字号 <16px 会触发页面缩放 */
  input,select,textarea,.input{font-size:16px !important}
  .kv{grid-template-columns:86px 1fr !important;gap:6px 9px;font-size:12.5px}
  .section-title{font-size:13.5px;margin:16px 0 8px}
  /* 小节标题 + 说明：窄屏改为两行，避免标题被挤成竖排 */
  .sec-head{flex-wrap:wrap;gap:3px 8px;margin:15px 0 7px}
  .sec-head h4{flex:0 0 auto;white-space:nowrap}
  .sec-head .sec-sub{flex:1 1 100%;font-size:11px;line-height:1.45}
  .kv dt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  /* ---------- 附件 ---------- */
  .attach-list{grid-template-columns:1fr}
  .attach-item img,.attach-ico{width:46px;height:46px}
  .attach-chip b{max-width:130px}
  .attach-box{padding:10px}

  /* ---------- 流程图 / 图表 / 其他 ---------- */
  .flow-wrap{flex-wrap:nowrap;overflow-x:auto;padding-bottom:6px;-webkit-overflow-scrolling:touch}
  .flow-node{min-width:64px}
  .flow-text{font-size:10px}
  .flow-line{min-width:12px}

  .chart-box{height:150px;overflow-x:auto}
  .chart-col{min-width:24px}
  .chart-legend{flex-wrap:wrap;gap:10px;font-size:11px}
  .hbar-top{font-size:11.5px}

  .hint{font-size:12.5px;padding:9px 11px}
  .pager{justify-content:center;flex-wrap:wrap;gap:6px}
  .pager button{padding:5px 12px}
  .pill{font-size:11px}
  .empty{padding:26px 0;font-size:12.5px}

  /* ---------- 登录页 ---------- */
  .login{padding:0 16px}
  .login-card{width:100% !important;max-width:416px;border-radius:4px}
  .login-hd{height:78px}
  .login-hd-title{font-size:20px;letter-spacing:3px;text-indent:1.5px}
  .login-bd{padding:22px 22px 18px}
  .login-divider{font-size:12px;margin-bottom:20px;gap:9px}
  .lf-field{height:48px;margin-bottom:12px}
  .lf-ico{width:44px}
  .lf-field input{font-size:16px}  /* iOS 聚焦不放大 */
  .login-btn{height:48px;font-size:16px;margin-top:6px}
  .login-err{font-size:12px}
  .login-foot{flex-wrap:wrap;gap:4px;font-size:11px;margin-top:12px}

  /* ---------- 权限矩阵：表头隐去，每行「模块 + 两个开关」 ---------- */
  .perm-table{border:none;border-radius:0;overflow:visible}
  .perm-hd{display:none}
  .perm-row{
    grid-template-columns:minmax(0,1fr) auto auto;
    grid-template-areas:"mod v e" "desc desc desc";
    gap:2px 6px;padding:11px 12px;margin-bottom:8px;
    border:1px solid var(--line);border-radius:10px;background:#fff;
  }
  .perm-row:hover{background:#fff}
  .perm-mod{grid-area:mod;min-width:0}
  .perm-mod b{font-size:14px}
  .perm-mod i{font-size:11.5px}
  .perm-desc{grid-area:desc;white-space:normal;font-size:12px;line-height:1.45;margin-top:2px}
  .perm-v{grid-area:v}
  .perm-e{grid-area:e}
  .perm-cell{gap:5px;padding:2px 0 2px 4px}
  .perm-cell em{display:inline}
  .perm-cell input{width:19px;height:19px}
}

/* 超窄屏（≤360px）再收一档 */
@media (max-width:360px){
  .view{padding-left:9px;padding-right:9px}
  .kpi-value{font-size:16px}
  .tb-item{font-size:10px}
  .m-grid{grid-template-columns:repeat(3,1fr)}
}
