/* --- Аванс Контроль: мобильное приложение (PWA) ---
   Только токены и компоненты UI-kit (kit.css — копия docs/ui-kit/kit.css).
   Здесь — мобильная раскладка: аппбар, карусели, нижняя кнопка, шторки, камера. */

:root {
  --appbar-h: 56px;
  --bottom-h: 88px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  font-variant-numeric: tabular-nums;
}
button { -webkit-tap-highlight-color: transparent; }
a { color: var(--brand-primary); }
[hidden] { display: none !important; }

.app { min-height: 100%; }
.splash { min-height: 100vh; display: grid; place-items: center; }

/* Общие мелочи поверх кита */
.btn-block { width: 100%; }
.btn-with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg, .icon-btn svg { flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--neutral-ink);
  cursor: pointer;
}
.icon-btn:active { background: var(--neutral-border); }
.icon { width: 24px; height: 24px; }
.icon-sm { width: 20px; height: 20px; }
.amount-negative { color: var(--status-error); }
.amount-positive { color: var(--status-success); }
.pending-text { color: var(--neutral-muted); }

/* --- Экраны входа (паттерн «Аутентификация» из кита) --- */
.auth-page {
  min-height: 100vh;
  padding: calc(24px + var(--safe-top)) var(--gutter) calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 16px;
  max-width: 480px; margin: 0 auto;
}
.auth-page .auth-screen-top { margin-top: 8px; }
.auth-page .auth-sub { max-width: none; }
.auth-page .card .field + .field,
.auth-page .card .field + .check,
.auth-page .card .check + .btn,
.auth-page .card .field + .btn { margin-top: 16px; }
.auth-page .check { align-items: flex-start; font-size: 14px; line-height: 1.45; }
.auth-page .check input { margin-top: 2px; flex-shrink: 0; }
.auth-page .alert { margin: 0; }
.auth-foot { margin-top: auto; text-align: center; }
.project-list { display: flex; flex-direction: column; }

/* --- Аппбар --- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--neutral-canvas);
}
.appbar.is-scrolled { box-shadow: 0 1px 0 var(--neutral-border); }
.appbar .org-switcher {
  min-width: 0; max-width: calc(100% - 56px);
  border: 0; background: transparent; font: inherit; text-align: left;
}
.appbar .org-switcher:active { background: var(--neutral-border); }
.appbar .org-logo { flex-shrink: 0; }
.appbar .org-info { min-width: 0; }
.appbar .org-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .org-chevron { margin-left: 12px; display: grid; }
.appbar-spacer { flex: 1; }
.appbar-title {
  flex: 1; min-width: 0;
  font-size: 17px; font-weight: 500; color: var(--neutral-ink-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- Главная --- */
