:root {
  color-scheme: light dark;
  --bg: #f7f8fc;
  --card: rgba(255, 255, 255, 0.88);
  --card-solid: #ffffff;
  --text: #141824;
  --muted: #7c8497;
  --line: rgba(121, 132, 160, 0.18);
  --accent: #6d5cff;
  --accent-2: #2f7bff;
  --income: #18bf78;
  --expense: #ff5c67;
  --shadow: 0 18px 48px rgba(34, 42, 78, 0.14);
  --soft-shadow: 0 10px 28px rgba(34, 42, 78, 0.09);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, rgba(109, 92, 255, 0.20), transparent 32%),
    linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg), #ffffff 26%));
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 18px;
}

h1,
h2,
p {
  margin: 0;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  font-size: 34px;
  line-height: 1;
  font-weight: 850;
  letter-spacing: 0;
}

.menu-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: var(--card);
  box-shadow: var(--soft-shadow);
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
}

.hero-card,
.metric-card,
.panel {
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-card {
  position: relative;
  overflow: hidden;
  min-height: 218px;
  padding: 22px;
  border-radius: var(--radius-xl);
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(47, 123, 255, 0.96), rgba(137, 55, 255, 0.98)),
    var(--accent);
}

.hero-card::after {
  content: "";
  position: absolute;
  inset: auto -18% -36% 18%;
  height: 150px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  filter: blur(20px);
}

.card-label,
.balance-label {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.76);
}

.budget-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.budget-row h2 {
  overflow: hidden;
  font-size: 18px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-label {
  margin-top: 34px;
}

.balance {
  position: relative;
  z-index: 1;
  margin-top: 6px;
  font-size: 40px;
  line-height: 1;
  font-weight: 850;
}

.sync-text {
  position: relative;
  z-index: 1;
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  font-weight: 700;
}

.sparkline {
  position: absolute;
  right: 20px;
  bottom: 24px;
  z-index: 1;
  display: flex;
  align-items: end;
  gap: 7px;
  height: 60px;
}

.sparkline span {
  width: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.58);
}

.sparkline span:nth-child(1) { height: 18px; }
.sparkline span:nth-child(2) { height: 32px; }
.sparkline span:nth-child(3) { height: 25px; }
.sparkline span:nth-child(4) { height: 46px; }
.sparkline span:nth-child(5) { height: 38px; }

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.metric-card {
  min-height: 126px;
  padding: 16px;
  border-radius: var(--radius-lg);
}

.metric-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 12px;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
}

.metric-icon.income {
  background: var(--income);
}

.metric-icon.expense {
  background: var(--expense);
}

.metric-card p {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric-card strong {
  display: block;
  margin-top: 5px;
  font-size: 21px;
}

.delta {
  display: inline-flex;
  width: fit-content;
  margin-top: 9px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.delta.positive {
  color: var(--income);
  background: color-mix(in srgb, var(--income), transparent 88%);
}

.delta.negative {
  color: var(--expense);
  background: color-mix(in srgb, var(--expense), transparent 88%);
}

.delta.neutral {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted), transparent 90%);
}

.delta-caption {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.panel {
  margin-top: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
}

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

.section-heading h2 {
  font-size: 18px;
  font-weight: 800;
}

.section-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.operation {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--card-solid), transparent 8%);
}

.operation-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 14px;
  color: #ffffff;
  font-weight: 850;
}

.operation-icon.income {
  background: var(--income);
}

.operation-icon.expense {
  background: var(--expense);
}

.operation-title {
  min-width: 0;
}

.operation-title strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-chip {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  margin-top: 6px;
  padding: 4px 8px;
  border: 1px solid color-mix(in srgb, var(--accent), transparent 82%);
  border-radius: 999px;
  color: color-mix(in srgb, var(--accent), var(--text) 24%);
  background: color-mix(in srgb, var(--accent), transparent 92%);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.operation-date {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.operation-amount {
  font-size: 14px;
  font-weight: 850;
  white-space: nowrap;
}

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

.operation-amount.expense {
  color: var(--expense);
}

.empty-state {
  padding: 22px 10px 12px;
  text-align: center;
}

.empty-state strong {
  display: block;
  font-size: 16px;
}

.empty-state p {
  width: min(260px, 100%);
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.actions-grid button {
  display: grid;
  min-height: 86px;
  place-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: color-mix(in srgb, var(--card-solid), transparent 10%);
  box-shadow: var(--soft-shadow);
  font-size: 13px;
  font-weight: 750;
}

.actions-grid span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 12px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 18px;
}

.is-loading .skeleton-target {
  position: relative;
  overflow: hidden;
}

.is-loading .skeleton-target::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  background: linear-gradient(110deg, transparent, rgba(255, 255, 255, 0.42), transparent);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1118;
    --card: rgba(24, 29, 38, 0.82);
    --card-solid: #151a22;
    --text: #f4f7fb;
    --muted: #8e98aa;
    --line: rgba(221, 230, 255, 0.10);
    --shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
    --soft-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  }

  body {
    background:
      radial-gradient(circle at 85% -10%, rgba(109, 92, 255, 0.25), transparent 32%),
      linear-gradient(180deg, #0b0f16, var(--bg));
  }
}

body.tg-dark {
  --bg: #0d1118;
  --card: rgba(24, 29, 38, 0.82);
  --card-solid: #151a22;
  --text: #f4f7fb;
  --muted: #8e98aa;
  --line: rgba(221, 230, 255, 0.10);
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.34);
  --soft-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

body.tg-light {
  --bg: #f7f8fc;
  --card: rgba(255, 255, 255, 0.88);
  --card-solid: #ffffff;
  --text: #141824;
  --muted: #7c8497;
  --line: rgba(121, 132, 160, 0.18);
  --shadow: 0 18px 48px rgba(34, 42, 78, 0.14);
  --soft-shadow: 0 10px 28px rgba(34, 42, 78, 0.09);
}

@media (max-width: 360px) {
  .app-shell {
    padding-inline: 14px;
  }

  .balance {
    font-size: 34px;
  }

  .metric-card strong {
    font-size: 18px;
  }

  .actions-grid button {
    font-size: 12px;
  }
}
