/* ---- 账本设计令牌 ---- */
:root {
  --paper: #F7F5EF;        /* 纸白 */
  --card: #FFFFFF;
  --ink: #22201B;          /* 墨 */
  --ink-2: #6E6A60;        /* 淡墨 */
  --mute: #8A8478;         /* 灰褐 */
  --verm: #BE2E22;         /* 朱砂 */
  --verm-weak: rgba(190, 46, 34, .14);  /* 账本格线 */
  --green: #1F8A4D;        /* 竹青（收入），已过对比度/色觉校验 */
  --hairline: rgba(34, 32, 27, .09);
  --tabbar-h: 56px;
  --num: "SF Mono", "Cascadia Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans",
    "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

button, input, select {
  font: inherit; color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible { outline: 2px solid var(--verm); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- 登录页 ---- */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 28px; padding: 24px;
}
.login-mark { width: 84px; height: 84px; border-radius: 18px; }
.login-title { font-size: 22px; font-weight: 600; letter-spacing: .12em; }
.login-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; }
.field {
  width: 100%; padding: 13px 14px; border: 1px solid var(--hairline);
  border-radius: 10px; background: var(--card); font-size: 16px;
}
.field:focus { border-color: var(--verm); outline: none; }
.btn-primary {
  padding: 13px; border: none; border-radius: 10px;
  background: var(--verm); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { filter: brightness(.92); }
.btn-primary[disabled] { opacity: .55; }
.login-error { color: var(--verm); font-size: 13px; min-height: 20px; text-align: center; }

/* ---- 应用壳 ---- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper); border-bottom: 1px solid var(--hairline);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.app-header h1 { font-size: 17px; font-weight: 600; letter-spacing: .06em; }
main { padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); max-width: 720px; margin: 0 auto; }
.page { display: none; animation: fadein .18s ease; }
.page.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* 底部 Tab */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--hairline);
  display: flex;
}
.tabbar button {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--mute); font-size: 11px;
}
.tabbar button.active { color: var(--verm); font-weight: 600; }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* 回单卡（月度汇总签名元素） */
.receipt {
  background: var(--card); border-radius: 12px; padding: 16px;
  border: 1px solid var(--hairline);
  position: relative; margin-bottom: 14px;
}
.receipt::after {   /* 裁切虚线 */
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 7px;
  border-bottom: 2px dashed var(--verm-weak);
}
.receipt .label { font-size: 12px; color: var(--mute); letter-spacing: .08em; }
.receipt .total { font-size: 32px; font-weight: 700; margin: 2px 0 8px; }
.receipt .sub { display: flex; gap: 18px; font-size: 13px; color: var(--ink-2); padding-bottom: 8px; }

/* 账本列表 */
.ledger { background: var(--card); border-radius: 12px; border: 1px solid var(--hairline); overflow: hidden; }
.ledger .day {
  padding: 8px 14px 4px; font-size: 12px; color: var(--mute);
  letter-spacing: .06em; border-bottom: 1px solid var(--verm-weak);
}
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--verm-weak);
}
.row:last-child { border-bottom: none; }
.row .mid { flex: 1; min-width: 0; }
.row .title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 12px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-size: 16px; font-weight: 600; }
.row .amt.in { color: var(--green); }

/* 印章：不必要支出 */
.seal {
  display: inline-block; font-size: 10px; color: var(--verm);
  border: 1.5px solid var(--verm); border-radius: 3px; padding: 0 3px;
  transform: rotate(-6deg); font-weight: 700; letter-spacing: .1em;
  opacity: .85; margin-left: 6px; vertical-align: 1px;
}

.empty { text-align: center; color: var(--mute); padding: 48px 0; font-size: 14px; }
.section-title { font-size: 13px; color: var(--mute); letter-spacing: .08em; margin: 18px 2px 8px; }

/* 月份切换 */
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav button {
  border: none; background: none; color: var(--ink-2); font-size: 18px;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}
.month-nav button:active { background: var(--verm-weak); }
.month-nav .cur { font-size: 15px; font-weight: 600; min-width: 76px; text-align: center; }

/* 筛选行 */
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--hairline); background: var(--card); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.chip.on { border-color: var(--verm); color: var(--verm); font-weight: 600; }
.search { flex: 1; min-width: 120px; border: 1px solid var(--hairline); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; background: var(--card); }

