/* NPO Ledger styles. Plain CSS, no framework.

   Colour means something everywhere:
     blue  (default button)   the main action on the page
     green (.success)         makes something final: approve, post, close, lock
     red   (.danger)          void, cancel, delete, reject
     white (.secondary)       everything else
   Buttons in forms whose action approves/posts/closes/locks (or voids/cancels/rejects) get those colours
   automatically (see "Button colours by action" below), so templates don't have to repeat them. */

:root {
  --ink: #1b2431;
  --muted: #667085;
  --line: #dde2ea;
  --paper: #ffffff;
  --shade: #f4f6f9;
  --brand: #1d4f91;
  --brand-dark: #163d70;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --good: #087443;
  --good-soft: #e7f6ee;
  --warn: #b54708;
  --warn-soft: #fff6e5;
  --bad: #c0261b;
  --bad-soft: #fdeceb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--shade); }
main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
h1 { font-size: 1.6rem; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 26px 0 10px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
.card h2:first-child, section.card h2 { margin-top: 0; }
a { color: var(--accent); }
a:hover { color: var(--brand-dark); }
.muted { color: var(--muted); }
.center { text-align: center; }
.inline { display: inline; }
.ok { color: var(--good); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }

/* ---------------------------------------------------------------- top bar and menu */
.topbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 0 20px; min-height: 56px;
  background: var(--brand); color: #fff; box-shadow: var(--shadow); position: relative; z-index: 20; }
/* Pinned to the top only on wide screens, where the menu fits on one line. */
@media (min-width: 1100px) { .topbar { position: sticky; top: 0; } }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { color: #fff; }
.mainnav { display: flex; align-items: center; gap: 2px; flex: 1; flex-wrap: wrap; }
.mainnav > a, .menu-title { color: #e8eefb; text-decoration: none; padding: 8px 11px; border-radius: 6px; font-size: 0.95rem;
  background: none; border: none; cursor: pointer; font: inherit; }
.mainnav > a:hover, .menu:hover .menu-title, .menu:focus-within .menu-title { background: rgba(255, 255, 255, 0.12); color: #fff; }
.mainnav > a.active, .menu.active .menu-title { background: rgba(255, 255, 255, 0.2); color: #fff; font-weight: 600; }
.mainnav > a.cta { background: #fff; color: var(--brand); font-weight: 600; margin-right: 6px; }
.mainnav > a.cta:hover { background: var(--accent-soft); color: var(--brand-dark); }
.menu { position: relative; }
.menu-title::after { content: " ▾"; font-size: 0.75em; opacity: 0.8; }
.menu-items { display: none; position: absolute; top: 100%; left: 0; min-width: 210px; padding: 6px; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16); z-index: 30; }
.menu:hover .menu-items, .menu:focus-within .menu-items { display: block; }
.menu-items a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.menu-items a:hover, .menu-items a.active { background: var(--accent-soft); color: var(--brand-dark); }
.usermenu { display: flex; align-items: center; gap: 10px; color: #dbe5f7; font-size: 0.92rem; }
.usermenu a { color: #fff; }
.role-tag { background: rgba(255, 255, 255, 0.16); padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; }
button.link { background: none; border: none; color: #fff; text-decoration: underline; padding: 0; cursor: pointer; font: inherit; }

/* ---------------------------------------------------------------- page layout */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
details.card > summary { cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 18px; }
.actions form, .actions .card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.filters { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label { margin: 0; font-weight: 400; font-size: 0.9em; }

/* ---------------------------------------------------------------- forms and buttons */
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd4df; border-radius: 6px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; margin: 10px 0 3px; font-weight: 600; font-size: 0.93rem; }
button, .button { font: inherit; font-weight: 600; padding: 7px 15px; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3; }
button:hover, .button:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary, .button.secondary { background: #fff; color: var(--ink); border-color: #c4ccd8; }
button.secondary:hover, .button.secondary:hover { background: var(--shade); color: var(--ink); border-color: #aab4c3; }
button.success, .button.success { background: var(--good); border-color: var(--good); color: #fff; }
button.success:hover, .button.success:hover { background: #05603a; border-color: #05603a; }
button.danger, .button.danger { background: #fff; color: var(--bad); border-color: #f1aaa4; }
button.danger:hover, .button.danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

/* Button colours by action: approve / post / close / lock = green; void / cancel / reject = red. */
form[action$="/post"] button:not(.secondary):not(.danger),
form[action$="/approve"] button:not(.secondary):not(.danger),
form[action$="/approve-post"] button:not(.secondary):not(.danger),
form[action$="/close"] button:not(.secondary):not(.danger),
form[action$="/lock"] button:not(.secondary):not(.danger),
form[action$="/confirm"] button:not(.secondary):not(.danger),
form[action$="/review"] button { background: var(--good); border-color: var(--good); color: #fff; }
form[action$="/void"] button, form[action$="/cancel"] button, form[action$="/reject"] button {
  background: #fff; color: var(--bad); border-color: #f1aaa4; }
form[action$="/void"] button:hover, form[action$="/cancel"] button:hover, form[action$="/reject"] button:hover {
  background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---------------------------------------------------------------- messages and badges */
.flash { padding: 11px 15px; background: var(--good-soft); border: 1px solid #a6e1c0; border-left: 4px solid var(--good); border-radius: 6px; margin-bottom: 16px; }
.error { padding: 11px 15px; background: var(--bad-soft); border: 1px solid #f6c4bf; border-left: 4px solid var(--bad); color: #8f1d14; border-radius: 6px; margin-bottom: 16px; }
.error ul { margin: 6px 0 0; }
.status { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.82em; font-weight: 600; background: var(--shade); border: 1px solid var(--line); color: #344054; white-space: nowrap; }
.status-good, .status-posted { background: var(--good-soft); border-color: #a6e1c0; color: var(--good); }
.status-wait, .status-draft { background: var(--warn-soft); border-color: #fedf89; color: var(--warn); }
.status-bad, .status-void { background: var(--bad-soft); border-color: #f6c4bf; color: var(--bad); }
.status-void { text-decoration: line-through; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; background: var(--paper); }
.table-wrap > table, main > table { border: 1px solid var(--line); border-radius: var(--radius); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f0f3f8; font-weight: 600; font-size: 0.88rem; color: #344054; }
tbody tr:hover td { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); background: #f8fafc; }
tr.subtotal td { font-weight: 600; }
tr.muted td { color: var(--muted); }
.lines input.amount { width: 110px; text-align: right; }
.lines select { width: 100%; min-width: 120px; }

/* ---------------------------------------------------------------- choices (Money in / out) */
.choices { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.choice { flex: 1 1 220px; display: block; background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; font-weight: 400; margin: 0; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-right: 8px; }
.inline-choice { display: block; font-weight: 400; margin: 4px 0; }

/* ---------------------------------------------------------------- summary boxes */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 14px 0 20px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); color: var(--ink); text-decoration: none; }
.stat strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.stat-good { border-top-color: var(--good); }
.stat-bad { border-top-color: var(--bad); }
.stat-link:hover { border-color: var(--accent); color: var(--ink); }

/* ---------------------------------------------------------------- dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.todo { list-style: none; margin: 0; padding: 0; }
.todo li a { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.todo li a:hover { background: var(--accent-soft); }
.todo-count { min-width: 32px; text-align: center; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-weight: 700; }

/* Charts: plain HTML bars; the server gives each bar its size as a percentage. */
.hbar { display: grid; grid-template-columns: minmax(110px, 30%) 1fr auto; gap: 10px; align-items: center; margin: 8px 0; }
.hbar-label { font-size: 0.92rem; }
.hbar-track { background: #edf1f7; border-radius: 999px; height: 12px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.hbar-fill.hbar-2 { background: #7a5af8; }
.hbar-fill.hbar-3 { background: #ee8b3a; }
.hbar-value { font-variant-numeric: tabular-nums; font-size: 0.92rem; white-space: nowrap; }
.vchart { display: flex; align-items: flex-end; gap: 6px; height: 220px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.vchart-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.vchart-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.vbar { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 1px; }
.vbar-income, .key-income { background: var(--good); }
.vbar-spending, .key-spending { background: #ee8b3a; }
.vchart-label { font-size: 0.78rem; color: var(--muted); padding-top: 4px; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; color: var(--muted); margin-bottom: 6px; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }

/* ---------------------------------------------------------------- small screens and printing */
@media (max-width: 700px) {
  .topbar { padding: 8px 12px; }
  .menu-items { position: static; box-shadow: none; }
  .hbar { grid-template-columns: 1fr auto; }
  .hbar-track { grid-column: 1 / -1; }
}
@media print {
  .topbar, .filters, .no-print, form, details, .page-actions { display: none !important; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; }
}
