:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66736e;
  --line: #e3e8e6;
  --primary: #0f5c4a;
  --primary-soft: #e3f1ec;
  --danger: #c0392b;
  --danger-soft: #fbeaea;
  --ilya: #2563eb;
  --sasha: #d97706;
  --radius: 16px;
  --nav-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  overscroll-behavior-y: contain;
}
main { max-width: 560px; margin: 0 auto; padding: 12px 14px 0; }
h1 { font-size: 22px; margin: 6px 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.topbar h1 { margin: 0; }
.icon-btn { border: 0; background: var(--card); border-radius: 12px; width: 44px; height: 44px; font-size: 20px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.back { border: 0; background: none; color: var(--primary); font-weight: 600; padding: 8px 0; font-size: 16px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }

/* Формы */
.amount-input {
  width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px;
  font-size: 30px; font-weight: 700; text-align: center; background: #fbfcfc; outline: none;
}
.amount-input:focus { border-color: var(--primary); background: #fff; }
.field { margin-top: 12px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.text-input { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fbfcfc; outline: none; }
.text-input:focus { border-color: var(--primary); background: #fff; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.seg { display: flex; background: #eef1f0; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.chips { position: relative; display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 14px; max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.chip small { color: var(--muted); font-weight: 400; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

.btn { display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px; font-weight: 700; font-size: 17px; background: var(--primary); color: #fff; margin-top: 14px; }
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* Цифры */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: #f7f9f8; border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.stat.big { grid-column: 1 / -1; background: var(--primary-soft); }
.stat.big .v { font-size: 28px; color: var(--primary); }
.stat.neg .v { color: var(--danger); }
.neg { color: var(--danger); }

.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sum { font-weight: 700; white-space: nowrap; }
.list .sum.plus { color: var(--primary); }
.del { border: 0; background: none; color: #a8b3af; font-size: 18px; width: 36px; height: 36px; border-radius: 10px; }
.del:active { background: var(--danger-soft); color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 14px 0; font-size: 14px; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; vertical-align: 1px; }
.tag.project { background: var(--primary-soft); color: var(--primary); }
.tag.personal { background: #f3e8ff; color: #7c3aed; }
.who { font-weight: 700; }
.who.ilya { color: var(--ilya); }
.who.sasha { color: var(--sasha); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.ilya { background: var(--ilya); }
.dot.sasha { background: var(--sasha); }

/* Объекты */
.obj { display: block; text-decoration: none; color: inherit; }
.obj .client { font-weight: 700; font-size: 17px; }
.obj .addr { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.obj .nums { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.obj .nums b { display: block; color: var(--text); font-size: 15px; }
.bar { height: 8px; background: #eef1f0; border-radius: 99px; overflow: hidden; margin: 10px 0 8px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.over > i { background: var(--danger); }
.archived { opacity: .6; }
.hand { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hand .stat .v { font-size: 16px; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 600; padding: 10px 0; width: 100%; }

.period { margin-bottom: 12px; }
.margin-line { font-size: 13px; color: var(--muted); margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.margin-line b { color: var(--primary); }
.calc-row { display: flex; justify-content: space-between; padding: 6px 0; color: var(--muted); }
.calc-row b { color: var(--text); white-space: nowrap; }
.calc-row.total { border-top: 1.5px solid var(--line); margin-top: 4px; padding-top: 10px; color: var(--text); font-weight: 700; font-size: 18px; }
.calc-row.total b { color: var(--primary); }
.calc-row.total.neg b { color: var(--danger); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.split .who { margin-bottom: 4px; }
.chev { color: #b5bfbb; font-size: 22px; }

/* Нижняя навигация */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); backdrop-filter: blur(8px);
}
#tabs a { flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
#tabs a .ti { font-size: 22px; line-height: 1.1; filter: grayscale(1); opacity: .6; }
#tabs a.on { color: var(--primary); }
#tabs a.on .ti { filter: none; opacity: 1; }

/* Нижняя шторка */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; animation: up .18s ease-out;
}
#sheet .grip { width: 40px; height: 5px; background: var(--line); border-radius: 9px; margin: 0 auto 12px; }
#sheet h1 { font-size: 20px; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
.list .sub.wrap { white-space: normal; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 12px);
  z-index: 50; background: #1d2724; color: #fff; padding: 12px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); width: max-content; max-width: 92vw;
}
#toast span { white-space: nowrap; }
#toast button { border: 0; background: none; color: #7ee0c3; font-weight: 700; }
#offline { background: #fff3cd; color: #7a5b00; text-align: center; font-size: 13px; padding: 6px; }

/* Вход */
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.login .logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 10px; display: block; }
.login h1 { text-align: center; }
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.who-pick button { border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 22px 8px; font-size: 19px; font-weight: 700; }
.who-pick button.on.ilya { border-color: var(--ilya); color: var(--ilya); }
.who-pick button.on.sasha { border-color: var(--sasha); color: var(--sasha); }
.pin-input { letter-spacing: .5em; }
.who-pick { grid-template-columns: 1fr 1fr 1fr; }
.who-pick button { padding: 20px 4px; font-size: 17px; }
.who-pick button.on.dasha { border-color: var(--dasha); color: var(--dasha); }
:root { --dasha: #db2777; }
.dot.dasha { background: var(--dasha); }
.who.dasha { color: var(--dasha); }
.tag.dasha { background: #fce7f3; color: var(--dasha); }

/* Обязательная разметка трат Даши — закрыть нельзя */
#blocker { position: fixed; inset: 0; z-index: 40; background: rgba(15, 30, 25, .55); display: flex; align-items: flex-end; justify-content: center; }
.blocker-card {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .18s ease-out;
}
.blocker-card h1 { font-size: 22px; margin: 8px 0 4px; }
.blocker-badge { display: inline-block; background: #fff3cd; color: #7a5b00; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 8px; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.list li.tap { cursor: pointer; }
.list li.tap:active { background: #f4f7f6; }
.mrow { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.mrow b, .mrow span:not(:first-child) { text-align: right; white-space: nowrap; }
.mrow.head { border-top: 0; font-size: 12px; color: var(--muted); padding-top: 0; }
.list li.month-head { justify-content: space-between; background: #f4f7f6; margin: 6px -16px 0; padding: 8px 16px; font-weight: 600; color: var(--muted); border-top: 0; }
.list li.month-head b { color: var(--text); }
.list li.month-head + li { border-top: 0; }
.hscroll { position: relative; height: 14px; margin-top: 4px; cursor: pointer; touch-action: none; }
.hscroll::before { content: ''; position: absolute; left: 0; right: 0; top: 5px; height: 4px; border-radius: 4px; background: #e3e8e6; }
.hscroll i { position: absolute; top: 3px; height: 8px; border-radius: 8px; background: var(--primary); opacity: .75; }
.obj .nums span { display: block; font-size: 11px; color: var(--muted); }
.obj .nums span.neg { color: var(--danger); }
.stat .k.neg { color: var(--danger); }
.obj .nums b.neg, .margin-line b.neg { color: var(--danger); }
