/* 資產管理 — C 沉穩紙本 */
:root {
  --paper: #F4F0E8; --paper-2: #EDE5D6; --paper-3: #E5DED1; --card: #FBF8F2;
  --ink: #1E1B16; --ink-2: #3D372E; --ink-3: #6E6658; --rule: #DED6C8; --rule-2: #CFC6B6;
  --accent: #2E5E4E; --accent-ink: #F4F0E8;
  --red: #B23A2A; --green: #2F7A55; --amber: #9A6A12;
  --c-tw: #2E5E4E; --c-us: #4D7A9E; --c-cash: #A6894F; --c-fx: #8C5A73;
  --serif: 'Noto Serif TC', 'Songti TC', serif;
  --sans: 'Noto Sans TC', -apple-system, 'PingFang TC', sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 15px; -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.serif { font-family: var(--serif); }
.num { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.right { text-align: right; justify-self: end; }
.red { color: var(--red); } .green { color: var(--green); } .flat { color: var(--ink-2); }
.pos { color: var(--ink); }

/* 版面 */
.app { min-height: 100dvh; }
.main { padding: env(safe-area-inset-top) 0 calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
.page { padding: 14px 18px 0; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col.narrow { max-width: 640px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.boot { padding: 80px 24px; text-align: center; }
.show-mobile { display: inline-flex; align-items: center; gap: 4px; }
.hide-mobile { display: none; }
.trend-grid .col:first-child:not(.hide-mobile) + .col:empty { display: none; }

/* 導覽 */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--paper); border-top: 1px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.nav-brand { display: none; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-3); text-decoration: none; font-size: 11px; min-height: 44px; }
.nav-item.on { color: var(--accent); font-weight: 700; }

/* 標題列 */
.masthead { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 2px solid var(--ink); padding-bottom: 8px; min-height: 52px; }
.masthead h1 { margin: 0; font-size: 20px; font-weight: 900; letter-spacing: 0.06em; }
.mast-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--ink); border-radius: 22px; cursor: pointer; }
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:disabled { opacity: .5; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 主數字 */
.hero { display: flex; flex-direction: column; gap: 2px; }
.eyebrow { font-size: 12px; color: var(--ink-3); letter-spacing: .12em; }
.hero-num { font-size: 44px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
.hero-sub { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; padding: 12px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.stats > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat { font-size: 22px; font-weight: 700; }
.stat-sm { font-size: 13px; }

/* 區塊 */
.section { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--ink); padding-top: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.block { display: flex; flex-direction: column; gap: 8px; }
.link { color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 2px; min-height: 32px; }
.link:hover { text-decoration: underline; }

/* 圖表 */
.chart { position: relative; }
.chart-tip { height: 18px; display: flex; gap: 10px; font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; }
.chart-tip b { font-weight: 500; }
.chart-body { position: relative; }
.ytick { position: absolute; left: 0; font-size: 10px; color: var(--ink-3); text-align: right; line-height: 14px; }
.marker { position: absolute; bottom: -2px; transform: translateX(-50%); font-size: 9px; line-height: 1; pointer-events: none; }
.marker.buy { color: var(--accent); } .marker.sell { color: var(--c-fx); }
.marker-legend { font-size: 9px; margin-left: 4px; } .marker-legend.buy { color: var(--accent); } .marker-legend.sell { color: var(--c-fx); }
.chart-tip.rich { height: auto; min-height: 18px; flex-wrap: wrap; white-space: normal; gap: 2px 10px; }
.xaxis { position: relative; height: 16px; margin-top: 3px; }
.xaxis span { position: absolute; top: 0; font-size: 10px; color: var(--ink-3); white-space: nowrap; }
.xunit { text-align: right; font-size: 10px; margin-top: -2px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 6px; }
.split > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.split .op { font-family: var(--serif); font-size: 20px; color: var(--ink-3); padding-bottom: 2px; }
.split .v { font-size: 17px; font-weight: 700; }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 6px 0; border-top: 1px solid var(--rule); font-size: 14px; }
.kv-row.total { border-top: 0; font-size: 15px; }
.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini-stats > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mini-stats b { font-size: 16px; }
.chart-empty { display: flex; align-items: center; justify-content: center; color: var(--ink-3); border: 1px dashed var(--rule-2); }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 0; margin-left: 4px; }
.lg-solid { border-top: 2px solid var(--accent); } .lg-dash { border-top: 2px dashed var(--ink-3); } .lg-gold { border-top: 2px solid var(--c-cash); }

/* 選項 */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.scroll-x { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.scroll-x .chips { flex-wrap: nowrap; }
.chip { border: 1px solid var(--rule-2); background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 999px; min-height: 36px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* 配置長條 */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar { display: grid; grid-template-columns: 64px minmax(0, 1fr) 40px 92px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { position: relative; height: 8px; background: var(--paper-3); }
.bar-fill { display: block; height: 8px; }
.bar-target { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--ink); }

/* 表格列 */
.ledger { display: flex; flex-direction: column; }
.ledger-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 72px; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--rule);
  color: inherit; text-decoration: none; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; width: 100%; min-height: 44px; font-size: 14px; }
.ledger-row.h4 { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, .9fr); }
.ledger-row.head { padding: 4px 0; min-height: 0; border-top: 0; }
a.ledger-row:hover, button.ledger-row:hover { background: var(--paper-2); }
.ledger-row.sel { background: var(--paper-2); }
.ledger-row input { width: 100%; }
.plain { background: none; border: 0; padding: 0; cursor: pointer; }
.plain.left { text-align: left; }

/* 提醒 */
.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--paper-2); border-radius: 4px; font-size: 13px; line-height: 1.6; color: var(--ink-2); }
.note-tag { font-size: 12px; font-weight: 900; color: var(--paper); background: var(--ink-2); padding: 1px 6px; border-radius: 2px; flex: none; }
.note.warn .note-tag { background: var(--red); }
.note.info .note-tag { background: var(--accent); }
.banner { display: flex; align-items: center; gap: 8px; background: var(--ink); color: var(--paper); font-size: 13px; padding: 8px 18px; }
.banner.demo { background: var(--accent); }
.progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 50; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 50% 100%; animation: prog 1s linear infinite; }
@keyframes prog { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.empty { color: var(--ink-3); font-size: 13px; padding: 16px 0; margin: 0; }

/* 表單 */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 12px; color: var(--ink-3); letter-spacing: .04em; }
.field-hint { font-size: 12px; color: var(--ink-3); }
.field-error, .form-error { font-size: 13px; color: var(--red); margin: 0; }
input, select, textarea { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--rule-2); border-radius: 4px; background: var(--card); font-size: 16px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 44px; }
.check input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
.fee-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.calc { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; background: var(--paper-2); padding: 10px 12px; border-radius: 4px; font-size: 13px; }
.calc b { font-size: 15px; }
.inline-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 44px; gap: 8px; align-items: center; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--rule-2); border-radius: 4px; padding: 0 10px; background: var(--card); color: var(--ink-3); }
.search input { border: 0; background: transparent; padding-left: 0; }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--ink); background: transparent; color: var(--ink);
  border-radius: 4px; font-size: 15px; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }

