:root {
  --bg: #F6F3EE; --surface: #FFFFFF; --surface-2: #F1ECE4; --ink: #2A2420; --muted: #7B7068; --line: #E8E1D7;
  --brand: #7A4A1E; --brand-ink: #FFFFFF; --logo-ink: #F6F3EE; --accent: #C9A227;
  --ok: #2E9E5B; --warn: #D99A00; --over: #D64545; --info: #4F8A8B; --love: #C0647A;
  --ok-soft: #E3F4EA; --warn-soft: #FBF1D6; --over-soft: #FBE4E4; --info-soft: #E2EFEF;
  --radius: 22px; --shadow: 0 1px 2px rgba(42, 36, 32, .04), 0 6px 20px rgba(42, 36, 32, .05);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412; --surface: #221E1B; --surface-2: #2C2723; --ink: #F2ECE6; --muted: #A89C92; --line: #37302B;
    --brand: #B9824F; --brand-ink: #1B1410; --logo-ink: #1B1410; --accent: #D9B54A;
    --ok-soft: #1E3326; --warn-soft: #3A2F12; --over-soft: #3D1F1F; --info-soft: #1D3132;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh; overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
#app { max-width: 560px; margin: 0 auto; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-size: 26px; line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 18px; letter-spacing: -.01em; }
small { display: block; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.fine { color: var(--muted); font-size: 12px; text-align: center; margin: 16px 0; }
.grow { flex: 1; min-width: 0; }
.grow b { display: block; overflow: hidden; text-overflow: ellipsis; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.neg { color: var(--over); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 36px; height: 36px; stroke: none; flex: none; }
.brand strong { display: block; font-size: 17px; }
.brand small { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; }
.icon-btn:active { background: var(--surface-2); }
.chip-btn { padding: 7px 14px; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-size: 14px; font-weight: 600; }

.page { padding: 4px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px); display: grid; gap: 14px; }

/* ---------- Hero ---------- */
.hero {
  border-radius: var(--radius); padding: 20px; color: #fff;
  background: radial-gradient(120% 120% at 100% 0%, #B9824F 0%, #7A4A1E 55%, #4E2F12 100%);
  box-shadow: 0 10px 30px rgba(122, 74, 30, .25);
}
.hero-date { opacity: .8; font-size: 14px; margin-bottom: 4px; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.hero-stats div { background: rgba(255, 255, 255, .14); border-radius: 16px; padding: 10px 12px; }
.hero-stats small { color: rgba(255, 255, 255, .8); }
.hero-stats strong { font-size: 20px; }

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.link { color: var(--brand); font-weight: 600; font-size: 14px; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); }
.list { list-style: none; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li.done b { text-decoration: line-through; color: var(--muted); }
.bubble { width: 42px; height: 42px; flex: none; border-radius: 14px; display: grid; place-items: center; font-size: 20px; background: var(--surface-2); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.date-badge { width: 46px; flex: none; text-align: center; background: var(--surface-2); border-radius: 12px; padding: 4px 0; }
.date-badge b { display: block; font-size: 18px; line-height: 1.1; }
.date-badge small { font-size: 11px; }
.text-btn { text-align: left; padding: 0; max-width: 100%; }
.row-btn { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; }
.tag { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.over { background: var(--over-soft); color: var(--over); }
.empty { text-align: center; padding: 18px 8px; color: var(--muted); }
.empty div { font-size: 34px; margin-bottom: 6px; }
.empty p { font-size: 14px; }
.empty .btn { margin-top: 12px; }

/* ---------- Today ---------- */
.today-list { list-style: none; display: grid; gap: 8px; }
.today-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 16px; background: var(--surface-2); position: relative; }
.today-item .bubble { background: var(--surface); }
.today-item.p-urgent { background: var(--over-soft); }
.today-item.p-warn { background: var(--warn-soft); }
.today-item.p-ok { background: var(--ok-soft); }
.today-item.done { opacity: .6; }
.today-item.done b { text-decoration: line-through; }
.mini-btn { padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.mini-btn.accent { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.dismiss { width: 28px; height: 28px; border-radius: 50%; color: var(--muted); font-size: 13px; flex: none; }
.dismiss:active { background: var(--line); }

.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick-grid > * { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 12px 4px; text-align: center; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); }
.quick-grid span { display: block; font-size: 24px; margin-bottom: 2px; }

.install-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--brand); }
.install-icon svg { width: 44px; height: 44px; stroke: none; }
.install-actions { display: flex; align-items: center; gap: 4px; }

/* ---------- Money ---------- */
.segmented { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.segmented > * { flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented > .active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented.small { margin-bottom: 14px; }
.month-switch { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.month-switch .icon-btn { font-size: 26px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
.stat b { font-size: 14px; display: block; overflow-wrap: anywhere; }
.stat.in b { color: var(--ok); }
.stat.out b { color: var(--over); }
.group-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 6px 4px -6px; }
.tx-list { padding-top: 4px; padding-bottom: 4px; }
.amt { white-space: nowrap; font-size: 15px; }
.amt.income { color: var(--ok); }
.amt.expense { color: var(--ink); }
.amt.transfer { color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.bar.warn i { background: var(--warn); }
.bar.over i { background: var(--over); }
.budget-total { margin-bottom: 8px; font-size: 14px; }
.total-balance { background: var(--surface-2); border-radius: 16px; padding: 12px 14px; margin-bottom: 4px; }
.total-balance b { font-size: 22px; }

/* ---------- Calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid.head span { font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 0; }
.day { aspect-ratio: 1 / 1; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; }
.day.today span { color: var(--brand); }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day.sel { background: var(--brand); color: var(--brand-ink); }
.day.sel span { color: var(--brand-ink); }
.dots { display: flex; gap: 3px; height: 6px; margin-top: 2px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--info); }
.dot.bill { background: var(--accent); }
.check { width: 26px; height: 26px; flex: none; border-radius: 8px; border: 2px solid var(--line); }
.check.on { background: var(--ok); border-color: var(--ok); position: relative; }
.check.on::after { content: "✓"; color: #fff; font-size: 16px; font-weight: 700; position: absolute; inset: 0; display: grid; place-items: center; }

/* ---------- Together ---------- */
.convo { border-radius: var(--radius); padding: 24px 20px; background: linear-gradient(160deg, #C0647A, #8E3D55); color: #fff; box-shadow: 0 10px 30px rgba(192, 100, 122, .3); }
.convo-cat { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; background: rgba(255, 255, 255, .18); padding: 4px 10px; border-radius: 99px; }
.convo-q { font-size: 21px; line-height: 1.35; font-weight: 600; margin: 14px 0 10px; }
.convo small { color: rgba(255, 255, 255, .75); }
.qt-meter { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--ok-soft); margin-bottom: 6px; }
.qt-meter.warn { background: var(--warn-soft); }
.qt-meter b { font-size: 34px; line-height: 1; }
.qt-meter span { font-size: 14px; color: var(--muted); }

/* ---------- Forms ---------- */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.form label[hidden] { display: none; }
.form label small { display: inline; font-weight: 400; }
.form label.inline { grid-template-columns: 1fr 1.2fr; align-items: center; font-weight: 500; }
input, select, textarea {
  font: inherit; font-size: 16px; /* cegah zoom otomatis di iOS */
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=color] { padding: 4px; height: 46px; }
input[type=date], input[type=time] { min-height: 48px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.money-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding-left: 14px; }
.money-input span { color: var(--muted); font-weight: 600; }
.money-input input { border: 0; padding-left: 8px; font-weight: 600; }
.money-input:focus-within { outline: 2px solid var(--brand); }
.money-input input:focus { outline: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex !important; align-items: center; gap: 10px; }
.check-row input { width: 22px; height: 22px; -webkit-appearance: checkbox; appearance: auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 13px 18px; border-radius: 16px; font-weight: 700; font-size: 15px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: var(--surface-2); }
.btn.danger { color: var(--over); background: var(--over-soft); }
.btn:active, .mini-btn:active, .quick-grid > *:active { transform: scale(.97); }
.file-btn { cursor: pointer; }
.kind-toggle, .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.kind-toggle label, .chips label { flex: 1; display: block; }
.kind-toggle input, .chips input { position: absolute; opacity: 0; pointer-events: none; }
.kind-toggle span, .chips span { display: block; text-align: center; padding: 10px 8px; border-radius: 12px; background: var(--surface-2); font-size: 14px; font-weight: 600; white-space: nowrap; }
.kind-toggle input:checked + span, .chips input:checked + span { background: var(--brand); color: var(--brand-ink); }
.chips label { flex: 0 0 auto; }
.smart { display: flex; gap: 8px; margin-bottom: 14px; }
.smart input { flex: 1; }
.smart .btn { padding: 0 16px; }

/* ---------- Sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 15, 10, .45); opacity: 0; transition: opacity .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 18px calc(24px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1); overscroll-behavior: contain;
}
#sheet.open .sheet-backdrop { opacity: 1; }
#sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 6px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.steps { list-style: none; display: grid; gap: 12px; margin-bottom: 8px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border-radius: 16px; padding: 12px; }
.steps li > span { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
.inline-ico { width: 18px; height: 18px; vertical-align: -3px; color: #2F7BF6; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0 auto; max-width: 560px;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; }
.tabbar a.active { color: var(--brand); }
.tabbar a.active svg { stroke-width: 2.4; }
.fab { justify-self: center; width: 54px; height: 54px; border-radius: 18px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; margin-top: -22px; box-shadow: 0 8px 20px rgba(122, 74, 30, .35); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.6; }

/* ---------- Onboarding ---------- */
.onboard { padding: calc(32px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); display: grid; gap: 14px; text-align: center; }
.onboard-logo svg { width: 76px; height: 76px; stroke: none; }
.onboard .lead { color: var(--muted); }
.onboard .form { text-align: left; }
.ios-note { text-align: left; background: var(--warn-soft); border-radius: 18px; padding: 14px; font-size: 14px; display: grid; gap: 10px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  body { background: var(--surface-2); }
  #app { background: var(--bg); min-height: 100dvh; box-shadow: 0 0 0 1px var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Akun & sinkronisasi ---------- */
.sync-ind { width: 32px; height: 40px; display: grid; place-items: center; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.sync-dot.synced { background: var(--ok); }
.sync-dot.syncing, .sync-dot.pending { background: var(--warn); animation: rk-pulse 1s ease-in-out infinite; }
.sync-dot.offline { background: var(--muted); }
.sync-dot.auth, .sync-dot.error { background: var(--over); }
@keyframes rk-pulse { 50% { opacity: .35; } }
.sync-line { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 12px 0; }
.acct-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
#account-card .btn.block, #account-card .row2 { margin-top: 10px; }
.notice { background: var(--info-soft); border-radius: 14px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); }
.notice.dev { background: var(--warn-soft); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.form-error { color: var(--over); background: var(--over-soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.otp-input { font-size: 24px !important; letter-spacing: .4em; text-align: center; font-weight: 700; }
.invite-list { display: grid; gap: 8px; margin: 12px 0; }
.invite-list .btn { justify-content: flex-start; }
.avatar.sm { width: 26px; height: 26px; font-size: 13px; }
.invite-code { font: 700 32px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .18em; text-align: center; background: var(--surface); border: 2px dashed var(--brand); border-radius: 18px; padding: 14px; margin-top: 8px; }
.invite-link { margin: 6px 0 10px; font-size: 14px !important; color: var(--muted); }
details.server-cfg, details.rejected { margin-top: 12px; font-size: 14px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
details .form { margin-top: 8px; }
details.rejected ul { margin: 6px 0 0 18px; color: var(--muted); }
