:root {
  --brand: #7a4a22;
  --brand-dark: #5c3517;
  --brand-soft: #f6ede3;
  --bg: #f3f1ed;
  --card: #ffffff;
  --text: #211c17;
  --muted: #847b70;
  --line: #e8e3db;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #2e7d32;
  --ok-soft: #e7f4e8;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --radius: 12px;
  --tabbar-h: 60px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", "Noto Sans SC", sans-serif; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 9px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
a { color: var(--brand); }
.icon { flex: none; vertical-align: middle; }

.page { padding: 0 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.form-page { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.loading, .load-error { padding: 40vh 16px 0; text-align: center; color: var(--muted); }
.load-error p { color: var(--danger); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px; height: 52px; margin: 0 -12px; padding: 0 8px; background: var(--bg); }
.tb-title { flex: 1; font-size: 17px; font-weight: 600; padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; gap: 2px; }
.tb-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text); }
.tb-btn:active { background: rgba(0, 0, 0, .06); }
.tb-btn.light { color: #fff; }
.home-logo { width: 30px; height: 30px; border-radius: 8px; margin-left: 4px; }
.home-bar .tb-title { font-size: 19px; letter-spacing: 1px; }

.month-picker { display: flex; align-items: center; gap: 4px; margin: 2px 0 10px; }
.mp-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--card); }
.mp-label { min-width: 92px; text-align: center; font-weight: 600; }
.month-picker .chip { margin-left: auto; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kpis.three { grid-template-columns: 1fr 1fr 1fr; }
.kpi { display: block; text-align: left; background: var(--card); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.kpi-l { font-size: 12px; color: var(--muted); }
.kpi-v { font-size: 20px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpis.three .kpi-v { font-size: 17px; }
.kpi-s { font-size: 11px; color: var(--muted); }
.kpi.warn { background: var(--warn-soft); }
.kpi.warn .kpi-l, .kpi.warn .kpi-v { color: var(--warn); }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

.quick { display: flex; gap: 8px; margin-bottom: 10px; }
.quick .btn { flex: 1; justify-content: center; padding: 10px 6px; }

.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card.flush { padding: 0 14px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 6px; }
.card-h.sub { margin-top: 12px; font-size: 14px; }
.card-h .muted { font-weight: 400; font-size: 13px; }
.row { display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.dim { opacity: .55; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; white-space: nowrap; }
.row-end.col { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.hint { margin-top: 6px; }
.warn-text { color: var(--warn); font-size: 13px; }
.pad { padding: 8px 0 12px; }
.pre { white-space: pre-wrap; }
.empty { padding: 18px 0; text-align: center; color: var(--muted); font-size: 14px; }

.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: #eee; color: #555; vertical-align: 1px; }
.tag.sale { background: #e6f0fa; color: #1f5a92; }
.tag.purchase { background: var(--brand-soft); color: var(--brand-dark); }
.tag.expense { background: #f1ecf8; color: #5b3d8a; }
.badge { font-size: 11.5px; padding: 1px 6px; border-radius: 4px; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; }
.btn:active { background: #f2efe9; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; justify-content: center; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .6; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; font-size: 13.5px; white-space: nowrap; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.filters { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.filters.scroll { overflow-x: auto; scrollbar-width: none; }
.filters .search { flex: 1; padding: 6px 10px; font-size: 14px; border-radius: 999px; }
.sum-line { font-size: 13px; color: var(--muted); margin: 0 2px 8px; }

.fab { position: fixed; right: max(16px, calc(50vw - 264px)); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(90, 50, 20, .3); z-index: 20; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; max-width: 112px; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--muted); }
.tabbar button.on { color: var(--brand); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 80px); transform: translateX(-50%); max-width: 86vw; background: rgba(30, 25, 20, .9); color: #fff; padding: 9px 16px; border-radius: 8px; z-index: 100; font-size: 14px; text-align: center; }

.banner { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* 详情 */
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.dh-party { font-size: 18px; font-weight: 650; }
.dh-amt { font-size: 20px; font-weight: 650; }
.line { padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-sub { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 4px; }
.line-amt { margin-left: auto; color: var(--text); font-size: 15px; }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 4px 0; vertical-align: middle; }
.kv td:last-child { text-align: right; white-space: nowrap; }
.kv tr.total td { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 650; font-size: 17px; }
.kv-foot { text-align: right; margin-top: 8px; }
.inline-num { width: 110px; text-align: right; padding: 5px 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.audit { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.7; }

/* 图片 */
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #eee; display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.new { outline: 2px solid var(--brand); outline-offset: -2px; }
.thumb.add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 1px dashed #c9bfb2; background: #fbf9f6; color: var(--muted); font-size: 11.5px; cursor: pointer; }
.thumb-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff; display: flex; align-items: center; justify-content: center; }
.g-label, .picker-label { font-size: 13px; color: var(--muted); margin: 4px 0 6px; }
.picker + .picker { margin-top: 6px; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; }
.lb-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 4px; padding: 6px 8px; color: #fff; font-size: 14px; }
.lb-bar span { flex: 1; padding-left: 8px; }
.lb-img { max-width: 100%; max-height: calc(100% - 60px); object-fit: contain; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; color: #fff; display: flex; align-items: center; justify-content: center; }
.lb-nav.l { left: 0; }
.lb-nav.r { right: 0; }
.print-only { display: none; }

/* 表单 */
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.field > span a { margin-left: 4px; font-size: 12px; }
.field em, em.err, .err { display: block; font-style: normal; color: var(--danger); font-size: 13px; margin-top: 3px; }
.field small { display: block; margin-top: 4px; font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 0 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 6px; }
.item-edit, .exp-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: #fdfcfa; }
.item-top { display: flex; gap: 6px; margin-bottom: 4px; }
.item-top select { flex: 1; font-weight: 600; }
.row-btns { display: flex; gap: 8px; }
.pay-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.pay-row input, .pay-row select { padding: 7px 6px; font-size: 14px; }
.calc-hint { background: var(--brand-soft); color: var(--brand-dark); border-radius: 8px; padding: 6px 10px; margin-bottom: 10px; font-size: 13.5px; }
.quick-product { margin-top: 10px; padding: 10px; border: 1px dashed #c9bfb2; border-radius: 10px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin: 6px 0; }
.check input { width: auto; margin-top: 4px; }
.save-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: rgba(243, 241, 237, .96); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; max-width: 560px; margin: 0 auto; }

/* 登录 */
.login { padding: 12vh 20px 20px; text-align: center; }
.login-logo { width: 76px; height: 76px; border-radius: 18px; }
.login h1 { margin: 10px 0 0; font-size: 26px; letter-spacing: 2px; }
.login-card { text-align: left; margin-top: 24px; padding: 16px; }

.admin-user { border-bottom: 1px solid var(--line); }
.admin-user:last-of-type { border-bottom: 0; }
.admin-user .row-end .ai-link { padding: 4px 6px; }

/* 拂晓助手 */
.ai-fab { position: fixed; right: max(14px, calc(50vw - 266px)); bottom: calc(var(--tabbar-h) + 84px + env(safe-area-inset-bottom)); z-index: 40; width: 52px; height: 52px; border-radius: 50%; background: #fff; color: var(--brand); border: 1px solid var(--line); box-shadow: 0 4px 14px rgba(70, 40, 15, .18); display: flex; align-items: center; justify-content: center; }
.ai-dot { position: absolute; top: 4px; right: 4px; width: 11px; height: 11px; border-radius: 50%; background: var(--danger); border: 2px solid #fff; }
.ai-panel { position: fixed; inset: 0; z-index: 150; background: rgba(20, 14, 8, .38); display: flex; align-items: flex-end; justify-content: center; }
.ai-sheet { width: 100%; max-width: 560px; height: 92vh; height: 92dvh; background: var(--bg); border-radius: 16px 16px 0 0; display: flex; flex-direction: column; overflow: hidden; }
.ai-head { display: flex; align-items: center; gap: 6px; padding: 8px 6px 8px 14px; background: var(--card); border-bottom: 1px solid var(--line); }
.ai-title { flex: 1; display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 16px; color: var(--brand-dark); }
.ai-link { color: var(--brand); font-size: 14px; padding: 6px 8px; }
.ai-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.ai-welcome { color: var(--muted); font-size: 14px; }
.ai-welcome p { margin: 4px 0 10px; }
.ai-example { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; color: var(--text); font-size: 14px; }
.ai-msg { max-width: 86%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.ai-msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.ai-msg.busy { color: var(--muted); }
.ai-msg.err { align-self: flex-start; background: var(--danger-soft); color: var(--danger); }
.ai-voice { margin-right: 4px; vertical-align: -2px; opacity: .85; }
.ai-card { align-self: stretch; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ai-card.pending { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.ai-card.superseded, .ai-card.cancelled, .ai-card.form { opacity: .5; }
.ai-card.action { padding: 8px; }
.ai-card-h { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
.ai-status { font-size: 12px; font-weight: 400; color: var(--muted); }
.ai-card.saved .ai-status { color: var(--ok); }
.ai-line { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.ai-line:last-of-type { border-bottom: 0; }
.ai-line .k { flex: none; width: 82px; color: var(--muted); }
.ai-line .v { flex: 1; text-align: right; }
.ai-line .v small { display: block; color: var(--muted); font-size: 12px; }
.ai-line.strong .v { font-weight: 650; font-size: 15.5px; }
.ai-line.item { flex-wrap: wrap; gap: 0 10px; }
.ai-line.item .k { width: 100%; color: var(--text); font-weight: 600; }
.ai-warn { margin-top: 6px; background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 5px 8px; font-size: 13px; }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.ai-actions .btn.primary { flex: 1; justify-content: center; }
.ai-input { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.ai-input textarea { flex: 1; resize: none; max-height: 120px; border-radius: 18px; padding: 8px 12px; line-height: 1.4; }
.ai-mic, .ai-send { flex: none; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.ai-mic { background: var(--brand-soft); color: var(--brand); }
.ai-mic:disabled { opacity: .5; }
.ai-send.on { background: var(--brand); color: #fff; }
.ai-rec { flex: 1; display: flex; align-items: center; gap: 8px; height: 40px; color: var(--danger); font-size: 15px; }
.ai-rec small { color: var(--muted); font-size: 12px; }
.ai-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: ai-blink 1s infinite; }
@keyframes ai-blink { 50% { opacity: .25; } }
.ai-sheet { position: relative; }
.ai-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.ai-imgs.in-card { margin: 8px 0 2px; }
.ai-img { display: flex; flex-direction: column; width: 96px; text-align: left; color: inherit; }
.ai-img img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; background: #eee; }
.ai-img span { font-size: 11px; line-height: 1.3; margin-top: 2px; opacity: .9; word-break: break-all; }
.ai-pending { display: flex; gap: 6px; align-items: center; padding: 8px 10px 0; background: var(--card); border-top: 1px solid var(--line); }
.ai-pending .thumb { width: 56px; height: 56px; flex: none; }
.ai-mic.off { opacity: .5; pointer-events: none; }
label.ai-mic { cursor: pointer; }
.ai-zoom { position: absolute; inset: 0; z-index: 5; background: rgba(0, 0, 0, .9); display: flex; align-items: center; justify-content: center; }
.ai-zoom img { max-width: 100%; max-height: 100%; object-fit: contain; }

@media print {
  body { background: #fff; }
  .tabbar, .fab, .topbar button, .no-print, .save-bar { display: none !important; }
  .page { padding: 0; }
  .card { break-inside: avoid; border: 1px solid #ddd; }
  .print-only { display: block; }
  .gallery .thumbs { display: none; }
  .print-img { break-inside: avoid; margin-top: 8px; }
  .print-img img { max-width: 100%; max-height: 95vh; }
}
