/* === Reset & Base === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --primary: #3b6ef5;
  --primary-dark: #2d57d6;
  --income: #16a34a;
  --income-bg: #dcfce7;
  --expense: #dc2626;
  --expense-bg: #fee2e2;
  --balance: #7c3aed;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08);
}
body {
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #6d8bf8);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.logo-icon svg { width: 22px; height: 22px; color: #fff; }
.logo h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.header-tag {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 4px 12px;
  border-radius: 20px;
}

/* === Main === */
.main {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
  flex: 1;
}

/* === Stats === */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-income::before { background: var(--income); }
.stat-expense::before { background: var(--expense); }
.stat-balance::before { background: var(--balance); }
.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.stat-income .stat-value { color: var(--income); }
.stat-expense .stat-value { color: var(--expense); }
.stat-balance .stat-value { color: var(--balance); }

/* === Section === */
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}
.form-section, .list-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

/* === Form === */
.record-form { display: flex; flex-direction: column; gap: 14px; }
.form-row {
  display: flex;
  gap: 12px;
}
.form-group {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.form-group.flex-2 { flex: 2; }
.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-group input,
.form-group select {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,110,245,0.1);
}

/* Type toggle */
.type-toggle {
  display: flex;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid var(--border);
}
.type-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.type-btn.active[data-type="expense"] {
  background: var(--expense);
  color: #fff;
}
.type-btn.active[data-type="income"] {
  background: var(--income);
  color: #fff;
}

/* Actions */
.form-actions { display: flex; gap: 10px; }
.btn-primary, .btn-secondary {
  padding: 11px 24px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--bg);
  color: var(--text-secondary);
}
.btn-secondary:hover { background: var(--border); }

/* === List === */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.list-header .section-title { margin-bottom: 0; }
.filter-select {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  cursor: pointer;
}

.table-wrap { overflow-x: auto; }
.record-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.record-table thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.record-table thead th.col-amount { text-align: right; }
.record-table thead th.col-actions { text-align: center; }
.record-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.record-table tbody tr:hover { background: #f8fafc; }
.record-table tbody td {
  padding: 10px 12px;
  vertical-align: middle;
}
.record-table tbody td.col-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.record-table tbody td.col-actions { text-align: center; white-space: nowrap; }

.type-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}
.type-badge.income { background: var(--income-bg); color: var(--income); }
.type-badge.expense { background: var(--expense-bg); color: var(--expense); }

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

.note-cell {
  color: var(--text-secondary);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-btn {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  background: #fff;
  color: var(--text-secondary);
  transition: all 0.2s;
  margin: 0 2px;
}
.action-btn.edit:hover { border-color: var(--primary); color: var(--primary); }
.action-btn.delete:hover { border-color: var(--expense); color: var(--expense); }

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

/* === Footer === */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

/* === Responsive === */
@media (max-width: 600px) {
  .stats-row { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .header-tag { display: none; }
  .record-table { font-size: 13px; }
  .note-cell { max-width: 80px; }
}
