:root {
  --paper: #ffffff;
  --ink: #212529;
  --muted: #67748e;
  --line: #d2d6da;
  --card: #ffffff;
  --sidebar: #ffffff;
  --sidebar-ink: #212529;
  --copper: #5e72e4;
  --copper-ink: #ffffff;
  --good: #2dce89;
  --warn: #fb6340;
  --err: #f5365c;
  --steed: #5e72e4;
  --junhao: #5e72e4;
  --shadow: none;
  --font: "Segoe UI", "PingFang HK", "PingFang TC", "Noto Sans CJK TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Source Han Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.45;
}
a { color: #5e72e4; text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.92em; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  flex: none;
  background: #ffffff;
  color: #212529;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 4px;
  display: grid; place-items: center;
  background: #5e72e4; color: white; font-weight: 700;
}
.brand strong { display: block; letter-spacing: 0.02em; color: #212529; }
.brand small { color: #67748e; }
.sidenav { display: flex; flex-direction: column; gap: 4px; }
.sidenav a {
  color: #212529; padding: 8px 10px; border-radius: 4px;
}
.sidenav a:hover { background: #f5f7fa; text-decoration: none; }
.sidenav a.is-active { background: #eff1fc; color: #5e72e4; font-weight: 650; }
.side-note { margin-top: auto; color: #67748e; font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px;
  padding: 10px 16px; background: #5e72e4; color: #ffffff;
  border-bottom: 1px solid #4b5bb6; position: sticky; top: 0; z-index: 6;
}
.switcher { display: flex; flex-wrap: nowrap; gap: 4px; background: rgba(255,255,255,0.16); padding: 3px; border-radius: 4px; }
.switcher button { white-space: nowrap; }
.switcher button, .usermenu button, .btn, button.link {
  font: inherit; cursor: pointer;
}
.switcher button {
  border: 0; background: transparent; color: #ffffff;
  border-radius: 4px; padding: 6px 12px;
}
.switcher button.is-on { background: #ffffff; color: #5e72e4; }
.top-status { margin-left: auto; color: #ffffff; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #ffffff; display: inline-block; }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; list-style: none; padding: 6px 8px; color: #ffffff; white-space: nowrap; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu[open] { background: #ffffff; border-radius: 4px; }
.usermenu[open] summary { color: #212529; }
.usermenu a, .usermenu button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 10px; color: var(--ink);
}
.nav-btn { display: none; }

.content { padding: 20px 18px 40px; }
.page-head, .row-actions { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.page-head h1, .auth-card h1 { margin: 0 0 4px; font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.page-head p, .lede, .hint { color: var(--muted); margin: 0; }
h2 { font-size: 18px; margin: 22px 0 8px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

.card {
  background: #ffffff; border: 1px solid var(--line); border-radius: 4px;
  box-shadow: none; padding: 14px;
}
.card + .card, .stats + .card, .filters + .card, .card + .table-wrap { margin-top: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow { max-width: 460px; }
.grow { flex: 1; min-width: 180px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 12px 0; }
.list-freeze {
  position: sticky;
  top: 61px;
  z-index: 4;
  background: #ffffff;
  margin: 0 0 12px;
  padding-bottom: 8px;
}
.list-freeze .filters {
  margin: 0 0 8px;
  padding: 10px 12px;
  background: #5e72e4;
  border-radius: 4px;
}
.list-freeze .filters label,
.list-freeze .filters label.check { color: #ffffff; }
.list-freeze .filters label.check { padding-bottom: 0; }
.list-freeze .filters .btn,
.list-freeze .filters .btn.primary {
  background: #ffffff;
  color: #3d4db7;
  border-color: #ffffff;
}
.list-freeze .filters .btn:hover,
.list-freeze .filters .btn.primary:hover {
  background: #eff1fc;
  color: #3d4db7;
  border-color: #ffffff;
}
.list-freeze .list-totals { position: static; top: auto; margin: 0; }
.pick-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 8px 12px;
  background: #e8eeff;
  border: 1px solid #c5d0f5;
  border-radius: 4px;
}
.pick-bar .check { color: #212529; padding-bottom: 0; margin: 0; }
.pick-bar .btn.primary { background: #5e72e4; color: #ffffff; border-color: #5e72e4; }
.pick-bar .btn.primary:hover { background: #4b5bb6; color: #ffffff; border-color: #4b5bb6; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check, label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); padding-bottom: 8px; white-space: nowrap; }
input, select, textarea {
  font: inherit; color: #212529; background: white;
  border: 1px solid #d2d6da; border-radius: 4px; padding: 8px 10px; min-width: 0;
}
textarea { width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cfd5f7; border-color: #5e72e4; }
input[readonly] { background: #f5f7fa; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span-2 { grid-column: span 2; }

.btn {
  border: 1px solid #d2d6da; background: white; color: #212529;
  border-radius: 4px; padding: 8px 12px; display: inline-flex; align-items: center;
}
.btn:hover { border-color: #5e72e4; color: #5e72e4; }
.btn.primary { background: #5e72e4; border-color: #5e72e4; color: #ffffff; }
.btn.primary:hover { background: #4b5bb6; border-color: #4b5bb6; color: #ffffff; }
.btn.tiny { padding: 4px 8px; font-size: 13px; }
.btn.sold { background: #f8e8e4; border-color: #e7c8bf; color: var(--err); }
.btn.unsold { background: #e7f3ec; border-color: #b7d8c6; color: var(--good); }
button.link {
  border: 0; background: none; color: var(--err); padding: 0; text-decoration: underline;
}
button.link:disabled {
  color: var(--muted); text-decoration: none; cursor: not-allowed; opacity: 0.7;
}
.inline-form { display: inline; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid #e4e7ed; text-align: left; vertical-align: top; color: #212529; }
table.grid th { color: #ffffff; font-weight: 600; background: #5e72e4; white-space: nowrap; border-bottom-color: #4b5bb6; }
table.grid.zebra tbody tr:nth-child(odd) td { background: #ffffff; }
table.grid.zebra tbody tr:nth-child(even) td { background: #d4e2fc; }
table.grid tfoot td { font-weight: 650; background: #f5f7fa; color: #212529; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.ops { white-space: nowrap; display: flex; gap: 8px; align-items: center; }
td.ops { display: table-cell; }
td.ops .inline-form, td.ops a, td.ops button { margin-right: 6px; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; }
.neg { color: var(--err); }
th.check, td.check { width: 36px; position: sticky; left: 0; z-index: 1; }
table.grid th.check { z-index: 2; background: #5e72e4; }
table.grid td.check { background: #ffffff; }
table.grid.zebra tbody tr:nth-child(even) td.check { background: #d4e2fc; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px;
  background: #eff1fc; color: #4b5bb6; font-size: 12px; font-family: var(--font);
}
.tag-printed { background: #e5f6ec; color: #1f6b4a; font-weight: 650; }
.badge-unprinted {
  display: inline-block;
  margin-left: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  background: #fb6340;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.3;
  vertical-align: middle;
  text-decoration: none;
}
.badge-unprinted:hover { background: #f5365c; color: #ffffff; text-decoration: none; }
.print-state { margin: 0 0 12px; }
.related { display: block; color: var(--muted); font-family: var(--font); font-size: 12px; margin-top: 2px; }

.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; color: var(--muted); }
.pager-links { display: flex; gap: 8px; }
.pager-jump { display: flex; gap: 6px; align-items: center; }
.pager-jump input { width: 72px; }

.alert { padding: 10px 12px; border-radius: 4px; margin-bottom: 10px; border: 1px solid transparent; }
.alert.ok { background: #e8f6ee; color: #145c32; }
.alert.err { background: #fde8ee; color: #9f1239; }
.alert.warn { background: #fff4d6; color: #7a5300; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 12px 0; }
.stats div { background: #ffffff; border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; }
.list-totals {
  display: flex; flex-wrap: wrap; gap: 12px 28px; align-items: baseline;
  margin: 0 0 12px; padding: 10px 12px;
  background: #ffffff; border: 1px solid var(--line); border-radius: 4px;
  color: #212529; position: sticky; top: 64px; z-index: 4;
}
.list-totals strong { margin-left: 6px; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.stats span { display: block; color: var(--muted); font-size: 12px; }
.stats strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.totals { display: flex; flex-wrap: wrap; gap: 16px; padding: 8px 2px; }
.actions-end { margin-left: auto; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
details#customer-quick { color: var(--muted); }
details#customer-quick summary { cursor: pointer; }
.customer-card { background: var(--paper); border-radius: 8px; padding: 8px 10px; }
.customer-card strong { display: block; color: var(--ink); }
.picker-results { display: flex; flex-direction: column; gap: 6px; }
.picker-results button {
  text-align: left; font: inherit; background: white; border: 1px solid var(--line);
  border-radius: 4px; padding: 8px 10px; cursor: pointer; color: #212529;
}
.bar { height: 10px; background: #e4e7ed; border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--copper); width: 0; }
ul.plain { margin: 0; padding-left: 18px; }
.series-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.series-form input[type="number"] { width: 88px; }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(440px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 4px; padding: 28px 24px; box-shadow: none;
}
.eyebrow { letter-spacing: 0.08em; text-transform: uppercase; font-size: 12px; color: var(--copper); margin: 0 0 6px; }
.error-detail { white-space: pre-wrap; background: #f5f7fa; padding: 10px; border-radius: 4px; overflow: auto; }

.print-body { background: #f0f2f4; }
.print-toolbar { max-width: 840px; margin: 16px auto; display: flex; gap: 10px; align-items: center; }
.sheet {
  max-width: 840px; margin: 0 auto 32px; background: white; padding: 32px;
  border: 1px solid var(--line);
}
.sheet-head, .sheet-customer, .sheet-totals { display: flex; justify-content: space-between; gap: 16px; }
.sheet-head h1 { margin: 0; font-size: 28px; }
.sheet-no { text-align: right; }
.sheet-no strong { font-family: var(--mono); font-size: 22px; }
.sheet-customer { margin: 16px 0; }
.sheet-customer span, .sheet-totals span { color: var(--muted); display: inline-block; min-width: 4em; }
.sheet-totals { flex-direction: column; align-items: flex-end; margin-top: 12px; }
.sheet-totals p { margin: 2px 0; }
.due { font-size: 18px; font-weight: 700; }

.print-form {
  display: grid;
  gap: 10px;
  max-width: 720px;
  margin-top: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.print-form h3 { margin: 4px 0 0; }
.print-form input { width: 100%; }
.lh-note {
  max-width: 210mm;
  margin: 0 auto 10px;
  color: var(--muted);
  font-size: 13px;
}
.letterhead {
  position: relative;
  width: 210mm;
  height: 297mm;
  margin: 0 auto 32px;
  background: white;
  color: #1a1a1a;
  padding: 0;
  box-sizing: border-box;
  border: 1px solid var(--line);
  font-family: PMingLiU, serif;
  font-size: 17px;
  overflow: hidden;
}
.lh-pay,
.lh-code, .lh-cname, .lh-addr, .lh-phone,
.lh-no, .lh-handler, .lh-date,
.lh-count, .lh-discount, .lh-due {
  position: absolute;
  font-family: PMingLiU, serif;
  font-size: 17px;
}
.lh-pay { top: 180px; left: 505px; line-height: 1.3; }
.lh-code { top: 310px; left: 165px; width: 410px; white-space: nowrap; overflow: hidden; }
.lh-cname { top: 345px; left: 165px; width: 410px; white-space: nowrap; overflow: hidden; }
.lh-addr { top: 370px; left: 120px; width: 430px; white-space: nowrap; overflow: hidden; }
.lh-phone { top: 400px; left: 120px; width: 430px; white-space: nowrap; overflow: hidden; }
.lh-no { top: 310px; left: 585px; }
.lh-handler { top: 360px; left: 560px; }
.lh-date { top: 400px; left: 560px; }
.lh-fit {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
}
.lh-lines {
  position: absolute;
  width: 700px;
  top: 470px;
  left: 75px;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: PMingLiU, serif;
  font-size: 17px;
}
.lh-lines col.c-item { width: 100px; }
.lh-lines col.c-desc { width: 260px; }
.lh-lines col.c-qty { width: 70px; }
.lh-lines col.c-price { width: 85px; }
.lh-lines col.c-amt { width: 185px; }
.lh-lines td {
  padding: 0 0 10px;
  border: 0;
  vertical-align: top;
  background: transparent;
  overflow: hidden;
  white-space: nowrap;
  font-size: 17px;
}
.lh-lines td.num { text-align: left; }
.lh-count { top: 905px; left: 435px; font-size: 17px; }
.lh-discount { top: 955px; left: 590px; }
.lh-due { top: 1020px; left: 590px; }
.sheet-related { max-width: 210mm; margin: 0 auto 24px; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-105%);
    transition: transform .18s ease;
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-btn { display: inline-flex; flex-direction: row; align-items: center; gap: 0; line-height: 1.2; white-space: nowrap; border: 1px solid rgba(255,255,255,0.7); border-radius: 4px; padding: 6px 10px; color: #ffffff; }
  .switcher { overflow-x: auto; max-width: 58vw; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
  .top-status { display: none; }
  .content { padding: 14px 12px 32px; }
}
@media (max-width: 560px) {
  .form-grid, .span-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .switcher { overflow-x: auto; max-width: 70vw; }
}

@media print {
  .print-toolbar, .lh-note, .sheet-related { display: none !important; }
  .print-body { background: white; }
  .sheet, .letterhead { border: 0; margin: 0; box-shadow: none; }
  .letterhead { width: 210mm; height: 297mm; padding: 0; }
  .sheet { max-width: none; }
}
@page { size: A4; margin: 12mm 16mm 14mm 16mm; }
@page letterhead { size: A4; margin: 0; }
.letterhead { page: letterhead; }
