:root {
  --bg: #0d1412;
  --bg-soft: #131b18;
  --card: #18211d;
  --border: #243029;
  --text: #eef3f0;
  --muted: #93a39a;
  --accent: #0e7a55;
  --accent-bright: #22b67e;
  --positive: #3ddc97;
  --negative: #ff7a7a;
  --danger: #e5484d;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 14px;
}
.wordmark { display: flex; align-items: center; gap: 12px; }
.wordmark-logo { border-radius: 8px; }
.wordmark-title { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; }
.wordmark-sub { font-size: 12px; color: var(--accent-bright); font-weight: 600; }

/* Buttons */
.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #0f8a60; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent-bright); }
.btn-danger-ghost { background: transparent; color: var(--negative); border-color: var(--border); }
.btn-danger-ghost:hover { border-color: var(--danger); }

/* Cards */
main { padding-top: 24px; padding-bottom: 40px; display: flex; flex-direction: column; gap: 20px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.muted { color: var(--muted); }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 17px; }

/* Range + filter buttons */
.range-btns, .filter-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.range-btn, .filter-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
}
.range-btn:hover, .filter-btn:hover { color: var(--text); border-color: var(--accent-bright); }
.range-btn.active, .filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Chart */
.chart-wrap { position: relative; height: 260px; }
#chart { width: 100%; height: 100%; display: block; }
.chart-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
.chart-empty[hidden] { display: none; }

/* Account totals */
.acct-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.acct-totals > div { display: flex; flex-direction: column; gap: 4px; }
.acct-totals .muted { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.acct-totals strong { font-size: 22px; font-variant-numeric: tabular-nums; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
.empty-note { color: var(--muted); font-size: 14px; padding: 8px 0 0; }
.empty-note[hidden] { display: none; }

/* History */
.data-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.data-btns .btn { padding: 7px 14px; font-size: 13px; }

.entry {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.entry:last-child { border-bottom: none; }
.entry-dir {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; flex-shrink: 0;
}
.entry-dir.in { background: rgba(61, 220, 151, 0.12); color: var(--positive); }
.entry-dir.out { background: rgba(255, 122, 122, 0.12); color: var(--negative); }
.entry-main { flex: 1; min-width: 0; }
.entry-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.entry-acct { font-weight: 700; font-size: 14px; }
.entry-amt { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 15px; }
.entry-meta { font-size: 12.5px; color: var(--muted); }
.entry-note { font-size: 13px; color: var(--text); opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  font: inherit; background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent-bright); }
.icon-btn.delete:hover { color: var(--danger); border-color: var(--danger); }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state[hidden] { display: none; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 8px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 auto 20px; font-size: 14px; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-soft); position: sticky; bottom: 0; z-index: 40; }
.footer-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 20px; padding-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.footer-wordmark { font-weight: 800; }
.footer-wordmark span { color: var(--accent-bright); font-weight: 600; }
.footer-privacy { color: var(--muted); font-size: 13px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 18px; font-size: 19px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select {
  font: inherit; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--accent-bright); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Mobile */
@media (max-width: 640px) {
  .cards { grid-template-columns: 1fr; }
  .stat-value { font-size: 26px; }
  .acct-totals { grid-template-columns: 1fr 1fr 1fr; }
  .acct-totals strong { font-size: 17px; }
  .header-inner { padding-top: 12px; padding-bottom: 12px; }
  #add-entry-btn { padding: 8px 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .entry { flex-wrap: wrap; }
  .entry-actions { width: 100%; justify-content: flex-end; }
}
