/* «Где кэшбеки» — дизайн-система и вёрстка.
   Токены и размеры — docs/04-ux-ui.md §5; строка сводки — §6.
   Mobile-first, без внешних шрифтов и иконок. */

:root {
  --bg: #FFFFFF;
  --surface: #F5F6F8;
  --line: #D8DCE2;
  --text: #14181F;
  --muted: #5A6472;
  --accent: #1F6FEB;
  --accent-ink: #FFFFFF;
  /* Акцент как цвет текста: в тёмной теме базовый --accent на фоне не
     дотягивает до 4,5 : 1, поэтому для ссылок и подписей он светлее. */
  --accent-text: #1F6FEB;
  --warn-ink: #8A4B00;
  --warn-bg: #FFF4E0;
  --danger: #B42318;

  --r-field: 8px;
  --r-card: 12px;
  --r-chip: 999px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;

  --tap: 44px;
  --btn: 48px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 2px rgba(20, 24, 31, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1216;
    --surface: #171C22;
    --line: #2A3138;
    --text: #ECEEF1;
    --muted: #A6AEBA;
    --accent: #2E6BE6;
    --accent-ink: #FFFFFF;
    --accent-text: #6E9BFF;
    --warn-ink: #F2C078;
    --warn-bg: #2A1F0E;
    --danger: #FF8A80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/24px var(--font);
  overscroll-behavior-y: contain;
}

h1, h2, p, ul, li, form { margin: 0; padding: 0; }
ul { list-style: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.muted { color: var(--muted); font-size: 15px; line-height: 20px; }

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

#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--s4) calc(140px + env(safe-area-inset-bottom));
}

.screen { padding-top: var(--s4); }

.screen-loading { padding-top: 40vh; text-align: center; }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: var(--s3); }

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--tap);
  padding: var(--s2) 0;
}

.topbar-title {
  font-size: 20px;
  line-height: 26px;
  font-weight: 600;
  letter-spacing: -.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screen-sub {
  margin: 0 0 var(--s3);
  color: var(--muted);
  font-size: 15px;
  line-height: 20px;
}

/* ------------------------------------------------------------- нет сети */

.netbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s3);
  max-width: 480px;
  margin: 0 auto;
  padding: var(--s3) var(--s4);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 15px;
  line-height: 20px;
  border-bottom: 1px solid var(--line);
}

.netbar-text { flex: 1; }

.netbar-retry {
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid currentColor;
  border-radius: var(--r-chip);
  background: transparent;
  color: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  width: 100%;
  min-height: var(--btn);
  padding: 0 var(--s4);
  border: 1px solid transparent;
  border-radius: var(--r-card);
  background: transparent;
  font-size: 17px;
  line-height: 22px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: transform .08s ease, filter .12s ease, opacity .12s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.99); filter: brightness(.94); }
.btn:disabled, .btn.is-loading { opacity: .4; pointer-events: none; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--bg); border-color: var(--line); color: var(--text); }
.btn-danger-text { background: transparent; color: var(--danger); }
.btn-danger-text:active { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.btn.is-loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

.link-btn {
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  background: transparent;
  color: var(--accent-text);
  font-size: 16px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: 0;
  border-radius: var(--r-field);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active { background: var(--surface); }
.icon-btn:disabled { opacity: .3; pointer-events: none; }

.avatar {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

/* --------------------------------------------------------------- поля */

.card {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s4);
  margin-bottom: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--bg);
  box-shadow: var(--shadow);
}

.card-warn { background: var(--warn-bg); border-color: transparent; }

.card-title,
.group-name {
  font-size: 17px;
  line-height: 24px;
  font-weight: 600;
}

.card-note {
  padding: var(--s3);
  border-radius: var(--r-field);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 15px;
  line-height: 20px;
}

.card-note-strong { font-weight: 600; color: var(--warn-ink); }

.field { display: flex; flex-direction: column; gap: var(--s2); }

.field > label,
.field > .label {
  color: var(--muted);
  font-size: 15px;
  line-height: 20px;
}

.input-row { display: flex; align-items: center; gap: var(--s2); }
.input-row > input { flex: 1; min-width: 0; }

.input-suffix {
  flex: none;
  color: var(--muted);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  min-height: var(--btn);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-field);
  background: var(--surface);
  color: var(--text);
  /* 16px и больше: иначе iOS увеличивает страницу при фокусе */
  font-size: 17px;
  line-height: 24px;
  -webkit-appearance: none;
  appearance: none;
}

