:root {
  --bg: #f4f6f8;
  --bg-soft: #edf0f4;
  --card: #ffffff;
  --card-2: #f7f9fb;
  --text: #1a1d23;
  --muted: #64748b;
  --line: rgba(0, 0, 0, 0.06);
  --line-strong: rgba(0, 0, 0, 0.1);
  --emerald: #16a34a;
  --emerald-2: #22c55e;
  --emerald-dark: #15803d;
  --emerald-soft: rgba(22, 163, 74, 0.08);
  --amber: #64748b;
  --amber-soft: rgba(100, 116, 139, 0.08);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.08);
  --blue: #64748b;
  --blue-soft: rgba(100, 116, 139, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 14px;
  --nav-h: 62px;
}


[data-theme="dark"] {
  --bg: #0f1419;
  --bg-soft: #1a2030;
  --card: #1e2736;
  --card-2: #172030;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: rgba(226, 232, 240, 0.08);
  --line-strong: rgba(226, 232, 240, 0.14);
  --emerald: #22c55e;
  --emerald-2: #4ade80;
  --emerald-dark: #16a34a;
  --emerald-soft: rgba(34, 197, 94, 0.12);
  --amber: #94a3b8;
  --amber-soft: rgba(148, 163, 184, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --blue: #94a3b8;
  --blue-soft: rgba(148, 163, 184, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}


* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }
.sidebar { display: none; }
.main-content { width: min(1100px, 100%); margin: 0 auto; padding: 16px 14px calc(var(--nav-h) + 22px); }


.topbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin: 6px 0 18px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.25rem, 3.5vw, 1.7rem); font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.month-select, input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-sm); padding: 10px 12px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.month-select { min-width: 130px; font-weight: 600; color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--emerald); box-shadow: 0 0 0 3px var(--emerald-soft); }
textarea { min-height: 96px; resize: vertical; }


/* Buttons */
.icon-btn, .btn {
  border: 1px solid transparent; border-radius: var(--radius-sm); min-height: 38px; padding: 8px 14px;
  font-weight: 600; font-size: .88rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.icon-btn { width: 38px; background: var(--card); border-color: var(--line); box-shadow: var(--shadow-sm); }
.icon-btn:hover { background: var(--bg-soft); }
.btn.primary { color: #fff; background: var(--emerald); box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--emerald-dark); }
.btn.secondary { background: var(--card); color: var(--text); border-color: var(--line); }
.btn.secondary:hover { background: var(--bg-soft); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg-soft); }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.small { min-height: 30px; padding: 5px 10px; border-radius: 6px; font-size: .8rem; }
.btn:active, .icon-btn:active { transform: scale(.98); }


/* Pills */
.pill, .status-pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px;
  background: var(--emerald-soft); color: var(--emerald-dark); border: 1px solid transparent;
  font-size: .72rem; font-weight: 600;
}
[data-theme="dark"] .pill { color: var(--emerald-2); }

.view-container { margin-top: 16px; }
.grid { display: grid; gap: 14px; }
.grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: .98rem; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: .88rem; line-height: 1.55; }


/* Metrics: Santai Scale style — colored dot icon + big bold number */
.metric { display: flex; flex-direction: column; gap: 6px; }
.metric .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.metric .value { font-size: clamp(1.3rem, 5vw, 1.8rem); font-weight: 700; letter-spacing: -.03em; color: var(--text); line-height: 1.1; word-break: break-word; }
.metric .hint { color: var(--muted); font-size: .78rem; }
.metric.good .value { color: var(--emerald); }
.metric.warn .value { color: var(--amber); }
.metric.bad .value { color: var(--red); }

/* Metric icon: small colored circle */
.metric-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 999px; flex-shrink: 0;
}
.metric-icon.good { background: var(--emerald-soft); }
.metric-icon.good::after { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--emerald); }
.metric-icon.bad { background: var(--red-soft); }
.metric-icon.bad::after { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--red); }
.metric-icon.neutral { background: var(--bg-soft); }
.metric-icon.neutral::after { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--muted); }


/* Progress bars */
.progress { overflow: hidden; height: 6px; border-radius: 999px; background: var(--bg-soft); }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--emerald); width: 0; transition: width .25s ease; }

.form-grid { display: grid; gap: 12px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-weight: 600; font-size: .8rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.tabs, .month-chips, .filter-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 6px; scroll-snap-type: x proximity; }
.tabs::-webkit-scrollbar, .month-chips::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: .8rem; scroll-snap-align: start;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
.chip:hover { background: var(--bg-soft); }
.chip.active { color: #fff; background: var(--emerald); border-color: var(--emerald); }
.chip:active, .nav-link:active { transform: scale(.98); }


/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 800px; background: var(--card); }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--card-2); position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }

/* Status pills */
.status-pill { padding: 4px 9px; border: 0; font-size: .72rem; }
.status-lunas { color: var(--emerald-dark); background: var(--emerald-soft); }
.status-belum-lunas { color: var(--amber); background: var(--amber-soft); }
.status-refund { color: var(--red); background: var(--red-soft); }
[data-theme="dark"] .status-lunas { color: var(--emerald-2); }

