:root {
  color-scheme: light;
  --page: #f6f6f3; --surface: #ffffff; --surface-2: #f1f0ec; --border: rgba(11,11,11,.10);
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e6f0fc;
  --in: #2a78d6; --out: #eb6834; --good: #006300; --bad: #b42a2a; --hold: #8a6a00;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --border: rgba(255,255,255,.10);
    --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #17283d;
    --in: #3987e5; --out: #d95926; --good: #0ca30c; --bad: #e66767; --hold: #c98500;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --border: rgba(255,255,255,.10);
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #17283d;
  --in: #3987e5; --out: #d95926; --good: #0ca30c; --bad: #e66767; --hold: #c98500;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); } .t2 { color: var(--text-2); } .small { font-size: 13px; }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand i { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: #fff; font-style: normal; }
.nav { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 0; background: none; cursor: pointer; text-align: left; color: var(--text-2); width: 100%; }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav:hover { background: var(--surface-2); }
.nav.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .who { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.main { padding: 24px 28px 96px; max-width: 1180px; width: 100%; margin: 0 auto; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.bottom { display: none; }
.fab { position: fixed; right: 24px; bottom: 24px; display: flex; gap: 8px; z-index: 5; }
.fab button { height: 50px; padding: 0 20px; border-radius: 25px; border: 0; color: #fff; font-weight: 600; font-size: 15px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.22); }
.fab .in { background: var(--in); } .fab .out { background: var(--out); }
.seg.dir { display: flex; } .seg.dir button { flex: 1; padding: 9px 8px; }
.seg.dir.in button.on { background: var(--in); color: #fff; } .seg.dir.out button.on { background: var(--out); color: #fff; }
.inp.dd { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; text-align: left; }
.inp.dd span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .inp.dd i { font-style: normal; color: var(--muted); }
.inp.dd.open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); } .inp.dd:disabled { opacity: .55; cursor: default; }
.ddlist { margin-top: -6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); max-height: 264px; overflow-y: auto; padding: 4px; display: grid; }
.ddlist button { border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.ddlist button:hover { background: var(--surface-2); } .ddlist button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.tag.wait { background: color-mix(in srgb, #fab219 28%, transparent); color: var(--text); }
h2 .tag { font-weight: 500; margin-left: 6px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g2 { grid-template-columns: repeat(2, 1fr); }
.stack { display: grid; gap: 14px; }
.tile .lbl { color: var(--text-2); font-size: 13px; }
.tile .val { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.hero { background: var(--accent); color: #fff; border-color: transparent; }
.tile.hero .lbl, .tile.hero .sub { color: rgba(255,255,255,.82); }
.tile.hero .val { font-size: clamp(22px, 2.6vw, 32px); }
.tile .val { font-size: clamp(18px, 2.1vw, 26px); }

/* controls */
.btn { height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.inp, select.inp, textarea.inp { width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); outline: none; }
textarea.inp { height: auto; padding: 10px 12px; resize: vertical; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.fld { display: grid; gap: 6px; } .fld > span { font-size: 13px; color: var(--text-2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.chip:hover, .chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .inp { width: auto; }

/* lists */
.day { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 14px 4px 6px; display: flex; justify-content: space-between; }
.op { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 6px; border-top: 1px solid var(--border); cursor: pointer; border-radius: 8px; }
.op:hover { background: var(--surface-2); }
.op .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.op.in .ic { background: var(--accent-soft); color: var(--in); }
.op.out .ic { background: color-mix(in srgb, var(--out) 14%, transparent); color: var(--out); }
.op .ttl { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .meta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .amt { text-align: right; font-weight: 600; }
.op .amt small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.op.del { opacity: .45; text-decoration: line-through; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 550; color: var(--text-2); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr.grp td { font-weight: 600; background: var(--surface-2); cursor: pointer; }
.scroll-x { overflow-x: auto; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* charts */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 32%) 1fr auto; gap: 10px; align-items: center; padding: 6px 4px; font-size: 14px; border-radius: 8px; }
.hbar.click { cursor: pointer; } .hbar.click:hover { background: var(--surface-2); }
.hbar .track { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--out); min-width: 2px; }
.hbar .fill.in { background: var(--in); }
.hbar .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip { position: fixed; z-index: 50; background: var(--text); color: var(--page); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; pointer-events: none; box-shadow: var(--shadow); max-width: 260px; }
.tip b { display: block; margin-bottom: 2px; }

/* dialog, toast, auth */
dialog { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 24px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.dlg-b { padding: 12px 20px 20px; display: grid; gap: 14px; }
.dlg-f { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.amount { font-size: 28px; font-weight: 650; height: 56px; text-align: right; padding-right: 44px; }
.amtwrap { position: relative; } .amtwrap span { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 24px; font-weight: 600; color: var(--muted); pointer-events: none; }
input[type="date"].inp { min-width: 150px; }
.hist { font-size: 12.5px; color: var(--text-2); border-top: 1px dashed var(--border); padding-top: 10px; display: grid; gap: 4px; }
#toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); background: var(--text); color: var(--page); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; }
#toast.on { opacity: 1; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); display: grid; gap: 14px; padding: 26px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.note { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--text-2); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 16px 16px 150px; }
  .g4, .g3 { grid-template-columns: repeat(2, 1fr); } .g2 { grid-template-columns: 1fr; }
  .tile.hero { grid-column: 1 / -1; }
  .bottom { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 6; }
  .bottom .nav { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 2px; justify-content: center; text-align: center; }
  .fab { right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .tile .val { font-size: 21px; } .tile.hero .val { font-size: 30px; }
  .card { padding: 14px; }
  .chart { overflow-x: auto; } .chart svg { min-width: 620px; }
}
@media print { .side, .bottom, .fab, .filters { display: none !important; } .shell { display: block; } }

.chk .op { border-top: 0; padding-top: 0; }
.chk .why { font-size: 13px; color: var(--text-2); padding: 4px 6px; }
.chk .why .tag { margin-right: 4px; }

.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--surface-2); }
.tbl tr.grp td { font-size: 13px; }

.gfit { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
@media (max-width: 860px) { .gfit { grid-template-columns: 1fr; } }
