/* Чёрно-красно-белая тема: светлая — белый фон и чёрный текст, тёмная — чёрный фон и белый текст,
   акцент в обеих — красный. Тема следует за Telegram. */
:root {
  --bg: #f3f3f3;
  --card: #ffffff;
  --card2: #efefef;
  --text: #0b0b0b;
  --sub: #3d3d3d;
  --hint: #777777;
  --red: #d71920;
  --red-2: #a90f15;
  --red-soft: rgba(215, 25, 32, 0.10);
  --on-red: #ffffff;
  --sep: rgba(0, 0, 0, 0.08);
  --track: rgba(0, 0, 0, 0.08);
  --grid: rgba(0, 0, 0, 0.08);
  --axis: rgba(0, 0, 0, 0.28);
  --ink: #0b0b0b;          /* серия «доход» в графиках — цвет текста */
  --good: #14853b;
  --warn: #c98500;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #141414;
  --card2: #222222;
  --text: #ffffff;
  --sub: #d6d6d6;
  --hint: #8c8c8c;
  --red: #ff2d37;
  --red-2: #b3121a;
  --red-soft: rgba(255, 45, 55, 0.16);
  --sep: rgba(255, 255, 255, 0.08);
  --track: rgba(255, 255, 255, 0.10);
  --grid: rgba(255, 255, 255, 0.08);
  --axis: rgba(255, 255, 255, 0.30);
  --ink: #ffffff;
  --good: #3ccf6e;
  --warn: #f2b01e;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.38 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; }
.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 16px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.pos { color: var(--good); }
.neg { color: var(--red); }
.red { color: var(--red); }

.hello { display: flex; justify-content: space-between; align-items: center; margin: 2px 2px 12px; }
.hello .h { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.hello .h b { color: var(--red); }
.hello .d { color: var(--hint); font-size: 13px; text-align: right; }

.section-title { margin: 24px 4px 8px; font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--hint); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-title .aside { text-transform: none; font-weight: 500; letter-spacing: 0; }
.section-title button.aside { color: var(--red); font-weight: 600; }
.card { background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; position: relative; }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--card2); }
.row + .row::before, .bar-row + .bar-row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
.row.has-ico + .row.has-ico::before { left: 56px; }
.ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 16px;
  flex: none; background: var(--card2); }
