:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1f2733;
  --ink-soft: #5b6675;
  --line: #e6eaf0;
  --primary: #2f6bff;
  --primary-dark: #1f4fd1;
  --primary-soft: #eaf0ff;
  --accent: #0fb39a;
  --danger: #e5484d;
  --shadow: 0 1px 3px rgba(20, 30, 50, .06), 0 6px 24px rgba(20, 30, 50, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Songti SC", "SimSun", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0;
  background: #0f1b33;
  color: #cdd6e6;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 22px 20px; font-size: 18px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  letter-spacing: .5px;
}
.sidebar .brand small { display:block; font-size: 11px; font-weight: 400; color:#7c8aa5; margin-top: 4px; letter-spacing: 0; }
.nav { padding: 12px 10px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin: 4px 0; border-radius: 9px;
  color: #cdd6e6; text-decoration: none; cursor: pointer; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); color:#fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a .ico { width: 18px; text-align: center; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 8px 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; }
.topbar .sub { color: var(--ink-soft); font-size: 13px; }
.content { padding: 26px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* 产品图册：iframe 填满内容区 */
.content.catalog-frame { padding: 0; max-width: none; height: calc(100vh - 61px); }
.content.catalog-frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

/* cards */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 18px; }
.card h2 { font-size: 18px; margin: 0 0 16px; font-weight: 650; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; }

.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .label { color: var(--ink-soft); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value.small { font-size: 20px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 15px; border-radius: 9px; font-size: 13.5px; font-weight: 550;
  transition: all .15s; text-decoration: none; line-height: 1;
}
.btn:hover { border-color: #c7cfdb; background: #f7f9fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c6c8; }
.btn.danger:hover { background: #fdeced; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* table */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; padding: 10px 12px; background: #f8fafc;
  border-bottom: 2px solid var(--line); font-weight: 600; color: var(--ink-soft);
  font-size: 14px; white-space: nowrap; transition: background .15s, color .15s;
}
table.data td {
  text-align: left; padding: 9px 12px; border-bottom: 1px solid #f1f5f9; font-size: 14px;
}
table.data th.sort-col { cursor: pointer; user-select: none; }
table.data th.sort-col:hover { background: #e0f2fe; color: #1d4ed8; }
table.data th.sort-col.sort-active { background: #eff6ff; color: #1d4ed8; }
table.data th.sort-col .sort-arrow { margin-left: 2px; font-size: 10px; opacity: .6; }
table.data tr { cursor: pointer; }
table.data tr:hover td { background: #f8fafc; }
.table-tools { display:flex; gap:10px; align-items:center; margin-bottom: 14px; flex-wrap: wrap; }
.search-input {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; font-size: 14px;
  min-width: 220px; outline: none;
}
.search-input:focus { border-color: var(--primary); }

/* form */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 16px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 550; }
.field .req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=number], input[type=date], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 10px 12px; font-size: 16px !important; font-family: inherit; outline: none; background:#fff; color: var(--ink);
}
::placeholder { font-size: inherit; opacity: 0.6; }
/* 数字输入框：隐藏上下箭头 */
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }

/* items table (注: 货物清单表格的字体/字号统一在下方 221 行起的专用块中定义) */
.items-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.items { width: 100%; border-collapse: collapse; min-width: 920px; }
table.items .col-idx { width: 42px; text-align: center; color: var(--ink-soft); }
table.items .col-amount { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals-bar {
  display: flex; justify-content: flex-end; gap: 30px; align-items: center;
  margin-top: 14px; flex-wrap: wrap;
}
.totals-bar .t { font-size: 14px; }
.totals-bar .t b { font-size: 18px; color: var(--primary-dark); }

/* 实物图单元格 */
table.items .col-pic { width: 116px; }
.pic-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pic-drop {
  width: 104px; height: 64px; border: 1px dashed #c2cad8; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  cursor: pointer; background: #fafbfd; transition: all .15s; outline: none;
}
.pic-drop:hover { border-color: var(--primary); background: #f3f7ff; }
.pic-drop.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.pic-drop.drag { border-color: var(--accent); background: #eafffb; }
.pic-drop.uploading { opacity: .6; }
.pic-drop .ph { font-size: 11px; color: var(--ink-soft); text-align: center; line-height: 1.3; }
.pic-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pic-act { display: flex; gap: 8px; font-size: 12px; }
.link.sm { font-size: 12px; }
.link.danger { color: var(--danger); }

/* 电子章上传 */
.seal-box { min-width: 160px; flex: 1; }
.seal-drop {
  width: 150px; height: 150px; border: 2px dashed #c2cad8; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  cursor: pointer; background: #fafbfd; transition: all .15s; outline: none;
}
.seal-drop:hover { border-color: var(--primary); background: #f3f7ff; }
.seal-drop.has { border-style: solid; border-color: var(--accent); }
.seal-drop.uploading { opacity: .6; }
.seal-drop .ph { font-size: 12px; color: var(--ink-soft); text-align: center; line-height: 1.5; }
.seal-drop img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* 签章区印章（预览/打印） */
.sign .seal-col { position: relative; }
.seal-img {
  position: absolute; width: 150px; height: 150px;
  object-fit: contain; opacity: .88;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.seal-img.buyer-seal {
  top: -20px; left: 4px;
}
.seal-img.seller-seal {
  top: -20px; left: 4px;
}

/* badge */
.badge { display:inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.empty { text-align:center; color: var(--ink-soft); padding: 50px 0; }
.link { color: var(--primary); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* toast */
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 999;
  background: #1f2733; color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); font-size: 13.5px; opacity: 0; transform: translateY(-8px);
  transition: all .25s; pointer-events: none; max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: #c0392b; }
.toast.ok { background: #2f9e6b; }

/* ====== contract preview (A4) ====== */
.preview-shell { background: #e9edf3; padding: 24px; }
.doc {
  background: #fff; width: 794px; max-width: 100%; margin: 0 auto;
  padding: 36px 36px 46px; color: #1a1a1a; font-size: 14px; line-height: 1.9;
  box-shadow: 0 4px 30px rgba(0,0,0,.12);
}
.doc h1.title { text-align: center; font-size: 24px; letter-spacing: 6px; margin: 0 0 26px; font-weight: 700; }
.doc .parties { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.doc .parties .p {}
.doc .intro { margin: 14px 0 18px; text-indent: 2em; }
.doc table.goods { border-collapse: collapse; margin: 6px 0 4px; font-size: 13px; max-width: 100%; table-layout: auto; }
.doc table.goods th, .doc table.goods td { border: 1px solid #333; padding: 4px 3px; text-align: center; vertical-align: middle; }
.doc table.goods th { font-weight: 600; white-space: nowrap; }
.doc table.goods td .pic { width: 70px; height: 70px; object-fit: contain; border: 1px dashed #bbb; }

/* 新建/编辑页表格：单元格居中，输入框居中 */
table.items { border-collapse: collapse; width: 100%; font-size: 16px; font-family: "Songti SC", "SimSun", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif; }
table.items th, table.items td { border: 1px solid #ccc; padding: 5px 4px; text-align: center; vertical-align: middle; }
table.items th { background: #f7f7f7; white-space: nowrap; font-size: 16px; color: var(--ink); }
table.items th.col-idx { color: var(--ink); }
table.items td input, table.items td select { text-align: center; font-family: inherit; font-size: 16px; box-sizing: border-box; border: none !important; outline: none !important; background: transparent; min-height: 36px; padding: 4px 6px; width: 100%; }
/* 聚焦：无任何边框/高亮（纯净无边框） */
table.items td input:focus, table.items td select:focus { outline: none !important; border-color: transparent !important; box-shadow: none !important; background: transparent !important; }
table.items td.col-amount { font-size: 16px; font-family: inherit; }
table.items td input[data-f="spec"] { border: none !important; outline: none !important; background: transparent; box-shadow: none !important; text-align: center !important; padding: 0 !important; width: 100% !important; }
table.items td input[data-f="spec"]:focus { border: none !important; outline: none !important; box-shadow: none !important; }
table.items td input.locked-input { border: none; background: transparent; outline: none; cursor: default; -webkit-appearance: none; appearance: none; }
table.items td.col-idx { cursor: pointer; position: relative; user-select: none; transition: background 0.15s; border-radius: 3px; }
table.items td.col-idx:hover { background: #e8f4fd; color: #1677ff !important; font-weight: 600; }
table.items td.col-idx:hover .idx-num { display: none !important; }
table.items td.col-idx:hover .idx-copy { display: inline !important; }
.doc .total-line { display:flex; justify-content: space-between; margin-top: 8px; padding: 6px 2px; }
.doc .total-line .big { font-weight: 700; }
.doc .section { margin-top: 18px; }
.doc .section .st { font-weight: 700; margin-bottom: 4px; }
.doc .terms li { margin: 2px 0; }
.doc .sign { display: flex; justify-content: space-between; margin-top: 40px; }
.doc .sign .col { width: 44%; }
.doc .sign .col:last-child { margin-left: auto; }
.doc .sign .line { margin: 22px 0 6px; }
.doc .sign .label { color: #333; }
.preview-toolbar { display:flex; gap:10px; justify-content:center; margin-bottom: 16px; flex-wrap: wrap; }
.print-tip { font-size: 12px; color: #d97706; text-align: center; margin: -6px 0 10px; }

/* print */
@media print {
  body { background: #fff; margin: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sidebar, .topbar, .preview-toolbar, .no-print, .print-tip { display: none !important; }
  .preview-shell { padding: 0; background: #fff; }
  .doc {
    box-shadow: none;
    width: 100%;
    box-sizing: border-box;
    padding: 14mm;
    font-size: 12pt;
    line-height: 1.75;
  }
  .doc h1.title { font-size: 20pt; letter-spacing: 4px; }
  .doc table.goods { font-size: 11pt; }
  /* 打印时规格型号列（第3列）保持与编辑页一致，不换行 */
  .doc table.goods th:nth-child(3), .doc table.goods td:nth-child(3) { white-space: nowrap; min-width: 90px; }
  /* 打印时去掉实物图虚线框，改用细实线 */
  .doc table.goods td .pic { border: 1px solid #ddd !important; }
  /* 打印时印章保持与屏幕预览一致：150px，盖在"（盖章）"文字上方 */
  .seal-img { width: 150px; height: 150px; opacity: .88; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  .seal-img.buyer-seal { top: -20px; left: 4px; }
  .seal-img.seller-seal { top: -20px; left: 4px; }
  /* A4 纸张、0 页边距，最大限度抑制浏览器自带页眉页脚 */
  @page { size: A4; margin: 0; }
}

/* 规格型号自定义下拉（替代 datalist，下拉文字可居中/改字体） */
.spec-combo {
  position: absolute; z-index: 1000;
  background: #fff; border: 1px solid #e6eaf0; border-radius: 9px;
  box-shadow: 0 6px 24px rgba(20,30,50,.12);
  max-height: 240px; overflow-y: auto;
  font-family: "Songti SC","SimSun","Microsoft YaHei",-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB",sans-serif;
  font-size: 16px;
}
.spec-combo-item { padding: 9px 14px; text-align: center; cursor: pointer; color: #1f2733; white-space: nowrap; }
.spec-combo-item:hover, .spec-combo-item.active { background: #eef5ff; color: #1677ff; font-weight: 600; }

/* 管理材质选项弹窗 */
.spec-manage-mask { position: fixed; inset: 0; background: rgba(15,27,51,.45); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.spec-manage-box { background: #fff; border-radius: 14px; width: 420px; max-width: 92vw; max-height: 84vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden; font-family: "Songti SC","SimSun","Microsoft YaHei",-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB",sans-serif; }
.spec-manage-box .sm-head { padding: 16px 18px; font-size: 17px; font-weight: 650; border-bottom: 1px solid var(--line); }
.spec-manage-box .sm-head .sm-sub { font-size: 12px; color: #888; font-weight: 400; }
.spec-manage-box .sm-list { padding: 14px 18px; overflow-y: auto; }
.spec-manage-box .sm-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.spec-manage-box .sm-input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: 15px; font-family: inherit; outline: none; }
.spec-manage-box .sm-input:focus { border-color: var(--primary); }
.spec-manage-box .sm-actions { display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); }

/* ===================== 手机端适配 ===================== */
/* 汉堡按钮与遮罩默认隐藏（桌面端不显示） */
.hamburger { display: none; }
.nav-overlay { display: none; }

@media (max-width: 820px) {
  /* 侧边栏改为可滑出的抽屉 */
  .app { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
    width: 80vw; max-width: 300px;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }
  .nav-overlay.show {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0,0,0,.45);
  }
  /* 顶栏显示汉堡按钮，缩小高度 */
  .hamburger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; font-size: 22px; line-height: 1;
    border: none; background: transparent; color: var(--ink); cursor: pointer;
    margin-right: 6px; flex-shrink: 0;
  }
  .topbar { height: 54px; padding: 0 12px; }
  .topbar h1 { font-size: 17px; }
  .topbar .sub { font-size: 12px; }

  /* 内容区 */
  .content { padding: 14px; }
  .content.catalog-frame { height: calc(100vh - 54px); }

  /* 表单单列、行竖排 */
  .form-grid { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .grid-stats { grid-template-columns: 1fr 1fr; gap: 12px; }

  /* 卡片内宽表格可横向滚动，避免撑破屏幕 */
  .card { padding: 16px; overflow-x: auto; }
  table.data { width: 100%; }

  /* 按钮加大点按区，预览工具栏竖排占满 */
  .btn { padding: 11px 16px; font-size: 15px; }
  .btn.sm { padding: 9px 13px; }
  .preview-toolbar { flex-direction: column; align-items: stretch; }
  .preview-toolbar .btn { width: 100%; justify-content: center; }
  .doc { padding: 18px; }
}

@media (max-width: 480px) {
  .grid-stats { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 16px; }
}

