/* app.css — 溫馨淡雅風格，手機優先 (375x812 基準) */
:root {
  --bg: #FBF6EE;          /* 暖米白背景 */
  --card: #FFFFFF;
  --card-soft: #FDF9F3;
  --ink: #4A4238;         /* 柔和深棕，非純黑 */
  --ink-soft: #8A8072;
  --muted: #A79E90;
  --line: #EFE7DC;
  --accent: #C9A88F;      /* 暖棕強調 */
  --accent-soft: #E8DDD0;
  --pos: #6FA07A;         /* 柔和綠（收入） */
  --neg: #C97C7C;         /* 柔和紅（支出） */
  --shadow: 0 2px 10px rgba(120, 100, 80, 0.06);
  --radius: 16px;
  --nav-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.muted { color: var(--muted); }
.small { font-size: 15px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.big { font-size: 20px; font-weight: 700; }
.center { text-align: center; }

/* ---- 頁首 ---- */
.page-hdr {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  padding: 14px 12px; padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.page-hdr h1 { margin: 0; font-size: 18px; text-align: center; font-weight: 700; }
.hdr-back, .hdr-action {
  background: none; border: none; color: var(--accent);
  font-size: 16px; padding: 4px 6px; cursor: pointer; border-radius: 8px;
}
.hdr-back { font-size: 26px; line-height: 1; justify-self: start; }
.hdr-action { justify-self: end; font-weight: 600; }
.hdr-spacer { display: block; }

/* ---- 通用 ---- */
.scroll { padding: 0 12px 20px; }
.sec { margin: 14px 0; }
.sec-title { font-size: 15px; color: var(--ink-soft); margin: 16px 4px 8px; font-weight: 600; }
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin: 10px 0;
}
.card.neg { color: var(--neg); }

.empty { text-align: center; padding: 60px 24px; color: var(--muted); }
.empty-emoji { font-size: 44px; margin-bottom: 12px; }
.empty-text { font-size: 16px; margin-bottom: 6px; color: var(--ink-soft); }
.empty-sub { font-size: 15px; }

/* ---- 資產總覽 ---- */
.asset-summary {
  margin: 12px; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, #F3E9DC, #EDE3D3);
  box-shadow: var(--shadow);
}
.asset-net { display: flex; flex-direction: column; gap: 2px; }
.asset-net-label { font-size: 15px; color: var(--ink-soft); }
.asset-net-val { font-size: 30px; font-weight: 700; letter-spacing: 0.5px; }
.asset-split { display: flex; gap: 20px; margin-top: 10px; font-size: 15px; }

/* ---- 帳戶分組 ---- */
.group-hdr, .month-hdr, .day-hdr {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 4px; margin-bottom: 2px;
}
.group-name { font-weight: 700; font-size: 15px; }
.group-sub { font-weight: 600; color: var(--ink-soft); }
.acc-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); padding: 14px; border-radius: 12px; margin: 6px 0;
  box-shadow: var(--shadow); cursor: pointer;
}
.acc-row.muted { opacity: 0.6; }
.acc-name-wrap { display: flex; flex-direction: column; gap: 2px; }
.acc-name { font-size: 15px; }
.acc-foreign { font-variant-numeric: tabular-nums; }
.acc-bal { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- 月份切換 ---- */
.month-switch {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); margin: 12px; padding: 8px 12px; border-radius: 14px;
  box-shadow: var(--shadow);
}
.ms-btn { background: none; border: none; font-size: 24px; color: var(--accent); cursor: pointer; padding: 4px 12px; }
.ms-mid { text-align: center; flex: 1; }
.ms-title { font-weight: 700; font-size: 16px; }
.ms-title.center { flex: 1; text-align: center; }
.ms-sum { display: flex; gap: 10px; justify-content: center; font-size: 15px; margin-top: 2px; flex-wrap: wrap; }

/* ---- 記錄列 ---- */
.month-hdr, .day-hdr { font-size: 15px; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
.day-date { font-weight: 600; }
.day-sum, .month-sum { display: flex; gap: 8px; font-variant-numeric: tabular-nums; }
.rec-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); padding: 12px 14px; border-radius: 12px; margin: 6px 0;
  box-shadow: var(--shadow); cursor: pointer;
}
.rec-ic {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  color: #fff;
}
.rec-mid { flex: 1; min-width: 0; }
.rec-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-sub { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; flex: none; }

/* ---- 底部導覽 ---- */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  max-width: 480px; margin: 0 auto;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: stretch;
  background: rgba(253, 249, 243, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.nav-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; padding: 4px 0;
}
.nav-btn.active { color: var(--accent); }
.nav-ic { font-size: 20px; }
.nav-primary {
  color: #fff;
}
.nav-primary .nav-ic {
  background: var(--accent); color: #fff;
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin-top: -18px; box-shadow: 0 4px 12px rgba(180, 150, 120, 0.4);
}

