:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --panel: #ffffff;
  --text: #17221d;
  --muted: #65736c;
  --line: #d8e0dc;
  --accent: #0b8f74;
  --accent-strong: #06735d;
  --danger: #c7362f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.app-shell {
  width: min(1380px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 750;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.status {
  min-width: 150px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: #eef5f2;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.status.ok {
  border-color: #9bd3c6;
  color: var(--accent-strong);
}

.status.error {
  border-color: #e7aaa6;
  color: var(--danger);
  background: #fff3f2;
}

.entry-panel,
.preview-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.store-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f8fbfa;
}

.store-picker__label {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.store-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.store-button {
  min-width: auto;
  border: 1px solid #9fc9d6;
  background: #fff;
  color: #1d5d70;
  padding: 8px 12px;
}

.store-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.preview-panel {
  margin-top: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
}

.purchase-table {
  width: 100%;
  min-width: 1240px;
  border-collapse: collapse;
}

.purchase-table th,
.purchase-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px;
  vertical-align: middle;
}

.purchase-table th {
  background: #f2f6f4;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
}

.purchase-table td:last-child,
.purchase-table th:last-child {
  border-right: none;
}

.purchase-table tr:last-child td {
  border-bottom: none;
}

.purchase-table input,
.purchase-table select,
#copyPreview {
  width: 100%;
  border: 1px solid var(--line);
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
  outline: none;
}

.purchase-table output {
  display: block;
  min-width: 58px;
  color: var(--muted);
  font-size: 14px;
}

.store-chip {
  display: inline-block;
  min-width: 126px;
  padding: 7px 9px;
  border: 1px solid #cfe3dc;
  background: #f1faf7;
  color: #166b56;
  font-size: 13px;
  white-space: nowrap;
}

.purchase-table input:focus,
.purchase-table select:focus,
#copyPreview:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 143, 116, 0.12);
}

.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
  border: 1px solid var(--line);
  background: #f8fbfa;
}

.summary-bar div {
  padding: 12px;
  border-right: 1px solid var(--line);
}

.summary-bar div:last-child {
  border-right: none;
}

.summary-bar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.summary-bar strong {
  font-size: 18px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.bottom-actions {
  margin-top: 14px;
}

.store-picker--compact {
  margin-bottom: 0;
}

.store-picker--compact .store-button {
  padding: 7px 10px;
  font-size: 13px;
}

button {
  min-width: 108px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

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

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

.secondary {
  background: #fff;
  color: var(--accent-strong);
  border-color: #8ccabe;
}

.icon-button {
  min-width: 36px;
  width: 36px;
  padding: 8px 0;
  background: #fff;
  color: var(--danger);
  border-color: #e7aaa6;
  font-size: 18px;
  line-height: 1;
}

.preview-panel h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

#copyPreview {
  min-height: 230px;
  resize: vertical;
  line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  background: #f8fbfa;
}

.success-celebration {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 34, 29, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.success-celebration.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.success-celebration__card {
  position: relative;
  z-index: 2;
  width: min(420px, 100%);
  padding: 28px 24px 22px;
  border: 1px solid #bfe1d7;
  background: #fff;
  box-shadow: 0 24px 80px rgba(23, 34, 29, 0.24);
  text-align: center;
  transform: translateY(12px) scale(0.96);
  transition: transform 220ms ease;
}

.success-celebration.is-visible .success-celebration__card {
  transform: translateY(0) scale(1);
}

.success-celebration__badge {
  display: inline-grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
}

.success-celebration__title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.success-celebration__text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
}

.success-celebration__close {
  margin-top: 18px;
  background: var(--accent);
  color: #fff;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  left: var(--x);
  width: 9px;
  height: 16px;
  border-radius: 2px;
  animation: confetti-fall var(--duration) ease-in var(--delay) forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate3d(0, -24px, 0) rotate(0deg);
    opacity: 0;
  }

  12% {
    opacity: 1;
  }

  100% {
    transform: translate3d(18px, 110vh, 0) rotate(var(--rotate));
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .success-celebration,
  .success-celebration__card {
    transition: none;
  }

  .confetti-piece {
    display: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 16px, 1380px);
    padding: 14px 0;
  }

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

  .entry-panel,
  .preview-panel {
    padding: 10px;
  }

  .table-wrap {
    overflow-x: visible;
    border: none;
  }

  .purchase-table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  .purchase-table thead {
    display: none;
  }

  .purchase-table,
  .purchase-table tbody,
  .purchase-table tr,
  .purchase-table td {
    display: block;
  }

  .purchase-table tr.purchase-row {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    background: #fff;
  }

  .purchase-table td {
    display: grid;
    grid-template-columns: 94px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    border-right: none;
    padding: 9px 10px;
  }

  .purchase-table td::before {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.2;
  }

  .purchase-table td:nth-child(1)::before {
    content: "所属门店";
  }

  .purchase-table td:nth-child(2)::before {
    content: "产品名称";
  }

  .purchase-table td:nth-child(3)::before {
    content: "单位";
  }

  .purchase-table td:nth-child(4)::before {
    content: "净重";
  }

  .purchase-table td:nth-child(5)::before {
    content: "毛重";
  }

  .purchase-table td:nth-child(6)::before {
    content: "进货金额";
  }

  .purchase-table td:nth-child(7)::before {
    content: "进货单价";
  }

  .purchase-table td:nth-child(8)::before {
    content: "皮重";
  }

  .purchase-table td:nth-child(9)::before {
    content: "备注";
  }

  .purchase-table td:nth-child(10) {
    display: flex;
    justify-content: flex-end;
  }

  .purchase-table td:nth-child(10)::before {
    content: "";
  }

  .purchase-table input,
  .purchase-table select {
    min-height: 40px;
    font-size: 16px;
  }

  .purchase-table output {
    min-width: 0;
    font-size: 16px;
  }

  .store-chip {
    min-width: 0;
    width: 100%;
    white-space: normal;
  }

  .summary-bar {
    grid-template-columns: 1fr;
  }

  .store-picker {
    align-items: stretch;
    flex-direction: column;
  }

  .bottom-actions {
    position: sticky;
    bottom: 0;
    z-index: 30;
    margin: 12px -10px 0;
    padding: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 24px rgba(23, 34, 29, 0.12);
  }

  .bottom-actions .store-picker {
    margin: 0 0 8px;
    padding: 8px;
  }

  .bottom-actions .store-picker__label {
    font-size: 13px;
  }

  .bottom-actions .store-buttons {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .bottom-actions .store-button {
    min-width: 0;
    padding: 8px 4px;
    white-space: nowrap;
  }

  .bottom-actions .actions {
    flex-wrap: nowrap;
    margin-top: 0;
  }

  .bottom-actions .actions button {
    min-width: 0;
    padding: 10px 8px;
  }

  .summary-bar div {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .summary-bar div:last-child {
    border-bottom: none;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 120px;
  }
}