.home {
  padding: 16px 0 calc(var(--bottom-h) + var(--safe-bottom) + 16px);
  max-width: 560px; margin: 0 auto;
}
.home > .section { padding: 0 var(--gutter); }
/* Предложение установить — фирменная полоса в самом верху, в края экрана */
.alert.install-banner {
  display: flex; align-items: center; gap: 12px;
  margin: 0; border-radius: 0;
  padding: calc(12px + var(--safe-top)) var(--gutter) 12px;
  background: var(--brand-primary); color: #fff;
}
.install-banner .alert-text { flex: 1; min-width: 0; color: rgba(255, 255, 255, .85); }
.install-banner .alert-text strong { color: #fff; }
.install-banner svg { color: #fff; flex-shrink: 0; }
.install-banner .btn { flex-shrink: 0; background: #fff; color: var(--brand-primary); }
.install-banner + .appbar { height: var(--appbar-h); padding-top: 0; }

/* Карусель карточек баланса */
.carousel {
  display: flex; gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  padding: 4px var(--gutter) 12px;
  scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }
.carousel > * { scroll-snap-align: start; flex: 0 0 100%; }
.carousel.is-multi > * { flex-basis: calc(100% - 24px); }
.dots { display: flex; justify-content: center; gap: 6px; height: 8px; margin: 0 0 8px; }
.dots span {
  width: 6px; height: 6px; border-radius: var(--radius-pill);
  background: var(--neutral-border); transition: width .2s ease, background .2s ease;
}
.dots span.is-active { width: 18px; background: var(--brand-primary); }

/* Карточка баланса: имя счёта → статус и сумма → прогноз с учётом чеков.
   Тон (tone-warn/info/success) даёт мягкий отсвет в углу и цвет акцентной полоски. */
.balance-card {
  --tone: var(--status-success);
  --tone-glow: rgba(22, 163, 74, .09);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 14px;
  height: 184px; padding: 20px 20px 16px;
  background:
    radial-gradient(130% 90% at 100% 0%, var(--tone-glow), transparent 60%),
    var(--neutral-surface);
  box-shadow: var(--shadow-card), inset 0 0 0 1px rgba(0, 0, 0, .035);
}
.balance-card::before {
  content: ""; position: absolute; left: 20px; top: 0;
  width: 32px; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--tone);
}
.balance-card.tone-warn { --tone: #e0a526; --tone-glow: rgba(217, 154, 34, .13); }
.balance-card.tone-info { --tone: var(--brand-primary); --tone-glow: rgba(56, 117, 249, .11); }
.balance-card .bc-name {
  height: 20px; line-height: 20px;
  font-size: 15px; font-weight: 500; color: var(--neutral-ink-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.balance-card .bc-name.is-brand {
  font-family: var(--font-brand); text-transform: uppercase;
  font-size: 13px; letter-spacing: .04em;
}
.balance-card .bc-main { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
.balance-card .bc-main .pill { white-space: nowrap; }
.balance-card .bc-amount {
  max-width: 100%; height: 42px;
  font-size: 36px; line-height: 42px; letter-spacing: -.025em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.balance-card .bc-amount.is-long { font-size: 30px; }
.balance-card .bc-amount.is-xlong { font-size: 25px; }
.balance-card .bc-forecast {
  margin-top: auto;
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 14px; line-height: 20px; color: var(--neutral-muted);
}
.balance-card .bc-forecast > span:first-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance-card .bc-forecast-value { flex-shrink: 0; white-space: nowrap; }

/* История */
.history-head { display: flex; align-items: baseline; justify-content: space-between; margin: 12px 0 8px; }
.history-head h3 { margin: 0; font-size: 16px; }
.history { padding: 8px 20px; }
.history .list-row { padding: 14px 0; text-decoration: none; color: inherit; }
.history .list-row:first-child { padding-top: 14px; }
.history .list-row:last-child { padding-bottom: 14px; }
.history .list-row.is-clickable { cursor: pointer; }
.history .avatar svg { width: 20px; height: 20px; }
.history .list-row > div:nth-child(2) { min-width: 0; flex: 1; }
.history .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .side { flex-shrink: 0; }
.history .side .title { font-variant-numeric: tabular-nums; }
.history .list-row.is-pending .title,
.history .list-row.is-pending .side .title { color: var(--neutral-muted); }
.history .list-row.is-pending .avatar { background: var(--neutral-canvas); color: var(--neutral-muted); }
.history .list-row.is-void .side .title { color: var(--neutral-muted); text-decoration: line-through; }
.history .pill { padding: 2px 10px; font-size: 12px; margin-top: 4px; }
.history-day { font-size: 13px; color: var(--neutral-muted); padding: 12px 0 0; }
.history-day:first-child { padding-top: 4px; }

/* Нижняя закреплённая кнопка */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 12px var(--gutter) calc(12px + var(--safe-bottom));
  background: linear-gradient(to bottom, rgba(246,246,246,0), var(--neutral-canvas) 28%);
}
.bottom-bar .btn { width: 100%; max-width: 528px; margin: 0 auto; display: flex; padding: 16px 24px; font-size: 17px; box-shadow: 0 8px 24px rgba(56,117,249,.28); }

/* --- Страницы (чек, настройки) --- */
.page { padding: 4px var(--gutter) calc(32px + var(--safe-bottom)); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page .card h3 { font-size: 15px; margin: 0 0 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--neutral-muted); }
.kv dd { margin: 0; text-align: right; color: var(--neutral-ink-strong); word-break: break-word; }
.items .list-row { align-items: flex-start; }
.items .list-row > div:first-child { min-width: 0; flex: 1; }
.receipt-hero { text-align: left; }
.receipt-hero .amount { font-size: 34px; }
.receipt-hero .amount.is-pending { color: var(--neutral-muted); }
.receipt-hero .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; font-size: 15px; }
.steps .step-num {
  width: 28px; height: 28px; border-radius: var(--radius-pill);
  background: var(--brand-primary-bg); color: var(--brand-primary);
  display: grid; place-items: center; font-weight: 500; font-size: 14px;
}
.steps .step-num.is-done { background: var(--status-success-bg); color: var(--status-success); }
.steps .step-num.is-current { background: var(--brand-primary); color: #fff; }
.steps .step-num.is-error { background: var(--status-error-bg); color: var(--status-error); }
.steps .muted { display: block; font-size: 13px; }
.inline-icon { display: inline-grid; place-items: center; vertical-align: -5px; width: 22px; height: 22px; color: var(--brand-primary); }
.settings-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 0; border: 0; border-bottom: 1px solid var(--neutral-border);
  background: none; font: inherit; color: var(--neutral-ink); text-align: left; cursor: pointer; text-decoration: none;
}
.settings-row:last-child { border-bottom: 0; }
.settings-row .grow { flex: 1; }
.settings-row svg { color: var(--neutral-muted); }
.version { text-align: center; font-size: 12px; color: var(--neutral-muted); }

/* --- Шторки (draggable bottom sheet) --- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.4);
  opacity: 0; transition: opacity .22s ease;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-height: 92vh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--neutral-surface);
  border-radius: var(--radius-m) var(--radius-m) 0 0;
  box-shadow: 0 -10px 25px rgba(0,0,0,.1);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-width: 640px; margin: 0 auto;
  touch-action: none;
}
.sheet.is-open { transform: translateY(0); }
.sheet.is-dragging { transition: none; }
.sheet-grip { padding: 10px 0 4px; display: grid; place-items: center; cursor: grab; flex-shrink: 0; }
.sheet-grip span { width: 40px; height: 5px; border-radius: var(--radius-pill); background: var(--neutral-border); }
.sheet-body {
  padding: 8px 20px calc(20px + var(--safe-bottom));
  overflow-y: auto; touch-action: pan-y;
  display: flex; flex-direction: column; gap: 16px;
}
.sheet-body h3 { margin: 0; font-size: 18px; }
.sheet-body .auth-sub { max-width: none; }
.sheet-actions { display: grid; gap: 8px; }
.sheet-actions.two { grid-template-columns: 1fr 1fr; }
.sheet-actions .btn { width: 100%; }
.sheet-amount { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sheet-amount .amount { font-size: 30px; }
.option-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px; border: 1px solid var(--neutral-border); border-radius: var(--radius-s);
  background: var(--neutral-surface); font: inherit; text-align: left; cursor: pointer; color: var(--neutral-ink);
}
.option-row + .option-row { margin-top: 8px; }
.option-row.is-active { border-color: var(--brand-primary); background: var(--brand-primary-bg); }
.option-row .grow { flex: 1; min-width: 0; }
.option-row .org-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--brand-primary-bg); border-top-color: var(--brand-primary);
  animation: spin .8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-line { display: flex; align-items: center; gap: 10px; font-size: 14px; }

/* --- Сканер --- */
.scanner {
  position: fixed; inset: 0; z-index: 50;
  background: #000; color: #fff; overflow: hidden;
}
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner-top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  padding-top: calc(8px + var(--safe-top));
  background: linear-gradient(to bottom, rgba(0,0,0,.55), rgba(0,0,0,0));
}
.scanner-bar { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.scanner-bar .icon-btn { color: #fff; background: rgba(0,0,0,.35); }
.scanner-bar .icon-btn.is-on { background: #fff; color: var(--neutral-ink-strong); }
.scanner-title { font-size: 15px; font-weight: 500; }
.scanner .carousel { padding-top: 8px; }
.scan-card { padding: 14px 16px; border-radius: var(--radius-s); display: flex; flex-direction: column; gap: 8px; color: var(--neutral-ink); }
.scan-card .row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.scan-card .card-name { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--brand-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-card .bal { font-size: 18px; font-weight: 500; color: var(--neutral-ink-strong); white-space: nowrap; }
.scan-card .meter { height: 8px; }
.scan-card .meter > span { transition: width .4s ease; }
.scan-card .meter-label { font-size: 13px; margin: 0; color: var(--neutral-ink); }
.scan-card .meter-label .muted { font-size: 13px; }
.scanner-frame {
  position: absolute; z-index: 1; left: 50%; top: 54%;
  width: min(68vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: var(--radius-m);
  box-shadow: 0 0 0 200vmax rgba(0,0,0,.35);
}
.scanner-frame i {
  position: absolute; width: 44px; height: 44px;
  border: 0 solid #fff; transition: border-color .2s ease;
}
.scanner-frame i:nth-child(1) { left: 0; top: 0; border-width: 4px 0 0 4px; border-top-left-radius: var(--radius-m); }
.scanner-frame i:nth-child(2) { right: 0; top: 0; border-width: 4px 4px 0 0; border-top-right-radius: var(--radius-m); }
.scanner-frame i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 4px 4px; border-bottom-left-radius: var(--radius-m); }
.scanner-frame i:nth-child(4) { right: 0; bottom: 0; border-width: 0 4px 4px 0; border-bottom-right-radius: var(--radius-m); }
.scanner-frame.is-hit i { border-color: var(--brand-primary-soft); }
.scanner-hint {
  position: absolute; z-index: 2; left: 0; right: 0;
  bottom: calc(32px + var(--safe-bottom)); padding: 0 24px;
  text-align: center; font-size: 15px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.scanner-error {
  position: absolute; z-index: 3; left: var(--gutter); right: var(--gutter); top: 50%; transform: translateY(-50%);
}
.scanner-error .card { color: var(--neutral-ink); display: flex; flex-direction: column; gap: 12px; }

/* --- Тосты --- */
.toasts {
  position: fixed; z-index: 80; left: var(--gutter); right: var(--gutter);
  bottom: calc(var(--bottom-h) + var(--safe-bottom) + 8px);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toasts .toast { pointer-events: auto; max-width: 528px; margin: 0 auto; width: 100%; animation: toast-in .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Скелетоны */
.skeleton { background: linear-gradient(90deg, var(--neutral-canvas), #ececec, var(--neutral-canvas)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-s); }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
