:root {
  --bg: #0A0A0D; --s1: #131318; --s2: #1A1A21; --s3: #24242D; --line: #1F1F27; --line2: #2A2A33;
  --t1: #F2F2F5; --t2: #9A9AA8; --t3: #62626E;
  --gold: #D4AF6A; --gold-hi: #EBCB8B; --gold-lo: #B48E4A;
  --red: #FF7A7A; --green: #4FD1A1;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --key-h: 56px;
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--t1); overscroll-behavior: none; }
body { -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; touch-action: manipulation; font-size: 15px; }
input { -webkit-user-select: text; user-select: text; }
button, label.row, label.key { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--t2); }
.small { font-size: 12.5px; }
.pos { color: var(--green); } .neg { color: var(--red); }
p { margin: 6px 0 0; line-height: 1.5; font-size: 13.5px; }

svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 17px; height: 17px; }
svg.i.xs { width: 13px; height: 13px; }
svg.i.xl { width: 44px; height: 44px; stroke-width: 1.4; color: var(--gold); }

#app { height: 100%; }
.boot { height: 100%; display: grid; place-items: center; color: var(--t3); letter-spacing: .2em; font-size: 13px; }
.layout { height: 100%; display: flex; }
.pane { flex: 1; min-width: 0; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.side { display: none; }
.tail { height: calc(110px + var(--safe-b)); }

/* two-pane layout for the unfolded inner screen, iPad and desktop */
@media (min-width: 640px) {
  .main { flex: 0 0 46%; max-width: 520px; }
  .side { display: block; border-left: 1px solid var(--line); background: #0C0C10; }
  .side .sheet { height: 100%; }
  .fab { right: auto !important; left: calc(min(46vw, 520px) - 84px); }
}

/* header */
.hdr { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: calc(var(--safe-t) + 8px) 10px 8px; background: rgba(10, 10, 13, .86);
  -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px); }
.side .hdr { background: rgba(12, 12, 16, .9); }
.hdr-s { width: 84px; display: flex; align-items: center; flex: none; }
.hdr-s.r { justify-content: flex-end; }
.sync { position: relative; width: 36px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--t3); }
.sync i { position: absolute; right: 6px; top: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--bg); }
.sync.busy i { background: var(--gold); animation: pulse 1s ease-in-out infinite; }
.sync.warn i { background: var(--gold); } .sync.warn { color: var(--gold); }
.sync.bad i { background: var(--red); } .sync.off i { background: var(--t3); }
@keyframes pulse { 50% { opacity: .3; } }
.hdr-c { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.ttl { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--t2); flex: none; }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.ghost { pointer-events: none; }
.icon-btn:active { background: var(--s2); color: var(--t1); }
.icon-btn.danger { color: var(--red); }
.month-btn { display: flex; align-items: center; gap: 5px; font-size: 17px; font-weight: 600; padding: 7px 10px; border-radius: 12px; white-space: nowrap; }
.month-btn svg { color: var(--t2); }
.month-btn:active { background: var(--s2); }

.side-hdr { justify-content: center; }
.tabs { display: flex; gap: 4px; background: var(--s1); border: 1px solid var(--line); padding: 4px; border-radius: 14px; }
.tabs button { display: flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600; color: var(--t2); }
.tabs button.on { background: var(--s3); color: var(--t1); }

