/* ============================================================
   «Сочтёмся» — дизайн-система мини-аппа.
   Палитра целиком строится от темы Telegram (светлой и тёмной):
   акцент = кнопочный цвет темы, оттенки считает color-mix.
   ============================================================ */

:root {
  /* Поверхности: фон страницы — secondary, карточки — основной bg */
  --bg: var(--tg-theme-secondary-bg-color, #eef1f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #8b93a1);
  --link: var(--tg-theme-link-color, #2c7fdb);
  --accent: var(--tg-theme-button-color, #2c7fdb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);

  /* Производные оттенки (fallback — плоский акцент) */
  --accent-soft: rgba(44, 127, 219, 0.12);
  --accent-soft: color-mix(in srgb, var(--accent) 13%, transparent);
  --accent-softer: rgba(44, 127, 219, 0.07);
  --accent-softer: color-mix(in srgb, var(--accent) 7%, transparent);
  --accent-hi: var(--accent);
  --accent-hi: color-mix(in srgb, var(--accent), #ffffff 16%);
  --accent-lo: var(--accent);
  --accent-lo: color-mix(in srgb, var(--accent), #000000 14%);
  --grad: linear-gradient(135deg, var(--accent-hi), var(--accent-lo));

  --ok: #2fae60;
  --ok-soft: rgba(47, 174, 96, 0.12);
  --ok-soft: color-mix(in srgb, var(--ok) 13%, transparent);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.12);
  --danger-soft: color-mix(in srgb, var(--danger) 13%, transparent);

  --r-l: 20px;   /* крупные блоки */
  --r-m: 14px;   /* поля, вложенные элементы */
  --r-s: 10px;

  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 24px rgba(16, 24, 40, 0.06);
  --shadow-fab: 0 6px 20px rgba(16, 24, 40, 0.28);

  --divider: rgba(128, 134, 146, 0.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 640px; margin: 0 auto; padding: 14px 16px 104px; }

/* Появление экрана */
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
#app.anim { animation: screenIn 0.22s ease both; }

/* ---------- Типографика ---------- */

.screen-title {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em;
  margin: 8px 2px 14px;
}

.subtitle { color: var(--hint); font-size: 14.5px; margin: -8px 2px 16px; }

.section-label {
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--hint);
  margin: 20px 6px 8px;
}

.hint { color: var(--hint); font-size: 13px; }

.amount, .value {
  font-weight: 700; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.amount.pos { color: var(--ok); }
.amount.neg { color: var(--danger); }

/* ---------- Загрузка ---------- */

.loading { display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 70vh; color: var(--hint); gap: 14px; }

.spinner { width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

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

.card {
  background: var(--card);
  border-radius: var(--r-l);
  padding: 15px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.card.tappable { cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease; }
.card.tappable:active { transform: scale(0.977); }

.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
/* Подписи в строках списков — одной строкой с многоточием */
.row .grow .hint { white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }

.chevron { color: var(--hint); font-size: 22px; font-weight: 300;
  line-height: 1; opacity: 0.7; }

/* ---------- Аватары ---------- */

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px;
  background-image: linear-gradient(180deg, rgba(255,255,255,0.22),
    rgba(0,0,0,0.08));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}

/* Квадратная плитка группы */
.tile {
  border-radius: 14px;
  background-color: var(--accent);
  background-image: var(--grad);
  font-size: 20px;
  box-shadow: none;
}

.cat-avatar {
  background-color: transparent;
  background-image: none;
  background: var(--accent-softer);
  font-size: 20px;
  box-shadow: none;
}

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

.btn {
  display: block; width: 100%; border: none; border-radius: var(--r-m);
  background: var(--accent);
  background-image: var(--grad);
  color: var(--accent-text);
  font-size: 16px; font-weight: 700; padding: 15px; cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, opacity 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.985); filter: brightness(0.96); }

.btn.secondary {
  background: var(--accent-soft); background-image: none;
  color: var(--accent);
}
.btn.danger {
  background: var(--danger-soft); background-image: none;
  color: var(--danger);
}
.btn.ghost {
  background: transparent; background-image: none;
  color: var(--hint); font-weight: 600; box-shadow: none;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn + .btn { margin-top: 10px; }

.chip {
  border: none; background: var(--accent-soft); color: var(--accent);
  border-radius: 18px; padding: 9px 15px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: transform 0.12s ease;
}
.chip:active { transform: scale(0.95); }
.chip:disabled { opacity: 0.55; }

.fab {
  position: fixed; right: 18px; bottom: 24px; z-index: 5;
  width: 60px; height: 60px; border-radius: 20px; border: none;
  background: var(--accent); background-image: var(--grad);
  color: var(--accent-text);
  font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: var(--shadow-fab);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease;
}
.fab:active { transform: scale(0.9) rotate(6deg); }

/* ---------- Хиро-карточка баланса ---------- */

.balance-hero { text-align: center; padding: 22px 16px; }
.balance-hero .label { color: var(--hint); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; }
.balance-hero .value { font-size: 34px; font-weight: 800;
  letter-spacing: -0.02em; margin-top: 6px; }
.balance-hero .hint { margin-top: 4px; }

/* Акцентный вариант — градиент от темы */
.hero-accent {
  position: relative; overflow: hidden;
  background: var(--accent);
  background-image: var(--grad);
  color: var(--accent-text);
}
.hero-accent::before, .hero-accent::after {
  content: ""; position: absolute; border-radius: 50%;
  background: rgba(255, 255, 255, 0.09); pointer-events: none;
}
.hero-accent::before { width: 190px; height: 190px; right: -60px; top: -90px; }
.hero-accent::after { width: 130px; height: 130px; left: -50px; bottom: -70px; }
.hero-accent .label { color: rgba(255, 255, 255, 0.72); }
.hero-accent .value { color: var(--accent-text); }
.hero-accent .hint { color: rgba(255, 255, 255, 0.75); font-size: 13.5px; }

/* ---------- Экран группы ---------- */

.topline { display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 4px; }

.group-head { display: flex; align-items: center; gap: 12px; margin: 6px 2px; }
.group-head .emoji {
  width: 46px; height: 46px; border-radius: 15px; flex-shrink: 0;
  background: var(--accent); background-image: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 23px;
}
.group-head h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }

.tabs {
  display: flex; background: var(--card); border-radius: var(--r-m);
  padding: 4px; margin: 14px 0; position: sticky; top: 8px; z-index: 4;
  box-shadow: var(--shadow);
}
.tabs button {
  flex: 1; border: none; background: transparent;
  color: var(--hint); font-size: 15px; font-weight: 600;
  padding: 10px; border-radius: 11px; cursor: pointer; font-family: inherit;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.tabs button.active {
  background: var(--accent); background-image: var(--grad);
  color: var(--accent-text);
}

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

.bar-wrap { background: var(--accent-softer); border-radius: 6px; height: 8px;
  overflow: hidden; margin-top: 7px; }
.bar { height: 100%; border-radius: 6px;
  transform-origin: left; animation: growX 0.55s cubic-bezier(.2,.7,.3,1) both; }
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.settle-row { background: var(--card); }
.settle-row .settle-badge {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--ok-soft); color: var(--ok);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}

/* ---------- Пустые состояния ---------- */

.empty { text-align: center; color: var(--hint); padding: 44px 16px;
  font-size: 15px; }
.empty .big, .empty-icon {
  width: 84px; height: 84px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--accent-softer);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}

/* ---------- Формы ---------- */

.field { margin-bottom: 16px; }
/* Только подпись поля (не вложенные label вроде .checkline!) */
.field > label { display: block; font-size: 13px; font-weight: 600;
  color: var(--hint); margin: 0 4px 7px; }

input[type="text"], select {
  width: 100%; border: none; border-radius: var(--r-m);
  background: var(--card); color: var(--text);
  font-size: 16px; padding: 14px 15px; outline: none;
  appearance: none; -webkit-appearance: none; font-family: inherit;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease;
}
input[type="text"]::placeholder { color: var(--hint); opacity: 0.8; }
input[type="text"]:focus, select:focus {
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft),
    inset 0 0 0 1.5px var(--accent);
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--hint) 50%),
    linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 19px) 55%, calc(100% - 14px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.checkline { display: flex; align-items: center; gap: 11px;
  padding: 11px 2px; border-bottom: 1px solid var(--divider);
  font-size: 15px; font-weight: 500; color: var(--text); cursor: pointer; }
.checkline:last-child { border-bottom: none; }
.checkline input[type="checkbox"] { width: 21px; height: 21px;
  accent-color: var(--accent); flex-shrink: 0; }
.checkline .share-input { width: 98px; text-align: right; padding: 9px 11px;
  border-radius: var(--r-s); background: var(--bg); border: none;
  color: var(--text); font-size: 15px; outline: none; box-shadow: none;
  font-variant-numeric: tabular-nums; }
.checkline .share-input:focus { box-shadow: 0 0 0 2px var(--accent); }

.split-status { text-align: center; font-size: 14px; font-weight: 600;
  margin-top: 10px; }
.split-status.err { color: var(--danger); }
.split-status.ok { color: var(--ok); }

.seg { display: flex; background: var(--accent-softer);
  border-radius: var(--r-m); padding: 4px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: none; background: transparent;
  color: var(--hint); font-size: 14px; font-weight: 600;
  padding: 9px 6px; border-radius: var(--r-s); cursor: pointer;
  font-family: inherit;
  transition: background-color 0.18s ease, color 0.18s ease;
}
.seg button.active { background: var(--card); color: var(--accent);
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.12); }

/* ---------- Категории ---------- */

/* Чипы переносятся на строки — горизонтальный скролл недоступен мышью
   на десктопе, часть категорий была недостижима */
.cats { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px; }
.cat {
  flex-shrink: 0; border: none; background: var(--card);
  color: var(--text); border-radius: 18px; padding: 9px 14px;
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
  font-family: inherit; box-shadow: var(--shadow);
  transition: background-color 0.15s ease, color 0.15s ease,
    transform 0.12s ease;
}
.cat:active { transform: scale(0.95); }
.cat.active { background: var(--accent); background-image: var(--grad);
  color: var(--accent-text); font-weight: 600; }

/* ---------- Сканирование чека ---------- */

.scan-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.scan-row:empty { display: none; }

/* ---------- Статистика ---------- */

.stat-title { font-weight: 700; font-size: 16px; margin-bottom: 12px; }
.stat-row { padding: 8px 0; }
.stat-row .amount { font-size: 14px; }
.stat-emoji { font-size: 20px; width: 28px; text-align: center;
  flex-shrink: 0; }

/* ---------- Главный экран ---------- */

.home-head { display: flex; align-items: center; gap: 13px;
  margin: 10px 2px 18px; }
.home-head .screen-title { margin: 0; font-size: 24px; }
.home-head .hint { margin-top: 1px; }

.dev-banner {
  background: linear-gradient(135deg, #ffd66b, #ffb84d); color: #5c4300;
  font-size: 12.5px; font-weight: 600; text-align: center; padding: 8px;
  border-radius: var(--r-s); margin-bottom: 12px;
}

/* ---------- Донаты ---------- */

.donate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.donate-card { text-align: center; padding: 20px 10px; border: none;
  font-family: inherit; color: var(--text); margin-bottom: 0; }
.donate-card:disabled { opacity: 0.55; }
.donate-star { font-size: 30px; line-height: 1.1; }
.donate-num { font-size: 23px; font-weight: 800; margin-top: 6px;
  font-variant-numeric: tabular-nums; }

/* ---------- Оверлей «Позиции чека» ---------- */

.overlay { position: fixed; inset: 0; background: var(--bg); z-index: 20;
  overflow-y: auto; animation: overlayIn 0.25s cubic-bezier(.2,.7,.3,1) both; }
@keyframes overlayIn {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}
.overlay-inner { max-width: 640px; margin: 0 auto; padding: 16px 16px 44px; }

.item-off { opacity: 0.45; }
.item-off .amount { text-decoration: line-through; }

.item-x { border: none; background: var(--bg); color: var(--hint);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  font-size: 14px; flex-shrink: 0; font-family: inherit;
  transition: transform 0.12s ease; }
.item-x:active { transform: scale(0.88); }

.item-members { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 11px; }
.mchip {
  border: none; background: var(--accent-softer); color: var(--hint);
  border-radius: 15px; padding: 7px 13px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease,
    transform 0.1s ease;
}
.mchip:active { transform: scale(0.93); }
.mchip.on { background: var(--accent); background-image: var(--grad);
  color: var(--accent-text); }

/* ---------- Тост ---------- */

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(24, 27, 33, 0.94); color: #fff; font-size: 14px;
  font-weight: 500; padding: 12px 20px; border-radius: 16px; z-index: 50;
  max-width: 88%; text-align: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px);
  pointer-events: none; }
