:root {
  --bg: #f1f4f9;
  --card: #fff;
  --text: #172433;
  --muted: #6b7889;
  --line: #e8edf3;
  --blue: #1a73e8;
  --indigo: #4f46e5;
  --in: #0f9d58;
  --ex: #e5484d;
  --navy: #0f2742;
  --navy-2: #1a3a5c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 33, 54, .06), 0 4px 14px rgba(16, 33, 54, .05);
  --grad: linear-gradient(135deg, #1a73e8, #4f46e5);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.blue, .in { color: var(--in); }
.red, .ex { color: var(--ex); }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ---------- thanh tiêu đề ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  box-shadow: 0 2px 12px rgba(4, 16, 32, .25);
}
.topbar .balance { flex: 1; text-decoration: none; display: flex; flex-direction: column; line-height: 1.15; padding: 2px 6px; }
.balance-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .65; }
.balance-value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 0; background: none; color: #fff;
  display: grid; place-items: center; cursor: pointer; text-decoration: none;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn:focus-visible { outline: 2px solid #8ab4ff; outline-offset: 1px; }

/* ---------- menu ---------- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 270px; z-index: 40;
  display: flex; flex-direction: column; gap: 2px;
  padding: calc(18px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, var(--navy), #12304f);
  color: #dbe6f3; box-shadow: 4px 0 24px rgba(0, 0, 0, .3);
  animation: slide-in .2s ease-out;
}
@keyframes slide-in { from { transform: translateX(-100%); } to { transform: none; } }
.side-head { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; margin-bottom: 8px; border-bottom: 1px solid rgba(255, 255, 255, .1); }
.side-head img { border-radius: 12px; }
.side-app { font-weight: 700; color: #fff; font-size: 17px; }
.side-user { font-size: 13px; opacity: .7; }
.sidebar a, .sidebar button {
  display: flex; align-items: center; gap: 14px; padding: 11px 12px; border-radius: 12px;
  color: inherit; text-decoration: none; background: none; border: 0; cursor: pointer; width: 100%; text-align: left;
}
.sidebar svg { width: 20px; height: 20px; opacity: .85; flex: none; }
.sidebar a:hover, .sidebar button:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.sidebar a.active { background: rgba(138, 180, 255, .18); color: #fff; font-weight: 600; }
.side-spacer { flex: 1; }
.overlay { position: fixed; inset: 0; background: rgba(6, 15, 28, .45); z-index: 30; backdrop-filter: blur(2px); }

main { max-width: 760px; margin: 0 auto; padding: 14px 12px 96px; }

.page-head { padding: 4px 4px 10px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- chọn tháng ---------- */
.month-nav {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
  background: var(--card); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow);
}
.month-nav .arrow {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  text-decoration: none; font-size: 24px; line-height: 1; color: var(--muted);
}
.month-nav .arrow:hover { background: #eef2f8; color: var(--text); }
.month-nav .current { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.month-nav .current strong { font-size: 16px; }
.pill { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pill.link { color: var(--blue); text-decoration: none; font-weight: 600; }

/* ---------- thẻ tổng quan ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 20px; padding: 18px 18px 14px; margin-bottom: 12px; color: #fff;
  background:
    radial-gradient(420px circle at 100% 0%, rgba(99, 102, 241, .55), transparent 60%),
    linear-gradient(135deg, var(--navy), var(--navy-2));
  box-shadow: 0 10px 28px rgba(15, 39, 66, .28);
}
.hero-top { display: flex; justify-content: space-between; align-items: center; }
.hero-top h2 { margin: 0; font-size: 14px; font-weight: 600; opacity: .8; }
.hero-top a { font-size: 13px; color: #b9d3ff; text-decoration: none; font-weight: 600; }
.hero-net { margin: 8px 0 14px; display: flex; flex-direction: column; }
.hero-net span { font-size: 12px; opacity: .65; }
.hero-net strong { font-size: 30px; letter-spacing: -.02em; line-height: 1.15; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-stats > div { background: rgba(255, 255, 255, .08); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; }
.hero-stats span { font-size: 12px; opacity: .7; }
.hero-stats strong { font-size: 16px; }
.hero .in { color: #7ee2a8; }
.hero .ex { color: #ffa4a6; }
.hero-wallets { margin-top: 12px; border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 6px; }
.wallet-line {
  display: grid; grid-template-columns: 1fr auto auto 14px; gap: 10px; align-items: center;
  padding: 8px 6px; border-radius: 10px; text-decoration: none; font-size: 14px;
}
.wallet-line:hover { background: rgba(255, 255, 255, .08); }
.wallet-line .wname { font-weight: 600; }
.wallet-line .wflow { display: flex; flex-direction: column; align-items: flex-end; font-size: 11.5px; line-height: 1.3; opacity: .9; }
.wallet-line .wnet { font-weight: 700; min-width: 92px; text-align: right; }
.wallet-line .chev { opacity: .5; }

/* ---------- thẻ ---------- */
.card { background: var(--card); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.card-head h2, .card-head h3 { margin: 0; font-size: 15.5px; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head > .num { font-weight: 700; }
.amount-tag { font-weight: 700; font-size: 14px; padding: 4px 10px; border-radius: 999px; background: #eefaf3; }
.amount-tag.ex { background: #fdeeee; }

.day .card-head { padding-bottom: 10px; }
.day-badge {
  width: 46px; height: 50px; border-radius: 12px; background: #eef3fb; color: var(--navy-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; flex: none;
}
.day-badge strong { font-size: 20px; }
.day-badge span { font-size: 10.5px; text-transform: uppercase; opacity: .7; }
.day-badge.today { background: var(--grad); color: #fff; box-shadow: 0 6px 14px rgba(26, 115, 232, .3); }

/* ---------- danh sách ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li .item { border-top: 1px solid var(--line); }
.card-head + .list { border-top: 1px solid var(--line); }
.list .item {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 11px 16px;
  background: none; border: 0; border-radius: 0; text-align: left; cursor: pointer;
}
.list button.item:hover { background: #f6f8fc; }
.list button.item:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.list .item.static { cursor: default; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .title { font-weight: 600; font-size: 14.5px; }
.list .item .meta { color: var(--muted); font-size: 12px; }
.list .item .note { color: #4f5d6d; font-size: 13px; overflow-wrap: anywhere; white-space: pre-wrap; margin-top: 1px; }
.list .item > .num { font-weight: 700; font-size: 14.5px; align-self: flex-start; padding-top: 2px; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}

/* ---------- thêm nhanh ---------- */
.quick { padding: 12px 14px 14px; display: grid; gap: 8px; }
.quick-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.quick-title span { font-weight: 700; font-size: 14px; }
.quick-title small { color: var(--muted); font-size: 12px; }
.quick-row { display: flex; gap: 8px; }
.quick-row textarea { flex: 1; min-height: 46px; resize: vertical; }
.quick > input[type=date] { justify-self: start; width: auto; height: 36px; padding: 0 10px; font-size: 13.5px; color: var(--muted); }

/* ---------- form ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid #dbe2ea; border-radius: 12px; background: #f8fafc;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input, select { height: 46px; }
input:focus, select:focus, textarea:focus {
  outline: none; background: #fff; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(26, 115, 232, .14);
}
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: #3c4a5a; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn, button.primary {
  height: 46px; padding: 0 18px; border-radius: 12px; border: 1.5px solid #dbe2ea; background: #fff;
  font-weight: 600; cursor: pointer; transition: filter .15s, box-shadow .15s, transform .1s;
}
.btn:hover { background: #f4f7fb; }
.btn.primary, button.primary {
  border: 0; color: #fff; background: var(--grad); box-shadow: 0 6px 16px rgba(26, 115, 232, .3);
}
.btn.primary:hover { filter: brightness(1.06); background: var(--grad); }
.btn:active { transform: translateY(1px); }
.btn.danger { color: var(--ex); border-color: #f3c4c5; }
.btn.danger:hover { background: #fdeeee; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible { outline: 3px solid rgba(26, 115, 232, .4); outline-offset: 2px; }

.search-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.span-2 { grid-column: 1 / -1; }

.cate-form { display: flex; gap: 10px; align-items: flex-end; padding: 14px 16px; flex-wrap: wrap; }
.cate-form .grow { flex: 1; min-width: 180px; }
.segmented { display: flex; background: #eef2f7; border-radius: 12px; padding: 4px; height: 46px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: grid; place-items: center; height: 38px; padding: 0 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.segmented input:checked + span { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--blue); }
.two-col { display: grid; gap: 12px; }
.two-col .card { margin: 0; }
.icon-del {
  width: 34px; height: 34px; border-radius: 10px; border: 0; background: none; color: #a0aab5; cursor: pointer; font-size: 14px;
}
.icon-del:hover { background: #fdeeee; color: var(--ex); }

/* ---------- voucher ---------- */
.voucher-tools { padding: 12px; display: grid; gap: 10px; }
.seg-group { display: flex; background: #eef2f7; border-radius: 12px; padding: 4px; }
.seg {
  flex: 1; display: flex; justify-content: center; align-items: center; gap: 6px; height: 38px; border-radius: 9px;
  text-decoration: none; font-weight: 600; font-size: 14px; color: var(--muted);
}
.seg.on { background: #fff; color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.seg .count { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: rgba(23, 36, 51, .08); }
.status { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.status.going { background: #e7f7ee; color: #0b7a43; }
.status.gone { background: #f1f3f6; color: #8a95a3; }

/* ---------- biểu đồ ví ---------- */
.donut { width: 190px; height: 190px; border-radius: 50%; margin: 6px auto 16px; display: grid; place-items: center; }
.donut-hole {
  width: 128px; height: 128px; border-radius: 50%; background: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; box-shadow: inset 0 0 0 1px var(--line);
}
.donut-hole span { font-size: 12px; color: var(--muted); }
.donut-hole strong { font-size: 16px; }
.legend { border-top: 1px solid var(--line); }
.legend details + details { border-top: 1px solid var(--line); }
.legend summary { display: flex; gap: 12px; align-items: center; padding: 11px 16px; cursor: pointer; list-style: none; }
.legend summary::-webkit-details-marker { display: none; }
.legend summary:hover { background: #f6f8fc; }
.legend .dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.legend .grow { flex: 1; min-width: 0; display: grid; gap: 5px; }
.lg-label { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; border-radius: 999px; background: #eef2f7; overflow: hidden; display: block; }
.bar span { display: block; height: 100%; border-radius: 999px; }
.lg-right { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.lg-right small { color: var(--muted); font-size: 12px; }
.legend details[open] summary { background: #f6f8fc; }
.legend details .list { border-top: 1px solid var(--line); background: #fbfcfe; }

/* ---------- nút + ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 15;
  width: 58px; height: 58px; border-radius: 18px; border: 0; color: #fff; cursor: pointer;
  background: var(--grad); box-shadow: 0 10px 24px rgba(79, 70, 229, .45);
  display: grid; place-items: center; font-size: 32px; font-weight: 300; line-height: 1;
  transition: transform .15s, box-shadow .15s;
}
.fab:hover { transform: translateY(-2px); box-shadow: 0 14px 28px rgba(79, 70, 229, .5); }
.fab:focus-visible { outline: 3px solid rgba(79, 70, 229, .45); outline-offset: 3px; }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(460px, 94vw); color: var(--text);
  box-shadow: 0 24px 60px rgba(4, 16, 32, .4);
}
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(6, 15, 28, .5); backdrop-filter: blur(2px); }
dialog form { display: grid; gap: 12px; padding: 18px 18px 16px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-close { width: 36px; height: 36px; border-radius: 10px; border: 0; background: none; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.dlg-close svg { width: 20px; height: 20px; }
.dlg-close:hover { background: #eef2f7; color: var(--text); }
.amount-input { font-size: 22px; font-weight: 700; height: 54px; }
.hint { color: var(--blue); font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

/* ---------- toast & trống ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: #1d2937; color: #fff; padding: 10px 18px; border-radius: 12px; max-width: 90vw; font-size: 14px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .25); animation: pop .18s ease-out;
}
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.empty-icon { font-size: 26px; opacity: .4; margin-bottom: 4px; }

@media (min-width: 720px) {
  .two-col { grid-template-columns: 1fr 1fr; align-items: start; }
  main { padding-top: 20px; }
}
@media (max-width: 420px) {
  .hero-net strong { font-size: 26px; }
  .wallet-line { grid-template-columns: 1fr auto 14px; }
  .wallet-line .wflow { display: none; }
  .search-form { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- trang đăng nhập ---------- */
body.auth {
  min-height: 100vh; min-height: 100dvh;
  background:
    radial-gradient(600px circle at 12% 18%, rgba(56, 189, 248, .28), transparent 60%),
    radial-gradient(520px circle at 88% 82%, rgba(99, 102, 241, .30), transparent 60%),
    linear-gradient(160deg, #0b1f36 0%, #1a3a5c 55%, #12304f 100%);
}
body.auth main { max-width: none; padding: 0; }
.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 20px; padding: 32px 28px 28px;
  box-shadow: 0 24px 60px rgba(4, 16, 32, .45), 0 2px 6px rgba(4, 16, 32, .2);
  display: grid; gap: 16px;
  animation: auth-in .35s ease-out both;
}
@keyframes auth-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .auth-card { animation: none; } }

.auth-brand { text-align: center; margin-bottom: 4px; }
.auth-logo {
  width: 60px; height: 60px; margin: 0 auto 12px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #1a73e8, #4f46e5);
  box-shadow: 0 10px 24px rgba(26, 115, 232, .35);
}
.auth-logo svg { width: 30px; height: 30px; }
.auth-brand h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; color: var(--navy); }
.auth-brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.auth-field { display: grid; gap: 6px; }
.auth-field label { font-size: 13px; font-weight: 600; color: #3c4a5a; }
.auth-input { position: relative; display: flex; align-items: center; }
.auth-input > .icon {
  position: absolute; left: 14px; width: 18px; height: 18px; color: #8a96a3; pointer-events: none;
  transition: color .15s;
}
.auth-input svg { width: 100%; height: 100%; display: block; }
.auth-input input {
  height: 48px; padding: 0 44px 0 42px; border-radius: 12px;
  border: 1.5px solid #d6dde5; background: #f8fafc; font-size: 16px; /* 16px: iOS không tự zoom */
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.auth-input input::placeholder { color: #a3adb8; }
.auth-input input:focus {
  outline: none; background: #fff; border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, .15);
}
.auth-input:focus-within > .icon { color: var(--blue); }
.auth-eye {
  position: absolute; right: 6px; width: 36px; height: 36px; padding: 8px;
  border: 0; border-radius: 8px; background: none; color: #8a96a3; cursor: pointer;
}
.auth-eye:hover { background: #eef2f6; color: var(--text); }
.auth-eye:focus-visible { outline: 2px solid var(--blue); outline-offset: 0; }
.auth-eye .icon { display: block; width: 20px; height: 20px; }

.auth-submit {
  height: 48px; margin-top: 4px; border: 0; border-radius: 12px; color: #fff; font-weight: 600; font-size: 16px;
  background: linear-gradient(135deg, #1a73e8, #4f46e5);
  box-shadow: 0 8px 20px rgba(26, 115, 232, .35);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .1s, box-shadow .15s, filter .15s;
}
.auth-submit:hover { filter: brightness(1.06); box-shadow: 0 10px 24px rgba(26, 115, 232, .45); }
.auth-submit:active { transform: translateY(1px); }
.auth-submit:focus-visible { outline: 3px solid rgba(26, 115, 232, .45); outline-offset: 2px; }
.auth-submit:disabled { cursor: progress; opacity: .85; }
.auth-submit .spinner {
  display: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.auth-submit.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-error {
  padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: #fdecea; color: #b3261e; border: 1px solid #f5c2bd;
}
.auth-foot { margin: 20px 0 0; color: rgba(255, 255, 255, .55); font-size: 13px; }

@media (max-width: 420px) {
  .auth-card { padding: 28px 20px 22px; border-radius: 18px; }
}
