/* 闪扫 - 扫描文件工具样式 */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #0f172a;
  --text-dim: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --radius: 16px;
  --topbar-h: 56px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}
.hidden { display: none !important; }
.dim { color: var(--text-dim); font-size: 12px; }

/* ===== 视图切换 ===== */
.view {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
.view.active { display: flex; }
.view-dark { background: #000; }

/* ===== 顶栏 ===== */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: #fff; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: #f1f5f9; color: var(--text);
  font-size: 18px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn.light { background: rgba(255,255,255,.18); color: #fff; }
.icon-btn.dim { opacity: .5; }

.btn {
  border: none; border-radius: 10px; cursor: pointer;
  font-size: 15px; padding: 12px 20px;
  background: #f1f5f9; color: var(--text);
}
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: #f1f5f9; }
.btn-danger { background: var(--danger); color: #fff; }

/* ===== 首页 ===== */
.home-main { flex: 1; overflow-y: auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
.install-banner {
  display: flex; align-items: center; gap: 10px;
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: 12px; padding: 12px 14px; margin-bottom: 16px;
}
.install-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.install-text b { font-size: 14px; }
.install-text span { font-size: 12px; color: var(--text-dim); }
.scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.action-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; text-align: center;
  box-shadow: 0 2px 10px rgba(15,23,42,.04);
}
.action-card:active { transform: scale(.97); }
.action-icon { font-size: 34px; line-height: 1; }
.action-card b { font-size: 16px; }
.action-card span { font-size: 12px; color: var(--text-dim); }
.home-tip {
  margin-top: 16px; font-size: 13px; color: var(--text-dim);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; line-height: 1.7;
}
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.cloud-entry {
  margin-top: 16px; padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
}
.cloud-entry:active { background: #f8fafc; }
.cloud-entry-left { display: flex; align-items: center; gap: 12px; }
.cloud-entry-icon {
  width: 42px; height: 42px; border-radius: 12px;
  background: #eff6ff; color: var(--primary);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.cloud-entry-icon.apk {
  background: #ecfdf5; color: #059669;
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
}
.cloud-entry b { font-size: 15px; }
.arrow { color: var(--text-dim); font-size: 22px; }

/* ===== 相机 ===== */
#camera-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #000;
}
.camera-mask { position: absolute; inset: 0; pointer-events: none; }
.camera-top {
  position: absolute; top: calc(env(safe-area-inset-top) + 10px); left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; z-index: 5;
}
.camera-title { color: #fff; font-size: 14px; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.camera-guide {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none; z-index: 3;
}
.guide-frame {
  width: 82%; height: 52%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 8px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.28);
}
.guide-frame::before, .guide-frame::after {
  content: ""; position: absolute; width: 26px; height: 26px;
  border: 4px solid #38bdf8;
}
.guide-frame::before { top: -4px; left: -4px; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.guide-frame::after { bottom: -4px; right: -4px; border-left: none; border-top: none; border-radius: 0 0 8px 0; }
.camera-guide p {
  margin-top: 18px; color: #fff; font-size: 13px;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
}
.camera-bottom {
  position: absolute; bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-evenly; z-index: 5;
}
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.9);
  background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.shutter span {
  width: 56px; height: 56px; border-radius: 50%; background: #fff;
  transition: transform .1s;
}
.shutter:active span { transform: scale(.88); }
.done-btn { padding: 12px 18px; }
.icon-btn.light { width: 44px; height: 44px; font-size: 20px; }

/* ===== 编辑页 ===== */
.edit-main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
.edit-preview-wrap {
  position: relative; background: #0f172a; border-radius: 12px;
  min-height: 200px; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#edit-canvas { max-width: 100%; max-height: 46vh; display: block; }
.edit-loading {
  position: absolute; inset: 0; background: rgba(15,23,42,.55);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 14px; border-radius: 12px;
}
.edit-src-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.edit-src-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.edit-src-box { position: relative; display: flex; justify-content: center; }
#edit-src-img { max-width: 100%; max-height: 30vh; display: block; border-radius: 6px; }
#edit-src-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.corner {
  position: absolute; width: 26px; height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%; background: rgba(37,99,235,.9);
  border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.4);
  cursor: grab; z-index: 4; touch-action: none;
}
.edit-tools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.filter-bar {
  display: flex; gap: 10px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px;
  overflow-x: auto; flex-shrink: 0;
}
.filter-item {
  flex: 1; min-width: 64px;
  border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text); padding: 6px 4px; border-radius: 10px;
}
.filter-item.active { background: #eff6ff; color: var(--primary); font-weight: 600; }
.filter-dot { width: 34px; height: 34px; border-radius: 8px; background: linear-gradient(135deg,#dbeafe,#93c5fd); }
.f-bw { background: linear-gradient(135deg,#fff,#111); }
.f-gray { background: linear-gradient(135deg,#eee,#666); }
.f-none { background: linear-gradient(135deg,#fca5a5,#fdba74); }

/* ===== 文档页 ===== */
.doc-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.doc-name-input {
  flex: 1; border: none; background: transparent; text-align: center;
  font-size: 16px; font-weight: 600; color: var(--text); min-width: 0;
}
.doc-stage {
  flex: 1; position: relative; margin: 12px 14px 0;
  background: #0f172a; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; min-height: 0;
}
#doc-preview { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.doc-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.16); color: #fff; font-size: 22px;
  cursor: pointer;
}
.doc-nav.prev { left: 10px; } .doc-nav.next { right: 10px; }
.doc-page-ind {
  position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px;
  padding: 4px 12px; border-radius: 20px;
}
.doc-page-del {
  position: absolute; top: 12px; right: 12px;
  background: rgba(220,38,38,.85); color: #fff; border: none;
  font-size: 12px; padding: 6px 12px; border-radius: 16px; cursor: pointer;
}
.thumb-bar {
  display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto;
  flex-shrink: 0; min-height: 76px; align-items: center;
}
.thumb {
  width: 56px; height: 72px; border-radius: 8px; object-fit: cover;
  border: 2px solid transparent; cursor: pointer; flex-shrink: 0; background: #fff;
}
.thumb.active { border-color: var(--primary); }
.thumb-add {
  width: 56px; height: 72px; border-radius: 8px; flex-shrink: 0;
  border: 2px dashed var(--border); background: var(--card);
  color: var(--text-dim); font-size: 24px; cursor: pointer;
}
.doc-actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border); flex-shrink: 0;
}
.doc-act {
  border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text); padding: 4px 0;
}
.doc-act:active { opacity: .6; }
.doc-act-icon { font-size: 22px; line-height: 1; }

/* ===== 云端列表 ===== */
.cloud-main { flex: 1; overflow-y: auto; padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); }
.cloud-list { display: flex; flex-direction: column; gap: 10px; }
.cloud-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
  display: flex; align-items: center; gap: 12px;
}
.cloud-item-icon {
  width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
}
.cloud-item-icon.pdf { background: #dc2626; }
.cloud-item-icon.img { background: #2563eb; }
.cloud-item-icon.zip { background: #d97706; }
.cloud-item-info { flex: 1; min-width: 0; }
.cloud-item-info b {
  display: block; font-size: 14px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.cloud-item-info span { font-size: 12px; color: var(--text-dim); }
.cloud-item-ops { display: flex; flex-direction: column; gap: 6px; }
.cloud-item-ops .btn { padding: 5px 10px; font-size: 12px; }
.cloud-empty { text-align: center; padding: 60px 20px; }
.cloud-empty-icon { font-size: 44px; color: #cbd5e1; }
.cloud-empty p { margin-top: 8px; font-size: 14px; }

/* ===== 弹层 / 提示 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  background: var(--card); border-radius: 16px;
  max-width: 340px; width: 100%; padding: 22px;
  max-height: 80vh; overflow-y: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 12px; }
.modal p { font-size: 14px; line-height: 1.8; color: var(--text); margin-bottom: 8px; }
.modal .modal-ops { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-ops .btn { flex: 1; }
.modal input[type="text"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; margin-top: 6px;
}
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.88); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 20px; z-index: 200;
  max-width: 80vw; text-align: center;
}
.loading-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  z-index: 150; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
}
.loading-spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #fff; font-size: 14px; }

@media (min-width: 700px) {
  .scan-actions { max-width: 640px; margin: 0 auto; }
  .home-main { max-width: 680px; margin: 0 auto; width: 100%; }
}
