:root {
  --green: #0e7454;
  --green-dark: #0a5a41;
  --green-soft: #e3f3ec;
  --gold: #f6c448;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17211d;
  --muted: #6b7772;
  --line: #e4e9e6;
  --ok: #1d9a5b;
  --ok-soft: #dff5e8;
  --warn: #c98a00;
  --warn-soft: #fff3d1;
  --bad: #d64545;
  --bad-soft: #fde3e3;
  --info-soft: #e7eefc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(20,60,40,.06);
  --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512;
    --card: #182019;
    --text: #eef3f0;
    --muted: #93a09a;
    --line: #26312b;
    --green-soft: #17342a;
    --ok-soft: #163b28;
    --warn-soft: #3d2f0c;
    --bad-soft: #3f1c1c;
    --info-soft: #1c2740;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--green);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-coin {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--gold); color: var(--green);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; opacity: .85; }

/* Layout */
.view { max-width: 640px; margin: 0 auto; padding: 14px 14px 24px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 8px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.card.hero {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
}
.hero .label { font-size: 12px; opacity: .85; }
.hero .big { font-size: 26px; font-weight: 800; margin: 2px 0 6px; }
.hero .sub { font-size: 13px; opacity: .9; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 18px; font-weight: 800; margin-top: 2px; }
.stat .value.neg { color: var(--bad); }

.progress { height: 8px; background: rgba(255,255,255,.25); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--gold); border-radius: 99px; transition: width .3s; }

/* Lists */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
.row.clickable:active { background: var(--green-soft); }
.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  background: var(--green-soft); color: var(--green);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.avatar.gold { background: var(--gold); color: var(--green-dark); }
.avatar.dim { background: var(--line); color: var(--muted); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-end { text-align: right; flex: none; }
.row-end .amt { font-weight: 700; font-size: 14px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 99px; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: #3559b8; }
.badge.gold { background: var(--gold); color: var(--green-dark); }
.badge.muted { background: var(--line); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px;
  font-weight: 700; font-size: 15px; background: var(--green); color: #fff;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn.block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-ghost { background: rgba(255,255,255,.18); color: #fff; }
.btn-outline { background: transparent; color: var(--green); border: 1.5px solid var(--green); }
.btn-soft { background: var(--green-soft); color: var(--green); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn-gold { background: var(--gold); color: var(--green-dark); }
.btn-row { display: flex; gap: 8px; margin: 10px 0; }
.btn-row .btn { flex: 1; }

/* Form */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 10px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 15px; }
.check input { width: 20px; height: 20px; }
select.inline {
  width: 100%; padding: 12px 14px; border-radius: 12px; font-weight: 700; font-size: 15px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text); margin-bottom: 12px;
  -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}

/* Summary chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { background: var(--card); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px; font-size: 12px; flex: 1; min-width: 90px; }
.chip b { display: block; font-size: 14px; margin-top: 1px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 6px 0;
}
.tab .tab-ico { font-size: 20px; }
.tab.active { color: var(--green); }

/* Modal / bottom sheet */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
  animation: up .2s ease;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet .sheet-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: #1f2924; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.toast.err { background: var(--bad); }

/* Setup screen */
.setup { padding: 20px 0; }
.setup ol { padding-left: 20px; line-height: 1.6; }
.setup code { background: var(--green-soft); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.small { font-size: 12px; color: var(--muted); }
.mt { margin-top: 12px; }
.text-right { text-align: right; }

/* Pilihan nominal cepat + segmented control */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip-btn {
  flex: 1; min-width: 56px; padding: 9px 6px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--bg); font-weight: 700; font-size: 14px;
}
.chip-btn.on { background: var(--green); color: #fff; border-color: var(--green); }
.seg { display: flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: block; text-align: center; padding: 11px 6px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg input:checked + span { background: var(--green); color: #fff; }

/* Pemilih bulan */
.period-nav { display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px; }
.period-nav select.inline { margin-bottom: 0; flex: 1; min-width: 0; }
.period-nav .btn { flex: none; width: 46px; padding: 0; font-size: 22px; border-radius: 12px; }
