:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --ink: #1c2a1e;
  --muted: #6b7a6d;
  --line: #e2e8e1;
  --brand: #3a7d44;
  --brand-dark: #2c5f34;
  --accent: #d98e2c;
  --danger: #c0392b;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 0.5em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1rem; color: var(--muted); margin-top: 1.2em; }
.muted { color: var(--muted); font-size: 0.9rem; }

.screen { min-height: 100vh; }

/* ---- login ---- */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
  text-align: center;
}
.login-card h1 { font-size: 1.6rem; }
.login-card form { text-align: left; margin-top: 20px; }

/* ---- layout ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--brand-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; }

#pages {
  padding: 14px 14px 90px;
  max-width: 640px;
  margin: 0 auto;
}

.page h2 { color: var(--brand-dark); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.68rem;
  padding: 6px 2px;
  border-radius: 10px;
}
.tab span { font-size: 1.15rem; }
.tab.active { color: var(--brand); font-weight: 700; background: #eaf3ea; }

/* ---- form / card elements ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.form input, .form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 1rem;
  background: #fbfcfb;
  color: var(--ink);
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--brand);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.5); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.full { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 0.8rem; }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; margin: 4px 0; }
.saved { color: var(--brand); font-size: 0.85rem; min-height: 1.1em; margin: 4px 0; }
.computed { font-size: 0.9rem; color: var(--brand-dark); font-weight: 600; margin: -4px 0 12px; }

/* ---- dashboard tiles ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat-tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.stat-tile.small { padding: 10px; text-align: center; }
.stat-label { font-size: 0.75rem; color: var(--muted); }
.stat-value { font-size: 1.25rem; font-weight: 700; color: var(--brand-dark); margin-top: 2px; }
.summary { margin-bottom: 8px; }

.row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.95rem; }
.row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 1.05rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 1.2em; }
.section-head h3 { margin: 0; }
.section-head select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }

/* ---- list items ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  font-size: 0.9rem;
}
.list-item .li-main { display: flex; flex-direction: column; gap: 2px; }
.list-item .li-date { font-weight: 600; }
.list-item .li-sub { color: var(--muted); font-size: 0.8rem; }
.list-item .li-amount { font-weight: 700; color: var(--brand-dark); }
.list-item .li-amount.neg { color: var(--danger); }
.list-item .li-del {
  background: none; border: none; color: var(--danger); font-size: 1.1rem;
  padding: 4px 6px; margin-left: 8px; cursor: pointer;
}
.empty { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 18px 0; }

@media (min-width: 640px) {
  .tabbar { max-width: 640px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}
