:root {
  --bg: #eef0ee;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --line: #d9ddd8;
  --line-strong: #bec5bd;
  --text: #202521;
  --muted: #687168;
  --green: #2f5b46;
  --green-dark: #214535;
  --green-soft: #e7efe9;
  --brown: #6a5549;
  --amber: #a56a18;
  --amber-soft: #fff4df;
  --danger: #a53a35;
  --shadow: 0 10px 28px rgba(26, 36, 29, 0.12);
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }

.app-header {
  height: 68px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #26352e;
  color: white;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.app-logo { width: 42px; height: 36px; object-fit: contain; filter: brightness(0) invert(1); }
.brand-block h1 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: 0; }
.brand-block p { margin: 3px 0 0; font-size: 12px; color: #c9d1cc; }
.header-actions { display: flex; gap: 8px; }

.step-tabs {
  height: 52px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.step-tab {
  min-width: 168px;
  padding: 0 20px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.step-tab span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 12px;
}

.step-tab.active { color: var(--green); border-bottom-color: var(--green); }
.step-tab.active span { color: white; border-color: var(--green); background: var(--green); }

.app-shell {
  height: calc(100vh - 120px);
  display: grid;
  grid-template-columns: minmax(560px, 1fr) minmax(430px, 0.82fr);
  overflow: hidden;
}

.editor-pane { overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); }
.step-panel { display: none; max-width: 900px; margin: 0 auto; padding: 28px 32px 48px; }
.step-panel.active { display: block; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.section-heading h2 { margin: 0; font-size: 22px; letter-spacing: 0; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.status-chip { padding: 5px 9px; background: var(--green-soft); color: var(--green); border-radius: 4px; font-size: 12px; white-space: nowrap; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > span { font-size: 13px; font-weight: 600; color: #434a44; }
.field > span b { color: var(--danger); }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 10px 12px;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}

textarea { resize: vertical; line-height: 1.65; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(47,91,70,0.12); }

.upload-row {
  margin-top: 22px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.qr-preview-wrap {
  width: 104px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: white;
}

.qr-preview-wrap img { width: 100%; height: 100%; object-fit: contain; }
.qr-placeholder { width: 42px; height: 42px; color: #8a928b; }
.upload-copy h3 { margin: 0; font-size: 15px; }
.upload-copy p { margin: 6px 0 13px; color: var(--muted); font-size: 12px; }
.inline-actions, .editor-actions, .panel-footer { display: flex; align-items: center; gap: 10px; }
.panel-footer { margin-top: 28px; justify-content: flex-end; }

.icon-text-button, .text-button, .icon-button {
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--green);
  color: white;
  min-height: 38px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 600;
  font-size: 13px;
}

.icon-text-button:hover, .icon-button:hover { background: var(--green-dark); }
.icon-text-button.secondary { background: white; color: #374139; border-color: var(--line-strong); }
.app-header .icon-text-button.secondary { background: rgba(255,255,255,0.08); color: white; border-color: rgba(255,255,255,0.22); }
.app-header .icon-text-button:not(.secondary) { background: white; color: #26352e; }
.text-button { padding: 6px 4px; min-height: 32px; border: 0; background: transparent; color: var(--green); }
.text-button.danger { color: var(--danger); }
.icon-button { width: 34px; height: 34px; min-height: 34px; padding: 0; background: white; color: var(--text); border-color: var(--line-strong); }
.icon-text-button svg, .icon-button svg, .option-icon svg, .qr-placeholder svg { width: 17px; height: 17px; stroke-width: 2; }

.menu-source { min-height: 190px; font-family: "Microsoft YaHei UI", sans-serif; }
.parse-toolbar { margin-top: 16px; display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; }
.parse-summary { min-height: 28px; margin: 18px 0 8px; font-size: 13px; color: var(--muted); }
.parse-summary.warning { padding: 10px 12px; background: var(--amber-soft); color: #754b11; border-left: 3px solid var(--amber); }

.category-editor { display: flex; flex-direction: column; gap: 14px; }
.category-block { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: white; }
.category-header { min-height: 52px; display: flex; align-items: center; gap: 9px; padding: 8px 10px 8px 14px; background: #f3f5f2; border-bottom: 1px solid var(--line); }
.category-header input { max-width: 260px; font-weight: 700; background: white; }
.category-count { color: var(--muted); font-size: 12px; margin-right: auto; white-space: nowrap; }
.mini-button { width: 31px; height: 31px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: white; color: #59615a; padding: 0; }
.mini-button:hover { color: var(--green); border-color: var(--green); }
.mini-button.danger:hover { color: var(--danger); border-color: var(--danger); }
.mini-button svg { width: 15px; height: 15px; }

.item-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.item-table th { padding: 8px 10px; text-align: left; color: var(--muted); font-size: 11px; font-weight: 600; background: #fafbfa; }
.item-table th:nth-child(2) { width: 116px; }
.item-table th:nth-child(3) { width: 130px; }
.item-table td { padding: 7px 10px; border-top: 1px solid #edf0ec; vertical-align: middle; }
.item-table input { padding: 8px 9px; }
.item-table tr.ambiguous td:first-child { position: relative; }
.item-table tr.ambiguous td:first-child::before { content: ""; position: absolute; left: 2px; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: var(--amber); }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.add-item-row { padding: 9px 12px 11px; border-top: 1px solid var(--line); }
.editor-actions { margin-top: 16px; justify-content: space-between; }

.export-options { display: grid; gap: 12px; }
.export-option { display: grid; grid-template-columns: auto 42px 1fr; align-items: center; gap: 13px; min-height: 76px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.export-option:hover { border-color: var(--green); }
.export-option input { width: 17px; height: 17px; accent-color: var(--green); }
.option-icon { width: 42px; height: 42px; display: grid; place-items: center; background: var(--green-soft); color: var(--green); border-radius: 5px; }
.option-icon svg { width: 21px; height: 21px; }
.export-option span:last-child { display: flex; flex-direction: column; gap: 4px; }
.export-option b { font-size: 14px; }
.export-option small { color: var(--muted); line-height: 1.45; }
.export-notice { margin: 18px 0; padding: 12px 14px; background: #f5f2ee; color: var(--brown); border-left: 3px solid #a68d7b; font-size: 12px; line-height: 1.65; }
.export-button { width: 100%; min-height: 48px; border: 0; border-radius: 5px; background: var(--green); color: white; font-size: 15px; font-weight: 700; display: flex; justify-content: center; align-items: center; gap: 9px; }
.export-button:hover { background: var(--green-dark); }
.export-button svg { width: 19px; height: 19px; }
.export-progress { margin-top: 16px; }
.progress-track { height: 6px; overflow: hidden; background: #dde2dd; border-radius: 3px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--green); transition: width 180ms; }
.export-progress p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.preview-pane { min-width: 0; display: flex; flex-direction: column; background: #dfe3df; overflow: hidden; }
.preview-toolbar { min-height: 54px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; background: #f8f9f8; border-bottom: 1px solid var(--line); }
.preview-toolbar strong { font-size: 13px; }
.preview-toolbar span { margin-left: 9px; color: var(--muted); font-size: 12px; }
.preview-actions { display: flex; gap: 6px; }
.canvas-stage { position: relative; flex: 1 1 auto; min-height: 0; padding: 22px; display: grid; place-items: center; overflow: hidden; }
#previewCanvas { display: block; width: 0; height: 0; max-width: none; max-height: none; aspect-ratio: 1080 / 1455; background: white; box-shadow: var(--shadow); }
.canvas-loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(223,227,223,0.86); color: var(--muted); font-size: 13px; }
.thumbnail-strip { min-height: 112px; padding: 11px 16px; display: flex; gap: 10px; overflow-x: auto; background: #f8f9f8; border-top: 1px solid var(--line); }
.thumbnail-button { flex: 0 0 auto; width: 65px; height: 88px; padding: 0; position: relative; overflow: hidden; border: 2px solid transparent; background: white; box-shadow: 0 2px 7px rgba(26,36,29,0.12); }
.thumbnail-button.active { border-color: var(--green); }
.thumbnail-button canvas { width: 100%; height: 100%; display: block; }
.thumbnail-number { position: absolute; right: 2px; bottom: 2px; min-width: 17px; height: 17px; display: grid; place-items: center; background: rgba(20,25,21,0.72); color: white; font-size: 10px; }

.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 30; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { max-width: 340px; padding: 11px 14px; border-radius: 5px; background: #26352e; color: white; box-shadow: var(--shadow); font-size: 13px; animation: toast-in 160ms ease-out; }
.toast.error { background: #7a302c; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

@media (max-width: 1050px) {
  .app-shell { height: auto; min-height: calc(100vh - 120px); grid-template-columns: 1fr; overflow: visible; }
  .editor-pane { overflow: visible; border-right: 0; }
  .preview-pane { height: 760px; border-top: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .app-header { height: auto; min-height: 68px; padding: 10px 14px; }
  .brand-block p { display: none; }
  .header-actions .icon-text-button { width: 38px; padding: 0; font-size: 0; }
  .step-tabs { justify-content: stretch; }
  .step-tab { flex: 1; min-width: 0; padding: 0 7px; font-size: 12px; }
  .app-shell { min-height: calc(100vh - 120px); }
  .step-panel { padding: 22px 16px 38px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .parse-toolbar { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .item-table th:nth-child(2) { width: 88px; }
  .item-table th:nth-child(3) { width: 108px; }
  .item-table td, .item-table th { padding-left: 6px; padding-right: 6px; }
  .preview-pane { height: 650px; }
}
