/* =========================================================
   家帳 Design System
   Layout: mobile-first single column, app bar + bottom tab bar,
   quick-entry bar pinned above the tab bar (thumb zone).
   ========================================================= */
:root {
  /* Color — neutrals lean slightly green toward the brand */
  --bg: #F3F4F1;
  --surface: #FFFFFF;
  --surface-2: #EDEFEB;
  --ink: #1B2220;
  --muted: #5F6A66;
  --faint: #646E6A;
  --line: #E1E4DF;
  --primary: #1C6B5C;
  --primary-ink: #FFFFFF;
  --primary-soft: #DCEDE8;
  --success: #2B7A4B;
  --warning: #96590E;
  --warning-soft: #FBEFD9;
  --danger: #B93A32;
  --danger-soft: #F8E3E1;
  /* Data colors (accounts / groups) */
  --living: #1C6B5C;
  --baby: #9E4266;
  --cat: #6F58A8;
  --fixed: #4A6687;
  --variable: #B98327;
  --gain: #C0392B;   /* 台股慣例：漲紅 */
  --loss: #2B7A4B;   /*           跌綠 */

  /* Type */
  --font: "Noto Sans TC", -apple-system, "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --fs-display: 34px; --fs-title: 22px; --fs-headline: 17px; --fs-body: 15px; --fs-sub: 13px; --fs-caption: 12px;

  /* Space (4pt scale) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;

  /* Shape & depth */
  --r-card: 16px; --r-control: 12px; --r-pill: 999px; --r-sheet: 20px;
  --shadow-1: 0 1px 2px rgba(20, 30, 26, .06);
  --shadow-2: 0 8px 28px rgba(20, 30, 26, .14);

  --tabbar-h: 58px;
  --quickbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101312; --surface: #191D1B; --surface-2: #232826; --ink: #ECEFEC; --muted: #A2ACA8; --faint: #8A9490;
    --line: #2B312F; --primary: #5BC0A6; --primary-ink: #082019; --primary-soft: #183A32;
    --success: #6CC08C; --warning: #E3A74A; --warning-soft: #3A2C14; --danger: #EF7D74; --danger-soft: #3D1E1C;
    --living: #5BC0A6; --baby: #E58CAB; --cat: #AE97E0; --fixed: #8FAACB; --variable: #E0B260; --gain: #EF7D74; --loss: #6CC08C;
    --shadow-1: none; --shadow-2: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101312; --surface: #191D1B; --surface-2: #232826; --ink: #ECEFEC; --muted: #A2ACA8; --faint: #8A9490;
  --line: #2B312F; --primary: #5BC0A6; --primary-ink: #082019; --primary-soft: #183A32;
  --success: #6CC08C; --warning: #E3A74A; --warning-soft: #3A2C14; --danger: #EF7D74; --danger-soft: #3D1E1C;
  --living: #5BC0A6; --baby: #E58CAB; --cat: #AE97E0; --fixed: #8FAACB; --variable: #E0B260; --gain: #EF7D74; --loss: #6CC08C;
  --shadow-1: none; --shadow-2: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: var(--fs-body); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
h1, h2, h3, h4 { margin: 0; text-wrap: balance; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 44px; padding: 0 var(--s4); border-radius: var(--r-control); border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); white-space: nowrap;
  transition: transform .08s ease, opacity .15s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; color: var(--primary); padding: 0 var(--s2); }
.btn.danger { background: transparent; color: var(--danger); padding: 0 var(--s2); }
.btn.small { min-height: 36px; padding: 0 var(--s3); font-size: 14px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--ink);
  display: inline-grid; place-items: center; cursor: pointer; position: relative; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.dot-badge::after {
  content: ""; position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 0 2px var(--bg);
}
.link-btn { border: 0; background: transparent; color: var(--primary); font-size: var(--fs-sub); font-weight: 500; cursor: pointer; min-height: 44px; padding: 0 0 0 var(--s3); margin: -12px 0; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s6) var(--s4); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: var(--s4); }
.brand { display: flex; gap: var(--s3); align-items: center; margin-bottom: var(--s4); }
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; font-size: 26px; font-weight: 700;
}
.brand h1 { font-size: var(--fs-title); font-weight: 700; }
.brand p { margin: 0; color: var(--muted); font-size: var(--fs-sub); }

