:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --danger: #dc2626;
  --warn-bg: #fef2f2;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --tabbar-h: 58px;
}

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

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

button { font-family: inherit; }

[hidden] { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-logo { font-size: 52px; }
.login-wrap h1 { font-size: 22px; margin: 8px 0 20px; color: var(--primary-dark); }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card .hint { min-height: 1.2em; margin: 0; }

/* ---------- 通用卡片 / 表单 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h2 .sub { font-size: 12px; font-weight: 400; color: var(--text-2); margin-left: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; color: var(--text-2); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* 防 iOS 聚焦缩放 */
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.hint { font-size: 12px; color: var(--text-2); }

.row { display: flex; gap: 8px; align-items: center; }
.row .field { flex: 1; margin-bottom: 0; }

/* ---------- 按钮 ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  min-height: 44px;
  cursor: pointer;
  transition: filter .15s;
}
.btn:active { filter: brightness(.9); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-outline { background: #fff; color: var(--primary-dark); border: 1px solid var(--primary); }
.btn-danger-outline { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 顶栏 / 底部导航 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-user {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#main {
  padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 0 6px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
}
.tab-btn .ico { font-size: 20px; line-height: 1; }
.tab-btn.active { color: var(--primary); font-weight: 600; }

/* ---------- 总览统计 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(15,23,42,.06);
}
.stat .num { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.stat .lbl { font-size: 12px; color: var(--text-2); }

/* ---------- 列表行 ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.list-sub { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.list-actions { display: flex; gap: 6px; flex-shrink: 0; }

.qty-big { font-size: 17px; font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
.qty-zero { color: var(--text-2); font-weight: 400; }

.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.badge-low { background: var(--warn-bg); color: var(--danger); border: 1px solid #fecaca; }
.badge-muted { background: var(--bg); color: var(--text-2); }
.badge-durable { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.badge-consume { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }

.empty { text-align: center; color: var(--text-2); padding: 26px 0; font-size: 14px; }

/* ---------- 流水 ---------- */
.tx-row { display: flex; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--border); }
.tx-row:last-child { border-bottom: none; }
.tx-badge {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.tx-in { background: #ecfdf5; }
.tx-consume { background: #fff7ed; }
.tx-transfer { background: #eff6ff; }
.tx-main { flex: 1; min-width: 0; }
.tx-line { font-size: 14px; }
.tx-line b { font-weight: 600; }
.tx-meta { font-size: 12px; color: var(--text-2); }
.tx-time { font-size: 12px; color: var(--text-2); white-space: nowrap; }

/* ---------- 场所 chips ---------- */
.loc-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  min-height: 38px;
  cursor: pointer;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slide-up .18s ease-out;
}
@keyframes slide-up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  border: none; background: var(--bg);
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 14px; cursor: pointer; color: var(--text-2);
}
.modal-body { padding: 16px; overflow-y: auto; }
.modal-body .field input, .modal-body .field select { font-size: 16px; }

.op-row { display: grid; grid-template-columns: 1fr 96px 34px; gap: 8px; margin-bottom: 10px; align-items: start; }
.op-row select { min-height: 44px; }
.op-row input { min-height: 44px; }
.op-remove {
  height: 44px;
  border: none;
  background: var(--warn-bg);
  color: var(--danger);
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
}

.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }
.add-line-btn {
  width: 100%;
  border: 1px dashed var(--border);
  background: none;
  color: var(--primary);
  border-radius: 10px;
  min-height: 40px;
  margin-bottom: 12px;
  font-size: 14px;
  cursor: pointer;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(15, 23, 42, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 86vw;
  text-align: center;
  animation: fade-in .15s ease-out;
}
#toast.toast-error { background: rgba(220, 38, 38, .95); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 筛选条（物料场景 / 属性） ---------- */
/* 复用 .chip / .chip.active 组件，仅在此上下文收紧密度以容纳两排 */
.filter-bar { margin-bottom: 12px; }
.filter-lbl {
  font-size: 11px;
  color: var(--text-2);
  margin: 0 0 5px 2px;
}
.filter-group { margin-top: 9px; }
.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-row .chip {
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13px;
}
.filter-count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 9px;
  min-height: 18px;
}
.filter-count b { color: var(--primary-dark); }
.clear-link {
  color: var(--text-2);
  text-decoration: underline;
  cursor: pointer;
  white-space: nowrap;
}
.filter-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  margin-bottom: 10px;
}

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.pager-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  min-height: 34px;
}
.pager-btn:disabled { opacity: .4; cursor: default; }
.pager-info {
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.pager-info b { color: var(--text); }

/* ---------- 库存页：场所行 + 批量入口 ---------- */
.loc-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 10px;
}
.loc-bar .loc-chips { padding: 0; flex: 1; }
.batch-btn {
  flex-shrink: 0;
  border: 1px solid var(--primary);
  background: #fff;
  color: var(--primary-dark);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  min-height: 38px;
}

/* ---------- 批量导入：上传区与预览 ---------- */
.drop-zone {
  display: block;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  background: #fbfdfe;
  cursor: pointer;
}
.drop-zone .ico { font-size: 28px; }
.drop-zone .t { font-size: 14px; margin-top: 6px; }
.drop-zone .s { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.drop-zone.picked {
  border-style: solid;
  border-color: var(--primary);
  background: var(--primary-light);
  cursor: default;
}
.preview-sum { display: flex; gap: 8px; margin: 12px 0; }
.sum-cell {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sum-cell .n {
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sum-cell .l { font-size: 11px; color: var(--text-2); margin-top: 1px; }
.sum-cell.in .n { color: var(--primary-dark); }
.sum-cell.out .n { color: #c2410c; }

.prev-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prev-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.prev-table td { padding: 7px 4px; border-bottom: 1px solid #f1f5f9; }
.prev-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.prev-table .plus { color: var(--primary-dark); font-weight: 600; }
.prev-table .minus { color: #c2410c; font-weight: 600; }
.prev-table tr.newmat td:first-child::after {
  content: "新";
  font-size: 10px;
  margin-left: 4px;
  padding: 0 4px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 4px;
  vertical-align: 1px;
}

.alert {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  margin: 10px 0;
}
.alert-info { background: #f0f9ff; color: #075985; }
.alert-warn { background: var(--warn-bg); color: #991b1b; white-space: pre-line; }
.alert-line { display: block; margin-top: 4px; }

/* ---------- 桌面适配 ---------- */
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 18px; }
}