/* 组徽标 / 来源徽标 */
.badge {
  font-size: 10px; padding: 1px 5px; border-radius: 4px; margin-left: 5px;
  background: var(--verm-weak); color: var(--verm); vertical-align: 1px; white-space: nowrap;
}
.badge.src { background: rgba(34,32,27,.06); color: var(--ink-2); }

/* 商品行明细 */
.items { padding: 4px 14px 10px 26px; font-size: 13px; color: var(--ink-2);
  border-bottom: 1px solid var(--verm-weak); }
.items li { display: flex; justify-content: space-between; gap: 10px; list-style: none; padding: 2px 0; }
.items li span:last-child { white-space: nowrap; }

/* 底部操作卡 */
.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: none; }
.sheet-mask.show { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--card); border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .2s ease; max-height: 75dvh; overflow: auto;
}
.sheet.show { transform: none; }
.sheet h3 { font-size: 15px; margin-bottom: 4px; }
.sheet .amt-line { font-size: 24px; font-weight: 700; margin: 6px 0 12px; }
.sheet .kv { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0;
  border-bottom: 1px solid var(--hairline); color: var(--ink-2); gap: 16px; }
.sheet .kv span:first-child { color: var(--mute); white-space: nowrap; }
.sheet .kv span:last-child { text-align: right; word-break: break-all; }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.btn-ghost {
  flex: 1; padding: 11px; border-radius: 10px; border: 1px solid var(--hairline);
  background: var(--card); font-size: 14px; cursor: pointer;
}
.btn-ghost.danger { border-color: var(--verm); color: var(--verm); }

/* 图表 */
.chart-card { background: var(--card); border: 1px solid var(--hairline); border-radius: 12px;
  padding: 14px; margin-bottom: 14px; }
.chart-card h3 { font-size: 13px; color: var(--mute); font-weight: 600; letter-spacing: .06em; margin-bottom: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar-pair { display: flex; align-items: flex-end; gap: 2px; height: 110px; width: 100%; justify-content: center; }
.bar { width: 12px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.exp { background: var(--verm); }
.bar.inc { background: var(--green); }
.bar-col .lbl { font-size: 10px; color: var(--mute); white-space: nowrap; }
.bar-col .val { font-size: 10px; color: var(--ink-2); white-space: nowrap; }
.bar-col.on .val { color: var(--verm); font-weight: 700; }

/* 横向条（分类/商户） */
.hbar-row { display: grid; grid-template-columns: minmax(64px, 30%) 1fr auto; gap: 8px;
  align-items: center; padding: 5px 0; font-size: 13px; }
.hbar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar-track { height: 14px; border-radius: 4px; background: rgba(34,32,27,.05); overflow: hidden; }
.hbar { height: 100%; background: var(--verm); border-radius: 4px; min-width: 2px; }
.hbar-row .v { color: var(--ink-2); }

/* 统计牌 */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--hairline); border-radius: 12px; padding: 12px 14px; }
.tile .label { font-size: 12px; color: var(--mute); }
.tile .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.tile .v.warn { color: var(--verm); }

/* 导入页 */
.drop {
  border: 2px dashed var(--verm-weak); border-radius: 12px; background: var(--card);
  padding: 28px 16px; text-align: center; color: var(--mute); font-size: 14px; cursor: pointer;
}
.drop strong { color: var(--verm); }
.report { background: var(--card); border: 1px solid var(--hairline); border-radius: 10px;
  padding: 10px 12px; margin-top: 10px; font-size: 13px; }
.report .ok { color: var(--green); }
.report .err { color: var(--verm); }
.file-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--hairline); font-size: 13px; }
.file-row:last-child { border-bottom: none; }
.file-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.file-row .m { color: var(--mute); white-space: nowrap; }

/* 设置页 */
.form-card { background: var(--card); border: 1px solid var(--hairline); border-radius: 12px;
  padding: 14px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.form-card h3 { font-size: 14px; }
.form-card .hint { font-size: 12px; color: var(--mute); }
.msg { font-size: 13px; min-height: 18px; }
.msg.ok { color: var(--green); }
.msg.err { color: var(--verm); }

.loadmore { width: 100%; padding: 12px; border: none; background: none; color: var(--verm);
  font-size: 14px; cursor: pointer; }
