/* =========================================================
   KeuanganKu — Stylesheet utama
   Tema terang & gelap, sidebar responsif, komponen kartu.
   ========================================================= */

:root {
  --bg:        #f5f6fa;
  --surface:   #ffffff;
  --surface-2: #f1f3f9;
  --border:    #e2e6f0;
  --text:      #1a1f36;
  --text-soft: #6b7280;
  --primary:   #4f46e5;
  --primary-d: #4338ca;
  --green:     #16a34a;
  --red:       #dc2626;
  --amber:     #f59e0b;
  --indigo:    #6366f1;
  --shadow:    0 1px 3px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.05);
  --radius:    14px;
  --sidebar-w: 250px;
}

html[data-theme="dark"] {
  --bg:        #0f1220;
  --surface:   #181b2e;
  --surface-2: #1f2338;
  --border:    #2b3050;
  --text:      #e8eaf6;
  --text-soft: #9aa3c0;
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.hidden { display: none !important; }
.muted { color: var(--text-soft); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.link { font-size: 13px; font-weight: 600; }

/* ---------------- Layout ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 17px; font-weight: 700;
}
.brand-logo { font-size: 24px; }

.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-soft);
  font-weight: 550;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active .nav-ico { filter: brightness(1.4); }
.nav-ico { font-size: 17px; width: 22px; text-align: center; }
.nav-sep { height: 1px; background: var(--border); margin: 10px 12px; }
.nav-admin { color: var(--indigo); font-weight: 650; }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
  font-weight: 700;
}
.avatar.sm { width: 30px; height: 30px; flex: 0 0 30px; font-size: 13px; }
.avatar.admin { background: linear-gradient(135deg, #6366f1, #a855f7); }
.user-meta { min-width: 0; }
.user-meta strong { display: block; font-size: 14px; }
.user-meta small { color: var(--text-soft); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 19px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.admin-badge {
  font-size: 10px; letter-spacing: .08em;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; padding: 3px 8px; border-radius: 6px; vertical-align: middle;
}

.content { padding: 22px 24px; flex: 1; display: flex; flex-direction: column; gap: 18px; }
.foot { padding: 18px 24px; color: var(--text-soft); font-size: 13px; border-top: 1px solid var(--border); }

/* ---------------- Tombol ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost     { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-danger    { background: var(--red); color: #fff; }
.btn-sm        { padding: 7px 12px; font-size: 13px; }
.btn-block     { width: 100%; }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 10px; cursor: pointer;
  font-size: 15px; color: var(--text);
}
.icon-link {
  background: none; border: none; cursor: pointer;
  font-size: 15px; padding: 3px 5px; border-radius: 6px; color: inherit;
}
.icon-link:hover { background: var(--surface-2); text-decoration: none; }
.icon-link:disabled { opacity: .28; cursor: not-allowed; }

/* ---------------- Kartu ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-head h2 { font-size: 16px; }

.stack { display: flex; flex-direction: column; gap: 18px; }
.grid-2     { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2-1   { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-1-2   { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; }
.stat-grid  { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ---------------- Stat card ---------------- */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--indigo);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.accent-indigo { border-left-color: var(--indigo); }
.accent-green  { border-left-color: var(--green); }
.accent-red    { border-left-color: var(--red); }
.accent-amber  { border-left-color: var(--amber); }

.stat-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--text-soft); font-weight: 600;
}
.stat-ico { font-size: 17px; }
.stat-value { font-size: 25px; font-weight: 700; margin: 6px 0 3px; letter-spacing: -.02em; }
.stat-sub { font-size: 12px; color: var(--text-soft); }