.ico.red { background: var(--red-soft); }
.row .main { flex: 1; min-width: 0; }
.row .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .subt { font-size: 13px; color: var(--hint); margin-top: 1px; }
.row .right { text-align: right; flex: none; }
.chev { color: var(--hint); font-size: 18px; flex: none; margin-left: -4px; }
.empty { padding: 20px 14px; color: var(--hint); text-align: center; }
.badge { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 6px; font-weight: 600; }
.badge.red { background: var(--red); color: var(--on-red); }
.badge.soft { background: var(--red-soft); color: var(--red); }
.badge.green { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.btn { background: var(--red); color: var(--on-red); border-radius: 10px; padding: 7px 13px; font-size: 14px; font-weight: 700; }
.btn:active { background: var(--red-2); }
.btn.ghost { background: var(--card2); color: var(--text); }

/* главная цифра — красная карточка */
.hero { border-radius: 22px; padding: 18px 18px 16px; color: #fff; position: relative; overflow: hidden;
  background: radial-gradient(120% 140% at 100% 0%, #ff4b52 0%, #d71920 45%, #7d0a0f 100%); }
.hero.bad { background: radial-gradient(120% 140% at 100% 0%, #3a3a3a 0%, #151515 55%, #000 100%); }
.hero::after { content: ""; position: absolute; right: -40px; bottom: -60px; width: 180px; height: 180px; border-radius: 50%;
  border: 28px solid rgba(255, 255, 255, 0.07); }
.hero .label { font-size: 14px; opacity: .85; }
.hero .big { font-size: 38px; font-weight: 800; letter-spacing: -.03em; margin: 2px 0; line-height: 1.1; }
.hero.bad .big { color: #ff3b44; }
.hero .per-day { font-size: 15px; opacity: .95; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; position: relative; z-index: 1; }
.stat { background: rgba(0, 0, 0, 0.22); border-radius: 12px; padding: 9px 10px; min-width: 0; text-align: left; color: #fff; }
.hero.bad .stat { background: rgba(255, 255, 255, 0.07); }
.stat .k { font-size: 12px; opacity: .75; }
.stat .v { font-size: 15px; font-weight: 700; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.hero-actions { display: flex; gap: 8px; margin-top: 10px; position: relative; z-index: 1; flex-wrap: wrap; }
.hero-actions button { background: rgba(255, 255, 255, 0.16); color: #fff; border-radius: 10px; padding: 6px 11px; font-size: 13px; font-weight: 600; }

/* полоски */
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.meter > i.redbar { background: var(--red); }
.meter > i.warn { background: var(--warn); }
.bar-row { padding: 11px 14px; position: relative; }
.bar-row.tap { cursor: pointer; }
.bar-row.tap:active { background: var(--card2); }
.bar-head { display: flex; justify-content: space-between; gap: 10px; }
.bar-head .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }

/* месяц */
.month-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card);
  border-radius: 16px; padding: 6px; box-shadow: var(--shadow); }
.month-nav button { width: 42px; height: 36px; border-radius: 10px; font-size: 22px; color: var(--red); }
.month-nav button:disabled { color: var(--hint); opacity: .3; }
.month-nav .m { font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.tile { background: var(--card); border-radius: 16px; padding: 11px 13px; box-shadow: var(--shadow); }
.tile .k { font-size: 13px; color: var(--hint); }
.tile .v { font-size: 19px; font-weight: 800; margin-top: 2px; letter-spacing: -.01em; }
.day-head { padding: 9px 14px 3px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); }

/* графики */
.chart-card { background: var(--card); border-radius: 16px; padding: 12px 10px 10px; box-shadow: var(--shadow); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--sub); padding: 0 4px 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
svg { display: block; width: 100%; overflow: visible; }
svg text { fill: var(--hint); font-size: 11px; font-variant-numeric: tabular-nums; }
.detail { margin-top: 8px; padding: 10px 12px; background: var(--card2); border-radius: 12px; font-size: 14px; }
.detail .dl { display: flex; justify-content: space-between; gap: 8px; }
.detail .dl + .dl { margin-top: 3px; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }

/* «Ещё» */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gi { background: var(--card); border-radius: 16px; padding: 14px 8px 12px; text-align: center; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; min-height: 86px; }
.gi:active { background: var(--card2); }
.gi .e { font-size: 24px; width: 42px; height: 42px; border-radius: 12px; background: var(--red-soft); display: grid; place-items: center; }

/* нижние вкладки */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card);
  border-top: 1px solid var(--sep); display: flex; align-items: center; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px;
  color: var(--hint); padding: 4px 0; font-weight: 600; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--red); }
.tabs .add { flex: none; width: 54px; height: 46px; margin: 0 4px; border-radius: 16px; background: var(--red);
  color: var(--on-red); justify-content: center; box-shadow: 0 4px 14px rgba(215, 25, 32, 0.35); }
.tabs .add svg { width: 26px; height: 26px; }

/* окна поверх: «Записать» и экраны бота */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; display: none;
  padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.sheet.open { display: block; }
.sheet-head { position: sticky; top: 0; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; max-width: 560px; margin: 0 auto; }
.sheet-head .t { flex: 1; font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.xbtn { width: 34px; height: 34px; border-radius: 50%; background: var(--card2); font-size: 16px; color: var(--sub); flex: none; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--card2); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px 0; border-radius: 9px; font-weight: 700; color: var(--hint); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg button.on.exp { background: var(--red); color: var(--on-red); }
.amount-box { background: var(--card); border-radius: 16px; padding: 14px; margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.amount-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text);
  font-weight: 800; font-size: 32px; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.cur { display: flex; background: var(--card2); border-radius: 10px; padding: 3px; flex: none; }
.cur button { padding: 5px 11px; border-radius: 8px; font-weight: 700; color: var(--hint); }
.cur button.on { background: var(--text); color: var(--bg); }
.cur.locked { opacity: .55; pointer-events: none; }
.hint { font-size: 13px; color: var(--hint); margin: 7px 4px 0; min-height: 17px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips button { background: var(--card); border-radius: 12px; padding: 8px 11px; text-align: left; max-width: 100%;
  border: 1.5px solid transparent; font-weight: 600; }
.chips button.on { border-color: var(--red); background: var(--red-soft); }
.chips button .cs { display: block; font-size: 12px; color: var(--hint); margin-top: 1px; font-weight: 400; }
.field { width: 100%; border: 0; outline: 0; background: var(--card); color: var(--text); border-radius: 14px; padding: 13px 14px; }
.save { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); z-index: 3; }
.save button { width: 100%; max-width: 528px; display: block; margin: 0 auto; background: var(--red);
  color: var(--on-red); border-radius: 14px; padding: 15px; font-weight: 800; font-size: 16px; }
.save button:disabled { opacity: .5; }
body.tg-main #sheet .save { display: none; }

/* сообщения бота в приложении */
.msgs { display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.msg .body { white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg .body b { font-weight: 700; }
.msg .body pre { background: var(--card2); border-radius: 10px; padding: 10px; margin: 6px 0; overflow-x: auto;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
.msg .body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
  background: var(--card2); padding: 1px 5px; border-radius: 5px; }
.msg .body a { color: var(--red); }
.msg.faded { opacity: .55; }
.kb { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.kb .kr { display: flex; gap: 6px; }
.kb button { flex: 1; min-width: 0; background: var(--card2); border-radius: 11px; padding: 10px 8px; font-size: 14px;
  font-weight: 600; line-height: 1.25; }
.kb button:active { background: var(--track); }
.kb button.prim { background: var(--red); color: var(--on-red); }
.kb button.danger { color: var(--red); }
.kb button.back { background: none; color: var(--hint); }
.reply-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; background: var(--bg);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); display: none; }
.reply-bar.on { display: block; }
.reply-bar .in { max-width: 536px; margin: 0 auto; display: flex; gap: 8px; }
.reply-bar input { flex: 1; min-width: 0; border: 0; outline: 0; background: var(--card); color: var(--text);
  border-radius: 14px; padding: 13px 14px; }
.reply-bar button { width: 48px; border-radius: 14px; background: var(--red); color: var(--on-red); display: grid; place-items: center; }
.loading { position: relative; }
.loading::after { content: ""; position: fixed; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px;
  border: 3px solid var(--red-soft); border-top-color: var(--red); border-radius: 50%; animation: spin .7s linear infinite; z-index: 30; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; top: 14px; transform: translate(-50%, -140%); transition: transform .25s;
  background: #111; color: #fff; padding: 11px 16px; border-radius: 14px; z-index: 40; border-left: 4px solid var(--red);
  font-size: 14px; max-width: calc(100% - 32px); visibility: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.3); }
.toast.show { transform: translate(-50%, 0); visibility: visible; }
.center-msg { padding: 60px 24px; text-align: center; color: var(--hint); }
.skeleton { height: 190px; border-radius: 22px; background: var(--card); }

/* ---------- экраны «Ещё» ---------- */
#view { z-index: 9; }
#panel { z-index: 11; }
#sheet { z-index: 12; }
#viewBack { font-size: 24px; line-height: 1; padding-bottom: 3px; }
.hero.dark { background: radial-gradient(120% 140% at 100% 0%, #2e2e2e 0%, #151515 55%, #000 100%); }
:root[data-theme="dark"] .hero.dark { border: 1px solid rgba(255, 255, 255, 0.06); }
.hero .stat { cursor: default; }
.item-card { background: var(--card); border-radius: 18px; padding: 14px; margin-top: 10px; box-shadow: var(--shadow); display: block; }
.item-card[data-a] { cursor: pointer; }
.item-card[data-a]:active { background: var(--card2); }
.item-card .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.item-card .nm { font-weight: 700; font-size: 16px; line-height: 1.3; }
.item-card .amt { font-weight: 800; font-size: 17px; white-space: nowrap; letter-spacing: -.01em; }
.item-card .meta { font-size: 13px; color: var(--hint); margin-top: 5px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.item-card .status { font-size: 13px; margin-top: 8px; }
.item-card .status:empty { display: none; }
.chip2 { display: inline-block; background: var(--card2); color: var(--text); border-radius: 7px; padding: 1px 7px; font-size: 12px; font-weight: 700; margin-right: 4px; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.acts button { background: var(--card); border-radius: 14px; padding: 10px 12px; text-align: left; font-weight: 700; font-size: 14px;
  display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); line-height: 1.25; min-height: 52px; }
.acts button:active { background: var(--card2); }
.acts button .e { width: 32px; height: 32px; border-radius: 10px; background: var(--red-soft); display: grid; place-items: center; font-size: 16px; flex: none; }
.acts button.prim { background: var(--red); color: var(--on-red); }
.acts button.prim .e { background: rgba(255, 255, 255, 0.18); }
.acts button.prim:active { background: var(--red-2); }
.acts button.danger { color: var(--red); }
.acts button.wide { grid-column: 1 / -1; }
.item-card .acts { margin-top: 14px; }
.item-card .acts button { background: var(--card2); box-shadow: none; }
.item-card .acts button.prim { background: var(--red); }
.add-wide { display: block; width: 100%; margin-top: 14px; padding: 15px; border-radius: 16px; background: var(--red); color: var(--on-red);
  font-weight: 800; font-size: 16px; box-shadow: 0 4px 14px rgba(215, 25, 32, 0.25); }
.add-wide:active { background: var(--red-2); }
.link-row { text-align: center; margin-top: 12px; }
.link-row button { color: var(--red); font-weight: 700; padding: 8px 12px; }
.tl-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; position: relative; }
.tl-row + .tl-row::before { content: ""; position: absolute; top: 0; left: 36px; right: 0; border-top: 1px solid var(--sep); }
.tl-row .d { flex: none; }
.tl-row .tag { flex: 1; font-size: 12px; color: var(--hint); }
.tl-row .a { font-weight: 700; }
.tl-row.overdue .tag, .tl-row.overdue .a { color: var(--red); }
.tl-row.paid .d, .tl-row.paid .a { color: var(--hint); }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 2px solid var(--axis); }
.tl-dot.paid { background: var(--good); border-color: var(--good); }
.tl-dot.part { background: linear-gradient(90deg, var(--good) 50%, transparent 50%); border-color: var(--good); }
.tl-dot.overdue { background: var(--red); border-color: var(--red); }
.tl-dot.next { border-color: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.more-row { display: block; width: 100%; padding: 12px; color: var(--red); font-weight: 700; border-top: 1px solid var(--sep); }
.payout { display: flex; align-items: center; gap: 10px; padding: 11px 0 2px; border-top: 1px solid var(--sep); margin-top: 11px; }
.payout .main { flex: 1; min-width: 0; }
.payout .subt { font-size: 13px; color: var(--hint); margin-top: 2px; }
.payout .right { text-align: right; }
.pbtns { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.pbtns .btn { padding: 6px 10px; font-size: 13px; }
.card-acts { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.card-acts button { flex: 1; background: var(--card2); border-radius: 11px; padding: 9px 10px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.card-acts button.danger { color: var(--red); flex: 0 0 auto; }
.dep-grid, .proj { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.dep-grid > div, .proj > div { background: var(--card2); border-radius: 12px; padding: 9px 11px; min-width: 0; }
.dep-grid .k, .proj .k { font-size: 12px; color: var(--hint); }
.dep-grid .v, .proj .v { font-weight: 800; margin-top: 1px; }
.proj .v { color: var(--good); }
.pending { background: var(--red-soft); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.pending .pbtns { justify-content: flex-start; }
.tip { background: var(--card); border-radius: 16px; padding: 14px; margin-top: 10px; box-shadow: var(--shadow); line-height: 1.45;
  border-left: 4px solid var(--red); }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--track); position: relative; flex: none; transition: background .2s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .2s; }
.switch.on { background: var(--red); }
.switch.on i { left: 23px; }
.gi .gt { line-height: 1.2; }
.gi .gs { font-size: 12px; color: var(--hint); font-weight: 600; margin-top: -2px; }

/* карточка «Придёт» под главной — тёмная с зелёной суммой */
.hero.income { margin-top: 10px; background: radial-gradient(120% 140% at 100% 0%, #1d6a3f 0%, #0d2f1d 45%, #030a06 100%); }
.hero.income .big { color: #45e08c; }
.inc-list { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; position: relative; z-index: 1; }
.inc-row { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, 0.28); border-radius: 14px; padding: 10px 12px; }
.inc-row .e { width: 32px; height: 32px; border-radius: 10px; background: rgba(255, 255, 255, 0.1); display: grid; place-items: center; font-size: 16px; flex: none; }
.inc-row .main { flex: 1; min-width: 0; }
.inc-row .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inc-row .subt { font-size: 13px; opacity: .8; margin-top: 2px; }
.inc-row .right { text-align: right; flex: none; }
.inc-row .amt { font-weight: 800; color: #45e08c; }
.inc-row .btn { margin-top: 6px; }
.inc-row .badge.green { background: rgba(69, 224, 140, 0.18); color: #45e08c; }
