:root {
  color-scheme: dark;
  --bg: #231c1a; --card: #302826; --card2: #3a312e; --ink: #f4ede7; --mute: #a0948c; --line: #433936;
  --lime: #cdeb9c; --lime-ink: #25301a; --orange: #f08a5d; --lav: #cbbdf0;
  --brand: var(--lime); --brand-ink: var(--lime-ink); --brand-soft: #3d3a2c;
  --pos: #b9e08a; --neg: #f4a27f; --warn: #f2c26b;
  --tab-h: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tab-h) + 96px + env(safe-area-inset-bottom)); }

/* 頂部 */
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px; background: linear-gradient(var(--bg) 70%, transparent); }
.ledger-btn { font-size: 16px; font-weight: 600; max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--card); border-radius: 10px; padding: 8px 16px; }
.caret { color: var(--mute); font-size: 12px; }
.badge { font-size: 13px; color: var(--mute); background: var(--card); border-radius: 10px; padding: 8px 14px; }
.badge.warn { color: var(--warn); }
main { padding: 0 18px; }

/* 月份 / 分段 */
.mnav { display: flex; align-items: center; gap: 4px; margin: 2px 0 0; color: var(--mute); }
.mnav button { width: 40px; height: 40px; font-size: 24px; color: var(--ink); border-radius: 50%; background: var(--card); }
.mnav b { font-size: 14px; font-weight: 500; flex: 1; text-align: center; }
.seg { display: flex; background: var(--card); border-radius: 12px; padding: 4px; margin: 14px 0; }
.seg button { flex: 1; padding: 9px 0; border-radius: 9px; color: var(--mute); font-weight: 600; }
.seg button.on { background: var(--lime); color: var(--lime-ink); }
.seg.slim { margin: 0 0 10px; }

/* 首頁摘要卡 */
.summary { background: var(--card); border-radius: 14px; padding: 12px 16px 14px; margin: 4px 0 0; }
.summary small { display: block; color: var(--mute); font-size: 12px; margin-top: 6px; }
.sum-top { display: flex; justify-content: space-between; align-items: center; color: var(--mute); font-size: 12px; }
.summary .mnav { margin: 0 0 0 -8px; gap: 2px; }
.summary .mnav button { width: 30px; height: 30px; font-size: 18px; background: none; color: var(--mute); }
.summary .mnav b { flex: none; font-size: 12px; }
.sum-big { display: block; font-size: 30px; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sum-sub { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; color: var(--mute); font-size: 12px; }
.sum-sub b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.sum-sub b.pos { color: var(--pos); }
.sum-bars { display: flex; gap: 2px; align-items: flex-end; height: 40px; margin-top: 12px; }
.sum-bars i { flex: 1; min-width: 0; border-radius: 9px; height: 14%; }
.sum-bars i.none { opacity: .22; }
.sum-bars i.fut { opacity: .08; }

/* 快速記一筆 */
.quick { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 8px; padding: 0 18px; }
.quick::-webkit-scrollbar { display: none; }
.pill { flex: none; background: var(--card); border-radius: 10px; padding: 8px 14px; font-size: 14px; white-space: nowrap; }

/* 卡片 */
.card { background: var(--card); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.card.pad { padding: 16px 18px; }
.card.flat { background: transparent; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.day { display: flex; justify-content: space-between; padding: 10px 8px 8px; color: var(--mute); font-size: 13px; }
.sec { margin: 20px 6px 10px; font-size: 14px; color: var(--mute); font-weight: 600; }

/* 清單列 */
.list .row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; text-align: left; min-height: 60px; }
.list .row + .row { border-top: 1px solid var(--line); }
.row.add { color: var(--lime); }
.row .ico { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: var(--card2); border-radius: 50%; font-size: 17px; }
.row .mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .mid b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { color: var(--mute); font-size: 13px; }
.row .amt { text-align: right; display: flex; flex-direction: column; flex: none; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--mute); padding: 40px 16px; line-height: 1.8; }
.empty.small { padding: 22px 16px; }
.note { color: var(--mute); font-size: 13px; margin: 8px 4px; }
.foot { text-align: center; color: var(--mute); font-size: 12px; margin: 24px 0 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.kv span { color: var(--mute); }
.kv b { text-align: right; word-break: break-all; }
.code { letter-spacing: .15em; font-size: 18px; color: var(--lime); font-variant-numeric: tabular-nums; }

/* 按鈕 */
.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; font-weight: 600; background: var(--card2); color: var(--ink); }
.btn.primary { background: var(--lime); color: var(--lime-ink); }
.btn.ghost { background: var(--card2); color: var(--ink); }
.btn.danger { color: var(--neg); }
.btn.small { min-height: 34px; padding: 0 14px; font-size: 14px; flex: none; }
.row .btn.small:not(.ghost) { background: var(--lime); color: var(--lime-ink); }
.btn.grow { flex: 1; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* 底部大按鈕 */
.cta { position: fixed; left: 50%; transform: translateX(-50%); width: calc(100% - 36px); max-width: 524px;
  bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom)); z-index: 6; display: flex; align-items: center; gap: 12px;
  height: 64px; padding: 0 22px 0 8px; border-radius: 14px; background: var(--lime); color: var(--lime-ink); box-shadow: 0 8px 28px rgba(0, 0, 0, .35); }
