:root {
  --primary: #2f6fed;
  --primary-d: #2257c4;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8b93a7;
  --ok: #18a058;
  --warn: #f0a020;
  --err: #e54d42;
  --line: #e6e9f0;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
}

.view { display: none; padding: 16px; padding-bottom: 90px; }
.view.active { display: block; }

/* 登录门 */
.login-card {
  margin-top: 18vh;
  background: var(--card);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: 0 10px 30px rgba(30, 50, 100, 0.08);
}
.brand { text-align: center; margin-bottom: 22px; }
.brand-logo {
  width: 56px; height: 56px; line-height: 56px; margin: 0 auto 12px;
  background: var(--primary); color: #fff; border-radius: 16px; font-size: 26px; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; }

form label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; background: #fbfcfe; color: var(--text); outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
.tip { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 按钮 */
.btn {
  border: none; border-radius: 10px; padding: 12px 16px; font-size: 15px; cursor: pointer;
  background: #eef1f6; color: var(--text); transition: .15s;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-outline { background: #fff; border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--err); color: #fff; }
.error { color: var(--err); font-size: 13px; margin-top: 12px; }
.hidden { display: none !important; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin: -16px -16px 16px; padding: 14px 16px; background: var(--card);
  box-shadow: 0 1px 0 var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 首页 */
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.home-action {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 16px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
}
.home-action:active { border-color: var(--primary); }
.ha-icon { font-size: 30px; }
.ha-label { font-size: 16px; font-weight: 600; }
.ha-desc { font-size: 12px; color: var(--muted); }

.stat-row { display: flex; gap: 12px; }
.stat { flex: 1; background: var(--card); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 扫码 */
.scan-tools { margin-bottom: 14px; }
.scan-tools-row { display: flex; gap: 8px; margin-top: 10px; }
.scan-tools-row .btn { flex: 1; }

.buffer { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.buffer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px;
}
.buffer-list { max-height: 52vh; overflow-y: auto; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.buf-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.buf-item .bi-main { flex: 1; min-width: 0; }
.buf-code { font-weight: 600; font-size: 14px; word-break: break-all; }
.buf-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.buf-sys { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: #eef3ff; color: var(--primary); margin-right: 6px; }
.buf-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.buf-status { font-size: 12px; padding: 3px 8px; border-radius: 8px; border: none; background: #f0f2f6; }
.buf-remove { font-size: 12px; color: var(--err); background: none; border: none; cursor: pointer; }

.submit-bar { position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; padding: 12px 16px; background: var(--bg); z-index: 4; }

/* 覆盖层 / 摄像头 */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#camera-video { width: 100%; max-width: 520px; object-fit: cover; }
#camera-canvas { display: none; }
.scan-frame {
  position: absolute; width: 70%; max-width: 320px; height: 180px;
  border: 2px solid var(--primary); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,.4);
}
.overlay-bar {
  position: absolute; bottom: 28px; display: flex; gap: 12px; align-items: flex-end; color: #fff;
  padding: 0 16px; width: 100%; max-width: 520px; justify-content: space-between;
}
.overlay-bar .muted { color: #cfd6e4; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; max-width: 58%; }
.overlay-actions .btn { white-space: nowrap; }
.debug { font-size: 10px; color: #9aa3b2; margin-top: 4px; line-height: 1.3; max-width: 180px; word-break: break-all; }

.sheet { background: #fff; border-radius: 16px; padding: 20px; width: 86%; max-width: 360px; }
.sheet-title { font-weight: 600; margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }

/* 记录 */
.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.input-sm { padding: 8px 10px; font-size: 13px; }
.records-list { display: flex; flex-direction: column; gap: 10px; }
.rec-card { background: var(--card); border-radius: 12px; padding: 14px; border: 1px solid var(--line); }
.rec-line { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; }
.rec-code { font-weight: 600; }
.rec-note { font-size: 12px; color: var(--muted); margin-top: 4px; }

.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; }
.tag-已盘 { background: #e6f7ee; color: var(--ok); }
.tag-异常 { background: #fdecea; color: var(--err); }
.tag-待复核 { background: #fff4e0; color: var(--warn); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(20,24,34,.9); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 99; max-width: 80%; text-align: center;
}
