:root {
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17212b);
  --hint: var(--tg-theme-hint-color, #7d8790);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2ea043);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d14b5a;
  --line: rgba(127, 139, 151, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom));
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.screen-header.compact {
  justify-content: flex-start;
}

.screen-header p {
  margin: 0 0 3px;
  color: var(--hint);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.14;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 17px;
}

.round-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 28px;
  line-height: 1;
}

.back-button,
.small-button,
.text-button {
  border: 0;
  background: transparent;
  color: var(--link);
  font-weight: 800;
}

.back-button {
  min-height: 38px;
  padding: 0 6px 0 0;
}

.small-button {
  min-height: 34px;
  padding: 0;
}

.text-button {
  padding: 0;
}

.list {
  display: grid;
  gap: 10px;
}

.compact-list {
  gap: 8px;
}

.card {
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.card.row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.card strong {
  overflow-wrap: anywhere;
  font-size: 16px;
}

.card span,
.hint,
.empty-state {
  color: var(--hint);
  font-size: 14px;
}

.amount {
  color: var(--text);
  font-weight: 900;
  white-space: nowrap;
}

.amount.positive {
  color: var(--button);
}

.amount.negative {
  color: var(--danger);
}

.summary {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  border-radius: 12px;
  padding: 16px;
  background: var(--surface);
}

.summary span {
  color: var(--hint);
  font-size: 14px;
  font-weight: 800;
}

.summary strong {
  font-size: 28px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(127, 139, 151, 0.14);
}

.tabs button {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-weight: 800;
}

.tabs button.active {
  background: var(--surface);
  color: var(--text);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 12px;
}

.section-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-line.tight {
  margin-bottom: 8px;
}

.simple-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--hint);
  font-size: 14px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--link);
}

.primary-button {
  min-height: 50px;
  border: 0;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 900;
}

.choice-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  border: 0;
  padding: 0;
}

.choice-group legend {
  grid-column: 1 / -1;
  color: var(--hint);
  font-size: 14px;
  font-weight: 800;
}

.choice-group label,
.participant-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
}

.choice-group input,
.participant-card input[type="checkbox"] {
  width: 20px;
  min-height: 20px;
  accent-color: var(--button);
}

.participant-card input[type="number"] {
  grid-column: 1 / -1;
  min-height: 42px;
}

.remove-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: rgba(209, 75, 90, 0.12);
  color: var(--danger);
  font-size: 20px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 96px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 16px;
  background: rgba(127, 139, 151, 0.08);
  text-align: center;
}

.hint {
  min-height: 20px;
  margin: 2px 0 0;
}

.hint.warning {
  color: var(--danger);
  font-weight: 800;
}

.muted-list {
  margin-top: 2px;
}
