/* ============================================================
 * mobile-fix.css · 通用窄屏适配 (P92-53 · 2026-10-26)
 * ------------------------------------------------------------
 * 这个文件解决一类反复出现的排版缺陷:
 *   【表格/多列网格在手机上被压扁】—— 每列只剩 ~35px,
 *   中文被压成竖排单字(「王店长」竖着排), 页面还能左右乱滑。
 *
 * 根因不是"忘了写 @media", 而是 @media 里只写了
 *   table { font-size:12px } / th,td { padding:6px 4px }
 * 这类【缩字号】的规则 —— 缩字号不会让表格产生滚动,
 * 只会让列更挤 -> 竖排。
 *
 * 正确做法(本文件):
 *   表格 -> 自身横向滚动 + 内容按自然宽度排(列不被压缩)
 *   多列网格 -> 窄屏改单列堆叠
 *
 * 桌面端零影响: 所有规则都在 @media (max-width: 900px) 里。
 * 断点 900px 与项目现有写法一致(admin-side.css / bottom-nav.css 都是 900)。
 * ============================================================ */

@media (max-width: 900px) {

  /* ---------- 表格: 自身滚 + 列不被压缩 ---------- */
  /* display:block 让表格成为可滚动容器(内部 tr/td 仍是表格布局, 列对齐不变);
     width:100% + max-width:max-content:
       宽表 -> 块宽=容器宽, 内部按内容自然宽度排, 列不压缩, 溢出部分自己滚
       窄表 -> 内容本来就窄, 不受影响, 也不会被拉宽
     (写死 min-width 的坑: 3 列的小表会被拉到 720px, 视觉上很空) */
  table {
    display: block;
    width: 100%;
    max-width: max-content;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 表格自己会横向滚了, 单元格就别再换行挤成竖排 */
  table td, table th { white-space: nowrap; }

  /* ---------- flex 容器的直接子项: 放开 min-width ---------- */
  /* body 是 flex 容器时(service-* 等页面), 直接子项默认 min-width:auto,
     也就是"不肯缩到内容以下" —— 表格一宽, 整页就被撑出横向滚动条。
     实测(2026-10-26): service-item 437 / service-membership 606 /
     service-work-order 474, 而视口只有 390。
     给直接子项放开 min-width:0 之后全部回到 390, 表格仍能在内部横滚,
     竖排也是 0(说明表格保宽那条规则没被破坏)。 */
  body > * { min-width: 0; }

  /* ---------- 多列网格: 窄屏改单列 ---------- */
  /* repeat(3,1fr) 在 390px 宽下每列只剩 ~110px, 内容撑破视口
     (实测 pricing.html scrollW=539 > clientW=390, 整个页面能左右滑) */
  .grid-3,
  .tier-grid,
  .price-grid,
  .compare-grid,
  .feature-grid {
    grid-template-columns: 1fr !important;
  }
  /* 单列后, 原来给多列留的最小高度就不需要了(否则空一大块) */
  .tier ul { min-height: 0; }

  /* ---------- 窄屏卡片式表格(P92-71) ----------
     上面那套「表格自己横滚」能保证页面不被撑破, 但表格内容照样比手机宽:
     实测 390px 上 super-* 的 11 张表最宽 1293px(要横拖 3.3 倍), 手机上读不了。

     修法: 排不下的表由 js/narrow-table.js 打上 .narrow-card, 在这里转成卡片式 ——
     每行一张卡, 单元格前带列名标签(data-label 由 JS 从表头自动注入)。
     ★ 不加 min-width 硬撑 —— 那只会把表格撑得更宽, 还是得横滚。
       页面上原有的 min-width:960px 之类, 在卡片式下一律被中和成 0。 */
  table.narrow-card,
  table.narrow-card tbody,
  table.narrow-card tr,
  table.narrow-card td,
  table.narrow-card th {
    display: block;
    width: auto;
    max-width: none;
    white-space: normal;
    overflow-x: visible;
  }
  /* min-width 用 !important: 页面里像 #tableWrap table{min-width:960px} 这种
     选择器比 table.narrow-card 更特异, 不用 !important 压不住。 */
  table.narrow-card { width: 100%; max-width: 100%; min-width: 0 !important; }
  table.narrow-card thead { display: none; }
  /* 没有 thead 的表: 首行就是表头, 转卡片后藏掉(不然会多出一张表头卡) */
  table.narrow-card tr.nc-head { display: none; }
  table.narrow-card tbody tr {
    border: 1px solid #1f2940;
    border-radius: 10px;
    margin: 10px 0;
    padding: 4px 0;
    background: rgba(255, 255, 255, .02);
  }
  table.narrow-card tbody td {
    border: none;
    padding: 6px 12px;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  /* 行内 style 里的 white-space:nowrap 会压住卡片式 —— 实测两处:
       super-merchant 的操作列(按钮排成一行 463px)
       super-settings 的 <code> 文件名(标签+文件名溢出 7px)
     行内 style 只能用 !important 压。 */
  table.narrow-card tbody td { white-space: normal !important; }
  /* 行内的 text-align:center 会让「默认：✅」这类单元格整块居中,
     和其它字段的左对齐不一致 —— 卡片式里统一左对齐(行内 style 只能用 !important 压)。 */
  table.narrow-card tbody td { text-align: left !important; }
  table.narrow-card tbody td code,
  table.narrow-card tbody td pre {
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-all;
  }
  table.narrow-card tbody td::before {
    content: attr(data-label) "：";
    color: #8C8C8C;
  }
  /* 取不到列名的单元格: 不要显示一个孤零零的冒号 */
  table.narrow-card tbody td.nc-nolabel::before { content: none; }
  /* 浅色主题 */
  body.light-theme table.narrow-card tbody tr {
    border-color: #e2e8f0;
    background: rgba(15, 23, 42, .02);
  }
  body.light-theme table.narrow-card tbody td::before { color: #64748b; }
}
