/* ============================================================
   Life Finance OS — Design System
   安静 · 温和 · 干净 · 有生活感
   ============================================================ */

:root {
  /* Surfaces */
  --bg: #F4F6F8;
  --bg-soft: #F8FAFB;
  --surface: #FFFFFF;
  --surface-2: #FBFCFD;
  --surface-sunken: #F1F3F6;

  /* Text */
  --text: #1E2A33;
  --text-2: #54606E;
  --text-3: #93A0AD;
  --text-faint: #B8C2CC;

  /* Lines */
  --border: #E9ECF0;
  --border-strong: #DDE2E8;

  /* Area palette (soft, light-theme friendly) */
  --c-income: #4FA777;      /* 美国收入 / 正现金流 */
  --c-income-bg: #E7F4EC;
  --c-life: #E89255;         /* 美国生活 */
  --c-life-bg: #FBEEE3;
  --c-love: #9376C4;         /* 恋爱与旅行 */
  --c-love-bg: #F0EBF7;
  --c-home: #3FA9BD;         /* 家庭民宿 */
  --c-home-bg: #E2F2F5;
  --c-social: #C26B7E;       /* 人情与家庭 */
  --c-social-bg: #F6E9ED;
  --c-biz: #4A5C7A;          /* 生意往来 */
  --c-biz-bg: #E9EDF2;
  --c-other: #98A1AE;        /* 其他 */
  --c-other-bg: #EEF1F3;
  --c-blue: #2E5C8A;         /* 资产 / 稳定 */
  --c-blue-bg: #E6EEF6;
  --c-red: #D9605A;           /* 仅异常 */
  --c-red-bg: #FBE9E7;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --num: "SF Pro Display", -apple-system, "Segoe UI", "PingFang SC", sans-serif;

  /* Radii */
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(30,42,51,.04), 0 2px 6px rgba(30,42,51,.04);
  --shadow: 0 4px 14px rgba(30,42,51,.06), 0 1px 3px rgba(30,42,51,.05);
  --shadow-lg: 0 12px 40px rgba(30,42,51,.12), 0 2px 8px rgba(30,42,51,.06);

  /* Layout */
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --maxw: 460px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---- Layout shell ---- */
.screen-host {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(var(--nav-h) + 18px + var(--safe-b));
  position: relative;
}
.screen { padding: 16px 16px 8px; animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 2px 14px;
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.topbar .actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-pill);
  display: grid; place-items: center; background: var(--surface);
  box-shadow: var(--shadow-sm); color: var(--text-2);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card-tight { padding: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.card-link { font-size: 12.5px; color: var(--c-blue); font-weight: 600; }

/* ---- Hero net worth ---- */
.hero {
  background: linear-gradient(160deg, #FFFFFF 0%, #F3F7FC 100%);
  border-radius: var(--r-xl);
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  position: relative; overflow: hidden;
}
.hero .label { font-size: 12px; color: var(--text-3); letter-spacing: .04em; text-transform: uppercase; }
.hero .net {
  font-family: var(--num); font-size: 38px; font-weight: 700; letter-spacing: -.02em;
  margin: 6px 0 2px; color: var(--c-blue);
}
.hero .net .cur { font-size: 22px; opacity: .8; margin-right: 2px; }
.hero .rate { font-size: 12px; color: var(--text-3); margin-top: 8px; }
.split-row { display: flex; gap: 10px; margin-top: 14px; }
.split-chip {
  flex: 1; background: var(--surface); border-radius: var(--r); padding: 11px 12px;
  box-shadow: var(--shadow-sm);
}
.split-chip .k { font-size: 11px; color: var(--text-3); }
.split-chip .v { font-family: var(--num); font-size: 17px; font-weight: 700; margin-top: 2px; }
.split-chip.usd .v { color: var(--c-blue); }
.split-chip.cny .v { color: var(--c-home); }

/* ---- Cashflow cards ---- */
.cf-grid { display: flex; gap: 10px; }
.cf-col { flex: 1; }
.cf-col .hd { font-size: 12px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; display:flex; align-items:center; gap:6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display:inline-block; }
.cf-line { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-size: 13.5px; color: var(--text-2); }
.cf-line .amt { font-family: var(--num); font-weight: 600; color: var(--text); }
.cf-line.income .amt { color: var(--c-income); }
.cf-line.expense .amt { color: var(--c-life); }
.cf-net { display:flex; justify-content:space-between; align-items:baseline; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.cf-net .amt { font-family: var(--num); font-weight: 700; }
.cf-net.pos .amt { color: var(--c-income); }
.cf-net.neg .amt { color: var(--c-life); }

/* ---- Donut + legend ---- */
.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { flex: none; width: 132px; height: 132px; position: relative; }
.donut svg { transform: rotate(-90deg); }
.donut .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .center .big { font-family: var(--num); font-size: 17px; font-weight: 700; }
.donut .center .sm { font-size: 10.5px; color: var(--text-3); }
.legend { flex: 1; }
.legend-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.legend-row .left { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.legend-row .sw { width: 9px; height: 9px; border-radius: 3px; }
.legend-row .val { font-family: var(--num); font-weight: 600; color: var(--text); }
.legend-row.clickable { cursor: pointer; }
.legend-row.clickable:active { opacity: .6; }

/* ---- Highlight list ---- */
.hl { display: flex; flex-direction: column; gap: 2px; }
.hl-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.hl-row:last-child { border-bottom: none; }
.hl-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.hl-ico svg { width: 17px; height: 17px; }
.hl-body { flex: 1; min-width: 0; }
.hl-body .t { font-size: 13.5px; font-weight: 600; }
.hl-body .s { font-size: 11.5px; color: var(--text-3); }
.hl-val { font-family: var(--num); font-weight: 700; font-size: 14px; }

/* ---- Quick actions ---- */
.qa-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qa {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 12px 4px; background: var(--surface-2); border-radius: var(--r);
  border: 1px solid var(--border);
}
.qa:active { transform: scale(.95); background: var(--surface-sunken); }
.qa .qa-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; }
.qa .qa-ico svg { width: 18px; height: 18px; }
.qa span { font-size: 11px; color: var(--text-2); }

/* ---- Todo reminders ---- */
.todo { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.todo:last-child { border-bottom: none; }
.todo .pill { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: var(--r-pill); flex: none; }
.todo .t { font-size: 13px; flex: 1; }
.todo .t .s { display:block; font-size: 11px; color: var(--text-3); }

/* ---- Section header ---- */
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 2px 10px; }
.sec-head h2 { font-size: 16px; font-weight: 700; margin: 0; }

/* ---- Bottom nav ---- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: var(--maxw); height: calc(var(--nav-h) + var(--safe-b));
  background: rgba(255,255,255,.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-start; padding: 8px 6px 0; z-index: 50;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-3); font-size: 10.5px; padding-top: 4px; position: relative;
}
.nav-item .nav-icon { width: 23px; height: 23px; }
.nav-item.active { color: var(--c-blue); }
.nav-item.active .nav-icon { stroke: var(--c-blue); }
.nav-center { padding-top: 0; }
.nav-plus {
  width: 50px; height: 50px; border-radius: 50%;
  background: linear-gradient(145deg, var(--c-blue), #3A72A4);
  color: #fff; display: grid; place-items: center; margin-top: -22px;
  box-shadow: 0 6px 16px rgba(46,92,138,.34);
}
.nav-plus svg { width: 26px; height: 26px; }
.nav-center span { position: relative; top: 3px; }
.nav-item:active .nav-plus { transform: scale(.92); }

/* ---- Sheets / modals ---- */
.sheet-layer { position: fixed; inset: 0; z-index: 80; display: none; }
.sheet-layer.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,28,36,.42); animation: bd .2s ease; }
@keyframes bd { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 0;
  width: 100%; max-width: var(--maxw); max-height: 92vh;
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  animation: up .3s cubic-bezier(.22,.9,.32,1);
}
.sheet.full { max-height: 94vh; }
@keyframes up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.sheet-handle { width: 38px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 10px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 18px 6px; flex: none; }
.sheet-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.sheet-head .close { font-size: 13px; color: var(--text-3); padding: 6px; }
.sheet-body { padding: 4px 18px calc(20px + var(--safe-b)); overflow-y: auto; flex: 1; }

/* ---- Segmented control ---- */
.seg { display: flex; background: var(--surface-sunken); border-radius: var(--r-pill); padding: 3px; }
.seg button { flex: 1; padding: 8px 0; border-radius: var(--r-pill); font-size: 13px; font-weight: 600; color: var(--text-3); transition: .18s; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg.three button.active.exp { color: var(--c-life); }
.seg.three button.active.inc { color: var(--c-income); }

/* ---- Amount keypad input ---- */
.amt-display { text-align: center; padding: 14px 0 6px; }
.amt-display .cur { font-size: 24px; color: var(--text-3); font-weight: 700; vertical-align: 6px; }
.amt-display .amt { font-family: var(--num); font-size: 52px; font-weight: 700; letter-spacing: -.02em; }
.amt-display.income .cur, .amt-display.income .amt { color: var(--c-income); }
.amt-display.expense .cur, .amt-display.expense .amt { color: var(--text); }

/* category mini seg for record type */
.rec-type-row { display:flex; gap: 8px; align-items: center; }
.rec-type-row .seg { flex: 1; }
.rec-type-row .more-type { font-size: 12px; color: var(--text-3); padding: 8px 10px; border: 1px dashed var(--border-strong); border-radius: var(--r-pill); }

/* ---- Category grid ---- */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 4px; margin-top: 14px; }
.cat-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 2px; border-radius: var(--r); }
.cat-cell:active { background: var(--surface-sunken); }
.cat-cell.active .cat-ico { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px currentColor; }
.cat-ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-sunken); }
.cat-ico svg { width: 22px; height: 22px; }
.cat-cell .nm { font-size: 11px; color: var(--text-2); text-align: center; line-height: 1.2; max-width: 56px; }
.cat-more { grid-column: 1 / -1; text-align: center; font-size: 12.5px; color: var(--c-blue); padding: 6px; }

