/* Бюджет. Сначала телефон, ниже — правки для компьютера (≥ 761px). */
:root {
  --bg: #f2f3f5; --surface: #fff; --surface-2: #f4f5f7; --hover: #eef0f3; --seg-on: #fff;
  --text: #15171b; --text-2: #3d434d; --muted: #6b7280; --faint: #a0a6ae;
  --line: #eceef1; --border: #dfe2e6;
  --accent: #2563eb; --accent-soft: #e9f0ff; --accent-text: #1d4ed8;
  --bad: #dc2626; --bad-soft: #fdeeee; --warn: #b45309; --warn-soft: #fff4e5; --ok: #15803d; --ok-soft: #e7f7ee;
  --c-inc: #1baf7a; --c-exp: #2a78d6; --grid: #e9e8e2; --axis: #c3c2b7; --heat: 42, 120, 214;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1b1e24; --surface-2: #23272e; --hover: #262a32; --seg-on: #343a44;
    --text: #eceef1; --text-2: #c3c8d0; --muted: #959ca7; --faint: #69707b;
    --line: #272b32; --border: #363b45;
    --accent: #3b82f6; --accent-soft: #1b2a46; --accent-text: #8fb4ff;
    --bad: #f87171; --bad-soft: #2c1718; --warn: #f0b35b; --warn-soft: #2b2212; --ok: #4ade80; --ok-soft: #13261b;
    --c-inc: #199e70; --c-exp: #3987e5; --grid: #262830; --axis: #3a3c42; --heat: 57, 135, 229;
    --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 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); text-decoration: none; }
p a, .hint a, .note-card a { text-decoration: underline; text-underline-offset: 2px; }
h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.015em; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
[id] { scroll-margin-top: 16px; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -4px; }
.num, td, .op-amt, b { font-variant-numeric: tabular-nums; }
.xs { font-size: 13px; color: var(--muted); margin: 0; }
.muted { color: var(--muted); }
.bad { color: var(--bad); } .good { color: var(--ok); } .warn { color: var(--warn); } .income { color: var(--ok); }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

