/* Дизайн-система Mini App: цвета берём из темы Telegram, раскладка — сгруппированные списки в духе iOS/Telegram. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #8e8e93));
  --header: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #6d6d72));
  --link: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #007aff));
  --accent: var(--tg-theme-button-color, #007aff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .22));
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --pos: #30b25b;
  --neg: #ff453a;
  --warn: #ff9f0a;
  --field: rgba(128, 128, 128, .12);
  --radius: 14px;
  --nav-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #000000; --card: #1c1c1e; --text: #ffffff; --hint: #8e8e93; --header: #8e8e93; --sep: rgba(255,255,255,.12); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.num, .money { font-variant-numeric: tabular-nums; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }

/* --- заголовок экрана --- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 14px 4px 10px; }
.page-head h1 { font-size: 30px; line-height: 1.1; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.head-action { border: 0; background: none; color: var(--link); font-size: 16px; font-weight: 500; padding: 6px 0; cursor: pointer; }

/* --- «герой»: главная цифра экрана --- */
.hero { padding: 4px 4px 16px; }
.hero .label { color: var(--hint); font-size: 14px; }
.hero .value { font-size: 36px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.hero .meta { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* --- секции и сгруппированные списки --- */
.section { margin-bottom: 22px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; padding: 0 16px 7px;
  color: var(--header); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.section-title button { border: 0; background: none; color: var(--link); font-size: 14px; text-transform: none; letter-spacing: 0; padding: 0; cursor: pointer; }
.section-note { color: var(--hint); font-size: 13px; padding: 7px 16px 0; line-height: 1.4; }
.group { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.group + .group { margin-top: 10px; }
.pad { padding: 14px 16px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 52px; position: relative; width: 100%;
  border: 0; background: none; text-align: left; }
button.row, .row.tap { cursor: pointer; }
button.row:active, .row.tap:active { background: var(--field); }
.row + .row::before, .row + details::before, details + .row::before, details + details::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px; height: 1px; background: var(--sep); transform: scaleY(.5); }
.row.with-av + .row::before, .row.with-av + details::before, details.with-av + details::before { left: 64px; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--hint); font-size: 13px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.row .end .v { font-size: 16px; font-weight: 500; }
.row .end .d { font-size: 13px; margin-top: 1px; }
.row .chev { color: var(--hint); opacity: .5; font-size: 20px; margin-left: -4px; }
.row .mini-bar { margin-top: 7px; }

.av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  font-weight: 700; font-size: 15px; color: #fff; background: #8e8e93; letter-spacing: -.02em; }
.av.sq { border-radius: 11px; }
.av.sm { width: 30px; height: 30px; font-size: 13px; }

.pos { color: var(--pos); } .neg { color: var(--neg); } .hint { color: var(--hint); } .warn { color: var(--warn); }

/* --- плитки со статистикой --- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { color: var(--hint); font-size: 13px; }
.tile .v { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile .s { font-size: 12px; color: var(--hint); margin-top: 2px; }
.kv-list .row { min-height: 44px; }
.kv-list .row .body { color: var(--text); font-size: 15px; }
.kv-list .row .end .v { font-size: 15px; font-weight: 500; }

/* --- плашки, сегменты --- */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--field); color: var(--hint); white-space: nowrap; }
.pill.pos { background: rgba(48,178,91,.14); color: var(--pos); }
.pill.neg { background: rgba(255,69,58,.14); color: var(--neg); }
.pill.warn { background: rgba(255,159,10,.16); color: var(--warn); }
.pill.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--link); }