.actions { display: flex; flex-wrap: wrap; gap: 6px; }


/* Transaction cards */
.tx-card-list { display: grid; gap: 12px; }
.tx-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.tx-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.tx-title { font-weight: 700; letter-spacing: -.01em; }
.tx-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; padding: 10px; border-radius: var(--radius-sm); background: var(--card-2); }
.tx-meta span { display: block; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tx-meta strong { display: block; margin-top: 3px; font-weight: 700; }

/* Empty state */
.empty { text-align: center; padding: 32px 18px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: var(--card-2); }
.empty .emoji { font-size: 2rem; display: block; margin-bottom: 8px; opacity: .8; }
.empty strong { display: block; color: var(--text); font-size: 1rem; margin-bottom: 4px; }


/* Bottom nav — clean and compact */
.bottom-nav {
  position: fixed; z-index: 20; left: 8px; right: 8px; bottom: 8px; height: var(--nav-h);
  display: grid; grid-template-columns: repeat(7, minmax(38px, 1fr)); gap: 2px; padding: 6px;
  background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.nav-link {
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 600; font-size: .62rem; min-width: 38px; transition: background .15s ease, color .15s ease;
}
.nav-link .ico { font-size: 1rem; }
.nav-link:hover { color: var(--text); }
.nav-link.active { background: var(--emerald-soft); color: var(--emerald-dark); }
[data-theme="dark"] .nav-link.active { color: var(--emerald-2); }

/* "Lainnya" grouped sheet */
.nav-more-sheet {
  position: absolute; right: 4px; bottom: calc(100% + 8px); z-index: 25;
  display: grid; gap: 2px; padding: 6px; min-width: 160px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.nav-more-sheet[hidden] { display: none; }
.nav-more-sheet .nav-link { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px; font-size: .84rem; }
.nav-more-sheet .nav-link .ico { font-size: 1rem; }


/* Toast */
.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--nav-h) + 22px);
  transform: translateX(-50%) translateY(18px); opacity: 0; pointer-events: none;
  background: #1a1d23; color: #fff; padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); transition: .22s ease; max-width: min(92vw, 420px); font-weight: 600;
  display: flex; align-items: center; gap: 8px; font-size: .88rem;
}
.toast::before { content: "✓"; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; background: var(--emerald); color: #fff; font-size: .74rem; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hide-mobile { display: none; }
.kv { display: grid; gap: 2px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv-row:last-child { border-bottom: 0; }
.kv-row span { color: var(--muted); font-size: .88rem; }
.kv-row strong { font-weight: 700; }
.setting-row { display: grid; gap: 10px; align-items: center; }


/* FAB */
.fab-add {
  position: fixed; z-index: 30; right: 14px; bottom: calc(var(--nav-h) + 16px); border: 0;
  min-height: 42px; padding: 0 16px; border-radius: 999px; color: #fff; background: var(--emerald);
  box-shadow: var(--shadow-md); font-weight: 700; font-size: .88rem; transition: background .15s ease, transform .1s ease;
}
.fab-add:hover { background: var(--emerald-dark); }
.fab-add:active { transform: scale(.97); }

/* Dashboard primary metrics */
.primary-metrics { gap: 14px; }
.primary-metrics .metric { min-height: 100px; justify-content: space-between; padding: 20px; }
.primary-metrics .metric .value { font-size: clamp(1.5rem, 5.5vw, 2rem); }

/* Secondary stats */
.stat-group { padding: 6px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 14px; background: var(--card); }
.stat-label { color: var(--muted); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.02rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); line-height: 1.15; word-break: break-word; }
.stat-hint { color: var(--muted); font-size: .74rem; }
.stat.neg .stat-value { color: var(--red); }


/* Target card */
.target-card .card-header { align-items: center; }
.target-pct { color: var(--emerald); font-size: 1.4rem; font-weight: 700; }
.inline-target { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.insight-card .kv-row strong { text-align: right; }

.subform-title { color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; padding-top: 4px; }
.profit-preview input { font-weight: 700; color: var(--emerald); background: var(--emerald-soft); border-color: transparent; }

/* Category badges */
.category-badge {
  display: inline-flex; width: fit-content; margin-top: 2px; padding: 3px 8px; border-radius: 6px;
  background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); font-size: .72rem; font-weight: 600;
}
.category-badge.expense { background: var(--bg-soft); color: var(--muted); }
.category-badge.recurring { background: var(--emerald-soft); color: var(--emerald-dark); border-color: transparent; }
[data-theme="dark"] .category-badge.recurring { color: var(--emerald-2); }

.big-action { min-width: min(100%, 220px); }

.expense-card .expense-amount { color: var(--red); font-size: 1rem; font-weight: 700; white-space: nowrap; }
.expense-card .tx-top { align-items: flex-start; }


/* Cashflow */
.cf-in { color: var(--emerald); font-weight: 700; }
.cf-out { color: var(--text); font-weight: 700; }

/* Cashflow line chart */
.cf-chart { width: 100%; }
.cf-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.cf-chart .cf-grid { stroke: var(--line); stroke-width: 1; }
.cf-chart .cf-axis-label { fill: var(--muted); font-size: 10px; font-weight: 600; }
.cf-chart .cf-line-net { fill: none; stroke: var(--emerald); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.cf-chart .cf-line-in { fill: none; stroke: var(--muted); opacity: .5; stroke-width: 1.5; stroke-dasharray: 4 3; }
.cf-chart .cf-line-out { fill: none; stroke: var(--muted); opacity: .85; stroke-width: 1.5; stroke-dasharray: 2 3; }
.cf-chart .cf-area { fill: var(--emerald-soft); }
.cf-chart .cf-dot { fill: var(--emerald); }
.cf-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: .76rem; color: var(--muted); font-weight: 600; }
.cf-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cf-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.cf-legend i.net { background: var(--emerald); }
.cf-legend i.in { background: var(--muted); opacity: .5; }
.cf-legend i.out { background: var(--muted); opacity: .85; }


/* Status dots */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; margin-right: 6px; vertical-align: middle; }
.dot.good { background: var(--emerald); }
.dot.warn { background: var(--amber); }
.dot.bad { background: var(--red); }
.dot.none { background: var(--muted); }

