:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1f2330; --border: #2a2f3d;
  --text: #e6e8ee; --muted: #8b92a5; --accent: #4cc9a0; --accent-2: #6aa8ff;
  --pos: #4cc9a0; --neg: #ff6b6b; --warn: #f2a541; --danger: #ff5c5c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--accent-2); }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; color: var(--text); }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; vertical-align: middle; font-weight: 700; }
.badge.demo { background: var(--warn); color: #000; }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs button { background: transparent; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.tabs button:hover { color: var(--text); background: var(--panel-2); }
.tabs button.active { color: var(--text); background: var(--panel-2); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.inline { display: inline; margin: 0; }

/* ---- layout ---- */
#app { padding: 20px; max-width: 1400px; margin: 0 auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-cal { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.grid-cal .card, .tx-layout .card { overflow-x: auto; }
.tx-layout { grid-template-columns: 1.2fr 1fr; }
@media (max-width: 900px) { .grid-2, .grid-cal, .tx-layout { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile.accent { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(76,201,160,.25); }
.tile-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tile-value { font-size: 28px; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; }

/* ---- buttons / forms ---- */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: #05261b; border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.wide { width: 100%; padding: 10px; font-size: 15px; }
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 13px; }
input:focus, select:focus { outline: none; border-color: var(--accent-2); }
input[type=color] { padding: 0 2px; width: 40px; height: 30px; }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
label input, label select { display: block; width: 100%; margin-top: 4px; }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 13px; }
label.check input { width: auto; margin: 0; display: inline; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.row-form input, .row-form select { flex: 1 1 120px; min-width: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 220px; }

/* ---- tables & lists ---- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; }
table.data select, table.data input { font-size: 12px; padding: 4px 6px; }
table.data .pending { opacity: .6; font-style: italic; }
table.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
table.kv td { padding: 5px 0; border-bottom: 1px dashed var(--border); }
table.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
table.kv tr.total td { font-weight: 700; border-bottom: 0; font-size: 15px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.list li:last-child { border-bottom: 0; }
.list.small li { font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--panel-2); color: var(--muted); }
.cat-chip { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; color: #000; font-weight: 600; }

/* ---- accounts ---- */
.acct-group { margin-bottom: 12px; }
.acct-group h3 { margin-top: 6px; }
.acct { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.acct:last-child { border-bottom: 0; }
.acct .name { font-weight: 500; }
.acct .inst { color: var(--muted); font-size: 12px; margin-left: 6px; }
.acct .bal { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- charts ---- */
.chart-box { position: relative; height: 260px; }
.chart-box.pie { height: 240px; flex: 0 0 240px; }
.chart-box.pie.small { height: 200px; flex: 0 0 200px; }
.pie-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 180px; font-size: 12px; }
.legend li { display: flex; justify-content: space-between; padding: 3px 0; gap: 8px; }
.legend li span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- calendar ---- */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cal-head h2 { margin: 0; flex: 0 0 auto; min-width: 150px; text-align: center; }
.cal-head .muted { margin-left: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; padding: 4px 0; }
.cal-cell { min-height: 84px; background: var(--panel-2); border-radius: 6px; padding: 4px 6px; font-size: 11px; cursor: pointer; border: 1px solid transparent; overflow: hidden; }
.cal-cell:hover, .cal-cell.selected { border-color: var(--accent-2); }
.cal-cell.other { opacity: .35; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell .d { font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.cal-cell.today .d { color: var(--accent); }
.ev { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 4px; border-radius: 3px; margin-bottom: 2px; }
.ev.bill { background: rgba(255,107,107,.18); color: #ffb3b3; }
.ev.bill.card { background: rgba(242,165,65,.18); color: #ffd699; }
.ev.income { background: rgba(76,201,160,.2); color: #9ff0d3; }
.ev.paid { text-decoration: line-through; opacity: .6; }
.cal-day { margin-top: 12px; }
.cal-day h3 { margin-top: 0; }

/* ---- insights ---- */
.insight { display: grid; grid-template-columns: 8px 1fr auto; gap: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 0; margin-bottom: 12px; overflow: hidden; }
.insight .bar { background: var(--muted); }
.insight.high .bar { background: var(--danger); }
.insight.medium .bar { background: var(--warn); }
.insight.low .bar { background: var(--accent-2); }
.insight h2 { margin-bottom: 4px; }
.insight .tip { color: var(--accent); margin-top: 6px; }
.insight .amt { font-size: 22px; font-weight: 700; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.insight .amt small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.insight.expandable { cursor: pointer; }
.insight.expandable:hover { border-color: var(--muted); }
.insight .hint { color: var(--accent-2); margin-top: 4px; }
.insight-tx { background: var(--panel); border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); margin: -13px 0 12px; padding: 4px 16px 8px; max-height: 420px; overflow-y: auto; }
.insight-tx tfoot td { font-weight: 700; border-top: 1px solid var(--border); border-bottom: 0; }

/* ---- goals ---- */
.goal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.goal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.goal .head { display: flex; justify-content: space-between; align-items: baseline; }
.goal .pct { font-size: 24px; font-weight: 700; }
.progress { height: 10px; background: var(--panel-2); border-radius: 5px; margin: 10px 0; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 5px; transition: width .4s; }
.goal.debt .progress > div { background: var(--accent-2); }
.goal .foot { display: flex; justify-content: space-between; margin-top: 10px; }
.ok { color: var(--pos); } .behind { color: var(--warn); }

/* ---- login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 340px; }
.login-card label input { width: 100%; padding: 9px; font-size: 15px; }
.error { color: var(--danger); background: rgba(255,92,92,.1); padding: 8px 10px; border-radius: 6px; font-size: 13px; }

/* ---- toast ---- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 8px; z-index: 20; }
.toast.err { border-color: var(--danger); }
