/* ============================================================
   进销存系统 - 移动端优先样式
   ============================================================ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #e8f7ee;
  --orange: #ea580c;
  --orange-bg: #fdf0e6;
  --red: #dc2626;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --line: #eef0f3;
  --radius: 14px;
  --shadow: 0 1px 4px rgba(16, 24, 40, 0.06);
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  height: 50px; padding: 0 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 17px; font-weight: 600; }
.icon-btn { font-size: 20px; padding: 6px 8px; border-radius: 8px; color: var(--text-2); }

/* ---------- 主区域 ---------- */
.view { max-width: 640px; margin: 0 auto; padding: 12px 12px calc(var(--tabbar-h) + var(--safe-b) + 20px); }
.page { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 底部标签栏 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; max-width: 640px; margin: 0 auto;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-3); gap: 2px;
}
.tab-item em { font-style: normal; font-size: 20px; line-height: 1; }
.tab-item.active { color: var(--primary); font-weight: 600; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 0;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 12px 14px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 18px; border-radius: 10px;
  font-size: 15px; font-weight: 500;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-orange { background: var(--orange); color: #fff; }
.btn-ghost { background: #f1f3f6; color: var(--text-2); }
.btn-danger-ghost { background: #fdecec; color: var(--red); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

/* ---------- 分段控件 ---------- */
.seg {
  display: flex; background: #eef1f5; border-radius: 10px; padding: 3px; margin-bottom: 12px;
}
.seg-item {
  flex: 1; padding: 8px 0; border-radius: 8px; font-size: 14px; color: var(--text-2);
}
.seg-item.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid #e3e7ed; border-radius: 10px;
  background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 64px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-tip { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
  background: linear-gradient(160deg, #eef4ff 0%, #f4f6f9 55%);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-logo {
  width: 88px; height: 88px; margin: 0 auto 14px; border-radius: 20px;
  display: block; object-fit: contain; background: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .10);
}
.login-brand h1 { font-size: 22px; font-weight: 700; }
.login-brand p { color: var(--text-2); font-size: 13px; margin-top: 6px; }
.login-card { padding: 18px 16px; }
.login-hint { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 14px; }

/* ---------- 首页 ---------- */
.welcome { padding: 4px 2px 12px; }
.welcome h2 { font-size: 20px; font-weight: 700; }
.welcome p { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 10px; text-align: center; }
.stat-card .num { font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.stat-card .num.green { color: var(--green); }
.stat-card .num.orange { color: var(--orange); }
.stat-card .lbl { font-size: 12px; color: var(--text-2); }

.quick-row { display: flex; gap: 10px; margin-bottom: 14px; }
.quick-row .btn { flex: 1; padding: 14px 0; font-size: 16px; font-weight: 600; }

/* ---------- 列表 ---------- */
.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 15px; font-weight: 600; }
.list-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-right { text-align: right; flex-shrink: 0; }
.list-num { font-size: 15px; font-weight: 700; }
.list-num.in { color: var(--green); }
.list-num.out { color: var(--orange); }
.list-extra { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stock-label { font-size: 12px; font-weight: 400; color: var(--text-2); }

.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 20px; margin-left: 6px; vertical-align: 1px; }
.tag-in { background: var(--green-bg); color: var(--green); }
.tag-out { background: var(--orange-bg); color: var(--orange); }
.tag-off { background: #f1f3f6; color: var(--text-3); }
.badge { display: inline-block; min-width: 22px; text-align: center; padding: 2px 6px; border-radius: 12px; font-size: 11px; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--text-3); font-size: 13px; }
.empty .empty-icon { font-size: 40px; display: block; margin-bottom: 10px; opacity: .6; }

/* ---------- 底部弹出层 ---------- */
.sheet-mask, #sheet-mask, .confirm-mask, #picker-mask {
  position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, .45);
}
#sheet, #picker {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  max-width: 640px; margin: 0 auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(16px + var(--safe-b));
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .12);
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(60%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: #d8dce3; margin: 8px auto 0; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 4px; font-size: 16px; font-weight: 600;
}
.sheet-close { font-size: 24px; color: var(--text-3); line-height: 1; padding: 4px; }
.sheet-body { padding: 10px 16px 6px; max-height: 74vh; overflow-y: auto; }
.sheet-body .btn { margin-top: 6px; }

/* ---------- 货品选择器 ---------- */
.picker-list { list-style: none; }
.picker-list li {
  padding: 12px 4px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.picker-list li:active { background: #f8fafc; }
.picker-list .p-name { font-size: 15px; font-weight: 500; }
.picker-list .p-sub { font-size: 12px; color: var(--text-2); }
.picker-list .p-stock { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; }

/* ---------- 统计 ---------- */
.stats-ctrl { display: flex; gap: 10px; margin-bottom: 12px; }
.stats-ctrl .seg { flex: 1; margin-bottom: 0; }
.stats-date { width: 150px; }
.chart-card { padding: 10px 8px 4px; }
.chart-card canvas { width: 100%; display: block; }
.totals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.totals-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.totals-card h4 { font-size: 13px; color: var(--text-2); font-weight: 500; margin-bottom: 6px; }
.totals-card .t-num { font-size: 22px; font-weight: 700; }
.totals-card .t-num.green { color: var(--green); }
.totals-card .t-num.orange { color: var(--orange); }
.totals-card .t-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ---------- 表格(统计明细) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-weight: 500; color: var(--text-2);
  padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 12px;
  position: sticky; top: 0; background: var(--card);
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 记录类型标记 ---------- */
.type-pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.type-pill.in { background: var(--green-bg); color: var(--green); }
.type-pill.out { background: var(--orange-bg); color: var(--orange); }

/* ---------- 分页/加载更多 ---------- */
.load-more { text-align: center; padding: 14px 0; color: var(--text-3); font-size: 13px; }
.load-more button { color: var(--primary); font-size: 14px; padding: 6px 16px; }
.load-more button:disabled { color: var(--text-3); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 30px);
  transform: translateX(-50%);
  background: rgba(17, 24, 39, .92); color: #fff;
  padding: 10px 18px; border-radius: 24px; font-size: 14px;
  z-index: 90; max-width: 80vw; text-align: center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 确认框 ---------- */
.confirm-box {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  width: min(300px, 84vw); background: var(--card); border-radius: 16px;
  padding: 22px 18px 14px; text-align: center; z-index: 70;
  animation: fadeIn .15s ease;
}
.confirm-box p { font-size: 15px; margin-bottom: 18px; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btns .btn { flex: 1; }

/* ---------- 我的 ---------- */
.profile-head { display: flex; align-items: center; gap: 12px; padding: 18px 16px; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 22px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.menu-item:last-child { border-bottom: none; }
.menu-item .arrow { color: var(--text-3); }
.about-line { padding: 12px 16px; font-size: 12px; color: var(--text-3); line-height: 1.8; }

/* ---------- 桌面端适配 ---------- */
@media (min-width: 768px) {
  body { background: #e9edf3; }
  .view { padding-top: 18px; }
  #app { max-width: 640px; margin: 0 auto; background: var(--bg); min-height: 100vh; }
}

/* ---------- 数值/单位 ---------- */
.unit-suffix { font-weight: 400; font-size: 12px; color: var(--text-3); }
