:root {
  --bg: #f5f6fa; --card: #fff; --ink: #1c2330; --muted: #667085; --line: #d9dee6;
  --accent: #1f4e9f; --accent-dark: #163a78; --tint: #e8eef8; --accent-ink: #fff; --danger: #b42318;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* login */
.login-wrap { background: linear-gradient(180deg, var(--accent) 0 220px, var(--bg) 220px); min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: 100%; max-width: 360px; }
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card { box-shadow: 0 10px 30px rgba(22, 58, 120, .12); }
.card h1.logo { margin: 0 0 14px; text-align: center; }
.card h1.logo img { width: 210px; height: auto; display: inline-block; }
.card button:hover:not(:disabled) { background: var(--accent-dark); }
.card p.sub { margin: 0 0 20px; color: var(--muted); }
.card label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13px; }
.card input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; }
.card button { margin-top: 18px; width: 100%; padding: 10px; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.card button:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); min-height: 1.3em; margin-top: 12px; font-size: 14px; }

/* app shell */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 3px solid var(--accent); }
.brand { display: inline-flex; align-items: center; margin-right: 8px; }
.brand img { height: 40px; width: auto; display: block; }
.switcher { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.switcher button { border: 0; background: none; padding: 6px 14px; color: var(--ink); }
.switcher button + button { border-left: 1px solid var(--line); }
.switcher button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.topbar input[type="month"] { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.spacer { flex: 1; }
.topbar a, .linkbtn { color: var(--accent); text-decoration: none; background: none; border: 0; padding: 0; }
.topbar a:hover, .linkbtn:hover { text-decoration: underline; }
.who { color: var(--muted); font-size: 13px; }
main { padding: 20px; }

/* settings */
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.tabs button { border: 0; background: none; padding: 10px 14px; border-bottom: 3px solid transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.settings h2 { margin: 0 0 12px; font-size: 18px; }
.settings h3 { margin: 20px 0 8px; font-size: 15px; }
.settings table { border-collapse: collapse; width: 100%; background: var(--card); }
.settings th, .settings td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.settings input, .settings select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.settings a.btn { text-decoration: none; color: var(--ink); display: inline-block; }
.settings button.btn, .settings a.btn { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.settings button.primary, .settings a.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.settings button.danger { color: var(--danger); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 10px 0; }
.row label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
.notice { padding: 8px 12px; border-radius: 6px; margin: 0 0 12px; background: var(--tint); }
.notice.err { background: #fde8e6; color: var(--danger); }
.muted { color: var(--muted); }
.mapcols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.diff { background: #fff4d6; }
code.uri { background: #eef1f5; padding: 2px 6px; border-radius: 4px; user-select: all; }
.pick { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: var(--card); min-width: 260px; }
.pick label { display: block; font-weight: 400; }
@media (max-width: 800px) { .mapcols { grid-template-columns: 1fr; } }

/* reports */
.strip { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.strip h2 { margin: 0; font-size: 18px; color: var(--accent-dark); }
.btn { padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); text-decoration: none; display: inline-block; }
.btn:disabled { opacity: .6; cursor: default; }
.banner { padding: 10px 14px; border-radius: 6px; margin: 0 0 12px; }
.banner.stale { background: #fff4d6; border: 1px solid #f0d58a; }
.banner.warn { background: #fde8e6; border: 1px solid #f3b8b2; color: var(--danger); }
.banner ul { margin: 6px 0 0; padding-left: 20px; }
.report-tabs { padding: 0; margin-bottom: 12px; border: 0; border-bottom: 1px solid var(--line); background: none; flex-wrap: wrap; }
.tablewrap { overflow-x: auto; }
/* report tables: a card with a blue header, quiet line rows, tinted subtotals and a strong net line */
.tablewrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 1px 3px rgba(22, 58, 120, .06), 0 6px 18px rgba(22, 58, 120, .05); }
table.report { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--card); font-size: 14.5px; }
table.report th, table.report td { padding: 8px 14px; border-bottom: 1px solid #eef0f5; text-align: left; font-weight: 400; }
table.report .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.report thead th { font-weight: 600; background: var(--accent); color: #fff; border-bottom: 0; }
table.report thead tr:first-child th:first-child { border-top-left-radius: 9px; }
table.report thead tr:first-child th:last-child { border-top-right-radius: 9px; }
table.report thead .span { text-align: center; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; padding-bottom: 4px; }
table.report thead tr.colhead th { background: var(--tint); color: var(--accent-dark); font-size: 12.5px; letter-spacing: .03em; text-transform: uppercase; border-bottom: 2px solid var(--accent); }
table.report thead tr.colhead:first-child th { background: var(--accent); color: #fff; border-bottom: 0; }
table.report .gstart { border-left: 1px solid #dfe3ee; }
table.report thead .gstart { border-left-color: rgba(255, 255, 255, .25); }
table.report thead tr.colhead .gstart { border-left-color: #cad7ec; }
table.report tbody tr:not(.grouphead):hover th, table.report tbody tr:not(.grouphead):hover td { background: #f4f7fc; }
table.report tbody th[scope="row"] { padding-left: 22px; }
table.report td.zero { color: #b3bac6; }
table.report tr.grouphead th { background: var(--tint); color: var(--accent-dark); font-weight: 700; font-size: 12.5px; letter-spacing: .05em; text-transform: uppercase; padding-top: 12px; }
table.report tr.subtotal th, table.report tr.subtotal td { font-weight: 700; background: #f3f6fc; border-top: 1px solid #c6d3ea; border-bottom: 1px solid #c6d3ea; }
table.report tr.subtotal th[scope="row"] { padding-left: 14px; color: var(--accent-dark); }
table.report tr.grand th, table.report tr.grand td { background: var(--tint); font-size: 15.5px; border-top: 2px solid var(--accent); border-bottom: 3px double var(--accent); }
table.report tr.grand td.zero { color: #9aa3b5; }
table.report tbody tr:last-child th:first-child { border-bottom-left-radius: 9px; }
table.report tbody tr:last-child td:last-child { border-bottom-right-radius: 9px; }
table.report td.fav { color: #067647; font-weight: 600; }
table.report td.unfav { color: var(--danger); font-weight: 600; }
table.report tr.detail th, table.report tr.detail td { font-size: 13px; color: var(--muted); padding-top: 4px; padding-bottom: 4px; background: #fbfbfd; }
table.report tbody tr.detail th { padding-left: 76px; }
table.report .toggle { width: 22px; height: 22px; margin-right: 8px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--card); color: var(--ink); font: inherit; line-height: 1; cursor: pointer; }
table.report .toggle-space { display: inline-block; width: 22px; margin-right: 8px; }
.detail-controls { display: flex; gap: 8px; margin-bottom: 8px; }
/* monthly view: up to 13 figure columns; the wrapper scrolls sideways and the label column is sticky */
.view-switch { margin: 0 0 10px; }
table.report.monthly th, table.report.monthly td { padding-left: 8px; padding-right: 8px; }
table.report.monthly { border-left: 0; } /* nothing may show left of the sticky labels */
table.report.monthly tbody th, table.report.monthly thead th:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--card); white-space: nowrap; box-shadow: 1px 0 0 var(--line);
}
table.report.monthly thead th:first-child { background: var(--accent); }
table.report.monthly tr.grouphead th { background: var(--tint); }
table.report.monthly tr.subtotal th { background: #f3f6fc; }
table.report.monthly tr.grand th { background: var(--tint); }
table.report.monthly tr.detail th { background: #fbfbfd; }
@media (max-width: 700px) {
  table.report.monthly tbody th { white-space: normal; min-width: 130px; max-width: 45vw; }
  table.report.monthly tr.detail th[scope="row"] { padding-left: 24px; }
}
.btn.small { padding: 4px 10px; font-size: 13px; }
.fav { color: #067647; }
.unfav { color: var(--danger); }
.mismatch { color: var(--danger); font-weight: 600; margin: 0 0 8px; }
.switcher.small button { padding: 4px 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile { border-top: 3px solid var(--accent); }
.tile-value { font-size: 20px; font-weight: 600; margin-top: 4px; color: var(--accent-dark); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.chartbox { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; height: 280px; display: flex; flex-direction: column; }
.chartbox figcaption { font-weight: 600; margin-bottom: 8px; }
.chartbox canvas { flex: 1; min-height: 0; }
.card p.hint { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card p a { color: var(--accent); }
/* user form: each access checkbox sits on one row with its label */
.row .grants { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding-bottom: 6px; }
.row .grants-title { font-size: 13px; font-weight: 600; width: 100%; }
.row label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; font-size: 14px; white-space: nowrap; }
.row label.inline input { margin: 0; }
.notice p { margin: 0 0 6px; }
.linkrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.settings input.link { flex: 1; min-width: 260px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.small { font-size: 12px; }
table.audit td { font-size: 13px; }
.settings .row > strong { min-width: 300px; align-self: center; }
