* { box-sizing: border-box; }
body {
  margin: 0; font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: #eef1f5; color: #1f2937; font-size: 14px;
}
[hidden] { display: none !important; }
.muted { color: #6b7280; }
.small { font-size: 12px; }
.center { text-align: center; }
.err { color: #dc2626; }
.num { text-align: right; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid #cbd5e1; background: #fff; color: #1f2937;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { background: #fff; border-color: #fca5a5; color: #dc2626; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #e2e8f0; }
.btn.block { width: 100%; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.tiny { padding: 1px 8px; font-size: 11px; margin-left: 6px; }
input, select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #cbd5e1; border-radius: 7px;
  font-size: 14px; font-family: inherit; background: #fff;
}
textarea { resize: vertical; line-height: 1.55; }
label { display: block; font-size: 13px; color: #374151; margin-bottom: 8px; }
label > input, label > select, label > textarea { margin-top: 3px; }
label.chk { display: flex; align-items: center; gap: 6px; }
label.chk input { width: auto; margin: 0; }
label.inline { display: flex; align-items: center; gap: 6px; }
label.inline input { margin: 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff; padding: 40px; border-radius: 16px; width: 340px;
  box-shadow: 0 10px 40px rgba(0,0,0,.08); text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input { margin: 18px 0 12px; }

/* ---------- layout ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 10px 22px; border-bottom: 1px solid #e2e8f0;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; cursor: pointer; }
.topbar nav { display: flex; gap: 8px; }
.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }

/* ---------- list table ---------- */
.list-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
.list-table th, .list-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef1f5; }
.list-table th { background: #f8fafc; font-size: 12px; color: #64748b; }
.list-table td.num, .list-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.list-table tr:hover td { background: #f8fafc; }
.link { color: #1d4ed8; cursor: pointer; text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; }
.tag.MA { background: #dbeafe; color: #1e40af; }
.tag.CR { background: #fef3c7; color: #92400e; }
.tag.QT { background: #dcfce7; color: #166534; }
.tag.draft { background: #e2e8f0; color: #475569; }
.tag.sent { background: #ffedd5; color: #9a3412; }
.tag.signed { background: #dcfce7; color: #166534; }

/* ---------- editor ---------- */
.edit-layout { display: flex; gap: 0; align-items: flex-start; }
.edit-form {
  flex: 0 0 46%; max-width: 620px; background: #fff; min-height: calc(100vh - 53px);
  padding: 18px 22px 60px; border-right: 1px solid #e2e8f0;
}
.form-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.form-head h2 { margin: 0; font-size: 18px; }
.form-head-actions { display: flex; gap: 6px; }
fieldset {
  border: 1px solid #e2e8f0; border-radius: 10px; margin: 16px 0; padding: 12px 14px 6px;
}
legend { font-weight: 700; font-size: 13px; color: #1d4ed8; padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 10px; }
.calc-result span { margin-right: 8px; }
.calc-box {
  background: #f0f6ff; border: 1px dashed #93c5fd; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 13px;
}
.calc-box strong { display: block; margin-bottom: 6px; }
.calc-result { display: flex; align-items: center; gap: 10px; }
.calc-result strong { display: inline; color: #1d4ed8; font-size: 15px; }
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.items-table th { background: #f8fafc; font-size: 12px; color: #64748b; padding: 6px; text-align: left; }
.items-table td { padding: 4px 3px; vertical-align: top; }
.items-table textarea { font-size: 13px; padding: 5px 7px; }
.items-table input { font-size: 13px; padding: 5px 7px; }
.del-item { color: #dc2626; cursor: pointer; font-size: 16px; padding: 6px 4px; }
.totals-preview { text-align: right; font-size: 14px; padding: 6px 4px; }
.totals-preview b { font-variant-numeric: tabular-nums; }
.form-foot { display: flex; gap: 8px; margin-top: 18px; }

/* ---------- preview sheet (screen) ---------- */
.preview-pane { flex: 1; padding: 18px; position: sticky; top: 53px; max-height: calc(100vh - 53px); overflow: auto; }
.preview-label { font-size: 12px; color: #64748b; margin-bottom: 8px; }
.sheet {
  background: #fff; width: 210mm; min-height: 290mm; margin: 0 auto;
  padding: 14mm 14mm 10mm; box-shadow: 0 4px 24px rgba(0,0,0,.12);
  font-family: "PMingLiU", "Noto Serif TC", "PingFang TC", serif;
  color: #000; font-size: 11.5pt; line-height: 1.45;
  transform-origin: top left;
}

/* ---------- quote document ---------- */
.q-head { position: relative; }
.q-logo { position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 9mm; width: auto; }
.q-company { text-align: center; font-size: 17pt; font-weight: 700; letter-spacing: 6px; }
.q-title { text-align: center; font-size: 14pt; font-weight: 700; letter-spacing: 10px; margin: 10px 0 14px; }
.q-info { width: 100%; border-collapse: collapse; font-size: 10.5pt; margin-bottom: 4px; }
.q-info td { padding: 1.5px 0; vertical-align: top; }
.q-info td.r { width: 38%; }
.q-ntd { text-align: right; font-size: 9.5pt; font-style: italic; padding: 2px 0; }
.q-items { width: 100%; border-collapse: collapse; font-size: 10.5pt; }
.q-items th, .q-items td { border: 1.2px solid #000; padding: 5px 7px; vertical-align: top; }
.q-items th { text-align: center; font-weight: 700; background: #fff; }
.q-items td.c { text-align: center; }
.q-items td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.q-items .desc { white-space: pre-wrap; }
.q-items .total-row td { font-weight: 700; }
.q-block { border: 1.2px solid #000; border-top: none; padding: 6px 8px; font-size: 9.5pt; white-space: pre-wrap; line-height: 1.5; }
.q-remark { margin-top: 8px; font-size: 9.5pt; white-space: pre-wrap; line-height: 1.55; }
.q-remark .h { font-weight: 700; }
.q-secret { margin-top: 8px; font-size: 9.5pt; font-weight: 700; }
.q-sign { margin-top: 14px; font-size: 11pt; display: flex; justify-content: space-between; align-items: flex-end; }
.q-sign-left { padding-bottom: 4mm; }
.q-sign .line { display: inline-block; width: 60mm; border-bottom: 1.2px solid #000; height: 14mm; vertical-align: bottom; }
.q-stamp { height: 30mm; width: auto; margin-right: 8mm; }

/* ---------- print ---------- */
@media print {
  body { background: #fff; }
  .no-print, .topbar, .preview-label { display: none !important; }
  .edit-layout { display: block; }
  .preview-pane { padding: 0; position: static; max-height: none; overflow: visible; }
  .sheet { box-shadow: none; width: auto; min-height: 0; margin: 0; padding: 0; zoom: 1 !important; }
  @page { size: A4 portrait; margin: 14mm; }
}

