/* Money · Duan Digi — mobile-first, tự động theo sáng/tối của hệ thống */
:root {
  --bg: #0b1020; --surface: #151b2e; --surface-2: #1d2439; --line: #2a3350;
  --text: #eef1f8; --muted: #9aa4c2; --dim: #6b7699;
  --brand: #6366f1; --brand-soft: #6366f126;
  --in: #34d399; --out: #fb7185; --warn: #fbbf24;
  --radius: 16px; --pad: 16px;
  --safe: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme='light'] {
  --bg: #f5f6fb; --surface: #ffffff; --surface-2: #f0f2f9; --line: #e3e6f0;
  --text: #10152a; --muted: #5d6785; --dim: #8b94ad;
  --in: #059669; --out: #e11d48; --brand-soft: #6366f119;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f5f6fb; --surface: #ffffff; --surface-2: #f0f2f9; --line: #e3e6f0;
    --text: #10152a; --muted: #5d6785; --dim: #8b94ad;
    --in: #059669; --out: #e11d48; --brand-soft: #6366f119;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  padding-bottom: calc(80px + var(--safe));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.hide { display: none !important; }

/* ---- Layout ---- */
.wrap { max-width: 720px; margin: 0 auto; padding: 0 var(--pad); }
.topbar {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
}
.topbar-in { display: flex; align-items: center; gap: 10px; height: 56px; }
.topbar h1 { font-size: 17px; flex: 1; }
.month-nav { display: flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 999px; padding: 3px; }
.month-nav button { padding: 5px 9px; border-radius: 999px; color: var(--muted); font-size: 15px; line-height: 1; }
.month-nav button:active { background: var(--surface-2); }
.month-nav .label { font-size: 13px; font-weight: 600; padding: 0 4px; min-width: 62px; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-title { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin: 22px 2px 10px; }
.muted { color: var(--muted); } .dim { color: var(--dim); }
.small { font-size: 13px; } .tiny { font-size: 11.5px; }
.in { color: var(--in); } .out { color: var(--out); }
.num { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--dim); padding: 28px 12px; font-size: 14px; }

/* ---- Tổng quan ---- */
.hero { background: linear-gradient(150deg, #4f46e5, #7c3aed 55%, #a855f7); color: #fff;
  border-radius: 20px; padding: 18px; border: none; }
.hero .label { font-size: 12.5px; opacity: 0.82; }
.hero .value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.hero .split { display: flex; gap: 18px; margin-top: 14px; }
.hero .split div { flex: 1; }
.hero .split .v { font-size: 16px; font-weight: 650; }
.hero .split .k { font-size: 11.5px; opacity: 0.82; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 18px; font-weight: 650; margin-top: 3px; letter-spacing: -0.01em; }

/* ---- Danh sách ---- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.item + .item { border-top: 1px solid var(--line); }
.item:active { background: var(--surface-2); }
.ico { width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  font-size: 18px; background: var(--surface-2); }
.item .body { flex: 1; min-width: 0; }
/* display:block là bắt buộc — overflow/text-overflow không có tác dụng trên thẻ inline,
   thiếu nó thì tên dài sẽ tràn ra và đè lên số tiền bên phải. */
.item .t { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { display: block; font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* flex:none — không cho co lại, nếu không chữ số nowrap sẽ tràn đè lên tên/nhãn bên trái */
.item .amt { font-weight: 650; white-space: nowrap; flex: none; }
.day-head { display: flex; justify-content: space-between; padding: 9px 14px; background: var(--surface-2);
  font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---- Thanh tiến độ ---- */
.bar { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--brand); transition: width 0.4s; }
.bar.ok > i { background: var(--in); } .bar.warn > i { background: var(--warn); } .bar.over > i { background: var(--out); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

/* ---- Điều hướng dưới ---- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe); }
.tabbar-in { display: flex; max-width: 720px; margin: 0 auto; }
.tab { flex: 1; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--dim); font-size: 10.5px; font-weight: 550; }
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--brand); }
.fab { position: fixed; right: 18px; bottom: calc(74px + var(--safe)); z-index: 31; width: 56px; height: 56px;
  border-radius: 50%; background: var(--brand); color: #fff; font-size: 28px; display: grid; place-items: center;
  box-shadow: 0 8px 24px #6366f166; }
.fab:active { transform: scale(0.94); }

/* ---- Sheet / modal ---- */
.overlay { position: fixed; inset: 0; z-index: 50; background: #0007; backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 18px var(--pad) calc(24px + var(--safe));
  animation: up 0.22s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes up { from { transform: translateY(24px); opacity: 0.4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font-size: 17px; }
.x { font-size: 22px; color: var(--muted); padding: 0 4px; }

label.f { display: block; margin-top: 13px; }
label.f > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 13px; outline: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
input[type='date'] { min-height: 45px; }
.amount-input { font-size: 26px; font-weight: 700; text-align: right; letter-spacing: -0.02em; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px; border-radius: 10px; font-size: 14px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px #0003; }
.seg button.on[data-v='income'] { color: var(--in); } .seg button.on[data-v='expense'] { color: var(--out); }

.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; background: var(--brand); color: #fff;
  font-weight: 650; margin-top: 18px; }
.btn:active { opacity: 0.85; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--out); border: 1px solid var(--line); }
.btn.sm { padding: 9px 14px; width: auto; margin: 0; font-size: 13.5px; border-radius: 11px; }
.btn:disabled { opacity: 0.5; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe)); transform: translateX(-50%); z-index: 90;
  background: #111827ee; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 13.5px;
  max-width: 88vw; text-align: center; animation: up 0.2s; }
:root[data-theme='light'] .toast { background: #111827f2; }
.toast.err { background: #e11d48f2; }

/* ---- Trang đăng nhập ---- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-logo { width: 62px; height: 62px; border-radius: 20px; display: grid; place-items: center; font-size: 30px;
  background: linear-gradient(150deg, #4f46e5, #a855f7); margin: 0 auto 16px; }
.auth h1 { text-align: center; font-size: 21px; }
.auth p.sub { text-align: center; color: var(--muted); font-size: 13.5px; margin: 7px 0 20px; }
.err { color: var(--out); font-size: 13px; margin-top: 10px; text-align: center; min-height: 18px; }

svg.chart { width: 100%; display: block; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; }
.legend > div { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* ---- Bộ chọn danh mục 2 cấp ---- */
.pick-group + .pick-group { margin-top: 12px; }
.pick-label { font-size: 11.5px; font-weight: 650; color: var(--dim); text-transform: uppercase;
  letter-spacing: 0.03em; margin-bottom: 6px; }
.pick-wrap { max-height: 42vh; overflow-y: auto; margin-top: 6px;
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface-2); }
.pick-wrap .chip { background: var(--surface); }
.pick-wrap .chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---- Nhãn dự án & cảnh báo hạn nợ ---- */
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-size: 10.5px; font-weight: 600; }
.badge.warn { background: #fbbf2422; color: var(--warn); }
.badge.over { background: #fb718522; color: var(--out); }
.tree-child { padding-left: 30px; }
.tree-child .t { font-weight: 450; }
