:root {
  --bg: #0b0f14; --surface: #131a22; --surface2: #1b2431; --line: rgba(255,255,255,.08);
  --text: #e8eef5; --mut: #8793a3; --teal: #00d4c8; --green: #3fb950; --red: #f85149; --amber: #d29922;
  --r: 16px; color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root[data-theme=auto] {
    --bg: #f4f7fa; --surface: #fff; --surface2: #eef2f6; --line: rgba(0,0,0,.08);
    --text: #0f1720; --mut: #5b6877; --teal: #00988f; --green: #1a7f37; --red: #cf222e; --amber: #9a6700; color-scheme: light;
  }
}
:root[data-theme=light] {
  --bg: #f4f7fa; --surface: #fff; --surface2: #eef2f6; --line: rgba(0,0,0,.08);
  --text: #0f1720; --mut: #5b6877; --teal: #00988f; --green: #1a7f37; --red: #cf222e; --amber: #9a6700; color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100dvh; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: inherit; }
h2, h3 { font-weight: 700; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--mut); margin-bottom: 12px; }
.mut { color: var(--mut); } .small { font-size: 12px; } .pos { color: var(--green); } .neg { color: var(--red); }
.between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.between h3 { margin-bottom: 0; }

#view { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(100px + env(safe-area-inset-bottom)); }
.ptitle { font-size: 24px; margin: 6px 0 14px; }

/* nav */
#nav {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
#nav .brand { display: none; }
#nav [data-tab] { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--mut); border-radius: 10px; }
#nav [data-tab] i { font-style: normal; font-size: 20px; }
#nav [data-tab].on { color: var(--teal); }
#nav [data-tab].desk { display: none; }
#nav .fab {
  justify-self: center; width: 52px; height: 52px; margin-top: -22px; border-radius: 50%; font-size: 28px; line-height: 1;
  background: linear-gradient(135deg, var(--teal), #00a79d); color: #04201e; box-shadow: 0 6px 20px rgba(0,212,200,.35);
}
#nav .fab span { display: none; }

/* hero */
.hero {
  position: relative; overflow: hidden; border-radius: 22px; padding: 20px; margin-bottom: 12px;
  background: linear-gradient(135deg, rgba(0,212,200,.2), rgba(88,166,255,.08) 60%, transparent), var(--surface);
  border: 1px solid rgba(0,212,200,.25);
}
.hero::after { content: ""; position: absolute; right: -50px; top: -50px; width: 170px; height: 170px; border-radius: 50%; background: radial-gradient(circle, rgba(0,212,200,.22), transparent 70%); }
.lbl { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--mut); }
.big { font-size: 38px; font-weight: 800; letter-spacing: -1.5px; margin: 4px 0 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; position: relative; z-index: 1; }
.chip { padding: 6px 12px; border-radius: 99px; font-weight: 700; font-size: 14px; background: var(--surface2); }
.chip.inc { color: var(--green); } .chip.exp { color: var(--red); }

/* month bar */
.mbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.mbar .gear { margin-left: 4px; }
.mbar button { width: 40px; height: 40px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 20px; }
.mbar .mlabel { width: auto; padding: 0 18px; font-size: 15px; font-weight: 700; }

