/* ============================================================
   智能表单录入助手 — 移动优先响应式样式
   主色：飞书蓝 #3370FF / 黄 #FFF3CD,#FFC107 / 红 #F5222D
   ============================================================ */

:root {
  --blue: #3370FF;
  --blue-dark: #245bdb;
  --blue-soft: #eaf0ff;
  --yellow-bg: #FFF3CD;
  --yellow-line: #FFC107;
  --red: #F5222D;
  --red-soft: #fff1f0;
  --ink: #1f2329;
  --ink-2: #646a73;
  --ink-3: #8f959e;
  --line: #e5e6eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(31, 35, 41, 0.06);
  --maxw: 560px;
}

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

/* 关键修复：带 hidden 属性的元素必须真正隐藏。
   否则 .overlay/.lightbox/.toast 等的 display:flex 会覆盖 hidden，
   导致"识别中…"遮罩从加载起就一直显示、永远关不掉。!important 确保 hidden 生效。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: var(--blue);
  color: #fff;
}
.topbar__back {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}
.topbar__title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.topbar__back + .topbar__title { margin-right: 40px; }
.topbar__back[hidden] + .topbar__title { margin-right: 0; }

/* ---------- 步骤点 ---------- */
.steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px 0 4px;
  background: var(--bg);
}
.steps__dot {
  width: 22px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  transition: background .2s;
}
.steps__dot.is-active { background: var(--blue); }

/* ---------- 屏容器 ---------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  width: 100%;
}
.screen {
  display: none;
  flex-direction: column;
  min-height: calc(100dvh - 52px - 30px);
  padding: 0;
}
.screen.is-active { display: flex; }
.screen--center .screen__body {
  justify-content: center;
  text-align: center;
}
.screen__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 24px;
}
.screen__heading {
  margin: 4px 0 4px;
  font-size: 20px;
  font-weight: 700;
}
.screen__sub {
  margin: 0 0 16px;
  color: var(--ink-2);
  font-size: 13px;
}
.screen__foot {
  position: sticky;
  bottom: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.screen__foot--hint {
  text-align: center;
  color: var(--ink-3);
  font-size: 12px;
  border-top: 1px dashed var(--line);
  background: transparent;
}

/* ---------- 模板卡片 ---------- */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.tmpl-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.tmpl-card:active { transform: scale(.99); }
.tmpl-card:hover { border-color: var(--blue); }
.tmpl-card__icon {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--blue-soft);
  font-size: 22px;
}
.tmpl-card__body { flex: 1; min-width: 0; }
.tmpl-card__name { font-size: 16px; font-weight: 600; }
.tmpl-card__desc {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tmpl-card__arrow { color: var(--ink-3); font-size: 22px; }

.loading-inline { padding: 24px 0; text-align: center; color: var(--ink-3); }

/* ---------- 拍照按钮 ---------- */
.shoot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 200px;
  padding: 24px;
  background: var(--card);
  border: 2px dashed var(--blue);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
}
.shoot:active { background: var(--blue-soft); }
.shoot__input { display: none; }
.shoot__icon { font-size: 48px; }
.shoot__text { font-size: 16px; font-weight: 600; color: var(--blue); }
.shoot__hint { font-size: 12px; color: var(--ink-3); }

.preview { margin-top: 16px; text-align: center; }
.preview__img {
  width: 100%;
  max-height: 46vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #000;
  border: 1px solid var(--line);
}
.preview__retake {
  margin-top: 10px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- 原图查看 ---------- */
.orig-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  margin-bottom: 14px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
}
.orig-toggle__thumb {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--line);
}

/* ---------- 字段表单 ---------- */
.fieldform { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.field__req { color: var(--red); margin-left: 2px; }
.field__input {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.field__input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(51, 112, 255, .12);
}
.field__msg {
  font-size: 12px;
  color: var(--ink-3);
  min-height: 0;
}

/* 状态：空 -> 黄底 */
.field.is-empty .field__input {
  background: var(--yellow-bg);
  border-color: var(--yellow-line);
}
.field.is-empty .field__msg { color: #9a7a00; }

/* 状态：格式错 -> 红框红字 */
.field.is-error .field__input {
  background: var(--red-soft);
  border-color: var(--red);
}
.field.is-error .field__input:focus {
  box-shadow: 0 0 0 3px rgba(245, 34, 45, .12);
}
.field.is-error .field__msg { color: var(--red); font-weight: 500; }

/* 状态：正常 -> 隐藏占位提示 */
.field.is-ok .field__msg { display: none; }

/* ---------- 查重 ---------- */
.dedup-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 14px;
}
.dedup-banner--new { background: var(--blue-soft); color: var(--blue-dark); }
.dedup-banner--exist { background: var(--yellow-bg); color: #8a6d00; }
.dedup-banner__icon { font-size: 18px; line-height: 1.3; }

.dedup-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.sum-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.sum-row__k { color: var(--ink-2); font-size: 13px; }
.sum-row__v { font-weight: 600; text-align: right; word-break: break-all; }

/* 对比表 */
.cmp-hint { font-size: 12px; color: var(--ink-2); margin: 0 0 8px; }
.cmp-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.cmp-table th {
  background: #fafbfc;
  color: var(--ink-2);
  font-weight: 600;
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
.cmp-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  word-break: break-all;
}
.cmp-table tr:last-child td { border-bottom: 0; }
.cmp-table .col-chk { width: 34px; text-align: center; }
.cmp-table .cell-old { color: var(--ink-3); }
.cmp-table .cell-new { color: var(--ink); font-weight: 500; }
.cmp-row.is-diff { background: #fffdf5; }
.cmp-row.is-diff .cell-new { color: var(--blue-dark); font-weight: 600; }
.cmp-table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}
.cmp-field { font-weight: 600; }
.cmp-toolbar {
  display: flex;
  gap: 14px;
  margin: 10px 2px 0;
  font-size: 13px;
}
.cmp-toolbar button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 0;
}

/* ---------- 成功 ---------- */
.success { align-items: center; }
.success__check {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  box-shadow: 0 6px 20px rgba(51, 112, 255, .35);
}
.success__title { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.success__line { margin: 0; color: var(--ink-2); font-size: 15px; }
.success__meta { margin-top: 14px; color: var(--ink-3); font-size: 12px; word-break: break-all; }

/* ---------- 按钮 ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:active { background: var(--blue-dark); }
.btn--primary:disabled { background: #a9c0ff; cursor: not-allowed; }
.btn--ghost {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn + .btn { margin-top: 10px; }

/* ---------- 遮罩 / 加载 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(2px);
}
.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--blue-soft);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay__text { color: var(--ink-2); font-size: 14px; }

/* ---------- 原图遮罩 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .9);
  padding: 20px;
}
.lightbox__img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox__close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  max-width: 86%;
  padding: 10px 16px;
  background: rgba(31, 35, 41, .92);
  color: #fff;
  font-size: 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- 宽屏微调 ---------- */
@media (min-width: 600px) {
  .screen__body { padding: 24px 24px 28px; }
  body { font-size: 16px; }
}