.cta i { width: 48px; height: 48px; border-radius: 10px; background: #2a211f; color: var(--lime); display: grid; place-items: center; font-style: normal; font-size: 26px; }
.cta b { flex: 1; text-align: left; font-size: 16px; font-weight: 600; }
.cta span { font-size: 14px; opacity: .65; font-variant-numeric: tabular-nums; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center; background: #1c1615;
  padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; max-width: 140px; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; color: var(--mute); gap: 2px; }
.tabs button span { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabs button.on { color: var(--lime); font-weight: 700; }
.tabs button.on span { filter: none; opacity: 1; }

/* 統計 */
.donut { position: relative; width: 230px; height: 230px; margin: 18px auto 8px; }
.donut svg { width: 100%; height: 100%; }
.donut circle { stroke-linecap: butt; }
.donut .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut .center small { color: var(--mute); font-size: 13px; }
.donut .center b { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--lime); }
.legend { list-style: none; margin: 0; padding: 4px 18px 16px; }
.legend li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.legend i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.legend span { flex: 1; }
.legend em { font-style: normal; color: var(--mute); font-size: 14px; width: 44px; text-align: right; }
.legend b { width: 96px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bars { display: flex; gap: 8px; height: 200px; padding: 16px 14px 12px; align-items: flex-end; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.bar small { font-size: 10px; color: var(--mute); white-space: nowrap; }
.bar i { width: 100%; max-width: 30px; background: var(--lav); opacity: .5; border-radius: 99px; min-height: 4px; }
.bar.on i { background: var(--orange); opacity: 1; }
.bar span { font-size: 12px; color: var(--mute); }

/* 彈出面板 */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(10, 6, 5, .6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; background: var(--bg); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; font-size: 16px; }
.sheet-head button { width: 36px; height: 36px; color: var(--mute); font-size: 16px; background: var(--card); border-radius: 50%; }
.sheet-body { overflow-y: auto; padding: 4px 18px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.sheet-foot .btn { min-height: 52px; }

/* 表單 */
.lbl { display: block; margin: 16px 4px 8px; color: var(--mute); font-size: 13px; font-weight: 600; }
.sheet input:not([type=radio]):not([type=checkbox]), .sheet select, .rate input {
  width: 100%; min-height: 48px; padding: 0 16px; background: var(--card); border: 0; border-radius: 10px; font-size: 16px; }
.sheet input:focus, .sheet select:focus { outline: 2px solid var(--lime); outline-offset: -2px; }
input[type=date] { color-scheme: dark; }
.amount-row { display: flex; gap: 8px; }
.amount-row .amount { font-size: 28px; font-weight: 600; min-height: 62px; flex: 1.2; min-width: 0; color: var(--lime); font-variant-numeric: tabular-nums;
  background: var(--card); border-radius: 10px; padding: 0 16px; text-align: right; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.amount-row .amount.focus { outline: 2px solid var(--lime); outline-offset: -2px; }
.amount-row .amount .ph { color: #6d625c; }
.expr { min-height: 18px; margin: 6px 6px 0; text-align: right; color: var(--mute); font-size: 13px; font-variant-numeric: tabular-nums; }
.lblrow { display: flex; justify-content: space-between; align-items: center; }
.lblrow .lbl { margin-top: 10px; }
.more { color: var(--lime); font-size: 11px; font-weight: 500; margin: 10px 4px 8px; }
.chips.cats { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.chips.cats::-webkit-scrollbar { display: none; }
.chips.cats .chip { flex: none; white-space: nowrap; }
.chips.cats.all { flex-wrap: wrap; overflow: visible; }
.two { display: flex; gap: 10px; }
.two > * { flex: 1; min-width: 0; }
.sheet { position: relative; }
.sheet.padopen .sheet-body { padding-bottom: 250px; }
.keypad { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); background: #1c1614; border-radius: 14px 14px 0 0;
  transform: translateY(105%); transition: transform .22s ease-out; }
.keypad.open { transform: none; }
.k { height: 48px; border-radius: 8px; background: var(--card); font-size: 20px; }
.k:active { background: var(--card2); }
.k-op { color: var(--lime); }
.k-done { background: var(--card2); font-size: 15px; font-weight: 600; }
.k-save { background: var(--lime); color: var(--lime-ink); font-size: 15px; font-weight: 600; }
.amount-row select { flex: 1; min-width: 0; min-height: 62px; }
.rate { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--mute); }
.rate input { flex: 1; min-width: 0; }
.hint { margin: 6px 4px 0; font-size: 13px; color: var(--mute); min-height: 20px; }
.warnx { color: var(--warn); }
.hint.conv { text-align: right; margin-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 42px; padding: 0 16px; border-radius: 10px; background: var(--card); }
.chip.on { background: var(--lime); color: var(--lime-ink); font-weight: 600; }
.receipt { display: flex; align-items: center; gap: 12px; }
.receipt img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.radios { display: grid; gap: 6px; margin: 6px 0 12px; }
.radios label { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--card); border-radius: 10px; }
.radios input { width: 20px; height: 20px; accent-color: var(--lime); }
.viewer { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 50;
  background: #f4ede7; color: #2a211f; padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 長按列 */
.row.danger .mid b { color: var(--neg); }
.list.menu { margin: 4px 0 8px; }
.row.lp { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.row .chev { flex: none; width: 32px; height: 32px; display: grid; place-items: center; color: var(--mute); font-size: 18px; }

/* 帳本圖示 */
.name-row { display: flex; gap: 8px; }
.sheet .name-row input.emo-in { flex: none; width: 52px; padding: 0; text-align: center; font-size: 24px; caret-color: transparent; }

/* 摘要卡輪播：三張（上月／本月／下月）並排，平常停在中間 */
.sum-view { overflow: hidden; margin: 4px -6px 0; touch-action: pan-y; }
.sum-track { display: flex; transform: translateX(-100%); }
.sum-track .slide { flex: 0 0 100%; padding: 0 6px; box-sizing: border-box; }
.sum-track .summary { margin: 0; }

/* 整頁面板（單筆分帳）：從右側滑入 */
.backdrop.page { align-items: stretch; background: var(--bg); }
.backdrop.page .sheet { max-height: none; height: 100%; border-radius: 0; padding-top: env(safe-area-inset-top); animation: inR .25s ease-out; }
@keyframes inR { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.backdrop.page .sheet-head b { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backdrop.page .sheet-head .sp { width: 36px; flex: none; }
.backdrop.page .sheet-head button { font-size: 20px; flex: none; }
.backdrop.page .sheet-body { flex: 1; }
.btn:disabled { opacity: .35; }

/* 分帳分頁 */
.split-hero .sum-big.pos { color: var(--pos); }
.people { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.people span { flex: 1 0 64px; min-width: 0; background: var(--card2); border-radius: 10px; padding: 6px 8px; font-size: 12px; color: var(--mute);
  text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people b { display: block; color: var(--ink); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.people b.pos { color: var(--pos); }
.tag { font-size: 11px; font-weight: 500; color: var(--lime); margin-left: 6px; }
.split-total { text-align: center; color: var(--mute); font-size: 13px; margin: 4px 0 0; }
.split-total b { display: block; color: var(--ink); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mlist { margin: 0; }
.mlist .row { min-height: 52px; cursor: pointer; }
.ck { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 2px solid #5a4e49; display: grid; place-items: center; font-size: 12px; color: transparent; }
.mrow.on .ck { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); }
.mrow:not(.on) .mid b, .mrow:not(.on) .amt { color: var(--mute); }
.sheet .mrow input.cin { flex: none; width: 110px; min-height: 38px; padding: 0 10px; text-align: right; background: var(--card2); border-radius: 8px; }
.sheet .mrow input.cin:disabled { opacity: .35; }
.hint.center { text-align: center; }
.okx { color: var(--pos); }

/* 帳本屬性 */
.types { display: grid; gap: 8px; margin-top: 4px; }
.type { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card); border-radius: 12px; padding: 12px 14px; border: 2px solid transparent; }
.type.on { border-color: var(--lime); }
.type i { font-style: normal; font-size: 24px; flex: none; }
.type b { display: block; font-weight: 600; }
.type small { display: block; color: var(--mute); font-size: 12px; }
.lform .tf { display: none; }
.lform[data-t=trip] .tf.trip, .lform[data-t=home] .tf.home { display: block; }
.tseg button { font-size: 13px; }
.tog { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border-radius: 10px; padding: 11px 14px; margin-top: 12px; }
.tog b { display: block; font-weight: 500; }
.tog small { display: block; color: var(--mute); font-size: 12px; }
.sheet .tog input { -webkit-appearance: none; appearance: none; width: 44px; height: 26px; margin: 0; flex: none; border-radius: 99px; background: var(--card2); position: relative; transition: background .15s; }
.sheet .tog input::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--mute); transition: left .15s; }
.sheet .tog input:checked { background: var(--lime); }
.sheet .tog input:checked::after { left: 21px; background: var(--lime-ink); }

/* 旅遊：每天一根長條，下面標 D1、D2… */
.sum-bars.trip { gap: 4px; }
.sum-bars i.pre { opacity: .45; }
.trip-lbl { display: flex; gap: 4px; margin-top: 4px; }
.trip-lbl em { flex: 1; min-width: 0; text-align: center; font-style: normal; font-size: 9px; color: var(--mute); white-space: nowrap; }
.trip-lbl em.on { color: var(--ink); font-weight: 600; }

/* 記一筆的地點 */
.loc { display: flex; align-items: center; gap: 10px; margin-top: 10px; background: var(--card); border-radius: 10px; padding: 10px 14px; font-size: 13px; }
.loc span { flex: 1; min-width: 0; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loc b { color: var(--ink); font-weight: 500; }
.loc a { color: var(--lime); text-decoration: none; flex: none; }
.loc button { color: var(--mute); font-size: 13px; flex: none; }
.loc button.add { color: var(--lime); }

/* 共同生活按月分帳、已結束的旅程 */
.settle-nav { margin-bottom: 10px; }
.list.ended .row:not(.add) { opacity: .55; }
