* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: #f5f6f8; color: #222; }
.hidden { display: none !important; }
.view:not(.hidden) { min-height: 1px; } /* 空视图（阶段 2-4 填充）也保持可见容器 */
main { max-width: 960px; margin: 0 auto; padding: 16px; padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
h1 { font-size: 20px; text-align: center; margin: 24px 0; }

/* 顶栏 */
#topbar { display: flex; justify-content: space-between; align-items: center; background: #1f7ae0; color: #fff; padding: 10px 16px; }
#topbar button { background: none; border: 1px solid #fff; color: #fff; border-radius: 4px; padding: 4px 12px; }
/* 工作台入口（统一登录门面 /home/）：与退出按钮同款描边，靠右排列 */
#topbar #home-link { margin-left: auto; margin-right: 8px; color: #fff; text-decoration: none; border: 1px solid #fff; border-radius: 4px; padding: 4px 12px; font-size: 14px; white-space: nowrap; }

/* PC 顶部导航（移动端隐藏） */
#mainnav { display: none; background: #fff; border-bottom: 1px solid #e5e6eb; }
#mainnav a { display: inline-block; padding: 12px 20px; color: #333; text-decoration: none; }
#mainnav a:hover { color: #1f7ae0; }

/* 移动端底部 Tab（PC 隐藏）：全部页签单行展示，超宽横向滑动、不换行；
   底部安全区留白，避免 iPhone Home 指示条遮挡 */
#tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: #fff; border-top: 1px solid #e5e6eb; z-index: 10;
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  padding-bottom: env(safe-area-inset-bottom, 0px); scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabs a { flex: 0 0 auto; min-width: 64px; text-align: center; padding: 10px 8px; color: #666; text-decoration: none; font-size: 14px; white-space: nowrap; }

/* 表单通用 */
form label { display: block; margin: 12px 0; font-size: 14px; color: #555; }
input, select, textarea { width: 100%; padding: 10px; margin-top: 4px; border: 1px solid #d0d3d9; border-radius: 6px; font-size: 15px; background: #fff; }
button { padding: 10px 18px; border: none; border-radius: 6px; background: #1f7ae0; color: #fff; font-size: 15px; cursor: pointer; }
button:disabled { background: #aab4c0; }
.error { color: #d83931; font-size: 13px; }

/* 登录页：居中卡片 + 柔和渐变底；输入框加大（16px 字号，移动端聚焦不缩放）
   min-height 取满视口高、负外边距抵消 main 的底部预留内边距，保证卡片在视口垂直居中 */
#view-login { position: relative; min-height: calc(100vh - 32px); margin-bottom: -76px; display: flex; align-items: center; justify-content: center; padding: 24px 0; }
#view-login::before { content: ''; position: fixed; inset: 0; z-index: -1; background: linear-gradient(135deg, #EDF3FF 0%, #F5F6F8 48%, #E8F7EE 100%); }
.login-card { width: 100%; max-width: 420px; background: #fff; padding: 34px 30px 30px; border-radius: 16px; box-shadow: 0 16px 48px rgba(31, 122, 224, .14), 0 2px 8px rgba(0, 0, 0, .04); }
.login-head { text-align: center; margin-bottom: 26px; }
.login-head h1 { font-size: 22px; margin: 14px 0 6px; letter-spacing: .5px; }
.login-head p { margin: 0; font-size: 13px; color: #86909c; }
.login-logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #1f7ae0 0%, #3c8af0 100%); box-shadow: 0 8px 18px rgba(31, 122, 224, .3); }
#login-form { margin: 0; }
#login-form label { margin: 0 0 18px; font-size: 13px; font-weight: 500; color: #4E5969; }
#login-form input { margin-top: 8px; padding: 14px 16px; font-size: 16px; border-radius: 10px; border-color: #E5E6EB; background: #FAFBFC; transition: border-color .18s, box-shadow .18s, background .18s; }
#login-form input:focus { outline: none; background: #fff; border-color: #1f7ae0; box-shadow: 0 0 0 4px rgba(31, 122, 224, .12); }
#login-form input::placeholder { color: #C9CDD4; }
#login-form button[type="submit"] { width: 100%; margin-top: 4px; padding: 14px 16px; font-size: 16px; font-weight: 600; border-radius: 10px; letter-spacing: 1px; background: #1f7ae0; }
#login-form button[type="submit"]:hover { background: #1867c9; }
@media (max-width: 480px) {
  .login-card { padding: 26px 20px 22px; border-radius: 14px; }
}

/* 扫码区（扫码按钮在 PC/移动端均可用；摄像头不可用时自动降级手动输入） */
.scan-bar { display: flex; gap: 8px; align-items: center; }
.scan-bar input#reg-barcode { flex: 1; margin-top: 0; }
/* 第二行：分店号（保留上次选择）+ 登记类型（保留上次选择）固定两列并排 */
.reg-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
.reg-toolbar .match-filter,
.reg-type-filter { display: flex; align-items: center; gap: 6px; margin: 0; min-width: 0; }
.reg-toolbar .match-filter label,
.reg-type-filter label { font-size: 14px; color: #4e5969; white-space: nowrap; }
.reg-toolbar select,
.reg-type-filter input { flex: 1; width: auto; min-width: 0; margin-top: 0; }
#reg-scan-btn { display: inline-block; white-space: nowrap; }
#reg-scan-area { margin-top: 12px; }
#scan-view { position: relative; overflow: hidden; border-radius: 8px; background: #000; }
#scan-view video { width: 100%; display: block; transition: transform 0.2s; }
/* 自绘取景框：中心宽扁区域 + 半透明遮罩（不依赖扫码库的 UI 渲染） */
#scan-frame {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 80%; height: 30%;
  border: 2px solid rgba(255, 255, 255, 0.95); border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.scan-zoom { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0 0; }
.scan-zoom button { min-width: 44px; }
#scan-zoom-label { font-weight: 600; min-width: 40px; text-align: center; }
.scan-info { margin: 6px 0 0; font-size: 12px; color: #86909c; text-align: center; }

/* 商品匹配列表：每条记录为标准表单布局，左侧独立 44×44 复选框热区，整行可点击选中 */
.match-list { margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.match-filter { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; }
.match-filter label { font-size: 14px; color: #4e5969; white-space: nowrap; }
.match-filter select { width: auto; min-width: 140px; margin-top: 0; }
.match-list[aria-busy="true"] { opacity: .65; pointer-events: none; } /* 查询中禁止点击旧结果，避免选中过期记录 */
.match-hint { margin: 0; font-size: 13px; color: #86909c; }
.match-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: #fff; padding: 10px 12px; border-radius: 8px; border: 1px solid #e5e6eb;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.match-item:hover { border-color: #1f7ae0; }
.match-item:focus-visible { outline: 2px solid #1f7ae0; outline-offset: 2px; }
.match-item.selected { border-color: #1f7ae0; background: #f0f7ff; box-shadow: 0 0 0 2px rgba(31, 122, 224, .12); }
/* 复选框：label 自身 44×44，满足移动端触屏最小热区；与整行垂直居中 */
.match-check { position: relative; flex: 0 0 44px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.match-check input { position: absolute; inset: 0; width: 44px; height: 44px; margin: 0; opacity: 0; cursor: pointer; }
.match-check-box {
  width: 22px; height: 22px; border: 2px solid #c9cdd4; border-radius: 5px; background: #fff;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
  transition: background-color .15s, border-color .15s;
}
.match-check input:checked + .match-check-box { background: #1f7ae0; border-color: #1f7ae0; }
.match-check input:checked + .match-check-box::after {
  content: ''; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
/* 字段区：移动端单列、较宽屏两列；标签固定宽度保证上下行对齐 */
.match-fields { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr; gap: 4px 12px; }
.match-field { display: flex; gap: 6px; min-width: 0; font-size: 14px; line-height: 1.5; }
.match-label { flex: 0 0 64px; color: #86909c; font-size: 12px; }
.match-value { flex: 1; min-width: 0; color: #222; overflow-wrap: anywhere; word-break: break-word; }
@media (min-width: 560px) { .match-fields { grid-template-columns: 1fr 1fr; } }
.match-complete { width: 100%; padding: 10px 12px; background: #fff; color: #1f7ae0; border: 1px solid #1f7ae0; border-radius: 8px; font-size: 15px; }

/* 只读信息区 */
.readonly { background: #fff; border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.readonly p { margin: 6px 0; font-size: 14px; }

/* 表格 */
/* 列表容器：内容超宽时左右滑动查看（移动端触摸惯性 + 桌面可见横向滚动条） */
.table-wrap {
  overflow-x: auto;
  /* 不再使用已废弃的 -webkit-overflow-scrolling:touch：iOS 13+ 默认带惯性，
     该属性在列表内容反复刷新后会导致容器横向手势失效（滑不动的已知来源） */
  touch-action: pan-y;   /* 只把纵向交给浏览器；横向拖动由 JS 接管（安卓原生横滑会偶发失效） */
  overscroll-behavior-x: contain; /* 滚到边缘时不把横向手势传递给页面/浏览器（减少误触返回手势） */
  max-width: 100%;
  background: #fff;
  border-radius: 8px;
  scrollbar-width: thin;
}
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #c9cdd4; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-track { background: #f2f3f5; }
/* 表格按内容撑开：列多时不压缩、不换行，由容器横向滚动 */
table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th, td { padding: 8px 10px; border-bottom: 1px solid #f0f1f3; text-align: left; }
th { background: #f7f8fa; }
tbody tr { cursor: pointer; }

/* 分页 */
.pager { margin: 12px 0; display: flex; align-items: center; gap: 8px; justify-content: center; }

/* 弹层（默认底部抽屉，PC 居中） */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; z-index: 20; }
.modal-body { background: #fff; width: 100%; max-height: 88vh; overflow-y: auto; padding: 16px; border-radius: 12px 12px 0 0; }
.modal-body h3 { margin: 4px 0 12px; }
/* 登记弹窗：标题栏固定、字段错误提示、底部操作区（移动端贴底，PC 右对齐） */
.reg-modal-body { padding-top: 0; }
.modal-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fff; padding: 12px 0 8px; margin-bottom: 4px; }
.modal-head h3 { margin: 0; }
.icon-btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; background: #f2f3f5; color: #4e5969; font-size: 24px; line-height: 1; }
.icon-btn:hover { background: #e5e6eb; }
.reg-field { display: block; margin: 12px 0; font-size: 14px; color: #555; }
.reg-field .req { color: #d83931; margin-left: 2px; }
.field-error { display: block; margin-top: 4px; color: #d83931; font-size: 12px; line-height: 1.4; }
.reg-field.invalid input, .reg-field.invalid select, .reg-field.invalid textarea { border-color: #d83931; background: #fff7f7; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { min-height: 44px; }
@media (max-width: 767px) {
  .modal-actions { position: sticky; bottom: -16px; background: #fff; margin: 16px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .modal-actions button { flex: 1; }
}

/* 查询表单网格 */
.query-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: #fff; padding: 12px; border-radius: 8px; margin-bottom: 12px; }
.query-grid .full { grid-column: 1 / -1; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: rgba(0,0,0,.75); color: #fff; padding: 10px 20px; border-radius: 6px; font-size: 14px; z-index: 30; max-width: 86vw; display: none; }
#toast.show { display: block; }
#toast.error { background: #d83931; }

/* 报表查询区 */
.query-grid .radio-group { grid-column: 1 / -1; display: flex; gap: 16px; }
.query-grid .radio-group label { display: flex; align-items: center; gap: 4px; margin: 0; }
.query-grid .radio-group input { width: auto; margin: 0; }
.query-grid .date-label { display: flex; align-items: center; gap: 6px; }
.query-grid .date-label input { margin-top: 0; }
button.outline { background: #fff; color: #1f7ae0; border: 1px solid #1f7ae0; }

/* 用户管理 */
.card { background: #fff; border-radius: 8px; padding: 4px 16px 16px; margin: 12px 0; }
.card h3 { margin: 12px 0 0; }
.table-wrap button { padding: 4px 10px; font-size: 13px; }
tr.u-reset-row td { white-space: normal; }
tr.u-reset-row input { display: inline-block; width: auto; margin: 0 4px; }

/* PC 断点 */
@media (min-width: 768px) {
  main { padding-bottom: 24px; }
  #tabs { display: none !important; }
  #mainnav { display: block; }
  .modal { align-items: center; }
  .modal-body { width: 480px; border-radius: 12px; }
  .reg-modal-body { width: 520px; }
  .query-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- RBAC 角色权限矩阵 ---------- */
.muted { color: #86909c; font-size: 13px; }
button.danger { color: #d83931; border-color: #d83931; }
.roles-layout { display: flex; gap: 16px; align-items: flex-start; }
.roles-side { flex: 0 0 210px; }
.roles-side h3 { margin: 0 0 8px; font-size: 15px; }
.role-list { display: flex; flex-direction: column; gap: 6px; }
.role-item { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 8px 10px; background: #fff; color: #333; border: 1px solid #e5e6eb; border-radius: 8px; }
.role-item:hover { border-color: #1f7ae0; }
.role-item.active { border-color: #1f7ae0; background: #f0f7ff; color: #1f40e0; }
.role-item .role-name { font-weight: 600; font-size: 14px; }
.role-item .role-meta { font-size: 12px; color: #86909c; }
.role-add { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.role-add input { margin-top: 0; padding: 8px; font-size: 14px; }
.roles-main { flex: 1; min-width: 0; }
.perm-matrix { width: 100%; border-collapse: collapse; background: #fff; }
.perm-matrix th, .perm-matrix td { padding: 6px 8px; border-bottom: 1px solid #eef0f3; text-align: center; font-size: 13px; }
.perm-matrix thead th { background: #fafafa; color: #86909c; font-weight: 500; }
.perm-matrix th:first-child { text-align: left; white-space: nowrap; }
.perm-matrix input[type="checkbox"] { width: auto; margin: 0; }
@media (max-width: 768px) {
  .roles-layout { flex-direction: column; }
  .roles-side { flex: 1 1 auto; width: 100%; }
}

/* ---------- 拍照上传 ---------- */
.photo-card { background: #fff; border-radius: 8px; padding: 2px 14px 14px; margin: 10px 0; }
.photo-title { font-size: 16px; margin: 10px 0 8px; }
/* 按字段值长度自适应横排：窄屏自动换列，保证不超出屏幕 */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 10px; }
.photo-field { margin: 0; min-width: 0; }
.photo-field-wide { grid-column: 1 / -1; }
.photo-card .photo-field input,
.photo-card .photo-field select,
.photo-card .photo-field textarea { margin-top: 3px; padding: 8px 10px; font-size: 14px; }
.photo-remark { display: block; margin: 8px 0 0; }
.photo-remark textarea { min-height: 36px; resize: vertical; }
.photo-info { margin: 4px 0 0; }
.photo-info:empty { display: none; }
.photo-sug {
  background: #fff; border: 1px solid #e5e6eb; border-radius: 8px; margin: 4px 0 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .08); max-height: 260px; overflow-y: auto;
}
.photo-sug-item {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  background: #fff; color: #222; border: 0; border-bottom: 1px solid #f2f3f5;
  border-radius: 0; padding: 10px 12px; text-align: left; font-size: 14px;
}
.photo-sug-item:last-child { border-bottom: 0; }
.photo-sug-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-sug-no { color: #86909c; font-size: 12px; }
.photo-sug-empty { margin: 0; padding: 12px; font-size: 13px; color: #86909c; }
.photo-pick { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; }
.photo-pick button { flex: 0 0 auto; padding: 8px 14px; font-size: 14px; }
/* 缩略图横向排列，超出可左右滑动，避免占满屏幕高度 */
.photo-previews { display: flex; gap: 8px; overflow-x: auto; margin: 6px 0 0; padding-bottom: 2px; }
.photo-thumb { position: relative; flex: 0 0 64px; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: #f2f3f5; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb-del {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; padding: 0;
  border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; font-size: 14px; line-height: 1;
}
.photo-result h3 { margin: 12px 0 8px; }
.photo-result p { margin: 6px 0; font-size: 14px; overflow-wrap: anywhere; }
.photo-actions { display: flex; gap: 8px; margin-top: 8px; }
.photo-actions button { flex: 0 0 auto; padding: 8px 18px; font-size: 14px; }
.photo-list { padding: 2px 14px 12px; }
.photo-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.photo-list-head h3 { margin: 10px 0 0; font-size: 15px; }
.photo-list .table-wrap { margin-top: 8px; }
.photo-list table th, .photo-list table td { padding: 7px 9px; }
@media (max-width: 340px) {
  .photo-grid { grid-template-columns: 1fr; }
}

/* ---------- 登记弹窗：上传图片至网盘 ---------- */
.reg-modal-body .modal-actions { flex-wrap: wrap; }
.modal-actions #reg-photo-btn { margin-right: auto; padding: 10px 12px; white-space: nowrap; }
.reg-photo-status { margin: 10px 0 0; }
.reg-progress { height: 8px; background: #f2f3f5; border-radius: 4px; overflow: hidden; }
.reg-progress-bar { height: 100%; width: 0; background: #1f7ae0; transition: width .2s ease; }
.reg-photo-msg { margin: 6px 0 0; font-size: 13px; color: #4e5969; overflow-wrap: anywhere; }
.reg-photo-msg.error-text { color: #d83931; }
.reg-photo-links { display: flex; align-items: center; gap: 10px; margin: 6px 0 0; font-size: 13px; }
.reg-photo-links button { padding: 4px 12px; font-size: 13px; }
.photo-src-actions { display: flex; gap: 10px; margin: 8px 0 0; }
.photo-src-actions button { flex: 1; }
.reg-photo-src-body .muted { margin: 10px 0 0; }
