:root {
  --pri: #0f766e;
  --pri-d: #0b5a54;
  --pri-l: #e6f4f2;
  --bg: #f4f5f7;
  --card: #fff;
  --line: #e3e6ea;
  --text: #1f2933;
  --muted: #6b7684;
  --err: #c0392b;
  --warn-bg: #fff6e5;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--pri); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; }
h3 small { font-weight: normal; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sp { flex: 1; }
.err { color: var(--err); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* 顶部导航 */
.nav {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 52px; padding: 0 20px;
  background: #13312e; color: #fff;
}
.nav .brand { font-weight: 600; font-size: 16px; letter-spacing: 1px; }
.nav nav { display: flex; gap: 4px; }
.nav nav a { color: #cfe3e0; padding: 6px 12px; border-radius: 6px; }
.nav nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.nav .me { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.nav .me a { color: #cfe3e0; }

.role { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; color: #fff; cursor: help; }
.role-admin { background: #7048e8; }
.role-cost { background: #d9480f; }
.role-sale { background: #1971c2; }
.role-none { background: #868e96; }

/* 页面框架 */
.page { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page-hd { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-hd .back { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.notice { background: var(--warn-bg); border: 1px solid #f5d9a6; border-radius: 6px; padding: 8px 12px; color: #8a5a00; margin-bottom: 14px; }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  height: 32px; padding: 0 14px;
  border: 1px solid #cfd4da; border-radius: 6px; background: #fff;
  color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--pri); color: var(--pri); text-decoration: none; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri-d); color: #fff; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { height: 26px; padding: 0 10px; font-size: 13px; }
.btn.link { border: none; background: none; color: var(--pri); padding: 0 4px; }
.btn.block { width: 100%; justify-content: center; height: 38px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* 表单 */
input, select, textarea {
  font: inherit; color: inherit;
  height: 32px; padding: 0 8px;
  border: 1px solid #cfd4da; border-radius: 6px; background: #fff;
  min-width: 0;
}
textarea { height: auto; padding: 6px 8px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
input:disabled, select:disabled, textarea:disabled { background: #f6f7f9; color: #444; }
input[type=checkbox] { height: auto; }
label { display: inline-flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 14px; color: var(--text); }
label.inline { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.search { width: 240px; }
.w60 { width: 64px; }
.w80 { width: 84px; }

/* 表格 */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-weight: 600; color: var(--muted); font-size: 12px; background: #fafbfc; white-space: nowrap; }
.tbl tbody tr:hover { background: #f8fbfb; }
.tbl tr.click { cursor: pointer; }
.tbl tr.off td { color: #aab; }
.tbl.compact th, .tbl.compact td { padding: 4px 6px; font-size: 13px; }
.tbl td.actions { white-space: nowrap; text-align: right; }
.tbl tfoot td { font-weight: 600; background: #fafbfc; }
.tbl .sub { color: var(--muted); font-size: 12px; }
.tbl td.mono, .sheet .ptbl td:first-child { white-space: nowrap; }
.tbl-wrap { overflow-x: auto; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 3px 12px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--pri); border-color: var(--pri); color: #fff; }

.status { display: inline-block; padding: 1px 10px; border-radius: 10px; font-size: 12px; }
.st-draft { background: #eef0f3; color: #555; }
.st-confirmed { background: #e3f2ff; color: #1864ab; }
.st-ordered { background: #e6f4ea; color: #2b8a3e; }
.dirty { color: #e67700; font-size: 13px; }

/* 报价单：窗帘条目 */
.item { padding: 0; overflow: hidden; }
.item-hd { display: flex; align-items: flex-end; gap: 12px; padding: 12px 16px; background: #fafbfc; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item-hd .idx { width: 28px; height: 28px; border-radius: 50%; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 600; margin-bottom: 2px; }
.item-hd .grow { flex: 1; min-width: 220px; }
.item-hd .grow select { width: 100%; }
.item-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.item-body .row { display: flex; gap: 12px; flex-wrap: wrap; }
.item-body .row label input[type=number] { width: 92px; }
.item-body .row label select { min-width: 150px; max-width: 320px; }
.item-body .note input { width: 100%; }
.item-body .note { display: flex; }
.item-calc { padding: 0 16px 12px; }
.item-calc:empty { display: none; }
.calc-bar { display: flex; gap: 22px; align-items: center; padding: 10px 12px; background: var(--pri-l); border-radius: 6px; flex-wrap: wrap; }
.calc-bar .stat span { display: block; font-size: 12px; color: var(--muted); }
.calc-bar .stat b { font-size: 15px; font-variant-numeric: tabular-nums; }
.calc-bar .stat.cost b { color: #d9480f; }
.errs { background: #fdecea; color: var(--err); border-radius: 6px; padding: 6px 12px; margin-bottom: 8px; font-size: 13px; }
.item-calc .tbl { margin-top: 8px; }
.add-item { width: 100%; justify-content: center; height: 42px; border-style: dashed; margin-bottom: 14px; }

.totals { display: flex; gap: 32px; flex-wrap: wrap; align-items: flex-end; }
.totals .t span { display: block; font-size: 12px; color: var(--muted); }
.totals .t b { font-size: 18px; font-variant-numeric: tabular-nums; }
.totals .t.big b { font-size: 26px; color: var(--pri); }
.totals .t.cost b { color: #d9480f; }
.totals .upper { font-size: 13px; color: var(--muted); }

/* 产品编辑 */
.def-tbl input, .def-tbl select { width: 100%; }
.def-tbl td { padding: 4px; }
.def-tbl .formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.def-tbl input.formula[data-k="qty_formula"] { min-width: 280px; }
.def-tbl input.formula[data-k="cond_formula"] { min-width: 140px; }
.help { font-size: 13px; color: #445; background: #f8fafb; border: 1px dashed var(--line); border-radius: 6px; padding: 10px 14px; }
.help code { background: #eef2f4; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.help .vars code { cursor: pointer; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.prod-card h3 { display: flex; gap: 8px; align-items: center; }
.prod-card .meta { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.tag { display: inline-block; background: #eef2f4; color: #445; padding: 0 8px; border-radius: 4px; font-size: 12px; margin: 0 4px 4px 0; }

/* 弹窗 / 提示 */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,32,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 10px; width: 520px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: 820px; }
.modal-hd { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-hd .x { margin-left: auto; border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-bd { padding: 16px 18px; overflow: auto; }
.modal-bd .form-grid { grid-template-columns: 1fr 1fr; }
.modal-ft { display: flex; gap: 8px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-err { color: var(--err); margin-right: auto; font-size: 13px; }
#toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 6px; }
#toast div { background: #13312e; color: #fff; padding: 8px 18px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
#toast div.err { background: var(--err); }

/* 登录 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #13312e, #0f766e); }
.login { width: 360px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; }
.login label input { height: 38px; }

/* 模型查看 */
.mv { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .mv { grid-template-columns: 1fr; } }
.mv-main { padding: 12px; }
.mv-bar { align-items: center; margin-bottom: 10px; }
.mv-stage { position: relative; height: min(64vh, 620px); min-height: 360px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #f0f2f5; }
.mv-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.mv-stage canvas:active { cursor: grabbing; }
.mv-axes { position: absolute; left: 8px; bottom: 8px; width: 72px; height: 72px; pointer-events: none; }
.mv-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; padding: 20px; text-align: center; }
.mv-msg.err { color: var(--err); }
.mv-hint { margin-top: 8px; font-size: 13px; }
.mv-side .card { padding: 14px; }
.mv-note { font-size: 13px; line-height: 1.6; margin: 0 0 10px; }
.mv-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 0; }
.mv-kv dt { color: var(--muted); white-space: nowrap; }
.mv-kv dd { margin: 0; overflow-wrap: anywhere; }
.mv-part { display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: 0 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.mv-part:hover { background: #f4f6f8; }
.mv-part.on { background: var(--pri-l); }
.mv-part input { height: auto; margin: 0; }
.mv-name { overflow-wrap: anywhere; }
.mv-part .tag { margin: 0 0 0 4px; }
.mv-size { grid-column: 3; font-size: 12px; }
.mv-dot { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); flex: none; }

/* 打印单据 */
body.print-mode { background: #e9ebee; }
.print-toolbar { display: flex; gap: 10px; align-items: center; max-width: 210mm; margin: 16px auto; }
.sheet { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto 30px; padding: 14mm 14mm; box-shadow: 0 2px 12px rgba(0,0,0,.12); font-size: 12px; }
.sheet h1 { text-align: center; font-size: 20px; margin: 0; }
.sheet .contact { text-align: center; color: #555; margin: 2px 0 8px; }
.sheet .doc-title { text-align: center; font-size: 17px; letter-spacing: 8px; font-weight: 600; margin: 6px 0 12px; }
.sheet table { width: 100%; border-collapse: collapse; }
.sheet .meta td { padding: 3px 4px; }
.sheet .meta td.k { color: #555; width: 70px; }
.sheet .ptbl { margin-top: 10px; }
.sheet .ptbl th, .sheet .ptbl td { border: 1px solid #555; padding: 4px 5px; vertical-align: top; }
.sheet .ptbl th { background: #f1f3f5; white-space: nowrap; }
.sheet .ptbl .total td { font-weight: 600; }
.sheet .blk { margin-top: 14px; page-break-inside: avoid; }
.sheet .blk-hd { font-weight: 600; font-size: 13px; padding: 4px 0; border-bottom: 2px solid #333; }
.sheet .terms { margin-top: 14px; white-space: pre-wrap; line-height: 1.7; }
.sheet .sign { display: flex; justify-content: space-between; margin-top: 30px; }
.sheet .sign div { width: 45%; border-bottom: 1px solid #333; padding-bottom: 26px; }
.sheet .internal { text-align: center; color: var(--err); font-weight: 600; }
@media print {
  @page { size: A4; margin: 0; }
  body, body.print-mode { background: #fff; }
  .no-print, .nav { display: none !important; }
  .sheet { box-shadow: none; margin: 0; width: auto; min-height: auto; }
}

/* 物料图片：表格里的缩略图（有图没图一样大，行高不乱）和点开的大图 */
.tbl th.pic, .tbl td.pic { width: 46px; padding-top: 3px; padding-bottom: 3px; vertical-align: middle; }
.tbl.compact th.pic, .tbl.compact td.pic { width: 36px; padding-top: 2px; padding-bottom: 2px; }
.pimg { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; margin: 0;
  border: 1px solid var(--line); border-radius: 4px; background: #fff; overflow: hidden; vertical-align: middle; flex: none; }
.tbl.compact .pimg { width: 30px; height: 30px; }
button.pimg { cursor: zoom-in; }
button.pimg:hover { border-color: var(--pri); box-shadow: 0 0 0 2px var(--pri-l); }
.pimg img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.pimg.none { background: #eef0f2; color: #9aa3ad; font-size: 10px; line-height: 1; white-space: nowrap; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(15,23,32,.82); display: grid; place-items: center; padding: 30px 70px; }
.lb-fig { margin: 0; display: flex; flex-direction: column; align-items: center; max-width: 100%; max-height: 100%; }
.lb-fig img { display: block; width: auto; height: auto; max-width: min(900px, calc(100vw - 140px)); max-height: calc(100vh - 150px);
  background: #fff; border-radius: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.35); }
.lb-fig figcaption { margin-top: 10px; padding: 8px 14px; background: #fff; border-radius: 6px; text-align: center; max-width: 900px; }
.lb-nav, .lb-x { position: absolute; border: none; background: rgba(255,255,255,.14); color: #fff; cursor: pointer; border-radius: 50%; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 30px; line-height: 1; }
.lb-nav.prev { left: 14px; }
.lb-nav.next { right: 14px; }
.lb-x { top: 14px; right: 14px; width: 38px; height: 38px; font-size: 24px; line-height: 1; }
.lb-nav:hover, .lb-x:hover { background: rgba(255,255,255,.3); }
@media print { .lightbox { display: none !important; } }
