:root {
  --bg: #0f1724;
  --card: #1b2638;
  --text: #e8edf5;
  --muted: #9aa6b8;
  --line: rgba(127, 127, 127, .18);
  --track: #33415a;
  --warn: #ff8a6b;
  --ok: #5fd39a;
  --yellow: #f2c94c;
  --blue: #6fa0ff;
  --violet: #9b7bff;
  --btn: #2f6fed;
  --red: #ff5a5a;
  --tag-bg: #3a2f1c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.35 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px)) 16px
    calc(76px + env(safe-area-inset-bottom, 0px));
}

h4 {
  margin: 16px 0 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
h4:first-child { margin-top: 0; }

.card { border-radius: 18px; padding: 14px; background: var(--card); margin-bottom: 10px; }
.card.chart { padding: 10px; }
.big { font-size: 26px; font-weight: 700; line-height: 1.2; }
.big .small { font-weight: 400; }
.warn { color: var(--warn); }
.ok { color: var(--ok); }
.small { font-size: 12px; color: var(--muted); }
.small.ok { color: var(--ok); }
.small.warn { color: var(--warn); }

.bar { height: 10px; border-radius: 5px; background: var(--track); margin: 10px 0 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), var(--yellow)); }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  min-width: 0;
}
.row .d { flex: 0 0 42px; font-size: 12px; color: var(--muted); }
.row .t { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.row .a { font-weight: 600; white-space: nowrap; text-align: right; }
.row .a.wrap { white-space: normal; font-weight: 500; font-size: 12px; max-width: 55%; }
.row .hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.row.overdue { background: rgba(255, 90, 90, .08); border-radius: 10px; padding-left: 6px; padding-right: 6px; }
.row.overdue .d { color: var(--red); font-weight: 600; }
.row.paid { color: var(--muted); }
.row.paid .a { font-weight: 500; }
.overdue-tag { display: block; font-size: 11px; color: var(--red); }

.pay {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 6px 9px;
  border-radius: 9px;
  border: 0;
  background: var(--btn);
  color: #fff;
}
.row.overdue .pay { background: #d9443a; }
.tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--tag-bg);
  color: var(--yellow);
  margin-left: 4px;
  white-space: nowrap;
}

.grp { font-size: 12px; color: var(--muted); margin: 14px 0 2px; text-transform: uppercase; letter-spacing: .03em; }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 8px 0; background: var(--track); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; }
.empty { padding: 12px 0; color: var(--muted); font-size: 13px; }

.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .legend-line { margin-top: 6px; }

/* bottom tabs */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(15, 23, 36, .96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
}
.tabs button {
  flex: 1;
  border: 0;
  background: none;
  padding: 10px 4px;
  font-size: 13px;
  color: var(--muted);
}
.tabs button.on { color: var(--blue); font-weight: 700; }

/* splash / full-screen states */
.splash, .full {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}
.full .title { color: var(--text); font-size: 18px; font-weight: 600; max-width: 300px; }
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--track);
  border-top-color: var(--blue);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  background: var(--btn);
  color: #fff;
  font-weight: 600;
}
.btn.ghost { background: var(--track); color: var(--text); }

.banner {
  position: sticky;
  top: 0;
  z-index: 4;
  text-align: center;
  font-size: 12px;
  padding: 6px 16px;
  background: var(--tag-bg);
  color: var(--yellow);
}

/* toast */
.toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  max-width: 448px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #24324a;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
  z-index: 6;
}
.toast-text { flex: 1; font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.toast-text .note { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.toast-undo {
  flex: 0 0 auto;
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 700;
  padding: 6px 2px;
  white-space: nowrap;
}

/* modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.overlay[hidden], .toast[hidden], .tabs[hidden], .banner[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
.m-name { font-size: 18px; font-weight: 700; margin-top: 4px; overflow-wrap: anywhere; }
.m-amount { font-size: 22px; font-weight: 700; margin: 6px 0 12px; }
.m-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.m-date {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--track);
  background: var(--bg);
  color: var(--text);
  color-scheme: dark;
}
.m-hint { margin-top: 8px; }
.m-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 138, 107, .12);
  color: var(--warn);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.m-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
