/* Toma los colores del tema de Telegram; afuera de Telegram usa claro/oscuro del sistema. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #1d1d1f);
  --hint: var(--tg-theme-hint-color, #6e6e73);
  --accent: var(--tg-theme-button-color, #0071e3);
  --line: rgba(128, 128, 128, 0.18);
  --soft: rgba(128, 128, 128, 0.10);
  --good: #1a8f3c; --good-bg: rgba(48, 209, 88, 0.18);
  --bad: #c81e1e;  --bad-bg: rgba(255, 59, 48, 0.16);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #000000; --card: #1c1c1e; --text: #f2f2f7; --hint: #8e8e93; --accent: #0a84ff;
    --good: #30d158; --bad: #ff6961;
  }
}
:root.tg-dark { --good: #30d158; --bad: #ff6961; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

.header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.nav-btn {
  width: 40px; height: 36px; border-radius: 10px; border: none;
  background: var(--card); color: var(--accent); font-size: 22px; line-height: 1; cursor: pointer;
}
.nav-btn:disabled { opacity: .35; }
.month-select {
  flex: 1; max-width: 220px; height: 36px; border-radius: 10px; border: none;
  background: var(--card); color: var(--text); font-size: 16px; font-weight: 600;
  text-align: center; text-align-last: center; padding: 0 8px; appearance: none; -webkit-appearance: none;
}

.main { padding: 12px 16px 24px; max-width: 640px; margin: 0 auto; }
.status { text-align: center; color: var(--hint); padding: 48px 8px; line-height: 1.5; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-total { grid-column: 1 / -1; }
.stat-card, .card { background: var(--card); border-radius: 14px; padding: 14px; }
.stat-card .label { font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-total .value { font-size: 28px; }
.stat-card .sub { font-size: 12px; color: var(--hint); margin-top: 4px; }
.value-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

/* Semántica inversa: verde = bajó (bueno), rojo = subió (malo). */
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge:empty { display: none; }
.badge.good { color: var(--good); background: var(--good-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.flat { color: var(--hint); background: var(--soft); }

.card { margin-bottom: 12px; }
.card h3 { font-size: 12px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: flex; background: var(--soft); border-radius: 9px; padding: 2px; }
.seg button { border: none; background: none; color: var(--hint); font-size: 13px; font-weight: 500; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--hint); user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.chart-wrap { position: relative; height: 260px; }

.tx-list { display: flex; flex-direction: column; }
.tx-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tx-item:last-child { border-bottom: none; }
.tx-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tx-main { flex: 1; min-width: 0; }
.tx-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 12px; color: var(--hint); margin-top: 2px; }
.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amount.refund { color: var(--good); }
.empty { text-align: center; color: var(--hint); padding: 24px 8px; }
