/* G 版：黑底、深藍資訊區塊、金色重點 */
:root {
  --accent: #c9a75d;             /* 金色：主色，可在設定換 */
  --on-accent: #000;
  --bg: #000;                    /* 純黑底 */
  --card: #0f2245;               /* 深藍資訊區塊 */
  --card-2: #13284a;             /* 區塊內的次層 */
  --sheet: #0b1a35;              /* 彈出面板 */
  --field: #081633;              /* 輸入框（比區塊再深） */
  --ink: #e6edf8;
  --muted: #8fa6cc;
  --line: #1d3a6b;
  --up: #ff8a8a; --down: #4fd18b; /* 台股習慣：紅漲綠跌 */
  --in: #4fd18b; --out: #e6edf8;  /* 收入綠、支出白 */
  --danger: #ff6b6b; --warn: #f2c14e;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; -webkit-tap-highlight-color: transparent; }
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

.muted { color: var(--muted); } .small { font-size: 12.5px; } .block { display: block; } .center { text-align: center; }
.grow { flex: 1; min-width: 0; } .right { text-align: right; }
.up { color: var(--up); } .down { color: var(--down); }
.up-ink { color: var(--in); } .down-ink { color: var(--out); } .danger-ink { color: var(--danger); }
.tx-amt.down, .imp-amt.down, .list-row .down { color: var(--out); }
.tx-amt.up, .imp-amt.up, .list-row .up { color: var(--in); }
.masked { letter-spacing: 1px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* 版面 */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--bg); }
.topbar h1 { font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; font-size: 22px; }
.icon-btn:active { background: var(--card); }
.sync { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.sync.ok { background: var(--accent); } .sync.pending, .sync.busy { background: var(--warn); } .sync.offline { background: var(--danger); }
.view { max-width: 720px; margin: 0 auto; padding: 0 16px calc(96px + var(--safe-b)); display: grid; gap: 12px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; padding: 6px 8px calc(6px + var(--safe-b)); background: var(--bg); border-top: 1px solid #1a1a1a; }
.tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabbar a.active { color: var(--accent); }
.fab { justify-self: center; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; margin-top: -18px; box-shadow: 0 0 0 4px var(--bg); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.6; }

/* 卡片 */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; display: block; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-head h3, .section-title { font-size: 14px; font-weight: 600; color: var(--accent); letter-spacing: .5px; }
.section-title { margin: 8px 0 4px; }
.hero-label, .stat-label { font-size: 13px; color: var(--muted); }
.hero { border: 4px solid var(--accent); padding: 12px 14px; }
.hero .hero-label { color: var(--accent); letter-spacing: 1px; }
.spark { display: block; width: 100%; height: 34px; margin-top: 6px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.8; vector-effect: non-scaling-stroke; }
.hero-value { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-sub { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat-value { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-3 .stat-value { font-size: 16px; }
.invest-mini { display: flex; justify-content: space-between; align-items: center; }

.list-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 0; border-top: 1px solid var(--line); }
.list-row:first-child, .card-head + .list-row, .acc-group-title + .list-row { border-top: 0; }
.acc-group + .acc-group { margin-top: 6px; }
.acc-group-title { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.menu-icon { font-size: 20px; width: 28px; text-align: center; }
.chev { color: var(--muted); font-size: 20px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--card-2); color: var(--muted); vertical-align: 1px; }
.tag.side-buy { color: var(--up); } .tag.side-sell { color: var(--down); } .tag.side-dividend { color: var(--accent); }

.tx-list { display: grid; }
.tx-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 0; border-top: 1px solid var(--line); }
.tx-row:first-child { border-top: 0; }
.tx-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--card-2); display: grid; place-items: center; font-size: 18px; flex: none; }
.tx-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.day { padding-top: 10px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; padding-bottom: 4px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-title { font-weight: 650; min-width: 96px; text-align: center; }
.search { flex: 1; min-width: 160px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.chip-bar { display: flex; gap: 8px; align-items: center; }
.chip { padding: 4px 10px; border-radius: 99px; background: var(--card); font-size: 13px; }
.chip.active { background: var(--accent); color: var(--on-accent); }
.empty { text-align: center; padding: 20px 8px; color: var(--muted); }
.empty-icon { font-size: 32px; }
.empty p { margin: 6px 0 0; }
.notice { border: 1px solid var(--accent); color: var(--accent); background: var(--card); padding: 12px 14px; border-radius: var(--radius); font-size: 14px; }

/* 預算 */
.budget { padding: 8px 0; border-top: 1px solid var(--line); }
.card-head + .budget { border-top: 0; }
.budget-top { display: flex; justify-content: space-between; gap: 8px; }
.bar { position: relative; height: 8px; border-radius: 99px; background: #000; margin: 6px 0 3px; overflow: visible; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.bar.warn i { background: var(--warn); } .bar.over i { background: var(--danger); }
.bar b { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--muted); border-radius: 1px; }

/* 報表 */
.donut-wrap { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center; }
.donut { width: 140px; height: 140px; }
.cat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.cat-list li { display: flex; align-items: center; gap: 8px; }
.cat-list i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.trend { width: 100%; height: auto; }
.trend .bar-in { fill: var(--in); } .trend .bar-out { fill: var(--out); }
.trend .axis { font-size: 10px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); justify-content: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .bar-in { background: var(--in); } .legend .bar-out { background: var(--out); }
@media (max-width: 420px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } .cat-list { width: 100%; } }

/* 投資 */
.holding { width: 100%; }
.holding-top, .holding-bottom { display: flex; justify-content: space-between; gap: 8px; }
.holding-bottom { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; font-variant-numeric: tabular-nums; }
.holding-name { font-weight: 650; }
.holding-price { font-weight: 650; font-variant-numeric: tabular-nums; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kv-grid div { background: var(--card-2); border-radius: 10px; padding: 8px 10px; display: grid; }
.kv-grid span { font-size: 12px; color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); }

/* 按鈕與表單 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .55; }
.btn-text { color: var(--accent); font-size: 14px; }
.row-btns { display: flex; gap: 10px; margin-top: 6px; }
.row-btns.tight { margin: 0; gap: 6px; }
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field > span { display: flex; justify-content: space-between; align-items: center; }
.field input, .field select { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font-size: 16px; min-height: 44px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field.inline { grid-template-columns: 1fr 140px; align-items: center; font-size: 15px; color: var(--ink); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { padding: 8px; border-radius: 8px; text-align: center; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card-2); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.amount-field { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--accent); padding: 4px 2px; }
.amount-cur { color: var(--muted); font-weight: 600; }
.amount-field input { flex: 1; min-width: 0; border: 0; background: none; font-size: 34px; font-weight: 700; text-align: right; outline: none; font-variant-numeric: tabular-nums; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.cat-chip { display: grid; justify-items: center; gap: 2px; padding: 8px 4px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); font-size: 12.5px; text-align: center; }
.cat-chip span { font-size: 20px; }
.cat-chip.active { background: var(--accent); color: var(--on-accent); }
.total-line { text-align: right; font-size: 15px; }
.total-line b { font-size: 20px; }
.lookup { min-height: 18px; }
.file-pick { display: block; position: relative; text-align: center; padding: 14px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--accent); font-weight: 600; cursor: pointer; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.grid-icon { display: flex; gap: 10px; }
.emoji-input { width: 64px !important; text-align: center; }
.accent-row { display: flex; flex-wrap: wrap; gap: 10px; }
.accent-dot { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid var(--card); box-shadow: 0 0 0 2px transparent; }
.accent-dot.active { box-shadow: 0 0 0 2px var(--c); }
.subhead { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; }
.subhead h2 { text-align: center; font-size: 17px; }
.confirm-msg { margin: 4px 0 8px; font-size: 16px; }
.error { color: var(--danger); min-height: 20px; margin: 0; font-size: 14px; }

/* 匯入 */
.imp-table { display: grid; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.imp-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); font-size: 13.5px; }
.imp-row:first-child { border-top: 0; }
.imp-row.dup { opacity: .5; }
.imp-row select { max-width: 110px; padding: 4px; border-radius: 8px; border: 1px solid var(--line); background: var(--field); color: var(--ink); }
.imp-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.imp-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 底部面板 */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .7); opacity: 0; transition: opacity .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; display: flex; flex-direction: column; background: var(--sheet); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; transform: translateY(100%); transition: transform .22s ease-out; max-width: 640px; margin: 0 auto; }
.sheet.wide { max-width: 860px; }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-head { display: grid; grid-template-columns: 60px 1fr 60px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { text-align: center; font-size: 16px; }
.sheet-head .btn-text { color: var(--muted); }
.sheet-body { overflow: auto; padding: 16px 16px calc(20px + var(--safe-b)); overscroll-behavior: contain; }
@media (min-width: 700px) { .sheet { bottom: 50%; transform: translateY(60%); opacity: 0; border-radius: 18px; transition: transform .2s, opacity .2s; } .sheet-wrap.open .sheet { transform: translateY(50%); opacity: 1; } }

/* 登入 */
.auth { max-width: 380px; margin: 0 auto; padding: calc(12vh + var(--safe-t)) 16px 32px; text-align: center; }
.auth-logo img { width: 72px; height: 72px; }
.auth h1 { margin: 12px 0 4px; font-size: 24px; }
.auth-form { margin-top: 20px; text-align: left; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--card); border: 1px solid var(--accent); color: var(--ink); padding: 10px 16px; border-radius: 99px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* G 版細節 */
.tabbar a.active { color: var(--accent); }
.file-pick { border-color: var(--accent); }
.auth-logo img { border-radius: 18px; }
.list-row .chev, .chev { color: var(--accent); }
.day-head span:first-child { color: var(--accent); }
.subhead h2 { color: var(--ink); }
.holding-price, .hero-value, .stat-value, .tx-amt { font-variant-numeric: tabular-nums; }
