/* 单据数据共用；屏幕按阅读顺序展示，纸面保持黑白表头和逐项明细。 */
.receipt-page { margin: 0; color: #111; background: #eef1f4; font: 16px/1.5 'MiSans VF', 'Microsoft YaHei', sans-serif; }
.receipt-page * { box-sizing: border-box; }
.receipt-toolbar { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px max(16px, calc((100% - 960px) / 2)); background: #fff; border-bottom: 1px solid #d8dde2; }
.receipt-toolbar a { color: #176939; text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }
.receipt-toolbar label { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.receipt-toolbar select, .receipt-toolbar button { min-height: 44px; max-width: 100%; padding: 8px 12px; border: 1px solid #cbd3d0; border-radius: 8px; background: #fff; color: #111; font: inherit; }
.receipt-toolbar button { background: #187b40; border-color: #187b40; color: #fff; cursor: pointer; }
.receipt-toolbar a, .receipt-toolbar button { flex-shrink: 0; white-space: nowrap; }
.receipt-toolbar button:disabled { opacity: .5; cursor: default; }
.receipt-status { max-width: 960px; margin: 20px auto; padding: 0 16px; }
.receipt-status:empty { display: none; }
.receipt-status.is-error { padding: 12px 16px; border: 1px solid #edbdb7; border-left: 4px solid #b42318;
  border-radius: 10px; background: #fff1ef; color: #9a2819; font-weight: 500; overflow-wrap: anywhere; }
.receipt-papers { max-width: 960px; margin: 24px auto; padding: 0 16px; }
.sales-receipt { background: #fff; color: #111; padding: 24px; margin: 0 0 24px; overflow-wrap: anywhere; line-height: 1.5; }
.sales-receipt__heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
.sales-receipt__heading h1 { margin: 0; font-size: 24px; line-height: 1.4; }
.sales-receipt__copy { white-space: nowrap; }
.sales-receipt__state { align-self: start; font-weight: 600; border: 1px solid #111; padding: 4px 12px; margin: 0 0 16px; }
.sales-receipt table { width: calc(100% - 1px); border: 1px solid #222; border-collapse: collapse; table-layout: fixed; }
.sales-receipt th, .sales-receipt td { border: 1px solid #222; padding: 8px; vertical-align: top; text-align: left; }
.sales-receipt__facts { margin-bottom: 12px; }
.sales-receipt__facts th { width: 13%; font-weight: 500; }
.sales-receipt__facts td { width: 37%; }
.sales-receipt__table-wrap { overflow-x: auto; }
.sales-receipt__reference { font-weight: 500; }
.sales-receipt__items thead { display: table-header-group; }
.sales-receipt__items tr { break-inside: avoid; }
.receipt-col-index { width: 6%; }
.receipt-col-name { width: 26%; }
.receipt-col-spec { width: 21%; }
.receipt-col-quantity { width: 9%; }
.receipt-col-unit { width: 6%; }
.receipt-col-price, .receipt-col-amount { width: 16%; }
.sales-receipt td.number { text-align: center; }
.sales-receipt td.amount { text-align: right; font-variant-numeric: tabular-nums; }
.sales-receipt__gift { margin-left: 8px; border: 1px solid currentColor; padding: 0 4px; white-space: nowrap; }
.sales-receipt__item-note { margin-top: 4px; white-space: pre-wrap; }
.sales-receipt__totals { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px 24px; border-top: 1px solid #222; padding: 12px 0 0; margin: 12px 0; break-inside: avoid; }
.sales-receipt__totals dt { font-weight: 400; }
.sales-receipt__totals dd { font-weight: 600; margin: 4px 0 0; font-variant-numeric: tabular-nums; }
.sales-receipt__note { white-space: pre-wrap; }
.sales-receipt__signatures { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: 12px 24px; padding-top: 12px; break-inside: avoid; }
.sales-receipt__signed { display: grid; gap: 6px; max-width: 100%; }
.sales-receipt__signed svg { width: 220px; max-width: 100%; height: auto; aspect-ratio: 3 / 1; }
.sales-receipt__signed-warning { flex-basis: 100%; margin: 0; padding: 10px 12px; border: 1px solid currentColor; color: #b42318; font-weight: 600; }

/* 同一组单元格重新排布，屏幕与打印不会出现两份金额或不一致的商品。 */
@media screen {
  .receipt-page--return .sales-receipt { border: 1px solid #d8dde2; border-radius: 12px; }
  .receipt-page--return .sales-receipt__copy,
  .receipt-page--return .sales-receipt + .sales-receipt { display: none; }
  .sales-receipt { container: receipt / inline-size; display: flex; flex-direction: column; font-size: 16px; }
  .sales-receipt__heading { order: 0; }
  .sales-receipt__state { order: 1; }
  .sales-receipt__facts { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 8px 16px; order: 2; border: 0; margin: 0; }
  .sales-receipt .sales-receipt__facts { border: 0; }
  .sales-receipt__facts tbody, .sales-receipt__facts tr { display: contents; }
  .sales-receipt__facts th, .sales-receipt__facts td { order: 2; display: block; width: auto; min-width: 0; padding: 0; border: 0; font-size: 16px; }
  .sales-receipt__facts th { grid-column: 1; color: #59616d; font-weight: 400; }
  .sales-receipt__facts td { grid-column: 2; }
  .sales-receipt__facts .receipt-fact-label--customer, .sales-receipt__facts .receipt-fact-label--phone,
  .sales-receipt__facts .receipt-fact-label--document, .sales-receipt__facts .receipt-fact-label--source { display: none; }
  .sales-receipt__facts .receipt-fact-value--customer { order: 0; grid-column: 1 / -1; font-size: 22px; font-weight: 600; }
  .sales-receipt__facts .receipt-fact-value--phone { order: 1; grid-column: 1 / -1; font-size: 18px; margin-bottom: 8px; }
  .sales-receipt__facts .receipt-fact-label--date, .sales-receipt__facts .receipt-fact-value--date { order: 3; white-space: nowrap; }
  .sales-receipt__facts .receipt-fact-label--card, .sales-receipt__facts .receipt-fact-value--card { order: 4; }
  .sales-receipt__facts .receipt-fact-value--document, .sales-receipt__facts .receipt-fact-value--source { grid-column: 1 / -1; order: 5; color: #59616d; font-size: 15px; }
  .sales-receipt__facts .receipt-fact-value--source { order: 6; }
  .receipt-fact-value--document::before, .receipt-fact-value--source::before { content: attr(data-label) ' '; }
  .sales-receipt__bottom { display: contents; }
  .sales-receipt__totals { order: 3; justify-content: flex-start; gap: 16px 24px; margin: 16px 0 20px; padding: 16px 0; border-block: 1px solid #d8dde2; }
  .receipt-figure { order: 3; flex: 1 0 auto; min-width: 0; max-width: 100%; }
  .sales-receipt__totals dt { color: #59616d; font-size: 16px; }
  .sales-receipt__totals dd { font-size: 22px; white-space: nowrap; }
  .sales-receipt__totals .receipt-figure-main { order: 0; flex-basis: 100%; }
  .sales-receipt__totals .receipt-figure-main dd { font-size: 30px; }
  .sales-receipt__totals .receipt-figure-paid { order: 1; }
  .sales-receipt__totals .receipt-figure-due { order: 2; }
  .sales-receipt__totals .receipt-figure-attention dt, .sales-receipt__totals .receipt-figure-attention dd { color: var(--app-state-danger, #b42318); font-weight: 600; }
  .sales-receipt__totals .receipt-figure-redundant { display: none; }
  .sales-receipt__totals .receipt-figure-text dd { font-size: 16px; white-space: normal; }
  .sales-receipt__totals .receipt-figure-long dd { font-size: 18px; }
  .sales-receipt__table-wrap { order: 4; }
  .sales-receipt .sales-receipt__items { border: 0; }
  .sales-receipt__items th, .sales-receipt__items td { padding: 12px 8px; border: 0; border-bottom: 1px solid #d8dde2; }
  .sales-receipt__items th { color: #59616d; background: #f6f8f7; font-size: 15px; font-weight: 500; }
  .sales-receipt__columns th { white-space: nowrap; }
  .sales-receipt__items .sales-receipt__reference { display: none; }
  .sales-receipt__note { order: 5; margin: 20px 0 0; font-size: 16px; }
  .sales-receipt__signatures { order: 6; padding-top: 24px; font-size: 16px; }
  .sales-receipt__signed-warning { font-size: 16px; }
  @container receipt (min-width: 681px) {
    .sales-receipt__facts { grid-template-columns: 80px minmax(0, 1fr) 80px minmax(0, 1fr); }
    .sales-receipt__facts .receipt-fact-value--customer { grid-column: 1 / 3; }
    .sales-receipt__facts .receipt-fact-value--phone { order: 0; grid-column: 3 / 5; align-self: baseline; }
    .sales-receipt__facts .receipt-fact-label--date { grid-column: 3; }
    .sales-receipt__facts .receipt-fact-value--date { grid-column: 4; }
    .sales-receipt__facts .receipt-fact-value--document { grid-column: 3 / 5; }
    .sales-receipt__totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .sales-receipt__totals .receipt-figure-text:not(.receipt-figure-main):not(.receipt-figure-paid):not(.receipt-figure-due) { grid-column: 1 / -1; }
  }
  @container receipt (max-width: 680px) {
    .sales-receipt__heading h1 { font-size: 22px; }
    .sales-receipt__items, .sales-receipt__items tbody { display: block; width: 100%; }
    .sales-receipt__items colgroup, .sales-receipt__items thead { display: none; }
    .sales-receipt__items tbody tr { display: grid; grid-template-columns: max-content max-content minmax(0, 1fr) auto; gap: 6px 4px; padding: 16px 0; border-bottom: 1px solid #d8dde2; }
    .sales-receipt__items tbody tr:first-child { padding-top: 0; }
    .sales-receipt__items td { display: block; min-width: 0; padding: 0; border: 0; text-align: left; }
    .sales-receipt__items .receipt-item-index, .sales-receipt__items .is-empty { display: none; }
    .sales-receipt__items .receipt-item-name { grid-column: 1 / -1; font-size: 17px; font-weight: 600; }
    .sales-receipt__items .receipt-item-spec { grid-column: 1 / -1; color: #59616d; font-size: 15px; }
    .sales-receipt__items .receipt-item-quantity { grid-column: 1; }
    .sales-receipt__items .receipt-item-unit { grid-column: 2; }
    .sales-receipt .sales-receipt__items .receipt-item-price { grid-column: 3; color: #59616d; text-align: left; }
    .receipt-item-price::before { content: '× '; }
    .sales-receipt__items .receipt-item-amount { grid-column: 4; justify-self: end; text-align: right; font-size: 18px; font-weight: 600; white-space: nowrap; }
    .sales-receipt__item-note { font-size: 15px; font-weight: 400; }
    .sales-receipt .sales-receipt__items .receipt-item-long .receipt-item-price { grid-column: 1 / -1; }
    .receipt-item-long .receipt-item-price::before { content: '单价 '; }
    .sales-receipt__items .receipt-item-long .receipt-item-amount { grid-column: 1 / -1; }
  }
  @container receipt (max-width: 280px) {
    .sales-receipt .sales-receipt__items .receipt-item-price { grid-column: 3 / -1; }
    .sales-receipt__items .receipt-item-amount { grid-column: 1 / -1; }
  }
}
/* 独立打印页同样守住触屏输入字号，避免选择联次时触发浏览器放大。 */
@media (pointer: coarse) {
  .receipt-toolbar select, .receipt-toolbar button { font-size: 16px; }
}
@media screen and (max-width: 599px) {
  .receipt-toolbar { gap: 8px; padding: 8px 12px; }
  .receipt-toolbar label { margin-left: auto; }
  .receipt-toolbar label > span { display: none; }
  .receipt-toolbar button { width: 100%; }
  .receipt-page--return .receipt-toolbar { padding-top: max(8px, env(safe-area-inset-top, 0px)); }
  .receipt-page--return .receipt-toolbar button { width: auto; }
  .receipt-papers { padding: 0 8px; margin: 12px auto; }
  .sales-receipt { padding: 16px; }
}
@page { size: auto; margin: 10mm; }
@media print {
  .receipt-page { background: #fff; font-size: 10pt; }
  .receipt-toolbar { display: none !important; }
  .receipt-papers { margin: 0; padding: 0; max-width: none; }
  .sales-receipt { display: block; container-type: normal; padding: 0; margin: 0; font-size: 10pt; }
  .sales-receipt + .sales-receipt { break-before: page; }
  .sales-receipt__heading { margin-bottom: 3mm; }
  .sales-receipt__heading h1 { font-size: 16pt; }
  .sales-receipt__state { display: inline-block; margin-bottom: 3mm; }
  .sales-receipt__facts { break-inside: avoid; }
  .sales-receipt__table-wrap { overflow: visible; }
  .sales-receipt th, .sales-receipt td { padding: 1.5mm; }
  .sales-receipt__columns th { white-space: nowrap; }
  .sales-receipt__totals { gap: 3mm 6mm; margin: 3mm 0; padding-top: 3mm; }
  .sales-receipt__totals dd { font-size: 11pt; }
  .sales-receipt__note { margin: 3mm 0; orphans: 3; widows: 3; }
  .sales-receipt__signatures { gap: 3mm 6mm; padding-top: 3mm; }
  .sales-receipt__signed svg { width: 54mm; }
  .sales-receipt__signed-warning { color: #111; font-size: 10pt; }
}
