/* Цвета — из темы Telegram (app.js кладёт их в --tg-*), без неё — свои светлая и тёмная.
   Инлайн-стили запрещены CSP: ширины полос — классами .w-0…w-100. */
:root {
  --tg-bg-color: #ffffff;
  --tg-text-color: #15202b;
  --tg-hint-color: #7b8794;
  --tg-link-color: #2678b6;
  --tg-button-color: #2f8fdc;
  --tg-button-text-color: #ffffff;
  --tg-secondary-bg-color: #eff2f5;
  --tg-section-bg-color: #ffffff;
  --tg-section-separator-color: #e1e6eb;
  --tg-destructive-text-color: #d93636;
  --good: #1f9d55;
  --bad: #d93636;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg-theme) {
    --tg-bg-color: #17212b;
    --tg-text-color: #f1f4f7;
    --tg-hint-color: #8b9aa8;
    --tg-link-color: #62aef0;
    --tg-button-color: #3d9be0;
    --tg-secondary-bg-color: #0f161e;
    --tg-section-bg-color: #17212b;
    --tg-section-separator-color: #253341;
    --good: #3cc77a;
    --bad: #ff5b5b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--tg-secondary-bg-color);
  color: var(--tg-text-color);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 12px max(12px, env(safe-area-inset-right, 0px)) calc(76px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
}
main { display: grid; gap: 12px; max-width: 720px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 2px 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--tg-hint-color); margin: 6px 4px -4px; font-weight: 600; }
p { margin: 0; }
.boot { padding: 40px 12px; text-align: center; color: var(--tg-hint-color); }
.hint { color: var(--tg-hint-color); font-size: 13px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.card { background: var(--tg-section-bg-color); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.big { font-size: 28px; font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpis div { background: var(--tg-section-bg-color); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.kpis b { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list { background: var(--tg-section-bg-color); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--tg-section-separator-color); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; color: inherit; font: inherit; text-align: left; }
.row:last-child { border-bottom: 0; }
button.row { cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--tg-hint-color); }
.dot.income { background: var(--good); }
.dot.expense { background: var(--bad); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 0; border-radius: 999px; padding: 7px 13px; background: var(--tg-section-bg-color); color: var(--tg-text-color); font: inherit; font-size: 14px; cursor: pointer; }
.chip.on { background: var(--tg-button-color); color: var(--tg-button-text-color); }

.btn { border: 0; border-radius: 10px; padding: 11px 14px; background: var(--tg-button-color); color: var(--tg-button-text-color); font: inherit; font-weight: 600; cursor: pointer; width: 100%; }
.btn.ghost { background: var(--tg-section-bg-color); color: var(--tg-link-color); }
.btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
a { color: var(--tg-link-color); }
:focus-visible { outline: 2px solid var(--tg-button-color); outline-offset: 2px; }

.bar { height: 6px; border-radius: 3px; background: var(--tg-secondary-bg-color); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--tg-button-color); border-radius: 3px; }
.bar.expense i { background: var(--bad); }
.bar.income i { background: var(--good); }
.w-0 { width: 0; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; } .w-20 { width: 20%; }
.w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; } .w-45 { width: 45%; }
.w-50 { width: 50%; } .w-55 { width: 55%; } .w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; }
.w-75 { width: 75%; } .w-80 { width: 80%; } .w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; } .w-100 { width: 100%; }

.fields { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; }
.fields dt { color: var(--tg-hint-color); }
.fields dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.chart img { width: 100%; height: auto; border-radius: 8px; display: block; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--tg-section-bg-color); border-top: 1px solid var(--tg-section-separator-color); padding: 4px max(4px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px)); }
.tabs button { border: 0; background: none; color: var(--tg-hint-color); font: inherit; font-size: 11px; display: grid; justify-items: center; gap: 1px; padding: 6px 0; cursor: pointer; }
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--tg-button-color); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(72px + env(safe-area-inset-bottom, 0px)); background: var(--tg-text-color); color: var(--tg-bg-color); padding: 10px 14px; border-radius: 10px; max-width: calc(100% - 32px); font-size: 14px; }
.htmx-request.btn, .htmx-request.chip { opacity: .6; }
@media (prefers-reduced-motion: no-preference) { .bar i { transition: width .3s; } }
.split { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.split > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-flat { display: grid; gap: 4px; }
.right { text-align: right; flex: none; }
button.card { border: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; }
.back { border: 0; background: none; color: var(--tg-link-color); font: inherit; padding: 4px 2px; text-align: left; cursor: pointer; justify-self: start; }
.more { justify-content: center; color: var(--tg-link-color); }

/* формы */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--tg-hint-color); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 16px; color: var(--tg-text-color); background: var(--tg-section-bg-color);
  border: 1px solid var(--tg-section-separator-color); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
.field textarea { resize: vertical; }
.field-err { color: var(--bad); font-size: 13px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 8px; border-radius: 10px; background: var(--tg-section-bg-color); cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg.small label { font-size: 13px; padding: 7px 8px; }
.seg input { accent-color: var(--tg-button-color); margin: 0; }
.seg label.on, .seg label:has(input:checked) { outline: 2px solid var(--tg-button-color); }
.check { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.notice { border-radius: var(--radius); padding: 10px 14px; margin: 0; }
.notice.ok { background: color-mix(in srgb, var(--good) 14%, var(--tg-section-bg-color)); }
.notice.warn { background: color-mix(in srgb, #f0a020 18%, var(--tg-section-bg-color)); }
.notice.err { background: color-mix(in srgb, var(--bad) 14%, var(--tg-section-bg-color)); }
.danger { color: var(--bad); }
.btn.danger-fill { background: var(--bad); color: #fff; }
.link { border: 0; background: none; font: inherit; font-size: 13px; color: var(--tg-link-color); cursor: pointer; padding: 0; }
.row.col { display: grid; gap: 6px; }
.tabs .plus span { color: var(--tg-button-color); }
code, .value { font: 13px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.fills { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.upload { display: grid; gap: 8px; }
.upload input[type=file] { font: inherit; font-size: 14px; color: var(--tg-text-color); }
.select { font: inherit; font-size: 16px; color: var(--tg-text-color); background: var(--tg-section-bg-color); border: 1px solid var(--tg-section-separator-color); border-radius: 10px; padding: 10px 12px; width: 100%; }
label.row { cursor: pointer; }
label.row input { accent-color: var(--tg-button-color); width: 18px; height: 18px; flex: none; }
.pre { white-space: pre-line; overflow-wrap: anywhere; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
