/* Мои финансы — «семейная сберкнижка»: банкнотный зелёный, гравировка на главной, остальное спокойно. */
:root {
  --paper: #EBF0EC;
  --surface: #FFFFFF;
  --ink: #142620;
  --muted: #5F726A;
  --line: #D3DED8;
  --note: #1D6A4F;
  --note-soft: #DCEBE3;
  --on-note: #F4FAF6;
  --plus: #17824F;
  --minus: #B3443A;
  --amber: #9A620F;
  --amber-soft: #F6EBD6;
  --press: rgba(20, 38, 32, .06);
  /* низ экрана: системный отступ или тот, что сообщает Телеграм (берём больший) */
  --safe-b: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --safe-t: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --display: "Unbounded", "Onest", system-ui, sans-serif;
  --text: "Onest", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --paper: #0D1512;
  --surface: #15201C;
  --ink: #E3ECE7;
  --muted: #8C9E96;
  --line: #23322C;
  --note: #5CBF95;
  --note-soft: #1B2E27;
  --on-note: #0D1512;
  --plus: #5CC28F;
  --minus: #E58275;
  --amber: #DDA74A;
  --amber-soft: #2C2516;
  --press: rgba(227, 236, 231, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body {
  font: 400 16px/1.4 var(--text);
  font-feature-settings: "tnum" 1, "lnum" 1;
  padding-bottom: calc(84px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
}
main { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--safe-t)) 16px 24px; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* отклик в момент нажатия, а не после отпускания */
.btn, .mini, .chips button, .seg button, .arrow, .fab, .tabs button, .link { transition: transform .1s ease-out, opacity .1s ease-out; }
.btn:active:not(:disabled), .mini:active, .chips button:active, .arrow:active:not(:disabled), .link:active { transform: scale(.97); }
.fab:active { transform: scale(.94); }
.seg button:active, .tabs button:active { opacity: .6; }

/* переходы между экранами: вглубь — справа, «Назад» — слева, вкладки — растворением */
@keyframes enter-right { from { opacity: 0; transform: translateX(28px); } }
@keyframes enter-left { from { opacity: 0; transform: translateX(-28px); } }
@keyframes enter-fade { from { opacity: 0; } }
main.enter-push { animation: enter-right .3s cubic-bezier(.2, .8, .2, 1) both; }
main.enter-pop { animation: enter-left .3s cubic-bezier(.2, .8, .2, 1) both; }
main.enter-tab { animation: enter-fade .18s ease-out both; }
:focus-visible { outline: 2px solid var(--note); outline-offset: 2px; border-radius: 6px; }

/* ---------- заголовки и текст ---------- */
.screen-title { font: 600 22px/1.2 var(--text); letter-spacing: -.01em; margin: 6px 2px 14px; }
.section { font: 600 15px/1.3 var(--text); color: var(--muted); margin: 26px 4px 8px; }
.hint { font-size: 14px; color: var(--muted); margin: 8px 4px 0; line-height: 1.45; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--muted); }

/* ---------- главная: купюра ---------- */
.note {
  position: relative; overflow: hidden; border-radius: 22px;
  background: var(--note); color: var(--on-note);
  padding: 20px 20px 20px;
}
.note svg.guilloche { position: absolute; right: -96px; top: -92px; width: 320px; height: 320px; opacity: .32; pointer-events: none; }
.note svg.guilloche path { fill: none; stroke: currentColor; stroke-width: .7; }
.note .who { font-size: 14px; opacity: .8; position: relative; }
.note .total {
  font: 600 clamp(30px, 9.5vw, 40px)/1.05 var(--display); letter-spacing: -.035em;
  margin: 10px 0 6px; position: relative; white-space: nowrap;
}
.note .total small { font-size: .55em; font-weight: 500; margin-left: 4px; opacity: .8; }
.note .own { font-size: 14px; opacity: .85; position: relative; }
.note svg.trend { display: block; width: calc(100% + 40px); height: 56px; margin: 6px -20px -20px; position: relative; }
.note svg.trend path.line { fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .9; }
.note svg.trend path.area { fill: currentColor; opacity: .08; }
.note .trend-caption { position: relative; font-size: 13px; opacity: .75; margin-top: 14px; }
@media (prefers-reduced-motion: no-preference) {
  .note.first svg.guilloche path { stroke-dasharray: 2400; stroke-dashoffset: 2400; animation: engrave 1.6s ease-out forwards; }
}
@keyframes engrave { to { stroke-dashoffset: 0; } }

/* ---------- списки ---------- */
.list { background: var(--surface); border-radius: 16px; overflow: hidden; }
.list + .list { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; position: relative; width: 100%;
  border: 0; background: none; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
button.row, .row.tap { cursor: pointer; }
button.row:active, .row.tap:active { background: var(--press); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 13px; letter-spacing: .005em; color: var(--muted); margin-top: 2px; }
.row .end { text-align: right; white-space: nowrap; }
.row .end .sub { text-align: right; }
.row .chev { width: 8px; height: 8px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(-45deg); opacity: .6; flex: none; }
.row .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--note-soft); color: var(--note);
  display: grid; place-items: center; flex: none; font-size: 17px; }
.row .ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.meter { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--note); border-radius: 3px; }
.meter.warn > i { background: var(--amber); }
.meter.over > i { background: var(--minus); }

.tag { display: inline-block; font-size: 12px; letter-spacing: .01em; line-height: 1; padding: 4px 8px; border-radius: 8px; margin-top: 6px;
  background: var(--note-soft); color: var(--note); }
