:root {
  --bg: #f3f5f8; --card: #fff; --ink: #14212b; --muted: #61707c; --line: #dfe4ea;
  --navy: #14324a; --accent: #1d6fb8; --good: #1b7a46; --bad: #b3261e; --warn: #9a5b00; --warn-bg: #fff4e0;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f151b; --card: #18212a; --ink: #e8eef3; --muted: #95a4b1; --line: #2a3742;
    --navy: #0b2133; --accent: #5aa7ee; --good: #4fc685; --bad: #ff8a80; --warn: #ffb74d; --warn-bg: #33270f; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom)); overflow-x: hidden; }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: .8rem 0 .4rem; }
a { color: var(--accent); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--navy); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo { background: #fff; color: var(--navy); border-radius: 8px; padding: 2px 6px; font-size: .8rem; }
#who { font-size: .85rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50%; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; text-align: center; padding: 10px 4px 12px; color: var(--muted); text-decoration: none; font-size: .78rem; }
.nav a .i { display: block; font-size: 1.25rem; line-height: 1.2; }
.nav a.on { color: var(--accent); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pad { padding: 24px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: .78rem; color: var(--muted); }
.stat .v { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.big { border-radius: var(--radius); padding: 16px; margin: 12px 0; color: #fff; background: var(--navy); }
.big .k { opacity: .85; font-size: .9rem; }
.big .v { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.big.owe-company { background: #7a3b00; }
.big.settled { background: #3a4a57; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: .9rem; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=date], input[type=month], input[type=number], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 44px; }
textarea { min-height: 120px; }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: .95rem; }
.check input { width: 20px; height: 20px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); padding: 10px 6px; min-height: 44px; cursor: pointer; font-size: .9rem; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.monthbar { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.monthbar .m { flex: 1; text-align: center; font-weight: 700; }
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lines li.tap { cursor: pointer; }
.lines .d { font-size: .8rem; color: var(--muted); }
.lines .t { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.lines .a { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.lines .b { text-align: right; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; font-weight: 500; }
.tag.income { color: var(--good); } .tag.cost { color: var(--bad); } .tag.payout { color: var(--accent); }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: .75rem; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; background: var(--bg); }
tr.click { cursor: pointer; }
td.wrap { white-space: normal; min-width: 160px; }
.code { font: 700 1.6rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: .12em; text-align: center; padding: 14px; background: var(--bg);
  border: 2px dashed var(--accent); border-radius: 12px; user-select: all; overflow-wrap: anywhere; }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-box { position: relative; background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-box { border-radius: 18px; } }
.sheet-x { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border: 0; background: none; font-size: 1.6rem; cursor: pointer; color: var(--muted); }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30; max-width: 480px; margin: 0 auto;
  background: #222; color: #fff; padding: 12px 16px; border-radius: 12px; text-align: center; }
.toast[hidden] { display: none; }
.login { max-width: 420px; margin: 24px auto; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 99px; cursor: pointer; white-space: nowrap; min-height: 40px; }
.tabs button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.status-ok { color: var(--good); } .status-dup { color: var(--muted); } .status-err { color: var(--bad); }
pre.log { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .75rem; margin: 4px 0 0; color: var(--muted); }
a.list-item { color: inherit; text-decoration: none; }
