:root {
  --green: #2f4430;
  --green-2: #4a6741;
  --cream: #f6f4ee;
  --card: #ffffff;
  --ink: #22281f;
  --muted: #7d8577;
  --line: #e3e1d8;
  --amber: #b07d2b;
  --red: #b0402b;
  --ok: #3e7a46;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Thai', 'Sarabun', sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.err { color: var(--red); font-size: .85rem; min-height: 1.2em; margin-top: 8px; }

/* ---------- login ---------- */
.login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  background: var(--green); padding: 24px;
}
.login-box {
  background: var(--card); border-radius: var(--radius); padding: 28px 22px;
  width: 100%; max-width: 360px; text-align: center;
}
.login-box h1 { font-size: 1.3rem; color: var(--green); margin-bottom: 6px; }
.login-box input {
  width: 100%; margin-top: 18px; padding: 12px 14px; font-size: 1.1rem; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; letter-spacing: .2em;
}
.login-box .btn { margin-top: 12px; width: 100%; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--green); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600;
}
.linklike { background: none; border: none; color: #d9e2d4; font-size: .9rem; cursor: pointer; }
main {
  padding: 14px 14px calc(env(safe-area-inset-bottom) + 86px);
  max-width: 760px; margin: 0 auto;
}
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; padding: 8px 0 10px;
  font-size: .72rem; color: var(--muted); cursor: pointer;
}
.tab .ico { display: block; font-size: 1.15rem; margin-bottom: 2px; }
.tab.active { color: var(--green); font-weight: 700; }

/* ---------- cards / common ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: .95rem; color: var(--green); margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 1.25rem; font-weight: 700; }
.stat .l { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.n.ok { color: var(--ok); } .n.warn { color: var(--amber); } .n.bad { color: var(--red); }

.btn {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; font-size: .9rem; cursor: pointer; color: var(--ink);
}
.btn.primary { background: var(--green-2); border-color: var(--green-2); color: #fff; font-weight: 600; }
.btn.small { padding: 5px 10px; font-size: .8rem; }
.btn.danger { color: var(--red); border-color: #e4c7bf; }
.row-actions { display: flex; gap: 6px; }

.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 76px); z-index: 11;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: var(--green-2); color: #fff; font-size: 1.7rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}

/* ---------- list rows ---------- */
.sec-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 18px 2px 8px;
}
.sec-head h3 { font-size: .95rem; color: var(--green); }
.sec-head .sum { font-size: .8rem; color: var(--muted); }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 10px; align-items: flex-start;
}
.item.done .t { text-decoration: line-through; color: var(--muted); }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; font-size: .92rem; }
.item .d { font-size: .8rem; color: var(--muted); margin-top: 2px; word-break: break-word; }
.item .amt { text-align: right; font-size: .9rem; white-space: nowrap; }
.item .amt .main { font-weight: 700; }
.item .amt .sub { font-size: .75rem; color: var(--muted); }
.check {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--green-2);
  background: #fff; cursor: pointer; flex: none; font-size: 1rem; color: #fff; line-height: 1;
}
.check.on { background: var(--green-2); }
.pill {
  display: inline-block; font-size: .7rem; padding: 2px 8px; border-radius: 99px;
  background: var(--cream); border: 1px solid var(--line); color: var(--muted); margin-right: 4px;
}
.pill.doing { background: #f4e8d2; color: var(--amber); border-color: #e6d2ac; }
.pill.done { background: #e2eee4; color: var(--ok); border-color: #c4dcc8; }
.pill.overdue { background: #f6e0da; color: var(--red); border-color: #e7c3b9; }

/* progress bar */
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--green-2); }
.bar > span.over { background: var(--red); }

/* budget table */
table.budget { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.budget th { text-align: right; color: var(--muted); font-weight: 500; padding: 4px 2px; border-bottom: 1px solid var(--line); }
table.budget th:first-child, table.budget td:first-child { text-align: left; }
table.budget td { padding: 6px 2px; text-align: right; border-bottom: 1px solid var(--cream); }
td.over { color: var(--red); font-weight: 700; }

/* filters */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 99px;
  padding: 6px 12px; font-size: .8rem; cursor: pointer; color: var(--ink); white-space: nowrap;
}
.chip.on { background: var(--green-2); border-color: var(--green-2); color: #fff; }

/* ---------- sheet (ฟอร์ม) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: #fff; border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  max-height: 86dvh; overflow-y: auto; max-width: 760px; margin: 0 auto;
}
.sheet h2 { font-size: 1rem; color: var(--green); margin-bottom: 12px; }
.sheet label { display: block; font-size: .8rem; color: var(--muted); margin: 10px 0 4px; }
.sheet input, .sheet select, .sheet textarea {
  width: 100%; padding: 10px 12px; font-size: .95rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-family: inherit;
}
.sheet .btns { display: flex; gap: 8px; margin-top: 16px; }
.sheet .btns .btn { flex: 1; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

@media (min-width: 700px) {
  body { font-size: 15px; }
  .grid2 { grid-template-columns: repeat(4, 1fr); }
}
