/* Tài chính gia đình: giao diện 2D, nhẹ, ưu tiên iPhone (320–430px). Không ảnh nặng, không hiệu ứng nặng. */
:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #14211f;
  --muted: #5a6b68;
  --line: #d5dfdc;
  --brand: #0b6b5d;
  --brand-ink: #ffffff;
  --in: #0a7a3d;
  --out: #b3261e;
  --move: #35508a;
  --warn-bg: #fff4d6;
  --warn-ink: #5c4300;
  --bad-bg: #fde8e6;
  --tk: #0b6b5d;
  --dp: #c98a00;
  --cc: #2d7fc0;
  --ps: #c2456b;
  --toast-bg: #14211f;
  --toast-ink: #ffffff;
  --on-out: #ffffff;
  --radius: 16px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1716;
    --surface: #18221f;
    --surface-2: #202d2a;
    --text: #e8f1ee;
    --muted: #9db1ac;
    --line: #2f403c;
    --brand: #31b79f;
    --brand-ink: #04201b;
    --in: #4ed08a;
    --out: #ff8a80;
    --move: #9db8f5;
    --warn-bg: #3a3012;
    --warn-ink: #ffe7a1;
    --bad-bg: #3a1c1a;
    --tk: #31b79f;
    --dp: #f0b429;
    --cc: #63aee8;
    --ps: #ee7fa1;
    --toast-bg: #e8f1ee;
    --toast-ink: #0f1716;
    --on-out: #2a0a08;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1716;
  --surface: #18221f;
  --surface-2: #202d2a;
  --text: #e8f1ee;
  --muted: #9db1ac;
  --line: #2f403c;
  --brand: #31b79f;
  --brand-ink: #04201b;
  --in: #4ed08a;
  --out: #ff8a80;
  --move: #9db8f5;
  --warn-bg: #3a3012;
  --warn-ink: #ffe7a1;
  --bad-bg: #3a1c1a;
  --tk: #31b79f;
  --dp: #f0b429;
  --cc: #63aee8;
  --ps: #ee7fa1;
  --toast-bg: #e8f1ee;
  --toast-ink: #0f1716;
  --on-out: #2a0a08;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
