:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e6eaf0;
  --text: #16202e;
  --muted: #6b7787;
  --primary: #2563eb;
  --primary-weak: #eaf1ff;
  --green: #16a34a;
  --green-weak: #e8f7ee;
  --orange: #ea580c;
  --red: #dc2626;
  --red-weak: #fdeaea;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

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

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

a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }

.wrap { max-width: 720px; margin: 0 auto; padding: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.row { display: flex; gap: 10px; }
.row.between { justify-content: space-between; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }

/* header */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .title { font-size: 17px; font-weight: 600; }
.topbar .wrap { padding: 0; }

/* buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
}
.btn:active { opacity: .7; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: #fff; border-color: #f3c3c3; color: var(--red); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; min-height: 34px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* form */
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-weak); border-color: var(--primary); }

/* list */
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.item .thumb {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 8px; background: #f0f3f7;
  object-fit: cover; border: 1px solid var(--line);
}
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 600; font-size: 15px; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: #f0f3f7; color: var(--muted);
}
.tag.in { background: var(--green-weak); color: var(--green); }
.tag.out { background: #f1f3f6; color: var(--muted); }
.tag.admin { background: var(--primary-weak); color: var(--primary); }

/* stats */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; z-index: 30; padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; text-align: center; padding: 8px 0 10px;
  color: var(--muted); font-size: 12px;
}
.nav a.active { color: var(--primary); }
.nav a .ic { display: block; font-size: 19px; line-height: 1.2; }

/* tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 14px; font-size: 14px; white-space: nowrap; color: var(--text);
}
.tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* scanner */
#scanVideo { width: 100%; border-radius: 10px; background: #000; }
.scanbox { position: relative; }
.scanline {
  position: absolute; left: 10%; right: 10%; top: 40%; height: 2px;
  background: var(--primary); box-shadow: 0 0 8px var(--primary);
}

/* table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }

.err { background: var(--red-weak); color: var(--red); padding: 10px; border-radius: 10px; font-size: 14px; }
.ok { background: var(--green-weak); color: var(--green); padding: 10px; border-radius: 10px; font-size: 14px; }

/* labels print */
.sheet { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.label {
  border: 1px dashed #b9c2cf; border-radius: 8px; padding: 8px; text-align: center; background: #fff;
}
.label img { width: 100%; max-width: 130px; }
.label .c { font-weight: 700; font-size: 13px; letter-spacing: .5px; }
.label .d { font-size: 11px; color: var(--muted); }

@media print {
  body { background: #fff; padding: 0; }
  .topbar, .nav, .noprint { display: none !important; }
  .card { border: none; box-shadow: none; padding: 0; }
  .sheet { grid-template-columns: repeat(3, 1fr); }
  .label { page-break-inside: avoid; }
}

.img-preview { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); margin-top: 8px; }

.qr-box { text-align: center; padding: 10px; }
.qr-box img { width: 190px; max-width: 80%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
