/* Splitty — дизайн-система.
 *
 * Мир продукта — стол в ресторане, а не финансовая панель. Отсюда тёплая
 * основа, аппетитный алый как основное действие и крупные скругления: экран
 * должен читаться как приложение, а не как таблица долгов.
 *
 * Цвет несёт смысл и только его: алый — действие, мятный — тебе должны,
 * ягодный — должен ты. Больше акцентов не вводим.
 */

@font-face {
  font-family: Onest;
  src: url('/static/fonts/onest-cyr.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: Onest;
  src: url('/static/fonts/onest-lat.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: Unbounded;
  src: url('/static/fonts/unbounded-cyr.woff2') format('woff2');
  font-weight: 600 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: Unbounded;
  src: url('/static/fonts/unbounded-lat.woff2') format('woff2');
  font-weight: 600 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --base: #fffcf9;
  --surface: #fff;
  --sunk: #f6f1ec;
  --ink: #171210;
  --ink-soft: #7a6e67;
  --line: #ece4dd;

  --flame: #ff5a36;
  --flame-ink: #fff;
  --flame-soft: #ffede7;

  --mint: #00a97f;
  --mint-soft: #e3f7f0;
  --berry: #e5484d;
  --berry-soft: #fdecec;

  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;
  --pill: 999px;

  --shadow-card: 0 1px 2px rgb(23 18 16 / .04), 0 8px 24px -12px rgb(23 18 16 / .10);
  --shadow-lift: 0 2px 6px rgb(23 18 16 / .06), 0 18px 40px -16px rgb(23 18 16 / .22);

  --gap: 12px;
  --pad: 18px;
  --ease: cubic-bezier(.32, .72, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --base: #14100e;
    --surface: #1e1917;
    --sunk: #171310;
    --ink: #f5efea;
    --ink-soft: #a2948b;
    --line: #2e2724;

    --flame: #ff6e4e;
    --flame-soft: #33201b;
    --mint: #3ed9ac;
    --mint-soft: #12312a;
    --berry: #f2696d;
    --berry-soft: #331b1d;

    --shadow-card: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -12px rgb(0 0 0 / .5);
    --shadow-lift: 0 2px 6px rgb(0 0 0 / .4), 0 18px 40px -16px rgb(0 0 0 / .7);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

/* Место под полосу прокрутки резервируется всегда: иначе её появление после
   загрузки списка сдвигает вёрстку вбок. */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--base);
  color: var(--ink);
  font: 400 16px/1.45 Onest, -apple-system, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.02em; }
p { margin: 0; }
button { font: inherit; color: inherit; }

/* Живой тёплый свет — только на входе, где экран пустой и его нечем занять.
   Внутри приложения фон статичен: анимация под списком трат отвлекает. */
.glow {
  position: fixed;
  inset: -30vmax -30vmax auto -30vmax;
  height: 70vmax;
  z-index: -1;
  background:
    radial-gradient(38% 38% at 22% 30%, color-mix(in oklab, var(--flame) 42%, transparent), transparent 70%),
    radial-gradient(34% 34% at 78% 22%, color-mix(in oklab, var(--mint) 30%, transparent), transparent 70%);
  filter: blur(40px);
  opacity: .45;
  will-change: transform;
  transform: translateZ(0);
  animation: drift 26s ease-in-out infinite alternate;
}

/* Двигаем только transform и без изменения масштаба: масштаб заставляет
   пересчитывать размытие каждый кадр, а сдвиг — нет. */
@keyframes drift {
  from { transform: translate3d(-3%, -2%, 0); }
  to   { transform: translate3d(5%, 3%, 0); }
}

/* --- каркас --- */

.app { max-width: 520px; margin-inline: auto; min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: max(env(safe-area-inset-top), 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--base) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
}
.topbar__title { font-size: 17px; text-align: center; }
.topbar__spacer { width: 40px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: var(--pill);
  background: var(--sunk);
  cursor: pointer;
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.screen {
  flex: 1;
  padding: 4px var(--pad) calc(env(safe-area-inset-bottom) + 96px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  animation: appear .22s var(--ease);
}
@keyframes appear { from { opacity: 0; } }

.eyebrow { font-size: 13px; font-weight: 600; color: var(--ink-soft); padding: 6px 2px 0; }

/* --- карточки и строки --- */

.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: var(--pad);
}
.card--flat { box-shadow: none; background: var(--sunk); }

.tile {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  padding: 16px var(--pad);
  border: 0; border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform .16s var(--ease);
}
.tile:active { transform: scale(.985); }
.tile__body { flex: 1; min-width: 0; overflow: hidden; }
.tile__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile__meta { font-size: 13px; color: var(--ink-soft); margin-top: 1px; }
.tile__title, .tile__meta { display: block; }
.tile__side { text-align: right; white-space: nowrap; }

/* --- деньги --- */

.amount { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: -.01em; }
.amount--hero {
  font-family: Unbounded, Onest, sans-serif;
  font-weight: 600;
  font-size: clamp(28px, 9vw, 44px);
  overflow-wrap: anywhere;
  letter-spacing: -.03em;
  line-height: 1.05;
}
.amount--plus { color: var(--mint); }
.amount--minus { color: var(--berry); }

/* --- кнопки --- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 17px 20px;
  border: 0; border-radius: var(--pill);
  background: var(--flame); color: var(--flame-ink);
  font-weight: 600; font-size: 16px;
  cursor: pointer;
  transition: transform .16s var(--ease), filter .16s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn:disabled { filter: grayscale(.6); opacity: .5; cursor: default; }
.btn--ghost { background: var(--sunk); color: var(--ink); }
.btn--quiet { background: none; color: var(--flame); padding: 12px; width: auto; }
.btn--tg { background: #2aabee; color: #fff; }

.fab {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: min(492px, calc(100% - 2 * var(--pad)));
  z-index: 30;
  box-shadow: var(--shadow-lift);
}

/* --- люди --- */

.avatar {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  border-radius: var(--pill);
  background: var(--flame-soft); color: var(--flame);
  font-size: 13px; font-weight: 600;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 26px; height: 26px; font-size: 11px; }
.avatar--lg { width: 46px; height: 46px; font-size: 16px; }

.stack { display: flex; }
.stack .avatar { margin-left: -8px; border: 2px solid var(--surface); }
.stack .avatar:first-child { margin-left: 0; }

/* --- позиции чека --- */

.line {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 14px 16px;
  border: 0; border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform .16s var(--ease);
}
.line:active { transform: scale(.985); }
.line__body { flex: 1; min-width: 0; overflow: hidden; }
.line__name, .line__meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .amount { flex: none; }
.line__name { font-weight: 500; }
.line__meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

/* Неразобранная позиция обязана бросаться в глаза: пока она есть,
   сумма долей не сходится с чеком, и расчёт неверен. */
.line--open {
  background: var(--flame-soft);
  box-shadow: none;
  outline: 2px dashed color-mix(in oklab, var(--flame) 45%, transparent);
  outline-offset: -2px;
}
.line--open .line__meta { color: var(--flame); font-weight: 600; }

.banner {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--flame-soft); color: var(--flame);
  font-size: 14px; font-weight: 600;
}
.banner--ok { background: var(--mint-soft); color: var(--mint); }

/* --- нижняя шторка --- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgb(0 0 0 / .4);
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed; z-index: 41;
  left: 0; right: 0; bottom: 0;
  max-width: 520px; margin-inline: auto;
  max-height: 86vh; overflow-y: auto;
  padding: 10px var(--pad) calc(env(safe-area-inset-bottom) + 18px);
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lift);
  animation: slide-up .32s var(--ease);
}
@keyframes slide-up { from { transform: translateY(100%); } }

.sheet__grip { width: 40px; height: 4px; border-radius: var(--pill); background: var(--line); margin: 0 auto 14px; }
.sheet__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }

/* --- доли --- */

.share {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.share:last-of-type { border-bottom: 0; }
.share__body { flex: 1; min-width: 0; overflow: hidden; }
.share__name, .share__sum { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share .avatar, .share .stepper { flex: none; }
.share__name { font-weight: 500; }
.share__sum { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.share--idle .share__sum { opacity: .45; }

.stepper { display: flex; align-items: center; gap: 4px; background: var(--sunk); border-radius: var(--pill); padding: 4px; }
.stepper button {
  width: 32px; height: 32px; border: 0; border-radius: var(--pill);
  background: transparent; font-size: 19px; line-height: 1; cursor: pointer;
  transition: background .14s var(--ease);
}
.stepper button:active { background: var(--surface); }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper__value { min-width: 22px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- балансы --- */

.balance { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.balance__body { flex: 1; min-width: 0; overflow: hidden; }
.balance .amount { flex: none; }
.balance__note { font-size: 13px; color: var(--ink-soft); }

.transfer {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-radius: var(--r-md);
  background: var(--sunk);
  font-weight: 500;
  min-width: 0;
}
.transfer > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer .amount { flex: none; margin-left: auto; }
.transfer__arrow { color: var(--ink-soft); flex: none; }

/* --- формы --- */

.field { display: block; }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 0 0 6px 2px; }
input, textarea, select {
  font: inherit; color: var(--ink);
  width: 100%; padding: 14px 16px;
  border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color .16s var(--ease);
}
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--flame); }
input::placeholder { color: color-mix(in oklab, var(--ink-soft) 70%, transparent); }

.seg { display: flex; gap: 6px; padding: 5px; background: var(--sunk); border-radius: var(--pill); }
.seg button {
  flex: 1; padding: 11px; border: 0; border-radius: var(--pill);
  background: transparent; font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--flame); box-shadow: var(--shadow-card); }

/* --- служебное --- */

.muted { color: var(--ink-soft); font-size: 14px; }
.center { text-align: center; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }
.empty__art { font-size: 40px; margin-bottom: 10px; }
.status { font-size: 14px; color: var(--ink-soft); text-align: center; min-height: 1.3em; white-space: pre-line; }
.status--error { color: var(--berry); }
.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

.steps { margin: 0; padding-left: 22px; color: var(--ink-soft); font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
.steps b { color: var(--ink); font-weight: 600; }

.scanner { position: relative; border-radius: var(--r-lg); overflow: hidden; background: #000; }
.scanner video { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.scanner__frame {
  position: absolute; inset: 16% 10%;
  border: 2.5px solid #fff; border-radius: var(--r-lg);
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .45);
}

:focus-visible { outline: 3px solid var(--flame); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .glow { animation: none; }
}

/* --- офлайн --- */

/* Полоса состояния поверх интерфейса: человек должен понимать, что его правки
   не потерялись, а ждут сети — иначе он начнёт делать их заново. */
.offline {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  z-index: 50;
  max-width: calc(100% - 2 * var(--pad));
  padding: 10px 16px;
  border-radius: var(--pill);
  background: var(--ink); color: var(--base);
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lift);
  animation: appear .22s var(--ease);
}
.offline--syncing { background: var(--mint); color: #fff; }
