:root {
  color-scheme: dark;
  --bg: #10141b;
  --panel: #1a222d;
  --panel-2: #202a37;
  --panel-3: #151c25;
  --line: #303b4b;
  --line-soft: rgba(255, 255, 255, 0.08);
  --text: #f5f7fa;
  --muted: #9ba6b5;
  --teal: #2fd0b4;
  --coral: #ff7067;
  --amber: #f2b84f;
  --blue: #5597f5;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 540px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(47, 208, 180, 0.08), transparent 235px),
    linear-gradient(180deg, #111923 0%, #0d1219 100%);
}

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

.eyebrow,
.section-title p,
.hero-report p,
.hero-side span,
.hero-side small,
.metric-card span {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  line-height: 1.15;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.hero-report,
.panel,
.metric-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
}

.hero-report {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  align-items: stretch;
  min-height: 162px;
  padding: 16px;
  background:
    linear-gradient(135deg, rgba(47, 208, 180, 0.16), transparent 48%),
    linear-gradient(180deg, #202a37, #18212c);
}

.hero-main {
  min-width: 0;
}

.hero-main strong {
  display: block;
  margin: 8px 0 10px;
  overflow-wrap: anywhere;
  font-size: clamp(38px, 10vw, 50px);
  line-height: 0.96;
}

.hero-main span {
  display: inline-flex;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid rgba(47, 208, 180, 0.22);
  border-radius: 8px;
  background: rgba(47, 208, 180, 0.08);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.hero-side {
  display: grid;
  align-content: space-between;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.hero-side strong {
  font-size: 30px;
  line-height: 1;
}

.hero-side small {
  overflow-wrap: anywhere;
  font-size: 12px;
}

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

.metric-card {
  min-height: 88px;
  padding: 14px;
  background: var(--panel-3);
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: clamp(21px, 6vw, 28px);
  line-height: 1.02;
}

.positive {
  color: var(--teal);
}

.negative {
  color: var(--coral);
}

.panel {
  margin-top: 10px;
  padding: 15px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title p {
  margin-top: 4px;
  font-size: 13px;
}

.section-title > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px 10px;
  max-width: 190px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.income-dot {
  background: var(--teal);
}

.expense-dot {
  background: var(--coral);
}

.balance-dot {
  background: var(--blue);
}

.chart-panel canvas {
  display: block;
  width: 100%;
  min-height: 220px;
}

.insights-list,
.category-list,
.account-list,
.transactions {
  display: grid;
  gap: 8px;
}

.insight-card,
.breakdown-row,
.transaction-row {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.insight-card {
  display: grid;
  gap: 5px;
  padding: 13px;
}

.insight-card strong {
  color: var(--text);
}

.insight-card span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.breakdown-row,
.transaction-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 12px;
  overflow: hidden;
}

.breakdown-row::before {
  content: "";
  position: absolute;
  inset: auto auto 0 0;
  width: var(--bar, 0%);
  height: 3px;
  background: var(--bar-color, var(--teal));
}

.breakdown-main,
.transaction-row div {
  min-width: 0;
}

.breakdown-main strong,
.breakdown-main span,
.transaction-row strong,
.transaction-row span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breakdown-main span,
.transaction-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.breakdown-row b,
.transaction-row b {
  flex: 0 0 auto;
  max-width: 42%;
  overflow-wrap: anywhere;
  text-align: right;
}

.state-message {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 17, 24, 0.95);
  color: var(--muted);
  text-align: center;
}

.state-message.hidden {
  display: none;
}

@media (max-width: 390px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .hero-report {
    grid-template-columns: 1fr;
  }

  .hero-side {
    grid-template-columns: 1fr 1fr 1fr;
    align-items: center;
    gap: 10px;
  }

  .legend {
    max-width: none;
    justify-content: flex-start;
  }

  .section-title {
    display: grid;
  }
}
