:root {
  --bg: #f3f4f7; --card: #ffffff; --text: #14171f; --muted: #5b6475; --line: #e6e9f0;
  --accent: #2f5bea; --accent-ink: #1d3fb8; --accent-soft: #eef2fe;
  --out: #c2410c; --in: #15803d; --danger: #b42318; --danger-soft: #fdecec;
  --r-lg: 22px; --r: 18px; --r-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: "Manrope", system-ui, sans-serif; font-size: 15px; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
/* Telegram в тёмной теме красит курсор в свой белый — на белом поле его не видно, и он закрывает
   буквы. Задаём свой цвет курсора и выделения — в любой теме Telegram и iOS. */
input, textarea { caret-color: var(--accent); }
::selection { background: rgba(47, 91, 234, .25); }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

main { padding: calc(18px + var(--safe-t)) 16px calc(150px + var(--safe-b)); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
main.bare { padding-bottom: calc(24px + var(--safe-b)); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 4px 0; }
.head h1 { font-size: 24px; font-weight: 800; margin: 0; }
.head .sub { color: var(--muted); font-size: 14px; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--card); display: inline-flex; align-items: center; justify-content: center; color: var(--text); text-decoration: none; flex-shrink: 0; }

.card { background: var(--card); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card.lg { border-radius: var(--r-lg); padding: 18px 20px; }
.card h2 { font-size: 15px; font-weight: 700; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* баланс: компоновка «Пульта» в стиле «Карточек» */
.bal-top { display: flex; align-items: baseline; justify-content: space-between; }
.bal-total { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.bal-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 12px; }
.bal-split > div { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.bal-split b { font-size: 18px; font-weight: 700; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--card); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text); border: none; text-align: left; }
.tile .val { font-size: 20px; font-weight: 700; }
.out { color: var(--out); } .in { color: var(--in); }

.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 3px; background: var(--bg); }
.legend { display: flex; flex-direction: column; gap: 8px; }
.legend a, .legend div { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); text-decoration: none; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .grow { flex-grow: 1; }

.list { background: var(--card); border-radius: var(--r); padding: 4px 16px; display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid #eef0f4; color: var(--text); text-decoration: none; }
.row:last-child { border-bottom: none; }
.row .ico { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.row .ico svg { width: 18px; height: 18px; }
.row .mid { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; }
.row .mid span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 700; white-space: nowrap; }
.day { font-size: 13px; font-weight: 700; color: var(--muted); padding: 12px 0 2px; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; border: none; background: var(--card); color: var(--muted); white-space: nowrap; font-weight: 600; }
.chip.on { background: var(--text); color: #fff; }
.card .chip { background: var(--bg); } .card .chip.on { background: var(--text); color: #fff; }
.month { display: flex; align-items: center; justify-content: space-between; }
.month button { width: 44px; height: 44px; border: none; border-radius: 22px; background: var(--card); font-size: 20px; }
.month span { font-weight: 700; font-size: 16px; }

.cats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cat { background: var(--card); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; border: 2px solid transparent; text-align: left; }
.cat.on { border-color: var(--accent); }
.cat .ico { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.cat .ico svg { width: 20px; height: 20px; }
.cat b { font-size: 19px; font-weight: 800; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 70px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div.zero { background: var(--line); }

/* карточка операции */
.hero { align-items: center; text-align: center; }
.hero .big { font-size: 38px; font-weight: 800; }
.hero .ico { width: 56px; height: 56px; border-radius: 18px; display: flex; align-items: center; justify-content: center; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pair > div { background: var(--bg); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.pair b { font-size: 17px; }

.btn { height: 52px; border-radius: 26px; border: none; font-weight: 700; font-size: 15px; padding: 0 20px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.soft { background: var(--card); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .5; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select { height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); padding: 0 14px; font-size: 16px; }
.code-input { font-size: 28px !important; letter-spacing: .4em; text-align: center; font-weight: 800; }
.err { color: var(--danger); font-size: 14px; }

/* нижняя панель: ввод + вкладки */
.composer { position: fixed; left: 0; right: 0; bottom: calc(62px + var(--safe-b)); padding: 10px 16px; display: flex; justify-content: center; pointer-events: none; z-index: 7; }
.composer-pill { pointer-events: auto; width: 100%; max-width: 528px; height: 56px; border-radius: 28px; background: var(--card); display: flex; align-items: center; gap: 8px; padding: 0 6px 0 18px; box-shadow: 0 2px 12px rgba(20, 23, 31, .10); }
.composer-pill input { flex-grow: 1; border: none; outline: none; background: transparent; font-size: 16px; min-width: 0; }
.mic { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cam { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.receipt-img { width: 100%; border-radius: 12px; display: block; background: var(--bg); min-height: 80px; }
.mic.rec { background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, .15); } }
.tabs { position: fixed; z-index: 7; left: 0; right: 0; bottom: 0; height: calc(62px + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); text-decoration: none; }
.tabs a.on { color: var(--accent); font-weight: 700; }

/* нижний лист: результат записи, правка */
.sheet { position: fixed; inset: 0; background: rgba(20, 23, 31, .35); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card { width: 100%; max-width: 560px; background: var(--bg); border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; max-height: 88vh; overflow-y: auto; }
.sheet-card #sheet-body { display: flex; flex-direction: column; gap: 12px; }
.result { white-space: pre-line; line-height: 1.5; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 0; }

/* переходы: застывшая копия старого экрана и новый экран поверх неё (непрозрачный до краёв) */
.ghost { position: fixed; inset: 0; background: var(--bg); overflow: hidden; pointer-events: none; }
.ghost > main { position: absolute; left: 0; right: 0; }
main.nav-top { position: relative; z-index: 6; min-height: 100vh; }
main.nav-top::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 50vw); width: 100vw; background: var(--bg); box-shadow: -10px 0 30px rgba(0, 0, 0, .12); z-index: -1; }

/* уточнение строк чеков */
.head-btns { display: flex; gap: 8px; }
.badge-btn { position: relative; color: var(--out); }
.badge { position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--out); color: #fff; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.qphoto { position: relative; height: 170px; overflow: hidden; border-radius: 12px; background: var(--bg); cursor: zoom-in; }
.qphoto img { position: absolute; left: 0; width: 100%; max-width: none; display: block; }
.qband, .qfull .qband { position: absolute; left: 0; right: 0; background: rgba(245, 158, 11, .25); box-shadow: inset 0 0 0 2px #f59e0b; border-radius: 6px; pointer-events: none; }
.qfull-wrap { position: relative; overflow: hidden; border-radius: 12px; }
.qfull { position: absolute; left: 0; right: 0; transform-origin: 50% 50%; transition: transform .25s ease; }
.qform { gap: 8px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; line-height: 1.4; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex-shrink: 0; margin: 0; cursor: pointer; transition: background .2s; }
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(20px); }
.switch:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.row .mid .small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
