:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e6e8ec;
  --text: #1a1d21;
  --text-2: #5c626b;
  --text-3: #9aa0a9;
  --accent: #4f6ef7;
  --accent-soft: #eef1fe;
  --green: #2fa36b;
  --green-soft: #e9f6ef;
  --amber: #d98a1f;
  --amber-soft: #fbf3e4;
  --red: #d95757;
  --red-soft: #fbecec;
  --purple: #8a63d2;
  --purple-soft: #f2edfb;
  --teal: #2b9aa8;
  --teal-soft: #e7f5f7;
  --shadow: 0 1px 2px rgba(16,20,28,.04), 0 4px 16px rgba(16,20,28,.05);
  --radius: 16px;
}
[data-theme="dark"] {
  --bg: #101216;
  --surface: #191c22;
  --surface-2: #22262e;
  --border: #2a2e37;
  --text: #eceef1;
  --text-2: #a2a8b3;
  --text-3: #6b7280;
  --accent: #7b90ff;
  --accent-soft: #232a45;
  --green: #4cc38a;
  --green-soft: #17301f;
  --amber: #e5a54a;
  --amber-soft: #33270f;
  --red: #e57373;
  --red-soft: #351b1b;
  --purple: #a98ae8;
  --purple-soft: #291f3d;
  --teal: #4fc3d1;
  --teal-soft: #10303a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro TC", "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 220px; flex-shrink: 0; padding: 24px 14px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 700;
}
.logo-name { font-size: 14.5px; font-weight: 700; letter-spacing: .2px; }
.logo-name span { display: block; font-size: 10.5px; font-weight: 500; color: var(--text-3); letter-spacing: .5px; }
.nav-label { font-size: 10.5px; font-weight: 600; color: var(--text-3); letter-spacing: 1px; padding: 14px 12px 6px; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 10px;
  font-size: 13.5px; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; font-size: 15px; }
.sidebar-foot { margin-top: auto; padding: 10px 12px; font-size: 11.5px; color: var(--text-3); }

