:root {
  --bg: #efede8; --card: #ffffff; --ink: #1c1b19; --ink2: #6f6c66; --ink3: #a5a19a;
  --line: #ebe8e2; --accent: #16a882; --accent-soft: #dcf4ec;
  --up: #e5484d; --down: #2f9e6b;           /* 台灣慣例：紅漲綠跌 */
  --shadow: 0 1px 2px rgba(40,30,20,.04), 0 6px 20px rgba(40,30,20,.05);
  --c1: #a99bd1; --c2: #7fa8d8; --c3: #e0b95c; --c4: #c96442; --c5: #7cbf9e; --c6: #d98aa0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --card: #1f1e1c; --ink: #f3f1ec; --ink2: #a19d95; --ink3: #6c6963;
    --line: #2b2a27; --accent: #2ecfa5; --accent-soft: #143a30;
    --up: #ff6b6f; --down: #4cc38a; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 ui-rounded, "SF Pro Rounded", -apple-system, "SF Pro Text", "PingFang TC", "Noto Sans TC", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.num, .big-num { font-variant-numeric: tabular-nums; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; padding: calc(env(safe-area-inset-top) + 8px) 16px calc(120px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; height: 44px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo { width: 22px; height: 22px; border-radius: 7px; background: var(--accent); position: relative; display: inline-block; }
.logo::after { content: ""; position: absolute; left: 5px; bottom: 5px; width: 3px; height: 8px; background: #fff; border-radius: 1px; box-shadow: 5px -3px 0 #fff, 10px -6px 0 #fff; }
.logo.big { width: 56px; height: 56px; border-radius: 17px; margin: 0 auto 12px; }
.logo.big::after { left: 14px; bottom: 14px; width: 6px; height: 16px; box-shadow: 10px -6px 0 #fff, 20px -12px 0 #fff; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--ink2); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: 22px; padding: 18px; margin-top: 12px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; }
.card h3 small { font-weight: 400; color: var(--ink3); font-size: 12px; }
.label { color: var(--ink2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.hero-num { font-size: 38px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; margin: 2px 0 0; }
.hero-num.sm { font-size: 30px; }
.sub { color: var(--ink2); font-size: 13px; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--ink3); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.eye { color: var(--ink3); padding: 2px; display: inline-grid; }
.chev { color: var(--ink3); }

/* 兩口袋 / 配置條 */
.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--line); gap: 2px; }
.bar > i { display: block; height: 100%; }
.legend { margin-top: 12px; display: grid; gap: 9px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .li .n { margin-left: auto; color: var(--ink2); font-size: 13px; }
.legend .li .p { width: 46px; text-align: right; font-weight: 600; }
.pocket { border-radius: 16px; padding: 14px; background: var(--bg); }
.pocket .v { font-size: 20px; font-weight: 700; margin-top: 2px; }

/* 進度條 */
.prog { height: 8px; border-radius: 5px; background: var(--line); overflow: hidden; margin-top: 8px; }
.prog > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; transition: width .4s; }
.prog.over > i { background: var(--up); }

/* 列表 */
.list > .item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list > .item:first-child { border-top: 0; }
.item .ic { width: 38px; height: 38px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; font-size: 19px; flex: none; }
.item .mid { flex: 1; min-width: 0; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { color: var(--ink2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .r { text-align: right; flex: none; }
.item .r .t { font-weight: 600; }
.tag { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; font-weight: 600; vertical-align: 1px; }
.group-h { margin: 18px 4px 0; color: var(--ink2); font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; }
.empty { text-align: center; color: var(--ink3); padding: 26px 0; font-size: 14px; }
.link { color: var(--accent); font-weight: 600; font-size: 14px; }

/* 分段 / 月份 */
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 10px; color: var(--ink2); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.monthbar { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.monthbar b { font-size: 16px; }
.monthbar button { width: 36px; height: 36px; border-radius: 50%; color: var(--ink2); font-size: 18px; }

/* 浮動按鈕 / 底部導覽 */
.tabs { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: min(480px, 100%); display: flex; padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); z-index: 20; }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--ink3); padding: 4px 0; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }
.fab { position: fixed; right: max(16px, calc(50% - 224px)); bottom: calc(76px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: 0 8px 20px rgba(22,168,130,.4); z-index: 21; display: grid; place-items: center; padding-bottom: 3px; }
.fab[hidden] { display: none; }

/* 底部彈出表單 */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fade .2s; }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(480px, 100%); max-height: 92dvh; overflow: auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); z-index: 41; animation: up .25s cubic-bezier(.2,.8,.2,1); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 14px; font-size: 18px; }
@keyframes up { from { transform: translate(-50%, 100%); } }
@keyframes fade { from { opacity: 0; } }
.field { margin-top: 14px; }
.field > label { display: block; color: var(--ink2); font-size: 12.5px; margin-bottom: 6px; }
.field input, .field select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; font-size: 16px; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.amount { font-size: 34px !important; font-weight: 700; text-align: center; padding: 14px !important; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 13px; border-radius: 999px; background: var(--bg); color: var(--ink2); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1.5px var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--ink2); font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.btns { display: flex; gap: 10px; margin-top: 22px; }
.btn { flex: 1; padding: 14px; border-radius: 14px; font-weight: 700; background: var(--bg); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { flex: 0 0 auto; padding: 14px 18px; color: var(--up); }

/* 登入 */
.login { position: fixed; inset: 0; background: var(--bg); z-index: 100; display: grid; place-items: center; padding: 24px; }
.login[hidden] { display: none; }
.login form { width: min(320px, 100%); text-align: center; }
.login h1 { font-size: 22px; margin: 0 0 20px; }
.login input { width: 100%; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 18px; text-align: center; outline: none; margin-bottom: 12px; }
.login .btn { width: 100%; }
.err { color: var(--up); min-height: 20px; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; }
.note { color: var(--ink3); font-size: 12px; text-align: center; margin: 14px 0 0; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; color: var(--ink2); }
.kv b { color: var(--ink); font-weight: 600; }
.kv.total { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 10px; }
svg.trend { width: 100%; height: 110px; display: block; }

.card h3 small.link { color: var(--accent); font-size: 13px; }
.grid2 .hero-num.sm { font-size: 24px; white-space: nowrap; }
.list > .item .s.wrap { white-space: normal; }

/* ───── Budget Flow 風格：圓潤字體、膠囊金額、懸浮導覽 ───── */
:root { --out: #e5484d; --out-bg: #fdeaea; --in: #0f9d6e; --in-bg: #e0f5ec; --neu-bg: #efeeeb; --blue: #4f6bd8; --bar: #8a9be8; }
@media (prefers-color-scheme: dark) { :root { --out: #ff7478; --out-bg: #3a2224; --in: #4cd6a0; --in-bg: #16332a; --neu-bg: #2a2926; --blue: #8ea2ff; --bar: #6f82d8; } }
body::before { content: ""; position: fixed; inset: 0 0 auto 0; height: 300px; background: radial-gradient(120% 100% at 80% -10%, #f6d9ea 0%, rgba(246,217,234,0) 60%), radial-gradient(90% 90% at 0% 0%, #e2e4fb 0%, rgba(226,228,251,0) 60%); pointer-events: none; z-index: 0; }
@media (prefers-color-scheme: dark) { body::before { opacity: .12; } }
#app { position: relative; z-index: 1; }
.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.5; }
.pill.out, .pill.down.neg { background: var(--out-bg); color: var(--out); }
.pill.in { background: var(--in-bg); color: var(--in); }
.pill.neu { background: var(--neu-bg); color: var(--ink2); }
.pill.up { background: var(--out-bg); color: var(--up); }
.pill.down { background: var(--in-bg); color: var(--down); }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 0; font-size: 20px; font-weight: 800; }
.sec-h .link { font-size: 15px; }
.group-h { font-size: 17px; font-weight: 800; color: var(--ink); margin-top: 22px; }
.group-h .num { font-weight: 700; font-size: 14px; color: var(--ink2); }
.card h3 { font-size: 17px; font-weight: 800; }
.item .ic { border-radius: 13px; }
.tile { background: color-mix(in srgb, var(--c, #8a8578) 16%, var(--card)); }
.tile.in { --c: #16a882; color: #16a882; font-weight: 800; }
.tile.out { --c: #e5484d; color: #e5484d; font-weight: 800; }
.item .r .pill + .pill, .r .pill + .s { margin-left: 4px; }
.r .s { margin-top: 3px; }

/* 懸浮膠囊導覽 */
.tabs { bottom: calc(10px + env(safe-area-inset-bottom)); width: min(456px, calc(100% - 24px)); border-radius: 34px; border: 1px solid var(--line); padding: 6px; box-shadow: 0 10px 34px rgba(40,40,70,.14); }
.tabs button { border-radius: 28px; padding: 7px 0 6px; }
.tabs button.on { background: var(--neu-bg); color: var(--accent); }
.fab { bottom: calc(96px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(110px + env(safe-area-inset-bottom)); }

/* 固定開銷卡片（仿 Budget Flow 訂閱清單） */
.fx { position: relative; background: var(--card); border-radius: 22px; margin-top: 12px; box-shadow: var(--shadow); overflow: hidden; cursor: pointer; }
.fx-main { display: flex; align-items: center; gap: 12px; padding: 16px 16px 20px; }
.fx .ic { width: 52px; height: 52px; border-radius: 15px; font-size: 26px; display: grid; place-items: center; flex: none; }
.fx .mid { flex: 1; min-width: 0; }
.fx .t { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx .s { margin-top: 3px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--ink2); font-size: 12.5px; }
.fx .n { color: var(--ink3); font-size: 12px; margin-top: 2px; }
.tagchip { display: inline-block; padding: 1px 8px; border-radius: 8px; background: var(--neu-bg); color: var(--ink2); font-size: 12px; font-weight: 600; }
.fx .r { text-align: right; flex: none; }
.fx-amt { font-weight: 800; font-size: 20px; }
.fx-amt small { font-size: 11px; color: var(--ink3); font-weight: 700; }
.fx-left { color: var(--blue); font-weight: 700; font-size: 14px; margin-top: 2px; }
.fx-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; }
.fx-bar > i { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }
.chipbar { display: flex; gap: 8px; overflow-x: auto; margin-top: 14px; padding-bottom: 2px; scrollbar-width: none; }
.chipbar::-webkit-scrollbar { display: none; }
.chipbar .chip { flex: none; }
.up-card .item { padding: 10px 0; }
.fx .t { white-space: normal; line-height: 1.25; }
.fx-amt { font-size: 18px; }
.item .ic.tile { background: color-mix(in srgb, var(--c, #8a8578) 16%, var(--card)); }

.backbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 6px; font-size: 18px; }
.backbar b { font-weight: 800; }
.backbar .back { color: var(--accent); font-weight: 700; font-size: 16px; padding: 8px 8px 8px 0; }
.backbar .link { font-size: 15px; }
button.pill { border: 0; cursor: pointer; font-family: inherit; }

/* ───── v3：記帳表單 / 帳戶圖片 / 展開收合 ───── */
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.hero-num.xs { font-size: 17px; letter-spacing: -.2px; margin-top: 2px; }
.ic.tile.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; flex: none; }
.thumb { width: 52px; height: 36px; border-radius: 9px; object-fit: cover; flex: none; background: var(--neu-bg); }
.thumb.big { width: 96px; height: 64px; border-radius: 12px; }
.thumb.ph { display: grid; place-items: center; font-size: 26px; }
.imgbox { display: flex; align-items: center; gap: 14px; }
.imgbtns { display: flex; flex-direction: column; gap: 8px; }
.btn.sm { flex: none; padding: 9px 16px; font-size: 14px; text-align: center; cursor: pointer; display: inline-block; }
.txhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.circ { width: 44px; height: 44px; border-radius: 50%; background: var(--neu-bg); font-size: 20px; font-weight: 700; }
.savebtn { padding: 10px 22px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 800; font-size: 16px; }
.amtbox { display: flex; align-items: baseline; gap: 6px; background: var(--bg); border-radius: 18px; padding: 14px 16px; margin-top: 6px; }
.amtsign { font-size: 26px; font-weight: 800; color: var(--ink2); }
.amount2 { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 34px; font-weight: 800; font-family: inherit; }
.minih { margin: 18px 4px 8px; font-size: 15px; font-weight: 800; color: var(--ink2); }
.picks { background: var(--bg); border-radius: 18px; overflow: hidden; }
.pick { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.pick:first-child { border-top: 0; }
.pick .pl { flex: 1; font-weight: 600; min-width: 0; }
.pick .pl small { display: block; color: var(--ink3); font-weight: 400; font-size: 12px; }
.pick .pv { color: var(--ink2); max-width: 55%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .ok { color: var(--accent); font-weight: 800; font-size: 18px; }
.pick input { border: 0; background: transparent; outline: none; font-size: 16px; text-align: right; font-family: inherit; min-width: 0; }
.pick input[type=date] { text-align: right; }
.pick #f-note { flex: 1; }
.pick input.mini { width: 44px; text-align: center; flex: none; }
.pick.addrow { justify-content: flex-start; }
.pillbtn { padding: 6px 14px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; flex: none; }
.pick .thumb { width: 44px; height: 30px; }

details.dd > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 0; cursor: pointer; }
details.dd > summary::-webkit-details-marker { display: none; }
details.dd > summary .t { flex: 1; font-weight: 700; }
details.dd > summary .cnt { color: var(--ink3); font-size: 12.5px; }
details.dd > summary::after { content: "›"; color: var(--ink3); font-size: 20px; transition: transform .2s; margin-left: 2px; }
details.dd[open] > summary::after { transform: rotate(90deg); }
details.dd.big > summary .t { font-size: 17px; font-weight: 800; }
details.dd.inner { border-top: 1px solid var(--line); }
details.dd .dd-body, details.dd > .list { padding-bottom: 6px; }
details.dd > summary + .list .item:first-child { border-top: 0; }
.card.cc { padding: 6px 16px 10px; }
.cc-head { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.cc-head .t { font-weight: 800; font-size: 16px; }
.cc-head .s { color: var(--ink2); font-size: 12.5px; }
.cc .item { padding: 10px 0; }
.cc-foot { text-align: right; padding-top: 4px; }
.cc .kv.total { margin-top: 4px; }
.cc-head .ic, .pick > .ic:not(.sm) { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex: none; }
.cc > .item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cc > .item .mid { flex: 1; min-width: 0; }
.ic.tile.sm { display: grid; place-items: center; }
.pick .thumb { flex: none; }

.ckrow { display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--bg); text-align: left; font-weight: 700; }
.ckrow small { color: var(--ink3); font-weight: 500; }
.box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--ink3); display: grid; place-items: center; color: #fff; font-size: 15px; flex: none; }
.box.on { background: var(--accent); border-color: var(--accent); }

.thumb { width: 56px; height: 44px; object-fit: contain; }
.thumb.big { width: 96px; height: 72px; }
.pick .thumb { width: 44px; height: 32px; }
