:root {
  color-scheme: light;
  --bg: #fff8ef;
  --panel: #ffffff;
  --text: #2a1c15;
  --muted: #7b6657;
  --line: #eadbcb;
  --primary: #8c4f2b;
  --primary-dark: #6f3b1f;
  --soft: #f7eadc;
  --danger: #c43c2f;
  --success: #247a4d;
  --shadow: 0 10px 24px rgba(87, 51, 24, 0.1);
}

* {
  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;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

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

.app {
  min-height: 100dvh;
  padding: 16px 14px 86px;
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 14px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
}

.topbar p,
.section-title span,
.hint,
.setting-tip {
  color: var(--muted);
}

.ghost-btn,
.secondary-btn {
  background: var(--soft);
  color: var(--primary-dark);
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin: 8px 0 12px;
}

.section-title h2 {
  font-size: 20px;
}

textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 12px;
  line-height: 1.65;
  outline: none;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(140, 79, 43, 0.13);
}

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

.sticky-actions {
  position: sticky;
  bottom: 76px;
  background: linear-gradient(transparent, var(--bg) 24%);
  padding-top: 22px;
}

.hint {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 248, 239, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.tab {
  min-height: 44px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
}

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

.review-list,
.packing-list,
.summary-list {
  display: grid;
  gap: 10px;
}

.row-card,
.customer-card,
.summary-item,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.row-card {
  padding: 12px;
}

.row-card.needs-confirm {
  border-color: var(--danger);
  background: #fff7f5;
}

.row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
  color: var(--text);
}

.field.full {
  grid-column: 1 / -1;
}

.row-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
}

.delete-btn {
  min-height: 34px;
  padding: 0 12px;
  background: #f3dfd8;
  color: var(--danger);
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
}

.summary-item strong {
  font-size: 17px;
}

.customer-card {
  padding: 14px 12px;
}

.customer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.customer-head h3 {
  font-size: 18px;
}

.packed-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  white-space: nowrap;
}

.packed-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
}

.item-lines {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.customer-total {
  display: grid;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.customer-total strong {
  color: var(--text);
}

.combo {
  font-size: 13px;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  padding: 14px 12px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 24px;
}

.subheading {
  font-size: 17px;
  margin: 18px 0 10px;
}

.empty {
  padding: 18px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.54);
}

dialog {
  width: min(92vw, 680px);
  border: 0;
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(42, 28, 21, 0.38);
}

.settings {
  padding: 16px;
}

.dialog-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--soft);
  color: var(--primary-dark);
  font-size: 24px;
}

.settings label {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  font-weight: 700;
}

.settings textarea {
  min-height: 150px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.setting-tip {
  margin-top: 6px;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 82px;
  transform: translateX(-50%) translateY(18px);
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

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

@media (max-width: 420px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

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

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