/* ---- Keypad ---- */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.keypad button { font-family: var(--num); font-size: 23px; font-weight: 600; padding: 13px 0; border-radius: var(--r); background: var(--surface-2); color: var(--text); }
.keypad button:active { background: var(--surface-sunken); transform: scale(.97); }
.keypad .kp-dot { font-weight: 700; }
.keypad .kp-del svg { width: 24px; height: 24px; }

/* ---- Account picker ---- */
.field { margin-top: 14px; }
.field-label { font-size: 12px; color: var(--text-3); margin-bottom: 7px; font-weight: 600; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.acct-pill { display: flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.acct-pill.active { border-color: var(--c-blue); background: var(--c-blue-bg); color: var(--c-blue); font-weight: 600; }
.acct-pill .bal { font-family: var(--num); font-size: 11.5px; color: var(--text-3); }
.acct-pill.active .bal { color: var(--c-blue); opacity: .8; }

/* ---- Inputs ---- */
.input, .textarea, .select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 13px; font-size: 14px; transition: .16s;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--c-blue); background: var(--surface); }
.textarea { resize: none; min-height: 60px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.input-num { font-family: var(--num); }
label.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.switch { position: relative; width: 40px; height: 23px; border-radius: 999px; background: var(--border-strong); transition: .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s; }
.switch.on { background: var(--c-income); }
.switch.on::after { left: 19px; }

/* ---- Buttons ---- */
.btn { width: 100%; padding: 14px; border-radius: var(--r); font-size: 15px; font-weight: 700; background: var(--c-blue); color: #fff; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.btn.danger { background: var(--c-red); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn.sm { padding: 9px; font-size: 13px; width: auto; }

/* ---- Transaction list ---- */
.tx-list { }
.tx-group-head { font-size: 12px; color: var(--text-3); font-weight: 600; padding: 14px 4px 8px; display: flex; justify-content: space-between; }
.tx-item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.tx-item:active { background: var(--surface-sunken); }
.tx-ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.tx-ico svg { width: 19px; height: 19px; }
.tx-body { flex: 1; min-width: 0; }
.tx-body .t { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-body .s { font-size: 11.5px; color: var(--text-3); }
.tx-tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.tx-amt { font-family: var(--num); font-weight: 700; font-size: 15px; text-align: right; }
.tx-amt .cur { font-size: 11px; opacity: .7; }
.tx-amt.inc { color: var(--c-income); }
.tx-amt.exp { color: var(--text); }
.tx-amt.pending { color: var(--text-3); }

/* ---- Filter bar ---- */
.filter-bar { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 7px 13px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }
.chip.active { background: var(--c-blue); color: #fff; border-color: var(--c-blue); }
.search-wrap { position: relative; margin-bottom: 10px; }
.search-wrap input { padding-left: 38px; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); }

/* ---- Empty state ---- */
.empty { text-align: center; padding: 40px 28px 30px; }
.empty .emoji { font-size: 40px; margin-bottom: 10px; opacity: .7; }
.empty p { color: var(--text-3); font-size: 13.5px; line-height: 1.6; margin: 0; }
.empty .big { font-size: 16px; color: var(--text-2); font-weight: 600; margin-bottom: 4px; }

/* ---- List item (accounts/projects/people etc) ---- */
.li { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.li:active { background: var(--surface-sunken); }
.li-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.li-ico svg { width: 20px; height: 20px; }
.li-body { flex: 1; min-width: 0; }
.li-body .t { font-size: 14.5px; font-weight: 600; }
.li-body .s { font-size: 12px; color: var(--text-3); }
.li-val { font-family: var(--num); font-weight: 700; font-size: 15px; text-align: right; }
.li-val .cur { font-size: 11px; opacity: .7; }
.li-chev { color: var(--text-faint); }
.li-chev svg { width: 18px; height: 18px; }

/* ---- Stat blocks ---- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow-sm); }
.stat .k { font-size: 11.5px; color: var(--text-3); }
.stat .v { font-family: var(--num); font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .v.inc { color: var(--c-income); }
.stat .v.exp { color: var(--c-life); }
.stat .v.net { color: var(--c-blue); }
.stat .sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ---- Progress bar (goals) ---- */
.prog { height: 8px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.prog .fill { height: 100%; border-radius: 999px; background: var(--c-blue); transition: width .4s; }

/* ---- Toast ---- */
.toast-layer { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(30,42,51,.92); color: #fff; padding: 10px 18px; border-radius: var(--r-pill); font-size: 13px; box-shadow: var(--shadow-lg); animation: tin .25s ease; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Inbox badge ---- */
.inbox-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--c-love); background: var(--c-love-bg); padding: 4px 9px; border-radius: var(--r-pill); font-weight: 600; }

/* ---- Utilities ---- */
.row { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.hr-soft { border: none; border-top: 1px dashed var(--border); margin: 12px 0; }
.num { font-family: var(--num); font-weight: 600; }
.tag-soft { font-size: 11px; color: var(--text-3); background: var(--surface-sunken); padding: 2px 8px; border-radius: 6px; }
.center { text-align: center; }
.pill-soft { font-size: 11px; padding: 3px 9px; border-radius: var(--r-pill); font-weight: 600; }
.pill-soft.green { color: var(--c-income); background: var(--c-income-bg); }
.pill-soft.orange { color: var(--c-life); background: var(--c-life-bg); }
.pill-soft.red { color: var(--c-red); background: var(--c-red-bg); }
.pill-soft.gray { color: var(--text-3); background: var(--surface-sunken); }

/* Scrollable horizontal lists */
.hscroll { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll .card { min-width: 200px; margin-bottom: 0; }

/* Bar chart */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.bar { width: 100%; max-width: 22px; border-radius: 6px 6px 3px 3px; background: var(--c-blue); min-height: 3px; }
.bar.exp { background: var(--c-life); }
.bar-col .lbl { font-size: 9px; color: var(--text-3); }