select {
  padding-right: 36px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    right 18px top 22px,
    right 12px top 22px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

input::placeholder { color: var(--muted); opacity: .8; }

input:focus, select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--tap);
  color: var(--text);
  font-size: 16px;
  line-height: 22px;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  flex: none;
  margin: 0;
  /* 16px и больше: iOS не увеличивает страницу при фокусе */
  font-size: 16px;
  accent-color: var(--accent);
}

.segmented {
  display: flex;
  gap: var(--s1);
  padding: var(--s1);
  border-radius: var(--r-field);
  background: var(--surface);
}

.seg {
  flex: 1;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.seg.is-on {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.quick {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  padding-bottom: var(--s1);
  scrollbar-width: none;
}

.quick::-webkit-scrollbar { display: none; }

.quick-btn {
  flex: none;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-chip);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.quick-btn:active { background: var(--surface); }

.form-error {
  padding: var(--s3);
  border-radius: var(--r-field);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 15px;
  line-height: 20px;
}

.actions { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s2); }

/* --------------------------------------------------------------- вход */

.auth-brand { padding: var(--s5) 0 var(--s5); }

.auth-title {
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.auth-brand .muted { margin-top: var(--s1); }

.auth-alt {
  margin: var(--s2) 0 var(--s4);
  text-align: center;
}

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

.monthbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: var(--s2) 0 var(--s3);
}

.month-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 22px;
  font-size: 17px;
  font-weight: 600;
}

.month-title .today {
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  font-weight: 400;
}

.chips {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  padding: 0 0 var(--s3);
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-chip);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.summary { display: flex; flex-direction: column; }

.summary-group { padding-top: var(--s3); }
.summary-group + .summary-group { margin-top: var(--s1); }

.summary-head {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.summary-head-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-head-count { flex: none; letter-spacing: 0; font-weight: 400; }

.rows { border-top: 1px solid var(--line); }

.row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--s3) 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.row:active { background: var(--surface); }
.row.is-locked { cursor: default; }

.row-main { flex: 1; min-width: 0; }

.row-cat {
  display: block;
  font-size: 17px;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-raw {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-note {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.row-pct {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  font-variant-numeric: tabular-nums;
}

.row-pct .upto { color: var(--muted); font-size: 13px; line-height: 16px; }

.row-pct .num {
  font-size: 22px;
  line-height: 24px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.empty {
  padding: var(--s5) var(--s4) var(--s5);
  text-align: center;
}

.empty-title { font-size: 17px; line-height: 24px; font-weight: 600; }
.empty-text { margin: var(--s1) 0 var(--s4); color: var(--muted); font-size: 15px; line-height: 20px; }

.skeleton { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4) 0; }

.skeleton-line {
  height: 16px;
  border-radius: var(--r-field);
  background: var(--surface);
  animation: pulse 1.2s ease-in-out infinite;
}

.skeleton-line:nth-child(2) { width: 70%; }
.skeleton-line:nth-child(3) { width: 45%; }

/* ------------------------------------------------------- нижняя панель */

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.totals {
  margin-bottom: var(--s2);
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  text-align: center;
}

.btn-add { font-size: 17px; }

/* ------------------------------------------------------------- группа */

.members { display: flex; flex-direction: column; gap: var(--s1); margin-top: var(--s2); }

.member {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  min-height: var(--tap);
  padding: var(--s2) 0;
  border-bottom: 1px solid var(--line);
}

.member:last-child { border-bottom: 0; }

.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { color: var(--muted); font-size: 13px; line-height: 16px; }
.member-me { color: var(--accent-text); font-size: 13px; line-height: 16px; }

.invite {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s3);
  border-radius: var(--r-field);
  background: var(--surface);
}

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 24px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: .08em;
}

/* --------------------------------------------------------- тост/модалка */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: calc(100% - 32px);
  max-width: 448px;
  padding: var(--s3) var(--s4);
  border-radius: var(--r-card);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  line-height: 20px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
}