/* ---------- Form fields ---------- */
.field { display: grid; gap: 6px; font-size: var(--fs-sub); color: var(--muted); font-weight: 500; }
.field-label { font-size: var(--fs-sub); color: var(--muted); font-weight: 500; }
.field-head { display: flex; align-items: center; justify-content: space-between; }
input, select {
  width: 100%; min-width: 0; min-height: 48px; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r-control); padding: 0 var(--s3); font-size: 16px; color: var(--ink); font-weight: 400;
}
input::placeholder { color: var(--faint); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-error { color: var(--danger); font-size: var(--fs-sub); margin: 0; }
.form-error:empty { display: none; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.row > * { min-width: 0; }

/* Segmented control */
.seg { display: flex; background: var(--surface-2); padding: 3px; border-radius: var(--r-control); gap: 2px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; background: transparent; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap; padding: 0 var(--s2);
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chips .group-label { width: 100%; font-size: var(--fs-caption); color: var(--faint); margin-top: var(--s1); }
.chip {
  min-height: 38px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* ---------- App shell ---------- */
.appbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  max-width: 640px; margin: 0 auto; padding: var(--s3) var(--s4) var(--s2);
}
.appbar h1 { font-size: var(--fs-title); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.appbar-actions { display: flex; align-items: center; gap: var(--s1); flex: none; }
.month-pill { display: flex; align-items: center; background: var(--surface); border-radius: var(--r-pill); border: 1px solid var(--line); }
.month-pill button { width: 40px; height: 40px; border: 0; background: transparent; cursor: pointer; font-size: 20px; color: var(--muted); border-radius: 50%; }
.month-pill button:active { background: var(--surface-2); }
.month-pill span { min-width: 56px; text-align: center; font-weight: 600; font-size: 15px; }

.wrap {
  max-width: 640px; margin: 0 auto;
  padding: var(--s1) var(--s4) calc(var(--tabbar-h) + var(--quickbar-h) + env(safe-area-inset-bottom, 0px) + var(--s6));
}
.wrap.no-quickbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--s6)); }
.view { display: grid; gap: var(--s3); grid-template-columns: minmax(0, 1fr); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border-radius: var(--r-card); padding: var(--s4); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.card-head h2 { font-size: var(--fs-headline); font-weight: 600; }
.sub { font-size: var(--fs-sub); color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: var(--s6) var(--s4); line-height: 1.7; }
.empty b { color: var(--ink); font-weight: 600; }

/* Summary */
.summary { display: grid; gap: var(--s3); }
.summary .eyebrow { font-size: var(--fs-sub); color: var(--muted); font-weight: 500; }
.summary .display { font-size: var(--fs-display); font-weight: 700; line-height: 1.1; margin-top: 2px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.stat { background: var(--surface-2); border-radius: var(--r-control); padding: var(--s3); display: grid; gap: 2px; min-width: 0; }
.stat .label { font-size: var(--fs-caption); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat b { font-size: var(--fs-headline); font-weight: 700; }
.stat .mini { font-size: var(--fs-caption); color: var(--muted); }
.swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; display: inline-block; }
.summary-foot { display: grid; gap: 6px; font-size: var(--fs-sub); color: var(--muted); }
.summary-foot .line { display: flex; justify-content: space-between; gap: var(--s2); }
.progress { height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: var(--r-pill); }

/* To-do list — one pattern for every reminder */
.todo { padding: 0 var(--s4); }
.todo-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); min-height: 64px; }
.todo-row:last-child { border-bottom: 0; }
.todo-ico {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 14px;
}
.todo-row.warn .todo-ico { background: var(--warning-soft); color: var(--warning); }
.todo-row.danger .todo-ico { background: var(--danger-soft); color: var(--danger); }
.todo-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.todo-text b { font-weight: 600; font-size: 15px; }
.todo-text span { font-size: var(--fs-sub); color: var(--muted); }
.status { font-weight: 600; }
.todo-row.warn .status { color: var(--warning); }
.todo-row.danger .status { color: var(--danger); }
.todo-row > .btn { flex: none; }
button.todo-row { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; color: inherit; border-bottom: 1px solid var(--line); }
button.todo-row:last-child { border-bottom: 0; }
.chev { color: var(--faint); font-size: 22px; line-height: 1; flex: none; }

/* Breakdown */
.disclosure { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--s2); background: transparent; border: 0; padding: 0; cursor: pointer; text-align: left; min-height: 36px; color: inherit; }
.disclosure h2 { font-size: var(--fs-headline); font-weight: 600; }
.disclosure .meta { display: flex; align-items: center; gap: var(--s2); color: var(--muted); font-size: var(--fs-sub); }
.disclosure .meta b { color: var(--ink); font-weight: 600; font-size: 15px; }
.disclosure .chev { transition: transform .2s ease; }
.disclosure[aria-expanded="true"] .chev { transform: rotate(90deg); }
.bars { display: grid; gap: var(--s3); margin-top: var(--s3); }
.stack { display: flex; height: 8px; border-radius: var(--r-pill); overflow: hidden; background: var(--surface-2); gap: 2px; }
.stack span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--fs-sub); color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { color: var(--ink); font-weight: 600; }
.details { margin-top: var(--s4); padding-top: var(--s2); border-top: 1px solid var(--line); display: grid; gap: 2px; }
.details h3 { font-size: var(--fs-sub); color: var(--muted); font-weight: 600; margin: var(--s3) 0 var(--s1); }
.bar-row { display: grid; grid-template-columns: 5.5em 1fr auto; gap: var(--s3); align-items: center; font-size: 14px; min-height: 30px; }
.bar-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: var(--r-pill); }