/* 交易清單 */
.glist { list-style: none; margin: 0; padding: 0; }
.gitem { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--rule); padding: 10px 0; min-height: 52px; cursor: pointer; }
.gitem:hover { background: var(--paper-2); }
.gmain { display: flex; flex-direction: column; min-width: 0; }
.gtype { color: var(--accent); font-weight: 700; }
.gtitle { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gnote { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 對話框 */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(30, 27, 22, .35); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto; background: var(--paper); border-top: 2px solid var(--ink); border-radius: 10px 10px 0 0; padding: 4px 18px calc(18px + env(safe-area-inset-bottom)); outline: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--paper); padding: 8px 0; border-bottom: 1px solid var(--rule); margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet h3 { font-size: 15px; margin: 16px 0 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 7px 6px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.tbl th { font-weight: 500; color: var(--ink-3); white-space: nowrap; }
.tbl td.right, .tbl th.right { text-align: right; }
.table-box { overflow: auto; max-height: 65dvh; border: 1px solid var(--rule); }
.tbl.raw { font-size: 12px; white-space: nowrap; }
.tbl.perf { white-space: nowrap; }
.tbl.perf td:first-child, .tbl.perf th:first-child { position: sticky; left: 0; background: var(--paper); }
.perf-box { max-height: 60dvh; }
.tbl.raw thead th { position: sticky; top: 0; background: var(--paper-2); }

/* 指標格 */
.ind-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }
.ind { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--rule); font-size: 13px; gap: 8px; }
.lamp { font-size: 12px; font-weight: 900; padding: 2px 6px; border-radius: 2px; color: var(--paper); }
.lamp-red { background: var(--red); } .lamp-yellow { background: var(--amber); } .lamp-green { background: var(--green); }

/* 更多 */
.menu { list-style: none; margin: 0; padding: 0; }
.menu-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) 20px; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--rule); color: var(--ink); text-decoration: none; min-height: 56px; }
.menu-item:hover { background: var(--paper-2); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--rule); font-size: 14px; }
.set-row select { width: auto; }

/* 設定、解鎖 */
.setup { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 18px; }
.setup-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; border-top: 2px solid var(--ink); padding-top: 14px; }
.setup-card.center { align-items: center; text-align: center; }
.setup-card h1 { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: .06em; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--rule); }

/* 通知 */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 60; max-width: min(92vw, 520px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 4px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.toast.error { background: var(--red); color: #fff; }

/* 寬螢幕（Mac） */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 200px minmax(0, 1fr); }
  .nav { position: sticky; top: 0; height: 100dvh; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--ink); padding: 24px 12px; gap: 4px; }
  .nav-brand { display: block; font-size: 22px; font-weight: 900; letter-spacing: .1em; padding: 0 12px 16px; border-bottom: 2px solid var(--ink); margin-bottom: 12px; }
  .nav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 0 12px; border-radius: 4px; min-height: 44px; }
  .nav-item.on { background: var(--paper-2); }
  .main { padding: 0 0 40px; }
  .page { padding: 24px 32px 0; }
  .grid-2 { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 32px; align-items: start; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hero-num { font-size: 52px; }
  .show-mobile { display: none; }
  .hide-mobile { display: flex; flex-direction: column; gap: 16px; }
  .toast { bottom: 24px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 6px; border: 1px solid var(--ink); border-top-width: 2px; max-height: 80dvh; }
  .sheet.wide { max-width: 860px; }
}
@media (max-width: 380px) {
  .bar { grid-template-columns: 58px minmax(0, 1fr) 36px; }
  .bar-amt { display: none; }
  .hero-num { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) { .spin, .spinner, .progress { animation: none; } }