.tag.soon { background: var(--amber-soft); color: var(--amber); }
.tag.late { background: color-mix(in srgb, var(--minus) 14%, transparent); color: var(--minus); }
.tag.grey { background: var(--press); color: var(--muted); }

.callout { background: var(--amber-soft); color: var(--ink); border-radius: 16px; padding: 14px 16px; font-size: 15px; }
.callout b { font-weight: 600; }

/* ---------- карточка объекта ---------- */
.head { padding: 6px 4px 14px; }
.head .kicker { color: var(--muted); font-size: 15px; }
.head .amount { font: 600 32px/1.1 var(--display); letter-spacing: -.03em; margin-top: 4px; }
.head .amount small { font-size: .55em; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 12px 16px; position: relative; }
.kv + .kv::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.kv > span:first-child { color: var(--muted); white-space: nowrap; }
.kv > span:last-child { text-align: right; }

/* ---------- кнопки ---------- */
.btn { display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px; font-weight: 600; font-size: 16px;
  background: var(--note); color: var(--on-note); margin-top: 10px; cursor: pointer; }
.btn.quiet { background: var(--surface); color: var(--note); }
.btn.danger { background: var(--surface); color: var(--minus); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.link { border: 0; background: none; color: var(--note); font-weight: 600; padding: 4px 0; cursor: pointer; }
.mini { border: 0; border-radius: 10px; padding: 7px 11px; font-size: 14px; font-weight: 600; cursor: pointer;
  background: var(--note-soft); color: var(--note); white-space: nowrap; }
.mini.ghost { background: none; color: var(--muted); font-weight: 500; }

.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; font-size: 14px; padding: 8px 4px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--note-soft); color: var(--note); font-weight: 600; }

/* ---------- формы ---------- */
.field { padding: 11px 16px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.field label { display: block; font-size: 13px; letter-spacing: .005em; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; border: 0; background: none; color: var(--ink); font: inherit;
  padding: 2px 0; outline: none; -webkit-appearance: none; appearance: none; min-height: 24px; }
.field textarea { resize: none; min-height: 46px; }
.field ::placeholder { color: var(--muted); opacity: .6; }
.field .two { display: flex; gap: 14px; }
.field .two > * { flex: 1; min-width: 0; }
.field input.big { font: 600 28px/1.2 var(--display); letter-spacing: -.02em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips button { border: 0; border-radius: 10px; padding: 6px 11px; font-size: 14px; cursor: pointer;
  background: var(--paper); color: var(--ink); }
.chips button.on { background: var(--note); color: var(--on-note); }
.error { color: var(--minus); font-size: 14px; margin: 12px 4px 0; min-height: 1em; }
.suggest { margin-top: 8px; border-top: 1px solid var(--line); }
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 0; cursor: pointer; }
.suggest button b { font-weight: 600; margin-right: 6px; }

/* ---------- расходы ---------- */
.period { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 6px; }
.period .name { font-weight: 600; }
.arrow { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--surface); cursor: pointer; display: grid; place-items: center; }
.arrow:disabled { opacity: .3; }
.arrow svg { width: 16px; height: 16px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spent { padding: 8px 4px 14px; }
.spent .amount { font: 600 32px/1.1 var(--display); letter-spacing: -.03em; }
.spent .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.days { display: flex; align-items: flex-end; gap: 2px; height: 46px; margin-top: 12px; }
.days i { flex: 1; background: var(--note); opacity: .75; border-radius: 2px 2px 0 0; min-height: 2px; }
.days i.zero { background: var(--line); opacity: 1; }

/* ---------- календарь ---------- */
.month-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 8px; }
.month-head b { font-weight: 600; text-transform: capitalize; }
.month-head span { font-size: 14px; }

.report { background: var(--surface); border-radius: 16px; padding: 16px; white-space: pre-wrap; line-height: 1.5; font-size: 15px; }
.report b { font-weight: 600; }

/* ---------- каркас ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; z-index: 5;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: .5px solid color-mix(in srgb, var(--line) 80%, transparent); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; max-width: 120px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: .01em;
  padding: 8px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--note); }
.tabs button.on svg { stroke-width: 2; }
.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(80px + var(--safe-b)); width: 54px; height: 54px;
  border-radius: 17px; border: 0; background: var(--note); color: var(--on-note); z-index: 6; cursor: pointer;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--note) 35%, transparent); display: grid; place-items: center; }
.fab[hidden] { display: none; }
.fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.empty { text-align: center; color: var(--muted); padding: 44px 24px; line-height: 1.5; }
.empty b { display: block; color: var(--ink); font-weight: 600; font-size: 17px; margin-bottom: 4px; }
.loading { text-align: center; color: var(--muted); padding: 80px 0; }
.toast { position: fixed; left: 50%; bottom: calc(146px + var(--safe-b)); transform: translate(-50%, 8px);
  background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 9;
  opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .18s; transform: translate(-50%, 0); }
  .btn:active:not(:disabled), .mini:active, .chips button:active, .arrow:active:not(:disabled), .link:active, .fab:active { transform: none; opacity: .7; }
  main.enter-push, main.enter-pop { animation-name: enter-fade; animation-duration: .18s; }
}
@media (prefers-reduced-transparency: reduce) {
  .tabs { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --muted: #3F4F48; --line: #9DB0A7; }
  :root[data-theme="dark"] { --muted: #B5C4BD; --line: #4A5E55; }
  .tabs { background: var(--surface); border-top: 1px solid var(--ink); }
}
:root[data-theme="dark"] .note { background: #1C5E46; color: #E9F5EE; }
