:root {
  --sidebar: #2f2cd8;
  --sidebar-2: #2a27c4;
  --primary: #4b48e8;
  --primary-d: #3a37d6;
  --bg: #eef1f8;
  --card: #ffffff;
  --navy: #20264f;
  --navy-2: #2b3470;
  --muted: #97a0b5;
  --muted-2: #aeb6c8;
  --line: #eef0f6;
  --pos: #16c784;
  --neg: #f4475a;
  --debit-1: #1e1b4b;
  --debit-2: #312a6b;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(33, 43, 90, .06);
  --shadow-sm: 0 2px 8px rgba(33, 43, 90, .05);
  --font: 'Nunito', 'Nunito Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--navy);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; min-height: 100vh; }
body.login-mode #app { display: block; }

.ic { display: inline-flex; width: 22px; height: 22px; }
.ic svg { width: 100%; height: 100%; }
.ic.tiny { width: 15px; height: 15px; }
.ic.mini { width: 13px; height: 13px; }
.ic.sm { width: 16px; height: 16px; }

/* ---------------- sidebar ---------------- */
.sidebar {
  width: 64px; flex: 0 0 64px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 0; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.logo {
  width: 40px; height: 40px; border-radius: 11px;
  background: rgba(255, 255, 255, .14);
  display: grid; place-items: center; color: #fff; margin-bottom: 14px;
}
.logo .ic { width: 22px; height: 22px; }
.nav { display: flex; flex-direction: column; gap: 4px; width: 100%; align-items: center; }
.nav-item {
  width: 44px; height: 44px; border: 0; background: transparent; color: rgba(255, 255, 255, .62);
  border-radius: 11px; cursor: pointer; display: grid; place-items: center; transition: .15s;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.nav-item.active { color: #fff; background: rgba(255, 255, 255, .18); }
.nav-item.disabled { color: rgba(255, 255, 255, .5); pointer-events: none; }

/* ---------------- main / topbar ---------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 34px; position: sticky; top: 0; z-index: 20;
  background: var(--bg);
}
.search { display: flex; align-items: center; background: #fff; border-radius: 8px; box-shadow: var(--shadow-sm); width: 320px; max-width: 38vw; overflow: hidden; }
.search-ic { display: none; }
.search input { flex: 1; border: 0; outline: 0; padding: 11px 14px; font: inherit; color: var(--navy); background: transparent; }
.search input::placeholder { color: var(--muted-2); }
.search-btn { border: 0; background: var(--primary); color: #fff; width: 42px; align-self: stretch; cursor: pointer; display: grid; place-items: center; }
.search-btn .ic { width: 18px; height: 18px; }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ic-btn { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.ic-btn:hover { background: #fff; color: var(--primary); }
.ic-btn .ic { width: 18px; height: 18px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; display: grid; place-items: center; cursor: pointer; }
.avatar .ic { width: 18px; height: 18px; }
.edit-btn {
  border: 1px solid #dfe3ee; background: #fff; color: var(--navy-2); border-radius: 8px;
  padding: 7px 13px; font: inherit; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.edit-btn:hover { border-color: var(--primary); color: var(--primary); }
.edit-btn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.save-status { font-size: 12px; color: var(--muted); opacity: 0; transition: .2s; font-weight: 600; }
.save-status.show { opacity: 1; }
.save-status.ok { color: var(--pos); }
.save-status.err { color: var(--neg); }

/* ---------------- page ---------------- */
.page { padding: 4px 34px 24px; flex: 1; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin: 8px 0 22px; }
.page-title { font-size: 23px; font-weight: 800; color: var(--navy); margin: 0; }
.page-sub { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.crumb { color: var(--muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 4px; }
.crumb .ic { color: var(--muted-2); }

.footer { padding: 14px 34px 26px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.footer strong { color: var(--primary); }
.socials { display: inline-flex; gap: 10px; color: var(--muted-2); }
.socials .ic { width: 15px; height: 15px; }

/* ---------------- layout grids ---------------- */
section { margin-bottom: 22px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 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; }
.grid-1-1 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------------- panels & cards ---------------- */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; position: relative; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { font-size: 15px; font-weight: 800; color: var(--navy-2); margin: 0; }
.panel-tools { display: inline-flex; gap: 4px; }

.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 7px; position: relative; }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--navy); }
.stat-card.lg .stat-value { font-size: 24px; }
.stat-trend { font-size: 11.5px; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; }
.stat-trend em { color: var(--muted); font-style: normal; font-weight: 600; }
.stat-trend.pos { color: var(--pos); }
.stat-trend.neg { color: var(--neg); }
.stat-sub { font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.stat-sub.pos { color: var(--pos); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.sm { font-size: 12px; }

/* ---------------- balance trends ---------------- */
.bt-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.bt-value { font-size: 26px; font-weight: 800; color: var(--navy); }
.bt-trend { font-size: 12px; color: var(--muted); }
.bt-trend em { font-style: normal; font-weight: 700; margin-left: 4px; display: inline-flex; align-items: center; gap: 3px; }

/* ---------------- charts ---------------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #f0f2f7; stroke-width: 1; }
.chart .axis { fill: var(--muted-2); font-size: 9px; font-family: var(--font); }
.donut { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.donut svg { width: 92px; height: 92px; }
.donut-pct { font-size: 19px; font-weight: 800; fill: var(--navy); font-family: var(--font); }
.donut-label { font-size: 12.5px; font-weight: 700; color: var(--navy-2); }

/* ---------------- expense breakdown ---------------- */
.legend-bar { height: 9px; border-radius: 6px; margin-bottom: 14px; }
.legend-list { display: flex; flex-direction: column; }
.legend-row { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-bottom: 1px solid var(--line); position: relative; }
.legend-row:last-child { border-bottom: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot.lg { width: 11px; height: 11px; }
.legend-name { color: var(--navy-2); font-weight: 600; }
.legend-amt { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.legend-pct { font-weight: 800; color: var(--navy); width: 38px; text-align: right; }

/* ---------------- budgets / progress ---------------- */
.round-ic { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; }
.round-ic .ic { width: 17px; height: 17px; }
.round-ic.sm { width: 26px; height: 26px; }
.round-ic.sm .ic { width: 14px; height: 14px; }
.budget-list { display: flex; flex-direction: column; gap: 16px; }
.budget-row { display: flex; align-items: center; gap: 12px; position: relative; }
.budget-main { flex: 1; }
.budget-top { display: flex; justify-content: space-between; font-weight: 700; color: var(--navy-2); margin-bottom: 6px; }
.budget-val { color: var(--navy); }
.budget-val em { color: var(--muted-2); font-style: normal; }
.hbar { display: block; height: 7px; border-radius: 6px; background: #eef0f6; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 6px; }

/* ---------------- payments ---------------- */
.pay-list { display: flex; flex-direction: column; }
.pay-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); position: relative; }
.pay-row:last-child { border-bottom: 0; }
.pay-name { font-weight: 700; color: var(--navy-2); }
.pay-date { color: var(--muted); font-size: 11.5px; }
.pay-right { display: flex; align-items: center; gap: 10px; }
.pay-amt { font-weight: 700; color: var(--navy); }
.pill { font-size: 10.5px; font-weight: 800; padding: 3px 10px; border-radius: 20px; color: #fff; }
.pill.ok { background: var(--pos); }
.pill.warn { background: #f5a524; }
.pill.bad { background: var(--neg); }

/* ---------------- goals ---------------- */
.goals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 4px; }
.goal-cell { display: flex; justify-content: center; padding: 8px 0; position: relative; }

/* ---------------- tables ---------------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 800; color: var(--navy-2); padding: 0 10px 12px; border-bottom: 1px solid var(--line); }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td { padding: 13px 10px; border-bottom: 1px solid var(--line); color: var(--navy-2); font-size: 12.5px; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .cat { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; }
.tbl .muted { color: var(--muted); }

/* ---------------- financial overview ---------------- */
.fo-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.fo-list { display: flex; flex-direction: column; gap: 12px; }
.fo-acc {
  background: #fff; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; cursor: pointer; text-align: left; position: relative; transition: .15s;
}
.fo-acc .round-ic { background: #f2f1fd; color: var(--primary); }
.fo-acc-main { display: flex; flex-direction: column; }
.fo-acc-name { font-weight: 800; color: var(--navy-2); }
.fo-acc-bal { color: var(--muted); font-size: 12px; }
.fo-acc.active { background: var(--primary); box-shadow: 0 10px 22px rgba(75, 72, 232, .3); }
.fo-acc.active .fo-acc-name, .fo-acc.active .fo-acc-bal { color: #fff; }
.fo-acc.active .fo-acc-bal { color: rgba(255, 255, 255, .8); }
.fo-acc .round-ic.on { background: rgba(255, 255, 255, .2); color: #fff; }
.fo-acc-tools { margin-left: auto; display: inline-flex; gap: 2px; }
.fo-acc.active .fo-acc-tools .tool { color: rgba(255, 255, 255, .85); }
.fo-add {
  background: #fff; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px 16px;
  display: flex; align-items: center; justify-content: space-between; cursor: pointer; font: inherit; font-weight: 700; color: var(--navy-2);
}
.fo-add:hover { color: var(--primary); }
.fo-add .ic { color: var(--primary); }

.fo-detail { display: flex; flex-direction: column; gap: 18px; }
.fo-title h3 { font-size: 16px; }
.fo-top { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.fo-summary { display: flex; flex-direction: column; gap: 6px; }
.fo-big { font-size: 26px; font-weight: 800; color: var(--navy); margin: 2px 0 8px; }
.fo-sumrow { display: flex; justify-content: space-between; padding: 5px 0; }
.fo-sumrow span:last-child { font-weight: 700; color: var(--navy); }
.fo-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.debit-card {
  background: linear-gradient(135deg, var(--debit-1), var(--debit-2)); color: #fff; border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; justify-content: space-between; min-height: 132px; box-shadow: var(--shadow);
}
.dc-label { font-size: 12px; opacity: .85; font-weight: 600; }
.dc-number { display: flex; align-items: center; gap: 14px; font-size: 16px; letter-spacing: 1px; font-weight: 700; margin: 6px 0; }
.dc-number i { width: 26px; height: 8px; display: inline-flex; gap: 3px; }
.dc-number i::before, .dc-number i::after { content: ''; }
.dc-number i { background: radial-gradient(circle, #fff 1.6px, transparent 1.7px) repeat-x; background-size: 7px 8px; height: 8px; }
.dc-foot { display: flex; justify-content: space-between; font-size: 12px; }
.dc-foot span:first-child { font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 40px; }

/* ---------------- edit tools ---------------- */
.tool { border: 0; background: #f3f4fa; color: var(--muted); width: 26px; height: 26px; border-radius: 7px; cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.tool:hover { background: var(--primary); color: #fff; }
.tool .ic { width: 14px; height: 14px; }
.row-tools { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: none; gap: 4px; background: rgba(255,255,255,.9); padding: 2px; border-radius: 8px; }
body.editing .legend-row:hover .row-tools,
body.editing .budget-row:hover .row-tools,
body.editing .pay-row:hover .row-tools,
body.editing .goal-cell:hover .row-tools,
body.editing .stat-card:hover .row-tools { display: inline-flex; }
.stat-card .row-tools { top: 12px; transform: none; }
.goal-cell .row-tools { top: 4px; }

/* ---------------- buttons ---------------- */
.btn { border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: #eef0f6; color: var(--navy-2); }
.btn.danger { background: var(--neg); color: #fff; }
.btn.block { width: 100%; }

/* ---------------- modal ---------------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 26, 60, .5); display: grid; place-items: center; z-index: 100; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; border-radius: 14px; width: 440px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 24px 60px rgba(20, 26, 60, .3); }
.modal.small { width: 380px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 800; color: var(--navy); }
.modal-x { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-body { padding: 20px 22px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; font-weight: 700; color: var(--navy-2); margin-bottom: 5px; }
.field input, .field select { width: 100%; border: 1px solid #dfe3ee; border-radius: 8px; padding: 9px 11px; font: inherit; color: var(--navy); outline: 0; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(75, 72, 232, .12); }
.field-help { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input { width: 46px; height: 36px; padding: 2px; }
.color-row code { color: var(--muted); font-size: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.confirm-text { color: var(--muted); margin: 0 0 18px; }

/* ---------------- login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--sidebar), #1c1aa0); padding: 20px; }
.login-card { background: #fff; border-radius: 18px; padding: 38px 34px; width: 380px; max-width: 100%; box-shadow: 0 30px 80px rgba(0, 0, 0, .25); }
.login-brand { display: flex; align-items: center; gap: 10px; color: var(--primary); font-weight: 800; font-size: 20px; margin-bottom: 22px; }
.login-brand .ic { width: 28px; height: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--navy); }
.login-sub { color: var(--muted); margin: 0 0 20px; }
.login-card input { width: 100%; border: 1px solid #dfe3ee; border-radius: 9px; padding: 12px 14px; font: inherit; outline: 0; margin-bottom: 14px; }
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(75, 72, 232, .12); }
.login-error { background: #fdeaec; color: var(--neg); padding: 9px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; margin-bottom: 14px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2-1, .grid-1-2, .grid-1-1 { grid-template-columns: 1fr; }
  .fo-layout { grid-template-columns: 1fr; }
  .fo-list { flex-direction: column; }
}
@media (max-width: 680px) {
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; width: 100%; height: 56px; flex-direction: row; justify-content: space-around; padding: 0 8px; z-index: 50; }
  .sidebar .logo { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .main { padding-bottom: 60px; }
  .page, .topbar, .footer { padding-left: 14px; padding-right: 14px; }
  .grid-4 { grid-template-columns: 1fr; }
  .fo-top, .fo-stats, .goals-grid { grid-template-columns: 1fr; }
  .search { max-width: none; }
  .tbl { font-size: 11.5px; }
  .tbl td, .tbl th { padding-left: 4px; padding-right: 4px; }
  .footer { flex-direction: column; gap: 8px; }
}
