/* ===== 乐立视 · 手机界面增强层 (2026-10-27) =====
   只在手机宽度生效，桌面端完全不受影响。
   目标：把电脑后台变成“能单手操作”的手机界面：
   1) 底部 5 个主 Tab（首页/筛查/客户/销售/我的）
   2) 表格自动变卡片，不再左右拖动
   3) 内联网格强制单列，杜绝横向溢出
   4) 弹窗近全屏、按钮/输入框适合手指
*/
@media (max-width: 768px) {
  :root {
    --m-tabbar-h: 58px;
    --m-safe-bottom: env(safe-area-inset-bottom, 0px);
  }

  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
  }

  body {
    background: #f5f7fb;
  }

  /* 顶部栏：更紧凑，保留汉堡和页面标题 */
  .header {
    height: 56px !important;
    min-height: 56px !important;
    padding: 0 10px !important;
    position: sticky !important;
    top: 0;
    z-index: 900;
  }
  .header .logo span { font-size: 14px !important; max-width: 42vw; }
  .header .logo img { height: 26px !important; }
  .header-center { display: none !important; }
  .header-right, #header-right-box { gap: 6px !important; }
  #header-right-box span { max-width: 26vw !important; }

  /* 内容区：给底部 Tab 留出空间 */
  .content {
    padding: 10px 10px calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 18px) !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  /* 所有内联网格：手机上一律单列，杜绝 2fr/1fr 被内容撑爆 */
  #content [style*="grid-template-columns"],
  .modal [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  /* 统计卡网格例外：两列更紧凑（JS 会打标） */
  #content .m-stat-grid,
  .modal .m-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  #content .m-stat-grid .stat-card {
    padding: 12px !important;
    min-height: 78px;
  }
  #content .m-stat-grid .stat-card h3,
  #content .m-stat-grid .stat-info h3 { font-size: 19px !important; }

  /* 卡片/标题/正文 */
  .card { padding: 12px !important; border-radius: 12px !important; }
  .card-header { padding: 10px 2px 8px !important; gap: 8px !important; }
  .card-title { font-size: 15px !important; }
  .card-body { padding: 6px 0 0 !important; }

  /* 筛选条：输入框整行，按钮不挤压 */
  .filter-bar, .search-bar, .opt-toolbar, .page-header-row, .section-intro {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    margin: 10px 0 !important;
  }
  .filter-bar input, .filter-bar select, .search-bar input, .search-input,
  .filter-item, .filter-item input, .filter-item select {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    width: 100% !important;
  }
  .filter-bar .btn, .search-bar .btn, .opt-toolbar .btn { flex: 1 1 auto; }

  /* 表单：iOS 16px 防自动放大 */
  input, select, textarea {
    font-size: 16px !important;
  }
  .form-group, .form-row { margin-bottom: 12px !important; }
  .form-row { display: block !important; }
  .form-row > * { width: 100% !important; }

  /* 按钮：手指友好 */
  .btn { min-height: 40px; padding: 9px 14px !important; border-radius: 9px; }
  .btn-sm { min-height: 34px; padding: 6px 10px !important; }
  .action-cell .btn, td .btn { margin: 2px 0; }

  /* 弹窗：近全屏，底部按钮并排 */
  /* main.min.css 里有 .screening-overlay > .modal 的 !important，
     这里用更高优先级把弹窗真正做成手机全屏 */
  html body .modal,
  html body .screening-overlay > .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    top: 0 !important;
    left: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--m-safe-bottom) !important;
  }
  /* 压过 .screening-overlay > .modal:not(...):not(...) 的 height:auto !important */
  html body .screening-overlay > .modal:not(.flex-layout):not([style*="flex"]),
  html body .screening-overlay > .modal.flex-layout,
  html body .screening-overlay > .modal[style*="flex"] {
    height: 100vh !important;
    max-height: 100vh !important;
  }
  html body .modal-content,
  html body .modal-container {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  html body .modal-overlay {
    padding: 0 !important;
    align-items: stretch !important;
    justify-content: stretch !important;
  }
  .modal-header { position: sticky; top: 0; background: #fff; z-index: 5; }
  .modal-header, .modal-footer { padding: 12px 14px !important; }
  .modal-body { padding: 14px !important; }
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #eef1f5;
  }
  .modal-footer .btn { flex: 1 1 0; }

  /* ===== 表格自动变卡片 ===== */
  .m-card-wrap {
    border: none !important;
    background: transparent !important;
    overflow: visible !important;
  }
  table.m-card-table {
    min-width: 0 !important;
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    display: block !important;
    background: transparent !important;
  }
  table.m-card-table thead { display: none !important; }
  table.m-card-table tbody { display: block !important; width: 100% !important; }
  table.m-card-table tr {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box;
    background: #fff;
    border: 1px solid #e8edf3;
    border-radius: 12px;
    margin: 0 0 10px !important;
    padding: 6px 12px !important;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
  }
  table.m-card-table tr:last-child { margin-bottom: 0 !important; }
  table.m-card-table td {
    display: flex !important;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    width: 100% !important;
    box-sizing: border-box;
    border: none !important;
    border-bottom: 1px dashed #f0f2f5 !important;
    padding: 8px 0 !important;
    white-space: normal !important;
    word-break: break-all;
    font-size: 13.5px !important;
    line-height: 1.45;
    text-align: right !important;
  }
  table.m-card-table td:last-child { border-bottom: none !important; }
  table.m-card-table td::before {
    content: attr(data-label);
    flex: 0 0 34%;
    max-width: 34%;
    text-align: left;
    color: #7b8a9a;
    font-weight: 600;
    font-size: 12.5px;
    line-height: 1.6;
  }
  table.m-card-table td[data-label=""]::before,
  table.m-card-table td.m-no-label::before {
    content: "" !important;
    flex: 0 0 0 !important;
    max-width: 0 !important;
  }
  table.m-card-table td.m-cell-title {
    font-size: 15px !important;
    font-weight: 700;
    color: #1f2d3d;
    text-align: left !important;
    padding: 4px 0 7px !important;
    border-bottom: 1px solid #f0f2f5 !important;
  }
  table.m-card-table td.m-cell-title::before { content: "" !important; flex: 0 0 0 !important; max-width: 0 !important; }
  table.m-card-table td.m-cell-empty { display: none !important; }
  table.m-card-table td.m-cell-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 9px !important;
  }
  table.m-card-table td.m-cell-actions::before { content: "" !important; flex: 0 0 0 !important; max-width: 0 !important; }
  table.m-card-table td .btn { margin: 1px 0; }

  /* 空数据行不要做成卡片 */
  table.m-card-table tr.m-empty-row {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  table.m-card-table tr.m-empty-row td {
    justify-content: center !important;
    border: none !important;
    padding: 30px 0 !important;
    color: #a0aec0;
  }
  table.m-card-table tr.m-empty-row td::before { content: "" !important; flex: 0 0 0 !important; max-width: 0 !important; }

  /* 底部 Tab 栏 */
  #m-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 950;
    display: flex;
    align-items: stretch;
    height: calc(var(--m-tabbar-h) + var(--m-safe-bottom));
    padding-bottom: var(--m-safe-bottom);
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid #e6ebf2;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  #m-tabbar .m-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    color: #8a99a8;
    font-size: 10.5px;
    line-height: 1.2;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    padding: 4px 0 2px;
  }
  #m-tabbar .m-tab i { font-size: 19px; height: 21px; }
  #m-tabbar .m-tab.active { color: #1677ff; font-weight: 700; }
  #m-tabbar .m-tab.active i { transform: translateY(-1px); }
  #m-tabbar .m-tab:active { background: #f2f6ff; }

  /* 登录页不要显示底部 Tab（JS 也会移除） */
  body.m-login #m-tabbar { display: none !important; }
  body.m-login .content { padding-bottom: 20px !important; }

  /* 隐藏桌面用的“页脚/版权”占位，减少手机滚动 */
  .footer, .page-footer { display: none !important; }
}

/* 极窄屏：统计卡单列，文字更小 */
@media (max-width: 360px) {
  #content .m-stat-grid { grid-template-columns: 1fr !important; }
  #m-tabbar .m-tab { font-size: 10px; }
}
