/* 我的书房 · 扫码登记 —— 手机优先样式 */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #14161a;
  --muted: #6b7280;
  --line: #e7e9ee;
  --primary: #2f6fed;
  --primary-ink: #ffffff;
  --ok: #12a150;
  --warn: #d97706;
  --err: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #171b21;
    --ink: #e8eaed;
    --muted: #9aa3ae;
    --line: #262c35;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：.sheet 设了 display:flex，会盖掉浏览器默认的 [hidden]{display:none} */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  overscroll-behavior-y: none;
}

.app { display: flex; flex-direction: column; height: 100dvh; max-width: 1120px; margin: 0 auto; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: .3px; }
.brand .logo { font-size: 18px; }
.topstat { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 主区 ---------- */
main { flex: 1; overflow-y: auto; padding: 12px 12px 96px; -webkit-overflow-scrolling: touch; }
.view { display: none; }
.view.active { display: block; }

/* ---------- 相机 ---------- */
.cam-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; }
.cam-box {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #0b0e12;
  border-radius: 10px; overflow: hidden; display: flex; align-items: center; justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-idle {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center;
  background: radial-gradient(circle at 50% 45%, #1b2230, #0b0e12 70%); color: #cfd6e0;
}
.cam-idle .hint { color: #8d97a5; font-size: 12px; margin: 0; line-height: 1.6; }
.cam-overlay { position: absolute; inset: 0; pointer-events: none; }
.scan-frame { position: absolute; inset: 14% 8%; border-radius: 10px; }
.corner { position: absolute; width: 26px; height: 26px; border: 3px solid #4ade80; }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }
.laser {
  position: absolute; left: 4%; right: 4%; height: 2px; top: 0;
  background: linear-gradient(90deg, transparent, #4ade80, transparent);
  animation: laser 1.8s ease-in-out infinite;
}
@keyframes laser { 0%,100% { top: 2%; opacity: .2 } 50% { top: 96%; opacity: .95 } }
.cam-tip {
  position: absolute; bottom: 10px; left: 0; right: 0; text-align: center;
  color: #cbd5e1; font-size: 12px; text-shadow: 0 1px 3px #000;
}
.cam-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* ---------- 控件 ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; transition: transform .06s ease, background .15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.xl { padding: 15px 24px; font-size: 16px; border-radius: 12px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.chip {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip[disabled] { opacity: .4; }

.switch { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--primary); }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
textarea { resize: vertical; min-height: 52px; }

/* ---------- 手动输入 ---------- */
.manual { display: flex; gap: 8px; margin-top: 10px; }
.manual input { font-size: 16px; letter-spacing: .5px; }

/* ---------- 扉页 OCR ---------- */
.ocr-row { margin-top: 8px; }
.ocr-panel { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.ocr-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; background: var(--bg); font-size: 12.5px; color: var(--muted);
}
.ocr-head em { font-style: normal; opacity: .7; margin-left: 6px; }
.link { border: 0; background: transparent; color: var(--primary); font-size: 12.5px; cursor: pointer; padding: 0; }
.ocr-text {
  margin: 0; padding: 9px 10px; font-size: 12.5px; line-height: 1.7; white-space: pre-wrap;
  max-height: 190px; overflow-y: auto; color: var(--ink); background: var(--card);
}
.sysinfo { font-size: 13px; }
.sys-row { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.sys-row:last-child { border-bottom: 0; }
.sys-row span { width: 74px; color: var(--muted); font-size: 12.5px; flex: none; }
.sys-row b { font-weight: 600; }
.sys-row em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: auto; text-align: right; }

/* ---------- OCR 引擎选择 ---------- */
.engine-box { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.engine-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg);
}
.engine-row.on { border-color: color-mix(in srgb, var(--primary) 55%, var(--line)); background: color-mix(in srgb, var(--primary) 6%, var(--card)); }
.engine-row input { width: auto; accent-color: var(--primary); }
.engine-row div { display: flex; flex-direction: column; min-width: 0; }
.engine-row b { font-weight: 600; }
.engine-row em { font-style: normal; color: var(--muted); font-size: 12px; }
.engine-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: auto; flex: none; }
.engine-row .dot.off { background: var(--err); opacity: .6; }

/* ---------- 本轮扫描列表 ---------- */
.feed { margin-top: 14px; }
.feed-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; padding: 0 2px; }
.feed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.feed-list .empty { color: var(--muted); font-size: 13px; text-align: center; padding: 22px 0; }
.feed-item {
  display: flex; gap: 10px; align-items: center; background: var(--card);
  border-radius: 12px; padding: 9px 10px; box-shadow: var(--shadow);
  animation: pop .22s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
.feed-item .thumb { width: 38px; height: 52px; border-radius: 5px; object-fit: cover; background: var(--line); flex: none; }
.feed-item .fi-main { min-width: 0; flex: 1; }
.feed-item .fi-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-item .fi-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.badge.new { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.dup { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.miss { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); }
.undo { border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; padding: 4px 6px; }

/* ---------- 书库 ---------- */
.search-row { display: flex; gap: 8px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding-bottom: 8px; }
.search-row input { flex: 1; }
.search-row select { width: 118px; flex: none; }
.lib-stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 2px 2px 10px; }
.lib-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.book-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.book-row {
  display: flex; gap: 10px; background: var(--card); border-radius: 12px; padding: 10px;
  box-shadow: var(--shadow); cursor: pointer; align-items: flex-start;
}
.book-row:active { background: color-mix(in srgb, var(--primary) 5%, var(--card)); }
.book-row .cover { width: 44px; height: 60px; border-radius: 5px; object-fit: cover; background: var(--line); flex: none; }
.book-row .rb-main { min-width: 0; flex: 1; }
.book-row .rb-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.book-row .rb-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-row .rb-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 5px; }
.book-row .rb-price { color: var(--ink); font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 16px 0 4px; font-size: 13px; color: var(--muted); }

/* ---------- 更多 ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h4 { margin: 0 0 10px; font-size: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tips { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--muted); line-height: 1.75; }
.tips b { color: var(--ink); }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.65; margin: 8px 0 0; }
.hint code { background: var(--bg); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.stats-body { font-size: 13.5px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-box { background: var(--bg); border-radius: 10px; padding: 9px 11px; }
.stat-box .k { font-size: 12px; color: var(--muted); }
.stat-box .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12.5px; }
.bar-row .name { width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-row .bar { flex: 1; height: 7px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.bar-row .num { width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 底部标签栏 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); z-index: 30;
}
.tab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; padding: 4px 0; cursor: pointer;
}
.tab i { font-style: normal; font-size: 19px; line-height: 1; filter: grayscale(1) opacity(.65); }
.tab.active { color: var(--primary); font-weight: 600; }
.tab.active i { filter: none; }

/* ---------- 弹层 ---------- */
.sheet-mask { position: fixed; inset: 0; background: rgba(6, 10, 16, .45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--card); border-radius: 18px 18px 0 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .25);
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6 } to { transform: none; opacity: 1 } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 16px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer; padding: 4px 8px; }
.sheet-body { padding: 12px 16px; overflow-y: auto; flex: 1; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
.sheet-search { display: flex; gap: 8px; margin-bottom: 8px; }
.candidates { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.candidates:empty { display: none; }
.cand {
  display: flex; gap: 8px; align-items: center; text-align: left; width: 100%;
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 7px 9px; cursor: pointer;
}
.cand img { width: 30px; height: 42px; object-fit: cover; border-radius: 4px; background: var(--line); }
.cand .c-main { min-width: 0; }
.cand .c-t { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand .c-s { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.isbn-line { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.isbn-line b { color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: .4px; }
.src-tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.grid label.wide { grid-column: 1 / -1; }
.grid input, .grid textarea { width: 100%; }

/* ---------- toast ---------- */
.toasts { position: fixed; top: 12px; left: 0; right: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast {
  max-width: 92%; background: #11161d; color: #f2f5f9; font-size: 13.5px;
  padding: 9px 15px; border-radius: 999px; box-shadow: 0 6px 22px rgba(0, 0, 0, .28);
  animation: toastIn .18s ease; line-height: 1.4;
}
.toast.ok { background: #0f7a3d; }
.toast.warn { background: #a45a06; }
.toast.err { background: #a81b1b; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) } to { opacity: 1; transform: none } }

/* ---------- 宽屏 ---------- */
@media (min-width: 900px) {
  #view-scan.active {
    display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr);
    gap: 16px; align-items: start;
  }
  #view-scan .cam-card { grid-row: span 2; }
  #view-scan .manual { margin-top: 0; }
  #view-scan .feed { margin-top: 0; max-height: calc(100dvh - 230px); overflow-y: auto; }
  .sheet { left: 50%; right: auto; transform: translateX(-50%); width: 720px; border-radius: 18px; bottom: 24px; }
  @keyframes slideup { from { transform: translate(-50%, 30px); opacity: .6 } to { transform: translateX(-50%); opacity: 1 } }
  .sheet-mask { border-radius: 0; }
  .tabbar { max-width: 1120px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}
