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

:root {
  --text: #16181d;
  --muted: #8b909a;
  --green: #23a566;
  --green-bg: #e7f6ee;
  --track: #eef0f4;
  --panel: #f4f5f7;
  --radius: 16px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #fff;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  max-width: 430px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

body.tg-fullscreen .app {
  padding-top: calc(env(safe-area-inset-top) + 24px);
}

.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.is-active { display: flex; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scroll::-webkit-scrollbar { width: 0; height: 0; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- список ---------- */

.list-header {
  padding: 60px 20px 6px;
  text-align: center;
}

.list-heading .muted { font-size: 15px; }

.hero-amount {
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-top: 6px;
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 20px 4px;
  font-size: 13px;
  color: var(--muted);
}

.day-header .day-total { font-variant-numeric: tabular-nums; }

.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.tx-row:active { background: #fafbfc; }

.tx-icon {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
}

.tx-icon.income { background: var(--green-bg); color: var(--green); }
.tx-icon svg { width: 16px; height: 16px; }

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

.tx-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.tx-amount {
  margin-left: auto;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-amount.income { color: var(--green); }

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- добавление ---------- */

.add-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 40px 20px 6px;
}

.link { font-size: 15px; padding: 4px 2px; }
.link.strong { font-weight: 600; margin-left: auto; padding-right: 0; }

.add-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding: 0 24px;
}

.amount-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.chart-icon { display: grid; place-items: center; }
.chart-icon svg { width: 30px; height: 30px; }
.chart-icon.income { color: var(--green); }
.chart-icon.expense { color: #d3372f; }

.amount-value { font-size: 54px; font-weight: 600; letter-spacing: -1px; }
.amount-currency { font-size: 30px; font-weight: 500; color: var(--muted); }

.add-bottom { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }

.save {
  display: block;
  width: 100%;
  height: 50px;
  border-radius: 25px;
  background: var(--text);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.save:disabled { opacity: .3; }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.numpad button {
  height: 62px;
  font-size: 26px;
  font-weight: 400;
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.numpad button:active { background: var(--panel); }
.numpad svg { width: 26px; height: 26px; }

/* ---------- таб-бар ---------- */

.tabbar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 24px calc(8px + env(safe-area-inset-bottom));
}

.app[data-screen="add"] .tabbar { display: none; }

.tabbar button {
  width: 64px;
  height: 52px;
  display: grid;
  place-items: center;
  color: #b6bac2;
}

.tabbar button.is-active { color: var(--text); }
.tabbar svg { width: 36px; height: 36px; }

/* ---------- диалоги и тост ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, .42);
  display: grid;
  place-items: end center;
  z-index: 40;
}

.sheet {
  width: 100%;
  max-width: 430px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(18px + env(safe-area-inset-bottom));
}

.sheet h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.sheet p { font-size: 13.5px; line-height: 1.45; }

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }

.sheet-actions button {
  flex: 1;
  height: 46px;
  border-radius: 14px;
  background: var(--panel);
  font-size: 15px;
  font-weight: 600;
}

.sheet-actions .danger { background: #fdecec; color: #d3372f; }
.sheet-actions .primary { background: var(--text); color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: rgba(22, 24, 29, .92);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 50;
  max-width: 320px;
  text-align: center;
}

@media (min-width: 480px) {
  .app { border-left: 1px solid var(--track); border-right: 1px solid var(--track); }
}