/* Entries */
.day { display: grid; gap: var(--s2); }
.day + .day { margin-top: var(--s2); }
.day-head { display: flex; justify-content: space-between; font-size: var(--fs-sub); color: var(--muted); padding: var(--s2) var(--s1) 0; }
.list { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-1); overflow: hidden; }
.entry {
  width: 100%; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4);
  border: 0; background: transparent; text-align: left; cursor: pointer; min-height: 62px; position: relative; color: inherit;
}
.entry + .entry::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--line); }
.entry:active { background: var(--surface-2); }
.glyph {
  width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center;
  font-size: 15px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.glyph.living { background: color-mix(in srgb, var(--living) 14%, transparent); color: var(--living); }
.glyph.baby { background: color-mix(in srgb, var(--baby) 15%, transparent); color: var(--baby); }
.glyph.cat { background: color-mix(in srgb, var(--cat) 15%, transparent); color: var(--cat); }
.glyph.in { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.entry .meta { flex: 1; min-width: 0; display: grid; }
.entry .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { font-weight: 600; white-space: nowrap; }
.amt.in { color: var(--success); }

/* Assets — group totals lead, items stay quiet */
.asset-groups { display: grid; gap: var(--s3); }
.asset-group { padding-bottom: var(--s2); }
.group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding-bottom: var(--s3); border-bottom: 1px solid var(--line); }
.group-head h2 { font-size: var(--fs-title); font-weight: 700; line-height: 1.2; }
.group-head .sub { display: block; margin-top: 2px; }
.group-head > b { font-size: var(--fs-title); font-weight: 700; white-space: nowrap; line-height: 1.2; }
.asset-row {
  width: 100%; display: flex; align-items: center; gap: var(--s3); padding: 10px 0; border: 0;
  border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; min-height: 52px; color: inherit;
}
.asset-group .asset-row:last-child { border-bottom: 0; }
.ar-main { flex: 1; min-width: 0; display: grid; }
.ar-name { font-size: 14px; font-weight: 500; }
.ar-sub { font-size: var(--fs-caption); color: var(--muted); }
.ar-val { font-size: 14px; font-weight: 500; white-space: nowrap; }
.add-asset { background: var(--surface); color: var(--primary); border: 1px dashed var(--line); }
.gain { color: var(--gain); }
.loss { color: var(--loss); }
.fx-note { margin: 0; padding: 0 var(--s1); font-size: var(--fs-caption); color: var(--faint); }
.trend { display: flex; gap: var(--s2); align-items: flex-end; height: 64px; }
.trend-col { flex: 1; display: grid; grid-template-rows: 1fr auto; justify-items: center; gap: 4px; height: 100%; min-width: 0; }
.trend-bar { width: 100%; max-width: 28px; display: flex; align-items: flex-end; height: 100%; }
.trend-bar span { display: block; width: 100%; background: color-mix(in srgb, var(--primary) 30%, transparent); border-radius: 4px 4px 2px 2px; }
.trend-col:last-child .trend-bar span { background: var(--primary); }
.trend-col small { font-size: 11px; color: var(--faint); }

/* Settings — inset grouped list */
.profile { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s1) var(--s2); }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 20px; flex: none; }
.profile b { font-size: var(--fs-headline); display: block; }
.section-title { font-size: var(--fs-sub); color: var(--muted); font-weight: 600; padding: var(--s3) var(--s1) 0; }
.settings-list { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-1); overflow: hidden; }
.settings-row {
  width: 100%; display: flex; align-items: center; gap: var(--s3); min-height: 52px; padding: var(--s2) var(--s4);
  border: 0; background: transparent; text-align: left; cursor: pointer; position: relative; font-size: var(--fs-body); color: inherit;
}
.settings-row + .settings-row::before { content: ""; position: absolute; top: 0; left: var(--s4); right: 0; border-top: 1px solid var(--line); }
.settings-row:active { background: var(--surface-2); }
.settings-row .label { flex: 1; min-width: 0; }
.settings-row .value { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.settings-row.danger { color: var(--danger); font-weight: 500; }
.settings-row.danger .label { text-align: center; }
.settings-foot { font-size: var(--fs-caption); color: var(--faint); text-align: center; padding: var(--s3); }

/* Settlement sheet */
.rule { font-size: var(--fs-sub); color: var(--muted); background: var(--surface-2); border-radius: var(--r-control); padding: var(--s3); margin: 0; }
.week { padding: var(--s3) 0; border-bottom: 1px solid var(--line); display: grid; gap: var(--s2); }
.week:last-child { border-bottom: 0; }
.week-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.week-head b { font-size: var(--fs-headline); }
.tag { font-size: var(--fs-caption); font-weight: 600; padding: 3px 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.warn { background: var(--warning-soft); color: var(--warning); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.ok { background: var(--primary-soft); color: var(--primary); }
.transfers { display: grid; gap: 6px; }
.transfer { display: flex; align-items: center; gap: var(--s2); font-size: 15px; }
.transfer b { margin-left: auto; font-weight: 600; }
.acct-tag { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; flex: none; }
.acct-tag.living { background: color-mix(in srgb, var(--living) 14%, transparent); color: var(--living); }
.acct-tag.baby { background: color-mix(in srgb, var(--baby) 16%, transparent); color: var(--baby); }
.acct-tag.cat { background: color-mix(in srgb, var(--cat) 16%, transparent); color: var(--cat); }
.history-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: 0; }
.history-row .transfers { flex: 1; min-width: 0; }
.sheet-section { font-size: var(--fs-sub); color: var(--muted); font-weight: 600; margin-top: var(--s2); }

/* Cards sheet */
.card-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.card-row:last-child { border-bottom: 0; }
.cr-main { flex: 1; min-width: 0; display: grid; text-align: left; border: 0; background: transparent; padding: 0; cursor: pointer; min-height: 44px; color: inherit; }
.cr-side { display: grid; justify-items: end; gap: 2px; text-align: right; }

/* Category manager */
.cm-group { display: grid; gap: var(--s2); padding: var(--s3) 0; }
.cm-group + .cm-group { border-top: 1px solid var(--line); }
.cm-group h3 { font-size: var(--fs-sub); color: var(--muted); font-weight: 600; }
.cm-chip { display: inline-flex; align-items: center; gap: 0; padding-right: 2px; cursor: default; }
.cm-del { border: 0; background: transparent; color: var(--faint); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 12px; }
.cm-del:active { background: var(--danger-soft); color: var(--danger); }
.cm-add { display: flex; gap: var(--s2); }
.cm-add input { flex: 1; }

/* Monthly asset update */
.u-group { font-size: var(--fs-sub); color: var(--muted); font-weight: 600; margin-top: var(--s2); }
.u-row { padding: var(--s3) 0; border-bottom: 1px solid var(--line); display: grid; gap: var(--s2); }
.u-name { font-weight: 500; }
.u-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--s2); }
.u-twd { font-size: var(--fs-caption); color: var(--muted); }
.update-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: var(--s2); }
.update-total b { font-size: var(--fs-title); }

