:root {
  --bg: var(--tg-theme-bg-color, #f4f4f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 16px;
  color-scheme: light dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.top {
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
}
.top h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--hint); }

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.tab {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 10px 8px;
  background: var(--sec);
  color: var(--hint);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { background: var(--btn); color: var(--btn-text); }

.app { padding: 0 16px; }
.card {
  background: var(--sec);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
label { display: block; font-size: 13px; color: var(--hint); margin: 0 0 6px; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }
.primary {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.primary:disabled { opacity: 0.5; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.muted { color: var(--hint); font-size: 13px; }
.amount { font-weight: 700; font-size: 18px; }
.item-title { font-weight: 600; }
.actions {
  display: flex;
  gap: 16px;
  justify-content: flex-end;
  margin-top: 10px;
}
.ghost, .edit {
  border: 0;
  background: transparent;
  color: var(--link);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.danger {
  border: 0;
  background: transparent;
  color: #e53935;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.danger-fill {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  background: #e53935;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.ghost.btn {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.form-actions {
  display: flex;
  gap: 8px;
}
.form-actions .primary { flex: 1; }
.form-actions .ghost.btn { flex: 0 0 auto; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--sec);
  color: var(--text);
  border-radius: 18px;
  padding: 18px 16px 16px;
}
.modal-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}
.modal-card p {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--hint);
  line-height: 1.4;
}
.modal-actions {
  display: flex;
  gap: 8px;
}
.modal-actions .ghost,
.modal-actions .danger-fill {
  flex: 1;
}
.bar {
  height: 8px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--btn) 18%, var(--bg));
  overflow: hidden;
  margin-top: 6px;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--btn);
}
.empty, .gate {
  text-align: center;
  color: var(--hint);
  padding: 32px 12px;
}
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  background: #111;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  z-index: 5;
}
.hidden { display: none !important; }
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.month-nav button {
  border: 0;
  background: var(--sec);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
}
