/* ========== 基础 ========== */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #0f9d6e;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Microsoft YaHei", "微软雅黑", "PingFang SC", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ========== 顶部工具栏 ========== */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(16, 24, 40, .04);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff; font-size: 20px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .28);
}
.brand-text h1 { margin: 0; font-size: 17px; letter-spacing: .3px; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.save-status { font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.save-status.flash { color: var(--accent); font-weight: 600; }

/* ========== 按钮 ========== */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #c7d2fe; background: #f8faff; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-accent:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; }
.btn-ghost.danger, .btn-mini.danger { color: var(--danger); }
.btn-mini { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-mini.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-mini.primary:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ========== 主布局 ========== */
.app-main {
  display: grid;
  grid-template-columns: minmax(430px, 520px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px 22px 40px;
  align-items: start;
}
@media (max-width: 1180px) {
  .app-main { grid-template-columns: 1fr; }
  .preview-stage { max-height: none; }
}

/* ========== 编辑面板 ========== */
.editor-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow);
}
.card-title {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 14px;
  font-size: 15px; font-weight: 700;
}
.card-title small { font-size: 12px; font-weight: 400; color: var(--muted); }
.col-toggle { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 400; color: var(--muted); cursor: pointer; white-space: nowrap; }
.col-toggle input { accent-color: var(--primary); cursor: pointer; }
.step {
  width: 22px; height: 22px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #eef2ff; color: var(--primary);
  font-size: 12px; font-weight: 700;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); min-width: 0; }
.field.span-2 { grid-column: 1 / -1; }
.field input, .field textarea, .control {
  width: 100%;
  border: 1px solid #d8dee9;
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus, .control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.field input::placeholder, .field textarea::placeholder { color: #b3bccb; }
.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 客户栏 */
.customer-bar { display: flex; gap: 6px; margin-bottom: 12px; }
.customer-bar select { flex: 1; min-width: 0; }

/* Logo 设置 */
.logo-controls { display: flex; gap: 16px; align-items: flex-start; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.logo-thumb { width: 84px; height: 84px; object-fit: contain; flex: none; border: 1px dashed var(--line); border-radius: 8px; background: #fff; }
.logo-placeholder {
  width: 84px; height: 84px; flex: none;
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 6px;
  border: 1px dashed #cbd5e1; border-radius: 8px;
  color: #94a3b8; font-size: 11px; line-height: 1.5;
}
.logo-controls > div:last-child { flex: 1; min-width: 0; }
.logo-controls .control { margin: 0 0 8px; padding: 7px 8px; font-size: 12px; }
.logo-size-row { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.logo-size-row label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.logo-size-row input[type=range] { flex: 1; min-width: 80px; accent-color: var(--primary); }
.logo-size-row b { min-width: 40px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.logo-actions { display: flex; gap: 6px; }

/* 明细编辑表 */
.items-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.items-editor { width: 100%; border-collapse: collapse; min-width: 920px; font-size: 12px; }
.items-editor th {
  background: #f7f9fc; color: #475569; font-weight: 600;
  text-align: left; padding: 8px 6px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.items-editor td { padding: 5px 4px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.items-editor tr:last-child td { border-bottom: 0; }
.items-editor input {
  width: 100%; border: 1px solid transparent; border-radius: 5px;
  padding: 6px 6px; background: transparent; font-size: 12px; outline: none;
}
.items-editor input:hover { border-color: #e2e8f0; background: #fff; }
.items-editor input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
.items-editor input[type=number] { text-align: right; -moz-appearance: textfield; }
.items-editor input[type=number]::-webkit-outer-spin-button,
.items-editor input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.items-editor .col-idx { width: 28px; text-align: center; color: var(--muted); }
.items-editor .col-custno { width: 100px; }
.items-editor .col-name { width: 110px; }
.items-editor .col-model { width: 125px; }
.items-editor .col-unit { width: 48px; }
.items-editor .col-qty { width: 56px; }
.items-editor .col-price { width: 78px; }
.items-editor .col-amt { width: 86px; }
.items-editor .col-delivery { width: 92px; }
.items-editor .col-remark { width: 120px; }
.items-editor .col-op { width: 28px; }
.items-editor.hide-delivery .delivery-col { display: none; }
.items-editor .row-idx { text-align: center; color: var(--muted); }
.items-editor .amt-cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: #111827; padding-right: 8px; }
.row-del {
  border: 0; background: transparent; color: #ef4444; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 4px; border-radius: 4px;
}
.row-del:hover { background: #fef2f2; }
.add-row { margin-top: 10px; }

.totals-editor {
  margin-top: 14px; padding: 12px 14px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  display: grid; gap: 7px;
}
.totals-editor > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 13px; }
.totals-editor span { color: var(--muted); }
.totals-editor strong { font-variant-numeric: tabular-nums; }
.totals-editor .grand { padding-top: 8px; border-top: 1px dashed #cbd5e1; font-size: 15px; }
.totals-editor .grand strong { color: var(--danger); font-size: 18px; }
.totals-editor .upper { font-size: 12px; }
.totals-editor .upper strong { color: #334155; text-align: right; }

/* 公章设置 */
.seal-controls { display: flex; gap: 16px; align-items: flex-start; }
.seal-thumb { width: 84px; height: 84px; object-fit: contain; flex: none; border: 1px dashed var(--line); border-radius: 8px; background: #fff; }
.seal-controls > div { flex: 1; min-width: 0; }
.seal-controls .control { margin: 8px 0; padding: 7px 8px; font-size: 12px; }

/* ========== 预览面板 ========== */
.preview-panel { min-width: 0; position: sticky; top: 78px; }
.preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; padding: 0 2px; flex-wrap: wrap;
}
.preview-title { font-weight: 700; font-size: 14px; }
.preview-title span { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 6px; }
.preview-sub { margin-top: 3px; font-size: 11px; font-weight: 400; color: #b45309; }
.preview-zoom { display: flex; align-items: center; gap: 6px; }
.preview-zoom #zoom-label { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }
.preview-stage {
  overflow: auto;
  max-height: calc(100vh - 120px);
  border-radius: 8px;
  background: #e9edf3;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* ========== 报价单 A4 页面 ========== */
.page {
  width: 297mm;
  min-height: 210mm;
  flex: none;
  background: #fff;
  padding: 10mm 14mm;
  box-shadow: 0 6px 24px rgba(16, 24, 40, .16);
  color: #111;
  font-family: "SimSun", "宋体", "Microsoft YaHei", serif;
  font-size: 10.5pt;
  line-height: 1.55;
  position: relative;
  transform-origin: top center;
}

.quote-header {
  display: flex; justify-content: space-between; align-items: center; gap: 8mm;
  padding-bottom: 3mm; border-bottom: 2.5px solid #b91c1c; break-inside: avoid;
}
.quote-brand { display: flex; align-items: center; gap: 4mm; flex: 1 1 auto; min-width: 0; }
.quote-logo { height: auto; object-fit: contain; flex: 0 0 auto; }
.quote-brand-text { flex: 1 1 auto; min-width: 0; }
.quote-company {
  font-family: "SimHei", "黑体", sans-serif; font-size: 17pt; font-weight: 700;
  color: #1a1a1a; letter-spacing: 1px; white-space: nowrap; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis;
}
.quote-company-sub {
  font-size: 8.5pt; color: #555; margin-top: 1mm;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.quote-doc-title { text-align: right; flex: none; }
.quote-doc-title .cn { font-family: "SimHei", "黑体", sans-serif; font-size: 21pt; font-weight: 700; letter-spacing: 6px; color: #b91c1c; line-height: 1.1; }
.quote-doc-title .en { font-family: Arial, sans-serif; font-size: 8pt; letter-spacing: 2.5px; color: #777; margin-top: 1mm; }

.quote-meta { display: flex; justify-content: space-between; gap: 8px; margin: 1.8mm 0; font-size: 9pt; color: #333; }
.quote-meta span b { font-weight: 600; }

.section-title {
  font-family: "SimHei", "黑体", sans-serif;
  font-size: 10.5pt; font-weight: 700;
  margin: 2mm 0 1mm; padding-left: 3mm;
  border-left: 3px solid #b91c1c;
}

.info-table { width: 100%; border-collapse: collapse; margin-bottom: 1.2mm; font-size: 9pt; }
.info-table td { border: 1px solid #333; padding: 1mm 2.5mm; vertical-align: middle; }
.info-table .lbl { width: 15%; background: #f6f6f6; font-weight: 600; white-space: nowrap; }
.info-table .val { width: 35%; }
.info-table .lbl2 { width: 13%; background: #f6f6f6; font-weight: 600; white-space: nowrap; }
.info-table .val2 { width: 37%; }

.quote-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 8.8pt; }
.quote-table th, .quote-table td { border: 1px solid #333; padding: 1mm 0.8mm; text-align: center; overflow-wrap: break-word; line-height: 1.35; }
.quote-table thead th { background: #f0f0f0; font-family: "SimHei", "黑体", sans-serif; font-weight: 700; }
.quote-table td.left { text-align: left; }
.quote-table td.right { text-align: right; font-variant-numeric: tabular-nums; }
.quote-table tbody tr { break-inside: avoid; page-break-inside: avoid; }
.quote-table .c-idx { width: 4%; }
.quote-table .c-custno { width: 11%; }
.quote-table .c-name { width: 11%; }
.quote-table .c-model { width: 18%; }
.quote-table .c-unit { width: 5%; }
.quote-table .c-qty { width: 6%; }
.quote-table .c-price { width: 9%; }
.quote-table .c-amt { width: 11%; }
.quote-table .c-delivery { width: 11%; }
.quote-table .c-remark { width: 14%; }
.quote-table .empty-row td { height: 8mm; color: #999; }

.summary-table { width: 100%; border-collapse: collapse; margin-top: 1mm; font-size: 9.5pt; }
.summary-table td { border: 1px solid #333; padding: 0.9mm 2.5mm; }
.summary-table .slbl { background: #f6f6f6; font-weight: 600; text-align: right; width: 20%; }
.summary-table .sval { width: 30%; text-align: right; font-variant-numeric: tabular-nums; }
.summary-table .grand-label { background: #fdecec; color: #b91c1c; font-weight: 700; text-align: right; }
.summary-table .grand-value { background: #fff7f7; color: #b91c1c; font-weight: 700; font-size: 12pt; text-align: right; font-variant-numeric: tabular-nums; }
.summary-table .upper-row .slbl { width: 12%; }
.summary-table .upper-row .sval { width: 88%; text-align: left; }

.remark-box { margin-top: 1.5mm; border: 1px solid #333; min-height: 10mm; break-inside: avoid; }
.remark-box .remark-title { background: #f6f6f6; border-bottom: 1px solid #333; padding: 0.6mm 2.5mm; font-family: "SimHei", "黑体", sans-serif; font-weight: 700; font-size: 9pt; }
.remark-box .remark-body { padding: 0.7mm 2.5mm; font-size: 8.5pt; white-space: pre-wrap; line-height: 1.4; min-height: 7mm; color: #222; }

.sig-row { display: flex; gap: 8mm; margin-top: 2mm; break-inside: avoid; page-break-inside: avoid; }
.sig-cell { flex: 1; position: relative; min-height: 15mm; font-size: 9pt; }
.sig-cell .sig-line { border-bottom: 1px solid #333; padding-bottom: 1mm; margin-bottom: 1.5mm; font-weight: 600; }
.sig-cell .sig-sub { font-size: 8.5pt; color: #333; line-height: 1.8; }
.seal-stamp {
  position: absolute;
  left: 55%; top: -3mm;
  width: 30mm; height: 30mm;
  object-fit: contain;
  opacity: .88;
  mix-blend-mode: multiply;
  transform: rotate(-13deg);
  pointer-events: none;
}

.page-footer {
  position: absolute;
  left: 14mm; right: 14mm; bottom: 6mm;
  border-top: 1px solid #bbb;
  padding-top: 2mm;
  font-size: 7.5pt;
  color: #666;
  display: flex; justify-content: space-between; gap: 10px;
  line-height: 1.35;
}

/* ========== 提示条 ========== */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #111827; color: #fff;
  padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ========== 打印：严格的 A4 板式 ========== */
@media print {
  @page { size: A4 landscape; margin: 10mm 12mm; }
  html, body {
    background: #fff !important;
    height: auto !important;
    overflow: visible !important;
  }
  .no-print, .toolbar, .editor-panel, .preview-head, .toast { display: none !important; }
  .app-main, .preview-panel, .preview-stage {
    display: block !important;
    position: static !important;
    padding: 0 !important; margin: 0 !important;
    max-height: none !important; overflow: visible !important;
    background: #fff !important;
    border: 0 !important;
  }
  .page {
    width: auto !important;
    min-height: 0 !important;
    padding: 0 !important; margin: 0 !important;
    box-shadow: none !important;
    transform: none !important;
    zoom: 1 !important;
  }
  .page-footer { position: static !important; margin-top: 3mm; border-top: 1px solid #bbb; padding-top: 1.5mm; }
  table, .remark-box, .sig-row { max-width: 100% !important; }
  thead { display: table-header-group; }
  tr, .sig-cell, .remark-box, .summary-table { break-inside: avoid; page-break-inside: avoid; }
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