/* ---------- каркас и вкладки ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 14px 14px calc(92px + env(safe-area-inset-bottom)); }
.top .brand { display: none; }
.tabs { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; font-size: 12px; font-weight: 500; color: var(--muted); border-radius: 10px; }
.tabs a .ico { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent-text); }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand .ico { color: var(--ok); width: 24px; height: 24px; }

.page-head { display: flex; align-items: center; gap: 4px; margin: 6px 0 14px; min-height: 40px; }
.page-head .btn-icon { margin-left: -8px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 2px -6px 12px; }
.month-nav h1 { font-size: 20px; text-align: center; }
.back-link { display: inline-flex; align-items: center; gap: 2px; font-size: 15px; margin: 2px 0 0 -6px; }

.card { background: var(--surface); border-radius: 18px; padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); min-width: 0; }
.sec-title { font-size: 15px; font-weight: 600; color: var(--text-2); margin: 22px 4px 8px; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 8px; }
.sec-head .sec-title { margin: 0; }
.sec-head a { font-size: 15px; }
.sub-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 4px 6px; }
.hint { font-size: 14px; color: var(--muted); margin: 0 4px 14px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; margin: 0; }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 14px; margin-bottom: 12px; font-size: 15px; }
.toast.ok { background: var(--ok-soft); color: var(--ok); }
.toast.bad { background: var(--bad-soft); color: var(--bad); }
.toast form { margin: 0; }
.err { color: var(--bad); margin: 0; font-size: 14px; }
.tag { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); margin-right: 6px; line-height: 18px; vertical-align: 1px; }

/* ---------- кнопки и поля ---------- */
button, .btn { font: inherit; font-size: 15px; font-weight: 500; border: 0; background: var(--surface-2); color: var(--text); padding: 10px 16px; border-radius: 12px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:hover, .btn:hover { background: var(--hover); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(.94); background: var(--accent); }
button.big { width: 100%; min-height: 52px; font-size: 17px; font-weight: 600; border-radius: 14px; }
button.ghost { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border); }
button.ghost:hover { background: var(--hover); }
.btn-sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn-link { background: none; padding: 0; color: var(--accent-text); font-weight: 500; border-radius: 0; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-danger, button.btn-danger { color: var(--bad); }
.btn-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--text-2); flex: none; }
.btn-icon:hover { background: var(--hover); }
.btn-icon.ghost { visibility: hidden; }
.wide { width: 100%; }
input, select { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-height: 46px; min-width: 0; width: 100%; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--accent); flex: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; min-width: 0; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text-2); cursor: pointer; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions button { flex: 1 1 auto; }
.edit-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- главная: итог месяца ---------- */
.msum { display: block; color: var(--text); }
.msum-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.msum-label { display: block; font-size: 13px; color: var(--muted); }
.msum-big { display: block; font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; white-space: nowrap; }
.msum-right { text-align: right; }
.msum-right b { font-size: 17px; white-space: nowrap; }
.progress { display: block; height: 8px; background: var(--surface-2); border-radius: 99px; margin: 12px 0 8px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress.over i { background: var(--bad); }
.msum-foot { display: block; font-size: 13px; color: var(--muted); }
.msum-warn { display: block; font-size: 13px; color: var(--warn); margin-top: 4px; }

/* ---------- главная: ввод ---------- */
.add { display: flex; flex-direction: column; gap: 14px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 9px; font-size: 15px; font-weight: 500; color: var(--muted); cursor: pointer; user-select: none; }
.seg input:checked + span { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.amount { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--line); cursor: text; }
.amount:focus-within { border-color: var(--accent); }
.amount input { border: 0; background: none; font-size: 40px; font-weight: 700; padding: 0; min-height: 0; letter-spacing: -.02em; outline: none; border-radius: 0; }
.amount input::placeholder { color: var(--faint); }
.amount .cur { font-size: 26px; color: var(--faint); font-weight: 600; }
.calc { font-size: 14px; color: var(--muted); margin-top: -8px; }
.calc:empty { display: none; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { position: relative; min-width: 0; }
.tile input { position: absolute; opacity: 0; pointer-events: none; }
.tile span { display: flex; align-items: center; gap: 8px; min-height: 50px; height: 100%; padding: 8px 10px; border-radius: 12px; background: var(--surface-2);
  border: 1.5px solid transparent; font-size: 14px; line-height: 1.2; color: var(--text); cursor: pointer; user-select: none; overflow-wrap: anywhere; }
.tile i { font-style: normal; font-size: 20px; line-height: 1; flex: none; }
.tile span:hover { background: var(--hover); }
.tile input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.tile input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.more-cats { margin-top: 8px; }
.more-cats > summary { display: inline-block; font-size: 15px; font-weight: 500; color: var(--accent-text); padding: 6px 2px; }
.more-cats > summary::after { content: " ▾"; }
.more-cats[open] > summary::after { content: " ▴"; }
.more-cats .tiles { margin-top: 6px; }
.add .cats, .add .transfer-to { display: none; }
.add:has(input[name=kind][value=expense]:checked) .cats[data-kind=expense],
.add:has(input[name=kind][value=income]:checked) .cats[data-kind=income] { display: block; }
.add:has(input[name=kind][value=transfer]:checked) .transfer-to { display: flex; }
.opts > summary { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-2); padding: 2px 0; }
.opts > summary .ico { color: var(--muted); }
.opts > summary em { font-style: normal; color: var(--accent-text); font-size: 14px; }
.opts[open] > summary em { display: none; }
.opts-body { display: grid; gap: 12px; margin-top: 12px; }

/* ---------- строки списков ---------- */
.list { padding: 4px 0; overflow: hidden; }
.op, .pend, .plan-row, .row-edit > summary { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; column-gap: 12px; align-items: center; padding: 10px 16px; color: var(--text); }
.list > * + *, .list > details + details { border-top: 1px solid var(--line); }
a.op:hover, .row-edit > summary:hover, label.op:hover { background: var(--hover); }
.op-ico { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; line-height: 1; color: var(--muted); }
.op-main { display: flex; flex-direction: column; min-width: 0; }
.op-main b { font-weight: 550; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-sub.bad { color: var(--bad); }
.op-amt { font-weight: 600; font-size: 15px; white-space: nowrap; text-align: right; }
.op form { margin: 0; }
.pend-act { grid-column: 2 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.pend-act form { margin: 0; }
.list-total { display: flex; justify-content: space-between; gap: 10px; padding: 12px 16px; font-size: 14px; color: var(--muted); }
.row-edit.off .op-main b { color: var(--faint); }
.row-edit.add .op-main b, .row-edit.add .op-ico { color: var(--accent-text); }
.row-edit[open] > summary { background: var(--surface-2); }
.row-edit > form { padding: 14px 16px 16px; }
.add-new > summary { display: flex; align-items: center; gap: 8px; color: var(--accent-text); font-weight: 500; }
.add-new[open] > summary { margin-bottom: 14px; }

/* ---------- история ---------- */
.search { margin-bottom: 4px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 14px; padding: 0 14px; box-shadow: var(--shadow); color: var(--muted); }
.search-box:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.search-box input { border: 0; background: none; padding: 0; outline: none; flex: 1; }
.filters > summary { display: inline-block; font-size: 14px; font-weight: 500; color: var(--accent-text); padding: 10px 4px 4px; }
.filters-body { display: grid; gap: 10px; margin: 8px 0 4px; }
.filters-act { display: flex; align-items: center; gap: 16px; }
.summary { font-size: 14px; color: var(--muted); margin: 8px 4px 0; }
.summary b { color: var(--text); }
.summary b.income { color: var(--ok); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 18px 4px 8px; }
.day-head h2 { font-size: 14px; font-weight: 600; color: var(--text-2); }
.day-head span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- итоги ---------- */
.flow-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 15px; }
.flow-row span { color: var(--text-2); }
.flow-row b { font-weight: 600; white-space: nowrap; }
.flow-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; align-items: baseline; }
.flow-row.total span { font-weight: 600; color: var(--text); font-size: 17px; }
.flow-row.total b { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.flow-note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.bars { padding: 4px 16px; }
.bar { display: block; padding: 11px 0; color: var(--text); }
.bar + .bar { border-top: 1px solid var(--line); }
.bar:hover .bar-name { color: var(--accent-text); }
.bar-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bar-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-name i { font-style: normal; font-size: 17px; }
.bar-top b { font-weight: 600; white-space: nowrap; }
.bar-track { display: block; height: 6px; background: var(--surface-2); border-radius: 99px; margin: 8px 0 6px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--c-exp); border-radius: 99px; }
.bar-track i.over { background: var(--bad); }
.bar-sub { display: block; font-size: 13px; color: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.sw.inc { background: var(--c-inc); } .sw.exp { background: var(--c-exp); }
.fold > summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; color: var(--text-2); }
.fold > summary::after { content: "▾"; color: var(--muted); }
.fold[open] > summary { margin-bottom: 12px; }
.fold[open] > summary::after { content: "▴"; }
.fold > .xs { margin-top: 10px; }

/* таблицы — только в «Подробно» */
.table-wrap { overflow-x: auto; margin: 0 -6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child { text-align: left; }
td { padding: 6px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
td:first-child { text-align: left; white-space: normal; min-width: 120px; }
td a { color: var(--text-2); }
tr.section td { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 7px 6px; }
.pnl tr.group td { font-weight: 600; }
.pnl tr.cat td:first-child { padding-left: 14px; }
.pnl tr.total td { font-weight: 650; }
.pnl tr.grand td { font-weight: 700; background: var(--accent-soft); }
.dyn td.heat { background: rgba(var(--heat), calc(var(--a) * .28)); }
.dyn td.cur { box-shadow: inset 0 0 0 1px var(--border); }

/* графики */
.chart { width: 100%; height: auto; display: block; }
.chart-wide { display: none; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .val { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .val.pos { fill: var(--ok); } .chart .val.neg { fill: var(--bad); }
.chart .bar-inc { fill: var(--c-inc); } .chart .bar-exp { fill: var(--c-exp); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--text); fill-opacity: .04; }

/* ---------- «Ещё» ---------- */
.menu { padding: 4px 0; overflow: hidden; }
.menu > a, .menu > form > button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; color: var(--text); font-size: 16px; font-weight: 400;
  background: none; border-radius: 0; justify-content: flex-start; }
.menu > * + * { border-top: 1px solid var(--line); }
.menu > form { margin: 0; }
.menu > a:hover, .menu > form > button:hover { background: var(--hover); }
.menu > a > .ico:first-child, .menu > form > button > .ico { color: var(--muted); }
.menu > a > span, .menu > form > button > span { flex: 1; text-align: left; }
.menu em { font-style: normal; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.menu em.warn { color: var(--warn); }
.menu > a > .ico:last-child { color: var(--faint); width: 18px; height: 18px; }
.menu-total { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; font-size: 14px; color: var(--muted); }
.menu-total b { color: var(--text); white-space: nowrap; }

/* ---------- план ---------- */
.plan-sum { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.plan-sum div { display: flex; flex-direction: column; justify-content: space-between; gap: 2px; min-width: 0; }
.plan-sum span { font-size: 12.5px; color: var(--muted); line-height: 1.25; }
.plan-sum b { font-size: 17px; font-weight: 650; white-space: nowrap; }
.plan-sum b.neg { color: var(--bad); }
.plan-row .op-main b { white-space: normal; line-height: 1.25; }
.plan-row .op-main .btn-link { font-size: 13px; text-align: left; font-weight: 400; justify-content: flex-start; white-space: normal; margin-top: 2px; }
.plan-in { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.plan-in input { width: 108px; text-align: right; padding: 8px 10px; min-height: 42px; }
.plan-in em { font-style: normal; font-size: 12px; color: var(--muted); min-height: 15px; }
.sticky-act { position: sticky; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 5; padding-top: 4px; }
.sticky-act button { box-shadow: 0 4px 16px rgba(37, 99, 235, .25); }

/* ---------- мне должны, запись ---------- */
.owed-row { cursor: pointer; }
.owed-row input[type=checkbox] { justify-self: center; width: 22px; height: 22px; }
.owed-act { display: flex; flex-direction: column; gap: 12px; }
.owed-sel { margin: 0; font-size: 15px; }
.note-card { font-size: 14px; color: var(--text-2); }
.edit-form:has(input[name=kind][value=transfer]:checked) .not-transfer { display: none; }
.edit-form:not(:has(input[name=kind][value=transfer]:checked)) .only-transfer { display: none; }
.danger-zone { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 18px 0 8px; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { justify-content: center; font-size: 19px; margin-bottom: 4px; }

/* ---------- компьютер ---------- */
@media (min-width: 761px) {
  .top { max-width: 640px; margin: 0 auto; padding: 16px 14px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .top .brand { display: inline-flex; }
  .tabs { position: static; display: flex; gap: 4px; background: none; border: 0; padding: 0; }
  .tabs a { flex-direction: row; gap: 6px; padding: 8px 12px; font-size: 15px; color: var(--text-2); }
  .tabs a .ico { width: 19px; height: 19px; }
  .tabs a:hover { background: var(--hover); }
  .tabs a.active { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow); }
  .wrap { padding: 18px 14px 56px; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-wide { display: block; }
  .chart-narrow { display: none; }
  .sticky-act { bottom: 12px; }
}
@media (max-width: 380px) {
  .amount input { font-size: 34px; }
  .msum-big { font-size: 24px; }
  .op-ico { width: 34px; height: 34px; font-size: 17px; }
  .op, .pend, .plan-row, .row-edit > summary { grid-template-columns: 34px minmax(0, 1fr) auto; column-gap: 10px; padding: 10px 12px; }
}
