/* ============================================================
 * 火灵CRM 1.0 — 移动端适配补丁 (style.mobile.css)
 * 加载顺序: 在 css/style.css 之后加载(同版本号 ?v=202610052300)
 * 作用:
 *   1) 侧栏 -> 顶部汉堡按钮 + 左侧滑出抽屉(默认收起)
 *   2) 表格 -> 容器横向滚动(保留火灵ERP列表列, 不压缩单元格)
 *   3) 表单/按钮 -> 全宽 + >=44px 触控目标
 *   4) modal -> 全屏化
 *   5) topbar / FAB / safe-area 精简适配
 * 说明: 本文件需后加载, 并用更高特异性/!important 覆盖 style.css 末尾
 *       已有的 @media(max-width:768px) 60px 图标侧栏规则。
 * ============================================================ */

/* ---------- 汉堡按钮 & 抽屉遮罩(由 mobile-nav.js 注入) ---------- */
#mb-nav-btn {
  display: none;               /* >768px 隐藏, 仅移动端出现 */
  width: 40px; height: 40px;
  margin-right: 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px; line-height: 1;
  color: var(--text-main);
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
#mb-nav-mask {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 55;                 /* 低于侧栏(60), 高于内容 */
}
#mb-nav-mask.show { display: block; }

/* 左缘提示条: 抽屉收起态显示, 提示"可向右滑出/点击展开" */
#mb-edge-grip {
  display: none;                 /* 默认隐藏, 仅 .show 且移动端出现 */
  position: fixed;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 22px; height: 56px;
  background: rgba(99, 102, 241, .85);
  color: #fff;
  border-radius: 0 12px 12px 0;
  align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
  z-index: 56;                   /* 低于侧栏(60)/遮罩(55)之上, 仅收起态显示 */
  box-shadow: 2px 0 10px rgba(15, 23, 42, .25);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;            /* 提示条自身不抢页面的触摸手势 */
}
#mb-edge-grip span { transform: translateX(-1px); }
#mb-edge-grip.show { display: flex; }

/* ============================================================
 * 断点一: <=768px (大手机 / 小平板竖屏)
 * ============================================================ */
