:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #16191f;
  --muted: #6b7280;
  --line: #e2e6eb;
  --accent: #123f7a;
  --accent-2: #2f6fb3;
  --ok: #1c7a4a;
  --warn: #a34848;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  height: 54px;
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 3px rgba(47,111,179,.16); }
.brand .tag { font-size: 10px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

.docline { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.doctitle { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.docselect {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px;
  background: #fff; font-size: 13px; color: var(--ink); max-width: 380px;
}

.tools { display: flex; align-items: center; gap: 14px; }
.pager, .zoom { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.pager b { color: var(--ink); }
.iconbtn {
  width: 26px; height: 26px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 15px; line-height: 1; cursor: pointer;
}
.iconbtn:hover { background: #f3f6fa; border-color: #cfd8e3; }

.badge {
  font-size: 11.5px; padding: 3px 9px; border-radius: 20px;
  background: #e9f5ee; color: var(--ok); border: 1px solid #cfe8da;
}
.badge.off { background: #fdf0ef; color: var(--warn); border-color: #f0d4d2; }

/* ---------------- 布局 ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  height: calc(100vh - 54px);
}

/* ---------------- 阅读区 ---------------- */
.stage {
  overflow: auto;
  padding: 26px 26px 80px;
  scroll-behavior: smooth;
  background:
    radial-gradient(1200px 400px at 50% -160px, #eef3f9 0%, transparent 70%),
    var(--bg);
  position: relative;
}

.viewer { display: flex; flex-direction: column; align-items: center; gap: 22px; }

.page {
  /* 100% 时铺满可用宽度但不超过 880；放大时按倍数溢出，配合 stage 的横向滚动。
     原来只改 max-width，桌面端窄屏上放大按钮其实按不动 —— 一并修掉。 */
  width: calc(min(100%, 880px) * var(--scale, 1));
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: width .12s ease;
}
.page img { display: block; width: 100%; height: auto; }

.page .holder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--muted); font-size: 12.5px;
  background: repeating-linear-gradient(135deg, #fbfcfd, #fbfcfd 10px, #f6f8fa 10px, #f6f8fa 20px);
}
.page .holder .spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #dde3ea; border-top-color: var(--accent-2);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page .pnum {
  position: absolute; right: 10px; bottom: 8px;
  font-size: 11px; color: #9aa4b1;
  background: rgba(255,255,255,.86); padding: 1px 6px; border-radius: 10px;
}

.page.failed .holder { color: var(--warn); background: #fdf5f4; }
.page.failed .holder .spin { display: none; }

.stagehint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
/* display:flex 会盖掉 [hidden] 的 UA 样式，必须显式处理 */
.stagehint[hidden] { display: none; }
.hintbox {
  max-width: 460px; background: rgba(255,255,255,.92);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 30px; box-shadow: var(--shadow); text-align: left;
}
.hintbox h2 { margin: 0 0 10px; font-size: 17px; }
.hintbox p { margin: 0 0 8px; color: #3d4552; line-height: 1.75; }
.hintbox .muted { color: var(--muted); font-size: 13px; }
/* 待授权提示：中性口吻，不用警示色 —— 这是正常流程的一步，不是出错 */
.stagehint.lockscreen { pointer-events: auto; background: rgba(246,247,249,.72); backdrop-filter: blur(2px); }
.lockscreen .hintbox { border-color: var(--line); box-shadow: 0 10px 30px rgba(20,30,50,.10); }
.lockscreen .hintbox h2 { display: flex; align-items: center; gap: 8px; }
.lockscreen .hintbox h2::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-2); box-shadow: 0 0 0 4px rgba(47,111,179,.14);
}
#lockText { margin: 0 0 16px; }
#btnReauth { width: auto; padding: 8px 18px; }
/* 上锁后翻页、缩放、划词都没有意义，直接收起，免得点了报错 */
body[data-locked="1"] .anntools,
body[data-locked="1"] .pager,
body[data-locked="1"] .zoom { display: none; }

/* ---------------- 右侧面板 ---------------- */
.panel {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 15px;
  background: #fff;
}
.card h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .3px; color: var(--accent); }
.card .hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.65; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
input[type=text], input[type=email] {
  display: block; width: 100%; margin-top: 5px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; color: var(--ink); background: #fcfdfe;
}
input:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(47,111,179,.12); }

button.primary {
  width: 100%; padding: 9px 12px; border: none; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 13.5px; font-weight: 600; cursor: pointer;
}
button.primary:hover { background: #0f3567; }
button.primary:disabled { background: #9fb2c9; cursor: default; }

button.ghost {
  display: block; width: 100%; text-align: left;
  padding: 9px 11px; margin-bottom: 7px;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fbfcfd; color: var(--ink); font-size: 12.5px; cursor: pointer;
}
button.ghost:hover { background: #f2f6fb; border-color: #cfd8e3; }
button.ghost.danger { color: var(--warn); }
button.ghost.danger:hover { background: #fdf5f4; }

.kv { display: grid; grid-template-columns: 78px 1fr; gap: 7px 10px; margin: 0; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); word-break: break-all; }
.kv dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
.kv dd.ok { color: var(--ok); }

.msg { font-size: 12px; line-height: 1.6; margin-top: 8px; min-height: 0; }
.msg:empty { display: none; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--warn); }
.msg.info { color: var(--muted); }

/* ---------------- 激活模式切换 ---------------- */
.modetabs { display: flex; gap: 6px; margin: 10px 0 12px; }
.modetab {
  flex: 1; padding: 7px 8px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: #fbfcfd;
  color: var(--muted); font-size: 12px;
}
.modetab.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------------- 恢复码 ---------------- */
.card.warn { border-color: #f0c98a; background: #fffaf1; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px; letter-spacing: 1.5px; font-weight: 700;
  color: #8a5a00; background: #fff; border: 1px dashed #e3b871;
  border-radius: 7px; padding: 11px 12px; text-align: center; margin: 4px 0 10px;
  user-select: all;
}
.rowbtns { display: flex; gap: 7px; }
.rowbtns button { margin-bottom: 0; text-align: center; }

/* ---------------- 设备列表 ---------------- */
.devlist { margin: 2px 0 8px; }
.devitem {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 7px; background: #fbfcfd;
  font-size: 12.5px;
}
.devitem.self { border-color: #bcd3ee; background: #f4f9ff; }
.devitem.gone { opacity: .68; }
.devitem .dname { flex: 1; min-width: 0; }
.devitem .dname b { display: block; font-weight: 600; }
.devitem .dname span { color: var(--muted); font-size: 11px; }
.devitem .dact { flex: none; }
.devitem .dact button {
  width: auto; margin: 0; padding: 4px 9px; font-size: 11.5px;
  border-radius: 6px; border: 1px solid var(--line); background: #fff;
  color: var(--warn); cursor: pointer;
}
.devitem .dact button:hover { background: #fdf5f4; }
.tagself {
  display: inline-block; margin-left: 5px; padding: 1px 6px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 10px;
}
.tagdead {
  display: inline-block; margin-left: 5px; padding: 1px 6px;
  border-radius: 9px; background: #e6ebf2; color: var(--muted); font-size: 10px;
}
.note ul li.ok { color: var(--ok); }

.note { background: #fbfcfd; }
.note ul { margin: 0; padding-left: 17px; color: var(--muted); font-size: 12px; line-height: 1.85; }

/* ---------------- 批注工具条 ---------------- */
.anntools { display: flex; gap: 4px; }
.toolbtn {
  padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); font-size: 12px; cursor: pointer;
}
.toolbtn:hover { border-color: #cfd8e3; }
.toolbtn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.toolbtn.danger { color: var(--warn); }

/* ---------------- 文字层 ----------------
 * 文字本身是透明的：用户看到的是底下的页面图片，
 * 但选中的是这一层真实文本，所以能划词、能划句高亮。
 */
.tlayer { position: absolute; inset: 0; overflow: hidden; z-index: 2; }
.tlayer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  line-height: 1;
  overflow: hidden;
  user-select: text;
  cursor: text;
}
.tlayer ::selection { background: rgba(47,111,179,.30); }

/* ---------------- 批注层 ---------------- */
.alayer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.alayer .mark { position: absolute; border-radius: 2px; pointer-events: auto; cursor: pointer; }
.alayer .mark.hl { background: rgba(255, 209, 92, .42); mix-blend-mode: multiply; }
.alayer .mark.hl.hasnote { background: rgba(255, 178, 62, .55); }
.alayer .mark.box { border: 1.5px solid rgba(47,111,179,.8); background: rgba(47,111,179,.06); }
.alayer .mark.srch { background: rgba(28,122,74,.26); }
.alayer .mark .num {
  position: absolute; right: -7px; top: -7px;
  min-width: 14px; height: 14px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 9px; line-height: 14px;
  text-align: center; padding: 0 3px;
}
.page .pnum { z-index: 4; }

.annpop {
  position: absolute; z-index: 40; width: 244px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); padding: 10px;
}
.annpop .qtext {
  font-size: 11.5px; color: var(--muted); margin-bottom: 7px; line-height: 1.5;
  border-left: 2px solid var(--line); padding-left: 7px; max-height: 46px; overflow: hidden;
}
.annpop textarea {
  width: 100%; min-height: 62px; resize: vertical;
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px;
  font-size: 12.5px; font-family: inherit; color: var(--ink);
}
.annpop .row { display: flex; gap: 6px; margin-top: 8px; }
.annpop .row button {
  flex: 1; padding: 6px; font-size: 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: #fbfcfd; color: var(--ink);
}
.annpop .row button.save { background: var(--accent); color: #fff; border-color: var(--accent); }
.annpop .row button.del { color: var(--warn); }

.annhead {
  display: flex; align-items: center; justify-content: space-between;
  margin: 12px 0 8px; font-size: 12px; color: var(--muted);
}
.anncount { background: #eef2f7; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.annlist { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; }
.annitem {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px;
  font-size: 12px; line-height: 1.55; cursor: pointer; background: #fbfcfd;
}
.annitem:hover { border-color: #cfd8e3; background: #f3f7fc; }
.annitem .p { color: var(--accent-2); font-weight: 600; margin-right: 5px; }
.annitem .q { color: var(--muted); }
.annempty { font-size: 12px; color: var(--muted); padding: 6px 2px; }

/* 划词后的浮动按钮 */
.selbtn {
  position: fixed; z-index: 60;
  padding: 6px 13px; min-width: 52px; min-height: 28px;
  border-radius: 6px;
  background: var(--accent); color: #fff; border: none;
  font-size: 12px; line-height: 16px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(16, 24, 40, .22);
  touch-action: none;          /* 移动端别让手势抢走 pointerdown */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.selbtn:active { background: #0f3567; }

/* 框选模式下不要触发文字选择，否则会跟拖拽打架 */
body[data-tool="box"] .tlayer { user-select: none; pointer-events: none; }
body[data-tool="box"] .page { cursor: crosshair; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  .stage { height: 62vh; }
}

/* 批注云端备份 */
.notesbox {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.noteshead {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.notesstate { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef2f7; }
.notesstate.on { background: #e8f3ec; color: #1f6b3f; }
.notesstate.wait { background: #fdf3e2; color: #8a5a12; }
.notesbtns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.notesbtns button { flex: 0 0 auto; }
.notesformtitle { font-size: 12px; color: var(--ink); margin: 10px 0 6px; font-weight: 600; }
#notesForm input {
  width: 100%; box-sizing: border-box; margin-bottom: 6px;
  padding: 7px 9px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 7px; background: #fbfcfd; color: var(--ink);
}
#notesForm input:focus { outline: none; border-color: var(--accent); background: #fff; }

/* hidden 必须压得住 button.ghost 的 display:block。
   少了这条，该收起的按钮会全部露在界面上（批注备份区踩过）。 */
[hidden] { display: none !important; }

/* 检索导航：一行放「上一条 / 第 3 / 12 处 / 下一条」 */
.searchnav { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; }
.searchnav button.ghost {
  width: auto; flex: 1; margin: 0; padding: 6px 8px;
  text-align: center; font-size: 12px;
}
.searchnav button.ghost:disabled { color: #b8c2cf; cursor: default; background: #fbfcfd; border-color: var(--line); }
.searchpos {
  flex: 0 0 auto; min-width: 64px; text-align: center;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
}
/* 当前定位到的那一处要能一眼找到，不然跳过去看不出跳到了哪 */
.alayer .mark.srch.on { background: rgba(255,168,38,.62); box-shadow: 0 0 0 2px rgba(170,90,0,.45); }

/* ---------------- 生产模式 ----------------
   读者看到的应该是产品，不是原型：验证卡、运行状态、本机 ID、文档切换器一律收起。
   由服务器 /config.js 下发 prod 标志，静态文件不用为环境改代码。 */
body[data-prod="1"] #diagCard,
body[data-prod="1"] #stateCard,
body[data-prod="1"] .card.note,
body[data-prod="1"] .devonly,
body[data-prod="1"] .brand .tag,
body[data-prod="1"] #docSelect { display: none !important; }

/* ---------------- 手机提示 ----------------
   窄屏不提供阅读，只说明为什么。挡在生成密钥之前，手机上不留设备记录。 */
.mgate {
  position: fixed; inset: 54px 0 0 0;
  display: flex; align-items: center; justify-content: center;
  padding: 28px 22px 40px;
  background: var(--bg);
  z-index: 30;
  overflow: auto;
}
.mgatebox { max-width: 430px; }
.mgateicon { width: 46px; height: 40px; color: var(--accent-2); display: block; margin-bottom: 18px; }
.mgatebox h2 { margin: 0 0 14px; font-size: 19px; line-height: 1.45; }
.mgatebox p { margin: 0 0 10px; color: #3d4552; line-height: 1.85; font-size: 14px; }
.mgatebox .mgatelast { color: var(--muted); }
.mgatefoot { margin-top: 24px; font-size: 12px; color: #9aa3ae; letter-spacing: .3px; }

/* 挡在门外时，翻页、缩放、划词都没有对象，收起来 */
body[data-gate="1"] .topbar .tools,
body[data-gate="1"] .topbar .docline,
body[data-gate="1"] .layout { display: none !important; }