.app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); }
.boot { padding: 40px 16px; text-align: center; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Thanh trên ---- */
.demo-banner { background: #7a4a00; color: #fff; text-align: center; font-size: 12px; font-weight: 600; padding: calc(4px + var(--safe-t)) 8px 4px; letter-spacing: .2px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; }
.brand-name { font-weight: 800; letter-spacing: .4px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-weight: 600; min-height: 36px; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 16px 8px; font-size: 13px; color: var(--muted); }
.status.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 16px; margin-bottom: 4px; }
.status.stale { background: var(--surface-2); padding: 8px 16px; }
.status.danger { background: var(--bad-bg); color: var(--out); padding: 8px 16px; margin-bottom: 4px; font-weight: 600; }
.status .link-btn { margin-left: auto; }

.main { padding: 0 16px; }
.screen { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.screen-title { font-size: 22px; font-weight: 800; }

/* ---- Thẻ tổng ---- */
.total-card { background: var(--brand); color: var(--brand-ink); border-radius: 20px; padding: 18px 18px 16px; }
.total-label { font-size: 14px; opacity: .9; }
.total-value { font-size: 38px; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; margin: 2px 0 6px; word-break: break-all; }
.total-split { display: flex; gap: 2px 18px; flex-wrap: wrap; font-size: 14px; }
.total-split .sep { display: none; }
.total-note { font-size: 12px; opacity: .8; margin-top: 8px; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 14px; min-height: 48px; font-weight: 700; text-align: center; user-select: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.secondary { background: var(--surface); }
.btn.danger { background: var(--out); color: var(--on-out); border-color: var(--out); }
.btn.warn { background: var(--warn-ink); color: var(--warn-bg); border-color: var(--warn-ink); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { min-height: 56px; font-size: 17px; }
.btn.big small { display: block; font-weight: 500; opacity: .85; font-size: 12px; }
.actions .btn.big { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 76px; padding: 10px 4px; font-size: 14px; }
.actions .ico { font-size: 26px; line-height: 1; font-weight: 800; }
.actions .in { border-color: var(--in); color: var(--in); }
.actions .out { border-color: var(--out); color: var(--out); }
.actions .mv { border-color: var(--move); color: var(--move); }
.big-save { min-height: 56px; font-size: 18px; margin-top: 6px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 700; padding: 8px 4px; min-height: 40px; }

/* ---- Thẻ quỹ ---- */
.fund-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fund-card { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--fc); border-radius: var(--radius); padding: 12px; min-width: 0; }
.fund-name { font-size: 13px; font-weight: 700; color: var(--fc); text-transform: uppercase; letter-spacing: .4px; }
.fund-total { font-size: 20px; font-weight: 800; margin: 2px 0 4px; word-break: break-all; }
.fund-split { display: flex; flex-direction: column; font-size: 12.5px; color: var(--muted); }
.fund-tk { --fc: var(--tk); } .fund-dp { --fc: var(--dp); } .fund-cc { --fc: var(--cc); } .fund-ps { --fc: var(--ps); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card h3 { font-size: 16px; }
.onboarding { border-color: var(--brand); }
.empty { color: var(--muted); text-align: center; padding: 14px 0; }

/* ---- Danh sách giao dịch ---- */
.tx-list { display: flex; flex-direction: column; }
.tx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: none; border: 0; border-top: 1px solid var(--line); padding: 12px 0; text-align: left; width: 100%; min-height: 56px; }
.tx-list .tx-row:first-child { border-top: 0; }
.tx-main { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.tx-title { font-weight: 700; overflow-wrap: anywhere; }
.tx-sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.tx-amt { font-weight: 800; white-space: nowrap; }
.tx-row.voided .tx-title, .tx-row.voided .tx-amt { text-decoration: line-through; opacity: .6; }
.amt-in { color: var(--in); } .amt-out { color: var(--out); } .amt-transfer { color: var(--move); }
.badge { font-style: normal; font-size: 11px; font-weight: 700; background: var(--bad-bg); color: var(--out); border-radius: 999px; padding: 1px 8px; margin-left: 6px; text-decoration: none; display: inline-block; }
.badge.muted { background: var(--surface-2); color: var(--muted); }

/* ---- Biểu mẫu ---- */
.page-head { display: flex; align-items: center; gap: 8px; }
.page-head h1 { font-size: 20px; font-weight: 800; }
.back { padding-left: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.input { width: 100%; min-height: 50px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 17px; /* >=16px để iOS không tự phóng to */ }
.input:focus { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
.input.money { font-size: 22px; font-weight: 700; text-align: right; }
.input.compact { min-height: 44px; font-size: 16px; padding: 6px 8px; }
.input.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.hint, .hint-line { font-size: 13px; color: var(--muted); }
.hint-line:empty { display: none; }
.who { font-size: 13px; color: var(--muted); }
.notice { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.section-title { font-size: 15px; font-weight: 800; margin-top: 6px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.balance-line { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 14px; }
.balance-line.bad { background: var(--bad-bg); color: var(--out); }
.receive-total { font-weight: 800; font-size: 17px; }
.more { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.more summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.more[open] { padding-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.more[open] summary { margin-bottom: 2px; }
.edit-banner { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.error-box { background: var(--bad-bg); color: var(--out); border: 1px solid var(--out); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; font-weight: 600; }
.error-box[hidden] { display: none; }
.error-text { color: var(--out); font-size: 14px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg-btn { border: 0; background: transparent; min-height: 44px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }

.fund-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fund-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 2px solid var(--line); border-left: 6px solid var(--fc); background: var(--surface); border-radius: 14px; padding: 10px 12px; min-height: 62px; text-align: left; }
.fund-opt.on { border-color: var(--fc); background: color-mix(in srgb, var(--fc) 10%, var(--surface)); }
.fund-opt-name { font-weight: 800; }
.fund-opt-bal { font-size: 13px; color: var(--muted); }

.matrix { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.matrix-head, .matrix-row { display: grid; grid-template-columns: 76px 1fr 1fr 78px; gap: 6px; align-items: center; }
.matrix-head { font-size: 12px; font-weight: 800; color: var(--muted); text-align: center; }
.matrix-fund { font-weight: 800; font-size: 13px; color: var(--fc); }
.row-total { font-size: 12px; text-align: right; color: var(--muted); overflow-wrap: anywhere; }
.matrix .input.money { font-size: 15px; padding: 6px; }
.sum-line { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.ok { color: var(--in); font-weight: 700; } .bad { color: var(--out); font-weight: 700; }

.open-grid { display: flex; flex-direction: column; gap: 10px; }
.open-row { background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--fc); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.open-fund { font-weight: 800; color: var(--fc); }
.open-row { display: grid; grid-template-columns: 1fr 1fr; }
.open-row .open-fund { grid-column: 1 / -1; }
.open-cell { display: flex; flex-direction: column; gap: 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; min-height: 44px; }
.check input { width: 24px; height: 24px; flex: none; margin-top: 1px; }

/* ---- Lịch sử / báo cáo ---- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .input { min-height: 44px; font-size: 15px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv .k { color: var(--muted); } .kv .v { font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.entry-head { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; margin-top: 8px; }
.entry-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.entry-ba { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.entry-cell { font-weight: 700; }
.chart { width: 100%; height: auto; }
.chart-line { stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.chart-dot { fill: var(--brand); }
.chart-axis { stroke: var(--line); stroke-width: 1; }
.chart-text { fill: var(--muted); font-size: 10px; }
.month summary { display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-height: 44px; justify-content: center; }
.month-name { font-weight: 800; }
.month-nums { display: flex; gap: 12px; font-size: 14px; font-weight: 700; flex-wrap: wrap; }
.year-row { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.year-row strong { min-width: 48px; }

/* ---- Đăng nhập / cài đặt ---- */
.login { align-items: stretch; text-align: center; padding-top: 24px; }
.login-logo { width: 72px; height: 72px; border-radius: 20px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 40px; font-weight: 800; margin: 0 auto; }
.login-logo.bad { background: var(--out); color: var(--on-out); }
.login-title { font-size: 22px; font-weight: 800; }
.login-sub { color: var(--muted); }
.login .notice { text-align: left; }
.login-form { text-align: left; margin: 6px 0; }
.login-form .input { font-size: 16px; }
.log { background: var(--surface-2); border-radius: 10px; padding: 10px; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-family: ui-monospace, Menlo, monospace; }
.demo-card { border-style: dashed; border-color: #b9770e; }
.sub-title { font-size: 14px; margin-top: 6px; }
.about { font-size: 12px; color: var(--muted); text-align: center; padding: 8px 0 16px; }
.lock-badge { font-size: 20px; }
.private-notes-head { margin-bottom: 4px; }
.notes-panel h2 { font-size: 17px; font-weight: 800; }
.notes-form { display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.notes-textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.private-note-list { display: flex; flex-direction: column; gap: 10px; }
.private-note-card { border: 1px solid var(--line); border-left: 5px solid var(--brand); background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.private-note-meta { color: var(--muted); font-size: 12px; font-weight: 700; }
.private-note-card h3 { font-size: 16px; overflow-wrap: anywhere; }
.private-note-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.danger-link { color: var(--out); align-self: flex-start; }

/* ---- Thanh tab dưới ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 480px; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 20; }
.tab { border: 0; background: none; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 700; color: var(--muted); }
.tab.on { color: var(--brand); }
.tab-ico { font-size: 22px; line-height: 1; }

/* ---- Tờ xác nhận và thông báo ---- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto; }
.sheet-title { font-size: 18px; font-weight: 800; }
.sheet-body { display: flex; flex-direction: column; gap: 6px; }
.sheet-line { font-size: 15px; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1 1 120px; }
.toast { border: 1px solid rgba(255,255,255,.18); position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); max-width: 448px; margin: 0 auto; background: var(--toast-bg); color: var(--toast-ink); border-radius: 14px; padding: 12px 14px; font-weight: 600; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.error { background: var(--out); color: var(--on-out); }