/* hero balance card */
.hero { margin: 6px 16px 6px; padding: 20px 20px 16px; border-radius: 24px; position: relative; overflow: hidden;
  background: linear-gradient(150deg, #1E1C22 0%, #141418 55%, #111114 100%); border: 1px solid #2A272F; }
.hero::before { content: ""; position: absolute; top: -90px; right: -70px; width: 240px; height: 240px; pointer-events: none;
  background: radial-gradient(closest-side, rgba(212, 175, 106, .20), transparent); }
.hero.slim { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.lbl { font-size: 12px; color: var(--t2); letter-spacing: .02em; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -.025em; margin: 4px 0 16px; position: relative; }
.big.sm { font-size: 24px; margin: 2px 0 0; }
.cur { font-size: .45em; color: var(--gold); font-weight: 600; margin-right: 6px; letter-spacing: .04em; vertical-align: .35em; }
.split { display: flex; gap: 10px; position: relative; }
.split > button { flex: 1; background: rgba(255, 255, 255, .035); border: 1px solid rgba(255, 255, 255, .04); border-radius: 14px; padding: 10px 12px; }
.split > button:active { background: rgba(255, 255, 255, .07); }
.split .v { font-size: 17px; font-weight: 600; margin-top: 2px; }
.cmp { font-size: 12px; margin-top: 12px; position: relative; }

/* entries */
.day { margin: 16px 16px 0; }
.day-h { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--t2); padding: 0 4px 7px; font-weight: 500; }
.card { background: var(--s1); border-radius: 18px; overflow: hidden; border: 1px solid var(--line); }
.card.pad { padding: 16px; margin: 12px 16px 0; }
.card.list { margin: 12px 16px 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; gap: 8px; }
.card-h > span:first-child { display: flex; align-items: center; gap: 7px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; width: 100%; text-align: left; position: relative; }
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--s2); }
.row.act > svg { color: var(--gold); }
.row.danger, .row.danger svg { color: var(--red) !important; }
.cat-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; transition: background .15s, color .15s; }
.cat-ic svg.i { width: 20px; height: 20px; }
.cat-ic.lg { width: 48px; height: 48px; border-radius: 15px; }
.row .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .n { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .m { font-size: 12.5px; color: var(--t2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .a { font-size: 15px; font-weight: 600; white-space: nowrap; }
.row .a2 { display: flex; flex-direction: column; align-items: flex-end; font-weight: 600; font-size: 14.5px; }
.row .a2 .m { font-weight: 400; }
.meter { height: 4px; background: var(--s3); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 2px; }

.empty { text-align: center; padding: 56px 32px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty.sm { padding: 28px 24px; }
.et { font-size: 17px; font-weight: 600; margin-top: 6px; }
.es { font-size: 13.5px; color: var(--t2); line-height: 1.5; }
.es.pad { padding: 16px; } .center { text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 11px 18px; border-radius: 14px; background: var(--s2); border: 1px solid var(--line2); font-weight: 600; font-size: 14.5px; margin-top: 10px; }
.btn:active { background: var(--s3); }
.btn.gold, .fab, .key.ok { background: linear-gradient(150deg, var(--gold-hi), var(--gold-lo)); color: #16130D; border: 0; }
.btn.wide { width: 100%; }
.pill.ok { color: var(--green); background: rgba(79,209,161,.12); } .pill.warn, .pill.busy { color: var(--gold); } .pill.bad { color: var(--red); background: rgba(255,122,122,.12); }
.btn.ghost { background: none; border-color: transparent; color: var(--t2); font-weight: 500; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--gold); }
.snaps { margin: 12px 0 0; max-height: 50vh; overflow-y: auto; }
.pill { font-size: 11px; font-weight: 600; color: var(--gold); background: rgba(212, 175, 106, .12); padding: 4px 9px; border-radius: 99px; }
.stat-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.stat-line:last-child { border-bottom: 0; }
.stat-line b { font-weight: 600; text-align: right; }
.ver { text-align: center; color: var(--t3); font-size: 12px; margin: 20px 0 0; }

.fab { position: fixed; right: 20px; bottom: calc(var(--safe-b) + 22px); width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center; z-index: 10;
  box-shadow: 0 12px 32px rgba(212, 175, 106, .28), 0 2px 6px rgba(0, 0, 0, .5); }
.fab svg.i { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }

/* segmented controls */
.seg { display: flex; margin: 8px 16px 4px; background: var(--s1); border-radius: 14px; padding: 4px; border: 1px solid var(--line); }
.seg button { flex: 1; padding: 9px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--t2); text-align: center; }
.seg button.on { background: var(--s3); color: var(--t1); }
.seg button.on.exp { color: var(--red); } .seg button.on.inc { color: var(--green); }
.seg.sm { margin: 0; padding: 3px; }
.seg.sm button { padding: 6px 12px; font-size: 13px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 16px 4px; }
.pnav { display: flex; align-items: center; }
.pnav .month-btn { font-size: 15px; }

/* stats */
.donut-row { display: flex; align-items: center; gap: 18px; }
.donut-wrap { position: relative; width: 150px; height: 150px; flex: none; }
.donut { width: 100%; height: 100%; }
.donut-c { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.dv { font-weight: 700; letter-spacing: -.02em; }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; font-size: 13.5px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.legend span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend b { font-weight: 500; color: var(--t2); }
.bars { display: flex; gap: 6px; height: 150px; margin-top: 14px; }
.bar { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.bv { font-size: 10px; color: var(--t3); height: 12px; white-space: nowrap; }
.bt { flex: 1; width: 100%; max-width: 30px; display: flex; align-items: flex-end; background: rgba(255, 255, 255, .025); border-radius: 7px; overflow: hidden; }
.bf { width: 100%; background: #3A3A46; border-radius: 7px; transition: height .3s ease; }
.bar.on .bf { background: linear-gradient(180deg, var(--gold-hi), var(--gold-lo)); }
.bar.on .bv { color: var(--gold); }
.bl { font-size: 11px; color: var(--t2); }
.bar.on .bl { color: var(--t1); font-weight: 600; }

/* search */
.search { display: flex; align-items: center; gap: 8px; margin: 6px 16px 0; padding: 0 12px; background: var(--s1); border: 1px solid var(--line); border-radius: 14px; color: var(--t2); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 12px 0; font-size: 16px; color: var(--t1); }
.res-h { display: flex; justify-content: space-between; margin: 14px 20px 0; font-size: 12.5px; color: var(--t2); }

/* add / edit sheet */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(18px); opacity: 0; } }
.sheet { display: flex; flex-direction: column; height: 100%; }
.cgrid { flex: 1; min-height: 120px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 14px 4px; padding: 14px 12px 16px; align-content: start; }
.cgrid button { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11.5px; color: var(--t2); min-width: 0; }
.cgrid button > span:last-child { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cgrid .cat-ic { width: 50px; height: 50px; border-radius: 16px; background: var(--s2); color: var(--t2); }
.cgrid button.on { color: var(--t1); font-weight: 600; }
.entry-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--s1); }
.entry-bar input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; font-size: 16px; color: var(--t1); padding: 8px 0; }
.entry-bar input::placeholder { color: var(--t3); }
.amt { font-size: 26px; font-weight: 700; white-space: nowrap; max-width: 60%; overflow: hidden; display: flex; align-items: baseline; justify-content: flex-end; letter-spacing: -.02em; }
.amt .cur { vertical-align: baseline; font-size: 12px; }
.keypad { background: var(--s1); padding-bottom: var(--safe-b); }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.key { background: var(--s1); height: var(--key-h); font-size: 23px; font-weight: 500; display: flex; align-items: center; justify-content: center; position: relative; }
.key:active { background: var(--s3); }
.key.ok { font-size: 26px; font-weight: 600; }
.key.ok:active { filter: brightness(.9); }
.key.ok svg.i { width: 28px; height: 28px; stroke-width: 2.4; }
.key.date { flex-direction: column; gap: 2px; font-size: 13.5px; font-weight: 600; color: var(--gold); overflow: hidden; }
.key.date small { color: var(--t3); line-height: 0; }
.key.date input { background: transparent; color: transparent; position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; margin: 0; -webkit-appearance: none; appearance: none; }
.key.date input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
@media (max-height: 700px) { :root { --key-h: 50px; } .cgrid .cat-ic { width: 44px; height: 44px; } }
@media (max-height: 560px) { :root { --key-h: 44px; } }

/* modals */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .15s ease-out;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
@keyframes fade { from { opacity: 0; } }
.pick { width: 100%; max-width: 380px; background: var(--s1); border: 1px solid var(--line2); border-radius: 24px; padding: 14px 16px 16px; animation: up .18s ease-out; }
.pick-h { display: flex; align-items: center; justify-content: space-between; font-size: 18px; margin-bottom: 8px; }
.mgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mgrid button { padding: 13px 0; border-radius: 14px; background: var(--s2); font-weight: 500; text-align: center; position: relative; }
.mgrid button i { position: absolute; left: 50%; bottom: 5px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--t3); }
.mgrid button.on { background: linear-gradient(150deg, var(--gold-hi), var(--gold-lo)); color: #16130D; font-weight: 700; }
.mgrid button.on i { background: #16130D; }
.imp { padding: 18px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.field input { background: var(--s2); border: 1px solid var(--line2); border-radius: 10px; padding: 7px 10px; color: var(--t1); font-size: 15px; }
.btns { display: flex; gap: 10px; margin-top: 8px; }
.btns .btn { flex: 1; }

.modal.left { justify-content: flex-start; align-items: stretch; padding: 0; }
.drawer { width: min(300px, 82vw); height: 100%; background: var(--s1); border-right: 1px solid var(--line2); padding: calc(var(--safe-t) + 22px) 14px 20px; display: flex; flex-direction: column; gap: 4px; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-24px); opacity: 0; } }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.brand b { font-size: 17px; }
.brand .muted { font-size: 12.5px; margin-top: 2px; }
.logo { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(150deg, var(--gold-hi), var(--gold-lo)); color: #16130D; }
.drawer > button { display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-radius: 14px; font-size: 15.5px; font-weight: 500; color: var(--t2); }
.drawer > button svg { color: var(--t2); }
.drawer > button.on { background: var(--s3); color: var(--t1); }
.drawer > button.on svg { color: var(--gold); }

#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 50;
  background: #26252C; border: 1px solid var(--line2); color: var(--t1); padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; max-width: 86vw; text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: rgba(255, 122, 122, .4); color: #FFB3B3; }
