:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1c2421; --muted: #6b7570; --line: #e4e2db;
  --brand: #0f5c4d; --brand-2: #127a65; --brand-soft: #e3f0ec; --accent: #f59e0b;
  --danger: #c2410c; --danger-soft: #fdecdf; --warn-soft: #fef6e0; --ok: #15803d;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,30,25,.06), 0 2px 10px rgba(20,30,25,.05);
  --tabh: 58px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111614; --card: #1b2220; --ink: #e9eeec; --muted: #94a19c; --line: #2b3431;
    --brand: #3fb89a; --brand-2: #56c9ab; --brand-soft: #1d3a33; --danger: #fb923c; --danger-soft: #3a2418;
    --warn-soft: #3a3116; --shadow: none; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { padding-top: calc(52px + var(--safe-t)); padding-bottom: calc(var(--tabh) + var(--safe-b) + 16px); }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }
.hidden, [hidden] { display: none !important; }

#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: calc(52px + var(--safe-t));
  padding: var(--safe-t) 8px 0; display: flex; align-items: center; gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); }
#title { flex: 1; font-size: 18px; margin: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { background: none; border: 0; font-size: 34px; line-height: 1; padding: 0 10px 4px; color: var(--brand); cursor: pointer; }
#topright { display: flex; gap: 6px; padding-right: 4px; }

#view { max-width: 760px; margin: 0 auto; padding: 8px 14px; }

#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-around;
  height: calc(var(--tabh) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); }
#tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#tabs a.active { color: var(--brand); }
#tabs a.cap b { display: grid; place-items: center; width: 50px; height: 50px; margin-top: -20px; border-radius: 50%;
  background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(15,92,77,.35); }
#tabs a.cap b svg { width: 26px; height: 26px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.right { text-align: right; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 12px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 10px 14px; border-radius: 11px; font-weight: 600; font-size: 15px; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.huge { padding: 18px; font-size: 18px; border-radius: 16px; }
.btn:disabled { opacity: .5; }
.linkbtn { background: none; border: 0; color: var(--brand); padding: 6px; font-weight: 600; cursor: pointer; }

label.f { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=search],
input[inputmode], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card);
  font-size: 16px; margin-top: 5px; -webkit-appearance: none; appearance: none; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); }

.seg { display: flex; background: var(--line); border-radius: 11px; padding: 3px; margin-top: 6px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.cat { background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.badge.cat::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.badge.fsa { background: #e0ecff; color: #1d4ed8; }
.badge.hsa { background: #efe5ff; color: #6d28d9; }
.badge.work { background: #fff1d6; color: #9a5b00; }
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.warn { background: var(--warn-soft); color: #a16207; }
.badge.err { background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .badge.fsa { background: #1e2c4a; color: #93b4ff; } .badge.hsa { background: #2c2147; color: #c4a7ff; }
  .badge.work { background: #fff1d6; color: #9a5b00; }
.badge.ok { background: #173323; color: #6ee7a0; }
}

/* receipt list */
.rlist { display: flex; flex-direction: column; gap: 8px; }
.ritem { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink); }
.thumb { width: 52px; height: 64px; flex: none; border-radius: 8px; background: var(--line) center top / cover no-repeat;
  display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.ritem .m { font-weight: 650; }
.ritem .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.ritem .badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.ritem.sel { outline: 2px solid var(--brand); }
.check { width: 24px; height: 24px; flex: none; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; }
.ritem.sel .check { background: var(--brand); border-color: var(--brand); color: #fff; }

/* messages */
.msg { border-left: 4px solid var(--accent); }
.msg.duplicate { border-left-color: #2563eb; }
.msg.failed, .msg.email { border-left-color: var(--danger); }
.msg .title { font-weight: 650; }
.msg .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.dups { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.dup { border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.dup .thumb { width: 100%; height: 110px; }

/* capture */
.pages { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x mandatory; }
.page { position: relative; flex: none; width: 130px; scroll-snap-align: start; }
.page img { width: 130px; height: 175px; object-fit: cover; object-position: top; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.page .tools { display: flex; justify-content: space-between; margin-top: 4px; }
.page .num { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 7px; }
.pdfbox { width: 130px; height: 175px; border-radius: 10px; border: 1px dashed var(--line); display: grid; place-items: center; text-align: center; padding: 8px; font-size: 13px; }
.camzone { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* detail */
.pageview { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -14px; padding: 0 14px 6px; }
.pageview img { height: 340px; max-width: 88vw; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); background: #fff; scroll-snap-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-child { border-top: 0; }
.item .top { display: flex; gap: 8px; }
.item .top input.d { flex: 1; margin: 0; }
.item .top input.a { width: 96px; margin: 0; text-align: right; }
.item .sub { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.item .sub select { flex: 1; margin: 0; padding: 7px 28px 7px 10px; font-size: 14px; }
.item .raw { font-size: 12px; color: var(--muted); margin-top: 3px; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.banner { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); }
.banner.err { background: var(--danger-soft); }
.banner.info { background: var(--brand-soft); }
.savebar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + var(--safe-b)); padding: 10px 14px; z-index: 15;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; gap: 10px; max-width: 760px; margin: 0 auto; }

/* library filters */
.searchrow { display: flex; gap: 8px; position: sticky; top: calc(52px + var(--safe-t)); z-index: 5; background: var(--bg); padding: 6px 0 8px; }
.searchrow input { margin: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.listfoot { display: flex; justify-content: space-between; align-items: center; margin: 10px 2px; font-size: 14px; }

/* reports */
.bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 10px 0; color: var(--ink); }
.bar .track { grid-column: 1 / 3; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 99px; }
.mtable { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
.mtable table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 100%; }
.mtable th, .mtable td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.mtable th:first-child, .mtable td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
.mtable tfoot td { font-weight: 700; }
.stat { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* list rows in settings */
.lrow { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.lrow:first-child { border-top: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
input[type=color] { width: 40px; height: 32px; border: 0; padding: 0; background: none; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabh) + var(--safe-b) + 70px); z-index: 50;
  background: #1c2421; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
#toast.err { background: var(--danger); }
#sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); max-width: 760px; margin: 0 auto; }
.sheet-body h3 { margin: 4px 0 8px; }

.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 10px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
