:root {
  --bg: #0d1420;
  --card: rgba(24, 33, 49, 0.82);
  --card-soft: rgba(39, 51, 73, 0.9);
  --text: #f7f2e9;
  --muted: #9fb0c7;
  --accent: #c9a86a;
  --accent-strong: #5d93d8;
  --accent-blue: #7db6ff;
  --accent-gold: #e1bf7a;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.11);
  --glow: rgba(201, 168, 106, 0.16);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% -8%, rgba(125, 182, 255, 0.28), transparent 31%),
    radial-gradient(circle at 96% 8%, rgba(225, 191, 122, 0.18), transparent 34%),
    radial-gradient(circle at 55% 105%, rgba(105, 83, 186, 0.14), transparent 28%),
    linear-gradient(180deg, #0f1825, var(--tg-theme-bg-color, var(--bg)) 48%, #0a101a);
  color: var(--tg-theme-text-color, var(--text));
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 16px 14px 28px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: stretch;
  padding: 18px;
  border-radius: 28px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    radial-gradient(circle at top left, rgba(201, 168, 106, 0.22), transparent 42%),
    radial-gradient(circle at bottom right, rgba(93, 147, 216, 0.18), transparent 45%),
    linear-gradient(135deg, #1b2638, #101826);
  border: 1px solid var(--border);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.hero::before {
  position: absolute;
  inset: -1px;
  content: "";
  pointer-events: none;
  background: linear-gradient(115deg, rgba(225, 191, 122, 0.28), transparent 28%, rgba(125, 182, 255, 0.18) 72%, transparent);
  opacity: 0.65;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  padding: 1px;
  border-radius: inherit;
}

.eyebrow,
.list-head p,
.stat-summary span {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.05;
}

h2 {
  font-size: 20px;
}

.hero-total {
  display: grid;
  min-width: 116px;
  padding: 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
  align-content: center;
  text-align: right;
}

.hero-total span {
  color: var(--muted);
  font-size: 12px;
}

.hero-total strong {
  margin-top: 4px;
  color: var(--accent-gold);
  font-size: 20px;
  text-shadow: 0 0 18px rgba(225, 191, 122, 0.28);
}

.notice {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 107, 107, 0.14);
  color: #ffd7d7;
}

.hidden {
  display: none !important;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
  padding: 6px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(18px);
}

.tab,
.filters button,
.quick-amounts button {
  min-height: 42px;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
}

.tab.active,
.filters button.active,
.quick-amounts button:hover {
  background: linear-gradient(135deg, var(--tg-theme-button-color, var(--accent-strong)), #6da6e6);
  color: var(--tg-theme-button-text-color, #fff);
  box-shadow: 0 10px 28px rgba(93, 147, 216, 0.24);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.card,
.filter-card,
.list-head,
.expense-card,
.stat-row {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--tg-theme-secondary-bg-color, var(--card));
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(18px);
}

.card:hover,
.expense-card:hover,
.stat-row:hover {
  border-color: rgba(225, 191, 122, 0.22);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.26), 0 0 28px rgba(125, 182, 255, 0.08);
}

.card,
.filter-card {
  padding: 16px;
}

.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.label-row {
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  outline: none;
  background: var(--card-soft);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.quick-amounts,
.filters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.filters {
  grid-template-columns: repeat(5, 1fr);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.category-grid button {
  min-height: 48px;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--card-soft);
  color: var(--text);
  text-align: left;
}

.category-grid button.active {
  background: linear-gradient(135deg, rgba(225, 191, 122, 0.2), rgba(125, 182, 255, 0.12));
  color: #ffe3a3;
  box-shadow: inset 0 0 0 1px rgba(225, 191, 122, 0.5), 0 0 24px rgba(225, 191, 122, 0.1);
}

.primary,
.danger,
.ghost,
.custom-range button {
  min-height: 48px;
  padding: 0 16px;
  border-radius: 16px;
}

.primary {
  background: linear-gradient(135deg, var(--tg-theme-button-color, var(--accent-strong)), #78aee9);
  color: var(--tg-theme-button-text-color, #fff);
  font-weight: 700;
  box-shadow: 0 14px 34px rgba(93, 147, 216, 0.26);
}

.danger {
  background: rgba(255, 107, 107, 0.16);
  color: var(--danger);
}

.ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.custom-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.custom-range button {
  grid-column: 1 / -1;
  background: var(--card-soft);
  color: var(--text);
}

.list-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
  padding: 14px;
}

.list-head strong {
  font-size: 22px;
}

.expenses-list,
.stats-list {
  display: grid;
  gap: 10px;
}

.expense-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  text-align: left;
  color: var(--text);
}

.expense-card strong {
  font-size: 17px;
}

.expense-card small,
.expense-card span,
.empty {
  color: var(--muted);
}

.expense-card .amount {
  color: var(--accent-gold);
  font-weight: 800;
}

.stat-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin: 12px 0;
}

.stat-summary strong {
  color: var(--accent-gold);
  font-size: 32px;
  text-shadow: 0 0 22px rgba(225, 191, 122, 0.18);
}

.stat-summary small {
  color: var(--muted);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-title span,
.hint {
  color: var(--muted);
  font-size: 12px;
}

.category-manager {
  margin-top: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.inline-form button,
.category-pill button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: rgba(201, 168, 106, 0.15);
  color: #f3d9a1;
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 6px 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.category-pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-pill button {
  min-height: 30px;
  padding: 0 10px;
  color: #ffd6d6;
  background: rgba(255, 107, 107, 0.13);
}

.donut {
  position: relative;
  display: grid;
  place-items: center;
  width: 118px;
  height: 118px;
  flex: 0 0 118px;
  border-radius: 50%;
  background: conic-gradient(rgba(255, 255, 255, 0.08) 0 100%);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.26), 0 0 36px var(--glow);
}

.donut::after {
  position: absolute;
  inset: 16px;
  content: "";
  border-radius: 50%;
  background: linear-gradient(145deg, #172131, #0f1724);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.donut div {
  position: relative;
  z-index: 1;
  display: grid;
  text-align: center;
}

.donut b {
  font-size: 22px;
}

.donut small {
  color: var(--muted);
}

.stat-row {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.stat-row-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #89d8ff);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  padding: 12px;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-content {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 18px;
  border-radius: 28px 28px 18px 18px;
  background: var(--card);
  border: 1px solid var(--border);
}

.sheet-head,
.actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.actions button {
  flex: 1;
}

@media (max-width: 420px) {
  .filters {
    grid-template-columns: repeat(3, 1fr);
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 22px;
  }

  .stat-summary {
    align-items: stretch;
  }

  .donut {
    width: 104px;
    height: 104px;
    flex-basis: 104px;
  }
}
