*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f1f5;
  --bg2: #fafbfc;
  --bg3: #e8eaef;
  --border: rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.12);
  --text: #2c2d35;
  --muted: #8a8d9a;
  --muted2: #6b6e7a;
  --surface: #ffffff;
  --surface-hover: rgba(0,0,0,0.04);
  --overlay: rgba(44,45,53,0.4);
  --blue: #3B82F6;
  --blue-light: rgba(59,130,246,0.08);
  --green: #10B981;
  --green-light: rgba(16,185,129,0.1);
  --amber: #D97706;
  --red: #DC2626;
  --red-light: rgba(220,38,38,0.08);
  --purple: #7C3AED;
  --purple-light: rgba(124,58,237,0.1);
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Noto Sans SC', 'PingFang SC', sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

html { font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(59,130,246,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.page-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg3);
  color: var(--muted2);
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.month-nav button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--muted2);
}

.month-nav button:disabled { opacity: 0.4; cursor: not-allowed; }

.month-label {
  font-weight: 600;
  min-width: 90px;
  text-align: center;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 560px) {
  .kpi-grid, .kpi-grid-2 { grid-template-columns: 1fr; }
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.kpi-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }

.kpi-value {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
}

.kpi-value.green { color: var(--green); }
.kpi-value.amber { color: var(--amber); }

.kpi-sub { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.kpi-change { font-size: 0.75rem; font-weight: 600; margin-top: 4px; }
.kpi-change.up { color: var(--green); }
.kpi-change.down { color: var(--red); }

.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
}

.section-header {
  padding: 14px 16px 10px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted2);
  border-bottom: 1px solid var(--border);
}

.line-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.line-item:last-child { border-bottom: none; }
.line-item-name { flex: 1; font-size: 0.9rem; }

.line-item-value {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
}

.line-item-value.green { color: var(--green); }
.line-item-value.red { color: var(--red); }

.line-item-total {
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  background: var(--bg2);
}

.line-item-total .value { font-family: var(--mono); }
.line-item-total .value.green { color: var(--green); }
.line-item-total .value.red { color: var(--red); }

.pill {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
}

.pill-cny { background: var(--bg3); color: var(--muted2); }
.pill-usd { background: var(--blue-light); color: var(--blue); }
.pill-hkd { background: rgba(234, 88, 12, 0.1); color: #EA580C; }
.pill-crypto { background: var(--purple-light); color: var(--purple); }

.net-worth-bar {
  background: var(--blue-light);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-bottom: 12px;
}

.net-worth-bar .value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green);
}

.net-worth-bar.negative {
  background: var(--red-light);
  border-color: rgba(220,38,38,0.15);
}

.net-worth-bar.negative .value { color: var(--red); }

.kpi-value.red { color: var(--red); }
.kpi-value.muted { color: var(--muted); }

.rate-note {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  margin-bottom: 16px;
}

.tips-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
}

.tips-card h3 { font-size: 0.9rem; margin-bottom: 10px; color: var(--muted2); }
.tips-card ul { list-style: none; font-size: 0.85rem; color: var(--muted); }
.tips-card li { padding: 4px 0 4px 16px; position: relative; }
.tips-card li::before { content: '·'; position: absolute; left: 4px; font-weight: 700; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  border: none;
  text-decoration: none;
}

.btn-primary { background: var(--blue); color: white; flex: 1; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border2); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fixed-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  z-index: 100;
}

.fixed-bottom .inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.nav-tab {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}

.nav-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--muted2); margin-bottom: 6px; }

.form-input, .form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.95rem;
  background: var(--surface);
}

.form-hint { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.form-hint.converted { color: var(--blue); font-family: var(--mono); }

.edit-section { margin-bottom: 20px; }
.edit-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted2);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}

.account-input-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}

.account-input-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.account-input-header .name { flex: 1; font-weight: 600; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state h2 { font-size: 1.1rem; color: var(--text); margin-bottom: 8px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.modal h2 { font-size: 1.1rem; margin-bottom: 16px; }
.modal-error { color: var(--red); font-size: 0.85rem; margin-top: 8px; }

.hidden { display: none !important; }

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-card-info { flex: 1; }
.account-card-name { font-weight: 600; }
.account-card-meta { font-size: 0.75rem; color: var(--muted); }

.account-card-actions { display: flex; gap: 6px; }

.btn-icon {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.preview-bar {
  background: var(--green-light);
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
}

.preview-bar .value { font-family: var(--mono); font-weight: 700; color: var(--green); }
.preview-bar-negative { background: var(--red-light); border-color: rgba(220,38,38,0.2); }
.preview-bar-negative .value { color: var(--red); }
.preview-bar .value.red { color: var(--red); }
.loading { text-align: center; padding: 40px; color: var(--muted); }