/* ---------- Quick bar & tab bar ---------- */
.quickbar {
  position: fixed; left: 0; right: 0; z-index: 6;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  display: flex; gap: var(--s2); align-items: center; padding: var(--s2) var(--s3);
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.quickbar input { flex: 1; border-radius: var(--r-pill); padding: 0 var(--s4); }
.quickbar .btn.primary { border-radius: var(--r-pill); min-width: 52px; min-height: 48px; }
.quickbar .add { width: 48px; height: 48px; background: var(--surface); border: 1px solid var(--line); }
.mic { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; }
.mic.listening { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex;
  padding: 0 var(--s2) env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; height: var(--tabbar-h); border: 0; background: transparent; color: var(--faint); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 500; position: relative;
}
.tabbar button[aria-current="page"] { color: var(--primary); font-weight: 700; }
.tabbar button.dot-badge::after { top: 7px; right: calc(50% - 19px); box-shadow: 0 0 0 2px var(--surface); }
@media (min-width: 700px) {
  .quickbar, .tabbar { left: 50%; transform: translateX(-50%); width: 640px; }
  .tabbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 16px 16px 0 0; }
}

/* ---------- Sheets ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink); width: 100%; max-width: 560px;
  border-radius: var(--r-sheet) var(--r-sheet) 0 0; margin: auto auto 0; max-height: 92dvh; overflow: auto;
  box-shadow: var(--shadow-2);
}
dialog.sheet[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) { dialog.sheet { border-radius: var(--r-sheet); margin: auto; } }
dialog::backdrop { background: rgba(10, 16, 14, .45); }
dialog.sheet > form, dialog.sheet > div { padding: 0 var(--s5) calc(var(--s5) + env(safe-area-inset-bottom, 0px)); display: grid; gap: var(--s4); }
.sheet-head {
  display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 1;
  background: var(--surface); padding-top: var(--s3); margin: 0 -10px 0 0;
}
.sheet-head h2 { font-size: var(--fs-headline); font-weight: 600; }
.sheet-note { margin: 0; font-size: var(--fs-sub); color: var(--muted); }
.sheet-actions { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); }
.sheet-actions .btn.primary { margin-left: auto; min-width: 128px; }
.amount-input { font-size: 28px; font-weight: 700; min-height: 60px; }
#asset-cur-other { margin-top: var(--s2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + var(--quickbar-h) + env(safe-area-inset-bottom, 0px) + var(--s2));
  width: max-content; max-width: calc(100% - 32px); display: flex; gap: var(--s1); align-items: center;
  background: var(--ink); color: var(--bg); padding: var(--s1) var(--s2) var(--s1) var(--s4); border-radius: var(--r-control);
  box-shadow: var(--shadow-2); font-size: 14px; animation: toast-in .18s ease;
}
.toast.no-quickbar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--s3)); }
.toast > span { padding: 8px 0; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; min-height: 40px; padding: 0 var(--s2); cursor: pointer; white-space: nowrap; flex: none; text-decoration: underline; text-underline-offset: 3px; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 第一次使用：建立帳號 */
.setup-person { border: 1px solid var(--line); border-radius: 14px; padding: var(--s3) var(--s4) var(--s4); margin: 0; display: grid; gap: var(--s3); min-width: 0; }
.setup-person legend { padding: 0 6px; font-size: var(--fs-sub); font-weight: 700; color: var(--ink); }
.setup-note { margin: 0; font-size: var(--fs-caption); color: var(--muted); line-height: 1.6; }