.toast span { flex: 1; }

.toast-action {
  flex: none;
  min-height: var(--tap);
  padding: 0 var(--s2);
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .toast { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
  .toast-action { color: var(--accent-text); }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 10, 14, .55);
  padding: 0;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  padding: var(--s5) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--bg);
}

.modal-title { font-size: 20px; line-height: 26px; font-weight: 600; }
.modal-text { margin: var(--s2) 0 var(--s5); color: var(--muted); font-size: 15px; line-height: 20px; }
.modal-actions { display: flex; flex-direction: column; gap: var(--s2); }

@media (min-width: 520px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 16px; }
}

/* ---------------------------------------------------------------- утиль */

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

.noscript {
  padding: var(--s4);
  color: var(--danger);
  text-align: center;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media (min-width: 480px) {
  #app { padding-left: var(--s5); padding-right: var(--s5); }
}

/* ------------------------------------------- загрузка скриншота (Э5) */

/* Две равнозначные кнопки в нижней панели: «Добавить» и «Со скриншота». */
.btn-pair { display: flex; gap: var(--s2); }
.btn-pair .btn { flex: 1 1 0; min-width: 0; padding: 0 var(--s2); font-size: 16px; }
.btn-pair .btn svg { flex: none; }
.btn-pair .btn-add { white-space: nowrap; }

.drop { position: relative; }

/* Поле файла прячем визуально, но оставляем в потоке фокуса: клик по подписи
   открывает камеру/галерею, а с клавиатуры зона остаётся достижимой. */
.drop-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 148px;
  padding: var(--s4);
  border: 2px dashed var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.drop-label:active { background: var(--bg); }
.drop:focus-within .drop-label { border-color: var(--accent); }

/* Файл выбран: зона сжимается до строки «выбрать другой». */
.drop.has-file .drop-label { min-height: 72px; border-style: solid; }
.drop.has-file .drop-label svg { display: none; }

.drop-title { color: var(--text); font-size: 17px; line-height: 24px; font-weight: 600; }
.drop-hint { font-size: 13px; line-height: 16px; }

.preview { display: flex; flex-direction: column; gap: var(--s1); }

.preview-img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--r-field);
  background: var(--surface);
}

.preview-name {
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  word-break: break-all;
}

.progress {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  color: var(--muted);
  font-size: 16px;
  line-height: 22px;
}

.progress-text { flex: 1; min-width: 0; }

.slow {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s3);
  border-radius: var(--r-field);
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.slow .muted { color: inherit; }

/* --------------------------------------- подтверждение разбора (Э6) */

.review-meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--tap);
  margin-bottom: var(--s2);
}

.meta-text {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 20px;
}

.review-count {
  margin-bottom: var(--s2);
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  text-align: center;
}

.rv-list { border-top: 1px solid var(--line); }
.rv-item { border-bottom: 1px solid var(--line); }

.rv-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: 56px;
  padding: var(--s2) 0;
}

.rv-row.is-editing {
  border-radius: var(--r-field) var(--r-field) 0 0;
  background: var(--surface);
}

.rv-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  min-height: var(--tap);
  flex: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rv-check input {
  width: 22px;
  height: 22px;
  margin: 0;
  font-size: 16px;
  accent-color: var(--accent);
}

.rv-main {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.rv-cat {
  display: block;
  font-size: 17px;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rv-raw {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rv-notes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1) var(--s2);
  margin-top: 2px;
}

.rv-badge {
  padding: 1px 8px;
  border-radius: var(--r-chip);
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 12px;
  line-height: 16px;
  font-weight: 600;
}

.rv-badge-warn {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.rv-limit { color: var(--muted); font-size: 13px; line-height: 16px; }

.rv-pct {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: var(--s1);
  font-variant-numeric: tabular-nums;
}

.rv-pct .upto { color: var(--muted); font-size: 13px; line-height: 16px; }

.rv-pct .num {
  font-size: 20px;
  line-height: 24px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.rv-pct .rv-none { color: var(--muted); }

.rv-edit {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3) var(--s3) var(--s4);
  border-radius: 0 0 var(--r-field) var(--r-field);
  background: var(--surface);
}