/* ---- 表單 ---- */
.form { padding-top: 6px; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 10px 2px; }
.field-label { font-size: 15px; color: var(--ink-soft); margin: 8px 2px 2px; }
.inp {
  width: 100%; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 12px 14px; font-size: 16px; color: var(--ink);
  font-family: inherit; outline: none;
}
.inp:focus { border-color: var(--accent); }
textarea.inp { resize: vertical; }
select.inp { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23A79E90' fill='none' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }

.amt-wrap { display: flex; align-items: center; gap: 8px; margin: 12px 2px; padding: 8px 14px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }
.amt-cur { font-size: 20px; color: var(--ink-soft); flex-shrink: 0; }
.amt-inp { flex: 1; min-width: 0; border: none; box-shadow: none; font-size: 34px; font-weight: 700; padding: 6px 0; text-align: right; }
.amt-cur-sel { width: auto; flex-shrink: 0; padding: 6px 22px 6px 10px; font-size: 14px; }

.type-tabs { display: flex; gap: 8px; margin: 12px 2px; }
.type-tabs.mini { margin: 8px 0; }
.type-tab {
  flex: 1; padding: 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink-soft); font-size: 15px; cursor: pointer;
  font-family: inherit;
}
.type-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.type-tab.active.支出 { background: var(--neg); border-color: var(--neg); }
.type-tab.active.收入 { background: var(--pos); border-color: var(--pos); }

.reward-hint { margin: 8px 2px; padding: 10px 14px; background: #F1F6EE; border-radius: 12px; font-size: 15px; color: var(--pos); }
.reward-hint b { color: var(--pos); }

/* ---- 按鈕 ---- */
.btn-primary, .btn-danger, .btn-ghost {
  border: none; border-radius: 12px; padding: 13px; font-size: 16px;
  cursor: pointer; font-family: inherit; font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: #F5E2E2; color: var(--neg); }
.btn-ghost { background: var(--accent-soft); color: var(--ink); }
.full { width: 100%; display: block; margin: 12px 0 0; }

/* ---- Sheet (底部彈出) ---- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(60, 50, 40, 0.35);
  display: flex; align-items: flex-end; opacity: 0; transition: opacity 0.2s;
}
.sheet-overlay.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 480px; margin: 0 auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  max-height: 90vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.25s;
}
.sheet-overlay.show .sheet { transform: translateY(0); }
.sheet-hdr {
  display: grid; grid-template-columns: 60px 1fr 60px; align-items: center;
  padding: 14px; border-bottom: 1px solid var(--line);
}
.sheet-title { text-align: center; font-weight: 700; }
.sheet-cancel { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; justify-self: start; }
.sheet-save { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; font-size: 15px; justify-self: end; }
.sheet-body { overflow-y: auto; padding: 8px 14px calc(20px + env(safe-area-inset-bottom)); }

/* ---- 確認框 ---- */
.confirm-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(60, 50, 40, 0.4); display: flex; align-items: center; justify-content: center; padding: 30px; }
.confirm-box { background: var(--card); border-radius: 18px; padding: 22px; max-width: 320px; width: 100%; }
.confirm-msg { text-align: center; margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions button { flex: 1; }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(74, 66, 56, 0.94); color: #fff; padding: 11px 20px; border-radius: 22px;
  font-size: 15px; z-index: 100; opacity: 0; pointer-events: none; transition: all 0.25s; max-width: 90%;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 統計 ---- */
.stat-totals { display: flex; gap: 8px; margin: 12px; }
.stat-tot { flex: 1; background: var(--card); border-radius: 14px; padding: 12px; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.stat-tot .big { font-size: 17px; }
.donut-wrap { display: flex; justify-content: center; padding: 14px; }
.donut-center { font-size: 15px; font-weight: 700; fill: var(--ink); }
.donut-center-sub { font-size: 12px; fill: var(--muted); }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 9px 4px; }
.cat-mid { flex: 1; min-width: 0; }
.cat-name { font-size: 15px; margin-bottom: 4px; }
.cat-bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 4px; }
.cat-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-card { background: var(--card); border-radius: var(--radius); padding: 14px 8px; box-shadow: var(--shadow); }
.bars .bar-label { font-size: 11px; fill: var(--muted); }

/* ---- 帳戶工具列／排序模式 ---- */
.acc-toolbar { display: flex; align-items: center; gap: 10px; margin: 4px 12px 8px; flex-wrap: wrap; }
.btn-ghost.sm { padding: 8px 14px; font-size: 15px; }
.grow { flex: 1; min-width: 0; }
.inp.sm { width: auto; padding: 8px 26px 8px 10px; font-size: 14px; }
.acc-row.sort { cursor: default; gap: 10px; }
.acc-name.grow { flex: 1; }
.ord-btns { display: flex; gap: 4px; flex: none; }
.ord-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card-soft); color: var(--accent); font-size: 15px; cursor: pointer;
}
.ord-btn:disabled { opacity: 0.3; cursor: default; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-family: inherit; padding: 2px 4px; }
.link-btn.small { font-size: 14px; }

