:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1e2430; --muted: #7a8194;
  --line: #e3e6ec; --accent: #2563eb; --accent-ink: #fff;
  --pos: #15803d; --neg: #b91c1c; --warn: #b45309;
  --cur: #eff6ff; --past: #fafafa;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2, h3 { margin: .4em 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 12px; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.dim { opacity: .45; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.error { background: #fee2e2; color: var(--neg); padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; }
.hidden { display: none !important; }

/* nav */
.topnav {
  display: flex; align-items: center; gap: 14px; padding: 8px 16px;
  background: #111827; color: #e5e7eb; position: sticky; top: 0; z-index: 20;
}
.topnav .brand { font-weight: 700; letter-spacing: .5px; margin-right: 6px; }
.topnav a { color: #cbd5e1; padding: 4px 6px; border-radius: 6px; }
.topnav a.active, .topnav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
#main { max-width: 1180px; margin: 0 auto; padding: 14px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 7px; padding: 6px 12px; cursor: pointer; font: inherit;
}
.btn:hover { border-color: #c7ccd6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.tiny { padding: 2px 7px; font-size: 12px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

/* worksheet toolbar */
.ws-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px;
}
.ws-balance { font-size: 15px; }
.ws-toolbar label { color: var(--muted); font-size: 13px; }
.ws-toolbar select { margin-left: 4px; }

/* period cards */
.period {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 14px; overflow: hidden;
}
.period.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.period.past { background: var(--past); }
.period-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  cursor: pointer; user-select: none;
}
.period.current .period-head { background: var(--cur); }
.period-dates { font-weight: 600; }
.chev { color: var(--muted); width: 12px; }
.badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  background: #e5e7eb; color: #4b5563; border-radius: 10px; padding: 1px 8px;
}
.badge.cur { background: var(--accent); color: #fff; }
.bal { font-size: 13px; color: var(--muted); }
.bal strong, .bal a { font-size: 14px; }
.bal a { color: var(--ink); }
.bal a.anchored { color: var(--warn); font-weight: 600; }
.period.collapsed .period-body { display: none; }
.period-body { padding: 4px 14px 12px; border-top: 1px solid var(--line); }
.sub { margin: 14px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.tbl th.r { text-align: right; }
.tbl td { padding: 5px 8px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
.tbl tr:hover td { background: #f8fafc; }
.tbl a { color: var(--ink); border-bottom: 1px dashed #c9cedb; }
.tbl a:hover { text-decoration: none; border-bottom-color: var(--accent); }
tr.pdi td { background: #fefce8; }
.inline-cat, .tbl select { max-width: 170px; font-size: 12px; }

/* chips / tags */
.chip {
  display: inline-block; font-size: 11px; border-radius: 10px; padding: 1px 8px;
  background: #e5e7eb; color: #374151;
}
.chip.ok { background: #dcfce7; color: var(--pos); }
.chip.part { background: #fef3c7; color: var(--warn); }
.chip.skip { background: #f3e8ff; color: #7c3aed; }
.tag {
  display: inline-block; font-size: 10px; border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px; color: var(--muted); vertical-align: 1px;
}

.note-btn { color: var(--muted); border-bottom: none; font-size: 13px; }
.note-btn:hover { color: var(--accent); text-decoration: none; }
.note-btn.has-note { color: var(--warn); }
.note-text {
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; display: inline-block; vertical-align: bottom;
}

/* card sections */
.cardsec { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: #fcfcfd; }
.cardsec summary { cursor: pointer; font-weight: 600; }
.cardsec summary .muted { font-weight: 400; }

/* slideover */
.slideover {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 50;
  display: flex; justify-content: flex-end;
}
.slideover-panel {
  width: 420px; max-width: 95vw; background: var(--panel); height: 100%;
  padding: 16px 18px; overflow-y: auto; box-shadow: -8px 0 24px rgba(0,0,0,.15);
}
.slideover-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.slideover-head h3 { margin: 0; }
.so-close {
  flex: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.so-close:hover { background: var(--neg); border-color: var(--neg); color: #fff; }
.soform label { display: block; margin: 10px 0 2px; font-size: 13px; color: var(--muted); }
.soform input[type=text], .soform input[type=number], .soform input[type=date],
.soform input:not([type]), .soform select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit;
}
.soform input[type=checkbox] { margin-left: 6px; vertical-align: -2px; }
.matchinfo { background: #f1f5f9; border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
.cand {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 4px; border-bottom: 1px solid var(--line);
}

/* generic pages */
.page-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-toolbar h2 { margin: 0 8px 0 0; }
.page-toolbar input, .page-toolbar select { padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.chk { color: var(--muted); font-size: 13px; white-space: nowrap; }
.settings-row { margin: 10px 0; }
.linkrow { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.linkrow .chk { flex: 1; color: var(--ink); }

/* savings */
.savings-strip { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.savings-strip .stat {
  flex: 1; min-width: 140px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px;
}
.savings-strip .stat-label {
  display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
}
.savings-strip .stat-val { display: block; font-size: 20px; font-weight: 600; margin-top: 2px; }
.goal-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.goal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.goal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.goal-actions { white-space: nowrap; flex: none; }
.goal-bar { background: var(--line); border-radius: 6px; height: 8px; overflow: hidden; }
.goal-bar-fill { background: var(--accent); height: 100%; border-radius: 6px; }
.goal-notes { white-space: pre-wrap; }
.goal-alloc { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.goal-alloc input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 9px 16px; border-radius: 8px;
  z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--neg); }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 30px; width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card h1 { margin: 0 0 14px; font-size: 22px; }
.login-card label { display: block; margin: 10px 0 2px; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }

@media (max-width: 760px) {
  .topnav { flex-wrap: wrap; gap: 8px; }
  .slideover-panel { width: 100%; }
  .tbl th:nth-child(4), .tbl td:nth-child(4) { display: none; }
}
