:root {
  --bg: #1a1d23;
  --bg-elev: #23272f;
  --bg-elev-2: #2a2f38;
  --fg: #e5e7eb;
  --fg-dim: #9aa0a8;
  --accent: #6ab0ff;
  --counted: #e5e7eb;
  --excluded: #6b7280;
  --deferred: #f5b86a;
  --positive: #6dd58c;
  --border: #353a44;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.nav-link:hover { color: var(--fg); background: var(--bg-elev-2); }
.nav-link.active { color: var(--fg); background: var(--bg-elev-2); }

main {
  padding: 20px;
  max-width: 1800px;
  margin: 0 auto;
}

/* ---- Summary grid ---- */

.summary-table {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.summary-table th, .summary-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
.summary-table th.cat, .summary-table td.cat {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--bg);
  font-weight: 500;
}
.summary-table th.avg, .summary-table td.avg {
  position: sticky;
  left: 0;
  background: var(--bg);
  font-weight: 600;
  border-right: 1px solid var(--border);
}
.summary-table thead th {
  background: var(--bg-elev);
  color: var(--fg-dim);
  font-weight: 500;
  position: sticky;
  top: 0;
}
.summary-table thead th.cat { z-index: 2; }
.summary-table tfoot td { font-weight: 600; background: var(--bg-elev); border-top: 2px solid var(--border); }
.summary-table td.amt.zero { color: var(--fg-dim); }

/* Distribution-based background coloring, relative to each category's
   6-month rolling avg. Magnitude above avg = red (spent more); below = green. */
.summary-table td.bg-red-bright    { background: rgba(220,  60,  60, 0.55); }
.summary-table td.bg-red-pale      { background: rgba(220,  60,  60, 0.25); }
.summary-table td.bg-green-pale    { background: rgba( 70, 180,  90, 0.25); }
.summary-table td.bg-green-bright  { background: rgba( 70, 180,  90, 0.55); }

.summary-table .period-cell:hover { outline: 1px solid var(--accent); cursor: pointer; }

.summary-table .hide-row {
  background: none;
  border: none;
  color: var(--fg-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 6px 0 0;
  opacity: 0;
  transition: opacity 0.1s;
}
.summary-table tr:hover .hide-row { opacity: 1; }
.summary-table .hide-row:hover { color: var(--fg); }

.hidden-list {
  margin-top: 16px;
  color: var(--fg-dim);
  font-size: 12px;
}
.hidden-list .show-row {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 4px;
}
.hidden-list .show-row:hover { color: var(--fg); border-color: var(--accent); }
.hidden-list .show-row span { opacity: 0.5; margin-left: 4px; }

.loading { color: var(--fg-dim); padding: 40px; text-align: center; }

/* ---- View header (shared by period/review/pending) ---- */

.view-header {
  margin-bottom: 16px;
}
.view-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.period-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.period-nav button {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.period-nav button:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 4px 2px 10px;
  font-size: 12px;
  color: var(--fg-dim);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.filter-chip .clear-filter {
  background: none;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 0 6px;
  width: auto;
  height: auto;
}
.filter-chip .clear-filter:hover { color: var(--fg); }

/* ---- Recurring expectations checklist ---- */

.exp-strip {
  margin-top: 8px;
  font-size: 12px;
  color: var(--fg-dim);
}
.exp-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  margin: 2px 4px 2px 0;
  font-size: 11px;
  border: 1px solid var(--border);
}
.exp-chip.exp-ok   { color: var(--positive); border-color: rgba(70,180,90,0.5); }
.exp-chip.exp-miss { color: #e98c8c; border-color: rgba(220,60,60,0.5); }

/* ---- Recurring CRUD table ---- */

.recurring-table input,
.recurring-table select {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid transparent;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}
.recurring-table input:hover,
.recurring-table select:hover { border-color: var(--border); }
.recurring-table input:focus,
.recurring-table select:focus { border-color: var(--accent); outline: none; }
.recurring-table .r-del,
.recurring-table .r-add {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  width: 26px; height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.recurring-table .r-del:hover { color: #e98c8c; border-color: #e98c8c; }
.recurring-table .r-add:hover { color: var(--positive); border-color: var(--positive); }
.recurring-table tr.r-new { background: rgba(106,176,255,0.04); }
.recurring-table tr.r-new td { border-bottom: none; }

/* ---- Obligations ---- */

.decision-strip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 12px;
}
.decision-strip .opt { margin-right: 16px; color: var(--fg-dim); }
.decision-strip .opt b { color: var(--fg); }

.cash-plan {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.cash-plan-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.cash-plan-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.cash-plan-meta { color: var(--fg-dim); font-size: 12px; }
.reserve-warn {
  background: rgba(245,184,106,0.1);
  border-left: 3px solid var(--deferred);
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  border-radius: 0 4px 4px 0;
}
.reserve-warn b { color: var(--deferred); }
.cash-plan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.cash-plan-table th {
  text-align: left;
  font-weight: 500;
  color: var(--fg-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.cash-plan-table th.num { text-align: right; }
.cash-plan-table td { padding: 8px 10px; vertical-align: top; border-bottom: 1px solid var(--border); }
.cash-plan-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cash-plan-table td.rank { color: var(--fg-dim); font-weight: 600; width: 24px; }
.cash-plan-table tr:last-child td { border-bottom: none; }
.cash-plan-table .dim { color: var(--fg-dim); }

.reserve-status {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--fg-dim);
}
.reserve-status b { color: var(--fg); }
.reserve-status .reserve-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-elev-2);
  border-radius: 2px;
  margin: 6px 0;
  overflow: hidden;
}
.reserve-status .reserve-bar-fill {
  height: 100%;
  background: var(--accent);
}
.reserve-backup-inline { float: right; }

.strategies {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.strategy {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 12px;
}
.strategy-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.strategy-head { display: flex; justify-content: space-between; align-items: center; }
.strategy-head h4 { margin: 0; font-size: 13px; font-weight: 600; }
.strategy-badge {
  background: var(--accent);
  color: var(--bg);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.strategy-summary {
  color: var(--fg-dim);
  margin: 8px 0;
}
.strategy-math {
  background: var(--bg-elev-2);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}
.strategy-math li { padding: 2px 0; color: var(--fg-dim); }
.strategy-math li:first-child { color: var(--fg); }
.strategy-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}
.strategy-cols b { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-dim); margin-bottom: 4px; }
.strategy-cols ul { margin: 0; padding-left: 16px; }
.strategy-cols li { padding: 2px 0; }
@media (max-width: 900px) {
  .strategies { grid-template-columns: 1fr; }
}

.strategy-anti {
  border-color: rgba(220, 60, 60, 0.4);
}
.strategy-anti h4 { color: #e98c8c; }
.anti-list {
  margin: 8px 0 0;
  padding-left: 20px;
}
.anti-list > li {
  margin-bottom: 12px;
}
.anti-list > li > b { color: var(--fg); }
.anti-list ul {
  margin: 4px 0 0;
  padding-left: 18px;
  color: var(--fg-dim);
  font-size: 11px;
}
.anti-list ul li { padding: 1px 0; }

/* ---- Velocity widget ---- */

.velocity {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 12px;
}
.velocity-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.velocity-head .obl-h3 { margin: 0; }
.velocity-day { color: var(--fg-dim); font-size: 12px; }
.velocity-bar {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.velocity-bar-fill { height: 100%; background: var(--accent); transition: width .3s; }
.velocity-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 24px;
  margin-bottom: 10px;
}
.velocity-stats > div { display: flex; flex-direction: column; gap: 2px; }
.velocity-stats .lbl { font-size: 10px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.velocity-stats .val { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.velocity-stats .val small { color: var(--fg-dim); font-weight: normal; }
.velocity-stats .over     { color: #e98c8c; }
.velocity-stats .under    { color: var(--positive); }
.velocity-stats .neutral  { color: var(--fg); }
.velocity-movers {
  margin-top: 6px;
  color: var(--fg-dim);
}
.velocity-movers b { color: var(--fg); }
.mover {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 4px;
  font-size: 11px;
}
.mover.over  { border-color: rgba(220, 60, 60, 0.5); color: #e98c8c; }
.mover.under { border-color: rgba(70, 180, 90, 0.5); color: var(--positive); }
.mover small { opacity: 0.7; margin-left: 2px; }

.obl-h3 {
  margin: 24px 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.obl-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.obl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.obl-head h4 { margin: 0; font-size: 16px; font-weight: 600; }
.obl-kind {
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.obl-note {
  color: var(--fg-dim);
  font-size: 12px;
  margin: 4px 0 12px;
}

.obl-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.obl-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.obl-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 24px;
}
.obl-stats > div { display: flex; flex-direction: column; gap: 2px; }
.obl-stats .lbl { font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.obl-stats .val { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.obl-stats .dim { color: var(--fg-dim); font-weight: normal; }

.obl-history {
  margin-top: 16px;
  font-size: 12px;
}
.obl-history summary {
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}
.obl-history summary:hover { color: var(--fg); }
.obl-history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.obl-history-table th {
  text-align: left;
  font-weight: 500;
  color: var(--fg-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
.obl-history-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.obl-history-table th.num, .obl-history-table td.num { text-align: right; }
.view-meta {
  color: var(--fg-dim);
  font-size: 12px;
}
.view-meta b { color: var(--fg); }

/* ---- Transaction list ---- */

.txn-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  border-bottom: none;
  font-size: 12px;
}
.txn-toolbar .bulk-count {
  color: var(--fg-dim);
  margin-left: auto;
  margin-right: 8px;
}
.txn-toolbar .bulk-btn {
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}
.txn-toolbar .bulk-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.txn-toolbar .bulk-btn:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent);
}

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
}
.txn-table th, .txn-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.txn-table th {
  color: var(--fg-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-elev-2);
}
.txn-table th.num, .txn-table td.num { text-align: right; }
.txn-table tbody tr:last-child td { border-bottom: none; }

.txn-row.unreviewed { background: rgba(106, 176, 255, 0.05); }
.txn-row.unreviewed td.date::before {
  content: '•';
  color: var(--accent);
  margin-right: 4px;
}

.txn-table .amt.pos { color: var(--positive); }
.txn-table .desc {
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.txn-table .account {
  color: var(--fg-dim);
  font-size: 11px;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-table select,
.txn-table input[type=text] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid transparent;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}
.txn-table select:hover,
.txn-table input[type=text]:hover { border-color: var(--border); }
.txn-table select:focus,
.txn-table input[type=text]:focus {
  border-color: var(--accent);
  outline: none;
}
.txn-table input[type=text] { width: 140px; }
.txn-table select.inline-status.status-excluded { color: var(--excluded); }
.txn-table select.inline-status.status-deferred { color: var(--deferred); }

.txn-table th.sortable { cursor: pointer; user-select: none; }
.txn-table th.sortable:hover { color: var(--fg); }

.txn-table .predicted {
  font-size: 11px;
  white-space: nowrap;
}
.txn-table .predicted .pred-cat { font-weight: 500; }
.txn-table .predicted .pred-cat.pred-excluded { font-style: italic; font-weight: 400; }
.txn-table .predicted .pred-conf {
  color: var(--fg-dim);
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
.txn-table .predicted.high  .pred-cat { color: var(--positive); }
.txn-table .predicted.med   .pred-cat { color: var(--accent); }
.txn-table .predicted.low   .pred-cat { color: var(--fg-dim); }
.txn-table .predicted.disagree {
  background: rgba(255, 170, 64, 0.08);
}
.txn-table .predicted.clickable { cursor: pointer; }
.txn-table .predicted.clickable:hover {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
.txn-table .predicted.accepting {
  opacity: 0.5;
  pointer-events: none;
}
.txn-row.removing {
  opacity: 0;
  transition: opacity 0.15s;
}

.period-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0;
  font-size: 12px;
}
.period-filters select,
.period-filters input[type=text],
.period-filters input[type=number] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}
.period-filters input[type=number] { width: 80px; }
.period-filters input[type=text] { width: 220px; }
.period-filters label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--fg-dim);
}
.period-filters button.pf-clear {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.period-filters button.pf-clear:hover { color: var(--fg); }

/* ---- Keywords view ---- */
.keyword-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.keyword-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.keyword-card.excluded {
  grid-column: 1 / -1;
  border-color: rgba(255, 170, 64, 0.4);
  background: rgba(255, 170, 64, 0.04);
}
.keyword-card h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.keyword-card h3 .count {
  color: var(--fg-dim);
  font-weight: 400;
  font-size: 11px;
}
.kw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  min-height: 4px;
}
.kw-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px 2px 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.kw-chip .kw-text { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw-chip .kw-del {
  background: none;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
}
.kw-chip .kw-del:hover { color: var(--excluded, #d66); }

.kw-add { display: flex; gap: 4px; }
.kw-add input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
}
.kw-add input:focus { outline: none; border-color: var(--accent); }
.kw-add input.error { border-color: var(--excluded, #d66); }
.kw-add button {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 4px;
  padding: 0 8px;
  cursor: pointer;
  font-size: 12px;
}
.kw-add button:hover { background: var(--accent); color: var(--bg); }
