/* ============ PureScan 网页扫描仪 ============ */
:root {
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-faint: #f0fdfa;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --ink: #1c2b33;
  --ink-2: #5b6b76;
  --ink-3: #8b98a3;
  --line: #e3e8ec;
  --danger: #dc2626;
  --radius: 16px;
  --shadow-1: 0 1px 2px rgba(28, 43, 51, .05), 0 4px 14px rgba(28, 43, 51, .06);
  --shadow-2: 0 4px 10px rgba(28, 43, 51, .08), 0 12px 32px rgba(28, 43, 51, .12);
  --topbar-h: 56px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  height: calc(var(--topbar-h) + var(--sat));
  padding: var(--sat) 14px 0 14px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .2px; }
.brand-sub {
  font-size: 12px; color: var(--ink-3); white-space: nowrap;
  padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px;
}
.topbar-actions { display: flex; gap: 8px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 12px; padding: 9px 14px; font-weight: 600; font-size: 14px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, .35);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-soft { background: var(--accent-faint); color: var(--accent-strong); border: 1px solid #bce8e2; }
.btn-soft:hover { background: var(--accent-soft); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: #eef1f3; }
.btn-big { padding: 14px 20px; font-size: 16px; border-radius: 14px; }
.btn-big svg { width: 20px; height: 20px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); transition: background .15s ease, transform .08s ease;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: #eef1f3; }
.icon-btn:active { transform: scale(.93); }

/* ---------- 主舞台 ---------- */
#stage { flex: 1; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; }

/* 空状态 */
#empty-view { align-items: center; justify-content: center; padding: 20px 16px 40px; gap: 26px; }
.hero { text-align: center; margin-top: 6px; }
.hero-logo {
  width: 64px; height: 64px; margin: 0 auto 14px; color: var(--accent);
  background: var(--accent-faint); border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 1px #bce8e2;
}
.hero-logo svg { width: 36px; height: 36px; }
.hero h1 { margin: 0; font-size: clamp(22px, 4.5vw, 30px); font-weight: 800; letter-spacing: .3px; }
.hero-sub { margin: 10px 0 0; color: var(--ink-2); font-size: 14px; }

.dropzone {
  width: min(560px, 100%);
  background: var(--surface);
  border: 1.5px dashed #b8c4cc;
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 10px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.dropzone.dragover {
  border-color: var(--accent); background: var(--accent-faint);
  box-shadow: 0 0 0 4px rgba(13, 148, 136, .12), var(--shadow-1);
}
.dz-inner { padding: 22px 18px; }
.dz-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.dz-hint { margin: 16px 0 0; text-align: center; color: var(--ink-3); font-size: 12.5px; }

.features {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(4, auto); gap: 8px 22px;
  justify-content: center;
}
.features li { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.features b { font-size: 13.5px; color: var(--ink); }
.features span { font-size: 12px; color: var(--ink-3); }

/* ---------- 工作台 ---------- */
#workbench-view { min-height: 0; }
.wb-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pages-panel { order: 3; border-top: 1px solid var(--line); background: var(--surface); }
.pages-strip {
  display: flex; gap: 10px; padding: 10px 12px calc(10px + var(--sab));
  overflow-x: auto; scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.viewer { order: 1; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px; gap: 10px; }
.viewer-canvas-wrap {
  position: relative; flex: 1; min-height: 220px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background-image:
    linear-gradient(45deg, #eceff1 25%, transparent 25%, transparent 75%, #eceff1 75%),
    linear-gradient(45deg, #eceff1 25%, transparent 25%, transparent 75%, #eceff1 75%);
  background-size: 18px 18px; background-position: 0 0, 9px 9px;
}
#preview-canvas { max-width: 100%; max-height: 100%; display: block; touch-action: none; }
.page-badge {
  position: absolute; left: 10px; top: 10px;
  background: rgba(28, 43, 51, .72); color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.detect-flag {
  position: absolute; right: 10px; top: 10px;
  display: flex; align-items: center; gap: 5px;
  background: rgba(13, 148, 136, .92); color: #fff;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px;
  animation: flag-in .25s ease;
}
.detect-flag svg { width: 13px; height: 13px; }
@keyframes flag-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.viewer-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-1); padding: 8px 10px;
}
.vt-group { display: flex; gap: 2px; }
#btn-crop { margin-right: auto; }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  background: #eef1f3; color: var(--ink-2);
  transition: background .15s ease, color .15s ease, transform .08s ease;
}
.chip:active { transform: scale(.94); }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(13,148,136,.35); }

/* 缩略图 */
.thumb {
  position: relative; flex: none;
  width: 74px; height: 74px; border-radius: 12px;
  border: 2px solid transparent; background: #eef1f3;
  overflow: hidden; cursor: pointer; padding: 0;
  transition: border-color .15s ease, transform .1s ease;
}
.thumb:active { transform: scale(.94); }
.thumb.current { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,.18); }
.thumb img, .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-num {
  position: absolute; left: 4px; top: 4px;
  background: rgba(28,43,51,.72); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px;
}
.thumb-filter {
  position: absolute; right: 4px; bottom: 4px;
  background: rgba(13,148,136,.9); color: #fff;
  font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 6px;
}
.thumb-actions {
  position: absolute; inset: 0; display: none;
  background: rgba(28,43,51,.55); backdrop-filter: blur(1px);
  align-items: center; justify-content: center; gap: 8px;
}
.thumb:hover .thumb-actions, .thumb:focus-within .thumb-actions { display: flex; }
.thumb-actions button {
  width: 30px; height: 30px; border-radius: 8px; color: #fff;
  background: rgba(255,255,255,.18); display: inline-flex; align-items: center; justify-content: center;
}
.thumb-actions button:hover { background: rgba(255,255,255,.32); }
.thumb-actions svg { width: 15px; height: 15px; }
.thumb-add {
  flex: none; width: 74px; height: 74px; border-radius: 12px;
  border: 1.5px dashed #b8c4cc; color: var(--ink-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; background: transparent;
}
.thumb-add svg { width: 20px; height: 20px; }
.thumb-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-faint); }

/* ---------- 桌面布局 ---------- */
@media (min-width: 960px) {
  .wb-layout { flex-direction: row; }
  .pages-panel {
    order: 0; width: 190px; flex: none; border-top: none;
    border-right: 1px solid var(--line); align-self: stretch;
    display: flex; flex-direction: column;
  }
  .pages-strip {
    flex: 1; display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 12px; padding: 14px; overflow-y: auto; align-content: start;
  }
  .viewer { padding: 18px; gap: 12px; }
  .thumb, .thumb-add { width: 100%; height: 110px; }
}

/* ---------- 页脚 ---------- */
.footer {
  padding: 14px 16px calc(14px + var(--sab));
  text-align: center; color: var(--ink-3); font-size: 12.5px;
}
.footer p { margin: 0; }

/* ---------- 模态 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 29, .6);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal-body {
  background: var(--surface); border-radius: 18px;
  box-shadow: var(--shadow-2);
  width: min(460px, 100%); max-height: calc(100dvh - 36px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modal-in .18s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 0; }
.modal-title { font-size: 16.5px; font-weight: 800; }

/* 裁剪编辑器（近全屏） */
#crop-modal { padding: 0; }
.crop-body { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; }
.crop-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sat)) 12px 10px;
  border-bottom: 1px solid var(--line); background: var(--surface);
  gap: 8px;
}
.crop-title { font-size: 14px; font-weight: 700; color: var(--ink-2); text-align: center; flex: 1; }
.crop-stage { position: relative; flex: 1; min-height: 0; background: #10181d; overflow: hidden; }
.crop-stage canvas { position: absolute; left: 0; top: 0; touch-action: none; }
.crop-foot {
  display: flex; gap: 10px; justify-content: space-between; align-items: center;
  padding: 12px 16px calc(12px + var(--sab));
  border-top: 1px solid var(--line); background: var(--surface);
}
.crop-foot .btn-primary { flex: 1; }

/* ---------- 导出选项 ---------- */
.export-body { padding-bottom: 14px; }
#export-pdf-options, #export-img-options { padding: 12px 18px 4px; display: flex; flex-direction: column; gap: 4px; }
.opt-row { display: flex; align-items: center; gap: 14px; padding: 8px 0; }
.opt-label { flex: none; width: 64px; font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  padding: 7px 13px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: #eef1f3; color: var(--ink-2);
  transition: background .15s ease, color .15s ease;
}
.seg-btn.selected { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(13,148,136,.3); }
.opt-note { margin: 4px 0 8px; font-size: 12.5px; color: var(--ink-3); }
.modal-actions { display: flex; gap: 10px; padding: 12px 18px 4px; }
.modal-actions .btn-primary { flex: 1; }

/* ---------- 进度遮罩 ---------- */
.overlay-progress {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(16, 24, 29, .5);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.op-box {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-2);
  padding: 22px 30px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-width: 200px;
}
.op-box p { margin: 0; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3.5px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--sab)); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(420px, calc(100vw - 32px));
}
.toast {
  background: rgba(28, 43, 51, .92); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-2);
  animation: toast-in .2s ease; text-align: center;
}
.toast.err { background: rgba(190, 30, 30, .95); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 窄屏微调 ---------- */
@media (max-width: 420px) {
  .brand-sub { display: none; }
  .topbar-actions .btn { padding: 9px 12px; }
  #btn-export-pdf span { display: none; }
  #btn-export-pdf { padding: 9px 14px; }
  .features { grid-template-columns: repeat(2, auto); gap: 10px 30px; }
  #btn-crop span { display: none; }
  #btn-crop { padding: 9px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
