:root {
  --bg: #0e1116;
  --surface: #171b21;
  --surface-2: #1e242c;
  --surface-3: #262d37;
  --text: #e8edf2;
  --muted: #8b96a5;
  --accent: #2ecc71;
  --accent-2: #21a038;
  --danger: #ff6b6b;
  --blue: #4a9eff;
  --border: #2a313b;
  --radius: 16px;
  --nav-h: 62px;
  --top-h: 54px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "SBSans Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- top bar ---------- */
#topbar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 30;
}
#title { font-size: 19px; font-weight: 700; margin: 0; font-family: "SBSans Display", "SBSans Text", sans-serif; }
.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  padding: 8px;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); }

/* ---------- account chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px 10px;
  scrollbar-width: none;
  position: sticky;
  top: var(--top-h);
  background: var(--bg);
  z-index: 25;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.chip.active { background: var(--text); color: #10141a; border-color: var(--text); }
.chip.active .dot { box-shadow: 0 0 0 2px rgba(0,0,0,.15); }

/* ---------- main view ---------- */
#view {
  flex: 1;
  padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}

/* ---------- bottom nav ---------- */
#bottomnav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(14, 17, 22, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 40;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.nav-btn .nav-ico { font-size: 19px; line-height: 1; }
.nav-btn.active { color: var(--accent); }

/* ---------- month bar ---------- */
.monthbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 14px;
}
.monthbar .m-label {
  font-size: 16px;
  font-weight: 700;
  text-transform: capitalize;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 10px;
}
.monthbar .m-label:hover { background: var(--surface-2); }
.m-nav {
  background: var(--surface-2);
  border: none;
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
}
.m-nav:disabled { opacity: .3; cursor: default; }

