:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --red: #e5484d;
  --green: #30a46c;
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: var(--text); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--bg); }
.top .month { font-weight: 600; font-size: 17px; text-transform: capitalize; }
.top .nav { width: 40px; height: 36px; font-size: 26px; line-height: 1; border-radius: 10px; color: var(--accent); }

main { padding: 0 12px; }
.tab { display: none; }
.tab.active { display: block; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; align-items: baseline; }
.card h2 .sum { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 14px; }

.summary .big { font-size: 26px; font-weight: 700; }
.summary .row { display: flex; justify-content: space-between; color: var(--hint); font-size: 13px; margin-top: 6px; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 4px; transition: width .3s; }

.period { margin-top: 4px; }
.period-title { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); padding: 8px 0 2px; border-top: 1px solid var(--line); }
.period:first-of-type .period-title { border-top: 0; padding-top: 0; }

.item { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.item + .item { border-top: 1px solid var(--line); }
.check { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--hint); display: grid; place-items: center; font-size: 15px; color: transparent; transition: .15s; }
.item.done .check { background: var(--green); border-color: var(--green); color: #fff; }
.item.done .name { text-decoration: line-through; color: var(--hint); }
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 12px; color: var(--hint); }
.item .amt { font-weight: 600; white-space: nowrap; text-align: right; }
.item .amt small { display: block; font-weight: 400; font-size: 11px; color: var(--hint); }
.day { flex: none; width: 34px; text-align: center; font-size: 12px; color: var(--hint); }
.day b { display: block; font-size: 16px; color: var(--text); }
.rate-hi { color: var(--red); }

.totals .line { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .line b { font-weight: 600; }
.totals .line.main { font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; }

.quick { display: flex; gap: 8px; }
.quick input { flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); outline: none; }
.btn { padding: 12px 16px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.ghost { background: var(--bg); color: var(--accent); }
.btn.danger { background: transparent; color: var(--red); }
.btn.round { width: 46px; padding: 0; font-size: 20px; }
.btn.rec { background: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.hint { font-size: 12px; color: var(--hint); margin-top: 8px; }

.op .icon { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); font-size: 17px; }
.op .amt.income { color: var(--green); }
.day-head { font-size: 12px; color: var(--hint); padding: 10px 0 2px; }
.day-head:first-child { padding-top: 0; }
.empty { text-align: center; color: var(--hint); padding: 24px 0; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--hint); }
.kpi .value { font-size: 19px; font-weight: 700; margin-top: 2px; }
.kpi .value.pos { color: var(--green); }
.kpi .value.neg { color: var(--red); }
.kpis + .card, .kpis { margin-bottom: 12px; }

