:root {
  --bg: #0d1117;
  --card: #161c26;
  --card2: #1d2533;
  --line: #2a3444;
  --fg: #e8edf4;
  --muted: #8b97a8;
  --accent: #35c2a0;
  --accent-dim: #1e6b58;
  --danger: #e0596b;
  --warn: #e0a94d;
  --radius: 14px;
  --nav-h: calc(62px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.5 -apple-system, "Noto Sans Thai", "Sukhumvit Set", sans-serif;
  padding-bottom: var(--nav-h);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.4em; font-size: 14px; }

/* ---------- PIN gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px;
}
.gate-logo { width: 56px; height: 56px; color: var(--accent); }
.gate input {
  width: 200px; text-align: center; letter-spacing: 8px; font-size: 26px;
}

/* ---------- inputs / buttons ---------- */
input, select {
  background: var(--card2); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; font-size: 16px; width: 100%;
  outline: none;
}
input:focus { border-color: var(--accent-dim); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card2); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 18px; font-size: 16px; cursor: pointer;
}
.btn svg { width: 21px; height: 21px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06231b; font-weight: 700; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.big { flex: 1; padding: 16px 10px; font-size: 17px; }
.btn.grow { flex: 1; }
.btn:active { transform: scale(.97); }

/* ---------- layout ---------- */
.page { padding: 18px 16px 30px; max-width: 560px; margin: 0 auto; }
.hero { text-align: center; padding: 26px 0 18px; }
.hero h1 { font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.pagehead { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 0 4px; }
.pagehead h2 { font-size: 20px; }
.nav-arrow { background: none; border: none; color: var(--muted); padding: 8px; cursor: pointer; }
.nav-arrow svg { width: 22px; height: 22px; }
.bigtotal { text-align: center; font-size: 38px; font-weight: 800; margin: 6px 0 16px; }
.sect { font-size: 14px; color: var(--muted); font-weight: 600; margin: 22px 0 10px; }
.actions { display: flex; gap: 10px; margin: 6px 0 4px; }
.row { display: flex; gap: 10px; align-items: end; }
.col { flex: 1; }

/* ---------- cards / list ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px;
}
.wait { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; cursor: pointer;
}
.item .ic {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--card2); color: var(--accent); font-size: 17px;
}
.item .mid { flex: 1; min-width: 0; }
.item .mid b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.item .mid span { font-size: 12.5px; color: var(--muted); }
.item .amt { font-weight: 700; font-size: 16px; white-space: nowrap; }
.day-sep { font-size: 13px; color: var(--muted); margin: 10px 2px 2px; }

/* ---------- chart ---------- */
.chart {
  display: flex; align-items: flex-end; gap: 2px; height: 110px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 10px 8px;
}
.chart .bar { flex: 1; background: var(--accent-dim); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.chart .bar.today { background: var(--accent); }

/* ---------- category rows / budgets ---------- */
.catrow { padding: 11px 13px; }
.catrow .top { display: flex; justify-content: space-between; margin-bottom: 6px; }
.catrow .top b { font-size: 15px; }
.meter { height: 6px; background: var(--card2); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter i.over { background: var(--danger); }
.meter i.near { background: var(--warn); }
.budget-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.budget-row span { flex: 1; }
.budget-row input { width: 120px; text-align: right; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters select { width: 130px; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--card); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin-bottom: 4px; }
.sheet .row { margin-top: 16px; }
.slip-thumb { max-height: 120px; border-radius: 10px; margin: 8px 0 2px; border: 1px solid var(--line); }
.cat-pick { display: flex; flex-wrap: wrap; gap: 7px; }
.cat-pick button {
  background: var(--card2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 999px; padding: 7px 14px; font-size: 14.5px; cursor: pointer;
}
.cat-pick button.on { background: var(--accent); border-color: var(--accent); color: #06231b; font-weight: 700; }

/* ---------- bottom nav ---------- */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: var(--nav-h);
  display: flex; background: rgba(13,17,23,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
#nav button {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11.5px; cursor: pointer;
}
#nav button svg { width: 23px; height: 23px; }
#nav button.on { color: var(--accent); }

/* ---------- segmented control ---------- */
.seg { display: flex; background: var(--card2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; margin: 10px 0 4px; }
.seg button { flex: 1; background: none; border: none; color: var(--muted); padding: 8px 6px; border-radius: 8px; font-size: 14.5px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #06231b; font-weight: 700; }
.center { text-align: center; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 5px; }
.tag.fam { color: var(--accent); border-color: var(--accent-dim); }
