/* 修复：登录页/弹窗用了 display:grid/flex，会盖过浏览器默认的 [hidden]{display:none}，
   导致 hidden 属性失效、登录后登录页不隐藏（表现"点登录没反应"）。强制 hidden 生效。 */
[hidden] { display: none !important; }

:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; background: var(--primary);
  color: #fff; font-weight: 700; font-size: 20px; display: grid; place-items: center;
}
.brand h1 { font-size: 17px; margin: 0; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.stats { display: flex; gap: 14px; margin-left: auto; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; text-align: center; min-width: 74px; }
.stat b { display: block; font-size: 18px; color: var(--primary); }
.stat span { font-size: 11px; color: var(--muted); }
.actions { display: flex; gap: 8px; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: .15s; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-d); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f1c4c4; }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* layout */
.layout { display: flex; height: calc(100vh - 65px); }
.sidebar { width: 300px; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.side-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.inst-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.inst-item { padding: 9px 10px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; margin-bottom: 4px; }
.inst-item:hover { background: var(--bg); }
.inst-item.active { background: #eaf1ff; border-color: #c5d8ff; }
.inst-item .nm { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.inst-item .ad { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.badge.todo { background: #fef3c7; color: var(--warn); }
.badge.done { background: #dcfce7; color: var(--ok); }
.badge.part { background: #e0edff; color: var(--primary); }

.content { flex: 1; overflow-y: auto; padding: 18px; }
.empty { color: var(--muted); text-align: center; margin-top: 60px; }

/* form */
.form-wrap { max-width: 980px; margin: 0 auto; }
.form-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.form-head h2 { margin: 0; font-size: 18px; }
.form-head-actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 12px; color: var(--ok); }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; overflow: hidden; box-shadow: var(--shadow); }
.section h3 { margin: 0; padding: 11px 16px; background: #f0f4ff; border-bottom: 1px solid var(--line); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 13px; }
.field .req { color: var(--danger); margin-left: 2px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 11px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; width: 100%; font-family: inherit;
}
.field textarea { min-height: 64px; resize: vertical; }
.pwd-row { display: flex; gap: 8px; align-items: center; }
.pwd-row input { flex: 1; }
.pwd-toggle { font-size: 12px; color: var(--primary); cursor: pointer; white-space: nowrap; }

/* photo */
.dropzone { border: 2px dashed var(--line); border-radius: 10px; padding: 16px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--primary); background: #f5f8ff; }
.upload-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.upload-bar .hint { margin: 0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.thumb { position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .del { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1; }
.thumb .cnt { position: absolute; bottom: 3px; left: 3px; background: rgba(0,0,0,.6); color: #fff; border-radius: 4px; font-size: 10px; padding: 1px 4px; }

.form-foot { display: flex; gap: 10px; justify-content: flex-end; margin: 8px 0 30px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 22px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card.wide { width: 560px; }
.modal-card h3 { margin: 0 0 14px; }
.modal-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.modal-card input, .modal-card textarea { width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; }
.modal-card .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin: -6px 0 12px; }
.modal-card code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }

/* ============ 移动端（≤860px，手机/小平板）专业适配 ============ */
@media (max-width: 860px) {
  /* 顶栏堆叠：品牌在上，统计与操作各自成行、可换行 */
  .topbar { gap: 10px; padding: 10px 12px; }
  .brand { width: 100%; }
  .stats { order: 2; width: 100%; margin-left: 0;
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { min-width: 0; padding: 8px 6px; }
  .stat b { font-size: 16px; }
  .stat span { font-size: 10px; }
  .actions { order: 3; width: 100%; flex-wrap: wrap; gap: 8px; }
  .actions .btn { flex: 1 1 auto; min-width: 120px; }
  .user-menu { flex: 0 0 auto; }

  /* 主区：侧栏变为"机构选择条"（搜索吸顶），表单在下方 */
  .layout { flex-direction: column; height: auto; }
  .sidebar { width: 100%; height: auto; max-height: 40vh;
    border-right: none; border-bottom: 1px solid var(--line); }
  .side-head { position: sticky; top: 0; background: var(--panel);
    z-index: 5; padding: 10px; }
  .side-head .btn { width: 100%; }
  .inst-list { max-height: 30vh; }

  /* 表单：单列、输入框 16px（防 iOS 聚焦自动放大）、触摸友好 */
  .content { padding: 12px; }
  .grid { grid-template-columns: 1fr; gap: 12px; padding: 14px; }
  .field label { font-size: 14px; }
  .field input, .field select, .field textarea {
    font-size: 16px; padding: 11px 12px; }
  .form-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .form-head-actions { flex-wrap: wrap; gap: 8px; }
  .form-head-actions .btn { flex: 1 1 auto; }

  /* 底部吸附操作条：保存/提交 大按钮，便于单手操作 */
  .form-foot { position: sticky; bottom: 0; background: var(--panel);
    border-top: 1px solid var(--line); padding: 12px;
    margin: 0 0 16px; gap: 10px; }
  .form-foot .btn { flex: 1; padding: 14px; font-size: 15px; }

  /* 弹窗：底部抽屉式（接近全宽），避免小屏溢出 */
  .modal { display: flex; align-items: flex-end; justify-content: center;
    padding: 0; }
  .modal-card, .modal-card.wide {
    width: 100%; max-width: 100%;
    border-radius: 16px 16px 0 0; padding: 18px 16px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    max-height: 92vh; overflow-y: auto; }
  .modal-card.wide { width: 100%; }
  .user-table { display: block; overflow-x: auto; white-space: nowrap; }

  /* 照片缩略图在窄屏稍大，便于点按删除 */
  .thumb { width: 84px; height: 84px; }
}

/* 超小屏（≤480px，如 iPhone SE）进一步收敛 */
@media (max-width: 480px) {
  .login-card { width: min(340px, 90vw); padding: 24px 18px; }
  .brand h1 { font-size: 15px; }
  .brand .sub { font-size: 11px; }
  .logo { width: 34px; height: 34px; font-size: 18px; }
  .stat { padding: 7px 4px; }
  .stat b { font-size: 15px; }
  .actions .btn { min-width: 100px; font-size: 12px; }
  .btn.block { padding: 12px; }
}

/* ---------- 登录页 ---------- */
.login-screen { position: fixed; inset: 0; background: linear-gradient(135deg, #0f766e, #1d4ed8); display: grid; place-items: center; z-index: 100; }
.login-card { background: var(--panel); border-radius: 16px; padding: 30px 28px; width: 340px; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-brand .logo { width: 36px; height: 36px; font-size: 18px; }
.login-brand h1 { font-size: 20px; margin: 0; }
.login-sub { color: var(--muted); font-size: 12px; margin: 0 0 18px; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.login-card input { width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.btn.block { width: 100%; padding: 10px; margin-top: 4px; }
.login-err { color: var(--danger); font-size: 12px; margin: 10px 0 0; }
.login-hint { color: var(--muted); font-size: 11px; margin: 14px 0 0; line-height: 1.5; }

/* ---------- 用户菜单 ---------- */
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 6px; }
.role-badge { font-size: 10px; background: #e0edff; color: var(--primary); padding: 1px 7px; border-radius: 10px; font-weight: 600; }
.role-badge.admin { background: #fde68a; color: #92400e; }
.user-drop { position: absolute; right: 0; top: 110%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 30; min-width: 130px; overflow: hidden; }
.drop-item { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 10px 14px; cursor: pointer; font-size: 13px; }
.drop-item:hover { background: var(--bg); }

/* ---------- 离线状态条 ---------- */
.offline-bar { padding: 7px 18px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.offline-bar.online { background: #ecfdf5; color: var(--ok); }
.offline-bar.offline { background: #fef3c7; color: var(--warn); }
.offline-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.offline-bar .sync { margin-left: auto; }

/* ---------- 用户管理 ---------- */
.modal-card.users-modal { width: 560px; max-width: 96vw; max-height: 88vh; display: flex; flex-direction: column; }
.user-toolbar { margin-bottom: 12px; }
.user-table-wrap { flex: 1 1 auto; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.users-modal .modal-actions { flex: 0 0 auto; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th, .user-table td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.user-table th { background: var(--bg); font-weight: 600; }
.user-table .tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.user-table .tag.admin { background: #fde68a; color: #92400e; }
.user-table .tag.collector { background: #e0edff; color: var(--primary); }
.user-table .tag.disabled { background: #f1f1f1; color: var(--muted); }
.user-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-table button { font-size: 12px; padding: 4px 8px; }

.assigned-tag { font-size: 12px; background: #e0edff; color: var(--primary); padding: 3px 9px; border-radius: 10px; }

/* ---------- 填报预览 / 大图灯箱 ---------- */
.pv-val { padding: 9px 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; min-height: 20px; word-break: break-all; }
.pv-meta { padding: 10px 14px; background: #eef6ff; border: 1px dashed #b9d2ff; border-radius: 8px; font-size: 13px; color: #2b5aa8; }
.muted { color: var(--muted); font-size: 12px; }
.preview-body { max-height: 72vh; overflow-y: auto; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; cursor: default; }

/* ---------- 提交校验未完成任务弹窗 ---------- */
.incomplete-body { max-height: 60vh; overflow-y: auto; }
.ic-group { margin-bottom: 14px; }
.ic-title { font-size: 13px; font-weight: 700; color: var(--danger, #dc2626); margin-bottom: 6px; }
.ic-list { margin: 0; padding-left: 20px; }
.ic-list li { font-size: 13px; line-height: 1.9; }
.ic-tip { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* ---------- 采集项目编辑（管理员） ---------- */
.schema-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.schema-count { color: var(--muted); font-size: 12px; margin-right: 4px; }

/* 采集项目编辑弹窗（卡片式） */
.modal-card.schema-modal { width: 920px; max-width: 96vw; max-height: 90vh; display: flex; flex-direction: column; }
.schema-modal h3 { flex: 0 0 auto; }
.schema-modal .hint { flex: 0 0 auto; }
.schema-modal .schema-toolbar { flex: 0 0 auto; }
.schema-modal .modal-actions { flex: 0 0 auto; }
.schema-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 2px; margin: 0 -2px; }
.sc-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color .15s;
}
.sc-card:hover { border-color: #cbd5e1; }
.sc-card:last-child { margin-bottom: 0; }
.sc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  flex-wrap: wrap;
}
.sc-idx { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.sc-key {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-weight: 600;
  color: var(--primary);
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.sc-type {
  background: var(--primary);
  color: #fff;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11.5px;
}
.sc-lock { color: #b45309; font-size: 11.5px; }
.sc-cust { color: #6b7280; font-size: 11.5px; }
.sc-tools { margin-left: auto; display: flex; gap: 4px; }
.sc-body { padding: 12px 14px; }
.sc-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.sc-row:last-child { margin-bottom: 0; }
.sc-row-full { grid-template-columns: 1fr; }
.sc-body label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.sc-body input[type="text"],
.sc-body input:not([type]),
.sc-body input[type="number"],
.sc-body select,
.sc-body textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 3px;
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
}
.sc-body input:focus, .sc-body select:focus, .sc-body textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, .12);
}
.sc-body textarea { min-height: 38px; resize: vertical; font-family: inherit; }
.sc-body label.sc-req {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  padding-top: 18px;
}
.sc-body label.sc-req input { width: auto; margin: 0; }
.sc-key-input { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: .2px; }
.sc-key-input[readonly] { background: #f1f5f9; color: var(--muted); cursor: not-allowed; }
.sc-key-input.dup { border-color: var(--danger) !important; box-shadow: 0 0 0 2px rgba(185,28,28,.12); }
.sc-sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.sc-err { display: block; font-size: 11.5px; color: var(--danger); font-weight: 600; margin-top: 2px; }
.mini.ins { color: var(--primary); border-color: #99f6e4; background: #f0fdfa; }
.mini.ins:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); }
@media (max-width: 720px) {
  .sc-row { grid-template-columns: 1fr; }
  .sc-tools { margin-left: 0; width: 100%; justify-content: flex-end; padding-top: 4px; }
}

.mini { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 2px 8px; cursor: pointer; font-size: 13px; line-height: 1.4; margin: 0 1px; }
.mini:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.mini:disabled { opacity: .4; cursor: not-allowed; }
.mini.danger { color: var(--danger); border-color: #f1c4c4; }
.mini.danger:hover:not(:disabled) { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- 多采集项目导航 ---------- */
.proj-bar { display: flex; flex-direction: column; gap: 4px; }
.proj-label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .3px; }
.proj-select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; font-family: inherit; }
.proj-actions { display: flex; gap: 6px; }
.proj-actions .btn { flex: 1; }

/* ---------- 项目设置：分配 ---------- */
.assign-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 12px 0; background: var(--bg); }
.assign-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.assign-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.assign-col { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.assign-col-h { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.assign-list { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.assign-chk { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 400 !important; margin: 0 !important; cursor: pointer; }
.assign-chk input { width: auto; margin: 0; flex: 0 0 auto; }
.chk-line { display: flex; align-items: center; gap: 8px; font-weight: 500 !important; }
.chk-line input { width: auto; margin: 0; }

/* ---------- 用户组管理 ---------- */
.group-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.group-list { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; }
.group-card { border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; overflow: hidden; }
.gc-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: #f1f5f9; border-bottom: 1px solid var(--line); font-size: 14px; }
.gc-head .muted { font-size: 12px; }
.gc-tools { margin-left: auto; display: flex; gap: 6px; }
.gc-members { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; }
.gc-members .muted { font-size: 12px; }
.gm { display: inline-flex; align-items: center; gap: 4px; background: #e0edff; color: var(--primary); border-radius: 14px; padding: 2px 8px; font-size: 12px; }
.gm .mini { padding: 0 6px; font-size: 12px; line-height: 1.3; }
.gc-add { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.grp-add-sel { padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; font-family: inherit; min-width: 160px; }

/* 通用工具类 */
.center { text-align: center; }
.pad { padding: 16px; }

@media (max-width: 720px) {
  .assign-cols { grid-template-columns: 1fr; }
}

