:root {
  --brand: #e8641b;
  --brand-dark: #c2510f;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e2e5ea;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--brand); color: #fff;
}
#logoutBtn { padding: 8px 14px; font-size: 14px; }
.brand { font-weight: 700; font-size: 17px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
#langSel { padding: 6px; border-radius: 8px; border: none; }
#mainnav {
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 19;
  display: flex; gap: 4px; overflow-x: auto;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 6px 8px;
}
#mainnav a {
  white-space: nowrap; padding: 8px 12px; border-radius: 999px;
  text-decoration: none; color: var(--text); font-size: 14px;
}
#mainnav a.active { background: var(--brand); color: #fff; }
main { padding: 14px; max-width: 960px; margin: 0 auto 60px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2, .card h3 { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
label.f { display: block; margin-bottom: 10px; font-size: 14px; }
label.f > span { display: block; margin-bottom: 4px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
.btn {
  display: inline-block; padding: 10px 18px; font-size: 15px;
  border: none; border-radius: 10px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600;
}
.btn:active { background: var(--brand-dark); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.ghost { background: #eef0f3; color: var(--text); }
.btn.danger { background: var(--bad); }
.btn:disabled { opacity: .5; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.bad { background: #fee2e2; color: var(--bad); }
.badge.info { background: #e0e7ff; color: #3730a3; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td {
  border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left;
}
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl-wrap { overflow-x: auto; }
.photo-thumb { width: 100%; max-height: 220px; object-fit: contain;
  border-radius: 10px; border: 1px solid var(--border); background: #000; }
.ocr-row { display: flex; gap: 8px; margin-top: 8px; }
.ocr-row .btn { flex: 1; }
.hidden { display: none !important; }
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 20px; border-radius: 10px;
  z-index: 50; font-size: 14px; max-width: 90vw;
}
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box { background: #fff; border-radius: 14px; padding: 24px;
  width: 100%; max-width: 340px; text-align: center; }
.modal-box.wide { max-width: 520px; }
#cropWrap { position: relative; overflow: hidden; border-radius: 10px; background: #111; }
#cropWrap img { width: 100%; display: block; transform-origin: 0 0; touch-action: none; }
#cropBox {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: 2px solid #ff7a1a; border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5);
  aspect-ratio: 3.5 / 1; pointer-events: none;
}
#cropSize { width: 100%; }
.spinner {
  width: 44px; height: 44px; margin: 12px auto;
  border: 4px solid var(--border); border-top-color: var(--brand);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.big-odo { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  max-width: 300px; margin: 12px auto; }
.pinpad .btn { font-size: 22px; padding: 14px 0; }
.pin-display { text-align: center; font-size: 28px; letter-spacing: 12px;
  margin: 8px 0; min-height: 40px; }
.brand-hero { text-align: center; margin-bottom: 16px; }
.brand-hero-logo { font-size: 54px; }
.brand-hero-name { font-size: 30px; font-weight: 800; letter-spacing: 1px;
  background: linear-gradient(135deg, #e8641b, #f5a623);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs .btn { white-space: nowrap; }
.alert { background: #fef3c7; border: 1px solid #fcd34d; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 10px; font-size: 14px; }
.alert.bad { background: #fee2e2; border-color: #fca5a5; }
.kv { display: flex; justify-content: space-between; padding: 6px 0;
  border-bottom: 1px dashed var(--border); font-size: 14px; }

/* ---- live scan (bank-card style auto-lock) ---- */
.scan-box { position: relative; width: min(94vw, 520px); }
#scanVideo { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 14px; background: #000; }
#scanRoi {
  position: absolute; left: 18%; right: 18%; top: 41%; height: 18%;
  border: 3px solid #f59e0b; border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.55); pointer-events: none;
  transition: border-color .2s;
}
#scanRoi.ok { border-color: #22c55e; }
#scanCancel { flex: 1; background: #fff; color: #111; }
#scanSnap { flex: 1; }
#scanGuess {
  position: absolute; left: 8%; right: 8%; top: calc(41% + 18% + 10px);
  text-align: center; color: #fff; font-size: 30px; font-weight: 800;
  letter-spacing: 5px; text-shadow: 0 1px 5px rgba(0,0,0,.85); min-height: 40px;
  font-variant-numeric: tabular-nums;
}
.scan-hint { text-align: center; color: #fff; margin: 12px 0 0; font-size: 14px; }
