@font-face {
  font-family: "Receipt Pixel";
  src: url("assets/fonts/ark-pixel-12px-proportional-latin.otf.woff2") format("woff2");
  font-display: block;
  unicode-range: U+0000-02FF, U+2000-2BFF;
}

@font-face {
  font-family: "Receipt Pixel";
  src: url("assets/fonts/ark-pixel-12px-proportional-zh_cn.otf.woff2") format("woff2");
  font-display: block;
  unicode-range: U+3000-9FFF, U+FF00-FFEF;
}

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #17181a;
  --muted: #666d78;
  --line: #d9dde4;
  --line-strong: #b8c0cc;
  --accent: #1c5fd4;
  --accent-dark: #164ba8;
  --danger: #b42318;
  --shadow: 0 24px 80px rgb(24 31 42 / 0.12);
  --radius: 18px;
  --receipt-paper: #fdfdfb;
  --receipt-edge: #f7f8f5;
  --receipt-ink: #111111;
  --store-title-size: 16px;
  --strip-store-size: 13px;
  --item-name-size: 15px;
  --item-amount-size: 15px;
  --content-width: min(920px, calc(100% - 40px));
  --pixel-font: "Receipt Pixel", monospace;
  --value-font: var(--pixel-font);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111316;
    --surface: #1a1d21;
    --surface-soft: #20242a;
    --text: #f3f5f7;
    --muted: #a7afba;
    --line: #343a43;
    --line-strong: #505966;
    --accent: #7aa7ff;
    --accent-dark: #9cbcff;
    --shadow: 0 24px 80px rgb(0 0 0 / 0.34);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgb(255 255 255 / 0.82), transparent 34rem),
    var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.app-header {
  width: var(--content-width);
  margin: 0 auto;
  padding: 28px 0 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
  font-weight: 760;
}

.serial-card {
  min-width: 178px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.74);
  box-shadow: 0 12px 40px rgb(24 31 42 / 0.08);
  display: grid;
  gap: 4px;
  text-align: right;
}

.header-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.mobile-section-tabs {
  width: var(--content-width);
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  box-shadow: 0 12px 32px rgb(24 31 42 / 0.08);
}

.mobile-section-tabs button {
  min-height: 42px;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 760;
}

.mobile-section-tabs button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 8px 18px rgb(24 31 42 / 0.08);
}

@media (prefers-color-scheme: dark) {
  .serial-card {
    background: rgb(26 29 33 / 0.78);
  }
}

.serial-card span {
  color: var(--muted);
  font-size: 12px;
}

.serial-card strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
}

.app-shell {
  width: var(--content-width);
  margin: 0 auto 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

#togglePanel {
  display: none;
}

.top-panel-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.quick-panel,
.history-panel,
.control-panel,
.defaults-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.82);
  box-shadow: var(--shadow);
}

@media (prefers-color-scheme: dark) {
  .quick-panel,
  .history-panel,
  .control-panel,
  .defaults-panel,
  .preview-panel {
    background: rgb(26 29 33 / 0.86);
  }
}

.quick-panel {
  padding: 18px;
  display: grid;
}