/* ---- 帳戶分組管理 ---- */
.group-manage-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); padding: 12px 14px; border-radius: 12px; margin: 6px 0;
  box-shadow: var(--shadow);
}
.group-manage-row .grow { cursor: pointer; }

/* ---- 月曆 ---- */
.cal { margin: 10px 12px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; }
.cal-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head .cal-wd { color: var(--muted); font-size: 13px; text-align: center; padding: 4px 0; }
.cal-cell {
  min-height: 52px; border-radius: 8px; padding: 4px 2px; text-align: center; cursor: pointer;
}
.cal-cell.empty { cursor: default; }
.cal-cell.has { background: var(--card-soft); }
.cal-d { font-size: 13px; color: var(--ink-soft); }
.cal-net { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.cal-day-panel { margin: 4px 12px; }

/* ---- 搜尋 ---- */
.search-summary { display: flex; gap: 12px; padding: 10px 4px; font-size: 15px; align-items: baseline; }

/* ---- 預算 ---- */
.budget-card { margin: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 600; }
.budget-sub { margin-top: 6px; }
.cat-budget { margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.cat-bar.mini { height: 4px; flex: 1; }

/* ---- 更多 ---- */
.more-stat { display: flex; gap: 8px; margin: 12px; }
.stat-box { flex: 1; background: var(--card); border-radius: 14px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.stat-box-n { font-size: 22px; font-weight: 700; }
.stat-box-l { font-size: 15px; color: var(--muted); }
.more-row { display: flex; align-items: center; gap: 14px; background: var(--card); padding: 15px; border-radius: 12px; margin: 8px 0; box-shadow: var(--shadow); cursor: pointer; }
.more-ic { font-size: 24px; width: 32px; text-align: center; }
.more-mid { flex: 1; }
.more-label { font-size: 15px; font-weight: 600; }
.more-desc { font-size: 15px; color: var(--muted); }
.more-arrow { color: var(--muted); font-size: 20px; }
.app-footer { text-align: center; color: var(--muted); font-size: 15px; margin: 24px 0; }

/* ---- 信用卡 ---- */
.credit-card { cursor: pointer; }
.cc-top, .cc-reward, .bill-top, .bill-mid, .hd-top { display: flex; justify-content: space-between; align-items: center; }
.cc-name, .bill-name, .hd-code { font-weight: 700; font-size: 16px; }
.cc-bal { font-variant-numeric: tabular-nums; }
.cc-rules { margin: 6px 0; }
.cc-reward { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.cc-reward-val { font-weight: 700; font-size: 16px; }
.cc-cap { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.progress { flex: 1; height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 5px; }
.bill-card { }
.bill-days { font-weight: 600; }
.bill-mid { margin: 8px 0; }
.bill-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.bill-due { font-size: 15px; margin-bottom: 10px; }

/* ---- 持股 ---- */
.hd-card { cursor: pointer; }
.hd-name { color: var(--ink-soft); font-weight: 400; }
.hd-mv { font-weight: 700; font-variant-numeric: tabular-nums; }
.hd-mid { margin: 6px 0; }
.hd-pnl { font-weight: 600; }

/* ---- 週期 ---- */
.up-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.up-name { font-size: 15px; }
.up-amt { font-weight: 600; }

/* ---- 匯入 ---- */
.import-progress { margin: 14px; }
.kv { display: flex; justify-content: space-between; padding: 6px 2px; border-bottom: 1px solid var(--line); }

/* ---- 掃描 ---- */
.scan-frame { border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; margin: 10px 0; display: flex; align-items: center; justify-content: center; }
.scan-video { width: 100%; height: 100%; object-fit: cover; }
.scan-status { text-align: center; padding: 8px; }

/* ---- 類別管理 / picker ---- */
.cat-manage-row { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 12px 14px; border-radius: 12px; margin: 6px 0; box-shadow: var(--shadow); cursor: pointer; }
.cat-manage-row .cat-name { flex: 1; }
.pick-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 2px 8px; }
.pick-emoji { width: 44px; height: 44px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.pick-emoji.sel { border-color: var(--accent); background: var(--accent-soft); }
.pick-color { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.pick-color.sel { border-color: var(--ink); }
