:root {
  --bg: #f4f5f8; --panel: #ffffff; --panel-2: #f8f9fb; --line: #e3e6ec; --line-2: #eef0f4;
  --text: #1c2230; --muted: #6b7385; --faint: #9aa1b0;
  --accent: #3b5bdb; --accent-soft: #e8edfd;
  --in: #1f8a55; --in-soft: #e3f4ea; --out: #c7362f; --out-soft: #fbe9e8;
  --warn: #b7791f; --warn-soft: #fdf3e1;
  --side: #1d2433; --side-text: #c4cad6; --side-active: #2c3547;
  --shadow: 0 1px 2px rgba(20, 28, 45, .06), 0 4px 16px rgba(20, 28, 45, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --panel: #1a1f29; --panel-2: #202632; --line: #2b3240; --line-2: #242a36;
    --text: #e6e9ef; --muted: #9aa2b3; --faint: #6c7486;
    --accent: #7b93f5; --accent-soft: #263058;
    --in: #4cc38a; --in-soft: #183527; --out: #f0716a; --out-soft: #3d1f1f;
    --warn: #e2b04f; --warn-soft: #3a2f17;
    --side: #0e1117; --side-text: #aab1c0; --side-active: #1f2533;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  display: grid; grid-template-columns: 224px 1fr; min-height: 100vh;
}
.num, td.money, .kpi .v { font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
kbd { font: 11px/1 ui-monospace, Consolas, monospace; border: 1px solid #ffffff30; border-radius: 4px; padding: 1px 4px; }

/* ---------- боковое меню */
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 20px; color: #fff; font-weight: 650; font-size: 16px; }
.brand small { color: var(--side-text); font-weight: 400; font-size: 13px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: #3b5bdb; display: grid; place-items: center; font-size: 17px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); }
nav a:hover { background: var(--side-active); color: #fff; }
nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #7b93f5; }
nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
#project-switch { margin: 0 4px 14px; width: calc(100% - 8px); background: var(--side-active); color: #fff; border: 1px solid #3a4459; font-weight: 600; }
.hint { margin-top: auto; font-size: 11.5px; color: #7f889a; padding: 8px; line-height: 1.9; }

main { min-width: 0; padding: 0 28px 48px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 16px; position: sticky; top: 0; background: var(--bg); z-index: 5; flex-wrap: wrap; }
.top h1 { font-size: 21px; margin: 0; font-weight: 650; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- кнопки и поля */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.out { background: var(--out); border-color: var(--out); color: #fff; }
.btn.in { background: var(--in); border-color: var(--in); color: #fff; }
.btn.out:hover, .btn.in:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--out); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
input[type=text], input[type=date], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-width: 0; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
label.f > span { display: flex; justify-content: space-between; gap: 6px; }
.chk { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }

/* ---------- панели */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h2, .card-h { font-size: 14px; font-weight: 650; margin: 0; padding: 14px 16px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-b { padding: 0 16px 16px; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.g-2 { grid-template-columns: 1.35fr 1fr; }
.kpi { padding: 14px 16px; }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.kpi .v { font-size: 23px; font-weight: 650; margin-top: 3px; letter-spacing: -.01em; white-space: nowrap; }
.kpi .s { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.main { background: #3b5bdb; border-color: #3b5bdb; color: #fff; }
.kpi.main .l, .kpi.main .s { color: #dfe5ff; }
.pos { color: var(--in); } .neg { color: var(--out); } .muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- таблицы */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
.t td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: var(--accent-soft); }
.t th.r, .t td.r, .t td.money { text-align: right; white-space: nowrap; }
.t tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: 0; }
.t tr.draft td { color: var(--muted); font-style: italic; }
.t tr.sub td { font-weight: 650; background: var(--panel-2); }
.t .desc { color: var(--muted); font-size: 12.5px; margin-top: 1px; max-width: 520px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 20px; background: var(--line-2); color: var(--muted); vertical-align: 1px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.in { background: var(--in-soft); color: var(--in); }
.badge.out { background: var(--out-soft); color: var(--out); }
.clip { display: inline-block; font-size: 12px; color: var(--muted); margin-left: 4px; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
td.cell-link { cursor: pointer; } td.cell-link:hover { background: var(--accent-soft); }

/* ---------- фильтры */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; }
.filters select, .filters input { width: auto; }
.filters input[type=search] { flex: 1; min-width: 180px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 6px 11px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sumbar { display: flex; gap: 22px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--line-2); font-size: 13px; }
.sumbar b { font-size: 15px; }

/* ---------- графики */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 10px; align-items: center; cursor: pointer; font-size: 13px; }
.bar-row:hover .bar-name { color: var(--accent); }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 9px; background: var(--line-2); border-radius: 5px; overflow: hidden; position: relative; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar i.over { background: var(--out); }
.bar-v { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .b { fill: var(--accent); } .chart .b:hover { fill: var(--out); }
.chart .grid-l { stroke: var(--line-2); }
.acc-list { display: flex; flex-direction: column; }
.acc-list div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-2); gap: 10px; }
.acc-list div:last-child { border-bottom: 0; }

/* ---------- кошельки */
.wallets { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.wallet { padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.wallet:hover { border-color: var(--accent); }
.w-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.w-name { font-weight: 650; }
.w-bal { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.w-rows { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.w-rows div { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- вкладки */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }

/* ---------- модальные окна */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; justify-content: flex-end; z-index: 50; animation: fade .12s; }
.overlay.center { justify-content: center; align-items: flex-start; padding-top: 8vh; }
@keyframes fade { from { opacity: 0 } }
.drawer { width: min(640px, 100%); height: 100%; background: var(--panel); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide .16s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: .6 } }
.dialog { width: min(460px, calc(100% - 32px)); background: var(--panel); border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; max-height: 84vh; }
.m-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.m-head h3 { margin: 0; font-size: 17px; flex: 1; }
.m-body { padding: 18px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.m-body > * { flex-shrink: 0; }
.m-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.type-seg { display: grid; grid-template-columns: repeat(3, 1fr); }
.type-seg button { padding: 9px; }
.type-seg button.on.t-expense { background: var(--out-soft); color: var(--out); }
.type-seg button.on.t-income { background: var(--in-soft); color: var(--in); }
.amount-in { font-size: 22px !important; font-weight: 650; padding: 8px 12px !important; font-variant-numeric: tabular-nums; }
.calc { font-size: 12px; color: var(--muted); min-height: 16px; }
.date-q { display: flex; gap: 10px; font-size: 12px; font-weight: 400; }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: 1.4fr 130px 1fr 28px; gap: 8px; align-items: center; }
.line input.amt { text-align: right; }
.lines-total { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding-top: 4px; }
.drop { border: 1.5px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; font-size: 13px; }
.drop.hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; font-size: 13px; }
.file a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.hist summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.hist ul { margin: 8px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.err { background: var(--out-soft); color: var(--out); padding: 9px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- уведомления */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 9px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13.5px; animation: fade .15s; max-width: 380px; }
.toast.error { background: var(--out); }

/* ---------- вход и пользователь */
.login-wrap { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card .btn { padding: 10px; }
.login-brand { display: flex; align-items: center; gap: 9px; font-size: 16px; margin-bottom: 4px; }
.login-brand .logo { color: #fff; }
.who { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px 0; margin-top: auto; color: #fff; font-size: 13px; }
.who .btn { color: var(--side-text); border-color: #3a4457; }
.who + .hint { margin-top: 0; }

/* ---------- телефон */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; padding: 4px; z-index: 30; flex-direction: row; }
  .brand, .hint, .who { display: none; }
  #project-switch { position: fixed; top: 10px; right: 16px; width: auto; margin: 0; z-index: 40; background: var(--panel); color: var(--text); border-color: var(--line); }
  nav { flex-direction: row; width: 100%; justify-content: space-around; }
  nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; }
  nav a.active { box-shadow: none; }
  main { padding: 0 16px 90px; }
  .g-2 { grid-template-columns: 1fr; }
  .quick .btn { padding: 7px 10px; }
  .two { grid-template-columns: 1fr; }
  .line { grid-template-columns: 1fr 110px 28px; }
  .line .lc { display: none; }
  .kpi .v { font-size: 20px; }
}
