:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e8eaf0; --muted: #8b93a5; --accent: #00d17a; --accent-ink: #0f1115;
  --red: #ff5c6c; --amber: #ffb547; --blue: #5ea8ff;
  --radius: 14px; --shadow: 0 10px 30px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--accent); } .neg { color: var(--red); }

#app { min-height: 100dvh; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: linear-gradient(var(--bg) 70%, transparent); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .08em; font-size: 14px; }
.brand em { font-style: normal; font-weight: 500; letter-spacing: 0; color: var(--muted); margin-left: 4px; }
.brand.big { font-size: 18px; justify-content: center; margin-bottom: 20px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-weight: 900; font-size: 18px; }
.top-right { display: flex; align-items: center; gap: 12px; }

main { flex: 1; padding: 4px 16px 110px; max-width: 760px; width: 100%; margin: 0 auto; }
h2 { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 22px 0 10px; font-weight: 700; }
h2:first-child { margin-top: 6px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; transition: border-color .15s, transform .15s; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: #3a4152; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card .row + .row { margin-top: 6px; }
.amount { font-size: 22px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.pair-title { font-size: 17px; font-weight: 700; }
.pair-title b { color: var(--accent); }
.settled { opacity: .55; }
.detail { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(-3px);} to { opacity: 1; transform: none; } }
.debt-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,.04); font-size: 14px; }
.debt-line:last-child { border-bottom: 0; }
.debt-line .sub { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; background: var(--panel2); color: var(--muted); }
.chip.purchase { background: rgba(94,168,255,.15); color: var(--blue); }
.chip.loan { background: rgba(255,181,71,.15); color: var(--amber); }
.chip.payment { background: rgba(0,209,122,.15); color: var(--accent); }
.chip.transfer { background: rgba(139,147,165,.18); color: #b8c0d2; }
.chip.credit { background: rgba(255,92,108,.15); color: var(--red); }
.chip.bank { background: rgba(94,168,255,.15); color: var(--blue); }
.chip.cash { background: rgba(0,209,122,.15); color: var(--accent); }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; position: relative; transition: border-color .15s; }
.list-item:hover { border-color: #3a4152; }
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.list-item .amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-item .ops { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.list-item:hover .ops, .list-item:focus-within .ops { opacity: 1; }
@media (hover: none) { .list-item .ops { opacity: .8; } }
.icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); transition: background .12s, color .12s; font-size: 15px; }
.icon:hover { background: var(--panel2); color: var(--text); }
.icon.x:hover { background: rgba(255,92,108,.18); color: var(--red); }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--panel2); flex: none; }
.trashed { opacity: .55; }
.trashed .title { text-decoration: line-through; }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty b { color: var(--text); display: block; margin-bottom: 4px; font-size: 16px; }

.inline-form { display: flex; gap: 8px; margin: 8px 0 14px; }
.inline-form input { flex: 1; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 11px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,209,122,.15); }
input[type=number] { font-variant-numeric: tabular-nums; }
label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; color: var(--text); font-size: 15px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-amount input { font-size: 30px; font-weight: 800; padding: 8px 12px; text-align: center; }

button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 800; padding: 12px 18px; border-radius: 12px; width: 100%; transition: transform .1s, filter .12s; }
button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: scale(.98); }
button.primary:disabled { opacity: .5; cursor: default; }
button.add-big { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 18px; padding: 16px; margin: 6px 0 4px; box-shadow: 0 6px 20px rgba(0,209,122,.25); }
button.add-big .sub { font-size: 12.5px; font-weight: 500; opacity: .75; }
button.ghost { color: var(--muted); padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); transition: background .12s, color .12s; }
button.ghost:hover { background: var(--panel2); color: var(--text); }
button.ghost.small { padding: 5px 10px; font-size: 12.5px; }
button.link { color: var(--accent); padding: 4px 0; font-weight: 600; }
button.link:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions .primary { flex: 1; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: rgba(23,26,33,.92); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tab { flex: 1; padding: 12px 6px 11px; color: var(--muted); font-weight: 700; font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase; position: relative; transition: color .12s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); }
.tab.active::after { content: ""; position: absolute; left: 30%; right: 30%; top: 0; height: 2px; background: var(--accent); border-radius: 2px; }

.fab { position: fixed; right: 18px; bottom: calc(66px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 34px; font-weight: 800; line-height: 1; box-shadow: 0 8px 24px rgba(0,209,122,.35); z-index: 7; transition: transform .12s, box-shadow .12s; }
.fab:hover { transform: scale(1.06); box-shadow: 0 10px 30px rgba(0,209,122,.5); }
.fab:active { transform: scale(.96); }

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fade .15s; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow: auto; background: var(--panel); border-radius: 20px 20px 0 0; padding: 14px 18px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); animation: up .2s cubic-bezier(.2,.8,.2,1); max-width: 760px; margin: 0 auto; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.seg { display: flex; background: var(--panel2); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: 13px; transition: background .12s, color .12s; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.seg.small button { padding: 6px 4px; font-size: 12px; }

.people-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pick { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); color: var(--muted); font-weight: 600; font-size: 13.5px; transition: all .12s; }
.pick:hover { border-color: var(--accent); color: var(--text); }
.pick.on { background: rgba(0,209,122,.15); border-color: var(--accent); color: var(--accent); }
.split-rows { margin-top: 8px; }
.split-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; margin-bottom: 6px; }
.split-row input { padding: 8px 10px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hint.warn { color: var(--amber); }
.msg { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }
.receipt-box { display: flex; align-items: center; gap: 10px; }
.receipt-box img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #262b36; color: var(--text); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; z-index: 30; animation: up .2s; max-width: 92vw; }
.toast button { color: var(--accent); font-weight: 800; letter-spacing: .06em; }
.toast.err { border: 1px solid var(--red); }

.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 20px; }
.gate-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.gate-card form { display: grid; gap: 12px; }

.acct-group { margin-bottom: 14px; }
.acct-group .who { font-weight: 800; margin: 10px 0 6px; }
.stat { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.bar { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--red); border-radius: 3px; transition: width .3s; }
.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.filters select { width: auto; padding: 7px 10px; }
.alloc { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.project-bar { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; }
.project-bar label { margin: 0; white-space: nowrap; }
.project-bar select { flex: 1; font-weight: 700; padding: 9px 12px; }
.chip.project { background: rgba(255,255,255,.07); color: #c9d0df; text-transform: none; letter-spacing: 0; }
.sum-table { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 14px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sum-table .h { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.sum-table .r { text-align: right; }
.sum-table .row-link { cursor: pointer; color: var(--text); font-weight: 600; }
.sum-table .row-link:hover { color: var(--accent); }
.dl-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; margin-bottom: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; transition: border-color .12s, transform .12s; }
.dl-row:hover { border-color: var(--accent); transform: translateX(2px); }
.dl-row .title { font-weight: 700; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.history-item:last-child { border-bottom: 0; }
