/* ============================================================
   移动端适配（≤900px）：
   1 抽屉菜单  2 搜索框+筛选弹层  3 表格卡片化
   4 底部操作栏  5 全屏弹窗  6 触控尺寸
   桌面端不受影响（所有规则都在媒体查询内）
   ============================================================ */
/* 桌面端：手机专属控件一律不显示（汉堡、底部操作栏、弹层） */
.m-burger, #m-actionbar, .m-sheet { display: none; }

@media (max-width: 900px) {
  :root { --m-bar-h: 68px; }

  html, body { -webkit-text-size-adjust: 100%; }
  body.m-mobile { overflow: hidden; }

  /* ---------- 框架：顶栏 / 抽屉 / 内容 ---------- */
  .topbar { height: 54px; flex: 0 0 54px; padding: 0 10px; gap: 8px; }
  .topbar .brand-mark.small { width: 26px; height: 26px; }
  .top-title { font-size: 15px; }
  .top-title .ver, .top-company { display: none; }
  .top-chip { display: none; }
  .top-right { gap: 6px; }
  .top-right .top-btn:not(.m-top-more) { display: none; }
  .m-top-more { width: 42px; height: 42px; font-size: 18px; line-height: 1; display: flex; align-items: center; justify-content: center; }

  .m-burger {
    flex: 0 0 42px; width: 42px; height: 42px; margin-right: 6px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 1px solid rgba(255, 255, 255, .28); border-radius: 9px; background: rgba(255, 255, 255, .14);
  }
  .m-burger span { display: block; width: 17px; height: 2px; border-radius: 2px; background: #fff; }

  .app-body { position: relative; min-height: 0; }
  .sidebar {
    position: fixed; z-index: 95; top: 0; left: 0; bottom: 0;
    width: min(84vw, 320px); flex: none; padding: 0 12px 30px;
    transform: translateX(-102%); transition: transform .24s ease;
    box-shadow: 14px 0 40px rgba(8, 32, 60, .22);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  body.m-nav-open .sidebar { transform: none; }
  .m-drawer-head {
    position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
    height: 54px; margin: 0 -12px 8px; padding: 0 6px 0 16px; background: #fff;
    border-bottom: 1px solid #eaf1f8;
  }
  .m-drawer-head b { font-size: 15px; color: #173c65; }
  .m-drawer-x {
    width: 44px; height: 44px; border: 0; background: none; color: #7b8ea3; font-size: 24px; line-height: 1;
  }
  .side-caption { display: none; }
  .nav-group-title { min-height: 46px; font-size: 14px; }
  .nav-item { min-height: 44px; font-size: 14px; }
  .nav-group.collapsed .nav-items { display: none; }

  .m-backdrop {
    position: fixed; inset: 0; z-index: 94; background: rgba(8, 24, 45, .45);
    opacity: 0; pointer-events: none; transition: opacity .24s;
  }
  body.m-nav-open .m-backdrop { opacity: 1; pointer-events: auto; }

  .content { padding: 10px 10px calc(var(--m-bar-h) + 26px); overflow: auto; -webkit-overflow-scrolling: touch; }
  .statusbar { display: none; }

  /* ---------- 页头 ---------- */
  .page-head { flex-direction: column; align-items: stretch; margin-bottom: 10px; gap: 4px; }
  .page-head > div:first-child { min-width: 0; }
  .page-title { display: flex; flex-wrap: wrap; align-items: center; font-size: 17px; line-height: 1.35; }
  .page-title::before { flex: 0 0 4px; }
  .page-sub { flex: 1 1 100%; display: block; margin: 4px 0 0; font-size: 11.5px; line-height: 1.5; color: #8598ad; }
  .page-head > div:last-child { display: none; }   /* 操作按钮已移至底部栏 */

  .card { border-radius: 10px; margin-bottom: 10px; }
  .info-line { font-size: 11.5px; line-height: 1.6; padding: 8px 12px; }

  /* ---------- 2. 搜索 + 筛选 ---------- */
  .toolbar { padding: 10px; gap: 8px; border-bottom: 1px solid var(--line-2); }
  .toolbar > label, .toolbar > .searchable, .toolbar > span:not(.m-filter), .toolbar > .spacer { display: none; }
  .toolbar:has(.m-filter) > *:not(.m-filter) { display: none; }
  .toolbar.m-no-filter > * { display: none; }

  .m-filter { display: flex; flex-direction: column; gap: 8px; width: 100%; }
  .m-filter-main { display: flex; align-items: center; gap: 8px; }
  .m-search-slot { flex: 1; min-width: 0; display: flex; }
  .m-search-slot > label { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; color: #8a9bad; font-size: 13px; }
  .m-search-slot > label > input {
    flex: 1; min-width: 0; width: auto !important; height: 44px; font-size: 16px;
    border: 1px solid #dbe7f4; border-radius: 10px; background: #f7fbff; padding: 0 12px;
  }
  .m-filter-btn {
    flex: 0 0 auto; position: relative; min-width: 76px; height: 44px; padding: 0 12px;
    border: 1px solid #cfe2f6; border-radius: 10px; background: #eef6ff; color: #15599a;
    font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  }
  .m-filter-btn .m-dot {
    min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: #1d7ed6; color: #fff;
    font-size: 11px; line-height: 17px; font-style: normal; display: none;
  }
  .m-filter-btn.has-on .m-dot { display: inline-block; }
  .m-chips { display: flex; flex-wrap: wrap; gap: 6px; }
  .m-chips:empty { display: none; }
  .m-chip {
    display: inline-flex; align-items: center; gap: 2px; max-width: 100%; min-height: 44px;
    padding: 0 2px 0 12px; border-radius: 22px; background: #eaf4ff; border: 1px solid #cfe4fa;
    color: #23608f; font-size: 12.5px;
  }
  .m-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-chip > button {
    width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: #5c86ad;
    font-size: 17px; line-height: 1; display: flex; align-items: center; justify-content: center;
  }
  .m-chip > button:active { background: #d7e9fa; }
  .m-filter-info { font-size: 11.5px; color: #93a5b8; }

  /* 底部弹层（筛选 / 更多 / 顶部菜单） */
  .m-sheet { position: fixed; inset: 0; z-index: 130; display: none; }
  .m-sheet.show { display: block; }
  .m-sheet-mask { position: absolute; inset: 0; background: rgba(8, 24, 45, .42); }
  .m-sheet-panel {
    position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh;
    background: #fff; border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
    box-shadow: 0 -12px 40px rgba(10, 40, 80, .22); animation: m-up .22s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  @keyframes m-up { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }
  .m-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px 6px; border-bottom: 1px solid #eef3f9; }
  .m-sheet-head b { font-size: 15px; color: #1d3f63; }
  .m-sheet-x { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; color: #7b8ea3; line-height: 1; }
  .m-sheet-body { padding: 12px 14px; overflow: auto; display: flex; flex-direction: column; gap: 12px; flex: 1; }
  .m-sheet-body .m-field { display: flex; flex-direction: column; gap: 6px; align-items: stretch; width: 100%; color: #6b8098; font-size: 12.5px; }
  .m-sheet-body .m-field > input,
  .m-sheet-body .m-field > select,
  .m-sheet-body .m-field > textarea,
  .m-sheet-body .m-field .searchable-input {
    width: 100% !important; height: 44px; font-size: 16px; border: 1px solid #dbe7f4; border-radius: 9px; padding: 0 11px; background: #fff; color: #22384d;
  }
  .m-sheet-body .m-field input[type=date] { width: 100% !important; }
  .m-sheet-body .m-field label { display: flex; align-items: center; gap: 8px; font-size: 15px; color: #33475b; }
  .m-sheet-body .m-field input[type=checkbox] { width: 20px; height: 20px; }
  .m-sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }
  .m-sheet-actions .btn { min-height: 44px; }
  .m-sheet-foot {
    display: flex; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #eef3f9; background: #fff;
  }
  .m-sheet-foot > button { flex: 1; height: 46px; border-radius: 10px; font-size: 15px; font-weight: 700; border: 1px solid #d5e4f4; background: #f5f9fd; color: #34546f; }
  .m-sheet-foot > button.primary { border-color: #1d7ed6; background: linear-gradient(180deg, #2f92e6, #1677d2); color: #fff; }
  .m-sheet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .m-sheet-grid .top-btn,
  .m-sheet-grid .btn {
    display: flex !important; align-items: center; justify-content: center; min-height: 46px;
    background: #f4f9ff; border: 1px solid #d7e6f6; color: #23577f; border-radius: 10px; font-size: 14px;
    flex: none;
  }
  .m-sheet-grid .top-btn.danger { color: #c0392b; border-color: #f0cfd3; background: #fff6f7; }

  /* ---------- 3. 表格 → 卡片 ---------- */
  .table-scroll { max-height: none; overflow: visible; border: 0; border-radius: 0; min-width: 0; }
  table.grid.m-cards {
    display: block; width: 100% !important; max-width: 100% !important; min-width: 0 !important;
    table-layout: auto !important;
    font-size: 13px; background: transparent; overflow: hidden;
  }
  table.grid.m-cards colgroup, table.grid.m-cards col, table.grid.m-cards thead { display: none; }
  table.grid.m-cards tbody { display: block; }
  table.grid.m-cards tr {
    display: flex; flex-direction: column; position: relative; margin: 0 0 10px; padding: 4px 12px 6px;
    max-width: 100%; box-sizing: border-box; overflow: hidden;
    background: #fff; border: 1px solid #e3ecf6; border-radius: 12px;
    box-shadow: 0 1px 3px rgba(20, 60, 110, .05);
  }
  table.grid.m-cards tbody tr:nth-child(even) { background: #fff; }
  table.grid.m-cards td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    max-width: 100%; box-sizing: border-box; min-width: 0; overflow: hidden;
    padding: 7px 2px; border: 0; border-bottom: 1px dashed #eef4fa;
    white-space: normal; word-break: break-word; text-align: right; line-height: 1.5;
  }
  table.grid.m-cards td > * { min-width: 0; max-width: 100%; }
  table.grid.m-cards tr > td:last-child { border-bottom: 0; }
  table.grid.m-cards td::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 42%;
    color: #93a5b8; font-size: 12.5px; text-align: left; font-weight: 400;
  }
  table.grid.m-cards td.num, table.grid.m-cards td.money { text-align: right; font-variant-numeric: tabular-nums; }
  table.grid.m-cards td.idx { display: none; }
  table.grid.m-cards td.mcard-title {
    display: block; order: -2; padding: 8px 2px 9px; font-size: 15px; font-weight: 700; color: #173c62;
    border-bottom: 1px solid #e9f1f9; text-align: left;
  }
  table.grid.m-cards td.mcard-title::before { content: none; }
  table.grid.m-cards td.ops {
    display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
    padding: 10px 0 4px; border-bottom: 0; border-top: 1px solid #eef4fa; margin-top: 2px;
  }
  table.grid.m-cards td.ops::before { content: none; }
  table.grid.m-cards td.ops .link-btn {
    min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center;
    border: 1px solid #d5e6f7; border-radius: 9px; background: #f5faff; color: #1a63a8;
    font-size: 13.5px; text-decoration: none;
  }
  table.grid.m-cards td.ops .link-btn.danger { border-color: #f2d2d6; background: #fff7f8; color: #c0392b; }
  table.grid.m-cards tr.mempty, table.grid.m-cards td.mempty { display: block; border: 0; padding: 0; }
  table.grid.m-cards td.mempty::before { content: none; }
  table.grid.m-cards tr.mempty { border: 0; box-shadow: none; }
  .summary-bar { gap: 10px 16px; padding: 9px 12px; font-size: 12px; }

  /* 平板竖屏（600-900px）：卡片两列排布，避免一屏只看到一张卡 */
  @media (min-width: 600px) {
    table.grid.m-cards tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: start; }
    table.grid.m-cards tr { margin: 0; }
    table.grid.m-cards tr.mempty { grid-column: 1 / -1; }
    .m-sheet-panel { max-width: 560px; margin: 0 auto; }
    .m-sheet-foot > * { flex: 1 1 0; }
    #m-actionbar { justify-content: center; }
    #m-actionbar > button, #m-actionbar > button.m-more-btn { flex: 1 1 0; max-width: 280px; }
  }
  .pager { justify-content: space-between; padding: 10px 4px; font-size: 12px; }
  .pager .btn-sm { min-height: 44px; padding: 0 16px; }

  /* 状态标签页：横向滚动 */
  .tabs { display: flex; overflow-x: auto; gap: 6px; padding: 8px 10px 0; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; min-height: 44px; padding: 0 14px; font-size: 13.5px; white-space: nowrap; }

  /* ---------- 4. 底部操作栏 ---------- */
  #m-actionbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .97); border-top: 1px solid #e2ecf6;
    box-shadow: 0 -6px 18px rgba(18, 52, 88, .08);
    backdrop-filter: blur(6px);
  }
  #m-actionbar:empty { display: none; }
  #m-actionbar > button {
    flex: 1; height: 46px; min-width: 0; border-radius: 11px; border: 1px solid #d5e6f7;
    background: #f6faff; color: #1f5c8f; font-size: 14.5px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #m-actionbar > button.primary { border-color: #1d7ed6; background: linear-gradient(180deg, #2f92e6, #1677d2); color: #fff; box-shadow: 0 4px 12px rgba(29, 126, 214, .28); }
  #m-actionbar > button.m-more-btn { flex: 0 0 84px; }
  #m-actionbar > button:active { transform: scale(.985); }

  /* ---------- 5. 弹窗：全屏单列 + 底部保存 ---------- */
  .modal-mask { padding: 0; align-items: stretch; overflow: hidden; }
  .modal, .modal.wide, .modal.mid, .modal.sm {
    position: static !important; width: 100% !important; max-width: none; height: 100%;
    border-radius: 0; display: flex; flex-direction: column; margin: 0 !important;
    animation: none; box-shadow: none;
  }
  .modal-head { flex: 0 0 auto; padding: 13px 14px; font-size: 15px; cursor: default; }
  .modal-head .x { width: 44px; height: 44px; font-size: 22px; }
  .modal-body { flex: 1; max-height: none; overflow: auto; padding: 14px 14px 20px; -webkit-overflow-scrolling: touch; }
  .modal-foot {
    flex: 0 0 auto; position: sticky; bottom: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: #fff; border-top: 1px solid #e9f0f8; gap: 10px; flex-wrap: wrap;
  }
  .modal-foot .btn { flex: 1 1 calc(50% - 5px); min-width: 0; min-height: 46px; font-size: 15px; }
  .modal-foot .spacer { display: none; }
  /* 弹窗里重复的「添加商品」与占位 span 隐藏，避免底栏按钮挤出屏幕 */
  .modal-foot .btn[data-do="pick"], .modal-foot > span[style*="flex"] { display: none; }

  .doc-meta, .form-grid, .form-grid.cols2, .form-grid.cols4 { grid-template-columns: 1fr !important; gap: 12px; }
  .modal-body > .card { border: 0; box-shadow: none; margin: 0 0 8px; }
  .modal-body > .card > .card-body { padding: 0; }
  /* 明细行表格：容器内横向滚动，不撑破弹窗；固定布局在手机上会把 10 列压扁，改自动布局 + 最小宽度 */
  .modal .table-scroll { overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; }
  .modal .table-scroll table.grid,
  .modal .table-scroll table.doc-items { min-width: 760px !important; table-layout: auto !important; width: 760px !important; }
  .modal .table-scroll table.doc-items td, .modal .table-scroll table.doc-items th { white-space: nowrap; padding: 6px 8px; }
  .modal .table-scroll table.doc-items input, .modal .table-scroll table.doc-items select { min-width: 72px; }

  .form-item.span2, .form-item.span3 { grid-column: auto; }
  .form-item > label { font-size: 13px; color: #4f657c; }
  .form-item input, .form-item select, .form-item textarea { height: 44px; font-size: 16px; border-radius: 9px; }
  .form-item textarea { height: auto; min-height: 84px; padding: 10px 11px; }
  .form-item .hint { font-size: 11.5px; }
  .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .detail-item { padding: 9px 0; }
  .checks label { min-height: 44px; font-size: 14px; }
  .checks input { width: 18px; height: 18px; }
  .searchable-input { height: 44px; font-size: 16px; }
  .searchable-menu { max-height: 40vh; overflow: auto; }

  /* ---------- 6. 触控尺寸 ---------- */
  .btn { min-height: 44px; padding: 0 14px; font-size: 14px; }
  .btn-sm { min-height: 44px; }
  .link-btn { min-height: 44px; }
  input, select, textarea { font-size: 16px !important; }   /* 避免 iOS 聚焦自动放大 */
  .tag { line-height: 20px; font-size: 11.5px; }

  /* 首页等图表容器自适应 */
  .dash-grid, .board-main, .board-second { grid-template-columns: 1fr !important; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stat-row.seven, .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .pd-kpis, .pd-kpis-sales, .pd-kpis-sales-sub { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .pd-kpi { padding: 10px 8px; }
  .pd-kpi-value { font-size: clamp(13px, 3.5vw, 17px); white-space: nowrap; word-break: normal; overflow: visible; letter-spacing: -.2px; }
  .pd-pager { flex-wrap: wrap; gap: 6px; padding: 8px 2px; }
  .pd-page-btn { min-width: 44px; min-height: 44px; font-size: 13px; }
  .chart-card svg, .donut-body svg, .rank-svg { width: 100%; height: auto; }
  .donut-body { flex-direction: row; align-items: center; gap: 10px; }
  .donut-wrap { width: 132px; flex: 0 0 132px; }

  /* 登录页 */
  .lg-screen { align-items: center; justify-content: center; }
  .lg-card { margin: 0 auto; width: calc(100vw - 28px); max-width: 420px; padding: 24px 20px 22px; }
  .lg-title { font-size: 19px; }
  .lg-sub { font-size: 9.5px; }
  .lg-field input { height: 46px; font-size: 16px; }
  .lg-submit { height: 48px; font-size: 16px; }
  .lg-copyright { display: none; }
}

@media (max-width: 380px) {
  .m-filter-btn { min-width: 66px; padding: 0 9px; }
  .page-title { font-size: 16px; }
}
