:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 6px 20px rgba(15, 23, 42, .04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { 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", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }

.app-header {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: #fff;
  padding: 12px 16px;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  box-shadow: 0 2px 10px rgba(30, 64, 175, .25);
}
.app-header h1 { font-size: 16px; margin: 0; font-weight: 600; }
.app-header .hd-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.app-header .sub { font-size: 11px; opacity: .85; font-weight: 400; display: block; margin-top: 2px; }
.app-header a, .app-header button {
  color: #fff; font-size: 13px; background: rgba(255,255,255,.16);
  border: 0; padding: 7px 12px; border-radius: 999px; cursor: pointer;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(24px + var(--safe-b)); }
.wrap.wide { max-width: 1080px; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .dot { width: 6px; height: 16px; border-radius: 3px; background: var(--primary); }

.muted { color: var(--text-3); font-size: 12.5px; }
.hint { color: var(--text-2); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  background: #e2e8f0; color: var(--text);
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: var(--text-2); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 17px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.field label .u { color: var(--text-3); font-weight: 400; }
.field input, .field select, .field textarea, input.input, select.input, textarea.input {
  width: 100%; padding: 12px 13px; font-size: 16px; /* 16px 防止 iOS 聚焦缩放 */
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.student-card {
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
  border: 1px solid #dbeafe;
}
.student-card .sc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.student-card .sc-name { font-size: 20px; font-weight: 700; }
.student-card .kv { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 10px; font-size: 13.5px; }
.student-card .kv .k { color: var(--text-3); }
.student-card .kv .v { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--success-soft); color: #15803d; }
.badge.pending { background: var(--warn-soft); color: #b45309; }
.badge.gray { background: #e2e8f0; color: var(--text-2); }
.badge.male { background: #dbeafe; color: #1d4ed8; }
.badge.female { background: #fce7f3; color: #be185d; }

#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #0f172a; }
#reader video { display: block; width: 100% !important; height: auto !important; }
.scan-box { position: relative; }
.scan-overlay {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.scan-overlay .line {
  position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: rgba(37, 99, 235, .9); box-shadow: 0 0 12px rgba(37,99,235,.8);
  animation: scanmove 2.2s ease-in-out infinite;
}
@keyframes scanmove { 0%,100% { transform: translateY(-70px);} 50% { transform: translateY(70px);} }
.scan-overlay .corner { position: absolute; width: 34px; height: 34px; border: 3px solid #60a5fa; }
.scan-overlay .corner.tl { top: 14%; left: 6%; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.scan-overlay .corner.tr { top: 14%; right: 6%; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.scan-overlay .corner.bl { bottom: 14%; left: 6%; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.scan-overlay .corner.br { bottom: 14%; right: 6%; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(15, 23, 42, .92); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-size: 14px; z-index: 999; max-width: 90vw; text-align: center;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.err { background: rgba(185, 28, 28, .95); }
.toast.ok { background: rgba(21, 128, 61, .95); }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; display: flex; align-items: center; gap: 10px; cursor: pointer; background: #fff;
}
.list li:active { background: #f8fafc; }
.list li .li-main { flex: 1; min-width: 0; }
.list li .li-title { font-weight: 600; }
.list li .li-sub { font-size: 12.5px; color: var(--text-3); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--text-2); font-weight: 600; font-size: 12.5px; position: sticky; top: 0; }
.table-scroll { overflow: auto; max-height: 62vh; border: 1px solid var(--border); border-radius: var(--radius-sm); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tabs button {
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; font-size: 14px; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }
.stat .n { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat .l { font-size: 12.5px; color: var(--text-3); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  background: #eef2f7; font-size: 12.5px; color: var(--text-2); margin: 0 6px 6px 0; }
.chip button { border: 0; background: transparent; color: var(--danger); cursor: pointer; font-size: 14px; }

.field-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.field-row .fr-main { flex: 1; min-width: 0; }
.field-row .fr-main b { font-size: 14px; }
.field-row .fr-main .m { font-size: 12px; color: var(--text-3); }

.notice { padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); color: #92400e; }
.notice.err { background: var(--danger-soft); color: #991b1b; }
.notice.info { background: var(--primary-soft); color: #1e40af; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); }

/* 操作员登录遮罩 */
.login-mask {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.login-mask.hidden { display: none; }
.login-card {
  width: 100%; max-width: 360px; background: #fff; border-radius: 18px;
  padding: 24px; box-shadow: 0 20px 60px rgba(15,23,42,.3);
}
.login-card h2 { font-size: 18px; font-weight: 700; }

/* 通用弹窗（管理端新增/编辑） */
.modal-mask {
  position: fixed; inset: 0; z-index: 200; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(3px);
}
.modal-mask.hidden { display: none; }
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 20px 60px rgba(15,23,42,.3);
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .btn-row { margin-top: 16px; }

/* 可搜索下拉（操作员登录） */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40;
  max-height: 220px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgba(15, 23, 42, .16);
}
.combo-list.hidden { display: none; }
.combo-list li { padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.combo-list li:hover { background: var(--primary-soft); color: var(--primary-dark); }
.combo-list li.combo-empty { color: var(--text-3); cursor: default; }
.combo-list li.combo-empty:hover { background: transparent; color: var(--text-3); }

/* 字段拖拽排序手柄 */
.drag-handle {
  flex: none; cursor: grab; user-select: none; padding: 4px 2px;
  color: var(--text-3); font-size: 18px; line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.field-row.dragging { opacity: .45; }
.field-row.over { background: var(--primary-soft); border-radius: 8px; }

/* 字段行内多列布局 */
.fr-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fr-groups { margin-top: 6px; align-items: center; }

/* 分组小标签 */
.grp-chip {
  display: inline-flex; align-items: center; padding: 2px 8px; margin: 2px 4px 2px 0;
  background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px;
  font-size: 12px; line-height: 1.6;
}

/* ============ 可搜索多选下拉 ============ */
.ms { position: relative; width: 100%; }
.ms-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  min-height: 40px; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; cursor: text;
}
.ms-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ms-chips { display: contents; }
.ms-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 10px; background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 999px; font-size: 13px; line-height: 1.6;
}
.ms-x {
  cursor: pointer; font-weight: 700; color: var(--primary-dark); opacity: .7;
  padding: 0 4px; border-radius: 50%;
}
.ms-x:hover { opacity: 1; background: rgba(37,99,235,.15); }
.ms-input {
  flex: 1; min-width: 140px; border: none; outline: none;
  padding: 4px; font-size: 14px; background: transparent;
}
.ms-drop {
  position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 240px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.ms-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
  font-size: 14px;
}
.ms-opt:hover { background: var(--bg); }
.ms-opt.on { background: var(--primary-soft); color: var(--primary-dark); }
.ms-cb {
  width: 16px; height: 16px; border: 1.5px solid var(--border); border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--primary-dark); flex: none;
}
.ms-opt.on .ms-cb { background: var(--primary); border-color: var(--primary); color: #fff; }
.ms-empty { padding: 10px 12px; color: var(--text-3); font-size: 13px; }
