:root {
  --paper: #EEF1EC;
  --slip: #FFFFFF;
  --ink: #16202B;
  --ink-2: #33403B;
  --muted: #5F6B66;
  --line: #D9DFD8;
  --line-strong: #BFC8C0;
  --accent: #0A6B56;
  --accent-press: #075544;
  --accent-soft: #DDEFE8;
  --danger: #B3261E;
  --danger-soft: #FBE9E7;
  --warn-bg: #FFF3D1;
  --warn-ink: #5E4100;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 18px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; left: -100px; top: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border-radius: var(--radius-m); border: 1px solid transparent;
  font-size: 16px; font-weight: 600; letter-spacing: .01em;
  background: none; touch-action: manipulation;
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.primary:disabled { background: #9DB6AE; }
.btn.ghost { background: var(--slip); border-color: var(--line-strong); color: var(--ink); }
.btn.ghost:active { background: #F4F6F3; }
.btn.text { min-height: 44px; padding: 0 8px; color: var(--accent); font-weight: 500; }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-col { display: grid; gap: 10px; }
.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: var(--ink-2);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: rgba(22, 32, 43, .07); }

/* ---------- 首次使用 ---------- */
.setup { min-height: 100vh; min-height: 100dvh; padding: calc(var(--safe-t) + 40px) 20px calc(var(--safe-b) + 32px); }
.setup-inner { max-width: 460px; margin: 0 auto; }
.setup-mark { width: 64px; height: 64px; border-radius: 15px; display: block; margin-bottom: 18px; box-shadow: 0 2px 8px rgba(10, 107, 86, .25); }
.setup h1 { font-size: 30px; line-height: 1.2; margin: 0 0 8px; letter-spacing: .02em; }
.setup-lead { margin: 0 0 24px; color: var(--muted); }
.setup-ios { background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius-m); padding: 14px 16px; margin-bottom: 20px; }
.setup-ios p { margin: 4px 0 0; font-size: 14px; }
.card-form { display: grid; gap: 16px; margin-bottom: 16px; }

/* ---------- 首页：顶部像一张小票 ---------- */
.home { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--safe-b) + 96px); max-width: 600px; margin: 0 auto; }
.slip {
  position: relative; background: var(--slip);
  padding: calc(var(--safe-t) + 8px) 20px 18px;
  margin-bottom: 16px;
}
.slip::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -9px; height: 10px;
  background: linear-gradient(-45deg, transparent 7px, var(--slip) 0) 0 0 / 12px 10px repeat-x,
              linear-gradient(45deg, transparent 7px, var(--slip) 0) 0 0 / 12px 10px repeat-x;
}
.slip-top { display: flex; align-items: center; gap: 6px; margin: 0 -8px 10px -6px; }
.period-btn {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 6px;
  border: 0; background: none; font-size: 18px; font-weight: 700; border-radius: var(--radius-s);
}
.period-btn svg { width: 20px; height: 20px; color: var(--muted); }
.period-btn:active { background: rgba(22, 32, 43, .06); }
.period-state { font-size: 13px; color: var(--muted); }
.period-state.closed { color: var(--warn-ink); background: var(--warn-bg); padding: 1px 8px; border-radius: 99px; }
.top-actions { margin-left: auto; display: flex; }
.slip-label { font-size: 13px; color: var(--muted); }
.slip-balance {
  font-size: 44px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin: 2px 0 14px; overflow-wrap: anywhere;
}
.slip-balance.neg { color: var(--danger); }
.slip-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0;
  padding-top: 12px; border-top: 1px dashed var(--line-strong);
}
.slip-stats div { min-width: 0; }
.slip-stats dt { font-size: 12px; color: var(--muted); }
.slip-stats dd { margin: 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ---------- 提示条 ---------- */
.banners { padding: 0 12px; display: grid; gap: 8px; }
.banners:empty { display: none; }
.banners { margin-bottom: 12px; }
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-bg); color: var(--warn-ink);
  border-radius: var(--radius-m); padding: 12px 12px 12px 14px; font-size: 14px;
}
.banner.info { background: var(--accent-soft); color: #0B3D31; }
.banner p { margin: 0; flex: 1; }
.banner .btn { min-height: 36px; padding: 0 12px; font-size: 14px; background: rgba(255,255,255,.7); border-color: transparent; }
.banner .x { min-height: 36px; width: 36px; padding: 0; color: inherit; border: 0; background: none; font-size: 20px; line-height: 1; }

/* ---------- 列表 ---------- */
.list { padding: 0 12px; }
.day { margin-bottom: 14px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 6px 6px; font-size: 13px; color: var(--muted);
}
.day-head .num { font-size: 13px; }
.day-rows { background: var(--slip); border-radius: var(--radius-m); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center;
  width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px;
  min-height: 64px;
}
.row + .row { border-top: 1px solid #EDF0EC; }
.row:active { background: #F6F8F5; }
.badge {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-size: 15px; font-weight: 700; color: var(--c, var(--ink-2)); background: #EDF0EC; background: color-mix(in srgb, var(--c, var(--ink-2)) 13%, white);
}
.badge.in { --c: var(--accent); }
.row-main { min-width: 0; }
.row-title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; white-space: nowrap; overflow: hidden; }
.row-sub .clip { display: inline-flex; align-items: center; gap: 2px; }
.row-sub svg { width: 14px; height: 14px; }
.row-sub .nopic { color: var(--warn-ink); }
.row-amt { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.row-amt.in { color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ---------- 底部操作 ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px;
  padding: 14px 12px calc(var(--safe-b) + 12px);
  background: linear-gradient(to top, var(--paper) 70%, rgba(238, 241, 236, 0));
  max-width: 600px; margin: 0 auto;
}
.actionbar .btn { min-height: 54px; border-radius: 16px; font-size: 17px; }
.actionbar .btn.ghost { box-shadow: 0 1px 2px rgba(22, 32, 43, .06); }
.actionbar .btn.primary { box-shadow: 0 4px 14px rgba(10, 107, 86, .28); }

/* ---------- 全屏表单 ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column;
  background: var(--paper); transform: translateY(100%); transition: transform .24s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet-head {
  flex: none; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: calc(var(--safe-t) + 6px) 8px 6px; background: var(--paper);
}
.sheet-head h2 { margin: 0; text-align: center; font-size: 17px; font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px 24px; display: grid; gap: 18px; align-content: start; grid-auto-rows: max-content; max-width: 600px; width: 100%; margin: 0 auto; }
.sheet-foot { flex: none; padding: 10px 16px calc(var(--safe-b) + 12px); background: var(--paper); border-top: 1px solid var(--line); max-width: 600px; width: 100%; margin: 0 auto; }
.sheet-foot .btn { min-height: 52px; font-size: 17px; }

.field { display: grid; gap: 6px; }
.label { font-size: 13px; color: var(--muted); font-weight: 500; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.hint.err { color: var(--danger); }
input:not([type=checkbox]), select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--slip);
  font-size: 17px; appearance: none; -webkit-appearance: none;
}
input[type=date] { min-height: 48px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10, 107, 86, .18); }
input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(179, 38, 30, .14); }
.amount-input { font-size: 30px !important; font-weight: 700; font-variant-numeric: tabular-nums; min-height: 60px !important; letter-spacing: -.01em; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #DFE4DE; padding: 3px; border-radius: 12px; }
.seg button { min-height: 42px; border: 0; background: none; border-radius: 9px; font-size: 16px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--slip); color: var(--ink); box-shadow: 0 1px 3px rgba(22, 32, 43, .12); }
#f-type button[data-v=in].on { color: var(--accent); }
.seg.small button { min-height: 38px; font-size: 15px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--line-strong);
  background: var(--slip); font-size: 15px; font-weight: 500;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.photos { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px; scrollbar-width: none; }
.photos::-webkit-scrollbar { display: none; }
.ph {
  position: relative; flex: none; width: 88px; height: 112px; border-radius: 10px; overflow: hidden;
  background: #DDE2DC; border: 0; padding: 0;
}
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .rm {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(22, 32, 43, .72); color: #fff; display: grid; place-items: center; padding: 0;
}
.ph .rm svg { width: 14px; height: 14px; }
.ph.busy::after { content: "处理中"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.7); font-size: 13px; color: var(--ink-2); }
.add-ph {
  flex: none; width: 88px; height: 112px; border-radius: 10px; border: 1.5px dashed var(--line-strong);
  background: var(--slip); display: grid; place-content: center; justify-items: center; gap: 4px;
  font-size: 13px; color: var(--ink-2); padding: 0;
}
.add-ph svg { width: 24px; height: 24px; color: var(--accent); }

.qr-box { border-radius: var(--radius-m); padding: 12px 14px; font-size: 14px; background: var(--slip); border: 1px solid var(--line); }
.qr-box.ok { background: var(--accent-soft); border-color: #B9DCCF; color: #0B3D31; }
.qr-box.warn { background: var(--warn-bg); border-color: #F0DB9C; color: var(--warn-ink); }
.qr-box strong { display: block; margin-bottom: 4px; }
.qr-box dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.qr-box dt { color: inherit; opacity: .75; }
.qr-box dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.qr-box .btn { margin-top: 8px; min-height: 40px; font-size: 14px; }
.qr-box .btn.text { padding: 0; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 导出 ---------- */
.tally { width: 100%; border-collapse: collapse; background: var(--slip); border-radius: var(--radius-m); overflow: hidden; font-size: 15px; }
.tally th, .tally td { padding: 10px 14px; text-align: left; font-weight: 400; }
.tally td { text-align: right; font-variant-numeric: tabular-nums; }
.tally tr + tr th, .tally tr + tr td { border-top: 1px solid #EDF0EC; }
.tally tr.total th, .tally tr.total td { font-weight: 700; border-top: 1px dashed var(--line-strong); }
.tally tr.cny th, .tally tr.cny td { color: var(--muted); font-size: 14px; }
.more { background: var(--slip); border-radius: var(--radius-m); padding: 0 14px; }
.more summary { min-height: 48px; display: flex; align-items: center; font-weight: 600; cursor: pointer; list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "展开"; margin-left: auto; font-weight: 400; font-size: 14px; color: var(--accent); }
.more[open] summary::after { content: "收起"; }
.more[open] { padding-bottom: 14px; }
.more .field + .field { margin-top: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.x-result, .x-close { background: var(--slip); border-radius: var(--radius-m); padding: 14px; display: grid; gap: 10px; }
.x-result { border: 1px solid #B9DCCF; }
.file-line { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.file-line strong { overflow-wrap: anywhere; }
.file-line span { color: var(--muted); font-size: 14px; flex: none; }
.x-close p { margin: 0; font-size: 14px; color: var(--muted); }

/* ---------- 设置 ---------- */
.set-group { background: var(--slip); border-radius: var(--radius-m); padding: 14px; display: grid; gap: 12px; }
.set-group h3 { margin: 0; font-size: 16px; }
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list li { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.cat-list li + li { border-top: 1px solid #EDF0EC; }
.cat-list .badge { width: 30px; height: 30px; font-size: 13px; }
.cat-list span.name { flex: 1; }
.cat-list button { min-height: 36px; padding: 0 10px; border: 0; background: none; color: var(--danger); font-size: 14px; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 0; }

/* ---------- 账期 ---------- */
.period-list { list-style: none; margin: 0; padding: 0; background: var(--slip); border-radius: var(--radius-m); overflow: hidden; }
.period-list li + li { border-top: 1px solid #EDF0EC; }
.p-item { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; padding: 12px 14px; border: 0; background: none; }
.p-item:active { background: #F6F8F5; }
.p-item.cur { box-shadow: inset 3px 0 0 var(--accent); }
.p-name { font-weight: 700; font-size: 16px; }
.p-meta { font-size: 13px; color: var(--muted); grid-column: 1; }
.p-bal { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.p-tag { font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }
.p-tag.open { background: var(--accent-soft); color: #0B3D31; }
.p-tag.closed { background: #E7EAE6; color: var(--muted); }
.p-undo { padding: 0 14px 12px; }
.p-undo .btn { min-height: 36px; font-size: 14px; }

/* ---------- 看照片 ---------- */
.viewer { position: fixed; inset: 0; z-index: 40; background: #0D1115; opacity: 0; transition: opacity .18s; }
.viewer.open { opacity: 1; }
.viewer-scroll { position: absolute; inset: 0; overflow: auto; display: grid; place-items: center; touch-action: pan-x pan-y pinch-zoom; }
.viewer img { max-width: 100%; max-height: 100%; display: block; }
.viewer img.zoom { max-width: none; max-height: none; width: 220%; }
.viewer-close { position: absolute; z-index: 2; top: calc(var(--safe-t) + 8px); right: 8px; color: #fff; background: rgba(0,0,0,.45); }

/* ---------- 对话框与提示 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(13, 17, 21, .45); display: grid; place-items: center; padding: 20px; opacity: 0; transition: opacity .16s; }
.modal.open { opacity: 1; }
.modal-card { width: 100%; max-width: 380px; background: var(--slip); border-radius: var(--radius-l); padding: 20px; display: grid; gap: 12px; max-height: 90vh; overflow-y: auto; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-body { font-size: 15px; color: var(--ink-2); display: grid; gap: 12px; }
.modal-body p { margin: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.modal-actions .btn { flex: 1; }
.modal-actions .btn.primary.danger { background: var(--danger); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.toast button { margin-left: 10px; border: 0; background: none; color: #8FE0C8; font-weight: 600; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  .sheet, .viewer, .modal { transition: none; }
  .spin { animation-duration: 2s; }
}
@media (min-width: 640px) {
  .slip { border-radius: 0 0 4px 4px; }
}
