:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #13201c;
  --muted: #5f6f6a;
  --line: #dde4e1;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: #d8efe8;
  --warn: #b45309;
  --danger: #c0362c;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --surface: #131f1c;
    --surface-2: #1b2a26;
    --text: #e8f0ed;
    --muted: #93a6a0;
    --line: #253632;
    --accent: #34c39f;
    --accent-ink: #062019;
    --accent-soft: #163a31;
    --warn: #f0a24b;
    --danger: #ff7a6e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left));
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- top ---------- */
.topbar { display: flex; align-items: center; gap: 8px; height: 48px; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 0; flex: 1; }
.sync { font-size: 13px; color: var(--warn); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); font-size: 24px; line-height: 1;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.3; }

/* ---------- hero ---------- */
.hero {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  margin: 4px 0 16px;
}
.hero-label { margin: 0; font-size: 14px; opacity: 0.85; }
.hero-value { margin: 2px 0 10px; font-size: 40px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-value.over { color: #ffe1dc; }
.hero-sub { margin: 8px 0 0; font-size: 14px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--accent-ink) 25%, transparent); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent-ink); border-radius: inherit; transition: width .3s; }
.meter.over span { background: #ffb4a8; }

/* ---------- entry ---------- */
.entry { background: var(--surface); border-radius: var(--radius); padding: 12px; margin-bottom: 20px; border: 1px solid var(--line); }
.entry-row { display: flex; gap: 8px; }
.entry-row input {
  flex: 1; min-width: 0;
  height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2);
  font-size: 17px; /* >=16px supaya iOS tidak auto-zoom */
}
.entry-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.primary {
  height: 48px; padding: 0 18px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.primary:disabled { opacity: 0.4; }

.preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.pv-amount { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pv-hint { font-size: 13px; color: var(--muted); }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px -12px -2px; padding: 0 12px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 14px; white-space: nowrap;
}
.chip[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.chip-quiet { background: var(--surface-2); border-color: transparent; }

/* ---------- period + breakdown ---------- */
.period { display: flex; align-items: center; margin-bottom: 8px; }
.period-label { flex: 1; text-align: center; display: flex; flex-direction: column; }
.period-label strong { font-size: 15px; }
.period-label span { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
.breakdown { padding: 6px 16px; margin-bottom: 20px; }
.breakdown:empty { display: none; }
.cat-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 2px 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .emoji { font-size: 20px; grid-row: span 2; }
.cat-row .name { font-size: 15px; }
.cat-row .amt { font-size: 15px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.cat-row .bar { grid-column: 2 / 4; height: 5px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.cat-row .bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.cat-row.over .bar span { background: var(--danger); }
.cat-row .budget { font-size: 12px; color: var(--muted); font-weight: 400; display: block; }
.cat-row.over .budget { color: var(--danger); }

/* ---------- list ---------- */
.day { margin-bottom: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px 6px; font-variant-numeric: tabular-nums; }
.day ul { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; border-bottom: 1px solid var(--line); }
.day li:last-child .item { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item .emoji { font-size: 20px; width: 28px; text-align: center; }
.item .text { flex: 1; min-width: 0; }
.item .note { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { display: block; font-size: 13px; color: var(--muted); }
.item .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.item.pending { opacity: 0.6; }
.item.pending .meta::after { content: " · menunggu sinkron"; color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- dialogs ---------- */
.sheet {
  width: min(560px, 100%); max-width: 100%;
  margin: auto auto 0; border: 0; padding: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
  max-height: 90dvh;
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet form { padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.sheet input, .sheet select {
  height: 44px; padding: 0 12px; font-size: 16px; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
}
.sheet-actions, .row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sheet-actions button:not(.primary), .row-actions button {
  height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.sheet-actions .primary { height: 44px; }
.spacer { flex: 1; }
.danger { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details summary { font-size: 14px; color: var(--muted); padding: 6px 0; }
.cat-budgets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding-top: 6px; }
.shortcut-box { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.shortcut-box strong { font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; font-size: 15px;
}
.help { font-size: 13px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; white-space: pre-line; z-index: 10;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
}
