:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14181f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --hutang: #b91c1c;
  --hutang-soft: #fee2e2;
  --piutang: #15803d;
  --piutang-soft: #dcfce7;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.015em; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; }
.spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); }
.wrap { max-width: 880px; margin: 0 auto; padding: 18px 16px 24px; }
.wrap.narrow { max-width: 460px; }

h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 16px; letter-spacing: -.01em; margin: 22px 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

/* ------------------------------------------------------------------- cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card.tight { padding: 12px; }
.cards { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (min-width: 640px) { .cards.three { grid-template-columns: repeat(3, minmax(0,1fr)); } }
/* Kartu ketiga ("Selisih") melebar penuh di layar sempit agar tidak
   menyisakan kolom kosong di sebelahnya. */
.cards.three > :nth-child(3) { grid-column: 1 / -1; }
@media (min-width: 640px) { .cards.three > :nth-child(3) { grid-column: auto; } }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 92px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; line-height: 1.3; min-height: 2.6em; }
.stat .v { font-size: 19px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 380px) { .stat .v { font-size: 17px; } }
.stat.hutang .v { color: var(--hutang); }
.stat.piutang .v { color: var(--piutang); }
.stat .n { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ------------------------------------------------------------------- table */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; gap: 12px; align-items: center;
  padding: 13px 14px; border-bottom: 1px solid var(--line);
  color: inherit;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #fafafa; text-decoration: none; }
.row .main { min-width: 0; flex: 1; }
.row .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .m { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 14px; }
.row .amt.hutang { color: var(--hutang); }
.row .amt.piutang { color: var(--piutang); }
.row .amt.lunas { color: var(--muted); text-decoration: line-through; }

/* -------------------------------------------------------------------- tags */
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; font-weight: 600; letter-spacing: .01em; }
.tag.hutang { background: var(--hutang-soft); color: var(--hutang); }
.tag.piutang { background: var(--piutang-soft); color: var(--piutang); }
.tag.muted { background: #f3f4f6; color: var(--muted); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--hutang); border-color: #fecaca; background: #fff }
.btn.danger:hover { background: var(--hutang-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------- forms */
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink); -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 76px; resize: vertical; }
.grid2 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.formfoot { margin-top: 16px; display: flex; gap: 8px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg label { margin: 0; flex: 1; text-align: center; padding: 9px 8px; font-size: 13.5px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg input { display: none; }
.seg input:checked + span { color: #fff; }
.seg label:has(input:checked) { background: var(--accent); color: #fff; }
.seg label:has(input[value=bayar]:checked) { background: var(--piutang); }
.seg label:has(input[value=hutang]:checked) { background: var(--hutang); }
.seg label:has(input[value=piutang]:checked) { background: var(--piutang); }

/* ------------------------------------------------------------------- flash */
.flash { border-radius: 10px; padding: 10px 13px; font-size: 13.5px; margin-bottom: 14px; }
.flash.ok { background: var(--piutang-soft); color: #14532d; border: 1px solid #bbf7d0; }
.flash.err { background: var(--hutang-soft); color: #7f1d1d; border: 1px solid #fecaca; }

/* ---------------------------------------------------------------- timeline */
.tl { position: relative; margin: 0; padding: 0 0 0 20px; list-style: none; }
.tl:before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl li { position: relative; padding: 0 0 14px; }
.tl li:before {
  content: ""; position: absolute; left: -20px; top: 5px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; border: 2px solid var(--muted);
}
.tl li.tambah:before { border-color: var(--hutang); }
.tl li.bayar:before { border-color: var(--piutang); }
.tl .t { font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.tl .t .amt { font-variant-numeric: tabular-nums; }
.tl .t .amt.tambah { color: var(--hutang); }
.tl .t .amt.bayar { color: var(--piutang); }
.tl .m { font-size: 12.5px; color: var(--muted); }

/* --------------------------------------------------------------- lampiran */
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.thumb {
  position: relative; display: block; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: #f9fafb; aspect-ratio: 1/1;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 10.5px; font-weight: 600;
  color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.72)); }
.thumb .doc { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 10.5px; font-weight: 600; color: var(--muted); text-align: center; padding: 10px 8px 22px; word-break: break-all; min-height: 100%; }
.thumb .doc svg { color: var(--accent); flex: none; }

/* ------------------------------------------------------------------ misc */
.empty { text-align: center; padding: 26px 16px; color: var(--muted); font-size: 13.5px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.bignum { font-size: 30px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.bignum.hutang { color: var(--hutang); }
.bignum.piutang { color: var(--piutang); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { font-size: 13px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--muted); font-weight: 600; }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip:hover { text-decoration: none; }

/* -------------------------------------------------------------- bottom nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  backdrop-filter: blur(10px);
}
.tabbar a {
  flex: 1; text-align: center; font-size: 11px; color: var(--muted); font-weight: 600;
  padding: 6px 2px; border-radius: 10px;
}
.tabbar a .ico { display: block; line-height: 0; margin-bottom: 3px; }
.tabbar a svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); background: var(--accent-soft); }
.tabbar a:hover { text-decoration: none; }

/* ---------------------------------------------------------------- login */
.authwrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.authcard { width: 100%; max-width: 380px; }
.authlogo { text-align: center; margin-bottom: 18px; }
.authlogo .big { font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.authlogo .s { color: var(--muted); font-size: 13px; }
@media print { .topbar, .tabbar, .actions { display: none; } body { padding: 0; } }