@media (max-width: 768px) {

  /* 侧栏改为离屏抽屉: 默认隐藏在左侧, 宽度 260px */
  .sidebar {
    width: 260px !important;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .35);
  }
  body.nav-open .sidebar { transform: translateX(0); }

  /* 恢复完整导航文字(覆盖原 60px 图标条隐藏文字的规则) */
  .sidebar .nav-item span:not(.nav-ico) { display: inline; }

  /* 主内容取消左边距, 占满整宽 */
  .main { margin-left: 0 !important; }

  /* 顶部栏: 给汉堡按钮让位, 精简内边距 */
  .topbar {
    height: 54px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  #mb-nav-btn { display: inline-flex; }

  /* 场景切换器在 <=768 收窄, 避免挤压标题 */
  .topbar-user { gap: 8px; }
  .scene-switcher { padding: 2px; }
  .scene-btn { padding: 4px 8px; font-size: 11px; }

  /* 内容区收窄留白 */
  .content { padding: 14px 12px; }

  /* 统计卡片保持 2 列(沿用), 间距收紧 */
  .stat-grid { gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 22px; }

  /* 表单栅格单列堆叠 */
  .form-grid, .form-grid-3 { grid-template-columns: 1fr !important; }

  /* 触控目标: 输入框/按钮最小高度 44px, 字号16px防iOS自动缩放 */
  .form-item input, .form-item select, .form-item textarea {
    min-height: 44px;
    font-size: 16px;
  }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 34px; }
  .toolbar input[type=text], .toolbar select { min-height: 42px; font-size: 16px; }

  /* 表格: 容器横向滚动, 保留原列样式(nowrap 由 style.css 保证) */
  .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table.tbl th, table.tbl td { padding: 10px 12px; }

  /* 弹窗全屏化 */
  .modal-mask { padding: 0 !important; align-items: stretch; }
  .modal {
    max-width: 100% !important;
    width: 100%;
    min-height: 100vh;
    border-radius: 0;
    display: flex; flex-direction: column;
  }
  .modal-body { flex: 1; overflow-y: auto; padding: 16px; }
  .modal-head, .modal-foot { padding: 14px 16px; }

  /* FAB 悬浮按钮贴边 + 底部安全区 */
  #fb-fab {
    right: 14px !important;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* body 底部安全区留白 */
  body { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* ============================================================
 * 断点二: <=480px (普通手机)
 * ============================================================ */
@media (max-width: 480px) {
  /* 顶栏更精简: 隐藏用户名文字, 只留头像/按钮 */
  .topbar-user .user-chip span:not(.avatar) { display: none; }
  .scene-switcher { display: none; }     /* 手机端隐藏场景切换, 避免拥挤 */
  .topbar-title { font-size: 16px; }

  /* 统计卡片仍 2 列, 数值再缩小 */
  .stat-num { font-size: 20px; }
  .stat-ico { width: 42px; height: 42px; font-size: 20px; }

  /* 卡片内边距收紧 */
  .card { padding: 14px; }
  .content { padding: 12px 10px; }

  /* 工具条按钮全宽换行 */
  .toolbar .btn { flex: 1 1 auto; }
  .toolbar input[type=text] { flex: 1 1 100%; }

  /* 详情键值改纵向堆叠 */
  .detail-row { flex-direction: column; }
  .detail-row .k { width: auto; margin-bottom: 2px; }

  /* 分页按钮紧凑 */
  .pagination { flex-wrap: wrap; }
}

/* ============================================================
 * 火灵CRM 移动端增强 v2 (2026-10-24) — 业务模块窄屏打磨
 * 追加段，后加载覆盖；仅窄屏生效，宽屏零影响。
 * 覆盖: 快捷卡横滑 / 看板2列 / 页头换行 / tab横滑 / 联络台堆叠 /
 *       表格紧凑 / 工具条铺满 / 弹窗按钮 / 抽屉触控 / FAB避让
 * ============================================================ */

@media (max-width: 768px) {
  /* 顶部快捷卡: 分组条横向可滚、隐藏滚动条、卡片触控反馈 */
  .top-tabbar { padding: 6px 8px; }
  .top-tabbar .tg-row { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .top-tabbar .tg-row::-webkit-scrollbar { display: none; }
  .top-tabbar .tg-group { flex: 0 0 auto; }
  .top-tabbar .pg-grid { gap: 8px; padding: 8px 2px; }
  .top-tabbar .pg { min-width: 74px; padding: 10px 10px 8px; border-radius: 12px; }
  .top-tabbar .pg:active { transform: scale(.96); }

  /* 看板统计卡(内联 repeat(4))压成 2 列 */
  .stat-cards { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }

  /* 页头: 标题与右侧操作换行不挤压 */
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head h2 { font-size: 18px; }

  /* tab 切换条横向可滚、按钮不折行 */
  .tab-bar { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-bar .btn { white-space: nowrap; flex: 0 0 auto; }

  /* 联络工作台: 左分组导航 + 右列表 纵向堆叠 */
  div:has(> .card > .wb-nav):has(> #wb-list) { flex-direction: column !important; }
  div:has(> .card > .wb-nav) > .card:first-child { width: 100% !important; flex: none !important; }

  /* 表格紧凑, 保留横滑 */
  table.tbl th, table.tbl td { padding: 9px 10px; font-size: 13px; }
  /* 工具条筛选控件纵向铺满整行
     关键修正: base 的 .toolbar 是 nowrap+横滑, 即便给检索框设 flex:1 1 100% 也会被压在一条可横滑行里,
     内联 width:200/220/240px 又把检索框压短。改成 wrap 让其独占一行撑满, 并强制检索框 100% 宽。 */
  .toolbar { gap: 8px; flex-wrap: wrap; overflow: visible; }
  .toolbar input[type=text], .toolbar select { flex: 1 1 100% !important; min-width: 0; }
  .toolbar input[type=text] { width: 100% !important; }
  .toolbar .grow { flex: 1 1 100%; }

  /* 弹窗底部操作按钮均分铺满 */
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }

  /* 抽屉导航触控目标 >=44px */
  .sidebar .nav-item { min-height: 44px; padding: 12px 14px; }

  /* 反馈悬浮球缩小避让主操作 */
  #fb-fab { width: 42px !important; height: 42px !important; font-size: 12px !important; right: 12px !important; }
}

@media (max-width: 480px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .top-tabbar .pg { min-width: 66px; font-size: 11px; padding: 9px 8px 7px; }
  .card { padding: 14px 12px; }
  table.tbl th, table.tbl td { padding: 8px 8px; font-size: 12.5px; }
  .page-head h2 { font-size: 17px; }
}


/* ============================================================
 * 火灵CRM 移动端适配 v3 (2026-10-24) — 内联栅格/附件/顶栏收尾
 * 追加段，后加载覆盖；仅窄屏生效，宽屏零影响。
 * 覆盖: 无类名内联 grid(附件墙/商机卡墙/管理后台双栏/待办双栏)
 *       窄屏压列, 附件图不溢出, 顶栏右侧按钮组横滚
 * ============================================================ */

@media (max-width: 768px) {
  /* 内联 3 列卡片墙/附件墙 -> 2 列 */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns:repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  /* 附件缩略图不溢出卡片 */
  [style*="grid-template-columns"] img {
    max-width: 100%;
    height: auto;
  }
  /* 顶栏右侧用户/按钮组可横滚，避免挤压标题 */
  .topbar > .topbar-right, .topbar-user {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .topbar > .topbar-right::-webkit-scrollbar, .topbar-user::-webkit-scrollbar { display: none; }
}

@media (max-width: 480px) {
  /* 小手机: 内联 3 列与 2 列统一压成单列纵向流 */
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns:repeat(3,1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  /* 附件块保留 2 列缩略图(比单列更省纵向空间) */
  [style*="margin-top:8px"][style*="1fr 1fr 1fr"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}


/* ============================================================
 * 火灵CRM 手机专属UI v4 (2026-10-24) — 像手机，不是PC缩小
 * 动态流卡片化 / 统计大数字 / 看板条紧凑 / 触控与留白
 * 仅窄屏生效，宽屏零影响。
 * ============================================================ */

@media (max-width: 768px) {
  /* 内容区更透气 */
  .content { padding: 12px 10px 24px; }
  .card { margin-bottom: 12px; border-radius: 14px; box-shadow: 0 1px 4px rgba(15,23,42,.06); }
  .card-title { font-size: 14px; padding: 12px 14px 8px; }

  /* 统计大数字卡：更醒目、触控 */
  .stat-card, .stat-cards > .card { padding: 14px; border-radius: 14px; }
  .stat-num { font-size: 24px !important; font-weight: 700; }
  .stat-label { font-size: 12px; color: #64748b; }
  .stat-ico { width: 40px; height: 40px; font-size: 18px; border-radius: 10px; }

  /* 最近跟进动态：纯文本流 -> 卡片化 */
  .timeline { padding: 4px 12px 12px; }
  .tl-item {
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  .tl-head { font-size: 13px; margin-bottom: 4px; }
  .tl-head b { color: #0f172a; }
  .tl-item > div:not(.tl-head), .tl-item .muted { font-size: 12px; line-height: 1.6; color: #475569; }

  /* 看板漏斗 / 客户等级条：行高收紧、金额右对齐不换行 */
  .mb12 { margin-bottom: 10px !important; }
  .flex-between { font-size: 12px; }
  .flex-between > * { white-space: nowrap; }
  .flex { gap: 8px !important; align-items: center; }

  /* 快捷入口大触控 */
  .top-tabbar .pg { border-radius: 14px; }
  .top-tabbar .pg .pg-ico { font-size: 22px; }
}

@media (max-width: 480px) {
  .stat-num { font-size: 22px !important; }
  .card-title { font-size: 13px; }
  .tl-item { padding: 9px 10px; }
  /* 动态里长模块标签折行不溢出 */
  .tl-item { word-break: break-word; }
}

/* v4.1 修正: 快捷卡横滑+白底卡片 */
@media (max-width:768px){
  .top-tabbar .tg-row{ display:flex !important; flex-wrap:nowrap; overflow-x:auto; -webkit-overflow-scrolling:touch; scrollbar-width:none; }
  .top-tabbar .tg-row::-webkit-scrollbar{ display:none; }
  .top-tabbar .pg{ flex:0 0 auto; width:78px; background:#fff; border:1px solid #eef2f7; border-radius:14px; padding:12px 6px; text-align:center; font-size:11px; box-shadow:0 1px 3px rgba(15,23,42,.05); }
  .top-tabbar .pg .pg-ico{ font-size:22px; display:block; margin-bottom:4px; }
}
@media (max-width:480px){
  .top-tabbar .pg{ width:70px; padding:10px 4px; }
  .topbar-user .user-chip span:not(.avatar){ display:none; }
}

/* 详情页头部：标题与操作按钮换行铺满，消除整行左右滑动（R9 手机端详情头部横滑修复） */
@media (max-width: 768px){
  .flex-between, .page-head { flex-wrap: wrap; gap: 8px; }
  .flex-between > .flex.gap-sm,
  .page-head > .flex.gap-sm { flex: 1 1 100%; flex-wrap: wrap; margin-top: 8px; row-gap: 8px; }
  .flex-between > div { white-space: normal; }
}