:root {
  --bg: #F6F8F6;
  --surface: #FFFFFF;
  --line: #E4EAE6;
  --line-2: #DCE3DF;
  --text: #1B1F1D;
  --text-2: #44504A;
  --muted: #5C6661;
  --accent: #2E5E46;
  --accent-ink: #1F4232;
  --mint: #D3EBDD;
  --mint-2: #E7F1EB;
  --chip: #EAEFEC;
  --up-bg: #FBE9DA; --up-ink: #8A4513;
  --down-bg: #DDEFE3; --down-ink: #1F5A36;
  --danger: #A3362B;
  --line-soft: var(--line-soft);
  --press: var(--press);
  --seg: #E7ECE9;
  --bar: #D5DDD8;
  --faint: #9AA39E;
  --ph: #98A19C;
  --on-accent: #FFFFFF;
  --total-ink: #12301F;
  --total-sub: #2E4A3C;
  --toast: #1F2A25;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0F1412;
  --surface: #182019;
  --line: #26302B;
  --line-2: #2F3A34;
  --text: #E8EEEA;
  --text-2: #B9C5BE;
  --muted: #8E9A93;
  --accent: #3F8A63;
  --accent-ink: #BFE6CF;
  --mint: #1F3A2C;
  --mint-2: #1A2B22;
  --chip: #222C27;
  --up-bg: #3A2617; --up-ink: #F2B98A;
  --down-bg: #17311F; --down-ink: #9FDDB4;
  --danger: #F08A7E;
  --line-soft: #222B26;
  --press: #222C27;
  --seg: #222C27;
  --bar: #34403A;
  --faint: #6F7C75;
  --ph: #66726B;
  --on-accent: #FFFFFF;
  --total-ink: #E3F4EA;
  --total-sub: #A9CDB7;
  --toast: #2B3631;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", system-ui, sans-serif;
  font-size: 15px; line-height: 1.35; -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select { font-size: 16px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.view {
  padding: calc(var(--safe-top) + 18px) 20px calc(var(--safe-bottom) + 110px);
  display: flex; flex-direction: column; gap: 16px; max-width: 560px; margin: 0 auto; min-height: 100vh;
}
.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.head h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -0.2px; }
.label { font-size: 13px; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 18px 20px; }
.card h2 { margin: 0; font-size: 17px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.link { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 14px; padding: 8px 0; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:active { background: var(--chip); }

/* ---------- avatar ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: none; }
.avatar svg { width: 32px; height: 32px; }

/* ---------- amount ---------- */
.amount-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px 14px 20px; }
.amount-card .grow { flex: 1; min-width: 0; }
.amount-line { display: flex; align-items: baseline; gap: 8px; }
.amount-input { border: none; outline: none; background: transparent; font-size: 40px; font-weight: 600; width: 100%;
  min-width: 0; padding: 0; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.amount-input::placeholder { color: var(--ph); }
.cur { font-size: 18px; color: var(--muted); font-weight: 600; }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--text-2); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; position: relative; white-space: nowrap; }
.chip.on { border-color: transparent; background: var(--mint); color: var(--accent-ink); font-weight: 600; }
.chip input[type=date] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.pill { flex: none; height: 30px; padding: 0 12px; border-radius: 999px; border: none; background: var(--chip); color: var(--text-2); font-size: 13px; }
.pill:active { background: var(--mint); }

/* ---------- categories grid ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 6px; }
.cat { border: none; background: transparent; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text); min-width: 0; }
.cat span.t { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .ic { width: 56px; height: 56px; border-radius: 19px; display: flex; align-items: center; justify-content: center; transition: transform .12s; }
.cat:active .ic { transform: scale(.94); }
.cat.on span.t { font-weight: 700; }
.cat .ic.more { background: var(--surface); border: 1px dashed var(--faint); color: var(--text-2); }
.auto-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--accent); font-weight: 600; }

/* ---------- place ---------- */
.place { display: flex; align-items: center; gap: 8px; height: 42px; border-bottom: 1px solid var(--line-2); color: var(--faint); }
.place input { flex: 1; border: none; outline: none; background: transparent; padding: 0; color: var(--text); font-size: 16px; }
.place input::placeholder { color: var(--ph); }

.primary { height: 54px; border: none; border-radius: 999px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; width: 100%; }
.primary:active { filter: brightness(.92); }
.primary:disabled { opacity: .5; }
.secondary { height: 50px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); font-size: 15px; font-weight: 600; }
.danger { color: var(--danger); border-color: var(--danger); }