.hbar { margin: 8px 0; }
.hbar .lbl { display: flex; justify-content: space-between; font-size: 13px; }
.hbar .track { height: 8px; background: var(--line); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.cols { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.col .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.col .pair i { width: 40%; max-width: 16px; border-radius: 4px 4px 0 0; min-height: 2px; }
.col .pair i.inc { background: var(--green); }
.col .pair i.exp { background: var(--red); }
.col .m { font-size: 11px; color: var(--hint); margin-top: 4px; }
.col.cur .m { color: var(--text); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; padding: 8px 0 10px; font-size: 11px; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active span { filter: none; opacity: 1; }

.fab { position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 6; width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 28px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }

.sheet-bg { position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .25s; max-height: 88vh; overflow-y: auto; }
.sheet.open { transform: none; }
.sheet-bg.open { opacity: 1; pointer-events: auto; }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); outline: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 8px; font-weight: 500; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 6px 10px; border-radius: 16px; background: var(--bg); font-size: 13px; }
.chips button.on { background: var(--accent); color: var(--accent-text); }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: rgba(30,30,30,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.edit-link { font-size: 12px; color: var(--accent); text-transform: none; letter-spacing: 0; }

.halves { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.card.half { padding: 12px; margin-bottom: 12px; min-width: 0; }
.card.half h2 { margin-bottom: 4px; }
.card.half .edit-link { font-size: 18px; line-height: 1; padding: 0 2px; }
.mini { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; }
.mini + .mini { border-top: 1px solid var(--line); }
.mini .body { flex: 1; min-width: 0; }
.mini .name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .amt { font-weight: 600; font-size: 14px; }
.mini .meta { font-size: 11px; color: var(--hint); }
.mini.done .name, .mini.done .amt { text-decoration: line-through; color: var(--hint); }
.mini.done .check { background: var(--green); border-color: var(--green); color: #fff; }
.check.sm { width: 22px; height: 22px; font-size: 12px; margin-top: 2px; }
.half-total { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; font-size: 13px; color: var(--hint); }
.half-total b { color: var(--text); }
.home-btn { display: block; width: calc(100% - 24px); margin: 0 12px 12px; }

/* Быстрая запись */
.bulk { width: 100%; min-height: 34vh; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); font: 17px/1.5 inherit; font-family: inherit; outline: none; resize: none; }
.bulk:focus { border-color: var(--accent); }
.bulk-preview { margin-top: 10px; }
.bp { display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.bp.income b { color: var(--green); }
.bp.bad { color: var(--red); }

/* Сводка по кредиту внутри карточки */
.credit-info { background: var(--bg); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.credit-info div { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.credit-info span { color: var(--hint); }
.credit-info .neg { color: var(--red); }
.credit-info .pos { color: var(--green); }


/* Заметки */
.notes-ta { width: 100%; min-height: 56px; border: 0; background: var(--bg); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 15px; resize: none; outline: none; overflow: hidden; }
.notes-ta:focus { box-shadow: 0 0 0 2px var(--accent); }


/* Вход по паролю (открыто не из Telegram) */
.login-mode .tabs, .login-mode .fab, .login-mode .top { display: none; }
.login { margin-top: 18vh; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login input { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); outline: none; font-size: 16px; }

/* Помощь */
.tabs button { min-width: 0; font-size: 10px; }
.help h2 { margin-bottom: 8px; }
.help-step { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.4; }
.help-step:first-of-type { border-top: 0; }
.help-step b { display: block; margin-bottom: 2px; }
.help .btn { width: 100%; margin: 4px 0 8px; }

/* Потянуть вниз — обновить: кружок стоит на месте и только крутится */
.ptr { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; z-index: 30; width: 52px; height: 52px; margin-left: -26px; border-radius: 50%; background: var(--card); color: var(--hint); box-shadow: 0 4px 16px rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .2s, color .15s, scale .15s; }
.ptr.ready, .ptr.spin { color: var(--accent); scale: 1.08; }
.ptr.spin { opacity: 1 !important; }
.ptr.spin svg { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
/* Копилка */
.piggy { padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.piggy:first-of-type { border-top: 0; padding-top: 2px; }
.piggy .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.piggy .name { font-weight: 500; }
.piggy .of, .piggy-big .of { color: var(--hint); font-weight: 400; font-size: 13px; }
.piggy .bar { margin-top: 6px; height: 6px; }
.piggy .meta { color: var(--hint); font-size: 12px; margin-top: 4px; }
.piggy-big { font-size: 26px; font-weight: 700; margin-bottom: 12px; }
.seg.emoji { flex-wrap: wrap; }
.seg.emoji button { flex: 0 0 20%; font-size: 20px; padding: 6px 0; }
.pg-hist { margin-top: 14px; font-size: 13px; }
.pg-hist .row { display: flex; justify-content: space-between; padding: 5px 0; border-top: 1px solid var(--line); color: var(--hint); }
.pg-hist .pos { color: var(--green); } .pg-hist .neg { color: var(--red); }
.pg-edit { margin-top: 14px; }
.pg-edit summary { color: var(--accent); cursor: pointer; margin-bottom: 10px; }