:root {
  --bg: #0b0d10;
  --panel: #14171c;
  --panel-2: #1b1f26;
  --line: #262b33;
  --text: #e6e9ee;
  --muted: #8a93a3;
  --dim: #5c6472;
  --accent: #4ade80;
  --danger: #f87171;
  --warn: #fbbf24;
  --blue: #60a5fa;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; }

/* ------------------------------------------------------------- sidebar */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #4ade80, #22c55e);
  color: #06210f; font-weight: 700; font-size: 19px;
  display: grid; place-items: center;
}
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--dim); }

nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; width: 100%;
  color: var(--muted); font: inherit; font-size: 13px;
  padding: 9px 11px; border-radius: 8px; cursor: pointer;
  text-align: left; transition: background .12s, color .12s;
}
.nav-item span { width: 16px; text-align: center; opacity: .75; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 550; }

.period { display: flex; flex-direction: column; gap: 6px; }
.period label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }

select, input[type="search"] {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit; font-size: 13px; outline: none;
}
select:focus, input:focus { border-color: #3c4655; }

.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--dim); line-height: 1.6; }
.warn { color: var(--warn); opacity: .8; margin-top: 4px; }

/* ---------------------------------------------------------------- main */
main { flex: 1; padding: 30px 34px 60px; max-width: 1180px; overflow-x: hidden; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 23px; font-weight: 620; letter-spacing: -0.02em; }
.sub { margin: 5px 0 0; color: var(--muted); font-size: 13px; max-width: 70ch; }

/* ---------------------------------------------------------------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; }
.kpi-label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 22px; font-weight: 620; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.pos { color: var(--accent); } .neg { color: var(--danger); }

/* --------------------------------------------------------------- cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.hint { font-size: 11.5px; color: var(--dim); }
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- charts */
.chart svg { width: 100%; height: 220px; display: block; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--dim); font-size: 9.5px; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 92px; align-items: center; gap: 11px; font-size: 12.5px; }
.bar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--panel-2); border-radius: 5px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; transition: width .3s ease; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.bar-row.over .bar-value { color: var(--danger); }

/* --------------------------------------------------------- transactions */
.filters { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input[type="search"] { flex: 1; min-width: 220px; }

.txn-list { display: flex; flex-direction: column; }
.txn {
  display: grid; grid-template-columns: 34px 1fr auto;
  gap: 12px; align-items: center;
  padding: 11px 17px; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background .1s;
}
.txn:hover { background: var(--panel-2); }
.txn:last-child { border-bottom: 0; }
.txn-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; }
.txn-main { min-width: 0; }
.txn-payee { font-weight: 520; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: 11.5px; color: var(--dim); margin-top: 2px; display: flex; gap: 7px; flex-wrap: wrap; }
.txn-amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 560; white-space: nowrap; }
.txn-amt .flow { display: block; font-size: 10.5px; font-weight: 400; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }

.chip { padding: 1px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); font-size: 10.5px; }
.chip.reviewed { color: var(--accent); border-color: rgba(74,222,128,.3); }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 13px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.pager button { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 6px 12px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 12.5px; }
.pager button:disabled { opacity: .35; cursor: default; }
.pager button:not(:disabled):hover { border-color: #3c4655; }

/* ------------------------------------------------------------ accounts */
.acct-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 13px; }
.acct { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.acct-top { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.acct-name { font-weight: 580; font-size: 14px; }
.acct-inst { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.acct-type { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; padding: 3px 7px; border-radius: 5px; background: var(--panel-2); color: var(--muted); }
.acct-rows { margin-top: 13px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.acct-row { display: flex; justify-content: space-between; }
.acct-row span:first-child { color: var(--dim); }
.acct-row span:last-child { font-variant-numeric: tabular-nums; }
.acct-flag { margin-top: 11px; font-size: 11px; color: var(--warn); background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.2); padding: 6px 8px; border-radius: 7px; }

/* ----------------------------------------------------------- recurring */
.recur-list { display: flex; flex-direction: column; gap: 9px; }
.recur { display: grid; grid-template-columns: 1fr auto auto; gap: 15px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 13px 16px; }
.recur-name { font-weight: 540; }
.recur-meta { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.recur-amt { text-align: right; font-variant-numeric: tabular-nums; }
.recur-amt small { display: block; color: var(--dim); font-size: 11px; }
.badge { font-size: 10.5px; padding: 3px 8px; border-radius: 5px; text-transform: uppercase; letter-spacing: .05em; }
.badge.active { background: rgba(74,222,128,.12); color: var(--accent); }
.badge.dormant { background: rgba(251,191,36,.12); color: var(--warn); }

/* ------------------------------------------------------------- quality */
.funnel { display: flex; flex-direction: column; gap: 7px; }
.funnel-row { display: grid; grid-template-columns: 190px 1fr 108px; align-items: center; gap: 12px; font-size: 12.5px; }
.funnel-bar { height: 26px; border-radius: 6px; background: linear-gradient(90deg, #2563eb, #60a5fa); display: flex; align-items: center; padding-left: 9px; font-size: 11.5px; color: #fff; }
.funnel-note { color: var(--dim); font-size: 11.5px; text-align: right; }

.mini-table { display: flex; flex-direction: column; font-size: 12.5px; }
.mini-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr 100px; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mini-row:last-child { border: 0; }
.mini-row.head { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.mini-row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.stat-line { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.stat-line:last-child { border: 0; }
.stat-line span:first-child { color: var(--muted); }
.stat-line span:last-child { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
/* display:grid above would otherwise defeat the hidden attribute */
.sheet[hidden] { display: none; }
.sheet-body { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, 100%); max-height: 84vh; overflow-y: auto; position: relative; }
.sheet-close { position: absolute; top: 12px; right: 14px; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.sheet h3 { margin: 0 0 3px; font-size: 17px; }
.sheet .raw { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 11px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px; color: var(--muted); white-space: pre-wrap; word-break: break-word; margin: 13px 0; }
.sheet-actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.sheet-actions button { background: var(--accent); color: #06210f; border: 0; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 580; cursor: pointer; }
.sheet-actions label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.empty { padding: 40px; text-align: center; color: var(--dim); font-size: 13px; }

/* -------------------------------------------------------------- legend */
.legend { display: flex; gap: 16px; margin-top: 10px; font-size: 11.5px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ------------------------------------------------------------- budgets */
.budget-list { display: flex; flex-direction: column; gap: 10px; }
.budget-row { display: grid; grid-template-columns: 140px 1fr 130px 110px; align-items: center; gap: 11px; font-size: 12.5px; }
.budget-row.over .bar-value { color: var(--danger); }
.budget-edit { display: flex; align-items: center; gap: 3px; color: var(--dim); font-size: 11.5px; }
.budget-edit input {
  width: 74px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
  font: inherit; font-size: 12px; text-align: right;
}
.budget-edit input:focus { outline: none; border-color: #3c4655; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 14px; padding: 14px 16px;
  }
  .brand { flex: 1 1 auto; }
  nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-item { width: auto; padding: 7px 10px; }
  .period { flex-direction: row; align-items: center; gap: 8px; }
  .sidebar-foot { display: none; }
  main { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 9px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 18px; }
  .bar-row { grid-template-columns: 104px 1fr 78px; }
  .funnel-row { grid-template-columns: 118px 1fr; }
  .funnel-note { display: none; }
  .mini-row { grid-template-columns: 1.2fr 1fr 88px; }
  .mini-row span:nth-child(3) { display: none; }
  .recur { grid-template-columns: 1fr auto; }
  .recur .badge { grid-column: 2; }
}