/* cards */
.grid { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.card.list { padding: 4px 12px; margin-bottom: 14px; }
.ringcard { display: flex; align-items: center; gap: 16px; }
.ring { width: 84px; height: 84px; flex-shrink: 0; }
.chart { width: 100%; height: auto; max-height: 190px; display: block; }
.ax { fill: var(--mut); font-size: 9px; } .dv { fill: var(--text); font-size: 15px; font-weight: 700; } .dl { fill: var(--mut); font-size: 8px; }
.ring .dv { font-size: 16px; }
.legend { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--mut); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; flex-shrink: 0; }
.donutwrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { width: 130px; height: 130px; flex-shrink: 0; }
.leg { flex: 1; min-width: 180px; display: grid; gap: 8px; }
.legrow { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.legrow span:nth-child(2) { flex: 1; }
.legrow .mut { width: 34px; text-align: right; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 2px; }
.stat span { font-size: 12px; font-weight: 600; } .stat b { font-size: 19px; letter-spacing: -.5px; }
.track { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.track i { display: block; height: 100%; border-radius: 4px; transition: width .5s; }
.brow { margin-bottom: 12px; } .brow:last-child { margin-bottom: 0; }

/* transactions */
.tx { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 0; text-align: left; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; flex-shrink: 0; background: color-mix(in srgb, var(--c) 18%, transparent); }
.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-t { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-s { font-size: 12px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; } .amt.income { color: var(--green); } .amt.expense { color: var(--red); }
.day { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--mut); margin: 4px 2px 8px; }
.empty { text-align: center; padding: 28px 12px; } .empty-t { font-weight: 600; margin-bottom: 4px; }
.link { color: var(--teal); font-weight: 600; font-size: 13px; }

/* tools */
.tools { display: grid; gap: 10px; margin-bottom: 14px; }
.pills { display: flex; gap: 8px; }
.pill { padding: 7px 16px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--mut); }
.pill.on { background: rgba(0,212,200,.14); border-color: rgba(0,212,200,.4); color: var(--teal); }

/* forms */
.f { display: grid; gap: 6px; margin-bottom: 12px; font-size: 12px; font-weight: 600; color: var(--mut); }
input:not([type=radio]):not([type=file]), select, textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); outline: none; font-weight: 500; color: var(--text);
}
#q { background: var(--surface); }
input:focus, select:focus, textarea:focus { border-color: var(--teal); }
textarea { resize: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.catadd { display: flex; gap: 8px; margin-top: 12px; } .catadd input[name=icon] { width: 64px; text-align: center; } .crow { padding: 6px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 12px; font-weight: 700; background: var(--surface2); border: 1px solid var(--line); }
.btn.primary { background: linear-gradient(135deg, var(--teal), #00a79d); color: #04201e; border: 0; }
.btn.danger { color: var(--red); } .btn.small { padding: 8px 14px; font-size: 13px; }
.btns { display: grid; gap: 10px; margin-bottom: 10px; }
.x { width: 34px; height: 34px; border-radius: 10px; color: var(--mut); }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 12px; border-radius: var(--r); background: rgba(163,113,247,.12); border: 1px solid rgba(163,113,247,.3); }
.banner > div { flex: 1; }

/* sheet */
dialog#sheet { margin: auto auto 0; width: 100%; max-width: 520px; max-height: 94dvh; border: 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text); }
dialog#sheet::backdrop { background: rgba(0,0,0,.6); }
#txform { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.shead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); margin-bottom: 14px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 9px; font-weight: 700; color: var(--mut); cursor: pointer; }
.seg input:checked + span { background: var(--surface2); color: var(--text); }
.seg label:has(input[value=expense]:checked) span { color: var(--red); } .seg label:has(input[value=income]:checked) span { color: var(--green); }
.acts { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 50;
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0,0,0,.35); font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; max-width: 92vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.ok { color: var(--green); } #toast.err { color: var(--red); } #toast button { color: var(--teal); font-weight: 700; }

/* tablet / desktop */
@media (min-width: 900px) {
  body { padding-left: 230px; }
  #nav { inset: 0 auto 0 0; width: 230px; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 22px 14px; border-top: 0; border-right: 1px solid var(--line); }
  #nav [data-tab].desk { display: flex; }
  .gear { display: none !important; }
  #nav .brand { display: block; font-size: 22px; font-weight: 800; padding: 0 10px 18px; background: linear-gradient(135deg, var(--teal), #7ee8e4); -webkit-background-clip: text; background-clip: text; color: transparent; }
  #nav [data-tab] { flex-direction: row; gap: 12px; font-size: 14px; padding: 11px 12px; }
  #nav [data-tab].on { background: rgba(0,212,200,.12); }
  #nav .fab { order: -1; width: auto; height: auto; margin: 0 0 12px; padding: 12px; border-radius: 12px; font-size: 15px; font-weight: 800; display: flex; justify-content: center; gap: 8px; }
  #nav .fab span { display: inline; }
  #view { max-width: 1040px; padding: 28px 32px 48px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .btns { grid-template-columns: 1fr 1fr; }
  dialog#sheet { margin: auto; border-radius: 22px; }
  #toast { bottom: 28px; }
}
@media (max-width: 360px) { .big { font-size: 30px; } .two { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* auth + admin */
body.auth #nav { display: none; }
body.auth { padding-left: 0; }
.authwrap { min-height: 80dvh; display: grid; place-items: center; }
.authcard { width: 100%; max-width: 400px; padding: 24px; }
.authcard h2 { margin-bottom: 16px; font-size: 22px; }
.authcard .btn { width: 100%; margin-top: 4px; }
.authcard p { margin-top: 10px; }
.brandmark { font-size: 26px; font-weight: 800; margin-bottom: 4px; background: linear-gradient(135deg, var(--teal), #7ee8e4); -webkit-background-clip: text; background-clip: text; color: transparent; width: fit-content; }
.center { text-align: center; } .center .brandmark { margin-inline: auto; }
.pwform { display: grid; gap: 8px; margin-top: 12px; }
.urow { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.urow:last-child { border-bottom: 0; }
.uact { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
@media (min-width: 900px) { .urow { grid-template-columns: 1fr auto auto; } .uact { grid-column: auto; } }

/* wealth */
.gear { width: 40px; height: 40px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 18px; }
.wtabs { margin-bottom: 14px; overflow-x: auto; }
.pad { padding: 12px 4px 4px; } .pad0 { margin: 6px 0 10px; }
.clickable { cursor: pointer; }
.worth { font-size: 30px; font-weight: 800; letter-spacing: -1px; margin: 2px 0 8px; }
.day.sub { margin: 10px 4px 4px; }
.cardtile { display: grid; gap: 12px; margin-bottom: 12px; }
.cardnums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cardnums div { display: grid; } .cardnums b { font-size: 15px; letter-spacing: -.3px; }
.badge { padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.ok { background: rgba(63,185,80,.15); color: var(--green); } .badge.warn { background: rgba(210,153,34,.18); color: var(--amber); } .badge.bad { background: rgba(248,81,73,.16); color: var(--red); }
.mtop { margin-top: 2px; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }
.stats .stat b { font-size: 17px; }

.inrow { display: grid; gap: 10px; margin-bottom: 10px; }
.inrow select { width: 100%; }
.dupbadge { width: fit-content; }
.inboxcard { display: flex; align-items: center; gap: 12px; }
textarea#paste { margin-bottom: 4px; }
textarea#paste + .btn { margin: 8px 0 4px; }
