:root {
  --primary: #7A2E1E;
  --cta: #A63A28;
  --cta-active: #8E3021;
  --secondary: #C98A3B;
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-soft: #F4EDE4;
  --border: #E4DBD0;
  --text: #2B2320;
  --muted: #655C56;
  --success: #2F7A4F;
  --error: #B3261E;
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 68px;
  --shadow: 0 2px 10px rgba(42, 28, 20, .05);
  --font-title: "Songti SC", "SimSun", "Noto Serif CJK SC", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}
button, input { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}
.icon-sm { width: 17px; height: 17px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--secondary); outline-offset: 2px; }

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 12px 32px rgba(42, 28, 20, .08);
  padding: 34px 24px 24px;
  text-align: center;
}
.login-mark {
  width: 56px; height: 56px; margin: 0 auto 16px;
  border-radius: 16px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
}
.login-mark .icon { width: 28px; height: 28px; }
.login-card h1 {
  font-family: var(--font-title);
  font-size: 27px; letter-spacing: .04em; color: var(--primary);
}
.login-subtitle { color: var(--muted); margin-top: 6px; font-size: 14px; }
.login-card form { margin-top: 28px; text-align: left; }
.field-label {
  display: block; font-size: 14px; font-weight: 600;
  margin-bottom: 8px; color: var(--text);
}
.input {
  width: 100%; min-height: 48px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--text);
  font-size: 16px;
}
.input::placeholder { color: #9A908A; }
.form-error { min-height: 20px; color: var(--error); font-size: 14px; margin-top: 8px; }
.login-footnote { margin-top: 20px; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ---------- 按钮 ---------- */
.btn {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s ease, background-color .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cta); color: #fff; }
.btn-primary:hover { background: var(--cta-active); }
.btn-primary:disabled { background: #D8CFC5; color: #FFF; cursor: not-allowed; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.text-btn {
  background: none; border: 0; color: var(--cta); font-weight: 700;
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 2px;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--primary); display: grid; place-items: center;
}
.icon-btn-sm { width: 36px; height: 36px; border-radius: 10px; }

/* ---------- 应用骨架 ---------- */
.app-shell {
  width: 100%; max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--border);
  display: flex; flex-direction: column;
}
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; flex: none;
}
.brand h1 { font-family: var(--font-title); font-size: 20px; color: var(--primary); }
.brand-sub { font-size: 12px; color: var(--muted); }
#mainContent { flex: 1; padding: 18px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }

.summary-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px;
  display: flex; align-items: center; justify-content: space-around;
}
.summary-item { display: flex; flex-direction: column; gap: 4px; text-align: center; }
.summary-label { font-size: 13px; color: var(--muted); }
.summary-value { font-size: 24px; color: var(--primary); font-variant-numeric: tabular-nums; }
.summary-divider { width: 1px; height: 38px; background: var(--border); }

.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 22px 2px 12px;
}
.section-head h2 { font-size: 17px; font-weight: 700; }
.count-badge {
  background: var(--surface-soft); color: var(--primary);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700;
}

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px;
}
.row-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.row-name { font-weight: 700; font-size: 16px; word-break: break-word; }
.row-amount { font-weight: 800; color: var(--primary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border);
}
.row-price { color: var(--muted); font-size: 14px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn {
  width: 40px; height: 40px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-soft);
  color: var(--primary); font-size: 22px; line-height: 1;
  display: grid; place-items: center;
}
.step-btn:active { transform: translateY(1px); }
.qty-input {
  width: 56px; height: 40px; text-align: center;
  border: 1px solid var(--border); border-radius: 11px;
  background: #fff; color: var(--text); font-size: 16px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.product-row { display: flex; align-items: center; gap: 10px; }
.product-info { flex: 1; min-width: 0; }
.product-name { font-weight: 700; word-break: break-word; }
.product-meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.row-actions { display: flex; gap: 6px; flex: none; }

.history-toggle {
  width: 100%; background: none; border: 0; text-align: left;
  display: flex; align-items: center; gap: 10px; padding: 0; color: inherit;
}
.history-main { flex: 1; min-width: 0; }
.history-no { font-size: 13px; color: var(--muted); }
.history-total { font-size: 20px; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.history-detail { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.detail-line {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 14px; padding: 4px 0; color: var(--muted);
}
.detail-line strong { color: var(--text); font-variant-numeric: tabular-nums; }
.history-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

.empty-state {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7;
}

.sticky-action {
  position: sticky;
  bottom: calc(var(--tabbar-h) + 8px + env(safe-area-inset-bottom));
  z-index: 15;
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(42, 28, 20, .10);
  padding: 12px;
  display: flex; align-items: center; gap: 12px;
}
.sticky-sum { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sticky-sum span { font-size: 12px; color: var(--muted); }
.sticky-sum strong { font-size: 22px; color: var(--primary); font-variant-numeric: tabular-nums; }
.sticky-action .btn { min-width: 132px; }

.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; z-index: 30;
  width: 100%; max-width: 560px;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.tab {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600;
}
.tab .icon { width: 21px; height: 21px; }
.tab.is-active { color: var(--primary); }
.tab.is-active .icon { stroke-width: 2.2; }

/* ---------- 弹层 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(24, 16, 12, .42); }
.modal-panel {
  position: relative; width: 100%; max-width: 560px;
  max-height: 90dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
}
.modal-panel h2 { font-family: var(--font-title); font-size: 21px; color: var(--primary); margin-bottom: 18px; }
.modal-panel .field-label { margin-top: 14px; }
.modal-panel .field-label:first-of-type { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.modal-panel-sm { max-width: 420px; border-radius: 20px; margin-bottom: 24px; }
.confirm-message { color: var(--muted); font-size: 14px; line-height: 1.7; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom));
  z-index: 120; max-width: calc(100% - 40px);
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 12px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

/* ---------- 响应式 ---------- */
@media (min-width: 768px) {
  .app-shell { max-width: 640px; }
  .tabbar { max-width: 640px; }
  .modal-panel { max-width: 640px; border-radius: 20px; margin-bottom: 24px; }
}
@media (min-width: 1280px) {
  .app-shell { max-width: 720px; margin: 24px auto; border-radius: 22px; overflow: hidden; }
  .tabbar { max-width: 720px; bottom: 24px; border-radius: 0 0 22px 22px; }
  .login-screen { background: radial-gradient(circle at 50% 0%, #F1E5D8, var(--bg) 60%); }
}
@media (max-width: 359px) {
  .summary-value { font-size: 21px; }
  .sticky-action .btn { min-width: 112px; padding: 8px 10px; }
  .qty-input { width: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
