/* 报价管理模块升级（T7 + UI 优化） —— 仅新建本文件。
   约定：
   1) 只补充 q2- 前缀组件样式，颜色/间距/圆角一律复用 styles.css 的 CSS 变量；
   2) 布局类优先复用全局契约（.field / .form-grid / .info-grid / .table-actions /
      .btn-danger-ghost / .row / .stack / .mt-* / .mb-* / .tnum / .fs-* / .fw-* 等）；
   3) 屏幕版式与 index.html 内联的 @media print 打印样式互不冲突：
      打印专属的「去装饰」覆盖统一写在本文件末尾的 @media print 块内，
      且不使用会影响 index.html 既有 !important 声明的写法。 */

/* ============ 1. 公司表头（只读区） ============ */
.q2-header { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.q2-logo { width: 56px; height: 56px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-alt); flex: 0 0 auto; }
.q2-header-info { min-width: 0; }
.q2-company-name { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.q2-readonly-note { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--border); }

/* ============ 2. 客户链接 ============ */
.q2-link { color: var(--primary); cursor: pointer; font-weight: 500; }
.q2-link:hover { text-decoration: underline; }

/* ============ 2.5 阶梯价单价来源标记（v1.49） ============
   显示在单价金额正下方：块级 div，字号 fs-xs(11.5px) < td 默认(~13.5px)，
   右对齐沿用 td.num；中文主色 success，英文次级 muted 形成对比。 */
.q2-tier-tag {
  display: block; margin-top: 2px;
  font-size: var(--fs-xs); line-height: 1.2;
  color: var(--success); font-weight: 500;
  letter-spacing: .01em;
}
/* v1.50：中文在上、英文在下（两块级行）；英文次级 muted 形成对比。 */
.q2-tier-tag-zh { display: block; }
.q2-tier-tag-en { display: block; color: var(--muted); font-weight: 400; margin-left: 0; }
/* v1.50：阶梯价行的原价（产品库销售单价，未套阶梯价前）——删除线展示 */
.q2-list-price {
  display: block; margin-top: 2px;
  font-size: var(--fs-xs); line-height: 1.2; color: var(--muted);
}
.q2-list-price s { text-decoration: line-through; }

/* ============ 3. 产品缩略图 / 占位符（统一 44×44，禁止高度塌陷） ============ */
.q2-line-img, .q2-pi-img, .q2-pick-img img {
  width: 44px; height: 44px; object-fit: cover; display: block;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-alt);
}
.q2-img-ph {
  width: 44px; height: 44px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted); line-height: 1;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-alt);
}
.q2-img-ph::after { content: "无图"; }
.q2-pick-img { flex: 0 0 auto; width: 44px; height: 44px; }
.q2-pick-img .q2-img-ph { width: 44px; height: 44px; }

