/* ============================================================================
 * 移动端适配层 · mobile.css                            2026-10-03
 * ----------------------------------------------------------------------------
 * 设计原则
 *   1) **全部规则包裹在 @media (max-width:768px) 内** —— PC 端（窗口 >768px）
 *      这些规则完全不参与层叠，页面渲染与引入前逐像素一致。
 *   2) 不改任何既有非媒体查询样式，不动 DOM 结构；只做"窄屏增量"。
 *   3) 宽表格在手机上转为卡片（每行一张卡，字段名+值竖排，无需左右滑）。
 *      卡片化由 static/js/mobile.js 给数据表加 .cardable 类 + td[data-label]。
 *
 * 逃生舱
 *   · 给 <table class="no-card"> → 跳过卡片化，保持原表格（自动横向滑动）
 *   · 给任意元素加 class="m-hide" → 仅在手机端隐藏
 *   · 给任意元素加 class="m-only" → 仅在手机端显示
 * ========================================================================== */

@media (max-width: 768px) {

  /* ---------- 1 全局：防溢出 / 防 iOS 字号放大 ---------- */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { overflow-x: clip; }            /* clip 不破坏 position:sticky；老浏览器忽略 */
  img, canvas, svg { max-width: 100%; }
  pre, .pre, .code { overflow-x: auto; }

  /* ---------- 2 页头：允许折行、收紧留白、解除绝对定位子元素 ---------- */
  header, .top, .topbar, .header, .hdr, .pagehead {
    height: auto !important; min-height: 0 !important;
    flex-wrap: wrap !important;
    gap: 6px 10px !important;
    padding: 9px 12px !important;
  }
  header h1, .top h1, .topbar h1, .header h1 { font-size: 16px !important; }
  header .sub, .top .sub { font-size: 11.5px !important; }
  /* 右上角用户名/日期一类的绝对定位，窄屏会压住标题 → 回到文档流 */
  header .user, header .usr, .top .user, .header .user, .topbar .user {
    position: static !important;
    margin: 2px 0 0 !important;
    font-size: 12px !important;
    line-height: 1.9 !important;
  }
  header .user a, .top .user a { margin: 0 12px 0 0 !important; }
  /* 页头里的按钮/链接统一紧凑 */
  header button, .top button, .topbar button { min-height: 30px; padding: 4px 10px; }
  header a, .top a { flex: none; }

  /* ---------- 3 容器：内边距收紧 ---------- */
  .wrap, .container, .page, .main, .content, .body {
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  .wrap { margin-top: 12px !important; }

  /* ---------- 4 筛选/工具条：自动折行 ---------- */
  .bar, .frm, .filters, .toolbar, .actbar, .batchbar, .qbar, .tabs, .pager {
    flex-wrap: wrap !important;
    gap: 7px 8px !important;
  }
  .qbar .qbreak { flex-basis: 100%; height: 0; }
  .bar .sp, .frm .sp { flex-basis: 100%; height: 0; }
  /* 输入框别写死宽度，跟着容器走 */
  .bar input, .frm input, .filters input, .toolbar input,
  .bar select, .frm select, .filters select, .toolbar select {
    min-width: 0;
    max-width: 100%;
  }
  .fld { min-width: 0; flex: 1 1 44%; }
  .fld input, .fld select { width: 100% !important; }

  /* ---------- 5 表单控件：字号 16px 以阻止 iOS 聚焦自动放大 ---------- */
  input:not([type=checkbox]):not([type=radio]), select, textarea {
    font-size: 16px !important;
  }
  input[type=checkbox], input[type=radio] { width: 17px; height: 17px; }

  /* ---------- 6 按钮：触控友好 ---------- */
  button, .btn, a.btn, input[type=button], input[type=submit] {
    min-height: 34px;
    touch-action: manipulation;
  }
  button.btn.mini, .btn.sm { min-height: 28px; }

  /* ---------- 7 数据表卡片化（.cardable 由 mobile.js 添加） ---------- */
  table.cardable {
    display: block; width: 100%; border: 0; border-collapse: separate;
    min-width: 0 !important; max-width: 100% !important;   /* 解除页面写死的 min-width */
  }
  table.cardable > thead { display: none; }
  /* 有些页面写成 <table><tr><th>…</th></tr><tr><td>…（表头行落在 tbody 里） */
  table.cardable > tbody > tr.mh-headrow { display: none !important; }
  table.cardable > tbody { display: block; }

  table.cardable > tbody > tr {
    display: block;
    background: #fff;
    color: #1f2937;               /* 卡片恒深色文字：页面可能是暗色主题（--txt 白），
                                     白卡+白字会看不见（2026-10-21 出项发票页实测） */
    border: 1px solid var(--line, #e5e9f0);
    border-left: 3px solid var(--pri, var(--indigo, var(--brand, #2f7bf6)));
    border-radius: 10px;
    margin: 0 0 10px;
    padding: 3px 12px 5px;
    box-shadow: 0 1px 3px rgba(16, 32, 64, .07);
  }
  table.cardable > tbody > tr:hover,
  table.cardable > tbody > tr.sel,
  table.cardable > tbody > tr.picked { background: #fff; }
  table.cardable > tbody > tr.ck { background: #f2f7ff; }
  table.cardable > tbody > tr.hide-row,
  table.cardable > tbody > tr[style*="display: none"] { display: none !important; }

  table.cardable > tbody > tr > td {
    display: flex; align-items: flex-start; gap: 10px;
    color: #1f2937;               /* 覆盖暗色主题的 --txt（白） */
    border: 0; border-bottom: 1px dashed #edf0f5;
    padding: 6px 0 !important;
    white-space: normal !important;      /* 关键：解除页面的 nowrap */
    font-size: 13px; line-height: 1.55;
    overflow-wrap: anywhere;
  }
  table.cardable > tbody > tr > td:last-child { border-bottom: 0; }

  /* 字段名（来自 mobile.js 写入的 data-label） */
  table.cardable > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 5.4em; max-width: 5.4em;
    font-size: 12px; font-weight: 600;
    color: var(--sub, var(--muted, #8a97a8));
    padding-top: 1px;
  }
  /* 勾选列 / 操作列：整行铺开，不加字段名 */
  table.cardable > tbody > tr > td[data-label=""] { display: block; }
  table.cardable > tbody > tr > td[data-label=""]::before { display: none; }
  /* 勾选列放卡片右上角，省一行高度 */
  table.cardable > tbody > tr > td.mh-ckcol {
    position: absolute; top: 9px; right: 12px;
    display: block; padding: 0 !important;
  }
  table.cardable > tbody > tr { position: relative; }
  /* 操作列：按钮横排、可换行、右对齐 */
  table.cardable > tbody > tr > td.mh-act {
    display: flex; flex-wrap: wrap; gap: 8px;
    justify-content: flex-start;
    padding-top: 8px !important;
    border-top: 1px solid #eef1f6; border-bottom: 0;
    margin-top: 3px;
  }
  table.cardable > tbody > tr > td.mh-act::before { display: none; }
  /* 空单元格不必显示 */
  table.cardable > tbody > tr > td.mh-empty { display: none; }
  /* 卡片里的进度条/图片/小标签自适应 */
  table.cardable td .bar-w, table.cardable td .prog { max-width: 100%; }

  /* 未卡片化的表格（单列/布局表/no-card）：容器可横向滑动 */
  table:not(.cardable) { max-width: 100%; }

  /* ---------- 8 弹窗 / 确认框：手机上近全屏，保证放得下 ---------- */
  .modal, .dialog, .dlg, .dlgbox, .popup, .cfm, .cfmbox, #cfmMask > div,
  .mask > .modal, .mask > .dlg, .ovl > div, .modal-box, .dlg-box {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    min-width: 0 !important;
    max-height: 88vh !important;
    overflow: auto !important;
    margin: 12px auto !important;
    box-sizing: border-box;
  }
  .modal-body, .dlg-bd { padding-left: 14px !important; padding-right: 14px !important; }
  .fgrid, .grid2, .formgrid, .form-grid, .wod-grid { grid-template-columns: 1fr !important; }
  .fgrid .wide, .grid2 .wide { grid-column: span 1 !important; }
  /* 弹窗底部按钮排布：可换行、不溢出 */
  .modal-footer, .dlg .act, .cfm-act { flex-wrap: wrap !important; gap: 8px !important; }
  .modal-footer button, .dlg .act button { flex: 1 1 auto; min-width: 90px; }

  /* ---------- 9 栅格 → 单列 ---------- */
  .cards, .kpis, .stats, .dash, .grid, .panes { grid-template-columns: 1fr !important; }
  .kpis, .cards { gap: 10px !important; }
  .charts, .tables { grid-template-columns: 1fr !important; }

  /* ---------- 10 提示 toast 别超出屏幕 ---------- */
  #msg, .toast, .flash, .tipbar {
    max-width: 92vw !important;
    font-size: 13px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    text-align: center;
  }

  /* ---------- 11 侧栏（部分页面的横向模块条） ---------- */
  .modrail { flex-wrap: wrap; }

  /* ---------- 12 工具类 ---------- */
  .m-hide { display: none !important; }
  .m-only { display: block !important; }
  .m-scroll-x { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .m-full { width: 100% !important; max-width: 100% !important; }
}

/* 手机端默认隐藏（PC 显示）—— 未被媒体查询包裹，故需成对定义 */
.m-only { display: none; }
