* { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 属性优先级最高，防止被其他 display 规则覆盖 */
[hidden] { display: none !important; }

:root {
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --in: #059669;
  --in-bg: #ecfdf5;
  --in-border: #a7f3d0;
  --out: #d97706;
  --out-bg: #fffbeb;
  --out-border: #fde68a;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --text-2: #6b7280;
  --line: #e5e7eb;
  --radius: 16px;
  --sheet-ease: cubic-bezier(.32, .72, 0, 1);
  --tabbar-h: 60px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }

button {
  font-family: inherit;
  touch-action: manipulation;              /* 防止移动端双击缩放吞掉点击 */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  cursor: pointer;
}
input { font-family: inherit; }

b { font-variant-numeric: tabular-nums; }

/* ================= 顶栏 ================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 620px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(79, 70, 229, .3);
}
.brand-icon svg { width: 19px; height: 19px; }
.topbar h1 { font-size: 18px; font-weight: 700; letter-spacing: .5px; }

/* ================= 内容区 ================= */
.content {
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px);
}

.page { display: none; }
.page.active { display: block; animation: pageIn .28s var(--sheet-ease); }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---- 统计条 ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04);
  animation: pageIn .4s var(--sheet-ease) backwards;
}
.stat:nth-child(2) { animation-delay: .05s; }
.stat:nth-child(3) { animation-delay: .1s; }
.stat b {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}
.stat span { font-size: 12px; color: var(--text-2); }
.stat b.alert { color: var(--danger); }

/* ---- 搜索 ---- */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  translate: 0 -50%;
  width: 17px;
  height: 17px;
  color: var(--text-2);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 12px 16px 12px 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 16px;               /* ≥16px 避免 iOS 聚焦放大 */
  background: var(--card);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
  appearance: none;
}
#search:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---- 物品列表 ---- */
.item-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.item-row {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04);
  animation: rowIn .34s var(--sheet-ease) backwards;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.item-row.flash-in  { animation: flashIn 1s ease-out; }
.item-row.flash-out { animation: flashOut 1s ease-out; }
@keyframes flashIn  { 0%, 35% { background: var(--in-bg); } 100% { background: var(--card); } }
@keyframes flashOut { 0%, 35% { background: var(--out-bg); } 100% { background: var(--card); } }

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.item-name {
  font-size: 15px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-stock {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.item-stock.s-zero { color: var(--danger); }
.item-stock.s-low  { color: var(--out); }
.item-stock.bump-up  { animation: bumpUp .5s var(--sheet-ease); }
.item-stock.bump-down { animation: bumpDown .5s var(--sheet-ease); }
@keyframes bumpUp {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.4); color: var(--in); }
  100% { transform: scale(1); }
}
@keyframes bumpDown {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.4); color: var(--out); }
  100% { transform: scale(1); }
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.act {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform .12s ease, background .15s;
}
.act:active { transform: scale(.94); }
.act.in  { flex: 1; color: var(--in);  background: var(--in-bg);  border-color: var(--in-border); }
.act.out { flex: 1; color: var(--out); background: var(--out-bg); border-color: var(--out-border); }
.act.edit,
.act.del {
  width: 40px;
  flex: 0 0 40px;
  color: #9ca3af;
  background: #f9fafb;
}
.act.edit:active { color: var(--primary); background: #eef2ff; }
.act.edit svg,
.act.del svg { width: 17px; height: 17px; }
.act.del:active { color: var(--danger); background: var(--danger-bg); }

/* ---- 骨架屏 ---- */
.skeleton {
  height: 96px;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, #eee 25%, #f7f7f8 45%, #eee 65%) #eee;
  background-size: 400px 100%;
  animation: shimmer 1.1s infinite linear;
}
@keyframes shimmer {
  from { background-position: -200px 0; }
  to   { background-position: 200px 0; }
}

/* ---- 记录筛选 chips ---- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  transition: transform .12s ease, background .2s, color .2s, border-color .2s;
}
.chip:active { transform: scale(.93); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ---- 记录列表 ---- */
.rec-day {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin: 18px 4px 8px;
}
.rec-day:first-child { margin-top: 4px; }
.rec-list { list-style: none; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(17,24,39,.04); }
.rec {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #f3f4f6;
  animation: rowIn .3s var(--sheet-ease) backwards;
  animation-delay: calc(var(--i, 0) * 30ms);
}
.rec:last-child { border-bottom: none; }
.rec-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  flex-shrink: 0;
}
.rec-icon.in  { color: var(--in);  background: var(--in-bg); }
.rec-icon.out { color: var(--out); background: var(--out-bg); }
.rec-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rec-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-time { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.rec-qty {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.rec-qty.in  { color: var(--in); }
.rec-qty.out { color: var(--out); }

/* ---- 空状态 ---- */
.empty { text-align: center; padding: 56px 20px 30px; animation: pageIn .3s var(--sheet-ease); }
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 600; }
.empty-hint { font-size: 13px; color: var(--text-2); margin-top: 6px; }
.empty-hint b { color: var(--primary); }

/* ================= 悬浮按钮 FAB ================= */
.fab {
  position: fixed;
  right: max(20px, calc((100vw - 620px) / 2));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  z-index: 30;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(79, 70, 229, .4);
  transition: transform .25s var(--sheet-ease), opacity .25s;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.9); }
.fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* ================= 底部标签栏 ================= */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner {
  max-width: 620px;
  margin: 0 auto;
  height: var(--tabbar-h);
  display: flex;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #9ca3af;
  font-size: 11px;
  font-weight: 500;
  transition: color .2s, transform .15s;
}
.tab-btn svg { width: 23px; height: 23px; transition: transform .25s var(--sheet-ease); }
.tab-btn:active { transform: scale(.92); }
.tab-btn.active { color: var(--primary); font-weight: 600; }
.tab-btn.active svg { transform: translateY(-1.5px) scale(1.08); }

/* ================= 弹层（底部抽屉） ================= */
.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  opacity: 0;
  transition: opacity .3s ease;
}
.sheet-layer.open .overlay { opacity: 1; }

.sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  translate: -50% 0;
  width: min(100%, 480px);
  max-height: 86dvh;
  overflow-y: auto;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  transition: transform .36s var(--sheet-ease);
  display: none;
}
.sheet.current { display: block; }
.sheet-layer.open .sheet.current { transform: none; }

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: #d1d5db;
  margin: 4px auto 14px;
}
.sheet-title { font-size: 18px; font-weight: 700; text-align: center; }
.sheet .field { margin-top: 18px; }

.field input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  font-size: 16px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  background: #fafafa;
}
.field input:focus { border-color: var(--primary-2); background: #fff; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.field-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  animation: shake .35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.move-item { text-align: center; color: var(--text); font-size: 15px; font-weight: 600; margin-top: 14px; }
.move-stock { text-align: center; color: var(--text-2); font-size: 13px; margin-top: 4px; }
.move-stock b { color: var(--text); }

/* 数量输入：− 输入 ＋ */
.qty-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 16px;
}
.qty-step {
  width: 52px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fafafa;
  font-size: 22px;
  color: var(--text-2);
  transition: transform .12s ease, background .15s, color .15s;
}
.qty-step:active { transform: scale(.9); background: #f3f4f6; color: var(--text); }
#move-qty {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: #fafafa;
  transition: border-color .2s, box-shadow .2s;
}
#move-qty:focus { border-color: var(--primary-2); background: #fff; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
#move-qty::-webkit-outer-spin-button,
#move-qty::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#move-qty { -moz-appearance: textfield; appearance: textfield; }

.quick-qty { display: flex; gap: 8px; margin-top: 10px; }
.quick-qty button {
  flex: 1;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  transition: transform .12s ease, background .15s, color .15s, border-color .15s;
}
.quick-qty button:active { transform: scale(.9); }
.quick-qty button.active { background: var(--in-bg); border-color: var(--in-border); color: var(--in); }

/* ---- 按钮 ---- */
.btn-block {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform .12s ease, opacity .2s, background .2s;
}
.btn-block:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; margin-top: 18px; box-shadow: 0 6px 16px rgba(79,70,229,.3); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 16px rgba(220,38,38,.25); }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.confirm-actions .btn-block { margin-top: 0; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn-ghost.loading::after { border-color: rgba(17,24,39,.15); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

.confirm-text {
  text-align: center;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  margin-top: 14px;
  padding: 0 8px;
}
.confirm-text b { color: var(--text); }

/* ================= Toast ================= */
.toast {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  z-index: 60;
  translate: -50% -140%;
  background: #111827;
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  max-width: calc(100vw - 40px);
  text-align: center;
  box-shadow: 0 10px 26px rgba(17, 24, 39, .3);
  transition: translate .38s var(--sheet-ease);
  pointer-events: none;
}
.toast.show { translate: -50% 0; }
.toast.toast-error { background: var(--danger); }

/* ================= 桌面端适配 ================= */
@media (min-width: 640px) {
  .content { padding-left: 0; padding-right: 0; }
  .sheet { border-radius: 22px; margin-bottom: 24px; transition: transform .36s var(--sheet-ease), opacity .3s; opacity: 0; }
  .sheet-layer.open .sheet.current { opacity: 1; }
  .sheet { bottom: auto; top: 50%; translate: -50% -30%; }
  .sheet-layer.open .sheet.current { translate: -50% -50%; }
  .sheet-handle { display: none; }
  .sheet-layer { display: flex; align-items: center; justify-content: center; }
}

/* ================= 动画减弱 ================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