/* ---------------- Toolbar & filter ---------------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-soft); }

input, select, textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: 1px;
}
input[type="color"] { padding: 3px; height: 40px; width: 66px; cursor: pointer; }
.mini-select { padding: 5px 8px; font-size: 13px; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; color: var(--text-soft);
}
.pill b { color: var(--text); }
.pill-green  { border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.pill-green b  { color: var(--green); }
.pill-red    { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.pill-red b    { color: var(--red); }
.pill-indigo { border-color: color-mix(in srgb, var(--indigo) 40%, var(--border)); }
.pill-indigo b { color: var(--indigo); }

/* ---------------- Form ---------------- */
.form { display: flex; flex-direction: column; gap: 13px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.form label input, .form label select { font-weight: 400; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid-2-cols, .grid-2 > .form { min-width: 0; }
.hint { font-size: 12px; color: var(--text-soft); margin: 0; }

.type-switch { display: flex; gap: 10px; grid-column: 1 / -1; }
.type-opt { flex: 1; cursor: pointer; }
.type-opt input { display: none; }
.type-opt span {
  display: block; text-align: center;
  padding: 11px; border: 2px solid var(--border); border-radius: 11px;
  font-weight: 650; color: var(--text-soft);
}
.type-opt.income  input:checked + span { border-color: var(--green); color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); }
.type-opt.expense input:checked + span { border-color: var(--red);   color: var(--red);   background: color-mix(in srgb, var(--red) 10%, transparent); }

.icon-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-opt {
  font-size: 17px; padding: 5px 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
.icon-opt:hover { border-color: var(--primary); }

/* ---------------- Tabel ---------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); font-weight: 650; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot th { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }
.col-check { width: 34px; }
.row-muted { opacity: .55; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.bulk-bar { padding-top: 12px; }

.tag {
  display: inline-block;
  background: color-mix(in srgb, var(--tag, #64748b) 15%, transparent);
  color: var(--tag, #64748b);
  border: 1px solid color-mix(in srgb, var(--tag, #64748b) 35%, transparent);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600;
}
.chip {
  display: inline-block; border-radius: 999px;
  padding: 2px 9px; font-size: 11px; font-weight: 650;
  background: var(--surface-2); color: var(--text-soft);
}
.chip-green  { background: color-mix(in srgb, var(--green) 16%, transparent);  color: var(--green); }
.chip-red    { background: color-mix(in srgb, var(--red) 16%, transparent);    color: var(--red); }
.chip-indigo { background: color-mix(in srgb, var(--indigo) 16%, transparent); color: var(--indigo); }
.chip-amber  { background: color-mix(in srgb, var(--amber) 18%, transparent);  color: #b45309; }
.badge { font-size: 11px; color: var(--text-soft); margin-left: 6px; font-weight: 400; }

.pagination { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-top: 14px; }
.pagination a {
  padding: 6px 11px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-soft); font-size: 13px; font-weight: 600;
}
.pagination a:hover { background: var(--surface-2); text-decoration: none; }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------------- Daftar transaksi ---------------- */
.trx-list, .wallet-list, .legend, .log-list { list-style: none; margin: 0; padding: 0; }
.trx-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.trx-list li:last-child { border-bottom: none; }
.trx-ico { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; }
.trx-info { flex: 1; min-width: 0; }
.trx-info strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trx-info small { color: var(--text-soft); font-size: 12px; }
.trx-amt { font-weight: 700; white-space: nowrap; font-size: 14px; }
.rank {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%;
  background: var(--surface-2); display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: var(--text-soft);
}

.legend li, .wallet-list li {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.legend li:last-child, .wallet-list li:last-child { border-bottom: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-weight: 650; white-space: nowrap; }
.legend-val small { color: var(--text-soft); font-weight: 400; }

.log-list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.log-list li:last-child { border-bottom: none; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 7px; flex: 0 0 8px; }
.log-list strong { display: block; font-size: 13px; text-transform: capitalize; }
.log-list small { display: block; font-size: 12px; color: var(--text-soft); }

/* ---------------- Grafik ---------------- */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 330px; }

/* ---------------- Anggaran & target ---------------- */
.budget-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.budget-row:last-child { border-bottom: none; }
.budget-row.lg { padding: 14px 0; }
.budget-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 7px; }
.budget-foot { display: flex; justify-content: space-between; font-size: 12px; margin-top: 6px; }

.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s; }
.bar-fill.ok   { background: var(--green); }
.bar-fill.warn { background: var(--amber); }
.bar-fill.over { background: var(--red); }

