:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #171d26;
  --surface-2: #1e2631;
  --text: #e6eaf0;
  --muted: #9aa6b5;
  --accent: #6cb6ff;
  --accent-ink: #0b1520;
  --border: #2a3441;
  --ok: #56d364;
  --warn: #e3b341;
  --bad: #ff8a80;
  --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 8px 24px rgb(0 0 0 / .25);
  --radius: 14px;
  --topbar: calc(56px + env(safe-area-inset-top));
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
}
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.pad { padding: 24px 4px; }

/* tombol */
.btn {
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

/* bar atas */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); text-decoration: none; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.lang { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-right: 4px; }
.lang button { min-width: 38px; height: 32px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.belldot {
  position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #20090a; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.avatar { background: var(--surface-2); font-weight: 650; overflow: hidden; width: 36px; height: 36px; margin-left: 4px; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.popover {
  position: absolute; top: calc(var(--topbar) - 4px); right: 8px; width: min(380px, calc(100vw - 16px)); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px;
}
.popover.narrow { width: min(260px, calc(100vw - 16px)); padding: 12px; }
.pop-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; }
.pop-me { margin-bottom: 10px; word-break: break-all; font-size: 13px; }
.notice { padding: 10px 12px; border-radius: 10px; border-left: 3px solid var(--accent); background: var(--surface-2); margin: 6px 0; }
.notice.bill { border-color: var(--warn); }
.notice.week_up { border-color: var(--bad); }
.notice.today { border-color: var(--ok); }
.notice.read { opacity: .6; border-color: var(--border); }

/* tata letak */
.shell { max-width: 1080px; margin: 0 auto; padding: 14px 12px 120px; }
.menu-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin-bottom: 10px; }
.menu-title h1 { font-size: 20px; }
.tabs {
  position: sticky; top: var(--topbar); z-index: 20; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -12px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.filters { display: grid; gap: 10px; padding: 12px 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 14px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-weight: 600; }
.custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.custom label, .sel { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
input[type="date"], select, .search, textarea {
  min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.selects { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.sel { flex: 1 1 140px; max-width: 260px; }
.sel select { width: 100%; }

.view { min-height: 120px; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.kpis.three .kpi:first-child { grid-column: 1 / -1; }
.grid { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 15px; font-weight: 650; }
.hint { font-size: 12.5px; margin-top: 2px; }
.card > :not(h3):not(.hint):first-of-type, .card h3 + * { margin-top: 10px; }
.kpi { padding: 12px 14px; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: clamp(16px, 4.8vw, 22px); font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; } /* jutaan tetap satu baris di HP */
.kpi-foot { font-size: 12.5px; margin-top: 2px; min-height: 18px; }
.delta { font-weight: 650; }
.delta.up { color: var(--warn); }    /* pengeluaran naik = perlu diperhatikan */
.delta.down { color: var(--ok); }
.delta.good.up { color: var(--ok); }     /* pemasukan naik = bagus */
.delta.good.down { color: var(--warn); }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.empty { padding: 18px 4px; text-align: center; }

/* batang horizontal */
.hbars { display: grid; gap: 4px; }
.hbar {
  width: 100%; display: grid; grid-template-columns: minmax(74px, 30%) 1fr auto; align-items: center; gap: 4px 10px; text-align: left;
  min-height: 40px; padding: 4px 8px; border-radius: 10px; border: 1px solid transparent; background: transparent; font-size: 14px;
}
button.hbar:hover { background: var(--surface-2); }
.hbar.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); }
.hbar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--accent); min-width: 2px; }
.hbar-prev { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: .7; border-radius: 1px; }
.hbar-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.hbar-sub { grid-column: 2 / 4; font-size: 12px; color: var(--muted); margin-top: -2px; }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-left: 6px; }
.legend .sw.prev { background: #5b6778; margin-left: 0; }
.legend .tick { width: 2px; height: 12px; background: var(--text); opacity: .7; }

/* grafik kolom */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-readout { min-height: 20px; font-size: 13px; }
.col { fill: var(--accent); }
.col.prev { fill: #5b6778; }
.hit { fill: transparent; }
.hit:hover, .hit:focus-visible { fill: rgb(255 255 255 / .07); outline: none; }
line.gl { stroke: var(--border); stroke-width: 1; }
.axis { fill: var(--muted); font-size: 10px; }
.chart-note { font-size: 13.5px; margin-top: 6px; }

/* daftar */
.rows { display: grid; }
.rows.scroll { max-height: 420px; overflow-y: auto; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row > div:first-child { min-width: 0; }
.row-main { font-weight: 550; overflow-wrap: anywhere; }
.row-sub { font-size: 12.5px; }
.row-amt { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row-end { display: grid; justify-items: end; gap: 4px; }
.row.done { opacity: .6; }
.prog { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.prog-track { position: relative; flex: 0 0 72px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.prog-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 3px; }
.prog-txt { font-size: 12px; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.search { width: 100%; margin-bottom: 6px; }

/* chat AI */
.chat { margin-top: 16px; }
.chat-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.msgs { display: grid; gap: 10px; max-height: 460px; overflow-y: auto; margin-top: 10px; }
.msgs:empty { display: none; }
.msg { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); max-width: 94%; }
.msg.user { justify-self: end; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.msg.err { border: 1px solid color-mix(in srgb, var(--bad) 50%, transparent); }
.msg .who { font-size: 11.5px; margin-bottom: 2px; }
.msg p + p, .msg ul + p, .msg p + ul { margin-top: 6px; }
.msg ul { list-style: disc; padding-left: 18px; }
.sug { flex-wrap: wrap; margin-top: 10px; overflow: visible; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.chat-form textarea { flex: 1; padding: 9px 10px; resize: none; line-height: 1.35; max-height: 140px; }

/* banner pasang aplikasi */
.install { position: fixed; z-index: 40; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: center; pointer-events: none; }
.install-card {
  position: relative; pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; width: min(460px, 100%); padding: 14px 44px 14px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.install-card img { border-radius: 10px; flex: none; }
.install-card p { font-size: 13.5px; margin-top: 2px; }
.install-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.install-x { position: absolute; top: 2px; right: 2px; font-size: 22px; }

/* halaman login */
body.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; justify-items: center; gap: 12px; text-align: center; padding: 28px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; }
.gbtn { min-height: 44px; display: grid; place-items: center; margin: 6px 0; }
.login-msg { color: var(--bad); font-size: 14px; }

@media (min-width: 760px) {
  .shell { padding-top: 20px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpis.two { grid-template-columns: repeat(2, 1fr); }
  .kpis.three { grid-template-columns: repeat(3, 1fr); }
  .kpis.three .kpi:first-child { grid-column: auto; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .card.wide { grid-column: 1 / -1; }
  .card { padding: 16px; }
  .install { justify-content: flex-end; left: auto; right: 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .hbar-fill, .col { transition: width .25s ease, height .25s ease; }
}
