:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --suami: #2563eb;
  --suami-soft: #eff6ff;
  --istri: #ec4899;
  --istri-soft: #fdf2f8;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f4f6fb;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; border: none; background: none; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }

.container { max-width: 1060px; margin: 0 auto; padding: 0 16px; }

header.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  max-width: 1060px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); }

.brand .logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 900;
}

.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }

.user-chip { display: flex; align-items: center; gap: 10px; }

.user-chip .avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: #fff;
}

.user-chip .avatar.suami { background: var(--suami); }
.user-chip .avatar.istri { background: var(--istri); }

.user-chip .uinfo { text-align: right; line-height: 1.2; }
.user-chip .uinfo .uname { font-weight: 700; font-size: 13px; }
.user-chip .uinfo .urole { font-size: 11px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  font-size: 14px; font-weight: 600;
  border-radius: 10px;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}

.btn:active { transform: scale(.97); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fde8e8; }

.btn-ghost { background: #f1f5f9; color: #334155; }
.btn-ghost:hover { background: #e2e8f0; }

.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.auth-card .auth-logo { display: flex; justify-content: center; margin-bottom: 12px; }

.auth-card h1 { font-size: 22px; text-align: center; }
.auth-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }

.auth-alt { text-align: center; font-size: 13px; margin-top: 16px; color: var(--muted); }

.error-box {
  display: none;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
}

.error-box.show { display: block; }

main { padding: 24px 16px 60px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

.page-head h1 { font-size: 24px; }
.page-head p { color: var(--muted); font-size: 13px; }

.month-picker input { width: auto; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }

.card-pad { padding: 20px; }

.grid-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }

.stat-card { padding: 18px 20px; position: relative; overflow: hidden; }

.stat-card .stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }

.stat-card .stat-value { font-size: 22px; font-weight: 800; }

.stat-card .stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.stat-card.accent-primary .stat-value { color: var(--primary); }
.stat-card.accent-suami .stat-value { color: var(--suami); }
.stat-card.accent-istri .stat-value { color: var(--istri); }
.stat-card.accent-green .stat-value { color: var(--green); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }

@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

.bar-row { margin-bottom: 12px; }
.bar-row:last-child { margin-bottom: 0; }

.bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.bar-top b { font-weight: 600; }
.bar-top span { color: var(--muted); }

.bar { height: 8px; border-radius: 99px; background: #eef2f7; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--primary); transition: width .4s ease; }
.bar-fill.cat-makanan { background: #f59e0b; }
.bar-fill.cat-transportasi { background: #3b82f6; }
.bar-fill.cat-belanja { background: #8b5cf6; }
.bar-fill.cat-tagihan { background: #ef4444; }
.bar-fill.cat-kesehatan { background: #10b981; }
.bar-fill.cat-pendidikan { background: #06b6d4; }
.bar-fill.cat-hiburan { background: #ec4899; }
.bar-fill.cat-tabungan { background: #14b8a6; }
.bar-fill.cat-lainnya { background: #94a3b8; }

.breakdown-people { display: flex; gap: 14px; }
.breakdown-people .bp-item { flex: 1; background: var(--bg); border-radius: 12px; padding: 12px 14px; }
.breakdown-people .bp-item b { display: block; font-size: 16px; }
.breakdown-people .bp-item span { font-size: 12px; color: var(--muted); }
.breakdown-people .bp-item.suami b { color: var(--suami); }
.breakdown-people .bp-item.istri b { color: var(--istri); }

.form-expense { display: grid; grid-template-columns: 2fr 1fr 1.2fr 1fr 1fr auto; gap: 10px; align-items: end; }

@media (max-width: 900px) {
  .form-expense { grid-template-columns: 1fr 1fr; }
  .form-expense .fe-full { grid-column: 1 / -1; }
}

.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }

.tab-btn { padding: 10px 14px; font-weight: 600; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }

.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }

td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }

tr:last-child td { border-bottom: none; }

tr:hover td { background: #fafbff; }

.amount { font-weight: 700; white-space: nowrap; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: #334155; white-space: nowrap; }

.badge.suami { background: var(--suami-soft); color: var(--suami); }
.badge.istri { background: var(--istri-soft); color: var(--istri); }

.badge-cat { background: var(--primary-soft); color: var(--primary); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.icon-btn { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; background: #f1f5f9; color: #475569; transition: background .15s; }

.icon-btn:hover { background: #e2e8f0; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 36px; display: block; margin-bottom: 8px; }

.log-list { max-height: 480px; overflow-y: auto; }

.log-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }

.log-item:last-child { border-bottom: none; }

.log-item .log-dot { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; background: #f1f5f9; }

.log-item .log-dot.tambah { background: var(--green-soft); }
.log-item .log-dot.ubah { background: var(--primary-soft); }
.log-item .log-dot.hapus { background: var(--danger-soft); }

.log-item .log-body { flex: 1; font-size: 14px; }
.log-item .log-body .lwho { font-weight: 600; }
.log-item .log-body .lwhat { color: #334155; }
.log-item .log-body .lwhen { font-size: 12px; color: var(--muted); margin-top: 2px; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}

.modal-backdrop.show { opacity: 1; visibility: visible; }

.modal {
  background: #fff; border-radius: 18px; padding: 24px;
  width: 100%; max-width: 440px;
  box-shadow: var(--shadow);
  transform: translateY(8px);
  transition: transform .2s;
}

.modal-backdrop.show .modal { transform: translateY(0); }

.modal h3 { margin-bottom: 16px; font-size: 18px; }

.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

#toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #1e293b; color: #fff;
  padding: 12px 18px; border-radius: 12px;
  font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility .25s, transform .25s;
  z-index: 200; max-width: 90vw; text-align: center;
}

#toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-4px); }
#toast.success { background: var(--green); }
#toast.error { background: var(--danger); }

.hidden { display: none !important; }

.mt-20 { margin-top: 20px; }
.muted { color: var(--muted); }
.text-sm { font-size: 13px; }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }