:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --border: #e4e9f0;
  --line-soft: #eef2f7;
  --text: #16202f;
  --muted: #6b7789;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 18px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.65 "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 12px 22px; background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff; font-size: 19px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(37, 99, 235, .28);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.sub { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.topmeta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  background: var(--primary-soft); color: #1d4ed8; border-radius: 999px;
  padding: 4px 11px; font-size: 12px; white-space: nowrap; font-weight: 600;
}
.badge-soft { background: #f1f4f8; color: var(--muted); font-weight: 500; }

/* ---------------- 导航 ---------------- */
.tabs {
  display: flex; gap: 2px; padding: 8px 22px 0; background: var(--card);
  border-bottom: 1px solid var(--border); position: sticky; top: 63px; z-index: 25;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; padding: 9px 15px; cursor: pointer; white-space: nowrap;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0;
  font-family: inherit; transition: color .15s, background .15s;
}
.tab:hover { background: #f7f9fc; color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; background: var(--primary-soft); }

main { padding: 18px 22px 64px; max-width: 1440px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { margin-bottom: 14px; }
.card-head h2 {
  margin: 0; font-size: 16px; font-weight: 700;
  padding-left: 10px; border-left: 3px solid var(--primary); line-height: 1.35;
}
.hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; line-height: 1.6; }
.notes {
  color: #475569; font-size: 12.5px; line-height: 1.75;
  background: #f8fafc; border: 1px solid var(--line-soft);
  border-left: 3px solid var(--primary); padding: 10px 12px; border-radius: 8px;
}

/* ---------------- 表单 ---------------- */
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
label.radio, label.check { flex-direction: row; align-items: center; gap: 7px; font-size: 13px; color: var(--text); font-weight: 500; }
input, select {
  padding: 8px 11px; border: 1px solid #d8e0ea; border-radius: 8px;
  font-size: 13.5px; color: var(--text); background: #fff; min-width: 130px;
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: #c3cede; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .13); }
input[type=date], input[type=time] { min-width: 140px; }

/* ---------------- 按钮 ---------------- */
.btn {
  padding: 9px 15px; border: 1px solid #d8e0ea; background: #fff; color: var(--text);
  border-radius: 9px; cursor: pointer; font-size: 13.5px; white-space: nowrap;
  font-family: inherit; font-weight: 500; min-height: 38px;
  transition: background .15s, border-color .15s, box-shadow .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: #f6f8fb; border-color: #c3cede; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); border-color: #1d4ed8; color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .25); font-weight: 600;
}
.btn.primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); }
.btn.danger { background: #fff; border-color: #f4b4b4; color: var(--red); }
.btn.danger:hover { background: #fef2f2; border-color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }
.btn.big { padding: 13px 22px; font-size: 15px; min-height: 48px; border-radius: 11px; }

.tip { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.tip.ok { color: var(--green); font-weight: 600; }
.tip.err { color: var(--red); font-weight: 600; }

.capture-bar, .result-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }

/* ---------------- 摄像头 / 预览 ---------------- */
.camera-wrap { margin-top: 12px; }
.camera-wrap video {
  width: 100%; max-width: 640px; border-radius: 10px; background: #0f172a; display: block;
}
.camera-btns { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }

.preview-wrap { position: relative; margin-top: 12px; display: inline-block; max-width: 100%; }
.preview-wrap canvas {
  max-width: 100%; border-radius: 10px; display: block; border: 1px solid var(--border);
}
.overlay { position: absolute; inset: 0; }
.face-box {
  position: absolute; border: 2px solid #22c55e; border-radius: 5px;
  background: rgba(34, 197, 94, .1); box-shadow: 0 0 0 1px rgba(255, 255, 255, .6);
}
.face-box.temp { border-color: var(--amber); background: rgba(217, 119, 6, .1); }

/* ---------------- 结果卡片 ---------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.fcard {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #fff;
  display: flex; gap: 11px; box-shadow: var(--shadow-sm); transition: box-shadow .15s;
}
.fcard:hover { box-shadow: var(--shadow); }
.fcard.new { border-color: var(--primary); background: #fbfdff; box-shadow: 0 0 0 2px var(--primary-soft); }
.fcard img {
  width: 78px; height: 78px; object-fit: cover; border-radius: 10px;
  background: #f1f5f9; flex: 0 0 78px;
}
.fcard .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.fcard .sid { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fcard .sid small { font-weight: 400; color: var(--muted); font-size: 11px; }
.fcard input, .fcard select { width: 100%; min-width: 0; padding: 6px 9px; font-size: 13px; }
.tag-new { background: #dbeafe; color: #1d4ed8; border-radius: 5px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.tag-hit { background: #dcfce7; color: #15803d; border-radius: 5px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.fc-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.src-tag { font-size: 11.5px; color: var(--muted); margin: 1px 0 3px; }

/* ---------------- 表格 ---------------- */
.table-wrap {
  overflow: auto; max-height: 660px; border: 1px solid var(--border);
  border-radius: 10px; background: #fff;
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
.table th {
  background: #f7f9fc; position: sticky; top: 0; z-index: 2; font-weight: 700;
  color: #475569; white-space: nowrap; font-size: 12.5px;
  box-shadow: 0 1px 0 var(--border);
}
.table tbody tr:hover { background: #fafbfd; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; display: block; }
.table input { width: 100%; min-width: 74px; padding: 5px 8px; }
.table td b { font-size: 13.5px; }

/* ---------------- 课次 ---------------- */
.session-list { display: flex; flex-direction: column; gap: 12px; }
.scard {
  border: 1px solid var(--border); border-radius: 12px; padding: 15px 16px;
  background: #fff; box-shadow: var(--shadow-sm);
}
.scard header { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.scard h3 { margin: 0; font-size: 15px; font-weight: 700; }
.scard .smeta { color: var(--muted); font-size: 12.5px; }
.scard .sbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.scard .records { margin-top: 10px; }

.provider-box {
  border: 1px dashed #cfd8e3; border-radius: 10px; padding: 13px 14px;
  margin-bottom: 12px; background: #fcfdff;
}
.hidden { display: none !important; }
.danger-zone {
  border: 1px solid #fecaca; background: #fff5f5; border-radius: 10px;
  padding: 13px 14px; margin-top: 14px;
}
.danger-zone h3 { margin: 0 0 6px; font-size: 14px; color: var(--red); }
.danger-zone p { margin: 0 0 10px; font-size: 12.5px; color: #7f1d1d; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13.5px; z-index: 99; box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
  max-width: 90vw; text-align: center;
}
.toast-err { background: #b42318; }
code {
  background: #f1f4f8; padding: 2px 6px; border-radius: 5px;
  font-size: 12.5px; word-break: break-all;
}

/* ---------------- 照片队列 ---------------- */
.photo-queue { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 12px; }
.photo-item {
  width: 142px; border: 2px solid #e4e9f0; border-radius: 10px; overflow: hidden;
  background: #fff; position: relative; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.photo-item:hover { border-color: #c3cede; }
.photo-item.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.photo-item img { width: 100%; height: 80px; object-fit: cover; display: block; background: #f1f4f8; }
.photo-meta { padding: 7px 9px 9px; }
.photo-name {
  font-size: 12px; font-weight: 700; color: #334155;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-status { font-size: 11.5px; color: #94a3b8; margin-top: 2px; }
.photo-status.ok { color: #059669; font-weight: 600; }
.photo-status.busy { color: var(--amber); font-weight: 600; }
.photo-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; line-height: 20px; text-align: center;
  border: none; border-radius: 50%; background: rgba(16, 24, 40, .55); color: #fff;
  font-size: 13px; cursor: pointer; padding: 0;
}
.photo-del:hover { background: var(--red); }
.photo-redo {
  position: absolute; right: 28px; top: 4px; width: 22px; height: 22px; line-height: 20px;
  border: none; border-radius: 50%; background: rgba(255, 255, 255, .92); color: #334155;
  font-size: 13px; cursor: pointer; padding: 0; box-shadow: var(--shadow-sm);
}
.photo-redo:hover { background: #fff; color: var(--primary); }

/* ---------------- 诊断面板 ---------------- */
.diag {
  margin-top: 12px; border: 1px solid var(--line-soft); border-radius: 10px;
  padding: 13px 15px; background: #f8fafc;
}
.diag-summary {
  font-size: 13px; line-height: 1.75; padding: 9px 13px; border-radius: 8px;
  margin-bottom: 10px; white-space: pre-wrap;
}
.diag-summary.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.diag-summary.bad { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.diag-row {
  display: flex; align-items: flex-start; gap: 9px; padding: 8px 2px;
  border-top: 1px solid #e8edf3; font-size: 13px; line-height: 1.6;
}
.diag-mark { font-weight: 700; width: 16px; flex: 0 0 16px; text-align: center; }
.diag-row.ok .diag-mark { color: #059669; }
.diag-row.bad .diag-mark { color: var(--red); }
.diag-name { flex: 0 0 132px; color: #334155; font-weight: 600; }
.diag-detail { flex: 1; color: var(--muted); word-break: break-all; }

/* ---------------- 账号管理 ---------------- */
.user-list { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.urow {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding: 11px 13px;
  border: 1px solid var(--line-soft); border-radius: 10px; background: #f8fafc;
}
.urow .smeta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.urow code { background: #eef2f7; padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.ubtns { display: flex; gap: 7px; flex-wrap: wrap; }

/* ---------------- 进度条 ---------------- */
.progress {
  height: 7px; background: #eef2f7; border-radius: 999px;
  overflow: hidden; margin: 10px 0 4px; max-width: 520px;
}
.progress > i {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #0ea5e9); transition: width .25s ease;
}

/* ---------------- 手机端 ---------------- */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 12px 14px; position: static;
  }
  .topmeta { justify-content: flex-start; }
  .tabs { padding: 8px 10px 0; position: static; }
  .tab { padding: 9px 13px; font-size: 13.5px; }
  main { padding: 14px 12px 70px; }
  .card { padding: 15px 14px; border-radius: 12px; }
  .form-row { gap: 10px; }
  .form-row > label { flex: 1 1 100% !important; }
  input, select { width: 100%; min-width: 0; font-size: 16px; }  /* 16px 可避免 iOS 自动放大页面 */
  .btn { min-height: 44px; padding: 10px 15px; font-size: 14px; }
  .btn.sm { min-height: 34px; }
  .btn.big { min-height: 52px; font-size: 16px; }
  .grid { grid-template-columns: 1fr; }
  .fcard img { width: 68px; height: 68px; flex: 0 0 68px; }

  /* 表格 → 卡片式，手机上不必左右拖动 */
  .table-wrap { max-height: none; border: 0; border-radius: 0; background: transparent; overflow: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    padding: 6px 12px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
  }
  .table td {
    border: 0; padding: 7px 0; display: flex; align-items: center;
    justify-content: space-between; gap: 12px; text-align: right;
  }
  .table td::before {
    content: attr(data-label);
    flex: 0 0 auto; color: var(--muted); font-size: 12.5px; font-weight: 600; text-align: left;
  }
  .table td > * { flex: 1 1 auto; max-width: 62%; }
  .table td[data-label="头像"]::before { display: none; }
  .table td[data-label="头像"] { justify-content: flex-start; }
  .table td img { width: 54px; height: 54px; max-width: none; }
  .table input { font-size: 15px; }

  .diag-name { flex: 0 0 92px; }
  .urow { flex-direction: column; align-items: flex-start; }
  .preview-wrap, .camera-wrap video { max-width: 100%; }
  .toast { bottom: 18px; font-size: 14px; }
}