/* ---------- pills (Расходы / Зачисления) ---------- */
.pills { display: flex; gap: 8px; margin-bottom: 16px; }
.pill {
  background: var(--surface-2);
  border: none;
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
}
.pill.active { background: var(--text); color: #10141a; }

/* ---------- summary ---------- */
.big-sum {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 4px 0 2px;
  font-family: "SBSans Display", "SBSans Text", sans-serif;
}
.big-sum .cur { font-size: 24px; margin-left: 4px; }
.sub-sum { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.sub-sum b { color: var(--text); font-weight: 600; }
.sub-sum .in { color: var(--accent); }
.sub-sum .out { color: var(--danger); }

/* ---------- chart ---------- */
.chartbox { position: relative; margin: 8px 0 4px; }
.chart-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
}

/* ---------- category list ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-top: 14px;
}
.catrow {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.catrow:last-child { border-bottom: none; }
.caticon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  flex: 0 0 auto;
  color: #0e1116;
}
.caticon.ico { padding: 0; }
.caticon.ico svg { width: 22px; height: 22px; display: block; }
.catmain { flex: 1; min-width: 0; }
.catname { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catcount { color: var(--muted); font-size: 13px; margin-top: 2px; }
.catsum { font-weight: 700; font-size: 15.5px; white-space: nowrap; }
.catsum.in { color: var(--accent); }

/* ---------- ops list ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 14px;
  outline: none;
}
.search:focus { border-color: var(--border); }
.search::placeholder { color: var(--muted); }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.filter-tag .x { color: var(--muted); font-size: 15px; }

.oprow {
  display: flex;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  align-items: flex-start;
}
.oprow:last-child { border-bottom: none; }
.oprow.hidden-op { opacity: .45; }
.opdate { color: var(--muted); font-size: 12.5px; width: 44px; flex: 0 0 auto; padding-top: 2px; }
.opmain { flex: 1; min-width: 0; }
.opdesc { font-size: 14.5px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.opmeta { color: var(--muted); font-size: 12.5px; margin-top: 3px; display: flex; gap: 6px; flex-wrap: wrap; }
.opmeta .edited { color: var(--blue); }
.opamount { font-weight: 700; font-size: 15px; white-space: nowrap; padding-top: 1px; }
.opamount.in { color: var(--accent); }
.opamount.out { color: var(--text); }

/* ---------- buttons / fields ---------- */
.btn {
  display: block;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 14px;
  font-weight: 700;
  font-size: 15.5px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08130c; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn + .btn { margin-top: 10px; }

.field {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
}
.field:focus { border-color: var(--accent); }
label.fl { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }

/* ---------- dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: var(--surface);
}
.dropzone.drag { border-color: var(--accent); color: var(--accent); }
.dropzone .dz-ico { font-size: 40px; display: block; margin-bottom: 10px; }
.dropzone b { color: var(--text); }

.progress-wrap { margin-top: 16px; }
.progress {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress > div { height: 100%; background: var(--accent); width: 0%; transition: width .2s; }
.progress-text { color: var(--muted); font-size: 13.5px; margin-top: 8px; }

/* ---------- result list ---------- */
.result {
  background: var(--surface);
  border-radius: 14px;
  padding: 13px 15px;
  margin-top: 10px;
  font-size: 14px;
}
.result .r-name { font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.result .r-meta { color: var(--muted); font-size: 13px; line-height: 1.5; }
.result.ok { border-left: 3px solid var(--accent); }
.result.warn { border-left: 3px solid #f1c40f; }
.result.err { border-left: 3px solid var(--danger); }

/* ---------- empty ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 44px 20px;
  line-height: 1.6;
}
.empty .e-ico { font-size: 44px; display: block; margin-bottom: 12px; }

/* ---------- section titles ---------- */
.sec-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 24px 0 10px; }

/* ---------- settings rows ---------- */
.srow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.srow:last-child { border-bottom: none; }
.srow .s-main { flex: 1; min-width: 0; }
.srow .s-name { font-weight: 700; font-size: 15px; }
.srow .s-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.srow .s-act { background: none; border: none; color: var(--blue); font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px; }
.srow .s-act.del { color: var(--danger); }

/* ---------- sheet ---------- */
#sheet-root { position: fixed; inset: 0; z-index: 60; }
#sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
#sheet {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow-y: auto;
  animation: sheet-up .22s ease;
}
@keyframes sheet-up { from { transform: translate(-50%, 40px); opacity: .5; } to { transform: translate(-50%, 0); opacity: 1; } }
#sheet-handle { width: 42px; height: 4px; background: var(--surface-3); border-radius: 2px; margin: 6px auto 12px; }
#sheet-title { font-size: 17px; font-weight: 800; margin-bottom: 6px; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  max-width: 90%;
  text-align: center;
}

/* ---------- misc ---------- */
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.mt { margin-top: 14px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- category screen ---------- */
.back-link {
  background: none; border: none; color: var(--muted);
  font-size: 14.5px; font-weight: 600; padding: 8px 0 2px; cursor: pointer;
}
.back-link:hover { color: var(--text); }
.cat-head { text-align: center; margin: 8px 0 4px; }
.cat-month { color: var(--muted); font-size: 15px; margin-bottom: 2px; text-transform: capitalize; }
.cat-head .big-sum { margin: 2px 0 8px; }
.count-pill {
  display: inline-block; background: var(--accent); color: #08130c;
  font-size: 13.5px; font-weight: 800; border-radius: 999px; padding: 4px 13px;
}

/* bars chart */
.bars {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 170px;
  margin: 18px 4px 22px;
  padding-bottom: 22px;
}
.bar-col {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  height: 100%; cursor: pointer; position: relative;
}
.bar {
  background: var(--surface-3);
  border-radius: 8px;
  min-height: 6px;
  transition: height .3s ease, background .2s;
}
.bar.sel { background: var(--accent); }
.bar-lbl {
  position: absolute; bottom: -20px; left: 0; right: 0; text-align: center;
  color: var(--muted); font-size: 11.5px; text-transform: uppercase; font-weight: 600;
}
.bar-lbl.sel { color: var(--text); }
.avg-line {
  position: absolute; left: 0; right: 0;
  border-top: 1px dashed rgba(255,255,255,.35);
  pointer-events: none;
  z-index: 2;
}
.avg-lbl {
  position: absolute; left: 0; top: -8px;
  background: var(--bg); color: var(--muted);
  font-size: 11.5px; line-height: 1.3; padding-right: 6px;
  z-index: 3;
}

/* switch */
.switch {
  width: 50px; height: 30px; border-radius: 999px; border: none;
  background: var(--surface-3); position: relative; cursor: pointer;
  flex: 0 0 auto; transition: background .18s; padding: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  transition: left .18s;
}
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; }

/* swipe actions */
.swipe-wrap { position: relative; overflow: hidden; }
.swipe-actions {
  position: absolute; inset: 0;
  display: flex; justify-content: flex-end;
}
.sa {
  width: 88px; border: none; color: #fff;
  font-size: 13px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sa.move { background: var(--blue); }
.sa.edit { background: var(--accent-2); }
.swipe-front {
  position: relative;
  background: var(--surface);
  transition: transform .22s ease;
  touch-action: pan-y;
  will-change: transform;
}
.swipe-front .caticon { margin-left: 0; }
.swipe-wrap .oprow { border-bottom: 1px solid var(--border); }
.group-ops { padding-left: 26px; background: rgba(0,0,0,.14); }
.group-ops .swipe-front { background: var(--surface); }

/* radio + pick rows */
.radio {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--muted); flex: 0 0 auto; position: relative;
}
.radio.on { border-color: var(--accent); }
.radio.on::after {
  content: ''; position: absolute; inset: 3px;
  border-radius: 50%; background: var(--accent);
}
.cat-pick { cursor: pointer; }
.cat-pick .caticon { width: 36px; height: 36px; font-size: 15px; }

/* info box */
.info-box {
  background: rgba(74, 158, 255, .12);
  border: 1px solid rgba(74, 158, 255, .35);
  color: #cfe4ff;
  border-radius: 14px;
  padding: 13px 15px;
  font-size: 13.5px;
  line-height: 1.5;
  margin: 14px 0 4px;
}
.apply-row { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 14px; }
.apply-row .s-name { font-weight: 600; font-size: 14.5px; line-height: 1.4; }
.list-card { padding-top: 0; }
.list-card .srow { border-bottom: 1px solid var(--border); }

/* ---------- ignored categories ---------- */
.struck { text-decoration: line-through; }
.catrow.ignored .catname,
.catrow.ignored .catsum,
.catrow.ignored .catcount { color: var(--muted); text-decoration: line-through; }
.catrow.ignored .caticon { opacity: .35; }
.srow .s-name.struck { color: var(--muted); text-decoration: line-through; }
.oprow.ignored-op .opdesc,
.oprow.ignored-op .opamount { color: var(--muted); text-decoration: line-through; }
.oprow.ignored-op .caticon { opacity: .35; }
.opmeta .struck { text-decoration: line-through; }
.big-sum.struck { color: var(--muted); text-decoration: line-through; }
.count-pill.muted { background: var(--surface-3); color: var(--muted); }
.ignored-block { opacity: .75; }
.ignored-block .oprow .opdesc,
.ignored-block .oprow .opamount,
.ignored-block .group-ops .opdesc { color: var(--muted); }

/* ---------- forecast + average rows ---------- */
.fc-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 13px;
  margin-top: 8px;
  line-height: 1.4;
}
.fc-row b { font-weight: 700; }
.fc-row.muted { color: var(--muted); }
.fc-row.muted b { color: var(--text); font-weight: 600; }
.fc-ico { flex: 0 0 auto; font-size: 15px; opacity: .8; }
.fc-hint { color: var(--danger); font-weight: 600; }

/* ---------- category limit (budget) ---------- */
.limit-row { padding: 14px 0 4px; border-bottom: 1px solid var(--border); }
.limit-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; font-size: 13.5px; color: var(--muted); font-weight: 600;
  margin-bottom: 9px;
}
.limit-val { color: var(--text); font-weight: 700; font-size: 14px; white-space: nowrap; }
.limit-val.over, .limit-sub .over { color: var(--danger); }
.limit-bar {
  height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden;
}
.limit-fill { height: 100%; border-radius: 999px; transition: width .35s ease; }
.limit-fill.ok { background: var(--accent); }
.limit-fill.warn { background: #f1c40f; }
.limit-fill.over { background: var(--danger); }
.limit-sub { font-size: 13px; color: var(--muted); margin-top: 8px; }
.limit-sub b { color: var(--text); }
