/* 报价方案 · 方案页移动端适配（通用）
 * 仅作用于窄屏（<=768px），桌面端与打印样式不受影响。
 * 配合 assets/plan-mobile.js 注入的 data-label，将多列表格转为「卡片式」逐行可读布局，
 * 每张卡片左列粗体标签、右列内容，彻底消除手机端横向滚动与表格溢出。
 */
@media (max-width: 768px) {
  /* 容器：去掉过大留白，贴边阅读 */
  .sheet,
  .page {
    max-width: 100%;
    margin: 8px auto;
    padding: 18px 14px;
    border-radius: 0;
    box-shadow: 0 2px 10px rgba(31, 78, 95, .10);
  }
  .topbar {
    margin: -18px -14px 16px;
  }

  /* 文档头：标题与元信息改为纵向堆叠，避免挤压重叠 */
  header.doc-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 14px;
    margin-bottom: 20px;
  }
  .doc-head .meta {
    text-align: left;
    margin-top: 2px;
  }
  .cover {
    /* .page 模板的封面块在小屏下同样纵向自适应 */
    text-align: left;
  }

  /* 签名区改为纵向堆叠 */
  .sign {
    flex-direction: column;
    gap: 16px;
  }
  .sign div {
    width: 100%;
  }
  .sign .line {
    margin-top: 30px;
  }

  /* 标题字号收敛，避免溢出 */
  h1 {
    font-size: 20px;
    letter-spacing: .5px;
  }
  h2 {
    font-size: 15px;
  }
  h3 {
    font-size: 14px;
  }

  /* 提示框留白收敛 */
  .callout,
  .risk,
  .important,
  .note {
    padding: 10px 12px;
    font-size: 13px;
  }

  /* 通用图片不溢出 */
  img {
    max-width: 100%;
    height: auto;
  }

  /* ===== 表格：卡片式堆叠（核心修复） ===== */
  table {
    display: block;
    width: 100%;
    border: 1px solid var(--line, #d8e0e3);
    border-radius: 10px;
    overflow: hidden;
    margin: 14px 0;
    background: #fff;
    font-size: 13px;
    border-collapse: collapse;
  }
  /* 隐藏原表头（列含义改由每行 data-label 呈现） */
  thead {
    display: none;
  }
  tbody,
  tfoot {
    display: block;
    width: 100%;
  }
  tbody tr,
  tfoot tr {
    display: block;
    width: 100%;
    border-bottom: 1px solid var(--line, #d8e0e3);
    padding: 9px 12px;
  }
  tbody tr:last-child,
  tfoot tr:last-child {
    border-bottom: none;
  }
  tbody tr:nth-child(even) {
    background: var(--soft, #f4f7f8);
  }

  /* 每个单元格独立成行（卡片式），显式 100% 宽度，避免被表格布局残留百分比挤窄 */
  td,
  th {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: none;
    padding: 4px 0;
    text-align: left;
    vertical-align: top;
    font-size: 13px;
    line-height: 1.6;
  }
  /* 行内标签（由 plan-mobile.js 注入列标题），左列固定占比，右列内容跟随换行 */
  td::before,
  th::before {
    content: attr(data-label);
    display: inline-block;
    width: 38%;
    min-width: 38%;
    margin-right: 8px;
    font-weight: 600;
    color: var(--brand, #1f4e5f);
    word-break: break-all;
    vertical-align: top;
  }
  /* 数值列：移动端统一左对齐、允许换行，避免与标签间出现大空隙或被 nowrap 顶飞 */
  td.num,
  th.num {
    text-align: left;
    white-space: normal;
    font-variant-numeric: tabular-nums;
  }
  /* 汇总 / 合计行高亮（保留各自列标签，逐行可读） */
  tr.total td,
  tr.grand td,
  tfoot td {
    background: #fbf6e7;
    font-weight: 700;
    color: var(--brand, #1f4e5f);
  }
  /* 跨列汇总单元格（如整行「首年合计」横幅）：占满整行，标签留空隐藏 */
  td[colspan],
  th[colspan] {
    width: 100%;
    font-weight: 700;
  }
  td[colspan]::before,
  th[colspan]::before {
    display: none;
    width: auto;
    margin-right: 0;
  }
  /* 兜底：无标签且非跨列的单元格，隐藏占位标签，内容占满整行 */
  td[data-label=""]:not([colspan])::before,
  th[data-label=""]:not([colspan])::before {
    display: none;
    width: auto;
    margin-right: 0;
  }
}

@media (max-width: 480px) {
  .sheet,
  .page {
    padding: 14px 12px;
  }
  h1 {
    font-size: 18px;
  }
  td::before,
  th::before {
    width: 42%;
    min-width: 42%;
  }
}
