:root {
  --bg: #F4F5F7; --surface: #FFFFFF; --surface-2: #F0F2F5; --text: #111315; --muted: #6B727B;
  --line: #E1E4E8; --primary: #111315; --on-primary: #FFFFFF; --accent: #4D90CD;
  --ok: #4E8A00; --ok-bg: #EAF5D3; --bad: #E4002B; --bad-bg: #FDE6EA; --info: #1F6FB2; --info-bg: #E3EFF9;
  --warn-bg: #FFF3CC; --radius: 14px; --shadow: 0 1px 2px rgba(17,19,21,.06), 0 4px 14px rgba(17,19,21,.05);
  --sab: env(safe-area-inset-bottom, 0px); --sat: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0C0D0F; --surface: #17191C; --surface-2: #202327; --text: #F2F4F6; --muted: #98A0A9;
    --line: #2A2E33; --primary: #4D90CD; --on-primary: #0C0D0F; --ok: #97D700; --ok-bg: #26340A;
    --bad: #FF5A75; --bad-bg: #3A1119; --info: #7DB8EA; --info-bg: #14283A; --warn-bg: #3A2F08; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
h1 { font-size: 1.5rem; margin: 0; } h2 { font-size: 1.05rem; margin: 0; }
a { color: var(--info); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .pos { color: var(--ok); }
[hidden] { display: none !important; }

/* каркас */
.shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: #111315; color: #E8EAED; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 4px 8px 20px; font-weight: 700; line-height: 1.15; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #4D90CD, #B580D1); display: grid; place-items: center; font-weight: 800; color: #fff; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: #B7BDC4; font-weight: 500; }
.nav-item:hover { background: #1D2024; color: #fff; text-decoration: none; }
.nav-item.is-on { background: #26292E; color: #fff; box-shadow: inset 3px 0 0 #97D700; }
.sidebar-spacer { flex: 1; }
.who { display: flex; gap: 10px; align-items: center; padding: 10px 8px; color: #fff; border-top: 1px solid #26292E; }
.who small { display: block; color: #8B929A; } .who:hover { text-decoration: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #B580D1; display: grid; place-items: center; font-weight: 700; color: #fff; }
.content { padding: 28px clamp(16px, 4vw, 40px) 40px; max-width: 1100px; width: 100%; }
.tabbar, .fab { display: none; }

/* элементы */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .back { flex-basis: 100%; color: var(--muted); }
.actions, .actions-wrap, .form-actions, .filter-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions-wrap form { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head form { margin: 0; }
.notice { border-color: var(--accent); background: var(--info-bg); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack-col > .card:last-child { margin-bottom: 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.15); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { min-height: 34px; padding: 6px 12px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; color: var(--info); font: inherit; cursor: pointer; padding: 6px 4px; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge-ok { background: var(--ok-bg); color: var(--ok); } .badge-bad { background: var(--bad-bg); color: var(--bad); } .badge-info { background: var(--info-bg); color: var(--info); }
.chip { display: inline-block; font-size: .8rem; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.14); }
.chip-ok { background: #97D70033; } .chip-bad { background: #E4002B44; }
.tag { color: var(--info); }

/* формы */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=color] { padding: 4px; max-width: 80px; }
.field.big input { font-size: 1.8rem; font-weight: 700; padding: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; }
.segmented { display: grid; grid-auto-flow: column; gap: 4px; background: var(--surface-2); padding: 4px; border: 0; border-radius: 12px; margin: 0; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span { display: block; text-align: center; padding: 9px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); }
.segmented-links { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented-links a { padding: 7px 14px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.segmented-links a.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.only-transfer, .only-income { display: none; }
form[data-type=transfer] .only-transfer { display: grid; }
form[data-type=transfer] .only-expense, form[data-type=income] .only-expense { display: none; }
form[data-type=income] .only-income { display: grid; }
form[data-type=transfer] .only-income { display: none; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.filters summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; align-items: end; }
.copy-field { font-family: ui-monospace, monospace; font-size: .85rem; }

/* списки операций */
.op-list { display: flex; flex-direction: column; }
.day-head { padding: 10px 16px 6px; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
.op { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); border-bottom: 1px solid var(--line); }
.op:last-child { border-bottom: 0; } .op:hover { background: var(--surface-2); text-decoration: none; }
.card:not(.flush) > .op-list .op { padding-left: 4px; padding-right: 4px; }
.dot { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 700; }
.op-main { flex: 1; min-width: 0; display: grid; }
.op-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-sub { color: var(--muted); font-size: .82rem; }
.op-amount { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amount-income { color: var(--ok); } .amount-transfer { color: var(--muted); }
.op.is-cancelled .op-title, .op.is-cancelled .op-amount, .detail.is-cancelled .detail-amount { text-decoration: line-through; opacity: .55; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 12px 0; }
.undo { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--warn-bg); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.undo form { margin: 0; }

/* главная и статистика */
.hero-card { background: linear-gradient(135deg, #111315, #23272C); color: #fff; border-radius: 18px; padding: 22px; margin-bottom: 16px; }
.hero-main { display: grid; gap: 6px; justify-items: start; }
.hero-label { color: #AEB5BC; font-size: .9rem; }
.hero-value { font-size: clamp(1.9rem, 6vw, 2.6rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.hero-stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 16px; }
.hero-stats small { display: block; color: #AEB5BC; } .hero-stats b { font-size: 1.1rem; }
.hero-card .pos { color: #97D700; }
.stack { display: flex; height: 10px; border-radius: 6px; overflow: hidden; margin-top: 16px; background: #2f343a; }
.legend, .rows, .bars { list-style: none; margin: 0; padding: 0; }
.legend li, .rows li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.legend li:last-child, .rows li:last-child { border-bottom: 0; }
.legend i, .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 8px; }
.rows li > span:first-child { display: grid; min-width: 0; } .row-end { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.rows form { margin: 0; } .rows li.is-archived { opacity: .6; }
.bars li { padding: 8px 0; } .bar-top { display: flex; justify-content: space-between; margin-bottom: 4px; gap: 8px; }
.bar-top i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; } .bar span { display: block; height: 100%; border-radius: 4px; }
.month-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 12px; font-size: 1.1rem; }
.columns { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; height: 190px; align-items: end; }
.col { min-width: 0; display: flex; flex-direction: column; height: 100%; justify-content: flex-end; text-align: center; color: var(--muted); }
.col:hover { text-decoration: none; background: var(--surface-2); border-radius: 8px; }
.col-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; flex: 1; }
.b-exp, .b-inc { width: 42%; min-height: 2px; border-radius: 4px 4px 0 0; } .b-exp { background: #4D90CD; } .b-inc { background: #97D700; }
.legend-inline { font-size: .8rem; color: var(--muted); } .legend-inline i, .k-exp, .k-inc { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 8px; }
.k-exp { background: #4D90CD; } .k-inc { background: #97D700; }

/* карточка операции */
.detail-amount { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; } .detail-title { font-size: 1.1rem; margin-bottom: 12px; }
.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; } .props dt { color: var(--muted); } .props dd { margin: 0; }
.split-total { display: flex; justify-content: space-between; align-items: center; } .split-total small { display: block; }
.split-sum { font-size: 1.6rem; font-weight: 800; }
.split-row { display: grid; grid-template-columns: 1fr 140px; gap: 10px; margin-bottom: 10px; }
.split-rest { font-weight: 600; } .split-rest.is-ok { color: var(--ok); } .split-rest.is-bad { color: var(--bad); }

/* вход, ошибки */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.auth-card form { display: grid; gap: 14px; }
.brand-big { display: flex; align-items: center; gap: 12px; } .error-card { text-align: center; } .error-code { font-size: 3rem; font-weight: 800; margin: 0; }
.flashes { display: grid; gap: 8px; margin-bottom: 14px; }
.flash { padding: 12px 14px; border-radius: 12px; background: var(--info-bg); color: var(--info); font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok); } .flash-error { background: var(--bad-bg); color: var(--bad); }
.offline-banner { background: var(--warn-bg); padding: 10px 14px; border-radius: 12px; margin-bottom: 14px; }

/* мобильные */
@media (max-width: 860px) {
  .shell { display: block; } .sidebar { display: none; }
  .content { padding: calc(16px + var(--sat)) 16px calc(96px + var(--sab)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--sab)); }
  .tabbar .nav-item { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 2px; color: var(--muted); border-radius: 10px; }
  .tabbar .nav-item:hover { background: none; color: var(--muted); } .tabbar .nav-item.is-on { background: none; color: var(--text); box-shadow: none; font-weight: 700; }
  .fab { display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(76px + var(--sab)); width: 56px; height: 56px; border-radius: 50%;
    background: #97D700; color: #111315; box-shadow: 0 6px 18px rgba(0,0,0,.28); z-index: 21; }
  .fab:hover { text-decoration: none; }
  .row-2 { grid-template-columns: 1fr; }
  .row-2.keep, .split-row { grid-template-columns: 1fr 120px; }
  .page-head h1 { font-size: 1.3rem; } .props { grid-template-columns: 1fr; gap: 2px; } .props dd { margin-bottom: 8px; }
}
@media (max-width: 860px) { .row-2 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .row-2 { grid-template-columns: 1fr; } .columns { gap: 3px; } }
@media (prefers-reduced-motion: no-preference) { .btn, .op { transition: background .15s; } }
@media print { .sidebar, .tabbar, .fab, .actions { display: none; } .shell { display: block; } }
.legend li > span, .legend li > a { flex: 1; text-align: left; min-width: 0; }
.legend li > i { flex: none; margin-right: 0; }
@media (max-width: 860px) { .filter-grid { grid-template-columns: 1fr 1fr; } .filter-grid .field:first-child, .filter-actions { grid-column: 1 / -1; } }
.filter-grid > *, .field { min-width: 0; }

/* строка категории в статистике — ссылка на список трат */
.bar-link { display: block; color: inherit; text-decoration: none; border-radius: 8px; margin: -4px -6px; padding: 4px 6px; }
.bar-link:hover, .bar-link:focus-visible { background: rgba(77, 144, 205, .08); }
.bar-link .chev { color: #9AA1AA; margin-left: 2px; font-weight: 400; }

/* самые узкие экраны (iPhone SE и т. п.): ничего не должно вылезать за край */
.field input, .field select, .field textarea { min-width: 0; max-width: 100%; }
@media (max-width: 360px) { .filter-grid { grid-template-columns: 1fr; } }
@media (max-width: 360px) { .col small { font-size: .62rem; letter-spacing: -.03em; } .columns { gap: 2px; } }

.qr{width:220px;max-width:100%;margin:12px auto}.qr svg{width:100%;height:auto;display:block;border-radius:8px}
.secret{font-size:1.05rem;letter-spacing:.06em;word-break:break-all}
.codes{list-style:none;padding:0;display:grid;grid-template-columns:1fr 1fr;gap:8px}.codes code{font-size:1.1rem}
.steps{padding-left:1.2rem}

.bar span.lim-ok{background:#2E9E6B}.bar span.lim-warn{background:#E0A100}.bar span.lim-bad{background:#D64545}
.neg{color:#D64545}

/* индикатор ожидания */
#nav-progress{position:fixed;top:0;left:0;height:3px;width:0;background:var(--primary);z-index:9999;opacity:0;pointer-events:none;transition:opacity .15s}
#nav-progress.on{opacity:1;width:92%;transition:width 8s cubic-bezier(.1,.7,.2,1),opacity .15s}
.is-loading{position:relative;pointer-events:none;opacity:.85}
.is-loading::after{content:"";display:inline-block;width:1em;height:1em;margin-left:8px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:spin .7s linear infinite;vertical-align:-.15em}
.is-submitting button,.is-submitting [type=submit]{pointer-events:none}
@keyframes spin{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){.is-loading::after{animation-duration:2s}}

/* строки категорий: название переносится, сумма и процент всегда в одну строку справа */
.bar-top { align-items: baseline; }
.bar-top > span:first-child { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.bar-top > b { flex: 0 0 auto; white-space: nowrap; text-align: right; }
.bar-top > b small { font-weight: 500; opacity: .75; }
.bar-top i { vertical-align: baseline; }
