:root {
  --lime: #b8d94e;
  --pale: #eaf2d8;
  --ink: #141414;
  --green: #9cc93b;
  --green-dark: #5f7d16;
  --white: #ffffff;
  --red: #c94f6d;
  --red-dark: #8f2f47;
  --muted: #444a35;
  --muted-on-dark: #e8eeda;
  --line: #141414;
  --radius-lg: 32px;
  --radius-md: 24px;
  --radius-pill: 999px;
  --spring: cubic-bezier(0.32, 0.72, 0, 1);
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--lime);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; transition: transform 200ms var(--bounce), opacity 160ms var(--spring); }
button:active { transform: scale(0.93); }
button, a, input, select { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 8px;
}

.summary-card :focus-visible,
.bottom-bar :focus-visible,
.modal :focus-visible {
  outline-color: var(--lime);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 60;
  background: var(--ink);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  text-decoration: none;
  transition: top 160ms var(--spring);
}
.skip-link:focus { top: 12px; }

.page {
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header: pale card with flat semicircle decoration */
.header-card {
  position: relative;
  overflow: hidden;
  background: var(--pale);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 20px 20px 18px;
  text-align: center;
}

.header-decor { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.decor-a, .decor-b { position: absolute; border-radius: 50%; }
.decor-a {
  width: 120px; height: 120px;
  right: -48px; top: -64px;
  background: var(--lime);
  border: 2px solid var(--ink);
}
.decor-b {
  width: 72px; height: 72px;
  left: -30px; bottom: -44px;
  background: var(--ink);
}

.header-eyebrow {
  position: relative;
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.month-nav {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.month-label {
  margin: 0;
  font-size: clamp(21px, 6vw, 26px);
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.month-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--white);
  border: 2px solid var(--ink);
  border-radius: 50%;
  transition: transform 200ms var(--bounce), opacity 160ms var(--spring);
}
.month-btn svg { width: 22px; height: 22px; display: block; }
.month-btn:active { transform: scale(0.93); }

.this-month-btn {
  position: relative;
  margin-top: 12px;
  min-height: 44px;
  padding: 10px 20px;
  background: var(--white);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  font-weight: 800;
}

/* Summary: black card */
.summary-card {
  background: var(--ink);
  color: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 22px 20px 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.summary-item { min-width: 0; }

.summary-label {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted-on-dark);
}

.summary-value {
  margin: 0;
  font-size: clamp(20px, 6.2vw, 26px);
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.summary-value.is-negative { color: #ffb3c2; }

.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.progress-track {
  flex: 1 1 auto;
  min-width: 0;
  height: 14px;
  background: #3a3f34;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--lime);
  border-radius: var(--radius-pill);
  transition: width 480ms var(--spring);
}
.progress-fill.is-over { background: var(--red); }

.progress-pill {
  flex: 0 0 auto;
  min-width: 56px;
  text-align: center;
  padding: 6px 12px;
  background: var(--lime);
  color: var(--ink);
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.progress-pill.is-over { background: var(--red); color: var(--white); }

.over-label {
  margin: 12px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #ffb3c2;
}

/* Pie: white card */
.pie-card {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.section-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.pie-empty p { margin: 12px 0 14px; color: var(--muted); }
.pie-body { margin-top: 16px; }

.pie-svg {
  display: block;
  width: min(220px, 72vw);
  height: auto;
  margin: 0 auto;
}
.pie-svg path { stroke: var(--white); stroke-width: 2; }
.pie-svg text {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
}

.pie-legend {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pie-legend li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  font-size: 14px;
}
.legend-dot {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  transform: translateY(2px);
}
.legend-name { flex: 1 1 auto; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.legend-value { flex: 0 0 auto; max-width: 55%; font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }

/* Buttons */
.btn {
  min-height: 44px;
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--ink);
  font-weight: 800;
  font-size: 15px;
  transition: transform 200ms var(--bounce), opacity 160ms var(--spring);
}
.btn:active { transform: scale(0.93); }
.btn-dark { background: var(--ink); color: var(--white); }
.btn-outline-dark { background: var(--white); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; text-decoration: underline; }
.btn-danger { background: var(--red); border-color: var(--red-dark); color: var(--white); }

/* Wallets */
.wallets-section, .history-section {
  background: var(--pale);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.all-time-label {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.wallet-list, .history-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wallet-tile {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 2px solid var(--green-dark);
  background: var(--white);
}
.wallet-tile.is-alt { background: var(--ink); color: var(--white); border-color: var(--ink); }
.wallet-main { flex: 1 1 auto; min-width: 0; }
.wallet-name { display: block; font-weight: 800; overflow-wrap: anywhere; }
.wallet-balance {
  display: block;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}
.wallet-tile.is-alt .wallet-balance { color: var(--lime); }

.icon-btn {
  flex: 0 0 auto;
  min-width: 44px; min-height: 44px;
  padding: 8px 10px;
  border-radius: var(--radius-pill);
  border: 2px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 800;
}
.wallet-tile:not(.is-alt) .icon-btn { border-color: var(--ink); color: var(--ink); }

/* History */
.history-empty { margin: 12px 0 0; color: var(--muted); }

.history-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--white);
  border: 2px solid var(--green-dark);
  border-radius: var(--radius-md);
}
.history-main { flex: 1 1 auto; min-width: 0; }
.history-desc { display: block; font-weight: 800; overflow-wrap: anywhere; }
.history-meta { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.history-amount {
  flex: 0 0 auto;
  max-width: 60%;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.history-amount.is-expense { color: var(--red-dark); }
.history-amount.is-income { color: #2f5d0a; }
.category-pill {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 10px;
  background: var(--ink);
  color: var(--white);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.row-actions { display: flex; gap: 6px; flex: 1 1 100%; justify-content: flex-end; }
.row-actions .icon-btn { border-color: var(--ink); color: var(--ink); padding: 8px; }

.bottom-spacer { height: 12px; }

/* Sticky bottom bar */
.bottom-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--ink);
  border-top: 2px solid var(--ink);
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 12px 6px;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  transition: transform 200ms var(--bounce);
  overflow-wrap: anywhere;
}
.action-btn:active { transform: scale(0.93); }
.action-expense { background: var(--lime); color: var(--ink); border-color: var(--lime); }
.action-income { background: var(--white); color: var(--ink); border-color: var(--white); }
.action-transfer { background: transparent; color: var(--white); border-color: var(--green); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(20, 20, 20, 0.62);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--pale);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 20px;
  animation: modal-in 220ms var(--spring);
}
@keyframes modal-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-head h2, .modal-small h2 { margin: 0; font-size: 20px; font-weight: 800; }
.modal-close {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--white);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: 14px;
}

.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-weight: 800; font-size: 14px; }
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--white);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 16px;
  font-variant-numeric: tabular-nums;
}
.field-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.field-row .field { min-width: 0; }
.field input[type="date"],
.field input[type="time"] {
  min-width: 0;
  padding-left: 10px;
  padding-right: 10px;
}
.field-hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.form-error, .form-warning {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 2px solid var(--ink);
  font-size: 14px;
  font-weight: 700;
}
.form-error { background: #fdeef1; color: var(--red-dark); border-color: var(--red-dark); }
.form-warning { background: #fff7d6; color: #5a4a00; border-color: #8a7600; }
.form-error[hidden], .form-warning[hidden] { display: none; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.transfer-note {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: #fff7d6;
  border: 2px solid #8a7600;
  border-radius: 16px;
  color: #5a4a00;
  font-weight: 700;
  font-size: 14px;
}
.transfer-note[hidden] { display: none; }

.modal-small p { color: var(--muted); overflow-wrap: anywhere; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--white);
  border: 2px solid var(--white);
  border-radius: var(--radius-pill);
  padding: 12px 20px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  overflow-wrap: anywhere;
  animation: toast-in 420ms var(--spring) both;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(0.9); }
  60% { opacity: 1; transform: translateX(-50%) translateY(-4px) scale(1.04); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.toast.toast-out {
  animation: toast-out 260ms ease-in both;
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  to { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.94); }
}

@media (min-width: 480px) {
  .modal-backdrop { align-items: center; }
  /* Layar lebar: Tanggal dan Jam boleh berdampingan, kolomnya lega. */
  .field-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- PWA: safe-area layar penuh ---------- */
/* Bottom bar, modal, dan toast sudah memakai env(safe-area-inset-bottom)
   di atas, dan .page sudah memakai 100dvh. Aturan aditif ini hanya menjaga
   jarak atas konten dari status bar / notch saat berjalan standalone. */
.app {
  padding-top: calc(16px + env(safe-area-inset-top));
}

/* Dipakai JS bila angka masih meluber di ukuran font minimum: barulah
   angka boleh pindah baris. */
.fit-wrap { white-space: normal; overflow-wrap: anywhere; }
