:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c1f24;
  --muted: #8a919c;
  --line: #eceef1;
  --accent: #f97316;
  --accent-soft: #fff1e6;
  --green: #16a34a;
  --green-soft: #e9f9ef;
  --red: #dc2626;
  --red-soft: #fdecec;
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, textarea { font-family: inherit; font-size: 15px; border: none; outline: none; background: none; color: inherit; }
.hidden { display: none !important; }

/* 顶部 */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px; background: var(--bg);
}
#topbar h1 { font-size: 22px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-nick {
  height: 36px; max-width: 42%; padding: 0 12px; border-radius: 999px; background: var(--card);
  font-size: 13px; font-weight: 600; color: var(--ink); flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); display: flex; align-items: center; gap: 4px;
}
#btn-nick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-refresh {
  width: 36px; height: 36px; border-radius: 50%; background: var(--card);
  font-size: 18px; color: var(--muted); box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
#btn-refresh.spin { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 工具栏 */
.toolbar { padding: 0 16px 10px; display: flex; flex-direction: column; gap: 10px; }
#search {
  width: 100%; height: 42px; border-radius: 12px; background: var(--card);
  padding: 0 14px; box-shadow: 0 1px 4px rgba(0,0,0,.04);
  -webkit-appearance: none;
}
.tabs { display: flex; background: #e9ebef; border-radius: 12px; padding: 3px; gap: 3px; }
.tabs button { flex: 1; height: 34px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs b { font-weight: 600; color: var(--accent); margin-left: 2px; }
.btn-ghost {
  align-self: flex-end; padding: 8px 14px; border-radius: 10px; background: var(--card);
  font-size: 13px; font-weight: 600; color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.05);
}

/* 商品卡片 */
#list { padding: 2px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.p-card {
  background: var(--card); border-radius: var(--radius); padding: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.p-card.out { border-left: 3px solid var(--red); }
.p-top { display: flex; gap: 12px; }
.p-img {
  width: 56px; height: 56px; border-radius: 10px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; overflow: hidden;
}
.p-img img { width: 100%; height: 100%; object-fit: cover; }
.p-info { flex: 1; min-width: 0; }
.p-name { font-size: 16px; font-weight: 600; line-height: 1.3; word-break: break-all; }
.p-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #f1f3f6; color: var(--muted); }
.tag.note { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-qty { text-align: right; flex-shrink: 0; }
.p-qty .n { font-size: 26px; font-weight: 700; line-height: 1; }
.p-qty .n.zero { color: var(--red); }
.p-qty .u { font-size: 11px; color: var(--muted); margin-top: 3px; }
.p-btns { display: flex; gap: 8px; margin-top: 12px; }
.p-btn {
  flex: 1; height: 44px; border-radius: 12px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.p-btn.sell { background: var(--red-soft); color: var(--red); }
.p-btn.sell:disabled { opacity: .35; }
.p-btn.ret { background: var(--accent-soft); color: var(--accent); }
.p-btn.restock { background: var(--green-soft); color: var(--green); }
.p-btn:active { opacity: .7; }

/* 空状态 */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty .btn-primary { margin-top: 16px; }

/* 流水 */
#logs { padding: 2px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.l-item {
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.l-badge {
  min-width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; padding: 0 6px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
}
.l-badge.in { background: var(--green-soft); color: var(--green); }
.l-badge.out { background: var(--red-soft); color: var(--red); }
.l-badge.ret { background: #e8f0fe; color: #2563eb; }
.l-badge.other { background: #f1f3f6; color: var(--muted); font-size: 12px; }
.l-main { flex: 1; min-width: 0; }
.l-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.l-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.l-time { font-size: 11px; color: var(--muted); flex-shrink: 0; text-align: right; }

/* 表单 */
#view-form { padding-bottom: 30px; }
.form-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px;
  position: sticky; top: 0; background: var(--bg); z-index: 20;
}
.form-head h2 { flex: 1; font-size: 20px; }
#btn-back {
  width: 36px; height: 36px; border-radius: 50%; background: var(--card);
  font-size: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.btn-danger-text { color: var(--red); font-size: 14px; font-weight: 600; }
.form-body { padding: 4px 16px; display: flex; flex-direction: column; gap: 18px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field label i { color: var(--red); font-style: normal; }
.field input[type=text], .field textarea {
  width: 100%; background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.04); resize: none;
}
#img-picker { position: relative; }
.img-add {
  width: 88px; height: 88px; border-radius: 12px; background: var(--card);
  border: 1.5px dashed #d4d8de; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
#img-preview { position: relative; width: 88px; height: 88px; }
#img-preview img { width: 100%; height: 100%; border-radius: 12px; object-fit: cover; }
#img-remove {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1;
}
.qty-stepper { display: flex; align-items: center; gap: 10px; }
.qty-stepper button {
  width: 48px; height: 48px; border-radius: 12px; background: var(--card); font-size: 22px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05); color: var(--ink);
}
#f-qty {
  width: 80px; height: 48px; background: var(--card); border-radius: 12px; text-align: center;
  font-size: 18px; font-weight: 700; box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button {
  padding: 9px 18px; border-radius: 999px; background: var(--card); font-size: 14px;
  color: var(--muted); box-shadow: 0 1px 4px rgba(0,0,0,.04); border: 1.5px solid transparent;
}
.chips button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn-primary {
  background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 20px;
  font-size: 15px; font-weight: 600;
}
.btn-primary:disabled { opacity: .5; }
.btn-big { height: 50px; font-size: 16px; }

/* 底部导航 */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#bottomnav button {
  flex: 1; height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--muted);
}
#bottomnav button.on { color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-add .nav-icon {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 600;
  margin-top: -14px; box-shadow: 0 4px 10px rgba(249,115,22,.4);
}

/* 弹层 */
.modal {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 20px;
  padding: 32px 24px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.1);
}
.modal-icon { font-size: 44px; }
.modal-card h2 { font-size: 22px; margin-top: 10px; }
.modal-sub { font-size: 13px; color: var(--muted); margin: 8px 0 20px; }
.modal-card input {
  width: 100%; height: 48px; border-radius: 12px; background: var(--bg);
  padding: 0 14px; margin-bottom: 10px; text-align: center; font-size: 16px;
}
#pin-enter { width: 100%; height: 48px; margin-top: 4px; }
.pin-error { color: var(--red); font-size: 13px; margin-top: 12px; }

/* 称呼切换弹层 */
.sheet {
  position: fixed; inset: 0; z-index: 55; background: rgba(28,31,36,.4);
  display: flex; align-items: flex-end;
}
.sheet-card {
  width: 100%; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { font-size: 17px; }
#nick-close {
  width: 32px; height: 32px; border-radius: 50%; background: var(--bg);
  font-size: 18px; color: var(--muted); line-height: 1;
}
.sheet-sub { font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
#nick-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.nick-row {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-radius: 12px; background: var(--bg); font-size: 15px; font-weight: 600;
  border: 1.5px solid transparent;
}
.nick-row.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.nick-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nick-check { font-weight: 700; }
.nick-del {
  width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,.06);
  color: var(--muted); font-size: 15px; line-height: 1; flex-shrink: 0;
}
.nick-add-row { display: flex; gap: 8px; }
.nick-add-row input { flex: 1; height: 46px; border-radius: 12px; background: var(--bg); padding: 0 14px; }
.nick-add-row .btn-primary { height: 46px; padding: 0 18px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(28,31,36,.9); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 60; white-space: nowrap;
}
