:root {
  --bg: #f4f2ee; --card: #ffffff; --text: #1c1b19; --muted: #6b6760; --line: #e4e0d8;
  --accent: #1f6f5c; --accent-ink: #fff; --pos: #1f7a4d; --neg: #b4411b; --danger: #b42318;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --card: #1f1f1d; --text: #ecebe7; --muted: #9c988f; --line: #33322e;
    --accent: #3fa587; --accent-ink: #0d1512; --pos: #4cc38a; --neg: #f07b52; --danger: #f97066;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.spacer { flex: 1; }
h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.narrow { max-width: 440px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label select { margin-top: 4px; }
input, select { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { width: 44px; padding: 3px; height: 40px; flex: none; }
.btn { font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.income { background: var(--pos); color: #fff; border-color: transparent; }
.btn.expense { background: var(--neg); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.icon { width: 38px; padding: 8px 0; font-size: 18px; line-height: 1; }
.btn.wide { width: 100%; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.error { color: var(--danger); min-height: 1em; margin: 0 0 8px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.hint:empty { display: none; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 17px; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 600 19px Georgia, serif; }
.brand.big { margin-bottom: 20px; } .brand.big .logo { width: 44px; height: 44px; font-size: 24px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 24px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-left: auto; }
.tabs button { font: inherit; background: none; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
main { max-width: 1080px; margin: 0 auto; padding: 16px; }

.monthbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.monthbar input[type=month] { width: auto; background: var(--card); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 4px; }
.stat small { color: var(--muted); display: block; font-size: 13px; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; display: block; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 16px; }

.bars .row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; margin-bottom: 10px; font-size: 14px; }
.bars .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bars .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .val { font-variant-numeric: tabular-nums; text-align: right; }
.bars .val small { color: var(--muted); margin-left: 6px; }
.bars .track { grid-column: 1 / -1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 3px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.legend { font-weight: 400; font-size: 12px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 6px; }
.pos-bg { background: var(--pos); } .neg-bg { background: var(--neg); }
.year { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 180px; }
.year .m { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; cursor: pointer; border-radius: 6px; padding-top: 4px; }
.year .m.cur { background: var(--bg); }
.year .pair { display: flex; gap: 2px; align-items: flex-end; flex: 1; width: 100%; justify-content: center; }
.year .b { width: 40%; max-width: 16px; border-radius: 3px 3px 0 0; min-height: 1px; }
.year .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; flex: 1 1 160px; }
.txlist .day { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 14px 0 4px; display: flex; justify-content: space-between; }
.txlist .day:first-child { margin-top: 0; }
.tx { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; }
.tx:hover { background: var(--bg); }
.tx .info { flex: 1; min-width: 0; }
.tx .info b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .info small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.catform { display: flex; gap: 8px; margin-bottom: 12px; }
.catform input:not([type=color]) { flex: 1; min-width: 0; }
.cat { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.cat input[type=color] { width: 30px; height: 30px; padding: 2px; }
.cat .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .cnt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cat.arch .nm { color: var(--muted); text-decoration: line-through; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--card); color: var(--text); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 9px; padding: 3px; margin-bottom: 14px; }
.seg button { font: inherit; border: 0; background: none; color: var(--muted); padding: 7px; border-radius: 7px; cursor: pointer; }
.seg button.on[data-k=expense] { background: var(--neg); color: #fff; }
.seg button.on[data-k=income] { background: var(--pos); color: #fff; }
.dlg-actions { display: flex; gap: 8px; margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; transition: transform .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .stat b { font-size: 18px; }
  .tabs { margin-left: 0; width: 100%; }
  .monthbar .spacer { display: none; }
  .monthbar [data-add] { flex: 1; }
  .year { height: 140px; gap: 2px; }
}
.feed { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; margin-bottom: 12px; font-size: 14px; }
.feed b { grid-column: 1 / -1; font-weight: 500; }
.feed code { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; overflow-x: auto; white-space: nowrap; min-width: 0; }
.hint code { font-size: 12px; }