/* Net profit highlight in recap */
.net-row strong.good-text { color: var(--emerald); }
.net-row strong.bad-text { color: var(--red); }
.good-text { color: var(--emerald); }
.bad-text { color: var(--red); }

/* Recurring checkbox row */
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); border: 1px solid var(--line); background: var(--card); border-radius: var(--radius-sm); padding: 10px 12px; }
.check-row input { width: auto; }

/* Budget progress bars */
.budget-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: 0; }
.budget-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-weight: 600; }
.budget-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: .8rem; }
.budget-status { font-weight: 700; }
.budget-over { color: var(--red); }
.budget-warn { color: var(--amber); }
.budget-ok { color: var(--emerald); }
.budget-none { color: var(--muted); }
.progress.ok > span { background: var(--emerald); }
.progress.warn > span { background: var(--amber); }
.progress.over > span { background: var(--red); }
.progress.none > span { background: var(--muted); }


/* Dashboard greeting/subtitle */
.dash-greeting { margin-bottom: 18px; }
.dash-greeting h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 4px; }
.dash-greeting p { color: var(--muted); font-size: .86rem; margin: 0; }

@media (min-width: 520px) and (max-width: 759px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 760px) {
  .main-content { padding: 24px; }
  .grid.two { grid-template-columns: repeat(2, 1fr); }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
  .grid.four { grid-template-columns: repeat(4, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .field.full { grid-column: 1 / -1; }
  .hide-mobile { display: block; }
  .hide-desktop { display: none; }
  .setting-row { grid-template-columns: 1fr auto; }
  .fab-add { bottom: 22px; }
}


@media (min-width: 1040px) {
  .app-shell { display: grid; grid-template-columns: 260px 1fr; }
  .sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 12px; padding: 20px 16px; background: var(--card); border-right: 1px solid var(--line); }
  .brand { display: flex; gap: 12px; align-items: center; padding: 8px 6px 16px; border-bottom: 1px solid var(--line); }
  .brand-mark { width: 38px; height: 38px; border-radius: var(--radius-sm); color: #fff; background: var(--emerald); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
  .brand strong, .brand small { display: block; }
  .brand strong { font-weight: 700; letter-spacing: -.01em; font-size: .92rem; }
  .brand small { color: var(--muted); font-weight: 600; font-size: .78rem; }
  .side-nav { display: grid; gap: 2px; }
  .side-nav .nav-link { flex-direction: row; justify-content: flex-start; padding: 10px 12px; font-size: .88rem; gap: 10px; border-radius: var(--radius-sm); }
  .side-nav .nav-link .ico { font-size: 1rem; }
  .side-nav .nav-link.active { background: var(--emerald-soft); color: var(--emerald-dark); }
  [data-theme="dark"] .side-nav .nav-link.active { color: var(--emerald-2); }
  .side-panel { margin-top: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--card-2); color: var(--muted); line-height: 1.55; font-size: .82rem; }
  .side-panel-icon { font-size: 1.3rem; display: block; margin-bottom: 6px; }
  .bottom-nav { display: none; }
  .main-content { padding: 28px 32px 40px; }
  .fab-add { right: 28px; bottom: 28px; }
}

@media (max-width: 380px) {
  .main-content { padding-left: 10px; padding-right: 10px; }
  .topbar { align-items: flex-start; }
  .top-actions { flex-direction: column; align-items: stretch; }
  .month-select { min-width: 112px; }
  .tx-meta { grid-template-columns: 1fr; }
  .fab-add { right: 10px; font-size: .84rem; }
}
