/* The sheet is a printed object: grey slide on a dark desk, same in light and dark mode.
   Each .page is a size container, so 1cqw = 1% of the page width and the whole slide scales as one. */
:root {
  --desk: #1b1c1e;
  --paper: #dadada;
  --ink: #111;
  --muted: #6d6d6d;
  --rule: #4a4a4a;
  --frame: #2b2b2b;
  --mat: #efefef;
  --bar: #111214;
  --bar-ink: #e9e9e9;
  --bar-muted: #9a9a9a;
  --accent: #e9e9e9;
  --ok: #8fd18f;
  --warn: #e7c46b;
  --err: #ff8f8f;
  --font: 'Helvetica Neue', Helvetica, Arial, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--desk); color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  padding: 10px 22px; background: var(--bar); color: var(--bar-ink); border-bottom: 1px solid #000;
}
.bar-left, .bar-right { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.brand { height: 14px; width: auto; filter: invert(1); display: block; }
.store { font-size: 13px; }
.status { font-size: 11px; letter-spacing: .06em; padding: 2px 8px; border: 1px solid currentColor; border-radius: 999px; }
.status.draft { color: var(--warn); }
.status.submitted { color: var(--ok); }
.status.closed { color: var(--bar-muted); }
.totals { font-size: 13px; color: var(--bar-muted); }
.totals b { color: var(--bar-ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.save-state { font-size: 11px; color: var(--bar-muted); min-width: 56px; }
.save-state.err { color: var(--err); }
.bar select { background: transparent; color: var(--bar-ink); border: 1px solid #3a3b3e; border-radius: 6px; padding: 4px 8px; font-size: 13px; }
.bar select option { color: #111; }
button { cursor: pointer; border-radius: 6px; padding: 6px 14px; font-size: 13px; border: 1px solid #3a3b3e; }
button.ghost { background: transparent; color: var(--bar-ink); }
button.ghost:hover { border-color: #6a6b6e; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
button.primary:hover { background: #fff; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- pages ---------- */
main { padding: 22px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.page {
  container-type: inline-size;
  width: 100%; max-width: 1400px; aspect-ratio: 2000 / 1155;
  background: var(--paper);
  scroll-margin-top: 70px;
}
.page-inner {
  height: 100%;
  display: grid; grid-template-columns: 46.4% 23.3% 26.1%; column-gap: .9cqw;
  padding: 2cqw 2cqw 1.8cqw 1.1cqw;
  font-size: 1cqw; line-height: 1.3;
}

.left { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.logo { display: flex; align-items: baseline; gap: .55cqw; margin-bottom: 1.3cqw; }
.logo img { height: 1.05cqw; width: auto; display: block; }
.logo span { font-size: 1.05cqw; letter-spacing: .02em; }

.logo { padding-bottom: .9cqw; border-bottom: 1.5px solid var(--ink); }
.logo span { font-weight: 700; }
.logo em { margin-left: auto; font-style: normal; font-size: .78cqw; letter-spacing: .18em; color: var(--muted); }

.fields { display: grid; grid-template-columns: 1fr 1fr; column-gap: 2cqw; row-gap: 1.05cqw; padding-left: 1.2cqw; }
/* label: bold zh + light small-caps en */
.f-label { font-size: .92cqw; display: flex; align-items: baseline; gap: .45cqw; }
.f-label { flex-wrap: wrap; }
.f-label b { font-weight: 700; letter-spacing: .04em; white-space: nowrap; flex: none; }
.f-label .en { font-size: .82cqw; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.f-value { margin-top: .3cqw; font-size: 1.1cqw; font-weight: 500; white-space: pre-line; }
.f-value.dim { color: var(--muted); font-weight: 400; }
.fields .name .f-value { font-size: 1.35cqw; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.block { padding-left: 1.2cqw; margin-top: 1.25cqw; }
.desc { list-style: none; margin: .4cqw 0 0; padding: 0; font-size: .95cqw; }
.desc li + li { margin-top: .25cqw; }
.desc li::before { content: '– '; color: var(--muted); }
.desc .en { margin-left: .7cqw; color: var(--muted); font-size: .85cqw; }
.model { margin-top: .4cqw; font-size: .85cqw; color: var(--muted); letter-spacing: .03em; }
table.grid.chart tr.fit-head td { background: #c6c6c6; font-weight: 700; font-size: .82cqw; }
table.grid.chart tr.fit-head td:not(.label) { color: var(--muted); font-weight: 400; }
table.grid.chart tr.fit td { font-size: .85cqw; height: 1.6cqw; }
table.grid.chart tr.fit-head td { height: 1.6cqw; }
.page.no-fit tr.fit-head, .page.no-fit tr.fit { display: none; }
@media (max-width: 760px) { .page.no-fit tr.fit-head, .page.no-fit tr.fit { display: table-row; } }

table.grid { border-collapse: collapse; margin-top: .6cqw; table-layout: fixed; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { border: 1px solid var(--rule); text-align: center; font-weight: 400; font-size: .95cqw; padding: 0; width: 7.4cqw; height: 1.8cqw; }
table.grid thead th { background: #c6c6c6; font-weight: 700; letter-spacing: .04em; }
table.grid thead th:first-child { font-size: .8cqw; letter-spacing: .12em; color: var(--muted); }
table.grid.chart td.label { white-space: nowrap; text-align: left; padding-left: .7cqw; font-weight: 500; background: #d2d2d2; }
table.grid.order td { height: 2.9cqw; }
table.grid.order td.color { font-size: .95cqw; font-weight: 700; background: #d2d2d2; }
.order-cell { background: #f4f4f4; }
.order-cell input {
  width: 100%; height: 100%; border: 0; margin: 0; padding: 0; background: transparent; text-align: center;
  font-size: 1.3cqw; color: var(--ink); -moz-appearance: textfield; border-radius: 0;
}
.order-cell input::-webkit-outer-spin-button, .order-cell input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.order-cell input::placeholder { color: #b5b5b5; }
.order-cell input:focus { outline: 2px solid #111; outline-offset: -3px; background: #fff; }
.order-cell input.has { font-weight: 700; background: #fff; }
.order-cell input:disabled { color: var(--ink); }
.order-head { display: flex; align-items: baseline; gap: 1.2cqw; }
.subtotal { font-size: .88cqw; color: var(--muted); font-variant-numeric: tabular-nums; }
.subtotal b { color: var(--ink); }

.photo { border: 1.5px solid var(--frame); padding: .38cqw; background: var(--mat); min-height: 0; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.photo.empty { background: transparent; }
.photo.big { grid-column: 2; }
.photo-col { grid-column: 3; display: grid; grid-template-rows: 357fr 428fr 260fr; row-gap: .9cqw; min-height: 0; }

/* ---------- summary (last page) ---------- */
.page.summary { aspect-ratio: auto; min-height: calc(min(100vw - 44px, 1400px) * 1155 / 2000); }
.sum-inner { padding: 2cqw 2.4cqw 2.2cqw 1.1cqw; font-size: 1cqw; line-height: 1.35; display: flex; flex-direction: column; }
.sum-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 2cqw; padding-left: 1.2cqw; }
.sum-store { margin-top: .45cqw; font-size: 1.6cqw; font-weight: 700; letter-spacing: .02em; }
.sum-meta { display: flex; gap: 1.6cqw; font-size: .9cqw; color: var(--muted); }
.sum-meta b { color: var(--ink); }
#sumBody { margin: 1.4cqw 0 0 1.2cqw; }
.sum-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .95cqw; }
.sum-table th, .sum-table td { border: 1px solid var(--rule); padding: .55cqw .8cqw; text-align: left; vertical-align: middle; }
.sum-table thead th { background: #c6c6c6; font-weight: 700; letter-spacing: .04em; }
.sum-table tbody tr { cursor: pointer; }
.sum-table tbody tr:hover td { background: #e6e6e6; }
.sum-table .n { text-align: right; white-space: nowrap; }
.sum-table td.sizes span { display: inline-block; margin-right: 1.2cqw; white-space: nowrap; }
.sum-table tfoot td { font-weight: 700; background: #c6c6c6; font-size: 1.05cqw; }
.sum-empty { color: var(--muted); padding: 2cqw 0; }
.sum-foot { display: flex; gap: 2cqw; align-items: flex-end; margin: 1.8cqw 0 0 1.2cqw; }
.sum-note { flex: 1; display: block; }
.sum-note textarea { display: block; width: 100%; margin-top: .5cqw; padding: .6cqw .8cqw; border: 1px solid var(--rule); background: #f4f4f4; color: var(--ink); font-size: .95cqw; resize: vertical; border-radius: 0; }
.sum-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .8cqw; max-width: 45%; }
.sum-actions .hint { flex-basis: 100%; text-align: right; margin: 0 0 .3cqw; font-size: .85cqw; color: var(--muted); }
.sum-actions button { font-size: 1cqw; padding: .7cqw 1.6cqw; border-radius: 0; }
.sum-actions .ghost { color: var(--ink); border-color: var(--ink); background: transparent; }
.sum-actions .primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.sum-actions .primary:hover { background: #000; }

.empty-msg { color: #bbb; text-align: center; padding: 80px 20px; font-size: 15px; }

/* ---------- modal ---------- */
.modal, .lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden], .lightbox[hidden] { display: none; }
.modal-box { background: #f4f4f4; color: #111; width: min(640px, 100%); max-height: 90vh; overflow: auto; border-radius: 10px; padding: 22px; }
.modal-box h2 { margin: 0 0 12px; font-size: 18px; }
.review-list table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.review-list th, .review-list td { text-align: left; padding: 6px 4px; border-bottom: 1px solid #ddd; }
.review-list td.n, .review-list th.n { text-align: right; }
.review-list tfoot td { font-weight: 700; border-bottom: 0; }
.note { display: block; margin-top: 14px; font-size: 13px; }
.note textarea { display: block; width: 100%; margin-top: 6px; padding: 8px; border: 1px solid #bbb; border-radius: 6px; resize: vertical; background: #fff; color: #111; }
.hint { font-size: 12px; color: #666; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.modal-actions .ghost { color: #111; border-color: #bbb; }
.modal-actions .primary { background: #111; color: #fff; border-color: #111; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- phone: stack into a scrolling card ---------- */
@media (max-width: 760px) {
  .bar { padding: 8px 16px; gap: 6px 10px; }
  .bar .brand, #btnPrint, .save-state { display: none; }
  .bar button { padding: 5px 10px; }
  main { padding: 16px; }
  .page { aspect-ratio: auto; }
  .page-inner { display: flex; flex-direction: column; gap: 10px; padding: 16px; font-size: 13px; }
  .logo { margin-bottom: 14px; gap: 6px; }
  .logo img, .logo span { height: 13px; font-size: 13px; }
  .fields { padding-left: 0; row-gap: 14px; column-gap: 14px; }
  .f-label, .f-value { font-size: 13px; }
  .f-label { gap: 2px 6px; }
  .f-label .en { font-size: 10px; }
  .fields .name .f-value { font-size: 15px; }
  .logo em { font-size: 9px; }
  table.grid thead th:first-child { font-size: 11px; }
  .f-value { margin-top: 4px; }
  .block { padding-left: 0; margin-top: 16px; }
  .desc { font-size: 13px; margin-top: 8px; }
  .desc li + li { margin-top: 4px; }
  .desc .en { font-size: 11px; margin-left: 6px; }
  .model { font-size: 12px; }
  table.grid.chart tr.fit-head td, table.grid.chart tr.fit td { font-size: 11px; }
  table.grid { margin-top: 8px; width: 100%; }
  table.grid th, table.grid td { font-size: 13px; height: 34px; width: auto; }
  table.grid.order td { height: 44px; }
  table.grid.order td.color { font-size: 13px; }
  .order-cell input { font-size: 16px; }
  .subtotal { font-size: 12px; }
  .order-head { gap: 12px; }
  .photo { padding: 4px; }
  .photo.big { aspect-ratio: 3 / 4.6; }
  .photo-col { grid-template-rows: none; grid-template-columns: 1fr 1fr 1fr; column-gap: 8px; }
  .photo-col .photo { aspect-ratio: 3 / 4; }
  .page.summary { min-height: 0; }
  .sum-inner { padding: 16px; font-size: 13px; }
  .sum-head { flex-direction: column; align-items: flex-start; padding-left: 0; gap: 6px; }
  .sum-store { font-size: 18px; }
  .sum-meta { font-size: 12px; gap: 12px; }
  #sumBody { margin: 12px 0 0; overflow-x: auto; }
  .sum-table { font-size: 12px; min-width: 560px; }
  .sum-table th, .sum-table td { padding: 6px 8px; }
  .sum-table tfoot td { font-size: 13px; }
  .sum-foot { flex-direction: column; align-items: stretch; margin: 16px 0 0; gap: 12px; }
  .sum-note textarea { font-size: 14px; padding: 8px; }
  .sum-actions { max-width: none; gap: 8px; }
  .sum-actions .hint { font-size: 12px; text-align: left; }
  .sum-actions button { font-size: 14px; padding: 10px 16px; flex: 1; }
}

/* ---------- print / PDF: one product per slide-shaped page ---------- */
@media print {
  @page { size: 346mm 200mm; margin: 0; }
  body { background: #fff; }
  .bar, .modal, .lightbox { display: none !important; }
  main { padding: 0; gap: 0; }
  .page { max-width: none; width: 346mm; height: 200mm; aspect-ratio: auto; break-after: page; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .order-cell, .order-cell input.has { background: transparent; }
  .page.summary { height: auto; min-height: 200mm; }
  .sum-actions button, .sum-actions .hint { display: none; }
  .sum-note textarea { resize: none; border-color: transparent; background: transparent; padding-left: 0; }
  .sum-table tbody tr:hover td { background: transparent; }
  .order-cell input:focus { outline: none; }
}