/* ============ 4. 客户自动带入信息块 ============ */
.q2-cust-auto { margin-top: 2px; }
.q2-cust-auto:empty { display: none; }
.q2-cust-auto-box {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px;
  padding: 10px 12px; background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.q2-cust-auto-box > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.q2-cust-auto-box .lbl { font-size: 12px; color: var(--muted); }
.q2-cust-auto-box .val { font-size: 13px; font-weight: 500; color: var(--text); word-break: break-word; }

/* ============ 5. 标准条款 ============ */
.q2-terms-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.q2-terms-list > li { padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
.q2-terms-list > li:last-child { padding-bottom: 0; border-bottom: 0; }
.q2-terms-list strong { display: block; font-size: 13px; color: var(--text); margin-bottom: 2px; }
.q2-terms-list .muted { line-height: 1.6; }
.q2-terms-edit { margin-top: var(--sp-3); }
.q2-terms-edit > label { margin-top: 0; }
/* font-size 必须 ≥16px：否则 iOS Safari 聚焦时整页放大且不还原 */
.q2-terms-edit textarea { min-height: 90px; font-size: 16px; line-height: 1.5; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ============ 6. 汇总条 ============ */
.q2-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 18px; }
.q2-summary > div { display: flex; flex-direction: column; gap: 3px; }
.q2-summary .lbl { font-size: 12px; color: var(--muted); }
.q2-summary .val { font-size: 18px; font-weight: 650; }
.q2-summary .val .badge { font-size: 13px; }
/* PI 总金额高亮（产品金额 + 费用 = PI 总金额） */
.q2-summary > .is-hero {
  padding: 8px 12px; margin: -8px -12px -8px -4px;
  background: var(--primary-weak); border-radius: var(--radius-sm);
}
.q2-summary > .is-hero .val { font-size: 22px; color: var(--primary); }
.q2-sum-formula {
  margin-bottom: 14px; padding: 8px 12px; font-size: 12.5px; line-height: 1.6;
  color: var(--text-sub); background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.q2-sum-formula b { color: var(--text); font-variant-numeric: tabular-nums; }
.q2-sum-eq { color: var(--primary) !important; font-size: 14px; }
.card-head h3 .head-count {
  margin-left: 8px; padding: 1px 8px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); background: var(--surface-alt);
  border: 1px solid var(--border); border-radius: 999px;
}
.q2-hint-line { margin-top: 10px; font-size: 12px; color: var(--muted); line-height: 1.6; }
/* 关税 / 进口增值税展示块（结合交货方式规则：DDP 卖方承担并计入 PI，否则买方目的国自缴） */
.q2-duty { margin-top: 14px; padding: 12px 14px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.q2-duty-head { font-size: 12.5px; font-weight: 600; color: var(--text-sub); margin-bottom: 10px; line-height: 1.5; }
.q2-duty .q2-summary { gap: 8px 18px; }
/* v7：税费对外显隐开关（草稿态可见，不进打印件） */
.q2-fxshow {
  margin: 4px 0 12px; padding: 10px 12px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-sm);
}
.q2-fxshow-t { font-size: 12px; color: var(--text-sub); margin-bottom: 8px; line-height: 1.5; }
.q2-fxrow { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; padding: 3px 0; }
.q2-fxname { font-size: 12.5px; font-weight: 600; min-width: 132px; }
.q2-fxopts { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.q2-fxchk {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--text-sub); cursor: pointer; user-select: none;
}
.q2-fxchk input { margin: 0; cursor: pointer; }
.q2-fxchk input:disabled { cursor: not-allowed; }

/* ============ 6-b. 详情页区块快捷跳转 ============ */
.q2-secnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.q2-secnav-item {
  padding: 5px 12px; font-size: 12.5px; font-family: inherit;
  color: var(--text-sub); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.q2-secnav-item:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-weak); }
.card[id^="q2Sec"] { scroll-margin-top: 16px; }

/* ============ 7. 毛利预警区 ============ */
.q2-margin-hero { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.q2-margin-rate { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.q2-banner { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; }
.q2-banner-ok { background: var(--success-weak); color: var(--success); }
.q2-banner-danger { background: var(--danger-weak); color: var(--danger); font-weight: 500; }
.q2-banner-warn { background: var(--warn-weak); color: var(--warn); }

/* ============ v82：费用版块附件（Freight & Charges 附件） ============ */
.q2-charge-atts { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.q2-att-chip { display: inline-flex; align-items: center; gap: 8px; }
.q2-att-chip a { color: var(--text); text-decoration: none; }
.q2-att-chip a:hover { color: var(--primary); }
.q2-att-chip .mail-att-x { cursor: pointer; font-weight: 700; color: var(--danger); padding: 0 2px; }

/* ============ 9. 行项弹窗实时预览 ============ */
.q2-preview { margin-top: 10px; padding: 8px 12px; background: var(--primary-weak); color: var(--primary);
  border-radius: var(--radius-sm); font-size: 12.5px; }

/* ============ 10. 「从产品库选品」弹窗 ============ */
.q2-pick-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.q2-pick-count { font-size: 12.5px; color: var(--muted); }
.q2-pick-wrap {
  max-height: 50vh;
  max-height: 50dvh; /* iOS 可视高度随地址栏变化，dvh 更贴近真实可视区 */
  overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.q2-pick-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.q2-pick-row:last-child { border-bottom: 0; }
.q2-pick-row:hover { background: var(--surface-alt); }
.q2-pick-chk { flex: 0 0 auto; width: 16px; height: 16px; margin: 0; cursor: pointer; }
.q2-pick-info { flex: 1 1 auto; min-width: 0; }
.q2-pick-info strong { font-size: 13px; }
.q2-pick-info .muted { margin-top: 2px; }
.q2-pick-qty {
  display: flex; align-items: center; gap: 6px; flex: 0 0 auto;
  margin: 0; font-size: 12.5px; font-weight: 500; color: var(--text-sub);
}
.q2-pick-qty-input { width: 84px; padding: 5px 8px; }

/* ============ 11. PI 单页：屏幕版式（打印时由末尾 @media print 去装饰） ============ */
.q2-pi-sheet {
  max-width: 900px; margin: 0 auto; padding: 28px 30px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.q2-pi-head { padding-bottom: 14px; margin-bottom: 0; border-bottom: 2px solid var(--text); }
/* PI 表头只放四个单据字段，**不再重复签发公司信息**：
   公司名称 / 地址 / 电话 / 税号统一由下方「卖方 Seller」区块承载，
   避免同一份 PI 里同一组信息出现两遍。 */
.q2-pi-head .muted { line-height: 1.6; }
/* 单据信息紧凑四列：PI单号 / 报价单号 / 生效日期 / 失效日期 */
.q2-pi-docinfo-grid.is-inline { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 22px; }
@media (max-width: 640px) {
  .q2-pi-docinfo-grid.is-inline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* 标题位于表头横线下方（表头 .q2-pi-head 只放四个单据字段并带底边框） */
.q2-pi-title {
  margin: 16px 0 16px; text-align: center;
  font-size: 22px; font-weight: 700; letter-spacing: .08em; color: var(--text);
}
/* 单据中文副标题（英文主标题之下），与销售合同 .ops-ct-subtitle 保持同一语汇 */
.q2-pi-subtitle {
  margin: -10px 0 16px; text-align: center;
  font-size: 13px; letter-spacing: .3em; color: var(--text-sub);
}
/* PI 表头单据信息（PI单号 / 报价单号 / 生效日期 / 失效日期），四列等宽 */
.q2-pi-docinfo { margin-top: 2px; }
.q2-pi-docinfo-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 18px;
}
.q2-pi-docinfo-grid .lbl { display: block; font-size: 11px; color: var(--text-sub); font-weight: 500; line-height: 1.4; }
.q2-pi-docinfo-grid .val { font-size: 14px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .q2-pi-docinfo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.q2-pi-meta {
  margin-bottom: 18px; padding: 12px 14px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.q2-pi-parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.q2-pi-parties .q2-pi-sec {
  margin-top: 0; padding: 12px 14px;
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.q2-pi-sec { margin-top: 0.7cm; }
.q2-pi-sec > h4 {
  margin-bottom: 8px; padding-bottom: 6px;
  /* v83：版块标题（含「运费港务等费用 Freight & Charges」）统一加黑 */
  font-size: 13px; font-weight: 700; color: var(--text); border-bottom: 1px solid var(--border);
}
.q2-pi-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
/* v1.31：产品明细的「数量 / 单位 / 单价」三列按内容自适应宽度。
   只给四张产品明细表挂 .q2-fit-table，费用表 / 包装表仍走 fixed，避免牵动既有版式。
   colgroup 里的百分比保留 —— 它既是无 CSS 环境的兜底，也是静态「列数 + 合计 100」的
   配平校验；渲染时用 !important 覆盖行内 width，把这三列交给 auto 布局按内容收缩。
   td 的 width:1% + nowrap 是经典的「收缩到内容宽度」组合，剩余空间让给品名 / 规格。
   特异性用 table.q2-fit-table（0,1,1）压过 .q2-pi-table（0,1,0），与容器无关。 */
table.q2-fit-table { table-layout: auto; }
.q2-fit-table col.q2-fit { width: auto !important; }
/* min-width 是 Chrome 实渲染后补的：纯 width:1% 会把短内容列压到 28px（content 仅 11px），
   表头「数量 / 单价」两个汉字都放不下。这里按 .num 区分数字列与单位列，不依赖列序，
   以后插品牌之类的列也不会失效；min-width 作用于 content box，加 7px×2 padding + 1px
   border 后约 43px / 39px，更长的内容由 nowrap 自己撑开。 */
.q2-fit-table th.num.q2-fit,
.q2-fit-table td.num.q2-fit { min-width: 26px; }
.q2-fit-table th.q2-fit:not(.num),
.q2-fit-table td.q2-fit:not(.num) { min-width: 22px; }
.q2-fit-table td.q2-fit { white-space: nowrap; width: 1%; }
/* 表头为「中文 English」双语，禁止 nowrap：否则 9 列会撑破单据宽度（A4 794px） */
.q2-pi-table th {
  padding: 7px 8px; text-align: left; white-space: normal; line-height: 1.35;
  font-size: 11.5px; font-weight: 600; color: var(--text-sub);
  background: var(--surface-alt); border: 1px solid var(--border);
}
.q2-pi-table td { padding: 7px 8px; vertical-align: middle; border: 1px solid var(--border); }
.q2-pi-table tbody .q2-pi-line:hover { background: #f7f9fc; }
.q2-pi-table tbody tr:nth-child(even) { background: #fbfcfe; }
.q2-pi-table th.num, .q2-pi-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.q2-pi-table tfoot td { font-weight: 700; background: var(--surface-alt); }
.q2-pi-table tfoot .q2-pi-row-sub td { font-weight: 500; color: var(--text-sub); background: transparent; }
.q2-pi-table tfoot .q2-pi-row-total td { font-weight: 700; font-size: 14px; border-top: 2px solid var(--text); }
.q2-pi-terms {
  margin: 0; padding-left: 18px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12.5px; line-height: 1.6; color: var(--text-sub);
}
.q2-pi-terms strong { color: var(--text); }
/* 条款中的英文：标题行内淡色斜体、正文另起一行，保持「中文在前、英文在后」的对照 */
.q2-cl-en { font-style: normal; font-size: 11px; font-weight: 500; color: var(--muted); }
.q2-cl-en-body { margin-top: 1px; font-size: 11.5px; line-height: 1.65; color: var(--muted); }
.q2-pi-foot {
  margin-top: 22px; padding-top: 12px;
  border-top: 1px dashed var(--border); text-align: center;
}

/* ============ 11-b. PI 费用明细行（计入 PI 的费用逐项列出） ============ */
.q2-pi-table tfoot .q2-pi-row-fee td {
  padding-top: 3px; padding-bottom: 3px;
  font-size: 12px; color: var(--text-sub); background: transparent;
}
/* 关税/增值税说明行（非 DDP：由买方目的国自缴，不计入 PI 总金额） */
.q2-pi-table tfoot .q2-pi-row-note td {
  padding: 7px 10px; font-size: 12px; font-weight: 500;
  color: var(--muted); background: transparent; line-height: 1.5;
}

/* PI 签署区（打印用，屏幕上也显示以便核对） */
.q2-pi-sign {
  display: grid; grid-template-columns: 1fr 1fr; gap: 40px;
  margin-top: 28px; padding-top: 8px;
}
.q2-pi-sign > div { display: flex; flex-direction: column; gap: 6px; }
.q2-pi-sign .line { height: 34px; border-bottom: 1px solid var(--text); }
.q2-pi-sign .lbl { font-size: 12px; color: var(--muted); text-align: center; }
/* v1.23：签字横线就是签名框的下边框，签名图贴线居中（两栏等高）。
   旧结构 sign-box(48px) + .line(34px) 让签名底部离横线 40px，视觉上飘在上方；
   现在报价表 / PI 不再输出 .line，销售合同的留白签字栏仍用 .line（下方规则）。
   Word 转表后由 doc_export.js 的兜底样式复刻同一位置（Word 不支持 flex）。 */
.q2-pi-sign .q2-sign-box {
  height: 48px; display: flex; align-items: flex-end; justify-content: center;
  border-bottom: 1px solid var(--text); padding-bottom: 2px;
}
.q2-pi-sign .q2-sign-img {
  max-width: 170px; max-height: 44px; object-fit: contain; display: block;
}

/* ============ 12. 表格操作列：与全局 .table-actions 的 gap 去重 ============ */
.table-actions .btn + .btn,
.table-actions .btn + .icon-btn,
.table-actions .icon-btn + .btn { margin-left: 0; }

/* ============ 13. 响应式 ============ */
@media (max-width: 860px) {
  .q2-pi-sheet { padding: 18px 16px; }
  .q2-pi-parties { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .q2-cust-auto-box { grid-template-columns: 1fr; }
  .q2-pick-row { flex-wrap: wrap; }
  .q2-pick-info { flex: 1 1 100%; }
  .q2-pick-qty-input { width: 72px; }
  .q2-header { align-items: flex-start; }
}

/* ============ 14. 打印：仅剥离屏幕装饰，不覆盖 index.html 的打印版式 ============ */
@media print {
  .q2-pi-sheet {
    max-width: none !important; margin: 0 !important; padding: 0 !important;
    background: #fff !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important;
  }
  .q2-pi-meta, .q2-pi-parties .q2-pi-sec { background: transparent !important; }
  .q2-pi-table tbody tr:nth-child(even) { background: transparent !important; }
  .print-area .q2-pi-table th.num,
  .print-area .q2-pi-table td.num { text-align: right !important; }
  .q2-pi-parties { grid-template-columns: 1fr 1fr !important; }
  /* 打印时表头四个单据字段保持一行四列（窄屏规则不参与打印） */
  .q2-pi-docinfo-grid.is-inline { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .q2-pick-wrap { max-height: none !important; overflow: visible !important; }
  /* 打印排版：章节不跨页、表头跨页重复、避免孤立表尾 */
  .q2-pi-sec { break-inside: avoid; page-break-inside: avoid; }
  .q2-pi-table thead { display: table-header-group; }
  .q2-pi-table tfoot { display: table-row-group; }
  .q2-pi-table tr { break-inside: avoid; page-break-inside: avoid; }
  .q2-pi-title { break-after: avoid; page-break-after: avoid; }
  .q2-pi-parties { break-inside: avoid; page-break-inside: avoid; }
  /* v1.21：签署区不跨页；签名图不被 index.html 的「产品图 48px」规则压小
     v1.23：打印同样以签名框下沿作签字线，签名贴线，不留 34px 空白 */
  .q2-pi-sign { break-inside: avoid; page-break-inside: avoid; }
  .q2-pi-sign .q2-sign-img { max-width: 170px !important; max-height: 44px !important; }
  .q2-pi-sign .q2-sign-box {
    height: 48px !important; border-bottom: 1px solid #000 !important; padding-bottom: 2px !important;
  }
  /* 打印 / PDF 不裁切表格：避免 overflow-x:auto 把右列与边框裁成竖黑条 */
  .table-wrap { overflow: visible !important; }
  /* v1.32：对外单据（报价单 / PI / 订单 PI / 销售合同附表）打印只列英文规格，
     中文规格一律不进打印稿。屏幕仍由 app.js specCell() 显示中英双语供内部核对。
     不挂 .print-area 是因为订单 PI 区块在 .card-body 内；这两个 class 只由
     specCell() 产出，不会误伤产品列表等其它页面的 .bi-en。
     英文副行恢复正文样式，否则打印出来又小又灰、不像规格主内容；
     英文未录入时 :empty::after 补破折号，宁缺勿中、绝不回退中文。 */
  .q2-spec-cn { display: none !important; }
  .q2-spec-en {
    color: inherit !important; font-size: inherit !important; font-weight: inherit !important;
  }
  .q2-spec-en:empty::after { content: "—"; }
}
