/* «Чекотека» мини-апп v2 (вариант F). Темы: «Как в Telegram» (по умолчанию, --tg-theme-*), светлая, тёмная, OLED.
   Шрифт — системный (SF на iPhone): приложение выглядит родным. Цвета категорий и акцента — системная палитра Apple (core.js). */
: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);
  --muted: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #6D6D72));
  --sep: var(--tg-theme-section-separator-color, #C6C6C8);
  --link: var(--tg-theme-link-color, var(--accent));
  --accent-text: var(--tg-theme-accent-text-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #D70015);
  --accent: #007AFF;
  --up: #C93400; --down: #248A3D; --warn: #C93400;
  --track: color-mix(in srgb, var(--muted) 18%, var(--card));
  --rest: color-mix(in srgb, var(--muted) 38%, var(--card));
  --muted-line: color-mix(in srgb, var(--muted) 60%, transparent);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --round: ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, system-ui, sans-serif;
}
[data-theme="light"] { --bg: #F2F2F7; --card: #FFFFFF; --text: #000000; --muted: #6D6D72; --sep: #C6C6C8; --link: var(--accent); --accent-text: color-mix(in srgb, var(--accent) 80%, #000); --danger: #D70015; }
[data-theme="dark"] { --bg: #1C1C1E; --card: #2C2C2E; --text: #FFFFFF; --muted: #A1A1A8; --sep: #48484A; --link: var(--accent); --accent-text: var(--accent); --danger: #FF6961; }
[data-theme="oled"] { --bg: #000000; --card: #1C1C1E; --text: #FFFFFF; --muted: #A1A1A8; --sep: #38383A; --link: var(--accent); --accent-text: var(--accent); --danger: #FF6961; }
[data-scheme="dark"] { --up: #FF9F0A; --down: #30D158; --warn: #FF9F0A; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.35 var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
button:disabled { opacity: .4; cursor: default; }
* { scrollbar-width: thin; scrollbar-color: var(--rest) transparent; }
[hidden] { display: none !important; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(96px + env(safe-area-inset-bottom)); }
.num, .big, .w-val, .amt, .kv { font-variant-numeric: tabular-nums; }
.sub { font-size: 13px; color: var(--muted); }
.hint { font-size: 13px; line-height: 1.4; color: var(--muted); margin: 8px 16px 16px; }
.muted { color: var(--muted); }
.bad { color: var(--danger) !important; }
.good { color: var(--down); }
.up { color: var(--up); } .down { color: var(--down); }

/* заголовки экранов */
.title { display: flex; justify-content: space-between; align-items: flex-end; padding: 8px 0 12px; }
.title h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.5px; display: flex; align-items: center; gap: 10px; }
.title .sub { margin: 0; }
.big-dot { width: 12px; height: 12px; }
.link { color: var(--link); font-size: 17px; min-height: 44px; display: inline-flex; align-items: center; }
.big-link { font-size: 17px; }
.link.strong { font-weight: 600; }
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; margin: 0 0 4px; }
.bar h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.bar > :last-child { justify-self: end; }

/* главная: сетка виджетов */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.w { background: var(--card); border-radius: 22px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.w-S { min-height: 148px; justify-content: space-between; }
.w-W { grid-column: 1 / -1; padding: 14px 16px; }
.wt { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.w-head { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 24px; }
.w-head .link { min-height: 24px; font-size: 15px; }
.w-total { display: inline-flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chev { color: var(--muted-line); flex: none; }
.w-val { display: flex; flex-direction: column; gap: 2px; }
.big { margin: 0; font-family: var(--round); font-size: 32px; font-weight: 700; letter-spacing: -0.6px; line-height: 1.08; }
.w-sub { font-size: 13px; color: var(--muted); }
.w-note { margin: 0; font-size: 14px; line-height: 1.35; color: var(--muted); }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; line-height: 1.25; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); } .delta.same { color: var(--muted); font-weight: 500; }
.delta svg { flex: none; }
.w-S .delta { align-items: flex-start; }
.w-S .delta svg { margin-top: 1px; }

.kuda { display: flex; align-items: center; gap: 16px; }
.kuda svg { flex: none; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lg { display: flex; align-items: center; gap: 8px; min-height: 30px; font-size: 15px; }
.lg i { width: 8px; height: 8px; border-radius: 4px; flex: none; }
.lg-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg.muted { font-size: 13px; color: var(--muted); }
.ring-big { fill: var(--text); font: 700 15px var(--font); font-variant-numeric: tabular-nums; }
.ring-small { fill: var(--muted); font: 11px var(--font); }
.ring-pct { fill: var(--text); font: 700 14px var(--font); font-variant-numeric: tabular-nums; }
.axis { fill: var(--muted); font: 10px var(--font); }
.axis.cur { fill: var(--text); font-weight: 600; }

.rings3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; }
.cell { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; padding: 2px 0; border-radius: 12px; }
.cell-name { font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-sub.warn { color: var(--warn); font-weight: 600; }
.cell-sub.bad { font-weight: 600; }
.one-limit { display: flex; justify-content: center; flex: 1; align-items: center; }

.month-s { display: flex; flex-direction: column; gap: 4px; }
.month-w { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kv { display: flex; flex-direction: column; }
.month-s .kv { flex-direction: row; justify-content: space-between; align-items: baseline; font-size: 15px; }
.month-w .kv .num { font-size: 19px; font-weight: 600; }
.rows { display: flex; flex-direction: column; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; border-bottom: 0.5px solid var(--sep); font-size: 16px; }
.row:last-child { border-bottom: 0; }
.row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-w { grid-column: 1 / -1; border: 1.5px dashed var(--rest); border-radius: 22px; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--link); font-size: 16px; }
.empty-w { text-align: center; }

/* списки в стиле настроек iOS */
.group { background: var(--card); border-radius: 12px; overflow: hidden; margin-bottom: 8px; }
.group.scroll { max-height: 60vh; overflow-y: auto; }
.group-title { margin: 20px 16px 6px; font-size: 13px; color: var(--muted); }
.cat-row, .edit-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px; width: 100%; border-bottom: 0.5px solid var(--sep); font-size: 16px; }
.group > :last-child, .group > .sub-block:last-child .cat-row { border-bottom: 0; }
.cat-row.tap:active, .cell:active, .lg:active, .w-head.tap:active { background: color-mix(in srgb, var(--text) 6%, transparent); }
.edit-main { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.edit-main > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.amt { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.dot { width: 10px; height: 10px; border-radius: 5px; flex: none; display: inline-block; }
.sq { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; color: #fff; }
.rm { width: 24px; height: 24px; border-radius: 12px; background: #FF3B30; color: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; }
.updown { display: flex; gap: 2px; }
.updown button { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.updown button:active { background: var(--track); }
.empty-row { margin: 0; padding: 16px; color: var(--muted); font-size: 15px; }
.group-btn { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 14px; background: var(--card); border-radius: 12px; margin-top: 20px; font-size: 16px; }
.group-btn.accent { color: var(--link); }
.plus-dot, .add-dot { width: 24px; height: 24px; border-radius: 12px; background: #34C759; color: #FFFFFF; display: flex; align-items: center; justify-content: center; flex: none; }
.add-dot { width: 30px; height: 30px; border-radius: 15px; }

/* сегменты */
.seg { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; background: var(--track); border-radius: 9px; padding: 2px; margin: 0 0 12px; }
.edit-main .seg { margin: 2px 0 0; justify-self: start; width: max-content; }
.seg button { text-align: center; padding: 6px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; min-height: 30px; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px color-mix(in srgb, #000 14%, transparent); }

/* куда уходит, категория */
.card { background: var(--card); border-radius: 14px; padding: 14px 16px 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.card .sub, .card p { margin: 0; }
.cmp { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.stack { display: flex; gap: 2px; height: 14px; margin-top: 8px; border-radius: 7px; overflow: hidden; }
.stack i { display: block; min-width: 2px; }
.cat-card { flex-direction: row; align-items: flex-end; gap: 16px; }
.cat-card .grow { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pbar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 4px; }
.pbar i { display: block; height: 100%; border-radius: 3px; }
.sub-block .cat-row.open .chev { transform: rotate(180deg); }
.sub-items { padding: 0 14px 10px 14px; border-bottom: 0.5px solid var(--sep); }
.item { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 14px; }

/* формы */
.input { width: 100%; border: 0; background: var(--card); color: var(--text); caret-color: var(--accent); border-radius: 12px; padding: 13px 14px; font: inherit; font-size: 16px; margin-bottom: 10px; }
.input::placeholder { color: var(--muted); }
.big-input { font-family: var(--round); font-size: 32px; font-weight: 700; text-align: center; }
.btn { width: 100%; min-height: 50px; border-radius: 12px; background: var(--accent); color: #FFFFFF; font-weight: 600; text-align: center; margin-top: 4px; }
.btn.ghost { background: transparent; color: var(--link); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--sep); }
.row-btns { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
.row-btns > :only-child { grid-column: 1 / -1; }
.chips-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 9px 12px; border-radius: 18px; background: var(--card); font-size: 15px; min-height: 40px; }
.chip.on { box-shadow: inset 0 0 0 2px var(--accent); }
.chip.more { color: var(--accent-text); }
.sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; z-index: 10; }
.sheet-body { width: 100%; max-width: 640px; margin: 0 auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); animation: up .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40px); opacity: .6; } }

/* оформление */
.swatch { width: 30px; height: 30px; border-radius: 8px; flex: none; border: 0.5px solid var(--sep); }
.sw-telegram { background: linear-gradient(135deg, #FFFFFF 50%, #17212B 50%); }
.sw-light { background: #F2F2F7; } .sw-dark { background: #2C2C2E; } .sw-oled { background: #000000; }
.tick { color: var(--accent); }
.accents { display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 4px 12px; }
.acc { width: 40px; height: 40px; border-radius: 20px; color: #FFFFFF; display: flex; align-items: center; justify-content: center; }
.acc.on { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px currentColor; }

/* нижняя панель */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep); padding: 6px 4px calc(8px + env(safe-area-inset-bottom)); }
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; justify-content: center; color: var(--muted); font-size: 10px; font-weight: 500; text-align: center; }
.tabs button.on { color: var(--accent); }
.tabs .fab { justify-self: center; width: 50px; height: 50px; min-height: 50px; border-radius: 25px; background: var(--accent); color: #FFFFFF; }
.tabs .fab.on { color: #FFFFFF; }

/* состояния */
.loading { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }
.sk { height: 72px; border-radius: 18px; background: var(--card); animation: pulse 1.2s ease-in-out infinite; }
.sk-big { height: 150px; }
@keyframes pulse { 50% { opacity: .55; } }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty p { margin: 0; max-width: 32ch; }
.empty .btn { max-width: 220px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 20; max-width: 90vw; }

/* одна анимация: кольца дорисовываются при первом открытии главной */
.intro .arc { animation: arcIn .9s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes arcIn { from { stroke-dasharray: 0 400; } }
@media (prefers-reduced-motion: reduce) { .intro .arc, .sheet-body, .sk { animation: none; } }

/* ПК: шире — две колонки виджетов остаются, текст крупнее не делаем */
@media (min-width: 700px) { main { padding-top: 20px; } }
