/* ============ tokens (gelap, clean, aksen indigo) ============ */
:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #131315;
  --surface-2: #1c1c1f;
  --surface-3: #27272b;
  --text: #f5f5f6;
  --text-2: #b9b9bf;
  --text-muted: #7c7c84;
  --line: #222225;
  --grid: #1c1c1f;
  --baseline: #34343a;
  --accent: #5b5ff0;           /* indigo */
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 95, 240, 0.18);
  --accent-text: #9396fa;      /* indigo terang untuk teks/link di atas hitam */
  --pos: #3fbf5f;
  --danger: #ff6b5e;

  /* palet kategori (varian gelap, divalidasi CVD & kontras pada permukaan gelap) */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s-muted: #3a3a40;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23b9b9bf' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --tabbar-h: 64px;
}

/* ============ base ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
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; }
a { color: inherit; }
h1, h2, p { margin: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--text-muted); }
.neg { color: var(--danger); }
.link { color: var(--accent-text); text-decoration: none; font-size: 14px; font-weight: 500; }

.app {
  max-width: 600px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 4px)
    max(16px, env(safe-area-inset-right))
    calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px)
    max(16px, env(safe-area-inset-left));
}
main > section { display: flex; flex-direction: column; gap: 12px; }

/* ============ topbar ============ */
.topbar { display: flex; align-items: center; gap: 8px; height: 56px; }
.topbar h1 { flex: 1; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.sync { font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.25; cursor: default; }

/* ============ cards ============ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 600; }
.card-head .muted { font-size: 13px; }

/* hero */
.hero { padding: 20px; }
.hero-label { font-size: 14px; color: var(--text-2); }
.hero-value { font-size: 44px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin: 4px 0 14px; }
.hero-value.over { color: var(--danger); }
.hero-sub { font-size: 13px; color: var(--text-muted); margin-top: 10px; }

.meter { height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--meter-color) 20%, transparent); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--meter-color); border-radius: inherit; transition: width .3s; }

/* quick entry */
.quick {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 52px; padding: 0 16px; border: 0; border-radius: var(--radius);
  background: var(--surface); color: var(--accent-text); text-align: left;
}
.quick span { color: var(--text-2); font-size: 16px; }
.quick em { font-style: normal; color: var(--text-muted); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border-radius: var(--radius-sm); padding: 12px; min-width: 0; }
.kpi-label { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); }
.kpi strong { display: block; font-size: 18px; font-weight: 650; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-icon { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 6px; font-style: normal; }
.kpi-icon.in { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.kpi-icon.out { background: var(--surface-2); color: var(--text-2); }

/* rows (dompet, kategori) */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 0; border: 0; background: none; text-align: left;
}
button.row:active { opacity: 0.6; }
.row-icon { font-size: 18px; width: 28px; text-align: center; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.row-line { display: flex; justify-content: space-between; gap: 8px; }
.row-sub { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.row-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-detail { font-size: 13px; color: var(--text-2); }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.budget-row { align-items: flex-start; }
.budget-row .swatch { margin-top: 6px; }
.hbar { display: block; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.hbar span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

/* transaksi */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-list.card { padding: 4px 16px; }
.tx-list li + li .tx { border-top: 1px solid var(--line); }
.tx { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 0; border: 0; background: none; text-align: left; }
.tx:active { opacity: 0.6; }
.tx.pending { opacity: 0.55; }
.tx-icon {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 11px;
  background: color-mix(in srgb, var(--c) 18%, var(--surface)); font-size: 17px;
}
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.in { color: var(--pos); }
.tx-amt.transfer { color: var(--text-2); font-weight: 500; }
.day { display: flex; flex-direction: column; gap: 6px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); padding: 0 4px; font-variant-numeric: tabular-nums; }
#r-list { display: flex; flex-direction: column; gap: 16px; }
.empty { text-align: center; color: var(--text-muted); font-size: 14px; padding: 16px 0; }
.list-summary { font-size: 13px; color: var(--text-muted); padding: 0 4px; }

/* riwayat: cari & filter */
.search {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px;
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text-muted);
}
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 16px; color: var(--text); }
.filters { display: flex; flex-direction: column; gap: 8px; }
.filter-selects { display: flex; gap: 8px; }
.select-chip { position: relative; flex: 1; min-width: 0; }
.select-chip select {
  width: 100%; height: 36px; padding: 0 36px 0 14px; appearance: none; -webkit-appearance: none;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 14px center; background-size: 11px;
  border: 1px solid var(--line); border-radius: 999px; background-color: var(--surface); font-size: 14px; color: var(--text-2);
}
.select-chip.active select { border-color: var(--accent); background-color: var(--accent-soft); color: var(--text); font-weight: 500; }

/* segmented */
.segmented { display: flex; padding: 3px; border-radius: 12px; background: var(--surface-2); gap: 2px; }
.segmented button {
  flex: 1; height: 34px; border: 0; border-radius: 9px; background: none; font-size: 14px; font-weight: 500; color: var(--text-muted);
}
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] {
  background: var(--surface-3); color: var(--text);
}
.segmented.small button { height: 30px; font-size: 13px; }

