:root {
  --brand: #0f4c81;
  --brand-2: #1b6ca8;
  --brand-3: #e8f1f9;
  --accent: #e8a33d;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --ok: #1e8e5a;
  --ok-bg: #e8f6ef;
  --warn: #b7791f;
  --warn-bg: #fdf6e3;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e3e9f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 42, 67, 0.06), 0 8px 24px rgba(16, 42, 67, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
p { margin: 0; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------------- 顶部 ---------------- */
.site-header {
  background: linear-gradient(135deg, #0f4c81 0%, #1b6ca8 60%, #2b86c5 100%);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(15, 76, 129, 0.22);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 42px; height: 42px; flex: none;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.32);
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.5px; font-size: 13px;
}
.brand .org { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .sub { font-size: 12px; opacity: 0.82; }
.header-link {
  color: #fff; font-size: 13px; padding: 7px 13px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}
.header-link:hover { background: rgba(255, 255, 255, 0.24); text-decoration: none; }

/* ---------------- 容器 ---------------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px 64px; }
.wrap-wide { max-width: 1240px; margin: 0 auto; padding: 18px 16px 64px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  margin-bottom: 16px;
}
.card > h2 { font-size: 18px; margin-bottom: 4px; }
.card > .hint { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* ---------------- 步骤条 ---------------- */
.stepper {
  display: flex; list-style: none; padding: 0; margin: 0 0 18px;
  counter-reset: step; gap: 6px;
}
.stepper li {
  flex: 1; text-align: center; font-size: 12.5px; color: var(--muted);
  position: relative; padding-top: 30px;
}
.stepper li::before {
  counter-increment: step; content: counter(step);
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 24px; border-radius: 50%;
  background: #dbe4ee; color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.stepper li.active { color: var(--brand); font-weight: 600; }
.stepper li.active::before { background: var(--brand); box-shadow: 0 0 0 4px rgba(15, 76, 129, 0.12); }
.stepper li.done::before { content: "✓"; background: var(--ok); }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 7px; }
.field .req { color: var(--danger); margin-left: 2px; }
.field .desc { font-size: 12px; color: var(--muted); margin-top: 5px; }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: inherit;
  border: 1px solid #cfd9e4; border-radius: 10px; background: #fff; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none; appearance: none;
}
.select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%236b7785' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(27, 108, 168, 0.14);
}
.textarea { min-height: 84px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.error-text { color: var(--danger); font-size: 12.5px; margin-top: 5px; }
.input.invalid { border-color: var(--danger); background: #fffafa; }

/* 选项 chips */
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  border: 1px solid #cfd9e4; background: #fff; border-radius: 999px;
  padding: 8px 15px; font-size: 13.5px; cursor: pointer; user-select: none;
  transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--brand-2); }
.chip input { display: none; }
.chip.checked { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .risk {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: #eef2f7; color: var(--muted);
}
.chip.checked .risk { background: rgba(255, 255, 255, 0.22); color: #fff; }
.risk-高 { background: #fff1e6 !important; color: #b45309 !important; }
.risk-极高 { background: #fdecea !important; color: var(--danger) !important; }
.chip.checked .risk-高, .chip.checked .risk-极高 { background: rgba(255,255,255,.22) !important; color: #fff !important; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 20px; font-size: 15px; font-weight: 600; font-family: inherit;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  transition: all 0.15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0c3f6c; }
.btn-accent { background: var(--accent); color: #3a2503; }
.btn-accent:hover:not(:disabled) { background: #d9922c; }
.btn-ghost { background: #fff; color: var(--brand); border-color: #cfd9e4; }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand-2); background: var(--brand-3); }
.btn-danger { background: #fff; color: var(--danger); border-color: #eec9c4; }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

/* ---------------- 安全告知书 ---------------- */
.notice-doc {
  border: 1px solid var(--line); border-radius: 12px; background: #fcfdff;
  padding: 20px 18px; max-height: 52vh; overflow: auto;
}
.notice-doc .notice-title {
  text-align: center; font-size: 19px; font-weight: 700; letter-spacing: 1px; margin-bottom: 4px;
}
.notice-doc .notice-meta {
  text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px dashed #d8e1ea;
}
.notice-doc h4 {
  font-size: 14.5px; color: var(--brand); margin: 16px 0 8px;
  padding-left: 9px; border-left: 3px solid var(--brand-2);
}
.notice-doc ol { margin: 0; padding-left: 20px; }
.notice-doc li { font-size: 13.5px; margin-bottom: 5px; color: #33414f; }
.notice-doc .doc-foot {
  margin-top: 16px; padding-top: 12px; border-top: 1px dashed #d8e1ea;
  font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}

.agree-bar {
  display: flex; gap: 11px; align-items: flex-start; margin-top: 16px;
  padding: 13px 14px; background: var(--brand-3); border-radius: 10px; font-size: 13.5px;
}
.agree-bar input { width: 18px; height: 18px; margin-top: 2px; flex: none; accent-color: var(--brand); }

/* ---------------- 签名 ---------------- */
.sign-box {
  position: relative; border: 1.5px dashed #b9c7d6; border-radius: 12px;
  background: #fff; height: 200px; overflow: hidden;
}
.sign-box canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.sign-box .placeholder {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #a8b6c5; font-size: 14px; pointer-events: none;
}
.sign-box .baseline {
  position: absolute; left: 24px; right: 24px; bottom: 38px;
  border-bottom: 1px solid #d8e1ea; pointer-events: none;
}
.sign-tools { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

/* ---------------- 访客凭证 ---------------- */
.pass-card {
  background: linear-gradient(160deg, #0f4c81, #1b6ca8 70%, #2b86c5);
  color: #fff; border-radius: 16px; padding: 22px; box-shadow: 0 12px 32px rgba(15, 76, 129, 0.28);
}
.pass-card .pass-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pass-card .pass-code { font-size: 13px; opacity: 0.85; }
.pass-card .pass-name { font-size: 24px; font-weight: 700; margin-top: 2px; }
.pass-card .pass-company { font-size: 13px; opacity: 0.9; }
.pass-qr {
  background: #fff; border-radius: 12px; padding: 10px; width: 150px; height: 150px; flex: none;
  display: grid; place-items: center;
}
.pass-qr svg { width: 100%; height: 100%; display: block; }
.pass-meta {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.22);
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; font-size: 12.5px;
}
.pass-meta .k { opacity: 0.72; }
.pass-meta .v { font-weight: 600; }

/* ---------------- 徽标 ---------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-pending_sign { background: var(--warn-bg); color: var(--warn); }
.badge-signed { background: var(--brand-3); color: var(--brand); }
.badge-checked_in { background: var(--ok-bg); color: var(--ok); }
.badge-checked_out { background: #eef2f7; color: var(--muted); }
.badge-rejected { background: var(--danger-bg); color: var(--danger); }
.badge-expired { background: var(--danger-bg); color: var(--danger); }

/* ---------------- 提示 ---------------- */
.alert { border-radius: 10px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 14px; }
.alert-info { background: var(--brand-3); color: #16405f; }
.alert-warn { background: var(--warn-bg); color: #7a5410; }
.alert-danger { background: var(--danger-bg); color: #8e2f24; }
.alert-ok { background: var(--ok-bg); color: #14603d; }

.toast-host { position: fixed; left: 50%; top: 78px; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1f2933; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); animation: slideIn 0.2s ease;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { background: #f7f9fc; font-weight: 600; color: var(--muted); font-size: 12.5px; }
.table tbody tr:hover { background: #fafcff; }
.table tbody tr:last-child td { border-bottom: none; }
.table td.wrap-cell { white-space: normal; min-width: 160px; }

/* ---------------- 管理后台 ---------------- */
.admin-bar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 0 18px;
  display: flex; align-items: center; gap: 18px; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 10px rgba(16, 42, 67, 0.05);
}
.admin-bar .title { font-weight: 700; color: var(--brand); padding: 14px 0; font-size: 15px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  padding: 15px 14px; font-size: 13.5px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; background: none; border-top: 0; border-left: 0; border-right: 0;
  font-family: inherit;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.admin-bar .spacer { flex: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.2; color: var(--brand); }
.stat .num.warn { color: var(--warn); }
.stat .num.danger { color: var(--danger); }
.stat .num.ok { color: var(--ok); }
.stat .lbl { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .input, .toolbar .select { width: auto; min-width: 150px; padding: 8px 12px; font-size: 13.5px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 42, 67, 0.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 680px; max-height: 88vh;
  overflow: auto; padding: 22px; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
}
.modal h3 { margin-bottom: 14px; }
.modal-close { float: right; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

.login-wrap { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.login-card { background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.role-switch { display: flex; background: #eef2f7; border-radius: 10px; padding: 4px; margin: 18px 0; }
.role-switch button {
  flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 8px;
  font-size: 14px; font-family: inherit; cursor: pointer; color: var(--muted);
}
.role-switch button.active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 8px 12px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-all; }

.sig-img { border: 1px solid var(--line); border-radius: 10px; background: #fff; max-width: 100%; }

.onsite-item {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
}
.onsite-item:last-child { border-bottom: 0; }
.onsite-item.overdue { background: #fff8f7; margin: 0 -8px; padding-left: 12px; padding-right: 12px; border-radius: 8px; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; font-size: 13.5px; }

@media print {
  .site-header, .no-print, .stepper, .btn-row { display: none !important; }
  body { background: #fff; }
  .card, .pass-card { box-shadow: none; }
  .pass-card { background: #fff !important; color: #000 !important; border: 2px solid #000; }
  .pass-qr { border: 1px solid #000; }
}

@media (max-width: 560px) {
  .wrap, .wrap-wide { padding: 14px 12px 48px; }
  .card { padding: 18px 15px; }
  .pass-card .pass-name { font-size: 20px; }
  .pass-qr { width: 120px; height: 120px; }
  .stepper li { font-size: 11.5px; }
  .admin-bar { gap: 10px; padding: 0 12px; }
}