.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.goal-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-2); }
.goal-card.done { border-color: var(--green); }
.goal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.goal-amt { font-size: 14px; margin-bottom: 8px; }
.goal-foot { display: flex; justify-content: space-between; font-size: 12px; margin: 7px 0 10px; }
.goal-deposit { display: flex; gap: 6px; }
.goal-deposit input { flex: 1; min-width: 0; padding: 6px 9px; font-size: 13px; }

/* ---------------- Dompet ---------------- */
.wallet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.wallet-card {
  border: 1px solid var(--border); border-left: 4px solid var(--wc, var(--primary));
  border-radius: 12px; padding: 14px; background: var(--surface-2);
}
.wallet-card.archived { opacity: .55; }
.wallet-top { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.wallet-ico { font-size: 21px; }
.wallet-top strong { display: block; font-size: 14px; }
.wallet-top small { color: var(--text-soft); font-size: 12px; text-transform: capitalize; }
.wallet-saldo { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.wallet-act { display: flex; gap: 3px; }

/* ---------------- Lain-lain ---------------- */
.alert { padding: 12px 15px; border-radius: 10px; font-size: 14px; font-weight: 550; border: 1px solid transparent; }
.alert-success { background: color-mix(in srgb, var(--green) 13%, transparent); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.alert-error   { background: color-mix(in srgb, var(--red) 13%, transparent);   color: var(--red);   border-color: color-mix(in srgb, var(--red) 30%, transparent); }

.empty { text-align: center; color: var(--text-soft); padding: 26px 12px; font-size: 14px; }
.danger-zone { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.danger-zone h2 { color: var(--red); }
.reset-row { flex-wrap: wrap; }

.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 16px; }
.mini-stats div { background: var(--surface-2); border-radius: 10px; padding: 12px; text-align: center; }
.mini-stats b { display: block; font-size: 19px; }
.mini-stats span { font-size: 12px; color: var(--text-soft); }

.backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 35;
}
.backdrop.show { display: block; }

/* ---------------- Halaman autentikasi ---------------- */
.auth-body {
  display: grid; place-items: center; min-height: 100vh; padding: 22px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed 60%, #a855f7);
}
.admin-auth { background: linear-gradient(135deg, #1e1b4b, #4c1d95 60%, #6d28d9); }

.auth-wrap {
  display: grid; grid-template-columns: 1fr 1fr;
  max-width: 940px; width: 100%;
  background: var(--surface);
  border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
.auth-hero { padding: 42px 36px; color: #fff; background: rgba(0,0,0,.22); backdrop-filter: blur(4px); }
.admin-auth .auth-hero { background: rgba(0,0,0,.32); }
.auth-hero { background-color: #4338ca; }
.admin-auth .auth-hero { background-color: #4c1d95; }
.auth-logo { font-size: 44px; margin-bottom: 10px; }
.auth-hero h1 { font-size: 27px; margin-bottom: 10px; }
.auth-hero p { color: rgba(255,255,255,.85); font-size: 14px; }
.auth-points { list-style: none; padding: 0; margin: 22px 0 0; font-size: 13px; color: rgba(255,255,255,.9); }
.auth-points li { padding: 5px 0; }

.auth-card { padding: 42px 36px; }
.auth-card h2 { font-size: 23px; margin-bottom: 5px; }
.auth-card .muted { font-size: 13px; margin: 0 0 20px; }
.auth-card .form { margin-top: 14px; }
.auth-alt { text-align: center; font-size: 13px; margin: 16px 0 0; color: var(--text-soft); }
.grid-2 > label, .form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }

/* ---------------- Responsif ---------------- */
@media (max-width: 1000px) {
  .grid-2, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .stat-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 15px; padding-right: 15px; }
  .filters { width: 100%; }
  .filters input, .filters select { flex: 1 1 140px; min-width: 0; }
}

@media (min-width: 721px) {
  #menuToggle { display: none; }
}

/* ---------------- Cetak ---------------- */
@media print {
  .sidebar, .topbar, .toolbar, .foot, .backdrop { display: none !important; }
  body { background: #fff; }
  .card, .stat-card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .content { padding: 0; }
}
