/* 视觉隐藏但保留可交互性（iOS Safari 对 display:none 的 file input 调 click() 无反应） */
.file-input-hidden {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* label 按钮（拍照/相册入口，原生触发 file input） */
label.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-size: 15px;
  font-weight: 600; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: #fff; width: 100%;
  -webkit-tap-highlight-color: transparent;
}
label.btn:active { transform: scale(.985); }
label.btn.secondary { background: #eef1f5; color: var(--text); }
label.btn.small { padding: 8px 12px; font-size: 13px; width: auto; }
label.big-fab { font-size: 17px; padding: 16px; }

:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-light: #ccfbf1;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2733;
  --text-2: #5b6b7b;
  --border: #e4e8ee;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --tab-h: 60px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
#app { max-width: 560px; margin: 0 auto; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 22px; }
.app-title { font-weight: 700; font-size: 17px; }
.icon-btn {
  border: 1px solid var(--border); background: var(--card);
  border-radius: 10px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--text);
}

/* ---------- bottom nav ---------- */
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px; margin: 0 auto;
}
.nav-btn {
  flex: 1; border: 0; background: none; padding: 8px 0 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--text-2); font-family: inherit;
}
.nav-btn.active { color: var(--primary); font-weight: 600; }
.nav-ico { font-size: 20px; line-height: 1; }

/* ---------- generic ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 12px 16px;
  box-shadow: var(--shadow);
}
h1.page-title { font-size: 18px; margin: 18px 16px 4px; }
.sub { color: var(--text-2); font-size: 13px; margin: 0 16px 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; }
.center { text-align: center; }

button.btn {
  border: 0; border-radius: 12px; padding: 13px 18px; font-size: 15px;
  font-weight: 600; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: #fff; width: 100%;
}
button.btn:active { transform: scale(.985); }
button.btn.secondary { background: #eef1f5; color: var(--text); }
button.btn.danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
button.btn.small { padding: 8px 12px; font-size: 13px; width: auto; }
button.btn:disabled { opacity: .5; }
.big-fab { font-size: 17px; padding: 16px; }

label.field { display: block; margin-bottom: 14px; }
label.field .label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
label.field .label .req { color: var(--danger); }
input[type=text], input[type=date], input[type=number], input[type=month], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
input[readonly] { background: #f4f6f8; color: var(--text-2); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag.auto { background: #e0f2fe; color: #0369a1; }
.tag.manual { background: #fef3c7; color: #b45309; }
.tag.ok { background: #dcfce7; color: #15803d; }
.tag.warn { background: #fef3c7; color: #b45309; }
.tag.bad { background: #fee2e2; color: #b91c1c; }
.tag.gray { background: #eef1f5; color: #5b6b7b; }

/* ---------- stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .v.small { font-size: 15px; }

/* ---------- record list ---------- */
.rec {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  background: var(--card); border-bottom: 1px solid var(--border); cursor: pointer;
}
.rec:first-of-type { border-top: 1px solid var(--border); }
.rec .thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: #eef1f5; flex: none; }
.rec .thumb.placeholder { display: flex; align-items: center; justify-content: center; font-size: 20px; }
.rec .main { flex: 1; min-width: 0; }
.rec .m1 { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .m2 { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .amt { text-align: right; flex: none; }
.rec .amt .a { font-weight: 700; font-size: 15px; }
.rec .amt .c { font-size: 11px; color: var(--text-2); }

.filter-bar { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; }
.filter-bar button {
  flex: none; border: 1px solid var(--border); background: var(--card); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; color: var(--text-2); font-family: inherit;
}
.filter-bar button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* ---------- images / receipt preview ---------- */
.img-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.img-item { position: relative; }
.img-item img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.img-item .rm { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 0; font-size: 12px; line-height: 1; }

/* ---------- export ---------- */
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; border: 1px solid var(--border); background: var(--card); border-radius: 10px; padding: 10px; font-family: inherit; font-size: 14px; color: var(--text-2); }
.seg button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.check-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.check-item:last-child { border-bottom: 0; }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.set-row .t { font-size: 14px; font-weight: 500; }
.set-row .d { font-size: 12px; color: var(--text-2); }

/* ---------- 页面内相机 ---------- */
.cam-mask { position: fixed; inset: 0; background: #000; z-index: 90; display: flex; flex-direction: column; }
.cam-mask.hidden { display: none; }
.cam-video, #camVideo { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.cam-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px calc(22px + env(safe-area-inset-bottom));
  background: #000;
}
.cam-cancel {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.18); color: #fff; font-size: 18px; font-family: inherit;
}
.cam-shoot {
  width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff;
  background: rgba(255,255,255,.25); position: relative; margin: 0 auto;
}
.cam-shoot::after {
  content: ''; position: absolute; inset: 8px; border-radius: 50%; background: #fff;
}
.cam-shoot:active { transform: scale(.94); }
.cam-spacer { width: 44px; }

/* ---------- toast / dialog ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px); transform: translateX(-50%);
  background: rgba(28, 39, 51, .92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 100; max-width: 86vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.hidden { display: none; }
.dialog-mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; }
.dialog { background: var(--card); border-radius: 16px; padding: 20px; width: 100%; max-width: 400px; max-height: 80vh; overflow: auto; }
.dialog h3 { margin: 0 0 12px; font-size: 16px; }
.dialog .btns { display: flex; gap: 10px; margin-top: 18px; }
.dialog .btns button { flex: 1; }

.banner {
  display: flex; align-items: center; gap: 10px; margin: 12px 16px; padding: 12px 14px;
  border-radius: 12px; font-size: 13px;
}
.banner.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.banner.info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.banner button { margin-left: auto; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-2); }
.empty .ico { font-size: 44px; margin-bottom: 10px; }

.ocr-status { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: #eff6ff; border: 1px solid #bfdbfe; font-size: 13px; color: #1e40af; margin-bottom: 12px; }
.ocr-status .spin { width: 14px; height: 14px; border: 2px solid #bfdbfe; border-top-color: #1e40af; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

fieldset { border: 1px solid var(--border); border-radius: 12px; margin: 0 0 14px; padding: 12px; }
legend { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 0 6px; }
