/* Палитра — из темы Telegram (--tg-theme-*, их ставит telegram-web-app.js); свои токены
   только для групп денег и сигналов. Без Telegram (браузер, отладка) — палитра прототипа.
   docs/mini-app.md, «Техника»; design/miniapp/prototype.html. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f0f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --fg: var(--tg-theme-text-color, #11161d);
  --hint: var(--tg-theme-hint-color, #6c7682);
  --line: var(--tg-theme-section-separator-color, #e2e6ec);
  --accent: var(--tg-theme-button-color, #2b74c4);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2367b0);
  --danger: var(--tg-theme-destructive-text-color, #c4372f);
  --fixed: #5d6191;
  --fixed-soft: #e9e9f3;
  --save: #18805e;
  --save-soft: #e1f3ec;
  --hot: #b9541a;
  --hot-soft: #fbece2;
  --display: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17212b); --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
    --fg: var(--tg-theme-text-color, #f1f4f8); --hint: var(--tg-theme-hint-color, #8a9bad);
    --line: var(--tg-theme-section-separator-color, #253342);
    --accent: var(--tg-theme-button-color, #3478bd); --link: var(--tg-theme-link-color, #70b2ef);
    --danger: var(--tg-theme-destructive-text-color, #f07a72);
    --fixed: #a9acdc; --fixed-soft: #262a45; --save: #4cc79a; --save-soft: #143328;
    --hot: #f39a62; --hot-soft: #3a2517;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #17212b); --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
  --fg: var(--tg-theme-text-color, #f1f4f8); --hint: var(--tg-theme-hint-color, #8a9bad);
  --line: var(--tg-theme-section-separator-color, #253342);
  --accent: var(--tg-theme-button-color, #3478bd); --link: var(--tg-theme-link-color, #70b2ef);
  --danger: var(--tg-theme-destructive-text-color, #f07a72);
  --fixed: #a9acdc; --fixed-soft: #262a45; --save: #4cc79a; --save-soft: #143328;
  --hot: #f39a62; --hot-soft: #3a2517;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg2); color: var(--fg); font: 15px/1.4 var(--body); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

main {
  max-width: 430px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px;
  padding: calc(16px + var(--tg-content-safe-area-inset-top, 0px)) 16px calc(24px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
}

h1, h2, h3 { margin: 0; font-family: var(--display); text-wrap: balance; }
h3 { font: 600 13px var(--body); text-transform: uppercase; letter-spacing: .06em; color: var(--hint); padding-inline: 4px; display: flex; justify-content: space-between; gap: 8px; }
p { margin: 0; }
.hint { color: var(--hint); font-size: 13px; }
.big { font: 700 46px/1 var(--display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.group { display: flex; flex-direction: column; gap: 6px; }
.section { background: var(--section); border-radius: var(--r); overflow: hidden; }
.pad { padding: 14px 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 48px; color: var(--fg); }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .sub { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .val { color: var(--hint); white-space: nowrap; }
.row .amt { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.emo { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--bg2); font-size: 18px; }
.who { font-size: 11px; font-weight: 600; color: var(--hint); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 6px; }
.split { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 7px; }
.tag.ok { background: var(--save-soft); color: var(--save); }
.tag.hot { background: var(--hot-soft); color: var(--hot); }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--bg2); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font-size: 13px; color: var(--hint); min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--section); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.bar { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.over { background: var(--hot); }

.hero { display: flex; flex-direction: column; gap: 12px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
/* норма и копилка рендерятся обе, видна одна — переключатель запоминается (app.js) */
.hero[data-mode="norm"] .bank, .hero[data-mode="bank"] .norm { display: none; }

.banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r); background: var(--hot-soft); color: var(--hot); font-weight: 500; }
.empty { text-align: center; }
.denied { margin-top: 30vh; text-align: center; display: flex; flex-direction: column; gap: 8px; }

.loading { margin-top: 40vh; text-align: center; }

