:root {
  --bg: #0f1419;
  --panel: #1a2129;
  --panel-2: #222b35;
  --line: #2d3742;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4c9aff;
  --pos: #3fb950;
  --neg: #f85149;
  --warn: #d29922;
  --chip: #2d3742;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --radius: 10px;
  --bank: #4c9aff;
  --mm: #56d4dd;
  --fi: #d29922;
  --stk: #bc8cff;
  --cry: #f778ba;
  --oth: #8b98a5;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---- top bar / sticky controls ---- */
header.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,20,25,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; margin-right: 4px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
nav.tabs button:hover { color: var(--text); background: var(--panel); }
nav.tabs button.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.spacer { flex: 1; }

.segmented { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button {
  background: transparent; border: none; color: var(--muted);
  padding: 6px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent); color: #fff; }
.ctl-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin-right: 2px; }

.scenario-banner {
  padding: 6px 18px; font-size: 12.5px; border-bottom: 1px solid var(--line);
  background: rgba(210,153,34,.12); color: var(--warn);
}
.scenario-banner.whatif { background: rgba(188,140,255,.12); color: var(--stk); }
.mode-banner {
  padding: 6px 18px; font-size: 12.5px; border-bottom: 1px solid var(--line);
  background: rgba(210,153,34,.18); color: var(--warn); font-weight: 600; letter-spacing: .02em;
}

/* ---- layout ---- */
main { padding: 18px; max-width: 1280px; margin: 0 auto; }
.section { margin-bottom: 26px; }
.section > h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.section > h2 .hint { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
.trend-slice { margin-left: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; color: inherit; font: inherit; font-size: 12px; padding: 3px 6px; }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .cols-4 { grid-template-columns: 1fr; } }

/* Mobile polish */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 560px) {
  main { padding: 12px; }
  .topbar-row { padding: 8px 12px; gap: 8px; }
  .kpi .value { font-size: 22px; }
  .kpi .label { font-size: 11px; }
  nav.tabs button { padding: 4px 8px; font-size: 12px; }
  .segmented button { padding: 4px 8px; font-size: 11px; }
  .entry-row { grid-template-columns: 1fr; gap: 4px; }
  .entry-row .acct small { font-size: 10px; }
  .card { overflow-x: auto; } /* wide tables scroll inside the card instead of clipping */
}

/* Viewer mode */
body.viewer-mode nav.tabs button[data-view="update"] { display: none; }
.viewer-pill { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); vertical-align: middle; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---- KPI ---- */
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; letter-spacing: .3px; }
.kpi .sub { font-size: 12px; }
.kpi .sub.pos { color: var(--pos); }
.kpi .sub.neg { color: var(--neg); }
.kpi .sub.muted { color: var(--muted); }

/* ---- tables ---- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
table.tbl td:first-child, table.tbl th:first-child { text-align: left; }
table.tbl tr:hover td { background: var(--panel-2); }
table.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
.num.pos { color: var(--pos); }
.num.neg { color: var(--neg); }
.muted { color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---- charts ---- */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 16px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 7px 9px; border-radius: 7px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=number] { text-align: right; }
.btn {
  background: var(--accent); color: #fff; border: none; padding: 8px 16px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:hover { filter: brightness(1.1); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--neg); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

/* Dashboard layout editor (reorder + hide/show) */
.layout-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.layout-toolbar .hint { color: var(--muted); font-size: 12px; }
.layout-block.editing { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 14px; background: rgba(76,154,255,.04); cursor: grab; }
.layout-block.editing:active { cursor: grabbing; }
.layout-block.editing.dragging { opacity: .4; }
.layout-block.editing.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.layout-block.editing.drop-after { box-shadow: 0 3px 0 var(--accent); }
.layout-block.editing.block-hidden { opacity: .55; }
.layout-block.editing .section { margin-bottom: 0; }
.block-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.block-grip { color: var(--muted); font-size: 16px; line-height: 1; user-select: none; }
.block-name { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.block-eye { margin-left: auto; }

.entry-row { display: grid; grid-template-columns: 1fr 140px 90px; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.entry-row .acct { display: flex; flex-direction: column; }
.entry-row .acct small { color: var(--muted); font-size: 11px; }
.cat-header { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 16px 0 4px; font-weight: 700; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--chip); color: var(--muted); }
.pill.pos { background: rgba(63,185,80,.16); color: var(--pos); }
.pill.neg { background: rgba(248,81,73,.16); color: var(--neg); }

.progress { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--pos); }
.progress > div.over { background: var(--accent); }

.note { color: var(--muted); font-size: 12px; }
.banner-info { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.banner-warn { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--warn); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 14px 0; }
.dq-empty { color: var(--pos); }
.dq-warn { color: var(--warn); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.hidden { display: none !important; }

#chartModal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
#chartModal .modal-body { background: var(--panel); border: 1px solid var(--line); padding: 24px; border-radius: 12px; box-shadow: var(--shadow); max-width: 95vw; max-height: 95vh; overflow: auto; position: relative; min-width: 70vw; }
#chartModal .modal-body h3 { margin: 0 0 12px 0; padding-right: 40px; }
#chartModal .modal-body svg { width: 100%; height: auto; min-height: 50vh; }
.modal-close { position: absolute; top: 12px; right: 14px; background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 28px; line-height: 1; padding: 0 8px; }
.modal-close:hover { color: var(--text); }
.card-expand { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0 6px; line-height: 1; }
.card-expand:hover { color: var(--text); }
