/* ============================================================
   摩点门禁 · 访客申请系统  样式
   移动端优先，无任何前端框架依赖。
   ============================================================ */

:root {
  --brand: #1677ff;
  --brand-dark: #0958d9;
  --ok: #00b42a;
  --warn: #ff7d00;
  --bad: #f53f3f;
  --text: #1d2129;
  --text-2: #4e5969;
  --text-3: #86909c;
  --line: #e5e6eb;
  --bg: #f2f3f5;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

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

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

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

/* ---------- 布局 ---------- */
/* 用满实际可用宽度。
   原来锁 620px —— 宽屏上大片留白，而且日志页里没包 .table-wrap 的表格
   会被 nowrap 撑破卡片背景。 */
.wrap { width: 100%; max-width: 100%; margin: 0 auto; padding: 0 20px 40px; }
.wrap-admin { max-width: 100%; }

/* 兜底：任何直接塞进卡片的宽元素都不许撑破容器 */
.wrap table, .wrap pre, .wrap img { max-width: 100%; }

.topbar {
  background: linear-gradient(135deg, #1677ff, #3c9cff);
  color: #fff;
  padding: 26px 20px 30px;
  margin-bottom: -18px;
}
.topbar h1 { margin: 0 0 6px; font-size: 21px; font-weight: 600; }
.topbar p { margin: 0; font-size: 13px; opacity: .9; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-sub { font-size: 13px; color: var(--text-3); margin: 0 0 16px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field .req { color: var(--bad); margin-left: 2px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }

input[type=text], input[type=tel], input[type=password], input[type=number],
input[type=datetime-local], input[type=date], select, textarea {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, .1);
}
textarea { resize: vertical; min-height: 72px; }
select { appearance: none; background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386909c' d='M6 8.5L1.5 4h9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; color: var(--text-2); border-color: var(--line); }
.btn-ghost:hover { background: #f7f8fa; color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #cb2634; }

/* ---------- 提示条 ---------- */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
  word-break: break-word;
}
.alert-success { background: #e8ffea; border-color: #aff0b5; color: #0e7a1a; }
.alert-error   { background: #ffece8; border-color: #fdcdc5; color: #a8071a; }
.alert-warn    { background: #fff7e8; border-color: #ffe4ba; color: #a86800; }
.alert-info    { background: #e8f3ff; border-color: #bedaff; color: #0e42d2; }

/* ---------- 状态标签 ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  font-size: 12px;
  border-radius: 20px;
  white-space: nowrap;
  font-weight: 500;
}
.badge.ok      { background: #e8ffea; color: #0e7a1a; }
.badge.pending { background: #fff7e8; color: #a86800; }
.badge.info    { background: #e8f3ff; color: #0e42d2; }
.badge.bad     { background: #ffece8; color: #a8071a; }
.badge.muted   { background: #f2f3f5; color: #86909c; }

/* ---------- 访客码展示（核心） ---------- */
.code-box {
  text-align: center;
  padding: 26px 16px;
  background: linear-gradient(135deg, #f0f7ff, #e8f3ff);
  border: 2px dashed #9dc6ff;
  border-radius: var(--radius);
  margin: 6px 0 18px;
}
.code-box .code-label { font-size: 13px; color: #0e42d2; margin-bottom: 8px; }
.code-box .code-value {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 8px;
  color: #0e42d2;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  line-height: 1.15;
  word-break: break-all;
}
.code-box .code-tip { font-size: 12px; color: var(--text-3); margin-top: 10px; }

/* ---------- 信息列表 ---------- */
.info-list { margin: 0; padding: 0; list-style: none; }
.info-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid #f2f3f5;
  font-size: 14px;
}
.info-list li:last-child { border-bottom: none; }
.info-list .k { color: var(--text-3); flex: 0 0 auto; }
.info-list .v { color: var(--text); text-align: right; word-break: break-all; font-weight: 500; }

/* ---------- 可复制文本框 ---------- */
.copy-area {
  width: 100%;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-2);
}
.copy-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- 步骤条 ---------- */
.steps { display: flex; margin: 4px 0 18px; }
.steps .step { flex: 1; text-align: center; position: relative; font-size: 12px; color: var(--text-3); }
.steps .step .dot {
  width: 22px; height: 22px; line-height: 22px; border-radius: 50%;
  background: #e5e6eb; color: #fff; margin: 0 auto 5px; font-size: 12px; font-weight: 600;
}
.steps .step.done .dot { background: var(--ok); }
.steps .step.active .dot { background: var(--brand); }
.steps .step.active { color: var(--brand); font-weight: 500; }
.steps .step::after {
  content: ''; position: absolute; top: 11px; left: 50%; width: 100%; height: 2px;
  background: #e5e6eb; z-index: -1;
}
.steps .step:last-child::after { display: none; }
.steps .step.done::after { background: var(--ok); }

/* ---------- 表格（后台） ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data th { background: #f7f8fa; color: var(--text-2); font-weight: 600; }
table.data tr:hover td { background: #fafbfc; }
table.data td.wrap-cell { white-space: normal; max-width: 320px; word-break: break-all; }

/* ---------- 后台布局 ---------- */
.admin-nav {
  background: #1d2129; color: #fff; padding: 0 20px; display: flex; align-items: center;
  gap: 4px; flex-wrap: wrap; min-height: 52px; position: sticky; top: 0; z-index: 10;
}
.admin-nav .brand { font-weight: 600; margin-right: 16px; font-size: 15px; color: #fff; }
.admin-nav a {
  color: #c9cdd4; padding: 8px 12px; border-radius: 6px; font-size: 14px; text-decoration: none;
}
.admin-nav a:hover { background: #2b3038; color: #fff; text-decoration: none; }
.admin-nav a.active { background: var(--brand); color: #fff; }
.admin-nav .spacer { flex: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: 13px; color: var(--text-3); margin-top: 4px; }
.stat.ok .n { color: var(--ok); }
.stat.pending .n { color: var(--warn); }
.stat.bad .n { color: var(--bad); }
.stat.info .n { color: var(--brand); }

/* ---------- 配置页 ---------- */
.group { margin-bottom: 22px; }
.group > h3 { font-size: 15px; margin: 0 0 4px; }
.group > .tip { font-size: 12px; color: var(--text-3); margin: 0 0 14px; line-height: 1.7; }
.field-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; line-height: 1.6; }
.key-name { font-family: monospace; font-size: 11px; color: #a9aeb8; }
.configured { font-size: 11px; color: var(--ok); margin-left: 6px; }

/* ============================================================
   后台：紧凑排版与常用组件
   ============================================================ */

/* ---------- 页面标题 ---------- */
.page-head { margin-bottom: 14px; }
.page-title { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.page-sub { margin: 0; color: var(--text-2); font-size: 13px; }

/* ---------- 统计条 ---------- */
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.stat {
  flex: 1 1 100px; min-width: 88px;
  background: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow);
}
.stat-num { font-size: 21px; font-weight: 600; line-height: 1.25; }
.stat-label { font-size: 12px; color: var(--text-3); }

/* ---------- 筛选条 ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 0; }
.filter-item { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-3); }
.filter-item select, .filter-item input { min-width: 130px; }

/* ---------- 紧凑表单（系统配置 / 接口调试） ----------
   原来的单列 + 大输入框在宽屏上把页面拉得很长、右边全空。
   这里压小行高与内边距，并用两列栅格。 */
.compact-form .field { margin-bottom: 10px; }
.compact-form .field > label { font-size: 13px; margin-bottom: 3px; }
.compact-form input[type=text],
.compact-form input[type=tel],
.compact-form input[type=password],
.compact-form input[type=number],
.compact-form input[type=datetime-local],
.compact-form input[type=date],
.compact-form select {
  padding: 6px 9px; font-size: 13px; min-height: 32px;
}
.compact-form textarea { padding: 6px 9px; font-size: 13px; min-height: 54px; }
.compact-form .field .hint,
.compact-form .field-meta { font-size: 11px; margin-top: 3px; line-height: 1.5; }
.compact-form .key-name { font-size: 10px; }
.compact-form .card.group { padding: 14px 16px; }
.compact-form .card.group h3 { margin: 0 0 4px; font-size: 15px; }
.compact-form .card.group .tip { margin: 0 0 10px; font-size: 12px; }

/* 两列栅格：短输入框并排，长文本（JSON）占满整行 */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0 18px;
  align-items: start;
}
.field-grid .field-wide { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .field-grid { grid-template-columns: 1fr; }
}

/* 接口调试页也用紧凑排版 */
.debug-page .card { padding: 14px 16px; }
.debug-page .field { margin-bottom: 10px; }
.debug-page .field > label { font-size: 13px; margin-bottom: 3px; }
.debug-page input[type=text],
.debug-page input[type=password],
.debug-page input[type=number],
.debug-page select { padding: 6px 9px; font-size: 13px; min-height: 32px; }
.debug-page .btn { padding: 6px 12px; font-size: 13px; }

/* ---------- 上传人脸页 ---------- */
.face-preview {
  display: block;
  width: 100%;
  max-width: 260px;
  margin: 4px auto 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
input[type=file] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fafbfc;
  font-size: 14px;
}

/* ---------- 可通行门禁勾选 ---------- */
.device-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.device-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  margin: 0;
}
.device-item:hover { border-color: var(--brand); }
.device-item input[type=checkbox] { margin-top: 3px; flex: none; }
.device-item-off {
  background: #fafafa;
  opacity: .72;
  cursor: not-allowed;
}
.device-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.device-name { font-size: 14px; font-weight: 500; }
.device-meta { font-size: 12px; color: var(--text-3); word-break: break-all; }
.device-warn { font-size: 11px; color: var(--warn); }

/* 列表页批量授权里的紧凑版勾选 */
.device-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  margin: 0;
  white-space: nowrap;
}
.device-inline input[type=checkbox] { margin: 0; }

/* 访客标识（开门记录里跟在姓名后面） */
.badge-visitor {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 4px;
  background: #e8f0fe;
  color: #1a56c4;
  vertical-align: middle;
}

/* ---------- 管理员账号：编辑区 ----------
   编辑表单**不放在表格里** —— 表格只负责列出，
   点「编辑」跳到下方独立卡片的 ?edit=<id> 区。 */
.row-editing { background: #fff9e6; }
.row-editing td { background: transparent; }

.edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.edit-block {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.edit-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.edit-block input[type=text],
.edit-block input[type=password] {
  width: 100%;
  padding: 7px 9px;
  font-size: 14px;
}
.edit-block .btn { align-self: flex-start; }

.edit-danger {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.edit-danger form { margin: 0; }

/* ---------- 概览页的一行式自检提示 ---------- */
.selfcheck-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  text-decoration: none;
  line-height: 1.5;
}
.selfcheck-bar:hover { border-color: var(--brand); }
.selfcheck-bar.ok   { border-color: #b7e1c1; background: #f2fbf4; color: #17683a; }
.selfcheck-bar.warn { border-color: #f3d9a4; background: #fffaf0; color: #8a5a00; }
.selfcheck-bar.bad  { border-color: #f0b4b4; background: #fff5f5; color: #a32020; }
.selfcheck-more { white-space: nowrap; opacity: .75; }

/* ---------- 调试输出 ---------- */
pre.out {
  background: #1d2129; color: #b8e986; padding: 14px; border-radius: 8px;
  /* ★ 必须 pre-wrap：回调报文是很长的单行 JSON，
     用默认的 white-space:pre 会横向撑破卡片背景（日志页就是这个毛病）。 */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: auto; overflow-y: auto;
  font-size: 12px; line-height: 1.6; max-height: 460px; margin: 0;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
}
pre.out.err { color: #ff9c9c; }

/* ---------- 折叠面板 ---------- */
details { border: 1px solid var(--line); border-radius: 8px; padding: 0 14px; margin-bottom: 10px; background: #fff; }
details > summary { cursor: pointer; padding: 12px 0; font-weight: 500; font-size: 14px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '▸ '; color: var(--text-3); }
details[open] > summary::before { content: '▾ '; }
details > div { padding-bottom: 14px; }

/* ---------- 工具类 ---------- */
.muted { color: var(--text-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mono { font-family: "SF Mono", Consolas, monospace; }
.break { word-break: break-all; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1677ff, #3c9cff); padding: 20px;
}
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 32px 28px; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.login-card p { font-size: 13px; color: var(--text-3); margin: 0 0 22px; }

/* ---------- 图形验证码 ---------- */
.captcha-row { display: flex; gap: 10px; align-items: stretch; }
.captcha-row input { flex: 1; min-width: 0; }
.captcha-img {
  flex: 0 0 auto;
  height: 46px;
  min-width: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  object-fit: contain;
  -webkit-user-select: none;
  user-select: none;
}
.captcha-img:active { opacity: .65; }

/* ---------- 蜜罐字段 ----------
   真实用户看不见，爬虫会填（服务端据此静默丢弃）。
   ★ 刻意不用 display:none / visibility:hidden —— 一部分爬虫会跳过这类「明显隐藏」的字段，
     移出视口 + 透明度 0 更容易被无脑脚本填上。 */
.hp-field {
  position: absolute !important;
  left: -9999px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ---------- 加载与遮罩 ---------- */
.spinner {
  display: inline-block; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .code-box .code-value { font-size: 34px; letter-spacing: 6px; }
  .topbar { padding: 20px 16px 26px; }
  .card { padding: 16px; }
}
