* {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --positive: #34d399;
  --negative: #f87171;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.btn {
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover,
.btn-primary:active {
  opacity: 0.9;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0.375rem;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}

.no-data {
  text-align: center;
  color: var(--text-muted);
}

.no-data .hint {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.has-data .card h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.month-view .month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.month-view .month-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  text-align: center;
}

.month-view .nav-arrow {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.month-view .nav-arrow:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.15);
}

.month-view .nav-arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

.month-view .month-total {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.month-view .total-label {
  margin: 0 0 0.25rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.month-view .total-value {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.month-view .total-value.over {
  color: var(--negative);
}

.month-view .total-value.under {
  color: var(--positive);
}

.month-view .bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.month-view .bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.2s ease;
}

.month-view .bar-fill.over {
  background: var(--negative);
}

.month-view .bar-fill.under {
  background: var(--positive);
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 0.5rem;
}

.category-list li:last-child {
  border-bottom: none;
}

.category-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-sum {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.category-sum.positive {
  color: var(--positive);
}

.category-sum.negative {
  color: var(--negative);
}

.meta {
  font-size: 0.9rem;
  color: var(--text-muted);
}

#by-month {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.month-block {
  padding: 0.5rem 0;
}

.month-block h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.month-block ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

.month-block li {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  color: var(--text-muted);
}

.month-block .sum {
  font-variant-numeric: tabular-nums;
}

.month-block .sum.positive { color: var(--positive); }
.month-block .sum.negative { color: var(--negative); }
.month-block .sum.over { color: var(--negative); }
.month-block .sum.under { color: var(--positive); }

.category-list .sum.over {
  color: var(--negative);
  font-weight: 600;
}

.category-list .sum.under {
  color: var(--positive);
}

/* Clickable category rows */
.category-list li.category-row {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.category-list li.category-row:active {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.375rem;
}

/* ── Detail view (transaction drill-down) ─────────────────────────── */

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.detail-header .nav-arrow {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.detail-header .nav-arrow:active {
  background: rgba(56, 189, 248, 0.15);
}

.detail-title-group {
  flex: 1;
  min-width: 0;
}

.detail-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.detail-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.transaction-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.transaction-list li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.9rem;
}

.transaction-list li:last-child {
  border-bottom: none;
}

.tx-date {
  flex-shrink: 0;
  width: 3rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.tx-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amount {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}
