:root {
  --bg: #f4f6f5;
  --card-bg: #ffffff;
  --text: #1c2620;
  --muted: #6b7770;
  --primary: #1b7a5c;
  --primary-dark: #145c46;
  --income: #1b7a5c;
  --expense: #c0392b;
  --border: #e3e7e5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 96px;
}

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px 20px;
  border-radius: 0 0 20px 20px;
}

.topbar h1 {
  margin: 0 0 12px;
  font-size: 1.3rem;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 1.05rem;
}

.month-nav button {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: -28px;
}

.card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
}

.card .label { font-size: 0.75rem; color: var(--muted); }
.card .value { font-size: 1.05rem; font-weight: 700; }
.card.income .value { color: var(--income); }
.card.expense .value { color: var(--expense); }

.chart-section, .list-section {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 16px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.list-header h2 { font-size: 1rem; margin: 0; }

.list-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  margin-left: 6px;
}

.empty-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 20px 0;
}

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

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: #eef2f0;
  flex-shrink: 0;
}

.tx-info { flex: 1; min-width: 0; }
.tx-category { font-weight: 600; font-size: 0.92rem; }
.tx-note { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 0.72rem; color: var(--muted); }

.tx-amount { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }

.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(27,122,92,0.4);
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: #fff;
  width: 100%;
  max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal h2 { margin: 0 0 4px; font-size: 1.1rem; }

.type-toggle {
  display: flex;
  background: #eef2f0;
  border-radius: 10px;
  padding: 4px;
}

.type-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0;
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
}

.type-btn.active {
  background: #fff;
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.modal input, .modal select {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  background: #fff;
}

.amount-input-row {
  display: flex;
  gap: 8px;
}

.amount-input-row input {
  flex: 1;
  min-width: 0;
}

.amount-op-btn {
  width: 44px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #eef2f0;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

.amount-op-btn:active {
  background: #dfe6e2;
}

.amount-preview {
  font-size: 0.8rem;
  min-height: 1.1em;
  color: var(--primary);
}

.amount-preview.invalid {
  color: var(--expense);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
}

.modal-actions .primary {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.modal-actions .primary:active { background: var(--primary-dark); }

.modal-actions #cancelBtn {
  background: #eef2f0;
  color: var(--text);
}

.modal-actions .danger {
  background: #fdecea;
  color: var(--expense);
}
