/* ZS 销售合同 — 桌面（灰蓝）上放一张 A4 纸；界面安静，合同是主角 */
:root {
  --desk: #e4e8ee;
  --panel: #ffffff;
  --field: #f6f7f9;
  --ink: #18223a;
  --muted: #5a6476;
  --line: #d3d9e2;
  --line-soft: #e6eaf0;
  --pen: #2b4db8;
  --pen-hover: #213d96;
  --pen-soft: #e7ecfa;
  --seal: #b3261e;
  --ok: #1f7a4d;
  --font: 'IBM Plex Sans', 'Noto Sans SC', system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --r-sm: 6px;
  --r: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--desk); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--pen); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.ico { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap; font-size: 13.5px; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--field); }
.btn.primary { background: var(--pen); border-color: var(--pen); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--pen-hover); }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.quiet:hover { background: rgba(24, 34, 58, 0.06); }
.btn.danger { color: var(--seal); }
.btn.sm { height: 28px; padding: 0 8px; font-size: 12.5px; }
.btn.icon { width: 30px; padding: 0; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- 顶栏 ---------- */
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.seal { width: 30px; height: 30px; border-radius: 4px; border: 2px solid var(--seal); color: var(--seal); display: grid; place-items: center; font-weight: 700; font-size: 11px; line-height: 1; letter-spacing: 0; font-family: 'Noto Sans SC', serif; transform: rotate(-4deg); }
.brand b { font-size: 15px; font-weight: 600; }
.bar .title { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 10px; overflow: hidden; }
.bar .title .no { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar .title .who { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .actions { display: flex; align-items: center; gap: 6px; }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.state.dirty .dot { background: var(--seal); }
.state.busy .dot { background: var(--pen); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- 列表页 ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; font-weight: 600; margin: 0; flex: 1; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search input { width: 100%; height: 36px; padding: 0 12px 0 34px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel); }
.search .ico { position: absolute; left: 11px; top: 10px; color: var(--muted); }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: var(--pen-soft); }
table.list .no { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list td.tnum { white-space: nowrap; }
table.list .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list .prod { color: var(--muted); max-width: 300px; }
.by-ai { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px; background: var(--pen-soft); color: var(--pen); font-weight: 500; }
.empty { padding: 48px 24px; text-align: center; }
.empty h2 { font-size: 16px; margin: 0 0 6px; font-weight: 600; }
.empty p { margin: 0 auto 16px; max-width: 46ch; color: var(--muted); }
.cards { display: none; }

/* ---------- 编辑页 ---------- */
.editor { display: grid; grid-template-columns: minmax(380px, 470px) 1fr; height: calc(100vh - 56px); }
.form { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 4px 20px 96px; }
.desk { overflow: auto; padding: 28px 24px 64px; }
.desk .zs-doc { margin: 0 auto; width: max-content; }
.desk .zs-doc .page { margin: 0 auto 24px; box-shadow: 0 1px 2px rgba(24, 34, 58, 0.08), 0 8px 24px rgba(24, 34, 58, 0.08); }
.desk-tools { display: flex; justify-content: center; gap: 8px; margin: -8px 0 16px; }

.sec { padding: 18px 0 6px; border-bottom: 1px solid var(--line-soft); }
.sec:last-child { border-bottom: 0; }
.sec > h2 { font-size: 13px; font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.sec > h2 .en { font-weight: 400; color: var(--muted); }
.f { display: block; margin-bottom: 10px; }
.f > span { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.in, .f input, .f textarea, .f select { width: 100%; min-height: 36px; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--field); outline: none; }
.f textarea { resize: vertical; line-height: 1.45; }
.in:focus, .f input:focus, .f textarea:focus { background: #fff; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }
.f input.miss, .f textarea.miss { border-color: #b9c6ec; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.with-btn { display: flex; gap: 6px; }
.with-btn input { flex: 1; min-width: 0; }
.suffix { position: relative; }
.suffix input { padding-right: 32px; }
.suffix em { position: absolute; right: 10px; top: 8px; font-style: normal; color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 10px; }
.chip { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { border-color: var(--pen); color: var(--pen); }
.hint { font-size: 12.5px; color: var(--muted); background: var(--field); border-radius: var(--r-sm); padding: 8px 10px; margin: -2px 0 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint b { color: var(--ink); font-weight: 500; }

.item { position: relative; padding: 12px 12px 2px; border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; background: #fff; }
.item-head { display: flex; align-items: center; justify-content: space-between; margin: -2px 0 6px; }
.item-head b { font-size: 12.5px; font-weight: 600; }
.item-head .tools { display: flex; gap: 2px; }
.item .sub { min-height: 36px; padding: 7px 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.units { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 2px 12px; font-variant-numeric: tabular-nums; }
.sum b { font-size: 17px; }

/* 还缺哪些字段 */
.missing { position: relative; }
.missing-pop { position: absolute; right: 0; top: 40px; z-index: 30; width: 260px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgba(24, 34, 58, 0.16); padding: 8px; }
.missing-pop p { margin: 4px 8px 6px; font-size: 12.5px; color: var(--muted); }
.missing-pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer; }
.missing-pop button:hover { background: var(--pen-soft); color: var(--pen); }

/* 打印菜单 */
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 40px; z-index: 30; min-width: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgba(24, 34, 58, 0.16); padding: 6px; }
.menu-pop button { display: flex; width: 100%; gap: 8px; align-items: center; border: 0; background: transparent; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; text-align: left; white-space: nowrap; }
.menu-pop button:hover { background: var(--pen-soft); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line-soft); margin: 4px 0; }

.tabs { display: none; }

/* ---------- 登录 / 提示页 ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.card h1 { font-size: 18px; margin: 14px 0 4px; font-weight: 600; }
.card p { margin: 0 0 16px; color: var(--muted); }
.card .btn.primary { width: 100%; justify-content: center; height: 40px; }
.err { color: var(--seal); font-size: 13px; margin: -6px 0 10px; }
.banner { background: #fff7e6; border: 1px solid #f3d9a4; border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* ---------- AI 连接页 ---------- */
.prose { max-width: 720px; }
.prose h2 { font-size: 15px; margin: 24px 0 8px; }
.prose ol { padding-left: 20px; margin: 0; }
.prose li { margin-bottom: 4px; }
.url-box { display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.url-box code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.say { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 8px; }
.say p { margin: 0; flex: 1; }

/* ---------- 提示 ---------- */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(24, 34, 58, 0.25); max-width: 90vw; }
.toast.bad { background: var(--seal); }

/* ---------- 对话框 ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; max-width: 420px; width: calc(100vw - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(24, 34, 58, 0.35); }
dialog h3 { margin: 0 0 6px; font-size: 16px; }
dialog p { margin: 0 0 16px; color: var(--muted); }
dialog .btns { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- 手机 ---------- */
@media (max-width: 900px) {
  .bar { gap: 6px; padding: 0 10px; }
  .brand b { display: none; }
  .bar .title .who { display: none; }
  .bar .title { gap: 4px; }
  .bar .title .no { overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; }
  .bar .actions { gap: 4px; }
  .bar .actions .btn { padding: 0 9px; }
  .hide-sm { display: none !important; }
  .editor { display: block; height: auto; }
  .form { border-right: 0; padding: 0 16px 120px; overflow: visible; }
  .desk { padding: 16px 0 120px; overflow-x: hidden; }
  .desk .zs-doc .page { margin-bottom: 12px; }
  .editor[data-tab='form'] .desk, .editor[data-tab='preview'] .form { display: none; }
  .tabs { display: flex; position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 25; background: var(--ink); border-radius: 999px; padding: 4px; gap: 2px; box-shadow: 0 6px 20px rgba(24, 34, 58, 0.3); }
  .tabs button { border: 0; background: transparent; color: rgba(255, 255, 255, 0.75); padding: 8px 18px; border-radius: 999px; cursor: pointer; font-size: 14px; }
  .tabs button[aria-pressed='true'] { background: #fff; color: var(--ink); font-weight: 500; }
  .sheet table.list { display: none; }
  .cards { display: block; }
  .cards a { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: var(--ink); }
  .cards a:last-child { border-bottom: 0; }
  .cards .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
  .cards .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
  .page { padding: 16px 12px 64px; }
  .search { max-width: none; order: 3; flex-basis: 100%; }
}
@media (max-width: 420px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .row3 .sub { grid-column: span 2; text-align: left; padding-top: 0; }
}

/* ---------- 打印：只打印合同纸张 ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 14mm 15mm; }
  html, body { background: #fff; height: auto; }
  #app, #toasts, dialog { display: none !important; }
  #print-root { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
