:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5d6673;
  --accent: #245bdb;
  --accent-ink: #ffffff;
  --ok: #1f7a4d;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff1d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --info-bg: #e8effc;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #222830;
    --border: #2f3640;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --accent: #6e9bff;
    --accent-ink: #0b1220;
    --ok: #5fd39a;
    --ok-bg: #133325;
    --warn: #f3c46b;
    --warn-bg: #3a2c10;
    --bad: #ff8a80;
    --bad-bg: #3b1714;
    --info-bg: #1c2840;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500;
}
.nav a.active { color: var(--text); background: var(--surface-2); }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; }

/* Controls */
.btn {
  white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 6px;
  cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=email], input[type=date], input[type=number], select, textarea {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 9px; border-radius: 6px; width: 100%;
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.seg { display: inline-flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; background: var(--surface); }
.seg button { white-space: nowrap; border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.seg .count { font-size: 12px; color: var(--muted); margin-left: 4px; }

/* Cards and tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.needs_review { background: var(--warn-bg); color: var(--warn); }
.pill.ready { background: var(--info-bg); color: var(--accent); }
.pill.approved { background: var(--ok-bg); color: var(--ok); }
.pill.rejected { background: var(--bad-bg); color: var(--bad); }
.pill.kind { background: var(--surface-2); color: var(--muted); }
.flagcount { color: var(--warn); font-weight: 600; }

/* Review page */
.review { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(380px, 1fr); gap: 16px; align-items: start; }
.viewer { position: sticky; top: 64px; height: calc(100vh - 84px); overflow: hidden; }
.viewer iframe { width: 100%; height: 100%; border: 0; border-radius: var(--radius); background: var(--surface-2); }
.viewer .empty { height: 100%; display: grid; place-items: center; }
.panel { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.panel > *, .review > * { min-width: 0; }
.headrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.headrow .spacer { flex: 1; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.fields .wide { grid-column: 1 / -1; }
.ai { font-size: 12px; color: var(--warn); margin-top: 2px; }
.flag { border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: 6px; padding: 10px 12px; }
.flag.cleared { border-left-color: var(--ok); }
.flag .code { font-weight: 700; font-size: 12px; letter-spacing: .3px; }
.flag .msg { margin: 2px 0 6px; }
.flag .row { display: flex; gap: 8px; }
.flag .done { font-size: 13px; color: var(--ok); }
.passes { font-size: 13px; color: var(--muted); }
.note { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; }
.banner { padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions input { flex: 1; min-width: 180px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* Reports */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .detail { color: var(--muted); font-size: 13px; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 20px 0 8px; }
.section-head h2 { margin: 0; }

/* Sign in */
.signin { max-width: 380px; margin: 12vh auto; }
.signin h1 { margin-bottom: 6px; }
.signin form { display: grid; gap: 12px; margin-top: 18px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 14px; border-radius: 8px; font-size: 13px; z-index: 20; max-width: calc(100vw - 32px);
}
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 900px) {
  main { padding: 16px; }
  .review { grid-template-columns: minmax(0, 1fr); }
  .viewer { position: static; height: 70vh; }
  .fields { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .who { margin-left: 0; width: 100%; }
}

/* Expense coding (GL lines) */
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); font-weight: 600; }
table.gl td { vertical-align: top; }
table.gl input { width: 100%; min-width: 0; }
table.gl td:first-child { min-width: 150px; }
table.gl td.num { width: 120px; }
table.gl td:last-child { width: 1%; white-space: nowrap; }

/* Approvals and settings */
.pill.pending_approval { background: var(--info-bg); color: var(--accent); border: 1px dashed currentColor; }
.btn.ms { width: 100%; margin-bottom: 12px; }
table.rules input[type=text], table.rules select, table.rules input[type=number] { width: 100%; min-width: 0; }
table.rules td.num { width: 130px; }
table select { max-width: 100%; }
.actions select { width: auto; flex: 0 0 auto; min-width: 160px; }
table.totals th, table.totals td { white-space: nowrap; }
table.totals thead tr:first-child th[colspan] { text-align: center; border-bottom: 1px solid var(--border); }
table.totals tfoot th, table.totals tfoot td { border-top: 2px solid var(--border); font-weight: 600; }
.stat .value.warn-text, .stat .value.ok-text { font-size: 1.25rem; }
/* Filing settings */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; }
.kv > div { min-width: 0; overflow-wrap: anywhere; }
.preview { margin-top: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 6px; display: grid; gap: 4px; overflow-wrap: anywhere; }
.bad-text { color: var(--bad); }
.mbox hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* Files that did not become invoices (Inbox) */
.files-card { margin-bottom: 12px; }
.files-card.warn { border-left: 4px solid var(--warn); }
.files-card summary { cursor: pointer; }
table.files { width: 100%; border-collapse: collapse; margin-top: 6px; }
table.files td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
table.files .actions-cell { white-space: nowrap; text-align: right; width: 1%; }
table.files .actions-cell .btn + .btn { margin-left: 4px; }
.dismiss-note { margin-top: 6px; }
@media (max-width: 640px) {
  table.files td:first-child { display: none; }
  table.files .actions-cell { white-space: normal; }
}

/* GP account picker (expense coding) */
.acctpick { position: absolute; z-index: 50; max-height: 320px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: 13px; }
.acctpick .opt { padding: 6px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acctpick .opt.on, .acctpick .opt:hover { background: var(--accent-bg, rgba(37,99,235,.12)); }
.acctpick .none { padding: 10px; }
.acctpick .foot { position: sticky; bottom: 0; padding: 4px 10px; background: var(--surface); border-top: 1px solid var(--border); }

/* Bulk approval (My approvals) */
.bulkbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.bulkbar #bulknote { flex: 1 1 220px; min-width: 0; }
th.tick, td.tick { width: 32px; padding-right: 0; }
td.tick input, th.tick input, .bulkbar label input { width: 16px; height: 16px; cursor: pointer; vertical-align: middle; }
tr.picked td { background: var(--accent-bg, rgba(37,99,235,.08)); }

/* Inbox date range + paging */
.toolbar.daterange { align-items: center; gap: 10px; margin-top: -4px; }
.toolbar.daterange input[type=date] { width: auto; padding: 4px 6px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.banner .btn { margin-left: 8px; }

/* Pick a PO line for an invoice line */
.pickline { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; min-width: 220px; }
.pickline select { max-width: 320px; font-size: 12px; }

/* Radio choices with a description under each (Settings > ERP) */
.radios { display: grid; gap: 8px; }
.radio { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.radio input { margin-top: 3px; }

/* Processes page */
table.procs td { vertical-align: top; }
.nowrap { white-space: nowrap; }
pre.runout { max-height: 360px; overflow: auto; background: var(--bg, #f6f7f9); padding: 10px; font-size: 12px; white-space: pre-wrap; margin: 0; }
@media (max-width: 640px) {
  .nav { flex-wrap: wrap; row-gap: 2px; min-width: 0; }
}
