:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16202e;
  --muted: #64748b;
  --line: #dfe3e9;
  --accent: #1f5f8b;
  --accent-soft: #e8f1f8;
  --ok: #157347;
  --warn: #b45309;
  --suggest: #fff8e1;
  --suggest-line: #f0c860;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px;
}
h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
h2 { margin: 0; font-size: 15px; }
h3 { margin: 0; font-size: 15px; }
h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.batch { display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; }
.batch label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.batch input { font-size: 14px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.batch input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.folder { display: flex; flex-direction: column; gap: 4px; }
.folder .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.folder code { font-family: var(--mono); font-size: 11.5px; background: var(--accent-soft); color: #14405e; padding: 6px 9px; border-radius: 6px; max-width: 520px; overflow-wrap: anywhere; }

/* ---------- panel ---------- */
main { padding: 18px 22px 40px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.actions { display: flex; gap: 8px; }

.btn {
  font: inherit; font-size: 13px; padding: 6px 13px;
  border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.mini { padding: 4px 9px; font-size: 12px; }
.btn.save { background: var(--ok); border-color: var(--ok); }
.btn.link { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- grid ---------- */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 1180px; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: middle; }
thead th { background: #f8fafc; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; white-space: nowrap; }
thead th span { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 10.5px; }
tbody tr.suggested { background: var(--suggest); box-shadow: inset 3px 0 0 var(--suggest-line); }
tbody tr.saved { background: #f6fbf7; box-shadow: inset 3px 0 0 var(--ok); }
tbody tr.busy { opacity: .6; }

td input, td select {
  font: inherit; width: 100%; padding: 5px 6px;
  border: 1px solid transparent; border-radius: 5px;
  background: rgba(255,255,255,.75); color: var(--ink);
}
td input:hover, td select:hover { border-color: var(--line); }
td input:focus, td select:focus { outline: none; border-color: var(--accent); background: #fff; }
td input.num { text-align: right; font-family: var(--mono); font-size: 13px; }
td.readonly { text-align: right; font-family: var(--mono); font-weight: 600; }

/* A setting that is present but unusable - louder than "not configured",
   because nothing will work and nothing is obviously missing. */
.bad { color: #b42318; font-weight: 600; }

/* Head office handed this statement back; the reason sits above the grid. */
.returned-note {
  margin: 0 0 12px;
  background: #fdf0e2; border: 1px solid var(--suggest-line);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
}
.returned-note strong { color: var(--warn); }
.returned-note .sub { display: block; margin-top: 4px; }

/* Remarks on one line, and the line they belong to. */
tr.flagged td { background: #fffaf2; }
tr.note-row td { background: #fffaf2; border-top: 0; padding-top: 0; }
.line-notes { display: grid; gap: 4px; padding: 2px 0 6px 6px; }
.line-note {
  font-size: 12px; color: var(--warn);
  border-left: 3px solid var(--suggest-line); padding-left: 8px;
}

/* The number a claim is tracked by. */
.docket {
  font-family: var(--mono); font-weight: 700; color: var(--accent);
  background: var(--accent-soft); padding: 1px 6px; border-radius: 5px;
}
.pill.returned { background: #fdf0e2; color: var(--warn); }

.c-date { width: 116px; } .c-vendor { width: 150px; } .c-desc { min-width: 210px; }
.c-acct { width: 190px; } .c-class { width: 130px; } .c-tax { width: 175px; } .c-num { width: 104px; text-align: right; }
.c-rcpt { width: 128px; } .c-save { width: 78px; } .c-cur { width: 82px; }
th.c-num, td.c-num { text-align: right; }
.total { color: var(--accent); }

/* The CAD translation of a foreign line: same columns, visibly subordinate to
   the line it belongs to rather than reading as a second expense. */
tr.fx-row td {
  background: #f6f9fc;
  border-top: 0;
  padding-top: 2px; padding-bottom: 6px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}
tr.fx-row td.c-num { text-align: right; }
tr.fx-row td.total { color: var(--accent); font-weight: 600; }
tr.fx-row .fx-label {
  font-family: inherit; font-size: 11px; text-transform: none;
  letter-spacing: .2px; color: var(--muted); text-align: right; padding-right: 10px;
}
tr.fx-row .fx-rate { white-space: nowrap; }
tr.fx-row .fx-rate input.rate { width: 84px; font-size: 12px; }
tr.fx-row .fx-note { display: block; font-family: inherit; font-size: 11px; color: #b45309; }

tfoot td { background: #f8fafc; font-family: var(--mono); font-weight: 600; border-top: 2px solid var(--line); }
tfoot .foot-label { font-family: inherit; text-transform: uppercase; font-size: 11px; letter-spacing: .5px; color: var(--muted); }

.rcpt { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.rcpt .name { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; max-width: 120px; }

.hint { padding: 10px 16px; margin: 0; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.hint.small { border: none; padding: 10px 0 0; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; padding: 24px; z-index: 50; }
/* `display: grid` above outranks the browser's [hidden] rule - restate it. */
.viewer[hidden] { display: none; }
.viewer-box { background: var(--panel); border-radius: 10px; width: min(1180px, 100%); height: min(88vh, 900px); display: flex; flex-direction: column; overflow: hidden; }
.viewer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.viewer-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.viewer-doc { background: #1e293b; display: grid; place-items: center; overflow: auto; padding: 12px; }
.viewer-doc img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; }
.viewer-doc iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-side { border-left: 1px solid var(--line); padding: 14px 16px; overflow: auto; }

.fields { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.notes { margin-top: 12px; font-size: 12.5px; color: var(--warn); }
.badge { display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: #14405e; }
.badge.low { background: #fdecec; color: #9b1c1c; }
.badge.medium { background: #fef4e2; color: #92400e; }
.badge.high { background: #e6f5ec; color: #14683c; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #16202e; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 70vw;
}
.toast.err { background: #9b1c1c; }

/* ---------- login / register ---------- */
body.gate { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 28px; width: min(420px, 100%);
  box-shadow: 0 10px 40px rgba(15,23,42,.07);
}
.card-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.card h2 { margin: 0 0 16px; font-size: 16px; }
.card form { display: flex; flex-direction: column; gap: 14px; }
.card label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.card input { font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
.card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.card .note { text-transform: none; letter-spacing: 0; font-size: 11.5px; color: var(--muted); }
.btn.wide { width: 100%; padding: 10px; font-size: 14px; margin-top: 4px; }
.alt { margin: 18px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.alt a, .card a { color: var(--accent); }
.err { margin: 14px 0 0; padding: 9px 11px; border-radius: 7px; background: #fdecec; color: #9b1c1c; font-size: 13px; }

/* ---------- welcome banner ---------- */
.welcome {
  margin: 14px 22px 0; padding: 13px 18px; border-radius: 8px;
  background: linear-gradient(90deg, var(--accent-soft), #fff);
  border: 1px solid #cfe0ee; color: #14405e; font-size: 15px;
}

/* Sign-in lands on an empty grid; this says what is already in the statement. */
.existing {
  margin: 10px 22px 0; padding: 9px 14px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #f8fafc; border: 1px solid var(--line);
  color: var(--muted); font-size: 12.5px;
}
.existing strong { color: var(--ink); }
.existing .btn.link { font-size: 12.5px; }

/* ---------- nav / status ---------- */
.nav { display: flex; align-items: center; gap: 10px; }
.who { font-size: 13px; color: var(--muted); }
.btn.submit { background: var(--ok); border-color: var(--ok); }
.pill {
  display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 9px; border-radius: 99px; vertical-align: middle; margin-left: 8px;
  background: #eef2f7; color: #475569; font-weight: 600;
}
.pill.submitted { background: #e6f5ec; color: #14683c; }
.pill.draft { background: #fef4e2; color: #92400e; }
.pill.under_process { background: #e8f1f8; color: #14405e; }
.pill.paid { background: #157347; color: #fff; }

.c-pick { width: 34px; text-align: center; }

/* status journey on a statement */
.step { color: var(--muted); font-size: 12px; }
.step.done { color: var(--ink); font-weight: 600; }
.step em { font-style: normal; color: var(--muted); font-weight: 400; }
.arrow { color: var(--line); margin: 0 8px; }
.ref {
  display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 99px;
  background: var(--accent-soft); color: #14405e; font-family: var(--mono); font-size: 11px;
}
.ref.pay { background: #e6f5ec; color: #14683c; }
.refs { white-space: nowrap; }
table.editable tr.paidline { background: #f3f7f4; color: var(--muted); }
table.editable tr.paidline input, table.editable tr.paidline select { background: transparent; }

/* ---------- history ---------- */
table.history tbody tr.clickable { cursor: pointer; }
table.history tbody tr.clickable:hover { background: var(--accent-soft); }
td.empty { text-align: center; color: var(--muted); padding: 26px; }
.viewer-box.wide { width: min(1280px, 100%); }
.viewer-body.detail { grid-template-columns: 1fr; overflow: auto; }
.detail-main { padding: 16px 18px; }
table.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 900px; }
table.mini th { background: #f8fafc; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; text-align: left; padding: 6px 8px; }
table.mini td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.mini tr.foot td { font-weight: 700; background: #f8fafc; border-top: 2px solid var(--line); }
table.mini a { color: var(--accent); }

.audit { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.audit-row { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 8px 10px; background: #f8fafc; border-radius: 6px; }
.audit-when { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.tag { display: inline-block; font-family: var(--mono); font-size: 11px; background: #e2e8f0; color: #334155; padding: 1px 7px; border-radius: 4px; margin-right: 6px; }
.chg { margin-top: 4px; font-size: 12px; color: var(--muted); }
.chg span:first-child { display: inline-block; min-width: 120px; color: var(--ink); }
.chg .from { color: #9b1c1c; text-decoration: line-through; }
.chg .to { color: #157347; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: 4px; padding: 0 22px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  font: inherit; font-size: 13px; padding: 10px 14px; cursor: pointer;
  background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted);
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .count { background: #9b1c1c; color: #fff; border-radius: 99px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.tab .count:empty { display: none; }

.stack { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.card-row {
  display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 16px; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: #fff;
}
.card-row.col { display: block; }
.card-row .between { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.companies .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 4px; }
.chks { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; white-space: nowrap; }
.chk input { accent-color: var(--accent); }
.inline-input { font: inherit; font-size: 13px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; }
.qboname { display: flex; flex-direction: column; gap: 3px; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.qboname input { width: 150px; font-size: 12.5px; padding: 4px 8px; text-transform: none; letter-spacing: 0; }
.src { font-family: var(--mono); font-size: 11.5px; }
.src.qbo { color: var(--ok); font-weight: 600; }
.chart { margin-top: 12px; }
.chart textarea {
  width: 100%; font-family: var(--mono); font-size: 12.5px; padding: 10px;
  border: 1px solid var(--line); border-radius: 6px; resize: vertical;
}
.chart .row-actions { margin-top: 8px; }
/* every invoice in the statement, side by side */
.invoice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.invoice { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.invoice-doc { height: 210px; background: #1e293b; display: grid; place-items: center; overflow: hidden; }
.invoice-doc img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; }
.invoice-doc iframe { width: 100%; height: 100%; border: 0; background: #fff; pointer-events: none; }
.invoice figcaption { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; font-size: 12px; }
.invoice figcaption .sub { font-size: 11px; overflow-wrap: anywhere; }
.invoice .amt { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.invoice .unmatched { color: var(--warn); font-weight: 400; }
.invoice .row-actions { margin-top: 4px; }

/* editable admin line grid */
table.editable td { padding: 3px 5px; }
table.editable input, table.editable select {
  font: inherit; font-size: 12.5px; width: 100%; padding: 4px 6px;
  border: 1px solid transparent; border-radius: 5px; background: #f8fafc;
}
table.editable input:hover, table.editable select:hover { border-color: var(--line); }
table.editable input:focus, table.editable select:focus { outline: none; border-color: var(--accent); background: #fff; }
table.editable input.num { text-align: right; font-family: var(--mono); }
table.editable tr.dirty { background: var(--suggest); }
table.editable .c-num { width: 92px; }

.files { display: flex; flex-direction: column; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 12px; font-size: 12.5px; padding: 6px 8px; background: #f8fafc; border-radius: 6px; }
.file-row a { color: var(--accent); overflow-wrap: anywhere; }
.done h3 { margin: 0 0 8px; font-size: 15px; color: var(--ok); }
.done p { margin: 0 0 8px; font-size: 13px; }

@media (max-width: 900px) {
  .card-row { grid-template-columns: 1fr; }
  .viewer-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .viewer-side { border-left: none; border-top: 1px solid var(--line); max-height: 40%; }
}

/* --- Access map + creating an account ------------------------------------ */
/* Destructive actions read as destructive. Ghost keeps them visually quieter
   than the primary action next to them; the colour is what stops a reflex
   click on "Delete" when "Approve" was meant. */
.btn.danger { color: var(--bad, #c0392b); border-color: var(--bad, #c0392b); }
.btn.danger:hover { background: var(--bad, #c0392b); color: #fff; }
.btn.link.danger { border: none; background: none; }

.newuser { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 6px; }
.newuser input { flex: 1 1 190px; min-width: 0; }
.newuser-apps { padding: 4px 16px 0; }
.newuser-apps .lbl { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* One tick per application per person, so the columns need to stay narrow
   enough that the whole grid is readable without scrolling sideways. */
#accessTable th { white-space: normal; }
#accessTable td input[type=checkbox] { transform: scale(1.15); }

/* Company boxes inside the access map. One per line and width-capped so a long
   company list stacks in its own column instead of stretching the whole grid.
   text-align is set explicitly: the cell inherits the centring used by the tick
   columns either side, which leaves these labels ragged down the left. */
/* Company boxes inside the access map. The base .chk is inline-flex and nowrap,
   which is right in the Users table where the column is wide; here the column is
   narrow, so the only overrides needed are a width for the cell and permission
   for a long company name to wrap instead of running into "Lands on". */
#accessTable td.companycol, #accessTable th.companycol { width: 300px; }
#accessTable .chks.narrow { flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; }