.history-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.control-panel {
  display: grid;
  gap: 18px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.control-panel form {
  display: grid;
  gap: 18px;
}

.control-panel .buyer-details,
.control-panel .form-section {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.82);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.control-panel .form-section {
  padding: 0 18px;
}

.control-panel .form-section-content {
  padding: 4px 0 18px;
}

@media (prefers-color-scheme: dark) {
  .control-panel .buyer-details,
  .control-panel .form-section {
    background: rgb(26 29 33 / 0.86);
  }
}

.defaults-panel {
  padding: 18px;
}

.preview-panel {
  position: static;
  min-height: 0;
  padding: 24px;
}

body[data-mobile-section="generate"] .history-panel,
body[data-mobile-section="generate"] .defaults-panel {
  display: none;
}

body[data-mobile-section="history"] .quick-panel,
body[data-mobile-section="history"] .control-panel,
body[data-mobile-section="history"] .defaults-panel,
body[data-mobile-section="history"] .preview-panel {
  display: none;
}

body[data-mobile-section="defaults"] .top-panel-grid,
body[data-mobile-section="defaults"] .quick-panel,
body[data-mobile-section="defaults"] .history-panel,
body[data-mobile-section="defaults"] .control-panel,
body[data-mobile-section="defaults"] .preview-panel {
  display: none;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
}

.export-toolbar {
  margin-top: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.export-toolbar > button {
  min-width: 0;
  padding-left: 10px;
  padding-right: 10px;
}

.primary,
.secondary,
.ghost,
.mini-button,
.danger-button {
  min-height: 42px;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 720;
  white-space: nowrap;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary {
  color: #ffffff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary,
.ghost,
.mini-button {
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.secondary:hover,
.ghost:hover,
.mini-button:hover {
  border-color: var(--line-strong);
}

.danger-button {
  color: var(--danger);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--danger) 34%, var(--line));
}

.section-details > summary,
.form-section > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 780;
  list-style: none;
}

.section-details > summary::-webkit-details-marker,
.form-section > summary::-webkit-details-marker {
  display: none;
}

.section-details > summary::after,
.form-section > summary::after {
  content: "收起";
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.section-details:not([open]) > summary::after,
.form-section:not([open]) > summary::after {
  content: "展开";
}

.section-content {
  padding-top: 12px;
}

.form-section {
  border-top: 1px solid var(--line);
}

.form-section:first-of-type {
  border-top: 0;
}

.form-section-content {
  padding: 4px 0 20px;
}

.buyer-details {
  margin: 0 0 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  overflow: hidden;
}

.buyer-details summary {
  min-height: 46px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 780;
  list-style: none;
}

.buyer-details summary::-webkit-details-marker {
  display: none;
}

.buyer-details summary b {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  line-height: 1.35;
}

.buyer-details[open] .summary-closed,
.buyer-details:not([open]) .summary-open {
  display: none;
}

.buyer-details .stack-grid {
  padding: 0 12px 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.5;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

input[type="file"] {
  padding: 8px;
}

.form-grid,
.stack-grid,
.asset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
}

.stack-grid {
  grid-template-columns: 1fr;
}

.range-field span {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.range-field b {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

input[type="range"] {
  min-height: 26px;
  padding: 0;
  accent-color: var(--accent);
}

.wide {
  grid-column: 1 / -1;
}

.asset-grid {
  align-items: end;
}

.file-field input {
  color: var(--muted);
  background: var(--surface-soft);
}

.paste-card {
  display: grid;
  gap: 12px;
  height: 100%;
  align-content: start;
}

.paste-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.paste-actions span {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.paste-actions span:empty {
  display: none;
}

.items-editor {
  display: grid;
  gap: 12px;
}

.item-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  overflow: hidden;
}

.item-card.is-dragging {
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgb(28 95 212 / 0.14);
  opacity: 0.78;
}

.item-card-header {
  min-height: 42px;
  padding: 10px 50px 10px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-card-header strong {
  font-size: 14px;
}

.item-card-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.item-card-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.item-card-actions .mini-button {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

.item-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 30px;
  height: 30px;
  padding: 0 0 2px;
  border: 1px solid color-mix(in srgb, var(--danger) 38%, var(--line));
  border-radius: 50%;
  color: var(--danger);
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
}

.item-delete:hover {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.drag-handle {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.item-reordering {
  user-select: none;
}

.item-fields {
  padding: 12px;
  display: grid;
  grid-template-columns: 0.72fr 1.5fr 0.9fr;
  gap: 10px;
}

.discounts {
  padding: 0 12px 12px;
  display: grid;
  gap: 9px;
}

.discount-row {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr auto;
  gap: 9px;
  align-items: end;
}

.calculation-strip {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.calculation-strip b {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.history-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.history-head h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.history-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.history-search {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.history-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  max-height: 320px;
  overflow: auto;
  flex: 1;
  align-content: start;
}

.history-empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  text-align: center;
}

.history-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  display: grid;
  gap: 8px;
}

.history-item strong {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-delete-button {
  width: 26px;
  height: 26px;
  min-height: 26px;
  flex: 0 0 26px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  border-radius: 999px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, #ffffff);
  font-size: 18px;
  font-weight: 760;
  line-height: 1;
}

.history-delete-button:hover {
  border-color: color-mix(in srgb, var(--danger) 42%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, #ffffff);
}

.history-details {
  display: grid;
  gap: 6px;
}

.history-details summary {
  width: fit-content;
  min-height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 720;
  list-style: none;
}

.history-details summary::-webkit-details-marker {
  display: none;
}

.history-details[open] summary {
  color: var(--text);
  border-color: var(--line-strong);
}

.history-details p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.history-details summary + p {
  margin-top: 2px;
}

.history-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, max-content));
  gap: 6px;
}

.history-actions .mini-button {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 720;
}

.history-safety {
  margin-top: 20px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.history-safety > summary {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 760;
  list-style: none;
}

.history-safety > summary::-webkit-details-marker {
  display: none;
}

.history-safety > summary::after {
  content: "展开";
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.history-safety[open] > summary::after {
  content: "收起";
}

.history-safety > summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
}

.history-safety-content {
  padding-top: 8px;
  display: grid;
  gap: 22px;
}

.safety-block + .safety-block {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.safety-block-head h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.safety-block-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.backup-list,
.audit-list {
  margin-top: 10px;
  display: grid;
  max-height: 300px;
  overflow: auto;
}

.safety-empty {
  margin: 0;
  padding: 14px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.backup-item,
.audit-item {
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.backup-item:first-child,
.audit-item:first-child {
  border-top: 0;
}

.backup-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.backup-item-top strong {
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.backup-item-top .mini-button {
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 12px;
}

.backup-details {
  margin-top: 7px;
}

.backup-details summary {
  width: fit-content;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.backup-details p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.audit-item {
  display: grid;
  gap: 4px;
}

.audit-item strong {
  font-size: 13px;
  line-height: 1.35;
}

.audit-item span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.history-danger {
  margin-top: 24px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 16%, var(--line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--danger) 4%, var(--surface-soft));
}

.history-danger summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style-position: inside;
}

.history-danger-body {
  margin-top: 12px;
  display: grid;
  gap: 16px;
}

.history-danger-body strong {
  color: var(--danger);
  font-size: 13px;
}

.history-danger-body p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.history-danger-body .danger-button {
  width: 100%;
  margin-top: 4px;
}

.danger-action-group {
  display: grid;
  gap: 8px;
}

.danger-action-group + .danger-action-group {
  padding-top: 16px;
  border-top: 1px solid color-mix(in srgb, var(--danger) 14%, var(--line));
}

.history-danger:not([open]) .history-danger-body {
  display: none;
}

.danger-dialog {
  width: min(100% - 32px, 380px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--text);
  background: transparent;
}

.danger-dialog::backdrop {
  background: rgb(14 18 24 / 0.34);
  backdrop-filter: blur(12px);
}

.danger-dialog-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.danger-dialog-card h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.danger-dialog-card p {
  margin: 8px 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.danger-dialog-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.danger-dialog-card input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-soft);
  outline: none;
}

.danger-dialog-card input:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent);
}

.danger-dialog-actions {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.image-preview-dialog {
  width: min(100% - 24px, 520px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--text);
  background: var(--surface);
}

.image-preview-dialog::backdrop {
  background: rgb(14 18 24 / 0.42);
  backdrop-filter: blur(10px);
}

.image-preview-sheet {
  max-height: calc(100dvh - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.image-preview-head {
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.image-preview-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.image-preview-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.image-preview-close {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-soft);
  font-size: 22px;
  line-height: 1;
}

.image-preview-stage {
  min-height: 0;
  padding: 14px;
  overflow: auto;
  background: var(--surface-soft);
  -webkit-overflow-scrolling: touch;
}

.image-preview-stage img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  background: var(--receipt-paper);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.image-preview-actions {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.image-preview-actions button {
  width: 100%;
}

.preview-frame {
  min-height: calc(100dvh - 168px);
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 8px 0 18px;
}

.export-details {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.export-details .export-toolbar {
  margin-top: 0;
}

.receipt {
  width: min(100%, 414px);
  color: var(--receipt-ink);
  position: relative;
  padding: 20px 0;
  filter: grayscale(1) contrast(1.12);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.receipt-paper {
  position: relative;
  overflow: visible;
  min-height: 720px;
  padding: 28px 22px 30px;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.34), transparent 26%, rgb(69 74 69 / 0.024) 82%, transparent),
    var(--receipt-paper);
  box-shadow:
    inset 1px 0 rgb(179 184 177 / 0.7),
    inset -1px 0 rgb(179 184 177 / 0.7),
    0 20px 58px rgb(0 0 0 / 0.2);
}

.receipt-paper::before,
.receipt-paper::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 20px;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 0.34), transparent 26%, rgb(69 74 69 / 0.024) 82%, transparent),
    var(--receipt-paper);
  pointer-events: none;
  z-index: 0;
}

.receipt-paper::before {
  top: -20px;
  clip-path: polygon(0 100%, 2.9% 28%, 5.8% 100%, 8.7% 28%, 11.6% 100%, 14.5% 28%, 17.4% 100%, 20.3% 28%, 23.2% 100%, 26.1% 28%, 29% 100%, 31.9% 28%, 34.8% 100%, 37.7% 28%, 40.6% 100%, 43.5% 28%, 46.4% 100%, 49.3% 28%, 52.2% 100%, 55.1% 28%, 58% 100%, 60.9% 28%, 63.8% 100%, 66.7% 28%, 69.6% 100%, 72.5% 28%, 75.4% 100%, 78.3% 28%, 81.2% 100%, 84.1% 28%, 87% 100%, 89.9% 28%, 92.8% 100%, 95.7% 28%, 100% 100%);
}

.receipt-paper::after {
  bottom: -20px;
  clip-path: polygon(0 0, 2.9% 72%, 5.8% 0, 8.7% 72%, 11.6% 0, 14.5% 72%, 17.4% 0, 20.3% 72%, 23.2% 0, 26.1% 72%, 29% 0, 31.9% 72%, 34.8% 0, 37.7% 72%, 40.6% 0, 43.5% 72%, 46.4% 0, 49.3% 72%, 52.2% 0, 55.1% 72%, 58% 0, 60.9% 72%, 63.8% 0, 66.7% 72%, 69.6% 0, 72.5% 72%, 75.4% 0, 78.3% 72%, 81.2% 0, 84.1% 72%, 87% 0, 89.9% 72%, 92.8% 0, 95.7% 72%, 100% 0);
}

.thermal {
  font-family: var(--pixel-font);
  font-weight: 720;
  letter-spacing: 0;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: geometricPrecision;
}

.thermal * {
  text-shadow:
    0.42px 0 currentColor,
    -0.24px 0 rgb(0 0 0 / 0.38),
    0 0.32px rgb(0 0 0 / 0.28);
}

.thermal-noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0.055;
  mix-blend-mode: multiply;
  background:
    radial-gradient(ellipse at 18% 12%, rgb(92 98 91 / 0.11), transparent 24%),
    radial-gradient(ellipse at 82% 76%, rgb(92 98 91 / 0.08), transparent 28%),
    radial-gradient(circle at 56% 42%, rgb(0 0 0 / 0.035), transparent 18%);
}

.receipt-header,
.receipt-details,
.receipt-shop-strip,
.date-row,
.receipt-items,
.receipt-summary,
.number-row,
.transaction-block,
.receipt-notice,
.feedback-line,
.receipt-qr {
  position: relative;
}

.receipt-title {
  display: grid;
  grid-template-columns: auto 42px minmax(0, 1fr) auto;
  justify-content: center;
  gap: 7px;
  align-items: center;
  font-size: var(--store-title-size);
  line-height: 1.15;
  white-space: nowrap;
}

.receipt-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: grayscale(1) contrast(1.08) saturate(0);
  mix-blend-mode: multiply;
  image-rendering: pixelated;
}

.receipt-title-text {
  min-width: 0;
  justify-self: center;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 0;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  color: #050505;
  font-family: var(--pixel-font);
  font-size: var(--store-title-size);
  font-weight: 950;
  white-space: nowrap;
  -webkit-text-stroke: 0.18px currentColor;
  text-shadow:
    0.46px 0 currentColor,
    0 0.34px currentColor;
}

.receipt-title-text .editable-text {
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  -webkit-text-stroke: inherit;
  text-shadow: inherit;
}

.receipt-copy-title {
  margin: 14px 0 19px;
  text-align: center;
  font-size: 17px;
  font-weight: 950;
  -webkit-text-stroke: 0.18px currentColor;
}

.receipt-details {
  display: grid;
  gap: 3px;
  margin-bottom: 18px;
  font-size: 13px;
  line-height: 1.32;
}

.receipt-details p {
  margin: 0;
  overflow-wrap: anywhere;
}

.detail-label {
  color: #050505;
  font-weight: 950;
  -webkit-text-stroke: 0.16px currentColor;
  text-shadow:
    0.62px 0 currentColor,
    -0.28px 0 rgb(0 0 0 / 0.45),
    0 0.36px rgb(0 0 0 / 0.32);
}

.detail-value {
  color: #060606;
  font-family: var(--value-font);
  font-weight: 400;
  -webkit-text-stroke: 0;
  text-shadow:
    0.04px 0 currentColor,
    0 0.08px rgb(0 0 0 / 0.1);
}

.editable-text {
  min-width: 32px;
  min-height: 1em;
  display: inline-block;
  border-radius: 2px;
  font-family: var(--value-font);
  font-weight: 400;
  -webkit-text-stroke: 0;
  outline: 0;
  cursor: text;
}

.editable-text:focus {
  background: rgb(0 0 0 / 0.08);
  box-shadow: 0 0 0 2px rgb(0 0 0 / 0.12);
}

.editable-text:empty::before {
  content: attr(data-placeholder);
  color: rgb(0 0 0 / 0.34);
}

.receipt-shop-strip {
  display: grid;
  grid-template-columns: 70px 1fr 70px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  text-align: center;
}

.receipt-shop-strip div:nth-child(2) {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.receipt-shop-strip strong {
  font-family: var(--value-font);
  font-size: 14px;
  font-weight: 840;
  -webkit-text-stroke: 0.08px currentColor;
}

.receipt-shop-strip span {
  font-family: var(--value-font);
  font-size: var(--strip-store-size);
  font-weight: 840;
  -webkit-text-stroke: 0.08px currentColor;
  white-space: nowrap;
  overflow: hidden;
}

.stamp-mark {
  height: 40px;
  background:
    linear-gradient(var(--receipt-ink), var(--receipt-ink)) 0 0 / 100% 18px no-repeat,
    linear-gradient(var(--receipt-ink), var(--receipt-ink)) 0 24px / 100% 16px no-repeat;
}

.date-row,
.number-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
}

.receipt-rule {
  margin: 8px 0 14px;
  border-top: 2px dashed var(--receipt-ink);
}

.receipt-items {
  display: grid;
  gap: 18px;
  margin-bottom: 24px;
}

.product-line,
.discount-line {
  display: grid;
  grid-template-columns: 76px 1fr 82px;
  gap: 8px;
  align-items: start;
  font-size: 15px;
  line-height: 1.25;
}

.product-line .amount,
.discount-line .amount {
  font-family: var(--value-font);
  font-size: var(--item-amount-size);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.product-line .name,
.discount-line .label {
  font-family: var(--value-font);
  font-size: var(--item-name-size);
  font-weight: 700;
}

.transaction-block .editable-text {
  font-family: var(--value-font);
  font-weight: 400;
  text-shadow:
    0.04px 0 currentColor,
    0 0.08px rgb(0 0 0 / 0.1);
}

.product-line .name {
  overflow-wrap: anywhere;
}

.discount-line {
  margin-top: 8px;
  font-size: 14px;
}

.discount-line .label {
  grid-column: 1 / 3;
}

.item-note {
  margin: 8px auto 0;
  max-width: 100%;
  font-family: var(--value-font);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.18;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.receipt-summary {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 15px;
}

.receipt-summary div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.transaction-block {
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
}

.transaction-block strong {
  white-space: nowrap;
}

.transaction-block .editable-text {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-align: right;
  white-space: nowrap;
}

.receipt-notice {
  margin: 16px 0 42px;
  display: grid;
  gap: 3px;
  text-align: center;
  font-size: 15px;
  line-height: 1.45;
}

.receipt-notice p,
.feedback-line {
  margin: 0;
}

.feedback-line {
  margin-bottom: 18px;
  text-align: center;
  font-size: 15px;
}

.receipt-qr {
  display: block;
  width: 190px;
  height: 190px;
  object-fit: contain;
  margin: 0 auto;
  filter: grayscale(1) contrast(1.08) saturate(0);
  mix-blend-mode: multiply;
  image-rendering: pixelated;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(16px);
  min-width: 220px;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .serial-card {
    text-align: left;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .controls-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .top-panel-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    grid-column: auto;
    grid-row: auto;
    position: static;
    min-height: 0;
  }

  .control-panel,
  .defaults-panel {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .app-header,
  .app-shell,
  .mobile-section-tabs {
    width: min(100% - 24px, 1380px);
  }

  .mobile-section-tabs {
    margin: -2px auto 14px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    box-shadow: 0 12px 32px rgb(24 31 42 / 0.08);
  }

  .mobile-section-tabs button {
    min-height: 40px;
    border-radius: 12px;
    color: var(--muted);
    background: transparent;
    font-size: 13px;
    font-weight: 760;
  }

  .mobile-section-tabs button[aria-pressed="true"] {
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 8px 18px rgb(24 31 42 / 0.08);
  }

  #togglePanel {
    display: none;
  }

  body[data-mobile-section="generate"] .history-panel,
  body[data-mobile-section="generate"] .defaults-panel {
    display: none;
  }

  body[data-mobile-section="history"] .quick-panel,
  body[data-mobile-section="history"] .control-panel,
  body[data-mobile-section="history"] .defaults-panel,
  body[data-mobile-section="history"] .preview-panel {
    display: none;
  }

  body[data-mobile-section="defaults"] .top-panel-grid,
  body[data-mobile-section="defaults"] .quick-panel,
  body[data-mobile-section="defaults"] .history-panel,
  body[data-mobile-section="defaults"] .control-panel,
  body[data-mobile-section="defaults"] .preview-panel {
    display: none;
  }

  body[data-mobile-section="generate"].controls-collapsed .control-panel,
  body[data-mobile-section="defaults"].controls-collapsed .defaults-panel {
    display: block;
  }

  .toolbar,
  .form-grid,
  .stack-grid,
  .asset-grid,
  .calculation-strip,
  .item-fields,
  .discount-row {
    grid-template-columns: 1fr;
  }

  .export-toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-head {
    display: grid;
  }

  .history-head p {
    display: none;
  }

  .history-search {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .history-search label:first-child {
    grid-column: 1 / -1;
  }

  .history-actions {
    gap: 6px;
  }

  .history-safety > summary {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .history-safety > summary small {
    width: auto;
    margin: -6px 0 0;
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .history-safety > summary::after {
    grid-column: 2;
    grid-row: 1;
  }

  .backup-item-top {
    align-items: flex-start;
  }

  .paste-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .paste-actions .ghost {
    width: 100%;
  }

  .preview-panel,
  .quick-panel,
  .history-panel,
  .defaults-panel {
    padding: 14px;
  }

  .control-panel {
    padding: 0;
  }

  .control-panel .form-section {
    padding: 0 14px;
  }

  .receipt-paper {
    padding: 24px 18px 28px;
  }

  .receipt-title {
    width: calc(100% + 18px);
    margin-left: -9px;
    grid-template-columns: 24px 30px minmax(0, 1fr) 24px;
    gap: 5px;
    font-size: var(--store-title-size);
  }

  .receipt-logo {
    width: 30px;
    height: 30px;
  }

  .receipt-title > span {
    font-size: 10px;
  }

  .receipt-title-text {
    font-weight: 900;
    -webkit-text-stroke: 0.08px currentColor;
    text-shadow:
      0.22px 0 currentColor,
      0 0.14px currentColor;
  }

  .product-line,
  .discount-line {
    grid-template-columns: 62px 1fr 70px;
    font-size: 14px;
  }

  .item-note {
    margin-left: auto;
    margin-right: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-header,
  .top-panel-grid,
  .quick-panel,
  .history-panel,
  .control-panel,
  .defaults-panel,
  .toolbar,
  .toast {
    display: none !important;
  }

  .app-shell,
  .preview-panel,
  .preview-frame {
    width: auto;
    margin: 0;
    padding: 0;
    display: block;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  .receipt {
    width: 80mm;
    margin: 0 auto;
  }

  .receipt-paper {
    box-shadow: none;
  }
}