/* --- онбординг (templates/onboarding.html) --- */
.onb, .stack { display: flex; flex-direction: column; gap: 16px; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.lead { font-size: 16px; color: var(--hint); }
.small { font-size: 12px; line-height: 1.45; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }

.actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.btn-primary { min-height: 50px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-weight: 600; font-size: 16px; }
.btn-link { background: none; border: 0; color: var(--link); padding: 10px; font-size: 15px; align-self: center; }
/* в Telegram главное действие — MainButton внизу экрана (app.js) */
html.tg .only-web { display: none; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { min-height: 56px; text-align: left; padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--section); font-size: 16px; }
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.switch { cursor: pointer; }
.switch input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
label.section.switch { border-radius: var(--r); }

.field { display: flex; gap: 8px; align-items: center; }
input, select { font: inherit; color: var(--fg); background: var(--section); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; min-width: 0; }
.field input { flex: 1; }
.round { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg); font-size: 22px; }

.orow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 8px 10px 12px; }
.orow + .orow { border-top: 1px solid var(--line); }
.orow .grow { flex: 1 1 0; min-width: 6em; }
.orow .money { width: 6.2em; text-align: right; font-variant-numeric: tabular-nums; }
.orow .day { width: 3.6em; text-align: center; padding-inline: 6px; }
.x { width: 36px; height: 36px; flex: none; border: 0; background: none; color: var(--hint); font-size: 22px; }
.prow .opts { display: flex; gap: 8px; flex-basis: 100%; flex-wrap: wrap; }
.prow .opts select { padding: 6px 8px; min-height: 36px; font-size: 14px; }
.prow .opts .day { min-height: 36px; padding-block: 6px; font-size: 14px; width: 4.2em; }
.prow:not(.yearly) .month { display: none; }