/* ── Main ── */
.main { flex: 1; padding: 28px 36px 60px; max-width: 1180px; margin: 0 auto; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.topbar .sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }
.span-3 { grid-column: span 3; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 650; }
.card-title .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ── Controls ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: filter .15s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn.ai { background: linear-gradient(120deg, var(--accent), var(--purple)); border: none; color: #fff; }
.btn.ai:hover { filter: brightness(1.08); }

.chip-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 99px; font-size: 12.5px; color: var(--text-2);
  cursor: pointer; box-shadow: var(--shadow);
}
.chip-btn:hover { color: var(--text); }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 130px; }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; padding: 9px 12px; background: var(--surface-2); color: var(--text-2); font-weight: 600; white-space: nowrap; }
.tbl td { padding: 8px 12px; border-top: 1px solid var(--border); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.tbl tr:hover td { background: var(--surface-2); }
.amount-neg { color: var(--red); font-weight: 600; }
.amount-pos { color: var(--green); font-weight: 600; }

.pill { font-size: 10.5px; padding: 3px 9px; border-radius: 99px; font-weight: 600; background: var(--surface-2); color: var(--text-2); display: inline-block; }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.purple { background: var(--purple-soft); color: var(--purple); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }

/* ── 匯入：多圖縮圖 ── */
.imgs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.img-thumb { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.img-thumb img { display: block; width: 100%; height: 130px; object-fit: cover; }
.img-x { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(16,20,28,.62); color: #fff; font-size: 12px; cursor: pointer; line-height: 1; }
.img-x:hover { background: var(--red); }
.img-name { font-size: 10.5px; color: var(--text-3); padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 44px 20px;
  text-align: center; color: var(--text-2); cursor: pointer; transition: border-color .15s, background .15s;
  background: var(--surface);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 32px; margin-bottom: 10px; }
.dropzone .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* ── Metrics ── */
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.metric .m-label { font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
.metric .m-value { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.metric .m-value small { font-size: 11px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.metric .m-sub { font-size: 11px; margin-top: 3px; color: var(--text-3); }

/* ── Bars ── */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar-row .bar-label { width: 72px; flex-shrink: 0; color: var(--text-2); }
.bar-row .bar-track { flex: 1; height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar-row .bar-val { width: 90px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }

.budget-bar { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.budget-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--green), var(--amber)); }

/* ── AI output ── */
.ai-box {
  background: linear-gradient(120deg, var(--accent-soft), var(--surface) 60%);
  border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  font-size: 13.5px; line-height: 1.8; color: var(--text);
}
.ai-box h4 { font-size: 12px; color: var(--accent); letter-spacing: .8px; text-transform: uppercase; margin-bottom: 8px; }
.ai-box .meta { font-size: 11px; color: var(--text-3); margin-top: 10px; }
.ai-box p { margin-bottom: 8px; }
.ai-box ul { margin: 4px 0 8px 18px; }
.ai-box li { margin-bottom: 4px; }

/* Todos */
.todo { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.todo:last-child { border-bottom: 0; }
.todo input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }
.todo.done label { text-decoration: line-through; color: var(--text-3); }
.todo label { flex: 1; cursor: pointer; }
.todo .del { color: var(--text-3); cursor: pointer; font-size: 14px; padding: 0 4px; background: none; border: none; }
.todo .del:hover { color: var(--red); }

/* Toast */
#toasts { position: fixed; bottom: 24px; right: 24px; z-index: 99; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 420px; animation: pop .2s ease;
}
.toast.err { background: var(--red); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* Spinner */
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; }
.btn:not(.primary):not(.ai) .spin { border-color: var(--border); border-top-color: var(--accent); }
@keyframes rot { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 28px 10px; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.muted { color: var(--text-3); font-size: 12px; }
.section-title { font-size: 14px; font-weight: 700; margin: 22px 0 10px; }

/* ── Dashboard: Morning Brief ── */
.brief-body { font-size: 13.5px; line-height: 1.85; }
.brief-body p { margin-bottom: 8px; }
.brief-body ul { margin: 4px 0 8px 18px; }
.brief-body li { margin-bottom: 4px; }
.brief-body b { color: var(--accent); }

/* ── Dashboard: 今日重點 ── */
.focus-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.focus-item:last-child { border-bottom: 0; }
.focus-no { width: 22px; height: 22px; flex-shrink: 0; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.focus-text { flex: 1; min-width: 0; }

/* ── Dashboard: 生活服務 / 財務提醒 ── */
.svc-item { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.svc-item b { color: var(--text); font-weight: 600; }
.svc-item a { color: var(--accent); }
.svc-ico { flex-shrink: 0; font-size: 15px; line-height: 1.4; }
.networth { font-size: 26px; font-weight: 750; letter-spacing: -.5px; }
.inline-coach { font-size: 12.5px; line-height: 1.6; color: var(--text-2); background: var(--teal-soft); border-radius: 10px; padding: 10px 12px; }
.inline-coach b { color: var(--teal); }

/* ── 問 AI 浮層 ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,20,28,.45); backdrop-filter: blur(2px); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; animation: pop .18s ease; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; width: 100%; max-width: 560px; }
.ask-answer { background: var(--surface-2); border-radius: 12px; padding: 14px; max-height: 46vh; overflow-y: auto; }
.ask-q { font-size: 12px; font-weight: 600; color: var(--text-3); margin-bottom: 8px; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ask-chip { font-size: 11.5px; padding: 5px 10px; }

/* ── 即將推出 ── */
.soon-badge { display: inline-block; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 5px 12px; border-radius: 99px; }
.soon-list { margin: 4px 0 0 18px; font-size: 13px; color: var(--text-2); line-height: 1.9; }

/* ── 理財年度儀表板 / 投資 ── */
.fin-num { font-size: 23px; font-weight: 750; letter-spacing: -.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.cat-row { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.cat-row:last-child { border-bottom: 0; }
.cat-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.cat-name { flex: 1; min-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-pct { width: 48px; flex-shrink: 0; text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; }
.cat-amt { width: 92px; flex-shrink: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
svg .ch-t { fill: var(--text-3); font-size: 11px; }
.donut-grid { display: grid; grid-template-columns: 1fr 1fr; justify-items: center; gap: 2px; }
select.txcat { width: auto; padding: 4px 8px; font-size: 12px; border-radius: 8px; }

/* ── 行事曆 ── */
.cal-day { font-size: 11.5px; font-weight: 700; color: var(--text-3); letter-spacing: .5px; padding: 8px 2px 3px; border-bottom: 1px solid var(--border); }
.cal-item { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 13px; border-bottom: 1px solid var(--border); }
.cal-item:last-child { border-bottom: 0; }
.cal-time { flex-shrink: 0; font-size: 11.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 2px 7px; font-variant-numeric: tabular-nums; }
.cal-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item .del { color: var(--text-3); cursor: pointer; font-size: 13px; background: none; border: none; padding: 0 4px; }
.cal-item .del:hover { color: var(--red); }
.ch-legend { display: flex; gap: 16px; justify-content: center; font-size: 12px; color: var(--text-2); margin-top: 8px; flex-wrap: wrap; }
.ch-legend .ld { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ── AI 助理對話 ── */
.chat-thread { display: flex; flex-direction: column; gap: 12px; max-height: 460px; overflow-y: auto; padding: 4px; }
.chat-row { display: flex; }
.chat-row.user { justify-content: flex-end; }
.chat-row.ai { justify-content: flex-start; }
.chat-bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.7; }
.chat-bubble.user { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.ai { background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.chat-bubble.ai .brief-body { font-size: 13.5px; }
.chat-bubble.ai .brief-body p:last-child { margin-bottom: 0; }
.chat-intro { text-align: center; color: var(--text-2); font-size: 13.5px; padding: 20px 10px; }
.chat-sugg { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.chat-chip { font-size: 12.5px; padding: 6px 12px; }

/* ── 生活探索 ── */
.exp-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.exp-chip { font-size: 12.5px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; user-select: none; transition: background .15s, color .15s, border-color .15s; }
.exp-chip:hover { border-color: var(--accent); }
.exp-chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.exp-item { display: flex; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--border); }
.exp-item:last-child { border-bottom: 0; }
.exp-ic { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-size: 22px; flex-shrink: 0; background: var(--surface-2); }
.exp-title { font-size: 14.5px; font-weight: 650; }
.exp-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.exp-why { font-size: 12.5px; color: var(--accent); margin-top: 6px; line-height: 1.55; }
.fav-btn { flex-shrink: 0; align-self: flex-start; background: none; border: none; cursor: pointer; font-size: 17px; color: var(--text-3); padding: 2px 4px; line-height: 1; transition: color .15s; }
.fav-btn:hover { color: var(--amber); }
.fav-btn.on { color: var(--amber); }

/* ── Weekly Report ── */
.wk-stat { font-size: 22px; font-weight: 750; letter-spacing: -.4px; margin-top: 6px; }
.wk-stat small { font-size: 12px; font-weight: 500; color: var(--text-3); }
.wk-delta { display: inline-block; margin-top: 6px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.wk-delta.up { color: var(--green); background: var(--green-soft); }
.wk-delta.down { color: var(--red); background: var(--red-soft); }
.wk-delta.flat { color: var(--text-3); background: var(--surface-2); }
.wk-days { display: flex; gap: 8px; align-items: flex-end; height: 120px; padding-top: 8px; }
.wk-day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.wk-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.wk-bar { width: 60%; min-height: 2px; border-radius: 5px 5px 0 0; background: var(--teal); transition: height .2s; }
.wk-day-label { font-size: 11px; color: var(--text-2); }
.wk-day-val { font-size: 10.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

@media (max-width: 1024px) {
  .sidebar { display: none; }
  .span-8, .span-6, .span-4, .span-3 { grid-column: span 12; }
  .main { padding: 18px; }
  #mobilenav { display: flex !important; }
}
#mobilenav {
  display: none; gap: 6px; overflow-x: auto; padding: 10px 14px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 5;
}
#mobilenav .nav-item { white-space: nowrap; }