/* ---------- tabbar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px 8px calc(var(--safe-bottom) + 8px); }
.tab { border: none; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; color: var(--text-2); padding: 2px 0; }
.tab .pillbg { width: 64px; height: 32px; border-radius: 999px; display: flex; align-items: center; justify-content: center; }
.tab.on { color: var(--text); font-weight: 700; }
.tab.on .pillbg { background: var(--mint); color: var(--accent); }
.tab.add .fab { width: 60px; height: 60px; margin-top: -30px; border-radius: 22px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(46,94,70,.35); border: 4px solid var(--surface); }

/* ---------- history ---------- */
.month-sw { display: flex; align-items: center; gap: 0; }
.month-sw span { font-size: 15px; font-weight: 600; min-width: 112px; text-align: center; }
.total-card { background: var(--mint); border-radius: 24px; padding: 18px 20px; display: flex; flex-direction: column; gap: 2px; color: var(--total-ink); }
.total-card .big { font-size: 32px; font-weight: 600; letter-spacing: -0.4px; }
.total-card .sub { font-size: 13px; color: var(--total-sub); }
.search { display: flex; align-items: center; gap: 10px; height: 46px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-2); padding: 0 16px; }
.search input { border: none; outline: none; background: transparent; flex: 1; padding: 0; }
.who-f { height: 40px; min-width: 40px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 14px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px; color: var(--text-2); }
.who-f.icon { padding: 0; width: 40px; }
.who-f svg { width: 28px; height: 28px; }
.who-f.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.day-h { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px; margin-top: 4px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
.item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 16px; border: none; border-bottom: 1px solid var(--line-soft); background: var(--surface); text-align: left; }
.item:last-child { border-bottom: none; }
.item:active { background: var(--press); }
.item .ic { position: relative; width: 40px; height: 40px; border-radius: 14px; display: flex; align-items: center; justify-content: center; flex: none; }
.item .ic svg { width: 21px; height: 21px; }
.item .who { position: absolute; right: -6px; bottom: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); display: flex; align-items: center; justify-content: center; }
.item .who svg { width: 20px; height: 20px; }
.item .mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item .mid .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sum { font-weight: 600; white-space: nowrap; }
.pending-dot { width: 7px; height: 7px; border-radius: 50%; background: #E08A3C; display: inline-block; margin-left: 6px; vertical-align: middle; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; font-size: 14px; }

/* ---------- stats ---------- */
.seg { display: inline-flex; background: var(--seg); border-radius: 999px; padding: 3px; }
.seg button { height: 32px; padding: 0 14px; border: none; border-radius: 999px; background: transparent; font-size: 14px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.delta { padding: 6px 10px; border-radius: 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.delta.up { background: var(--up-bg); color: var(--up-ink); }
.delta.down { background: var(--down-bg); color: var(--down-ink); }
.bars { display: grid; gap: 8px; align-items: end; height: 140px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; border: none; background: none; padding: 0; min-width: 0; }
.bar .b { width: 100%; border-radius: 8px 8px 4px 4px; background: var(--bar); min-height: 3px; }
.bar.on .b { background: var(--accent); }
.bar .v { font-size: 11px; color: var(--text); font-weight: 700; white-space: nowrap; }
.bar .m { font-size: 12px; color: var(--muted); }
.bar.on .m { color: var(--text); font-weight: 700; }
.donut-wrap { display: flex; justify-content: center; padding: 4px 0; }
.donut { width: 190px; height: 190px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.donut .hole { width: 124px; height: 124px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.leg { width: 100%; display: flex; align-items: center; gap: 12px; padding: 0 10px; height: 46px; border: none; border-radius: 12px; background: transparent; text-align: left; }
.leg.on { background: var(--mint-2); }
.leg .dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.leg .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg .p { font-size: 13px; color: var(--muted); width: 40px; text-align: right; }
.leg .s { font-weight: 600; width: 88px; text-align: right; }
.track { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.track > div { height: 100%; border-radius: 999px; background: var(--accent); }

/* ---------- categories editor ---------- */
.cat-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 0 8px 0 14px; height: 56px; border: none; border-bottom: 1px solid var(--line-soft); background: var(--surface); color: var(--text); text-align: left; }
.cat-row:last-child { border-bottom: none; }
.cat-row .ic { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; }
.cat-row .ic svg { width: 20px; height: 20px; }
.cat-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv { width: 36px; height: 36px; border: none; background: transparent; border-radius: 10px; color: var(--faint); display: inline-flex; align-items: center; justify-content: center; }
.mv:active { background: var(--chip); }
.mv:disabled { opacity: .25; }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(20,30,25,.38); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet .panel { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 24px); display: flex; flex-direction: column; gap: 16px; animation: up .2s ease-out; }
.grab { width: 36px; height: 4px; border-radius: 2px; background: var(--bar); align-self: center; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input, .field select { height: 48px; border-radius: 14px; border: 1px solid var(--line-2); padding: 0 14px; background: var(--surface); color: var(--text); outline: none; width: 100%; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.sw { width: 36px; height: 36px; border-radius: 50%; border: none; padding: 0; }
.sw.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px currentColor; }
.icons { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.icons button { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.icons button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.menu-btn { height: 52px; border: none; border-radius: 14px; background: var(--press); color: var(--text); font-size: 16px; text-align: left; padding: 0 16px; display: flex; align-items: center; gap: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 96px); z-index: 60; max-width: 528px; margin: 0 auto;
  background: var(--toast); color: #fff; border-radius: 14px; padding: 12px 14px 12px 16px; display: flex; align-items: center; gap: 12px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: up .2s ease-out; }
.toast span { flex: 1; }
.toast button { border: none; background: none; color: #9FD8B8; font-weight: 700; font-size: 14px; padding: 6px 4px; }

/* ---------- lock ---------- */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 28px; padding: calc(var(--safe-top) + 20px) 24px calc(var(--safe-bottom) + 20px); }
.lock .logo { width: 72px; height: 72px; border-radius: 22px; background: var(--accent); display: flex; align-items: center; justify-content: center; color: #fff; }
.lock h1 { margin: 0; font-size: 20px; font-weight: 600; }
.lock .msg { min-height: 20px; font-size: 14px; color: var(--danger); text-align: center; }
.dots { display: flex; gap: 18px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); }
.dots i.on { background: var(--accent); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; }
.pad button { width: 76px; height: 76px; border-radius: 50%; border: none; background: var(--surface); color: var(--text); font-size: 30px; font-weight: 400;
  box-shadow: 0 1px 2px rgba(0,0,0,.06); display: flex; align-items: center; justify-content: center; }
.pad button:active { background: var(--mint); }
.pad button.ghost { background: transparent; box-shadow: none; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--mint); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#view-add { gap: 14px; }
#add-tips::-webkit-scrollbar { display: none; }
.avatar span svg { width: 100%; height: 100%; }
.menu-btn span svg { width: 26px; height: 26px; }

/* month button */
.month-btn { border: none; background: transparent; display: inline-flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; color: var(--text); padding: 8px 6px; border-radius: 10px; }
.month-btn:active { background: var(--chip); }
.month-btn svg { color: var(--accent); }
/* scrollable month strip */
.strip { display: flex; gap: 8px; align-items: flex-end; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; margin: 0 -20px; padding: 0 20px; -webkit-overflow-scrolling: touch; }
.strip::-webkit-scrollbar { display: none; }
.sbar { flex: none; width: 40px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; border: none; background: none; padding: 0; }
.sbar .b { width: 100%; border-radius: 8px 8px 4px 4px; transition: background .15s; }
.sbar .v { font-size: 11px; font-weight: 700; min-height: 13px; white-space: nowrap; }
.sbar .m { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sbar.on .m { color: var(--text); font-weight: 700; }
/* month picker */
.mp-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.mp { height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 14px; }
.mp .s { font-size: 12px; color: var(--muted); }
.mp.empty { color: var(--faint); }
.mp.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.mp.on .s { color: rgba(255,255,255,.8); }
.mp:disabled { opacity: .35; }
/* swipe feedback */
.swipe-l { animation: swl .22s ease-out; }
.swipe-r { animation: swr .22s ease-out; }
@keyframes swl { from { transform: translateX(28px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes swr { from { transform: translateX(-28px); opacity: .5; } to { transform: none; opacity: 1; } }

/* analytics: category purchases */
.leg .chev { color: var(--faint); display: inline-flex; margin-left: -4px; }
.leg.on .chev { color: var(--accent); }
.leg.more-cats { justify-content: center; color: var(--accent); font-weight: 600; font-size: 14px; gap: 4px; }
.leg.more-cats .n { flex: none; }
.cat-items { margin: 2px 0 10px 16px; padding-left: 10px; display: flex; flex-direction: column; }
.ci { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 42px; border: none; border-bottom: 1px solid var(--line-soft); background: none; text-align: left; padding: 6px 4px; }
.ci:last-child { border-bottom: none; }
.ci:active { background: var(--press); }
.ci-d { width: 48px; flex: none; font-size: 12px; color: var(--muted); }
.ci-w { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-w.muted { color: var(--faint); }
.ci-who { width: 20px; height: 20px; flex: none; display: flex; }
.ci-who svg { width: 20px; height: 20px; }
.ci-s { font-size: 14px; font-weight: 600; white-space: nowrap; }
.ci.more { justify-content: center; color: var(--accent); font-weight: 600; font-size: 14px; }
.leg { gap: 8px; padding: 0 6px 0 10px; }
.leg .p { width: 34px; }
.leg .s { width: auto; min-width: 64px; }

/* active tab: bolder icon */
.tab svg { transition: stroke-width .12s; }
.tab.on svg { stroke-width: 2.6; }
/* BYN as a button */
.cur-btn { flex: none; display: inline-flex; align-items: center; gap: 5px; height: 36px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--mint-2); color: var(--accent-ink); font-size: 16px; font-weight: 700; }
.cur-btn:active { background: var(--mint); }
.cur-btn svg { color: var(--accent); }
/* calculator */
.calc-screen { background: var(--press); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; min-height: 84px; justify-content: center; }
.calc-expr { font-size: 22px; color: var(--text-2); word-break: break-all; text-align: right; }
.calc-res { font-size: 30px; font-weight: 600; }
.calc-pad { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.ck { height: 56px; border-radius: 16px; border: none; background: var(--press); font-size: 24px; color: var(--text); }
.ck:active { background: var(--mint); }
.ck.op { background: var(--mint-2); color: var(--accent); font-weight: 600; }
.ck.fn { color: var(--danger); font-size: 20px; }
.ck.eq { grid-row: span 2; height: auto; background: var(--accent); color: #fff; }
.ck.zero { grid-column: span 2; }

/* arrange categories */
.cat { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#add-grid.arranging { touch-action: none; }
.cat.jig { cursor: grab; }
.cat.jig .ic { animation: jig .28s ease-in-out infinite alternate; }
.cat.jig:nth-child(2n) .ic { animation-delay: -.14s; }
.cat.dragging .ic { animation: none; transform: scale(1.14); box-shadow: 0 8px 18px rgba(0,0,0,.18); }
.cat.dragging { opacity: .95; z-index: 2; }
@keyframes jig { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
.arr-done { border: none; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; height: 34px; padding: 0 16px; border-radius: 999px; }

/* dark-theme extras */
:root[data-theme="dark"] .lock .pad button { box-shadow: none; }
:root[data-theme="dark"] .tabbar { background: rgba(24,32,25,.94); }
:root[data-theme="dark"] .cat-row, :root[data-theme="dark"] .item { background: var(--surface); color: var(--text); }
:root[data-theme="dark"] .sheet { background: rgba(0,0,0,.55); }
:root[data-theme="dark"] .avatar { background: #24302A; }
/* no zoom: no double-tap zoom, no text-size bump */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
body, button, a, input { touch-action: manipulation; }

/* «Добавить» — зелёная капсула */
.tab.add .pillbg { width: 58px; height: 40px; margin-top: -4px; border-radius: 14px; background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(46,94,70,.35); }
.tab.add .pillbg svg { width: 26px; height: 26px; stroke-width: 2.6; }
.tab.add { color: var(--text); font-weight: 700; }
.tab.add.on .pillbg { background: var(--accent); color: #fff; }
.tab.add:active .pillbg { transform: scale(.94); }
/* switch */
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--bar); position: relative; flex: none; transition: background .15s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s; }
.switch.on { background: var(--accent); }
.switch.on i { left: 21px; }

/* avatar picker */
.av-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 6px; }
.av-opt { border: 2px solid transparent; background: var(--press); border-radius: 18px; padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-2); }
.av-opt span { width: 48px; height: 48px; display: flex; }
.av-opt span svg { width: 100%; height: 100%; }
.av-opt small { font-size: 11px; }
.av-opt.on { border-color: var(--accent); background: var(--mint-2); color: var(--text); font-weight: 600; }
.av-opt:disabled { opacity: .3; }
.avatar svg, .who-f svg, .item .who svg, .ci-who svg { overflow: visible; }

/* ---------- выбор категории ---------- */
.sheet.layer { z-index: 60; }
.pick-body { display: flex; flex-direction: column; gap: 12px; min-height: 40vh; }
.pick-h { margin-top: 2px; }
.sheet .search { flex: none; background: var(--press); border-color: transparent; }

/* ---------- импорт истории ---------- */
.imp-ex { display: block; margin: 6px 0; padding: 8px 12px; border-radius: 12px; background: var(--press); color: var(--text-2); font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.imp-text { width: 100%; min-height: 28vh; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  padding: 12px 14px; font-family: inherit; line-height: 1.45; font-size: 16px; resize: vertical; outline: none; box-sizing: border-box; }
.imp-text:focus { border-color: var(--accent); }
.imp-file { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.imp-file input { position: absolute; inset: 0; opacity: 0; }
.imp-month { margin-top: 6px; padding-bottom: 2px; border-bottom: 1px solid var(--line); }
.imp-row { display: flex; align-items: center; gap: 10px; min-height: 52px; }
.imp-row.off .imp-main, .imp-row.off .imp-amt, .imp-row.off .imp-cat { opacity: .4; }
.imp-chk { flex: none; width: 26px; height: 26px; border-radius: 8px; border: 1.5px solid var(--line-2); background: var(--surface); color: #fff; font-size: 15px; font-weight: 700; padding: 0; }
.imp-row:not(.off) .imp-chk { background: var(--accent); border-color: var(--accent); }
.imp-main { flex: 1; min-width: 0; }
.imp-txt { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-cat { flex: none; max-width: 38%; height: 30px; border: none; border-radius: 999px; padding: 0 10px; display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; }
.imp-cat span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-amt { flex: none; min-width: 58px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.imp-dup { color: var(--up-ink); font-weight: 600; }
.imp-skip summary { font-size: 14px; color: var(--muted); padding: 6px 0; }
.imp-skipline { font-size: 13px; color: var(--text-2); padding: 4px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
.imp-go { position: sticky; bottom: 0; flex: none; box-shadow: 0 -10px 18px var(--surface); }
.imp-bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.imp-bar i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.who-pick { width: 42px; height: 42px; border-radius: 50%; border: 2px solid transparent; background: var(--press); padding: 5px; display: flex; align-items: center; justify-content: center; }
.who-pick.on { border-color: var(--accent); background: var(--mint); }

/* ---------- клавиатура: нижние окна живут в видимой части экрана ---------- */
.sheet { top: var(--vvt, 0px); bottom: auto; height: var(--vvh, 100%); }
.sheet .panel { max-height: calc(var(--vvh, 100vh) - 12px); }
.kb .sheet .panel { border-radius: 22px 22px 0 0; padding-bottom: 14px; }
/* выбор категории: окно сразу во всю высоту — строка поиска сверху, результаты под ней */
.sheet .panel:has(#cq) { height: calc(var(--vvh, 100vh) - 12px); }
.sheet .panel:has(#cq) > .search { position: sticky; top: -10px; z-index: 2; box-shadow: 0 6px 10px var(--surface); }

/* ---------- поиск в истории ---------- */
.q-cancel { display: none; padding: 0 2px; white-space: nowrap; }
.searching .q-cancel { display: inline-block; }
.searching .head, .searching #hist-total { display: none; }
.searching .hist-search { position: sticky; top: calc(var(--safe-top) + 6px); z-index: 5; box-shadow: 0 8px 14px var(--bg); }
#hist-found:empty { display: none; }

/* ---------- доходы ---------- */
.kind-seg { display: grid; grid-template-columns: 1fr 1fr; border-radius: 14px; }
.kind-seg button { border-radius: 11px; height: 38px; }
.item.kind-inc .sum { color: var(--down-ink); }
.item.kind-save .sum, .item.kind-unsave .sum { color: var(--up-ink); }
.bal-line { font-size: 15px; }
.num.pos { color: var(--down-ink); }
.num.neg { color: var(--danger); }
.num.pig { color: var(--up-ink); }
.bal-track { height: 8px; border-radius: 4px; background: var(--down-bg); overflow: hidden; }
.bal-track i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- начало месяца ---------- */
.day-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day-grid button { height: 40px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums; }
.day-grid button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- копилка ---------- */
.pig-btn { color: var(--up-ink); }
.pig-hero { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 22px; background: var(--up-bg); color: var(--text); }
.pig-ic { flex: none; width: 64px; height: 64px; border-radius: 20px; background: var(--surface); color: var(--up-ink); display: flex; align-items: center; justify-content: center; }
.goal { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); text-align: left; width: 100%; color: var(--text); }
.goal-emo { flex: none; width: 44px; height: 44px; border-radius: 14px; background: var(--press); display: flex; align-items: center; justify-content: center; font-size: 24px; }
.goal-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.goal-bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; display: block; }
.goal-bar i { display: block; height: 100%; background: #E08A3C; border-radius: 4px; }
.emo-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.emo-grid button { height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 22px; padding: 0; }
.emo-grid button.on { border-color: var(--accent); background: var(--mint); }
.search svg { flex: none; }