.seg.wide { display: grid; grid-template-columns: repeat(3, 1fr); }
.seg label { display: grid; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label span { text-align: center; padding: 8px 12px; border-radius: 7px; font-size: 14px; color: var(--hint); cursor: pointer; }
.seg input:checked + span { background: var(--section); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg input:focus-visible + span { outline: 2px solid var(--link); }

.preview { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 8px; padding: 12px 16px; border-radius: var(--r); background: var(--section); min-height: 1em; }
.preview:empty { display: none; }
.preview .full { flex-basis: 100%; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .total { border-top: 1px solid var(--line); padding-top: 8px; }
.funnel .per { display: block; text-align: right; color: var(--hint); font-size: 12px; font-weight: 400; }

/* --- вкладки и «Семья» --- */
main:has(.tabs) { padding-bottom: calc(88px + var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--hint); min-height: 52px; }
.tabs a[aria-current="page"] { color: var(--link); }
.tabs svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

a.row { color: var(--fg); }
button.row { background: none; border: 0; width: 100%; text-align: left; font: inherit; color: var(--fg); }
button.row[disabled] { opacity: .5; cursor: default; }
.row + .row, .row + .invite, .invite + .row { border-top: 1px solid var(--line); }
.chev { color: var(--hint); font-size: 18px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--section); border-radius: 999px; padding: 6px 12px; font-size: 13px; min-height: 32px; white-space: nowrap; }
.chip-radio input { position: absolute; opacity: 0; pointer-events: none; }
.chip-radio { position: relative; }
.chip-radio span { display: inline-block; border: 1px solid var(--line); background: var(--section); border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer; }
.chip-radio input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip-radio input:focus-visible + span { outline: 2px solid var(--link); }
.invite { flex-wrap: wrap; }
.invite .grow { flex: 1 1 100%; }
.row .sub.wrap { white-space: normal; }
.invite:not(.waiting) .grow { color: var(--hint); }
.sub-cat { padding-left: 32px; }
.family-title { display: flex; gap: 8px; align-items: center; }
.family-title input { flex: 1; font: 700 22px var(--display); border-color: transparent; background: transparent; padding-inline: 4px; }
.family-title input:focus { border-color: var(--line); background: var(--section); }

.member-head { display: flex; gap: 14px; align-items: center; }
.big-emo { width: 56px; height: 56px; font: 600 24px var(--display); background: var(--section); }
.row.danger, .btn-danger { color: var(--danger); }
.btn-primary.btn-danger { background: var(--danger); color: #fff; }

/* --- админка --- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats div { background: var(--section); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stats b { font: 700 22px var(--display); }
.stats span { font-size: 12px; color: var(--hint); }
.tag.soft { background: var(--bg2); color: var(--hint); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.round.ghost { background: var(--bg2); color: var(--fg); }
textarea { font: inherit; color: var(--fg); background: var(--section); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; resize: vertical; min-height: 120px; }
.bubble { align-self: flex-start; max-width: 100%; background: var(--section); border-radius: 16px 16px 16px 4px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.bubble-btn { margin-top: 8px; text-align: center; padding: 8px; border-radius: 10px; background: var(--bg2); color: var(--link); font-size: 14px; white-space: normal; }
.prow .mark { align-self: center; font-size: 13px; color: var(--hint); }
.prow .mark.ok { color: var(--save); }
/* --- история --- */
.filters { gap: 8px; }
.filters select { flex: 1; }
input[type="search"] { width: 100%; }
.day-head { display: flex; justify-content: space-between; margin: 8px 4px 0; font-size: 13px; font-weight: 600; color: var(--hint); }
.more { padding: 16px; text-align: center; }
.banner .btn-primary { margin-top: 10px; width: 100%; }
.seg.two { display: grid; grid-template-columns: 1fr 1fr; }
.seg a { text-align: center; padding: 8px 12px; border-radius: 7px; font-size: 14px; color: var(--hint); }
.seg a[aria-selected="true"] { background: var(--section); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; font: 600 17px var(--display); }
.round-spacer { width: 44px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head { text-align: center; font-size: 11px; color: var(--hint); }
.cal-day { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 0; border-radius: 10px; background: var(--section); color: var(--fg); min-height: 46px; font-size: 14px; }
.cal-day span { font-size: 10px; color: var(--hint); }
.cal-day.ok { background: var(--save-soft); }
.cal-day.warm { background: color-mix(in srgb, var(--hot-soft) 50%, var(--section)); }
.cal-day.hot { background: var(--hot-soft); }
.cal-day.free { box-shadow: inset 0 0 0 1.5px var(--save); }
.cal-day.future { opacity: .4; }
.cal-day.today b { color: var(--link); }
.paid { color: var(--save); }
.field .money { width: 7em; flex: none; text-align: right; }

/* --- ввод трат на «Сегодня» (webapp/entry.py) --- */
.entry { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.entry input { flex: 1; }
.entry .btn-primary { min-height: 44px; width: 52px; flex: none; font-size: 20px; }
.entry-wait { display: none; width: 100%; }
.entry.htmx-request .entry-wait { display: block; }
.row-link { color: var(--fg); min-width: 0; }
.btn-ok { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0; background: var(--save-soft); color: var(--save); font-size: 18px; font-weight: 700; }

/* --- «Чаты с ботом» в админке (admin_chat.html) --- */
.chat { display: flex; flex-direction: column; gap: 8px; }
.chat-day { text-align: center; font-size: 12px; margin: 6px 0 2px; }
.msg { max-width: 86%; padding: 8px 12px; border-radius: 14px; background: var(--section); display: flex; flex-direction: column; gap: 3px; }
.msg.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--fixed-soft); }
.msg.bad { box-shadow: inset 0 0 0 1px var(--hot); }
.msg .meta { font-size: 12px; color: var(--hint); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg .run { font-size: 12px; color: var(--save); }
.msg .run.bad { color: var(--hot); }
.msg .ids { font-size: 11px; }

/* --- кабинет семьи: полоса сверху на всех экранах (app.js) --- */
.cabinet { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--hot-soft); color: var(--hot); font-size: 14px; font-weight: 500; }
.cabinet[hidden] { display: none; }
.cabinet span { flex: 1; min-width: 0; }
.cabinet button { background: none; border: 0; color: var(--link); font: inherit; padding: 4px; }

/* --- фото чека в карточке траты (webapp/photos.py); тап — во весь экран --- */
.receipts { display: flex; gap: 8px; overflow-x: auto; }
.receipts img { height: 180px; width: auto; max-width: 100%; border-radius: var(--r); background: var(--section); object-fit: cover; cursor: zoom-in; }
.zoom { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; overflow: auto; }
.zoom img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* --- правка позиции чека в карточке траты --- */
.item-edit { gap: 8px; }
.item-edit select { flex: 1; }
.chip.danger { color: var(--danger); }
.row .link { color: var(--link); }