/* navigasi periode */
.period-nav { display: flex; align-items: center; justify-content: space-between; }
.period-nav strong { font-size: 15px; font-weight: 600; }

/* anggaran */
.budget-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.budget-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.budget-value span { font-size: 15px; font-weight: 500; color: var(--text-muted); letter-spacing: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin: 14px 0 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: 12px; color: var(--text-muted); }
.facts dd { margin: 2px 0 0; font-size: 15px; font-weight: 600; }
.help { font-size: 13px; color: var(--text-muted); margin-top: 10px; }

/* ============ grafik ============ */
.chart { width: 100%; min-height: 150px; }
.bar-wrap { width: 100%; height: 12px; margin-bottom: 6px; }
.viz { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-baseline { stroke: var(--baseline); stroke-width: 1; }
.viz-tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-ref { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.7; }
.viz-ref-label { fill: var(--text-2); font-size: 11px; }
.viz-track { fill: var(--surface-2); }
.viz-break { stroke: var(--surface); stroke-width: 2; fill: none; }
.viz-over { fill: var(--text-2); font-weight: 600; }
.viz-hit { fill: transparent; outline: none; }
.viz-hit:hover, .viz-hit:focus-visible { fill: rgba(255, 255, 255, 0.05); }
.viz-mark { transition: opacity .15s; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin: -4px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.viz-tip {
  position: fixed; z-index: 30; pointer-events: none; min-width: 110px;
  padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text);
  box-shadow: 0 4px 24px rgb(0 0 0 / 0.6); border: 1px solid var(--line); font-size: 13px;
}
.viz-tip-title { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 6px; }
.viz-tip-row strong { font-weight: 650; }
.viz-tip-row span:not(.viz-tip-key) { color: var(--text-2); }
.viz-tip-key { width: 10px; height: 3px; border-radius: 2px; }
.table-toggle summary { font-size: 13px; color: var(--accent-text); margin-top: 8px; cursor: pointer; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table th { text-align: right; font-weight: 500; color: var(--text-muted); padding: 6px 4px; border-bottom: 1px solid var(--line); }
.data-table td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }

/* ============ tab bar ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: flex-start; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  /* latar selebar layar, isi tetap di kolom 600px yang sama dengan konten */
  padding: 6px max(8px, env(safe-area-inset-right), calc((100% - 600px) / 2)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left), calc((100% - 600px) / 2));
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 96px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding-top: 4px; font-size: 11px; color: var(--text-muted); text-decoration: none;
}
.tabbar a[aria-current] { color: var(--accent-text); font-weight: 600; }
.tab-icon { display: grid; place-items: center; }
.tab-add {
  flex: none; display: grid; place-items: center; width: 52px; height: 52px; margin-top: -2px;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
}
.tab-add:active { transform: scale(0.96); }

