/* Layout: one phone column; a blue-to-mint hero sits behind white cards that overlap it; floating pill nav. */
:root {
  --bg: #F2F5F9; --card: #FFFFFF; --soft: #EEF2F8; --line: #E3E9F2;
  --fg: #16204A; --muted: #68738F; --faint: #97A1B8;
  --blue: #2F6BDB; --blue-soft: #E1EAFB; --green: #2FA573; --green-soft: #DBF4E6;
  --red: #D8485A; --red-soft: #FCE3E6; --amber: #A87400; --amber-soft: #FFF1CC;
  --h1: #3C74DD; --h2: #6FAEEA; --h3: #BCE8C4; --on-hero: #FFFFFF;
  --glass: rgba(255, 255, 255, .24); --ring-a: #2F6BDB; --ring-b: #9BE3D0;
  --shadow: 0 8px 24px rgba(40, 64, 120, .08); --nav-shadow: 0 10px 30px rgba(40, 64, 120, .16);
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0E1426; --card: #182139; --soft: #212C48; --line: #2A3654;
  --fg: #EEF2FB; --muted: #A2ADC6; --faint: #75819D;
  --blue: #7DA7F5; --blue-soft: #243660; --green: #5FD2A0; --green-soft: #173F35;
  --red: #F2808E; --red-soft: #4A2230; --amber: #F1C557; --amber-soft: #43371A;
  --h1: #234C9E; --h2: #2E71A8; --h3: #2C7B6B; --glass: rgba(255, 255, 255, .14);
  --ring-a: #7DA7F5; --ring-b: #7CE3C8;
  --shadow: 0 8px 24px rgba(0, 0, 0, .28); --nav-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #0E1426; --card: #182139; --soft: #212C48; --line: #2A3654;
  --fg: #EEF2FB; --muted: #A2ADC6; --faint: #75819D;
  --blue: #7DA7F5; --blue-soft: #243660; --green: #5FD2A0; --green-soft: #173F35;
  --red: #F2808E; --red-soft: #4A2230; --amber: #F1C557; --amber-soft: #43371A;
  --h1: #234C9E; --h2: #2E71A8; --h3: #2C7B6B; --glass: rgba(255, 255, 255, .14);
  --ring-a: #7DA7F5; --ring-b: #7CE3C8;
  --shadow: 0 8px 24px rgba(0, 0, 0, .28); --nav-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; overflow-x: hidden; width: 100%; }
