:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --text: #1c211f;
  --muted: #6b736f;
  --line: #e1e4de;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcece6;
  --plus: #1f8a4c;
  --minus: #b5432f;
  --warn-bg: #fff3d6;
  --warn-ink: #7a5300;
  --shadow: 0 6px 20px rgba(20, 30, 25, .18);
  --radius: 14px;
  --nav-h: 64px;
  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: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

/* ---------- Шапка ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
}
.top .grow { flex: 1; min-width: 0; }
.top-total { font-size: 26px; font-weight: 650; letter-spacing: -.01em; }
.top-label { color: var(--muted); font-size: 14px; }
.top-title { font-size: 18px; font-weight: 600; }
.top-date { font-size: 19px; font-weight: 650; padding: 10px 0; }
.page-title { margin: 0 16px 10px; font-size: 22px; font-weight: 650; }
.hint { margin: 10px 16px; color: var(--muted); font-size: 14px; }

.icon-btn {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- Нижнее меню ---------- */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav-inner { display: flex; width: 100%; max-width: 560px; }
.nav a {
  flex: 1;
  height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--accent); font-weight: 600; }

/* ---------- Блоки ---------- */

.section-title { margin: 20px 16px 8px; font-size: 20px; font-weight: 650; }
.day-title { margin: 22px 16px 4px; font-size: 17px; font-weight: 650; }

.list { background: var(--surface); border-radius: var(--radius); margin: 0 12px; overflow: hidden; }

.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0; background: transparent; text-align: left;
  cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .name { font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; white-space: nowrap; }
.row .amount { font-size: 17px; font-variant-numeric: tabular-nums; }
.row .after { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.avatar {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 650;
}
.avatar svg { width: 22px; height: 22px; }
.avatar.mine { background: var(--accent-soft); color: var(--accent); }

.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--muted); }
.strike { text-decoration: line-through; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 12px;
  vertical-align: 2px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

.notice {
  margin: 12px 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-ink);
}
.notice .btn { margin-top: 10px; }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Экран счёта ---------- */

.hero { text-align: center; padding: 4px 16px 6px; }
.hero .avatar { width: 64px; height: 64px; margin: 0 auto 10px; font-size: 24px; }
.hero .title { font-size: 18px; }
.hero .owner { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 34px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }

.month {
  display: flex; align-items: center; justify-content: space-between;
  margin: 16px 8px 6px;
}
.month .label { font-size: 18px; font-weight: 650; }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 12px; }
.total-card {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
}
.total-card .k { color: var(--muted); font-size: 14px; }
.total-card .k::before {
  content: ""; display: inline-block;
  width: 8px; height: 8px; margin-right: 6px; border-radius: 50%;
  vertical-align: 1px;
}
.total-card.in .k::before { background: var(--plus); }
.total-card.out .k::before { background: var(--minus); }
.total-card .v { font-size: 19px; font-variant-numeric: tabular-nums; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0; border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--minus); border: 1.5px solid currentColor; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; }

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 264px));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 20;
  width: 60px; height: 60px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s;
}
.fab svg { width: 28px; height: 28px; }
.fab.open { transform: rotate(45deg); }

.dial-backdrop { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .35); }
.dial {
  position: fixed;
  right: max(16px, calc(50vw - 264px));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px);
  z-index: 20;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.dial a {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  border-radius: 99px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  font-size: 17px; font-weight: 600;
}

/* ---------- Форма ---------- */

.seg {
  display: flex;
  margin: 4px 16px 0;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
}
.seg button {
  flex: 1;
  min-height: 38px;
  border: 0; border-radius: 9px;
  background: transparent;
  font-weight: 600; color: var(--muted);
  cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.amount-box { padding: 26px 16px 10px; text-align: center; }
.amount-input {
  width: 100%;
  border: 0; outline: 0;
  background: transparent;
  text-align: center;
  font-size: 44px; font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: var(--line); }
.amount-hint { color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 16px 4px; }
.chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 99px;
  background: var(--surface);
  cursor: pointer;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.fields { margin: 14px 12px 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.field { display: flex; align-items: center; gap: 12px; padding: 4px 14px; min-height: 54px; }
.field + .field { border-top: 1px solid var(--line); }
.field > svg { flex: none; width: 22px; height: 22px; color: var(--muted); }
.field select, .field input, .field textarea {
  flex: 1; min-width: 0;
  padding: 12px 0;
  border: 0; outline: 0;
  background: transparent;
  font-size: 17px;
}
.field textarea { resize: none; min-height: 48px; }
.field label { color: var(--muted); font-size: 14px; min-width: 64px; flex: none; }

.form-actions {
  position: sticky;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 14px 12px;
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* ---------- Подробности ---------- */

.detail-head { text-align: center; padding: 8px 16px 16px; }
.detail-head .kind { color: var(--muted); }
.detail-head .big { font-size: 40px; font-weight: 650; font-variant-numeric: tabular-nums; }
.detail-head .cat { margin-top: 4px; font-size: 18px; }

.kv { display: flex; gap: 12px; padding: 12px 14px; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv .k { width: 150px; flex: none; color: var(--muted); }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 12px; }
.actions .btn { flex: 1; }

/* ---------- Вход ---------- */

.login { padding: calc(60px + env(safe-area-inset-top)) 20px 20px; }
.login h1 { margin: 0 0 4px; font-size: 30px; }
.login p { margin: 0 0 24px; color: var(--muted); }
.login .fields { margin: 0 0 16px; }

/* ---------- Модальное окно и уведомления ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .4);
}
.modal {
  width: 100%; max-width: 560px;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--bg);
}
.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal p { margin: 0 0 12px; color: var(--muted); }
.modal .fields { margin: 0 0 14px; }
.modal .actions { padding: 0; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
  z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text); color: var(--bg);
  box-shadow: var(--shadow);
}
.toast.error { background: var(--minus); color: #fff; }

.hash { font-family: ui-monospace, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }

/* ---------- Отчёты ---------- */

.report-total { margin: 14px 12px 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); }
.report-total .k { color: var(--muted); font-size: 14px; }
.report-total .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a.cat { display: inline-block; }

/* ---------- Выбор поставщика ---------- */

.supplier-pick {
  display: flex; align-items: center; gap: 12px;
  width: calc(100% - 24px); margin: 6px 12px 0; padding: 14px;
  border: 1.5px solid var(--accent); border-radius: var(--radius);
  background: var(--accent-soft); color: var(--text); font-size: 17px; text-align: left;
  cursor: pointer;
}
.supplier-pick svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.supplier-pick .grow { flex: 1; }
.picker { margin: 0; max-height: 50vh; overflow-y: auto; }
.picker .row { padding: 4px 6px 4px 14px; cursor: default; }
.picker .row.chosen { background: var(--accent-soft); }
.pick-name { border: 0; outline: 0; background: transparent; text-align: left; font-size: 17px; padding: 12px 0; cursor: pointer; }