/* ============ sheets ============ */
.sheet {
  /* selalu menempel di bawah (juga di layar lebar), lebar mengikuti kolom konten */
  position: fixed; inset: auto 0 0 0;
  width: min(600px, 100%); max-width: 100%; margin: 0 auto; border: 0; padding: 0;
  border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
  border-top: 1px solid var(--line);
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-up .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.72); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
@media (prefers-reduced-motion: reduce) { .sheet[open] { animation: none; } }
.sheet form { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px); }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto 2px; }
.sheet h2 { font-size: 18px; font-weight: 650; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 6px; }
.sheet label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); }
.sheet input, .sheet select {
  height: 46px; padding: 0 12px; font-size: 16px; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background-color: var(--surface-2); min-width: 0;
}
.sheet select {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: var(--chevron); background-repeat: no-repeat; background-position: right 14px center; background-size: 12px;
}
.sheet input:focus, .sheet select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sheet input[type="date"] { width: 100%; -webkit-appearance: none; appearance: none; display: flex; align-items: center; }
.sheet input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.sheet input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: 0.6; }
.big-input { height: 54px !important; font-size: 18px !important; }
.field-label { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 34px; }
.preview-amount { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.preview-amount.in { color: var(--pos); }
.preview-hint { font-size: 13px; color: var(--text-muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); font-size: 14px; white-space: nowrap; color: var(--text);
}
.chip[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.chip.quiet { background: var(--surface-2); border-color: transparent; color: var(--text-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-2 > * { min-width: 0; }
.sheet-actions, .row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* aksi utama selebar panel di baris pertama; tombol pendamping berbagi rata di bawahnya */
.sheet-actions .primary { order: -1; flex: 1 0 100%; height: 52px; }
.sheet-actions .btn { flex: 1 1 0; }
.sheet-actions .spacer { display: none; }
.spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 44px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); text-decoration: none; font-size: 15px;
}
.btn.small { height: 34px; font-size: 14px; padding: 0 12px; }
.btn.danger { color: var(--danger); }
.primary {
  height: 46px; padding: 0 18px; border: 0; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16px;
}
.primary.block { width: 100%; height: 52px; }
.primary:disabled { opacity: 0.35; }
.settings-group { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.wallet-edit { display: grid; grid-template-columns: 46px 1fr 110px 36px; gap: 6px; align-items: center; }
.wallet-edit input { height: 42px !important; }
.emoji-input { text-align: center; padding: 0 !important; }
.error { color: var(--danger); font-size: 14px; }

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

@media (max-width: 360px) {
  .hero-value { font-size: 38px; }
  .kpi strong { font-size: 16px; }
  .wallet-edit { grid-template-columns: 40px 1fr 92px 32px; }
}

/* ============ halaman masuk ============ */
.login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
  background: radial-gradient(600px 420px at 50% 0%, rgba(91, 95, 240, 0.22), transparent 70%), var(--bg);
}
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 4px; }
.login h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.login-tagline { font-size: 18px; color: var(--text-2); text-wrap: balance; }
.login-points { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.login-points li { background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; color: var(--text-2); }
.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; height: 52px; margin-top: 6px;
  border-radius: var(--radius-sm); background: #fff; color: #1f1f1f; font-weight: 600; font-size: 16px; text-decoration: none;
}
.google-btn:active { opacity: 0.85; }
.login-note { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }

/* ============ akun & token ============ */
.account { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.avatar {
  position: relative; display: grid; place-items: center; flex: none; width: 48px; height: 48px; padding: 0; border: 0;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 18px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.busy { opacity: 0.5; }
.account-actions { display: flex; gap: 12px; margin-top: 4px; }
.linkish { padding: 0; border: 0; background: none; color: var(--accent-text); font-size: 13px; font-weight: 500; }
.account-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account-main strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-main span { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; color: var(--text-2); display: flex; flex-direction: column; gap: 4px; }
.token-new { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 12px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.token-new code { font-size: 13px; word-break: break-all; color: var(--text); }
.token-new .help { grid-column: 1 / -1; margin: 0; }
.token-list .row { padding: 10px 0; }
.token-list .row-main { font-size: 14px; }
