/* Budget Planner — USAA-inspired theme (see docs/phase-bp/phase-bp-plan.md BP-6) */

:root {
  --navy: #1c3a5e;
  --navy-deep: #16304e;
  --gold: #ffb81c;
  --link: #1a5dab;          /* validated series/link blue */
  --ink: #1f2933;
  --muted: #5b6770;
  --hairline: #e3e7eb;
  --surface: #ffffff;
  --bg: #f4f6f8;
  --green: #177245;         /* validated */
  --red: #b3261e;           /* validated */
  --red-soft: #fdecea;
  --green-soft: #e8f3ed;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.shell { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------------------------------------------------------------- header */
.topbar { background: var(--navy); color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 28px; height: 64px; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand span { font-weight: 300; opacity: .85; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-link {
  background: none; border: 0; color: #fff; font: inherit; font-size: 15px;
  padding: 20px 14px; cursor: pointer; border-bottom: 3px solid transparent;
}
.nav-link:hover { background: var(--navy-deep); }
.nav-link.active { border-bottom-color: var(--gold); font-weight: 600; }
.top-link { color: #fff; text-decoration: none; font-size: 14px; opacity: .9; }
.top-link:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- greeting */
.greeting { margin: 26px 0 20px; }
.greeting h1 { font-size: 26px; font-weight: 600; color: var(--ink); }
.gold-bar { width: 72px; height: 4px; background: var(--gold); margin-top: 8px; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 4px;
  margin-bottom: 20px; overflow: hidden;
}
.card-pad { padding: 18px 20px; }
.card-title { font-size: 17px; font-weight: 600; }
.card-head-navy {
  background: var(--navy); color: #fff; padding: 14px 18px;
}
.card-head-navy h2 { font-size: 18px; font-weight: 600; }
.card-head-light {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 18px; border-bottom: 1px solid var(--hairline); background: #fafbfc;
}
.subtabs button {
  background: none; border: 0; font: inherit; font-size: 15px; color: var(--muted);
  padding: 14px 4px; margin-right: 20px; cursor: pointer;
  border-bottom: 3px solid transparent;
}
.subtabs button.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--navy); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

.tab { display: none; }
.tab.active { display: block; }

/* ---------------------------------------------------------------- account rows */
.acct-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 13px 18px; border-bottom: 1px solid var(--hairline);
}
.acct-row:last-child { border-bottom: 0; }
.acct-name { color: var(--link); font-weight: 600; }
.acct-asof { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.acct-bal { font-weight: 600; font-variant-numeric: tabular-nums; }
.acct-paydown { color: var(--muted); font-size: 12.5px; text-align: right; }
.totals { padding: 12px 18px; border-top: 2px solid var(--hairline); background: #fafbfc; }
.totals .trow {
  display: flex; justify-content: flex-end; gap: 14px; font-size: 14px; padding: 2px 0;
}
.totals .trow .tval { min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.totals .trow.grand { font-weight: 700; }
.totals .trow.trow-muted { color: var(--muted); font-size: 12.5px; }
.totals .trow .tlbl { color: var(--muted); }
.totals .trow.grand .tlbl { color: var(--ink); }

/* ---------------------------------------------------------------- tables */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 12.5px; text-transform: none; color: var(--muted);
  font-weight: 600; padding: 10px 18px; border-bottom: 1px solid var(--hairline);
}
table.data td { padding: 11px 18px; border-bottom: 1px solid var(--hairline); }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.desc { color: var(--link); font-weight: 600; }
.neg { color: var(--red); }
.pos { color: var(--ink); }

.empty { padding: 22px 18px; color: var(--muted); }

/* chips */
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px;
  font-weight: 600; white-space: nowrap;
}
.chip-fit { background: var(--green-soft); color: var(--green); }
.chip-short { background: var(--red-soft); color: var(--red); }
.chip-gray { background: #eef1f4; color: var(--muted); }

/* ---------------------------------------------------------------- forms */
.grid-form {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; align-items: end;
}
.grid-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.grid-form input, .grid-form select, .stat-cushion input {
  font: inherit; font-size: 14.5px; color: var(--ink);
  padding: 8px 10px; border: 1px solid #c3ccd4; border-radius: 4px; background: #fff;
}
.grid-form input:focus, .grid-form select:focus { outline: 2px solid var(--link); outline-offset: 0; }
.grid-form .check { flex-direction: row; align-items: center; gap: 8px; padding-bottom: 10px; }
.grid-form .check[hidden] { display: none; }  /* [hidden] must beat display:flex */
.btn {
  font: inherit; font-weight: 600; color: #fff; background: var(--link);
  border: 0; border-radius: 4px; padding: 10px 22px; cursor: pointer;
}
.btn:hover { background: #14497f; }
.btn-small { padding: 7px 14px; font-size: 13.5px; margin: 8px 0; }
.btn-ghost { background: #fff; color: var(--link); border: 1px solid #c3ccd4; }
.btn-ghost:hover { background: #eef1f4; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #8f1e18; }
.btn-danger-ghost { background: #fff; color: var(--red); border: 1px solid #d9b2af; }
.btn-danger-ghost:hover { background: var(--red-soft); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.modal-check { display: flex; gap: 8px; align-items: center; margin: 14px 0; }
.mini-btn {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--link);
  background: #fff; border: 1px solid #c3ccd4; border-radius: 4px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.mini-btn:hover { background: #eef1f4; }
tr.editing td { background: #fff8e6; }
.linkish {
  background: none; border: 0; color: var(--link); font: inherit; font-size: 13.5px;
  cursor: pointer; padding: 8px 0 0; text-decoration: underline;
}
.muted-note { color: var(--muted); font-size: 13px; margin-top: 10px; }
.icon-btn {
  background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 15px;
  padding: 2px 6px; border-radius: 3px;
}
.icon-btn:hover { background: #eef1f4; color: var(--red); }
select, input[type="date"] { font-family: inherit; }
#txn-account-filter { margin: 8px 0; font: inherit; padding: 7px 9px; border: 1px solid #c3ccd4; border-radius: 4px; }

/* ---------------------------------------------------------------- chart */
.chart-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid #c3ccd4; border-radius: 4px; overflow: hidden; }
.seg button {
  background: #fff; border: 0; border-right: 1px solid #c3ccd4; font: inherit;
  font-size: 13.5px; padding: 6px 14px; cursor: pointer; color: var(--muted);
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--navy); color: #fff; font-weight: 600; }

.stats-row { display: flex; gap: 34px; flex-wrap: wrap; margin: 16px 0 6px; }
.stat-lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 26px; font-weight: 700; margin-top: 2px; }
.stat-val.warn { color: var(--red); }
.stat-sub { font-size: 12.5px; color: var(--muted); }
.stat-cushion { margin-left: auto; display: flex; flex-direction: column; gap: 5px; }
.stat-cushion input { width: 110px; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.lg-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: #fff; border: 1px solid #c3ccd4; border-radius: 999px;
  font: inherit; font-size: 13px; color: var(--ink); padding: 5px 12px; cursor: pointer;
}
.lg-chip:hover { background: #f2f5f8; }
.lg-chip .lg-swatch {
  width: 14px; height: 4px; border-radius: 2px; background: #c3ccd4;
  border: 1px solid transparent;
}
.lg-chip.off { color: var(--muted); border-style: dashed; }
.lg-chip.off .lg-swatch { background: transparent; }
.lg-total {
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px;
  color: var(--muted); padding: 5px 2px;
}
.chart-wrap { position: relative; margin-top: 6px; }
.chart-wrap:focus { outline: 2px solid var(--link); outline-offset: 2px; }
#chart { width: 100%; height: 300px; display: block; }

.tooltip {
  position: absolute; pointer-events: none; background: #fff;
  border: 1px solid var(--hairline); border-radius: 4px; padding: 9px 12px;
  box-shadow: 0 2px 10px rgba(31, 41, 51, .14); font-size: 13px; min-width: 170px;
  max-width: 260px; z-index: 5;
}
.tooltip .tt-date { color: var(--muted); font-size: 12px; }
.tooltip .tt-bal { font-size: 17px; font-weight: 700; margin: 1px 0 3px; }
.tooltip .tt-ev { display: flex; justify-content: space-between; gap: 12px; padding: 1px 0; }
.tooltip .tt-ev .n { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-flex; align-items: center; }
.tooltip .tt-ev .v { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.tooltip .tt-key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 6px; flex: none; }

#chart-table table { margin-top: 10px; }

/* ---------------------------------------------------------------- modal + toast */
.modal {
  position: fixed; inset: 0; background: rgba(22, 48, 78, .55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 6px; padding: 28px; width: min(420px, 90vw);
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box input { font: inherit; padding: 9px 11px; border: 1px solid #c3ccd4; border-radius: 4px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 4px;
  font-size: 14px; z-index: 60; box-shadow: 0 3px 12px rgba(0,0,0,.25);
}

.footer { color: var(--muted); font-size: 12.5px; padding: 10px 0 40px; }
.footer a { color: var(--link); }

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 0; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .nav-link { padding: 12px 10px; }
  .stats-row { gap: 20px; }
}
