:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17211f;
  --muted: #5d6b68;
  --line: #e3e8e6;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f1;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --err: #b42318;
  --err-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --card: #182120;
    --text: #e8eeec;
    --muted: #9aa8a5;
    --line: #26312f;
    --brand: #2bb3a5;
    --brand-ink: #062320;
    --brand-soft: #143a36;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --warn: #f5b450;
    --warn-soft: #3a2a10;
    --err: #f87168;
    --err-soft: #3b1614;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; scroll-padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.has-nav { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--brand); }
code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
ul { margin: 4px 0; padding-left: 20px; }

.ic { width: 22px; height: 22px; flex: none; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn { background: rgba(255,255,255,.18); color: inherit; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; margin-left: -10px; color: inherit; border-radius: 50%; }
.icon-btn:active { background: rgba(255,255,255,.15); }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px; }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 10px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 550;
}
.tabbar a.on { color: var(--brand); }

/* Cards & lists */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card-title { margin: 0 0 12px; font-size: 1rem; }
.card.list { padding: 0; overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px 16px;
  color: inherit; text-decoration: none;
  border-top: 1px solid var(--line);
}
.list-item:first-child { border-top: 0; }
a.list-item:active, a.row-link:active { background: var(--brand-soft); }
.list-item .ic, .row-link .ic { color: var(--muted); width: 18px; height: 18px; }
.list-item.me { background: var(--brand-soft); }
.list-item.dim { opacity: .55; }
.row-link { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.grow { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.amount { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--err); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.pre { white-space: pre-wrap; margin: 0; }
.empty { text-align: center; padding: 28px 16px; }
.empty p { margin-top: 0; }

.section-title { font-size: .95rem; margin: 22px 4px 8px; color: var(--muted); font-weight: 600; }
.hello { margin: 0 4px 12px; }
.meta-line { display: flex; align-items: center; gap: 8px; margin: 0 4px 12px; flex-wrap: wrap; }

.hero { background: var(--brand); color: var(--brand-ink); border: 0; }
.hero .label { opacity: .85; }
.big { font-size: 1.9rem; font-weight: 750; margin: 2px 0 12px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.split strong { display: block; font-variant-numeric: tabular-nums; }
.label { display: block; font-size: .8rem; color: var(--muted); margin: 0; }
.hero .label { color: inherit; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat { min-width: 0; }
.stat strong { display: block; font-size: clamp(.95rem, 4.2vw, 1.1rem); margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.kv > span:last-child { text-align: right; white-space: nowrap; }
.kv.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }

.profile { display: flex; align-items: center; gap: 14px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 1.2rem; }

/* Badges & alerts */
.badge { display: inline-block; font-size: .7rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: .92rem; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-err { background: var(--err-soft); color: var(--err); }
.alert a { color: inherit; font-weight: 600; }

/* Forms */
.form label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 14px; }
.form label:last-child { margin-bottom: 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* 16px mencegah zoom otomatis di iOS */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 label { margin-bottom: 14px; min-width: 0; }
.grid2 input { min-width: 0; max-width: 100%; }
input[type=date] { -webkit-appearance: none; appearance: none; min-width: 0; }
.money { display: flex; align-items: center; margin-top: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.money:focus-within { outline: 2px solid var(--brand); border-color: transparent; }
.money span { padding: 0 12px; color: var(--muted); font-weight: 600; }
.money input { margin: 0; border: 0; background: transparent; text-align: right; font-variant-numeric: tabular-nums; }
.money input:focus { outline: 0; }
.total-line { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.total-line strong { font-size: 1.15rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;
  font: inherit; font-weight: 650; text-decoration: none;
  color: var(--brand-ink); background: var(--brand);
  border: 0; border-radius: 12px; cursor: pointer;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn-sm .ic { width: 18px; height: 18px; }
.btn-block { display: flex; width: 100%; }
.btn-ghost { background: var(--card); color: var(--brand); border: 1px solid var(--line); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.actions form { display: contents; }
.actions > .btn, .actions form .btn { flex: 1 1 140px; }
form.actions { display: block; }

.pay-form { display: flex; gap: 8px; align-items: center; padding: 0 16px 12px; }
.pay-form input[type=date] { margin: 0; min-height: 36px; padding: 6px 10px; flex: 1; }
.pay-form .btn { flex: none; }

.login-box { max-width: 380px; margin: 6vh auto 0; }
.brand { text-align: center; margin-bottom: 18px; }
.brand h2 { margin: 10px 0 2px; }
.brand p { margin: 0; }

.print-only { display: none; }

/* Grafik */
:root { --bar: #008f80; --bar-neg: #c8322a; --grid: #edf0ef; --axis: #c9d1ce; }
@media (prefers-color-scheme: dark) { :root { --bar: #2bb3a5; --bar-neg: #e5534b; --grid: #222c2a; --axis: #3a4744; } }
.chart-card { padding: 12px 12px 8px; }
.chart { position: relative; -webkit-tap-highlight-color: transparent; user-select: none; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .val { fill: var(--text); font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--bar); }
.chart .bar.neg { fill: var(--bar-neg); }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit.on { fill: var(--text); fill-opacity: .05; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 150px; padding: 8px 10px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: .8rem;
}
.chart-tip[hidden] { display: none; }
.chart-tip span { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.chart-tip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip b.neg { color: var(--err); }
.chart-table { margin-top: 6px; font-size: .85rem; }
.chart-table summary { color: var(--brand); cursor: pointer; padding: 6px 4px; font-weight: 600; }
.chart-table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td { text-align: right; padding: 6px 4px; border-top: 1px solid var(--line); }
.chart-table th:first-child, .chart-table td:first-child { text-align: left; }
.chart-table th { color: var(--muted); font-weight: 600; }

@media (min-width: 720px) {
  .wrap { padding: 24px 16px; }
}

@media print {
  .topbar { position: static; background: none; color: #000; padding: 0; }
  .topbar .icon-btn, .topbar .btn, .tabbar, .no-print, .pay-form { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .print-only { display: block; }
}

/* Proyek & transaksi */
.amount-col { text-align: right; }
.amount-col .small { margin-top: -2px; }
.quick-add { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 4px; }
.quick-add .btn { min-width: 0; }
.btn-in { background: var(--ok-soft); color: var(--ok); }
.btn-out { background: var(--err-soft); color: var(--err); }
.tx-ic { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; }
.tx-ic .ic { width: 18px; height: 18px; color: inherit; }
.list-item .tx-ic .ic { color: inherit; }
.tx-in { background: var(--ok-soft); color: var(--ok); }
.tx-out { background: var(--err-soft); color: var(--err); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; margin-bottom: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.form .seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 9px; font-weight: 650; color: var(--muted); cursor: pointer; }
.seg-in input:checked + span { background: var(--ok-soft); color: var(--ok); }
.seg-out input:checked + span { background: var(--err-soft); color: var(--err); }
.seg input:focus-visible + span { outline: 2px solid var(--brand); }

.share { padding: 14px 16px; border-top: 1px solid var(--line); }
.share:first-child { border-top: 0; }
.share.me { background: var(--brand-soft); }
.share-head { display: flex; align-items: center; gap: 12px; }
.share-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; padding: 10px 12px; background: var(--bg); border-radius: 10px; }
.share-split strong { display: block; font-variant-numeric: tabular-nums; }
.share-split .small { display: block; }
.share .pay-form { padding: 10px 0 0; }

.hero-link { display: block; text-decoration: none; }
.flow ol { margin: 0; padding-left: 20px; }
.flow li { margin: 4px 0; }
