:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f0f3f2;
  --border: #e2e7e5;
  --text: #17201d;
  --muted: #66736f;
  --accent: #0f766e;
  --accent-soft: #e0f2ef;
  --pos: #15803d;
  --neg: #c2410c;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 22, .05), 0 4px 16px rgba(16, 24, 22, .04);
  --radius: 14px;
  --c1: #0f766e; --c2: #f59e0b; --c3: #6366f1; --c4: #ec4899; --c5: #0ea5e9;
  --c6: #84cc16; --c7: #a855f7; --c8: #ef4444; --c9: #14b8a6; --c10: #94a3b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --surface: #161e1b; --surface-2: #1d2724; --border: #27322e;
    --text: #e7eeeb; --muted: #93a29d; --accent: #2dd4bf; --accent-soft: #123a35;
    --pos: #4ade80; --neg: #fb923c; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .95rem; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; padding: 20px 14px; border-right: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; padding: 0 8px 20px; }
.brand.big { font-size: 1.4rem; padding: 0 0 4px; }
.logo {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: .8rem; font-weight: 800;
}
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
#nav a i { font-style: normal; width: 22px; text-align: center; }
#nav a:hover { background: var(--surface-2); }
#nav a.active { background: var(--accent-soft); color: var(--accent); }
.logout { margin-top: auto; }
main { flex: 1; min-width: 0; padding: 24px clamp(16px, 3vw, 36px) 100px; max-width: 1180px; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

/* controls */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600;
  cursor: pointer; background: var(--surface-2); color: var(--text); text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04201c; } }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:hover { filter: brightness(1.05); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 1.1rem; cursor: pointer;
}
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: grid; gap: 5px; font-size: .85rem; font-weight: 500; color: var(--muted); }
.month-pick { display: flex; align-items: center; gap: 8px; }
.month-label { min-width: 130px; text-align: center; font-weight: 600; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 4px 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.link { color: var(--accent); text-decoration: none; font-size: .85rem; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 16px; }

/* quick add */
.quick { position: relative; display: flex; gap: 8px; margin-bottom: 16px; }
.quick input { padding: 13px 16px; font-size: 1rem; border-radius: 12px; box-shadow: var(--shadow); }
.quick .btn { border-radius: 12px; padding: 0 20px; }
.quick-preview {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 5; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 8px; display: none;
}
.quick-preview.show { display: block; }
.pv-row { display: flex; gap: 10px; align-items: center; padding: 6px 8px; font-size: .9rem; }
.pv-row .chip { font-size: .75rem; }
.pv-err { color: var(--neg); font-size: .85rem; padding: 4px 8px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 2px; }
.stat span { color: var(--muted); font-size: .8rem; font-weight: 500; }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat small { font-size: .75rem; color: var(--muted); }

/* charts */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text, .donut-wrap text { fill: var(--muted); font-size: 10px; }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { width: 150px; height: 150px; flex-shrink: 0; }
.legend { flex: 1; min-width: 160px; display: grid; gap: 6px; font-size: .85rem; }
.legend div { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: .9rem; }

/* budget bars */
.bar-row { margin-bottom: 12px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; gap: 8px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; border-radius: 99px; background: var(--accent); }
.bar > div.warn { background: var(--warn); }
.bar > div.over { background: var(--danger); }

/* transactions */
.tx-list { display: grid; }
.tx-day { font-size: .78rem; font-weight: 600; color: var(--muted); padding: 12px 18px 4px; display: flex; justify-content: space-between; }
.tx { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 9px 18px; cursor: pointer; }
.card:not(.flush) .tx { padding: 9px 0; }
.card:not(.flush) .tx-day { padding: 12px 0 4px; }
.tx:hover { background: var(--surface-2); }
.tx .ic { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; font-size: 1.1rem; }
.tx .t1 { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); font-size: .72rem; color: var(--muted); }
.chip.wa { background: #dcfce7; color: #166534; }
@media (prefers-color-scheme: dark) { .chip.wa { background: #12351f; color: #86efac; } }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; margin-bottom: 12px; }
.tx-totals { display: flex; gap: 18px; font-size: .88rem; margin-bottom: 10px; flex-wrap: wrap; color: var(--muted); }
.tx-totals b { color: var(--text); }

/* kategori & dompet */
.tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; font: inherit; font-weight: 600; padding: 6px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.cat-list, .acc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); }
.item:hover { border-color: var(--accent); }
.item .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.item .name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.item .kw { font-size: .78rem; color: var(--muted); margin-top: 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .bal { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.item .bar { margin-top: 8px; }

/* whatsapp */
.wa-qr { display: grid; place-items: center; gap: 10px; text-align: center; padding: 8px 0; }
.wa-qr img { width: 240px; height: 240px; border-radius: 12px; background: #fff; padding: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: var(--pos); } .dot.wait { background: var(--warn); }
.pin { font-size: 1.6rem; letter-spacing: .25em; font-weight: 700; font-family: ui-monospace, monospace; color: var(--accent); }
ol.steps { padding-left: 20px; margin: 8px 0; font-size: .9rem; }
ol.steps li { margin-bottom: 4px; }
.chat { background: var(--surface-2); border-radius: 12px; padding: 12px; height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: .88rem; white-space: pre-wrap; word-wrap: break-word; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
@media (prefers-color-scheme: dark) { .bubble.me { color: #04201c; } }
.bubble.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; margin-top: 8px; }
.chat-input textarea { resize: none; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.examples button { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-size: .85rem; padding: 5px 11px; border-radius: 99px; cursor: pointer; }
.examples button:hover { border-color: var(--accent); }
.allowed-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px; }

/* dialog */
dialog { border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text); width: min(460px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 15, 13, .45); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.dlg h3 { margin: 0 0 4px; font-size: 1.1rem; }
.dlg .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.dlg .actions .spacer { flex: 1; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); padding: 3px; border-radius: 10px; }
.seg label { display: block; color: var(--muted); }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 7px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: .9rem; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.amount-input { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }

.fab {
  position: fixed; right: 22px; bottom: 22px; width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--accent); color: #fff; font-size: 1.8rem; cursor: pointer; box-shadow: 0 8px 24px rgba(15,118,110,.35); z-index: 20;
}
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 12px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }
.err { color: var(--danger); font-size: .9rem; min-height: 1em; }

/* mobile */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; width: auto; z-index: 30;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .sidebar .brand, .sidebar .logout { display: none; }
  #nav { flex-direction: row; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 0; font-size: .68rem; padding: 6px 4px; flex: 1; text-align: center; }
  #nav a i { font-size: 1.15rem; width: auto; }
  main { padding: 16px 16px 120px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat b { font-size: 1.05rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { grid-column: 1 / -1; }
  .grid2 { grid-template-columns: 1fr; }
  .fab { bottom: calc(76px + env(safe-area-inset-bottom)); right: 16px; }
  .quick .btn { padding: 0 14px; }
  .month-label { min-width: 100px; }
  .tx { padding: 9px 16px; }
}
.wa-add { display: grid; grid-template-columns: 1.3fr 1fr auto; gap: 8px; margin-bottom: 8px; }
@media (max-width: 760px) { .wa-add { grid-template-columns: 1fr 1fr; } .wa-add .btn { grid-column: 1 / -1; } }
.bubble.template { cursor: pointer; font-family: ui-monospace, monospace; border-style: dashed; }
.bubble.template::after { content: '✎ klik untuk isi'; display: block; font-family: system-ui, sans-serif; font-size: .72rem; color: var(--accent); margin-top: 4px; }
.rep-form { display: grid; gap: 4px; }
.rep-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); color: var(--text); font-size: .9rem; }
.rep-ctl { display: flex; align-items: center; gap: 8px; }
.rep-ctl input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.rep-ctl input[type=time] { width: 110px; }
.rep-form .btn { margin-top: 10px; justify-self: start; }
.networth { display: grid; gap: 4px; background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }
.networth b { display: block; font-size: 1.8rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.nw-parts { display: flex; gap: 18px; flex-wrap: wrap; font-size: .88rem; margin-top: 6px; }
.nw-parts span b { display: inline; font-size: inherit; letter-spacing: 0; }
.section-title { margin: 22px 0 10px; font-size: 1rem; }
.item .sub { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.item.done { opacity: .55; }
.hist { max-height: 160px; overflow: auto; font-size: .85rem; border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.hist div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.hist div:last-child { border-bottom: 0; }
.dlg .tabs { margin: 0; }
@media (max-width: 760px) { #nav a span { font-size: .62rem; } }
