:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f2f3f5);
  --surface: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181c);
  --muted: var(--tg-theme-hint-color, #7c828d);
  --accent: var(--tg-theme-button-color, #2aabee);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --separator: var(--tg-theme-section-separator-color, rgba(120, 120, 128, 0.18));
  --positive: #23a566;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 112px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .13em;
}

h1 { margin: 0; font-size: 32px; letter-spacing: -.035em; }

.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--positive) 14%, transparent);
}

.updated { margin: 6px 2px 20px; color: var(--muted); font-size: 13px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--text) 7%, transparent);
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-weight: 650;
}

.tab.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

.cards { display: grid; gap: 12px; }

.card {
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--separator);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 5px 24px rgba(0, 0, 0, .045);
}

.account-head { display: flex; justify-content: space-between; gap: 12px; }
.account-name { margin: 0; font-size: 15px; font-weight: 700; }
.identity { margin-top: 3px; color: var(--muted); font-size: 13px; }
.balance { margin: 22px 0 3px; font-size: clamp(29px, 9vw, 38px); font-weight: 750; letter-spacing: -.045em; }
.credit { margin: 0; color: var(--muted); font-size: 13px; }

.income {
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid var(--separator);
}

.income-summary { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.income-total { color: var(--positive); font-weight: 750; white-space: nowrap; }
.payments { display: grid; gap: 11px; margin-top: 14px; }
.payment { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; font-size: 14px; }
.payer { overflow-wrap: anywhere; }
.payment-amount { color: var(--positive); font-weight: 650; white-space: nowrap; }
.note { margin: 12px 0 0; color: var(--muted); font-size: 12px; }

.empty { padding: 58px 24px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 38px; }
.empty h2 { margin: 12px 0 6px; color: var(--text); font-size: 19px; }
.empty p { margin: 0; line-height: 1.4; }
.hidden { display: none !important; }

.bottom-bar {
  position: fixed;
  z-index: 5;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.refresh {
  display: block;
  width: min(100%, 528px);
  min-height: 52px;
  margin: 0 auto;
  border: 0;
  border-radius: 15px;
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 700;
}

.refresh:disabled { opacity: .65; }

.skeleton span {
  display: block;
  height: 14px;
  margin-bottom: 14px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--text) 9%, transparent);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.skeleton span:nth-child(2) { width: 72%; height: 34px; margin-top: 30px; }
.skeleton span:nth-child(3) { width: 48%; }
@keyframes pulse { to { opacity: .38; } }

@media (prefers-reduced-motion: reduce) { .skeleton span { animation: none; } }
