:root {
  --navy: #17365D; --blue: #1F5FA8; --blue-dark: #163F70; --ink: #1B2735; --muted: #556375; --sub: #3E4C5E;
  --line: #D9E2EC; --line-soft: #E6ECF2; --field: #B8C7D8; --bg: #F3F6FA; --card: #FFFFFF;
  --red: #C00000; --red-dark: #9B2A1E; --red-line: #E2B4B0; --red-bg: #FDECEA; --amber: #8A4B0F;
  --head: #E4ECF5; --sect: #EEF3F9; --total: #F5F8FB;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; }
input, select, textarea, button { font: inherit; color: inherit; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.25; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

header.top { background: var(--navy); color: #fff; padding: 12px 16px; }
.wrap { max-width: 1240px; margin: 0 auto; }
header.top .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
header.top h1 { margin: 0; font-size: 21px; font-weight: 700; }
header.top .sub { font-size: 13px; color: #C9D8EA; }
.year-pick { min-height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid #8FB0D6; background: var(--blue-dark); color: #fff; font-weight: 700; font-size: 17px; }

nav.tabs { position: sticky; top: 0; z-index: 30; background: var(--head); border-bottom: 1px solid #C9D6E5; }
nav.tabs .wrap { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; scrollbar-width: thin; }
nav.tabs a { flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 8px; font-weight: 600;
  text-decoration: none; white-space: nowrap; background: #fff; color: var(--navy); border: 1px solid #B9CEE1; }
nav.tabs a[aria-current="page"] { background: var(--blue); color: #fff; border-color: var(--blue); }

main { max-width: 1240px; margin: 0 auto; padding: 18px 14px 80px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; font-size: 18px; }
.card h3 { margin: 0; font-size: 16px; }
.muted { font-size: 13px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero { background: var(--navy); color: #fff; border-radius: 14px; padding: 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.hero .label { font-size: 14px; color: #C9D8EA; }
.hero .big { font-size: 30px; font-weight: 700; }
.neg { color: var(--red); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid #B9CEE1; background: #fff; color: var(--blue); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--red-dark); border-color: var(--red-line); }
.btn.danger-solid { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.btn.light { background: #fff; color: var(--navy); border-color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.icon { min-height: 34px; min-width: 34px; padding: 0 8px; font-size: 14px; }
.btn:focus-visible, nav.tabs a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #72A5E1; outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.end { justify-content: flex-end; }
.actions.between { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select { min-height: 44px; padding: 8px 12px; border: 1px solid var(--field); border-radius: 8px; background: #fff; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }

/* Month chips */
.months { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.months a { flex: 0 0 auto; min-width: 54px; min-height: 44px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid #B9CEE1; background: #fff; color: var(--navy); text-decoration: none; font-weight: 600; font-size: 14px; }
.months a .dot { width: 7px; height: 7px; border-radius: 50%; background: #C9D3DE; margin-top: 3px; }
.months a.done .dot { background: #2E8B57; }
.months a[aria-current="page"] { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Spreadsheet-style tables */
.sheet-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; max-height: calc(100vh - 150px); }
table.sheet { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
table.sheet th, table.sheet td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); text-align: right; white-space: nowrap; background: #fff; }
table.sheet th:first-child, table.sheet td:first-child { text-align: left; position: sticky; left: 0; z-index: 1; border-right: 1px solid var(--line); min-width: 170px; }
table.sheet thead th { position: sticky; top: 0; z-index: 2; background: var(--head); color: var(--navy); font-size: 13px; border-bottom: 1px solid #C9D6E5; }
table.sheet thead th:first-child { z-index: 3; }
table.sheet tr.section td { background: var(--sect); font-weight: 700; color: var(--navy); text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
table.sheet tr.subtotal td { background: var(--total); font-weight: 700; border-top: 1px solid var(--line); }
table.sheet tr.total td { background: #E9EFF6; font-weight: 800; border-top: 2px solid #9FB4CC; }
table.sheet tr:hover td { background: #F8FBFE; }
table.sheet tr.section:hover td { background: var(--sect); }
table.sheet td.neg, table.sheet .neg { color: var(--red); }
table.sheet td.edit { padding: 2px 4px; }
.tag { font-size: 11px; font-weight: 700; color: var(--muted); background: #EDF1F6; border-radius: 4px; padding: 1px 5px; margin-left: 4px; vertical-align: 1px; }
.tag.hand { background: #FBF0DC; color: #7A4E0B; }

/* Editable amounts look like cells until touched */
input.amt { width: 118px; text-align: right; border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; background: #F7FAFD; font-variant-numeric: tabular-nums; }
input.amt:hover { border-color: var(--field); }
input.amt:focus { border-color: var(--blue); background: #fff; }
input.amt.neg { color: var(--red); }
input.amt.override { background: #FFF8E6; }
input.amt.saving { opacity: .5; }
input.name { width: 100%; min-width: 150px; border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; background: transparent; font-weight: 500; }
input.name:hover { border-color: var(--field); }
.reset { border: 0; background: none; color: var(--blue); cursor: pointer; font-size: 13px; padding: 2px 4px; }

/* Bottom block under a month / the Master */
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums; }
.kv:last-child { border-bottom: 0; }
.kv strong { font-weight: 700; }
.kv.big strong { font-size: 18px; }

/* Usage bars on Home */
.usage { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr auto; gap: 6px 12px; align-items: center; font-size: 14px; }
.bar { height: 10px; border-radius: 6px; background: #E6ECF2; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--blue); border-radius: 6px; }
.bar.over span { background: var(--red); }

/* Lists */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1 1 220px; min-width: 0; }
.audit-row { font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); overflow-wrap: anywhere; }
.notice { background: #FBF0DC; color: #6B420A; border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.ok-note { background: #E3F3EA; color: #1E6B43; border-radius: 10px; padding: 12px 14px; font-size: 14px; }
details.card > summary { cursor: pointer; font-weight: 700; font-size: 17px; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 32px; }
details.card > summary::after { content: "▸"; color: var(--muted); }
details.card[open] > summary::after { content: "▾"; }

/* Change pop-up */
.chg { display: grid; grid-template-columns: minmax(130px, 1.4fr) repeat(3, minmax(80px, auto)) auto; gap: 6px 12px; align-items: center; font-variant-numeric: tabular-nums; font-size: 14px; }
.chg .h { font-size: 12px; font-weight: 700; color: var(--muted); }
.chg .r { text-align: right; }
.seg { display: inline-flex; border: 1px solid #B9CEE1; border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; color: var(--blue); padding: 6px 10px; font-weight: 600; cursor: pointer; font-size: 13px; min-height: 34px; }
.seg button + button { border-left: 1px solid #B9CEE1; }
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100; background: var(--ink); color: #fff; padding: 12px 18px;
  border-radius: 10px; font-size: 14px; max-width: min(92vw, 520px); box-shadow: 0 6px 24px rgba(0,0,0,.2); white-space: pre-line; }
#toast.error { background: #8A1C12; }
dialog { border: 0; border-radius: 14px; padding: 22px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 16px 60px rgba(0,0,0,.25); }
dialog.wide { width: min(860px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(15,35,58,.55); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { white-space: pre-line; color: var(--sub); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

@media (max-width: 700px) {
  main { padding: 12px 8px 80px; }
  .card { padding: 14px; }
  table.sheet { font-size: 13px; }
  table.sheet th, table.sheet td { padding: 5px 7px; }
  table.sheet th:first-child, table.sheet td:first-child { min-width: 128px; max-width: 150px; white-space: normal; }
  input.amt { width: 100px; font-size: 16px; }   /* 16px stops phones zooming in */
  input.name { font-size: 16px; }
  .chg { grid-template-columns: 1fr auto; }
  .chg .h.opt, .chg .opt { display: none; }
  .stat .value { font-size: 19px; }
}
table.sheet.ny th:first-child, table.sheet.ny td:first-child { min-width: 0; width: 56px; max-width: 56px; text-align: center; }