body { margin: 0; width: 100%; overflow-x: hidden; background: var(--bg); color: var(--fg); font: 16px/1.4 var(--font); overscroll-behavior-y: none; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

.app { width: 100%; max-width: 480px; margin: 0 auto; overflow-x: clip; min-height: 100dvh; padding-bottom: calc(112px + env(safe-area-inset-bottom)); }

/* Hero */
.hero {
  padding: calc(16px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 92px max(20px, env(safe-area-inset-left));
  background: linear-gradient(168deg, var(--h1) 0%, var(--h2) 58%, var(--h3) 100%);
  color: var(--on-hero);
}
.hero.short { padding-bottom: 76px; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.hero h1 { font-size: 24px; line-height: 1.2; font-weight: 700; margin-top: 16px; text-wrap: balance; }
.hero h1 span { display: block; font-size: 17px; font-weight: 500; opacity: .92; margin-top: 2px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; min-height: 44px; }
.brand img { border-radius: 11px; box-shadow: 0 4px 12px rgba(10, 40, 120, .28); }
.tag { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 8px; background: var(--glass); font-size: 12px; font-weight: 600; color: var(--on-hero); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--on-hero); background: var(--glass); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.balance-pill { margin-top: 16px; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; border-radius: 16px; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.balance-pill .ic { width: 38px; height: 38px; border-radius: 11px; background: var(--card); color: var(--blue); display: grid; place-items: center; flex: none; }
.balance-pill .ic svg { width: 20px; height: 20px; }
.balance-pill .txt { min-width: 0; flex: 1; }
.balance-pill small { display: block; font-size: 12px; opacity: .92; }
.balance-pill strong { font-size: 18px; font-weight: 700; }
.btn-white { background: var(--card); color: var(--blue); font-size: 14px; font-weight: 700; padding: 10px 14px; border-radius: 12px; flex: none; }

/* Content */
.content { padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 24px; margin-top: -68px; min-width: 0; }
.content > * { min-width: 0; }
.hero.short + .content { margin-top: -56px; }
.card { background: var(--card); border-radius: 22px; padding: 16px; box-shadow: var(--shadow); }
.sec-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 12px; }
.sec-head h2 { font-size: 18px; font-weight: 700; }
.link { color: var(--blue); font-size: 14px; font-weight: 600; padding: 4px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }

.free { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.free .txt { min-width: 0; }
.free .label { font-size: 13px; color: var(--muted); margin-top: 12px; }
.free .big { font-size: clamp(22px, 7.4vw, 30px); overflow-wrap: anywhere; line-height: 1.15; font-weight: 800; letter-spacing: -.01em; }
.free .sub { font-size: 13px; color: var(--muted); margin-top: 6px; }
.ring { position: relative; flex: none; display: grid; place-items: center; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring .mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring .mid b { font-size: 22px; font-weight: 800; line-height: 1.1; }
.ring .mid small { font-size: 12px; color: var(--muted); }
.hero .ring .mid small { color: var(--on-hero); opacity: .9; }

/* Horizontal account cards */
.hscroll { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 12px; scroll-snap-type: x proximity; scroll-padding-inline: 16px; }
.hscroll::-webkit-scrollbar { display: none; }
.acc-card { flex: 0 0 150px; scroll-snap-align: start; background: var(--card); border-radius: 20px; padding: 14px; box-shadow: var(--shadow); text-align: left; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.acc-dot { width: 34px; height: 34px; border-radius: 11px; color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.acc-card .name { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-card .val { font-size: 17px; font-weight: 700; }

/* Rows */
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; background: var(--card); border-radius: 18px; box-shadow: var(--shadow); }
.tile { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 20px; flex: none; background: var(--soft); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.row .amt { font-size: 15px; font-weight: 700; }
.amt.in { color: var(--green); }
.day-label { font-size: 13px; font-weight: 600; color: var(--muted); margin: 8px 4px 0; display: flex; justify-content: space-between; }

.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; color: transparent; }
.check svg { width: 16px; height: 16px; }
.check.on { background: var(--green); border-color: var(--green); color: var(--card); }

/* Bars */
.bar-row { display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: center; }
.bar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; }
.bar-sub { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.bar { height: 7px; border-radius: 4px; background: var(--soft); overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--ring-a), var(--ring-b)); }

/* Segments */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--soft); border-radius: 14px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 11px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--blue); box-shadow: 0 2px 6px rgba(40, 64, 120, .1); }
.hero .seg { background: var(--glass); margin-top: 16px; }
.hero .seg button { color: var(--on-hero); }
.hero .seg button.on { color: var(--blue); }

/* Chart */
.chart { width: 100%; display: block; touch-action: pan-y; }
.chart text { fill: var(--faint); font-size: 11px; font-family: var(--font); }
.chart text.on { fill: var(--fg); font-weight: 700; }
.chart .tip-text { fill: #fff; font-weight: 700; font-size: 12px; }
.chart .tip-sub { fill: #fff; opacity: .85; font-size: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--soft); border-radius: 14px; padding: 10px; min-width: 0; }
.stat small { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 14px; font-weight: 700; }

.search { width: 100%; padding: 12px 14px; border-radius: 14px; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 16px; }
.filter { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.filter::-webkit-scrollbar { display: none; }
.pick { flex: none; padding: 8px 12px; border-radius: 12px; background: var(--card); font-size: 14px; font-weight: 600; color: var(--muted); border: 1.5px solid var(--line); }
.pick.on { background: var(--blue-soft); color: var(--blue); border-color: var(--blue); }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; font-size: 14px; }
.notice { background: var(--amber-soft); color: var(--amber); font-size: 13px; font-weight: 600; padding: 10px 12px; border-radius: 14px; }

/* Bottom nav */
.nav {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); width: min(calc(100% - 32px), 448px);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 6px; background: var(--card); border-radius: 26px; box-shadow: var(--nav-shadow);
}
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--faint); }
.nav button svg { width: 22px; height: 22px; }
.nav button.on { color: var(--blue); }
.nav .add span { width: 50px; height: 50px; border-radius: 18px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #3C74DD, #57BFC0); box-shadow: 0 6px 14px rgba(47, 107, 219, .35); }
.nav .add { padding: 0; }

/* Bottom sheet */
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(12, 20, 44, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 480px; max-height: 92dvh; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--bg); border-radius: 26px 26px 0 0;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 14px; animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-size: 19px; font-weight: 700; }
.close { width: 34px; height: 34px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; color: var(--muted); flex: none; }
.close svg { width: 16px; height: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.input { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); font-size: 16px; }
.input:focus { outline: none; border-color: var(--blue); }
input[type="date"].input { -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; min-width: 0; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.amount-box { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 12px; background: var(--card); border-radius: 18px; border: 1.5px solid var(--line); }
.amount-box:focus-within { border-color: var(--blue); }
.amount-box span { font-size: 20px; font-weight: 700; color: var(--muted); }
.amount-box input { width: 170px; max-width: 60%; border: 0; background: none; font-size: 36px; font-weight: 800; text-align: left; outline: none; padding: 0; }
.cat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; border-radius: 14px; font-size: 12px; font-weight: 600; color: var(--muted); border: 1.5px solid transparent; background: var(--card); min-width: 0; }
.cat i { font-style: normal; font-size: 22px; line-height: 1.2; }
.cat span { max-width: 100%; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.cat.on { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.err { color: var(--red); font-size: 13px; font-weight: 600; }
.btn { display: block; width: 100%; padding: 15px; border-radius: 16px; font-size: 16px; font-weight: 700; text-align: center; color: #fff; background: linear-gradient(120deg, #3C74DD, #4FA9D8); }
.sheet .btn[type="submit"] { position: sticky; bottom: 0; z-index: 2; box-shadow: 0 6px 18px rgba(47, 107, 219, .3); }
.btn.plain { background: var(--soft); color: var(--fg); }
.btn.danger { background: var(--red-soft); color: var(--red); }

.toast { position: fixed; z-index: 40; left: 50%; transform: translateX(-50%); bottom: calc(100px + env(safe-area-inset-bottom)); background: #16204A; color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: var(--nav-shadow); max-width: calc(100% - 32px); width: max-content; text-align: center; }

/* Pull to refresh */
.ptr { position: fixed; z-index: 15; top: calc(10px + env(safe-area-inset-top)); left: 50%; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: var(--card); box-shadow: var(--nav-shadow); display: grid; place-items: center; opacity: 0; transform: translateY(-60px); pointer-events: none; }
.ptr span { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--blue); }
.ptr.spin span { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ptr.spin span { animation-duration: 2.4s; } }
