:root {
  --bg:       var(--tg-theme-bg-color, #0f0f14);
  --bg2:      var(--tg-theme-secondary-bg-color, #1a1a24);
  --bg3:      rgba(255,255,255,0.04);
  --text:     var(--tg-theme-text-color, #f0f0f0);
  --hint:     var(--tg-theme-hint-color, #6b7280);
  --accent:   var(--tg-theme-button-color, #3b82f6);
  --accent-t: var(--tg-theme-button-text-color, #fff);
  --income:   #22c55e;
  --expense:  #ef4444;
  --warn:     #f59e0b;
  --radius:   16px;
  --radius-sm: 10px;
  --shadow:   0 4px 24px rgba(0,0,0,0.3);
  --border:   rgba(255,255,255,0.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100%; }

/* ── Header ─────────────────────────────────────────────────────────── */
.header {
  padding: 14px 16px 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-title { font-weight: 700; font-size: 17px; letter-spacing: -0.3px; }
.header-sub   { font-size: 11px; color: var(--hint); margin-top: 1px; }
.header-period { display: flex; gap: 4px; }
.period-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--hint);
  border-radius: 20px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s;
}
.period-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-t);
}

/* ── Period button icon variant ─────────────────────────────────────── */
.period-btn-icon {
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.period-btn-icon.active svg { stroke: var(--accent-t); }

/* ── Date range bar ─────────────────────────────────────────────────── */
.date-range-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: none;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.date-range-bar.visible { display: flex; }
.date-range-inputs {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.date-field label {
  font-size: 10px;
  color: var(--hint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.date-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
}
.date-input:focus { border-color: var(--accent); }
.date-range-sep {
  font-size: 14px;
  color: var(--hint);
  margin-top: 14px;
  flex-shrink: 0;
}
.date-apply-btn {
  background: var(--accent);
  color: var(--accent-t);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 14px;
  transition: opacity .15s;
}
.date-apply-btn:active { opacity: 0.8; }

/* ── Content ────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 4px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── Bottom nav ─────────────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 7px;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
  position: relative;
}
.nav-btn.active { color: var(--accent); }
.nav-btn.active::before {
  content: '';
  position: absolute;
  top: 0; left: 25%; right: 25%;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}
.nav-icon { width: 22px; height: 22px; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.card-row { display: flex; gap: 8px; margin-bottom: 10px; }
.card-half {
  flex: 1;
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}

.label {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 600;
}
.amount { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.5px; }
.amount.income  { color: var(--income); }
.amount.expense { color: var(--expense); }
.amount.balance { color: var(--text); }

/* ── Hero balance card ──────────────────────────────────────────────── */
.hero-card {
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}
.hero-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 60%, #8b5cf6) 100%);
  opacity: 0.92;
}
.hero-card > * { position: relative; z-index: 1; }
.hero-label { font-size: 12px; color: rgba(255,255,255,0.7); font-weight: 500; margin-bottom: 4px; }
.hero-amount { font-size: 36px; font-weight: 800; color: #fff; letter-spacing: -1px; line-height: 1.1; }
.hero-sub { font-size: 12px; color: rgba(255,255,255,0.65); margin-top: 8px; display: flex; gap: 12px; }
.hero-sub span { display: flex; align-items: center; gap: 4px; }

/* Health bar inside hero */
.hero-health { margin-top: 14px; }
.hero-health-label { display: flex; justify-content: space-between; font-size: 11px; color: rgba(255,255,255,0.7); margin-bottom: 5px; }
.hero-bar { height: 5px; background: rgba(255,255,255,0.2); border-radius: 3px; overflow: hidden; }
.hero-bar-fill { height: 100%; border-radius: 3px; transition: width .6s cubic-bezier(.4,0,.2,1); }

/* Streak badge */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  color: #fff;
  font-weight: 600;
  margin-top: 8px;
}

/* ── Insight banner ─────────────────────────────────────────────────── */
.insight-banner {
  background: linear-gradient(135deg, rgba(245,158,11,0.12), rgba(239,68,68,0.08));
  border: 1px solid rgba(245,158,11,0.25);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.insight-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.insight-text { font-size: 13px; line-height: 1.5; color: var(--text); }
.insight-text strong { color: var(--warn); }

/* ── Savings progress ───────────────────────────────────────────────── */
.savings-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.savings-pct { font-size: 18px; font-weight: 700; }
.progress-bar { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  background: var(--income);
}
.progress-fill.warn { background: var(--warn); }
.progress-fill.bad  { background: var(--expense); }

/* ── Section title ──────────────────────────────────────────────────── */
.section-title {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .7px;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ── Category rows ──────────────────────────────────────────────────── */
.cat-row {
  display: flex;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity .15s;
  gap: 10px;
}
.cat-row:last-child { border-bottom: none; padding-bottom: 0; }
.cat-row:first-child { padding-top: 0; }
.cat-row:active { opacity: 0.6; }
.cat-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-size: 14px; font-weight: 500; }
.cat-meta { display: flex; justify-content: space-between; margin-top: 3px; }
.cat-count { font-size: 11px; color: var(--hint); }
.cat-bar-wrap { width: 100%; height: 3px; background: var(--bg3); border-radius: 2px; margin-top: 5px; }
.cat-bar { height: 3px; border-radius: 2px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.cat-amount { font-size: 14px; font-weight: 700; color: var(--text); white-space: nowrap; }
.cat-arrow { font-size: 14px; color: var(--hint); flex-shrink: 0; }

/* ── Chart ──────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 200px; margin: 4px 0; }
.chart-wrap.tall { height: 240px; }

/* ── Stats grid ─────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat-val { font-size: 18px; font-weight: 700; margin-top: 4px; }
.stat-val.income  { color: var(--income); }
.stat-val.expense { color: var(--expense); }
.stat-val.neutral { color: var(--text); }

/* ── Transactions ───────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  margin-bottom: 8px;
  gap: 8px;
}
.search-bar svg { flex-shrink: 0; color: var(--hint); }
.search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
}
.search-bar input::placeholder { color: var(--hint); }

.filter-chips { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--hint);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-t); }

.tx-item {
  display: flex;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  cursor: default;
}
.tx-item:last-child { border-bottom: none; }
.tx-emoji {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.tx-left { flex: 1; min-width: 0; }
.tx-cat  { font-size: 13px; font-weight: 600; }
.tx-note { font-size: 11px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; margin-top: 1px; }
.tx-date { font-size: 10px; color: var(--hint); margin-top: 2px; }
.tx-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }
.tx-amount.income  { color: var(--income); }
.tx-amount.expense { color: var(--expense); }

.load-more {
  width: 100%;
  padding: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: var(--radius);
  margin-top: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.load-more:active { opacity: 0.7; }

/* ── Trends ─────────────────────────────────────────────────────────── */
.month-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.month-row:last-child { border-bottom: none; }
.month-name { font-size: 13px; font-weight: 600; width: 60px; flex-shrink: 0; }
.month-bars { flex: 1; }
.month-bar-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.month-bar-row:last-child { margin-bottom: 0; }
.month-bar-bg { flex: 1; height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.month-bar-fill { height: 5px; border-radius: 3px; }
.month-bar-fill.inc { background: var(--income); }
.month-bar-fill.exp { background: var(--expense); }
.month-val { font-size: 11px; font-weight: 600; width: 46px; text-align: right; flex-shrink: 0; }
.month-balance {
  font-size: 12px;
  font-weight: 700;
  width: 52px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Bottom sheet modal ──────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  animation: slideUp .22s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.sheet-handle {
  width: 36px; height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 10px auto 4px;
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px 14px;
  border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 16px; font-weight: 700; }
.sheet-close {
  background: var(--bg3);
  border: none;
  color: var(--hint);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sheet-body { overflow-y: auto; padding: 8px 16px 32px; flex: 1; }

/* ── Skeleton loader ─────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skel-hero { height: 140px; border-radius: var(--radius); margin-bottom: 10px; }
.skel-row  { display: flex; gap: 8px; margin-bottom: 10px; }
.skel-half { flex: 1; height: 80px; border-radius: var(--radius); }
.skel-card { height: 200px; border-radius: var(--radius); margin-bottom: 10px; }
.skel-line { height: 14px; border-radius: 4px; margin-bottom: 8px; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,40,0.95);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: all .25s;
  white-space: nowrap;
  z-index: 300;
  backdrop-filter: blur(10px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Error state ────────────────────────────────────────────────────── */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  gap: 12px;
}
.error-icon { font-size: 40px; }
.error-title { font-size: 16px; font-weight: 700; }
.error-msg { font-size: 13px; color: var(--hint); line-height: 1.5; }
.error-btn {
  margin-top: 8px;
  padding: 10px 24px;
  background: var(--accent);
  color: var(--accent-t);
  border: none;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.empty { text-align: center; padding: 40px 16px; color: var(--hint); font-size: 14px; }

/* ── Divider label ──────────────────────────────────────────────────── */
.date-divider {
  font-size: 11px;
  color: var(--hint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 0 4px;
}

/* ── Type toggle (income/expense) ───────────────────────────────────── */
.type-toggle {
  display: flex;
  background: var(--bg3);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
}
.type-toggle-btn {
  flex: 1;
  padding: 7px;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
}
.type-toggle-btn.active { background: var(--bg2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
