/* 扫描仪 · 界面样式（变量来自 tokens.css） */
html { -webkit-text-size-adjust: 100%; }
body { font-size: 15px; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
input { user-select: text; -webkit-user-select: text; }
.hidden-input { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

/* 触屏尺寸：按钮加高 */
.btn { height: 42px; padding: 0 20px; font-size: 15px; white-space: nowrap; }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13.5px; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.icon-btn { width: 42px; height: 42px; }
.round-btn { width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow-card); color: var(--text); display: inline-flex; align-items: center; justify-content: center; flex: none; transition: transform 0.15s, box-shadow 0.15s; }
.round-btn:active { transform: scale(0.92); }
.input { height: 44px; font-size: 16px; width: 100%; }
.toast-host { top: calc(env(safe-area-inset-top) + 20px); }
.toast { font-size: 14px; }

.view { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); animation: riseIn 0.35s var(--ease-out); }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 72px; }

/* 首页 */
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.big-title { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }
.sub { margin: 6px 0 0; color: var(--text-2); font-size: 15px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.hint { display: flex; align-items: center; gap: 12px; padding: 14px 16px 14px 18px; margin-bottom: 20px; background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow-card); color: var(--text-2); font-size: 14px; line-height: 1.5; }
.hint b { color: var(--text); font-weight: 600; }
.hint .grow { flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px; }
.doc-card { border: 0; padding: 0; text-align: left; background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow-card); overflow: hidden; display: flex; flex-direction: column; transition: transform 0.3s var(--ease-out), box-shadow 0.3s; }
.doc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.doc-card:active { transform: scale(0.98); }
.doc-thumb { aspect-ratio: 3 / 4; background: var(--panel-2); display: flex; align-items: center; justify-content: center; padding: 14px; }
.doc-thumb img { max-width: 100%; max-height: 100%; border-radius: 3px; box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.35); background: #fff; }
.doc-meta { padding: 12px 16px 14px; min-width: 0; }
.doc-name { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info { margin-top: 3px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 90px 20px; color: var(--text-3); font-size: 14px; text-align: center; }
.empty svg { opacity: 0.6; }

/* 文档页 */
.doc-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.doc-title { flex: 1; min-width: 160px; display: flex; flex-direction: column; align-items: flex-start; border: 0; background: transparent; padding: 0; text-align: left; }
.doc-title .name { display: flex; align-items: center; gap: 8px; max-width: 100%; font-size: 24px; font-weight: 600; letter-spacing: -0.03em; }
.doc-title .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-title .name svg { color: var(--text-3); flex: none; }
.doc-title .info { font-size: 13px; color: var(--text-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.page-card { position: relative; }
.page-no { position: absolute; left: 12px; bottom: 12px; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 99px; background: rgba(29, 29, 31, 0.78); color: #fff; font-size: 12.5px; font-weight: 600; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.add-card { border: 0; background: transparent; border-radius: var(--r-lg); box-shadow: inset 0 0 0 1.5px var(--line-strong); color: var(--text-2); aspect-ratio: 3 / 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 14px; font-weight: 500; transition: background 0.15s, color 0.15s; }
.add-card:hover { background: var(--hover); color: var(--text); }

.sync-btn { position: relative; }
.sync-dot { position: absolute; right: 9px; bottom: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--text-4); box-shadow: 0 0 0 2px var(--panel); }
.sync-btn[data-status='ok'] .sync-dot { background: var(--success); }
.sync-btn[data-status='syncing'] .sync-dot { background: var(--primary); }
.sync-btn[data-status='offline'] .sync-dot, .sync-btn[data-status='error'] .sync-dot { background: var(--warning); }
.form-err { min-height: 18px; font-size: 13px; color: var(--danger); }

/* 弹窗 */
.modal { width: 400px; }
.modal-header { cursor: default; }
.modal-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; margin: 24px 24px 0; }
.modal-icon.danger { background: var(--danger-bg); color: var(--danger); }
.modal-footer { justify-content: stretch; }
.modal-footer .btn { flex: 1; height: 44px; }
.btn-red { background: var(--danger); color: #fff; }
.btn-red:hover { background: var(--danger); }
.file-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel-2); border-radius: var(--r); }
.file-row .app-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; }
.file-row .fname { font-weight: 600; font-size: 14.5px; word-break: break-all; user-select: text; -webkit-user-select: text; }
.file-row .finfo { font-size: 12.5px; color: var(--text-3); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* 处理中 */
.busy { position: fixed; inset: 0; z-index: 3500; background: rgba(0, 0, 0, 0.3); display: flex; align-items: center; justify-content: center; animation: fadeIn 0.15s ease-out; }
.busy-card { display: flex; align-items: center; gap: 14px; background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px 24px; font-size: 15px; font-weight: 500; }

/* 全屏深色工作区：裁剪 / 调整 / 查看。只换变量，不写死颜色 */
.editor { --panel: #1c1c1e; --panel-2: #2c2c2e; --fill: #2c2c2e; --fill-hover: #3a3a3c; --text: #f5f5f7; --text-2: #a1a1a6; --text-3: #8e8e93; --hover: rgba(255, 255, 255, 0.08); --primary: #0a84ff; --primary-hover: #409cff; --danger: #ff453a; --danger-bg: rgba(255, 69, 58, 0.14);
  position: fixed; inset: 0; z-index: 2000; background: #000; color: var(--text); display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); animation: fadeIn 0.2s ease-out; }
.ed-top { height: 60px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 14px; }
.ed-title { flex: 1; text-align: center; font-size: 16px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ed-side { width: 96px; display: flex; }
.ed-side.right { justify-content: flex-end; }
.ed-stage { flex: 1; min-height: 0; position: relative; touch-action: none; overflow: hidden; }
.ed-bottom { flex: none; display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px 18px; }
.ed-bottom .spacer { flex: 1; max-width: 40px; }
.editor .icon-btn { color: var(--text); background: var(--fill); }

.crop-box { position: absolute; }
.crop-box canvas { width: 100%; height: 100%; display: block; border-radius: 2px; }
.crop-box svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.crop-mask { fill: rgba(0, 0, 0, 0.5); fill-rule: evenodd; }
.crop-line { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round; }
.crop-handle { cursor: grab; }
.crop-handle .hit { fill: transparent; }
.crop-handle .dot { fill: #fff; stroke: var(--primary); stroke-width: 3; transition: r 0.15s; }
.crop-handle.drag .dot { r: 8; }
.crop-box canvas.loupe { position: absolute; width: 124px; height: 124px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5); pointer-events: none; display: none; background: #000; }
.result-img { position: absolute; inset: 16px; margin: auto; max-width: calc(100% - 32px); max-height: calc(100% - 32px); border-radius: 2px; background: #fff; }

.seg { display: inline-flex; padding: 3px; border-radius: 99px; background: var(--fill); }
.seg button { height: 38px; padding: 0 18px; border: 0; border-radius: 99px; background: transparent; color: var(--text-2); font-weight: 500; font-size: 14.5px; transition: background 0.15s, color 0.15s; }
.seg button.active { background: #636366; color: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }

/* 实时相机 */
.editor { --primary-soft: rgba(10, 132, 255, 0.24); }
.editor .chip { height: 38px; font-size: 14px; }
.cam-box { position: absolute; overflow: hidden; border-radius: 10px; background: #111; }
.cam-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-box svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-quad { fill: rgba(10, 132, 255, 0.14); stroke: var(--primary); stroke-width: 3; stroke-linejoin: round; transition: fill 0.25s; }
.cam-quad.steady { fill: rgba(10, 132, 255, 0.34); }
.cam-side { width: 112px; display: flex; justify-content: center; }
.shutter { position: relative; width: 74px; height: 74px; padding: 0; border: 4px solid #fff; border-radius: 50%; background: transparent; flex: none; }
.shutter::after { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.shutter:active::after { transform: scale(0.86); }
.cam-last { position: relative; width: 54px; height: 54px; padding: 0; border: 0; border-radius: 12px; background: var(--fill) center / cover no-repeat; }
.cam-last .page-no { left: auto; bottom: auto; right: -8px; top: -8px; background: var(--primary); }
.camera.flash .cam-box::after { content: ''; position: absolute; inset: 0; background: #fff; pointer-events: none; animation: camFlash 0.35s ease-out forwards; }
@keyframes camFlash { from { opacity: 0.85; } to { opacity: 0; } }

.nav-arrow { position: absolute; top: 50%; margin-top: -22px; z-index: 2; }
.nav-arrow.prev { left: 12px; }
.nav-arrow.next { right: 12px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 62px; border: 0; background: transparent; color: var(--text); font-size: 12px; font-weight: 500; padding: 6px 4px; border-radius: 12px; transition: background 0.15s, transform 0.15s; }
.tool:hover { background: var(--hover); }
.tool:active { transform: scale(0.94); }
.tool[disabled] { opacity: 0.3; pointer-events: none; }
.tool.danger { color: var(--danger); }

@media (max-width: 760px) {
  .page { padding: 20px 16px 60px; }
  .big-title { font-size: 30px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .hint { flex-wrap: wrap; }
  .ed-side { width: 72px; }
  .seg button { padding: 0 13px; }
}
