:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5f6b7a;
  --line: #e2e7ee;
  /* Credence Firm logo: navy #042641 and green #25E506 */
  --navy: #042641;
  --accent: #25e506;
  --brand: #0b3a63;
  --brand-ink: #ffffff;
  --brand-soft: #e6eef6;
  --in: #137a4b;
  --in-soft: #e6f5ee;
  --out: #b4372f;
  --out-soft: #fbeceb;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --card: #171e26; --ink: #e6ebf1; --muted: #9aa6b4; --line: #26303b;
    --brand: #5b9bd5; --brand-ink: #0f141a; --brand-soft: #1b2a3a;
    --in: #4cc38a; --in-soft: #13281f; --out: #f07b72; --out-soft: #2e1817;
    --warn: #f2c36b; --warn-soft: #2d2412; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--in); }
.out { color: var(--out); }

/* Top bar: always the logo's navy, in light and dark mode */
.topbar { background: var(--navy); color: #fff; border-bottom: 3px solid var(--accent); }
.topbar .wrap { display: flex; align-items: center; gap: 16px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; opacity: .9; }
.topbar a:hover { opacity: 1; text-decoration: underline; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; margin-right: auto; opacity: 1 !important; }
.brand img { width: 32px; height: 32px; border-radius: 7px; }
.brand .by { font-weight: 400; font-size: .75rem; opacity: .75; }
.topbar .linkbtn { color: #fff; }
.topbar .clientpick select { color: #fff; }
.topbar form { margin: 0; }
.navname { opacity: .9; }
.linkbtn { background: none; border: 0; color: var(--brand-ink); font: inherit; cursor: pointer; padding: 0; opacity: .9; }
.clientpick select {
  min-height: 34px; padding: 4px 8px; width: auto; max-width: 220px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .45); background: rgba(255, 255, 255, .12); color: var(--brand-ink); font: inherit; font-weight: 600;
}
.clientpick select option, .clientpick select optgroup { color: #1b2430; background: #fff; }
.clientpick select optgroup { font-weight: 700; font-style: normal; color: #5f6b7a; }
.clientpick select option { font-weight: 400; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1180px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
main.wrap { padding-top: 20px; padding-bottom: 80px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.pagehead > div { min-width: 0; overflow-wrap: anywhere; }
.pagehead { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 40px;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.go { background: var(--in); border-color: var(--in); color: #fff; }
.btn.danger { color: var(--out); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=url], select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font: inherit; min-height: 40px;
}
textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font: .9rem/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 20px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 260px; width: auto; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* Flash messages */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: var(--in-soft); border-color: var(--in); }
.flash.error { background: var(--out-soft); border-color: var(--out); }
.warn { background: var(--warn-soft); color: var(--ink); border: 1px solid var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }

/* Upload */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--brand); background: var(--brand-soft); }
.drop input { display: none; }
.drop strong { display: block; font-size: 1.05rem; }
details summary { cursor: pointer; color: var(--brand); margin-top: 12px; }

/* Tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--card); position: sticky; top: 0; }
tbody tr:hover { background: var(--brand-soft); }
td.desc { min-width: 260px; }
tr.sent { opacity: .6; }
tr.excluded td:not(:first-child) { opacity: .45; text-decoration: line-through; }
tfoot td { font-weight: 700; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill.ready { background: var(--in-soft); color: var(--in); }
.pill.failed { background: var(--out-soft); color: var(--out); }
.pill.queued, .pill.processing { background: var(--warn-soft); color: var(--warn); }
.pill.sent { background: var(--brand-soft); color: var(--brand); }

/* Tabs above the transactions table */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
/* Statement navigation: views on the left, review pages on the right */
.stmtnav { display: flex; gap: 6px 16px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.stmtnav .tabs { margin-bottom: 0; }
.stmtnav a.review-in { border-color: var(--in); color: var(--in); }
.stmtnav a.review-out { border-color: var(--out); color: var(--out); }
.stmtnav a.review-in.on { background: var(--in); color: #fff; }
.stmtnav a.review-out.on { background: var(--out); color: #fff; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { color: var(--muted); font-size: .82rem; }
.tile .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: .82rem; }

.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Review page */
/* Review tables stay a table at every width; narrow screens scroll sideways. */
.reviewtable { min-width: 980px; }
.reviewtable th, .reviewtable td { padding: 7px 8px; vertical-align: middle; }
.reviewtable tbody tr:nth-child(even) { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.reviewtable td input[type=text] { min-height: 34px; padding: 6px 8px; }
.reviewtable td:nth-child(4) input { min-width: 190px; }
.reviewtable td:nth-child(5) input { min-width: 200px; }
.reviewtable td:nth-child(6) input { min-width: 130px; }
.reviewtable td.desc { min-width: 220px; max-width: 300px; font-size: .8rem; }
.actionbar {
  position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  margin: 0 -18px -18px; border-radius: 0 0 var(--radius) var(--radius);
}
.total-big { font-size: 1.15rem; font-weight: 700; }

/* Ask page */
.switchrow { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 4px 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.switchrow input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
textarea.asktext { font: inherit; font-size: 1rem; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: .82rem; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.spinner.inline { display: inline-block; width: 14px; height: 14px; border-width: 2px; margin: 0 4px -2px 0; }
.answer .a { white-space: pre-line; margin-top: 10px; font-size: 1.02rem; }
.answertable { margin-top: 12px; max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.answertable th, .answertable td { padding: 6px 9px; font-size: .88rem; }
pre.sql { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: .8rem; }

/* Analysis */
.periodform { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 12px 16px; }
.periodform label { margin-top: 0; font-size: .85rem; }
.periodform input { width: auto; min-width: 150px; }
.periodform input[type=checkbox] { min-width: 0; }
input[type=date] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; min-height: 40px; }
.pill.sev-high { background: var(--out-soft); color: var(--out); }
.pill.sev-medium { background: var(--warn-soft); color: var(--warn); }
.pill.sev-low { background: var(--brand-soft); color: var(--brand); }
.pill.sev-info { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.warnc { color: var(--warn); }
.chip.static { cursor: default; }
ul.issues { list-style: none; padding: 0; margin: 12px 0; }
ul.issues li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.audittable { min-width: 1000px; }
.audittable td { vertical-align: top; }
.audittable td.why { min-width: 280px; max-width: 420px; font-size: .88rem; }
.audittable select { min-width: 140px; min-height: 34px; padding: 4px 6px; }
.audittable input[type=text] { min-width: 200px; min-height: 34px; padding: 6px 8px; }
select.st-ok, select.st-resolved { border-color: var(--in); color: var(--in); }
select.st-query { border-color: var(--out); color: var(--out); }
.bar { position: relative; height: 10px; background: var(--bg); border-radius: 5px; margin-top: 4px; }
.bar .act { position: absolute; left: 0; top: 0; bottom: 0; background: var(--in); border-radius: 5px; opacity: .8; }
.bar .act.outbar { background: var(--out); }
.bar .exp { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
.benford td { padding: 6px 10px; }
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; }
.catrow .bar { grid-column: 1 / -1; }
.grid2.gap { gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
h3.acct { font-size: 1rem; margin: 16px 0 8px; }
.small-tiles .v { font-size: 1.1rem; }

/* Expenses / income by head */
details.head { border-bottom: 1px solid var(--line); }
details.head summary {
  display: grid; grid-template-columns: minmax(0, 1fr) 50px 140px 56px 22%; gap: 10px; align-items: center;
  padding: 10px 4px; cursor: pointer; color: var(--ink); margin: 0; list-style: none;
}
details.head summary::-webkit-details-marker { display: none; }
details.head summary .hname::before { content: "▸"; display: inline-block; width: 16px; color: var(--muted); transition: transform .15s; }
details.head[open] summary .hname::before { transform: rotate(90deg); }
details.head summary:hover { background: var(--brand-soft); }
details.head summary .bar { margin-top: 0; }
details.head.uncl summary .hname { color: var(--muted); }
details.head > .tablewrap { margin: 0 0 12px 16px; max-height: 420px; overflow: auto; }
.headtotal { display: flex; justify-content: space-between; padding: 12px 4px 0; font-size: 1.05rem; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: .85rem; }
table.matrix td, table.matrix th { white-space: nowrap; font-size: .85rem; padding: 6px 8px; }
@media (max-width: 760px) {
  details.head summary { grid-template-columns: minmax(0, 1fr) 110px; }
  details.head summary > :nth-child(2), details.head summary > :nth-child(4) { display: none; }
  details.head summary .bar { grid-column: 1 / -1; }
}

/* Data tables */
.datatable { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.datatable th, .datatable td { white-space: nowrap; font-size: .86rem; padding: 6px 9px; }
.datatable thead th { z-index: 1; }
.datatable tfoot td { position: sticky; bottom: 0; background: var(--card); border-top: 2px solid var(--line); }
a.sorthead { color: inherit; text-decoration: none; }
a.sorthead:hover { color: var(--brand); }
.rolechip { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-size: .68rem; text-transform: none; letter-spacing: 0; }
.tableinfo { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; justify-content: space-between; }
label.inlinecheck { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 0 0 10px; }

/* Documents & notes */
.thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.msg { max-width: 80%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; background: var(--brand-soft); border-color: transparent; }
.msg.firm { align-self: flex-start; background: var(--card); }
.msg .who { font-size: .8rem; font-weight: 600; margin-bottom: 4px; }
.msg .body { white-space: pre-line; overflow-wrap: anywhere; }
input[type=month] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; min-height: 40px; width: 100%; }
.docshortcut { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.navcount { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 3px; border-radius: 9px; background: #e5484d; color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 18px; }
@media (max-width: 760px) { .msg { max-width: 95%; } }

/* Admin's client picker, under the top bar */
.clientbar { background: var(--card); border-bottom: 1px solid var(--line); }
.clientbar form { display: flex; gap: 8px; align-items: center; margin: 0; padding: 6px 0; }
.clientbar label { margin: 0; font-size: .85rem; color: var(--muted); }
.clientbar select { width: auto; min-height: 32px; padding: 3px 8px; font-weight: 600; }

/* Admin viewing someone's workspace */
.viewbar { background: var(--warn-soft); border-bottom: 2px solid var(--warn); }
.viewbar .wrap { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.viewbar form { margin: 0; }

/* Log in / sign up: the introduction beside the form */
.authlayout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 440px); gap: 36px; align-items: start; max-width: 1000px; margin: 28px auto; }
.authlayout .authcard { margin: 0; width: 100%; }
.about { padding-top: 6px; }
.aboutlogo { width: 72px; height: 72px; border-radius: 16px; box-shadow: var(--shadow); }
.about .tagline { font-size: 1.9rem; line-height: 1.2; margin: 16px 0 10px; }
.about .lead { font-size: 1.05rem; color: var(--ink); margin: 0 0 18px; }
.personas { display: grid; gap: 12px; margin-bottom: 14px; }
.personas > div { border-left: 4px solid var(--accent); background: var(--card); border-radius: 0 8px 8px 0; padding: 10px 14px; }
.personas p { margin: 4px 0 0; color: var(--muted); font-size: .93rem; }
@media (max-width: 860px) {
  .authlayout { grid-template-columns: 1fr; gap: 18px; margin-top: 12px; }
  .authlayout .about { order: 2; }
  .about .tagline { font-size: 1.5rem; }
}

/* Log in / sign up */
.authcard { max-width: 440px; margin: 40px auto; }
.authlinks { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 16px 0 0; }
textarea.plain { font: inherit; }
.accessmsg { white-space: pre-line; background: var(--brand-soft); border-radius: 8px; padding: 14px 16px; margin-top: 12px; }
.grantform { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.grantform select, .grantform input { width: auto; min-height: 34px; padding: 4px 8px; }
.grantform input[type=date] { min-height: 34px; padding: 4px 8px; }
.grantform input[name=note] { width: 150px; }
fieldset.usertype { border: 0; padding: 0; margin: 8px 0 4px; }
fieldset.usertype legend { font-weight: 600; margin-bottom: 6px; }
label.typechoice { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 0 0 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
label.typechoice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
label.typechoice input { margin-top: 4px; flex: none; }
.d-block { display: block; margin-top: 2px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
input[type=email] { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; min-height: 40px; }

/* Statement list */
.stmt { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.stmt:last-child { border-bottom: 0; }
.stmt .name { font-weight: 600; word-break: break-word; }
.stmt .figs { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; }

/* Phones: review table becomes cards */
@media (max-width: 760px) {
  h1 { font-size: 1.25rem; }
  .card { padding: 14px; }
  .actionbar { margin: 0 -14px -14px; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; padding: 8px 10px; }
  table.cards td { border: 0; padding: 4px 0; }
  table.cards td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; }
  table.cards td.num { text-align: left; }
  .stmt { grid-template-columns: 1fr; }
}