.seg { display: flex; background: var(--field); border-radius: 10px; padding: 2px; gap: 2px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; font-weight: 500;
  color: var(--text); white-space: nowrap; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.seg-wrap { margin: 0 0 10px; }

/* --- прогресс --- */
.bar { height: 6px; background: var(--field); border-radius: 3px; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.thick { height: 10px; border-radius: 5px; }
.bar .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .7; }
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.stack > i { display: block; height: 100%; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* --- цели --- */
.goal { padding: 16px; }
.goal + .goal { border-top: .5px solid var(--sep); }
.goal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal-name { font-size: 17px; font-weight: 600; }
.goal-date { color: var(--hint); font-size: 14px; white-space: nowrap; }
.goal-progress { display: flex; justify-content: space-between; font-size: 14px; margin: 10px 0 6px; font-variant-numeric: tabular-nums; }
.goal-progress b { font-weight: 600; }
.goal .tiles { margin-top: 12px; }
.goal .tile { background: var(--field); padding: 10px 12px; }
.goal .tile .v { font-size: 18px; }
.goal-status { margin-top: 12px; font-size: 14px; line-height: 1.35; }
.goal-status .pill { margin-bottom: 6px; }
.gs-line { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.gs-line span { color: var(--hint); }
.gs-line b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- таблица по месяцам --- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mtable th { white-space: nowrap; font-size: 12px; font-weight: 500; color: var(--hint); text-align: right; padding: 10px 8px 6px; }
.mtable th:first-child, .mtable td:first-child { text-align: left; padding-left: 16px; }
.mtable th:last-child, .mtable td:last-child { padding-right: 16px; }
.mtable td { text-align: right; padding: 9px 6px; font-size: 14px; white-space: nowrap; border-top: .5px solid var(--sep); vertical-align: top; }
.mtable td .r { font-size: 12px; margin-top: 1px; }
.mtable tr.total td { font-weight: 600; }

/* --- раскрывающиеся позиции --- */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary .chev { transform: rotate(90deg); }
details .inner { padding: 0 16px 14px; }
.lots th { font-size: 12px; color: var(--hint); font-weight: 500; text-align: right; padding: 6px 4px; }
.lots td { font-size: 13px; text-align: right; padding: 6px 4px; border-top: .5px solid var(--sep); }
.lots th:first-child, .lots td:first-child { text-align: left; }

/* --- кнопки --- */
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--card); color: var(--link); }
.btn.danger { background: var(--card); color: var(--danger); }
.btn.plain { background: var(--field); color: var(--text); }
.btn:disabled { opacity: .5; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack-gap > * + * { margin-top: 10px; }

/* --- нижняя навигация --- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.nav button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--hint); font-size: 10.5px; font-weight: 500; padding: 2px 0; cursor: pointer; position: relative; }
.nav button svg { width: 26px; height: 26px; }
.nav button.on { color: var(--link); }
.nav .badge { position: absolute; top: -2px; left: calc(50% + 6px); background: var(--neg); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }

/* --- шторки (формы, детали) --- */
dialog.sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 92vh;
  background: var(--bg); color: var(--text); border-radius: 16px 16px 0 0; overflow-y: auto;
  animation: up .22s ease-out; }
@media (min-width: 700px) { dialog.sheet { max-width: 560px; margin: auto; border-radius: 16px; } }
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-inner { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--hint); opacity: .35; margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-size: 20px; margin: 0; font-weight: 700; }
/* Закрыть — «светофор» macOS: насыщенный красный с лёгким объёмом, тёмный ободок, тёмно-красный крестик; 30 px */
.sheet-head .x { position: relative; flex-shrink: 0; width: 30px; height: 30px; padding: 0; border-radius: 50%;
  border: 1px solid #c8352e; background: radial-gradient(circle at 50% 30%, #ff7a72 0%, #ff5f57 45%, #e5453d 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35); cursor: pointer; outline: none; }
.sheet-head .x::after { content: ""; position: absolute; inset: 0; margin: auto; width: 13px; height: 13px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.4 2.4l7.2 7.2M9.6 2.4l-7.2 7.2' stroke='%23600a04' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat; }
.sheet-head .x:active { filter: brightness(.85); }

/* поля форм — сгруппированные строки */
.fields { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.field { display: flex; align-items: center; gap: 10px; padding: 0 16px; min-height: 48px; position: relative; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--sep); transform: scaleY(.5); }
.field > span { color: var(--text); font-size: 16px; flex-shrink: 0; min-width: 96px; }
.field input, .field select { flex: 1; min-width: 0; border: 0; background: none; color: var(--text); font: inherit; text-align: right;
  padding: 12px 0; outline: none; -webkit-appearance: none; appearance: none; }
.field select { direction: rtl; text-align-last: right; cursor: pointer; }
.field select option { direction: ltr; }
.field input::placeholder { color: var(--hint); opacity: .7; }
.field.stack { flex-direction: column; align-items: stretch; padding: 10px 16px; gap: 6px; }
.field.stack input { text-align: left; padding: 4px 0; }
.form-hint { color: var(--hint); font-size: 13px; padding: 0 16px 12px; line-height: 1.4; }
.form-error { color: var(--danger); font-size: 14px; padding: 0 16px 10px; min-height: 0; }
.form-error:empty { display: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 0 12px; }
.chips button { border: 0; background: var(--card); color: var(--link); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 500; cursor: pointer; }

.empty { text-align: center; color: var(--hint); padding: 28px 16px; font-size: 15px; }
.skeleton { color: var(--hint); padding: 18px 16px; font-size: 14px; }
.error-card { background: var(--card); border-radius: var(--radius); padding: 18px 16px; margin-top: 20px; }
svg.chart { display: block; width: 100%; height: auto; }
[hidden] { display: none !important; }

/* --- v0.9: подразделы «Ещё», чек-лист, счётчик --- */
.back-link { border: 0; background: none; color: var(--link); font-size: 16px; padding: 10px 4px 0; cursor: pointer; }
.badge-inline { background: var(--neg); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 1px 7px; margin-right: 6px; }
.checklist .row.check { gap: 12px; min-height: 46px; cursor: pointer; }
.checklist .row.check input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.checklist .row.check span { font-size: 15px; line-height: 1.3; }
.hero .value.pos { color: var(--pos); } .hero .value.neg { color: var(--neg); }
button.row[disabled] { cursor: default; opacity: 1; }
[hidden] { display: none !important; }

/* --- v0.10: подсказки «i» --- */
.tip { position: relative; display: inline-grid; place-items: center; width: 17px; height: 17px; margin: 0 0 0 5px; padding: 0;
  border: 1px solid currentColor; border-radius: 50%; background: none; color: var(--hint); font: italic 700 11px/1 Georgia, serif;
  vertical-align: 1px; cursor: pointer; opacity: .8; text-transform: none; letter-spacing: 0; }
.tip::after { content: ""; position: absolute; inset: -10px; }        /* палец попадает легко */
.section-title .tip { color: var(--header); border: 1px solid currentColor; padding: 0; font-size: 11px; }
.tip:hover { opacity: 1; color: var(--link); }
.tip-text { font-size: 16px; line-height: 1.5; margin: 0 2px 8px; }
