: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; }

/* A line whose receipt could not be read. After a bulk upload the toast has
   long gone by the time anyone works down the grid, so the line says so
   itself - it is the one that has to be typed in by hand. */
tbody tr.unread { background: #fff8ed; }
tbody tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--warn); }


/* Who is owed something. The strip above the statements list: one chip per
   claimant, starred when they have statements still outstanding. */
.people { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 0; }
.people .person {
  display: inline-flex; align-items: baseline; gap: 6px;
  font: inherit; font-size: 13px; cursor: pointer;
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--ink);
}
.people .person:hover { border-color: var(--accent); }
.people .person.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.people .person.on .sub, .people .person.on .count { color: #dbeafe; }
.people .person .count { font-size: 11.5px; color: var(--muted); }
.people .person .sub { font-size: 11.5px; color: var(--muted); }
/* The star is the whole point of the strip, so it is red on every
   background — including the selected chip, which is otherwise blue. */
.star, .people .person.on .star { color: #dc2626; font-size: 14px; }
.people .person.owed { border-color: #fca5a5; }

/* The payment date, entered against a statement in the list. */
td.c-pay input[type="date"] { font: inherit; font-size: 12.5px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; }
td.c-pay input[type="date"]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* Dragging receipts anywhere over the grid. */
.grid-panel.dropping { outline: 2px dashed var(--accent); outline-offset: -4px; background: var(--accent-soft); }

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; }

/* ---------- carry on with the phone ---------- */
/* Sized to its contents rather than to the screen: the receipt viewer fills
   the window because a receipt needs the room, and a QR code does not. */
.viewer-box.phone-box { width: min(660px, 100%); height: auto; max-height: 88vh; }
.phone-body { display: grid; grid-template-columns: auto 1fr; gap: 20px; padding: 18px; overflow: auto; }
.phone-qr {
  width: 232px; height: 232px;
  display: grid; place-items: center;
  /* Read off the screen by a camera, so it keeps its own white quiet zone
     whatever the panel behind it is doing. */
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px;
}
.phone-qr svg { width: 100%; height: 100%; display: block; }
.phone-side { min-width: 0; }
.phone-steps { margin: 0 0 12px; padding-left: 20px; font-size: 13px; display: grid; gap: 6px; }
.phone-url { font-size: 11px; overflow-wrap: anywhere; }
.phone-live {
  margin: 12px 0 0; padding: 9px 11px; border-radius: 6px;
  background: var(--accent-soft); color: #14405e; font-size: 12.5px;
}
@media (max-width: 620px) {
  .phone-body { grid-template-columns: 1fr; justify-items: center; }
}

/* ---------- 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; }

/* ================================================================== */
/* Printing                                                            */
/* ================================================================== */

/* Off screen entirely; the print stylesheet below is what reveals it. */
.print-head { display: none; }

@media print {
  /* Landscape: a statement line is fourteen columns wide, and portrait
     either shrinks it past reading or drops the right-hand half. */
  @page { size: A4 landscape; margin: 10mm; }

  :root { --line: #999; }

  body {
    background: #fff;
    /* Printers do not render backgrounds by default, so anything that relied
       on one to be legible has to stop relying on it. */
    color: #000;
    font-size: 10pt;
  }

  /* Only under print media: if afterprint never fires and the class is left
     behind, nothing on screen changes. */
  .print-hide { display: none !important; }

  .print-head { display: block; margin: 0 0 10px; }
  .print-head h1 { margin: 0; font-size: 15pt; }
  .print-sub { margin: 2px 0 0; font-size: 9.5pt; color: #333; }
  .print-when { margin: 2px 0 0; font-size: 8.5pt; color: #666; }

  /* The chrome. None of it means anything on paper, and the buttons in
     particular print as empty rounded boxes. */
  .topbar, .tabs, .nav, .actions, .toast, .hint, .sheet,
  #welcome, #existing, .panel-head .actions, .c-save, .files, .row-actions {
    display: none !important;
  }

  .panel, .grid-panel, main {
    border: 0; box-shadow: none; padding: 0; margin: 0; background: none;
  }

  /* Tables are the point of the exercise. */
  .tablewrap { overflow: visible !important; }
  table { width: 100% !important; border-collapse: collapse; }
  table.mini { min-width: 0 !important; }
  /* Repeat the header on every sheet - a second page of figures with no
     column names is not a record of anything. */
  thead { display: table-header-group; }
  tr { page-break-inside: avoid; }
  th, td { border: 1px solid #bbb; padding: 3px 5px; font-size: 9pt; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Grid cells are inputs. Printed as inputs they come out as a page of empty
     boxes with the values crammed inside; printed as text they read. */
  input, select, textarea {
    border: 0 !important; background: none !important; padding: 0 !important;
    font-size: 9pt !important; color: #000 !important;
    -webkit-appearance: none; appearance: none;
  }
  select { text-overflow: ellipsis; }

  .pill, .badge {
    border: 1px solid #999; color: #000 !important; background: none !important;
  }

  /* A statement opened in its viewer is the thing being printed: unpin it from
     the window, drop the backdrop, and let it run to as many sheets as it
     needs instead of being cropped to the height of the screen. */
  body.print-detail main,
  body.print-detail .topbar,
  body.print-detail .tabs { display: none !important; }

  body.print-detail .viewer {
    position: static !important;
    inset: auto !important;
    display: block !important;
    background: none !important;
    padding: 0 !important;
  }
  body.print-detail .viewer[hidden] { display: none !important; }
  body.print-detail .viewer-box {
    width: 100% !important; height: auto !important; max-height: none !important;
    box-shadow: none !important; border: 0 !important; border-radius: 0 !important;
    overflow: visible !important;
  }
  body.print-detail .viewer-head { border-bottom: 1px solid #999; padding: 0 0 6px; }
  body.print-detail .viewer-body {
    display: block !important; overflow: visible !important;
  }
  body.print-detail .detail-main { padding: 8px 0 0; }
  /* The receipt viewer's dark stage would print as a solid black rectangle. */
  body.print-detail .viewer-doc { background: none !important; }

  /* The audit trail is the part that makes a printed claim defensible. */
  .audit-row { background: none !important; border-bottom: 1px solid #ddd; }
  a { color: #000; text-decoration: none; }
}

/* ---- Admin -> Mining data (World Mine Atlas publishing) ---------------------- */
.mtotals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; padding: 12px 16px 4px; }
.mtot { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 12px; }
.mtot .v { display: block; font-size: 20px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.mtot .l { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.mrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 16px; }
.mrow input[type="text"] { flex: 1; min-width: 180px; }
.mchk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.madd { margin: 12px 16px 0; }
.madd summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.mreason { max-width: 440px; font-size: 12px; line-height: 1.45; }
.mstatus { min-width: 160px; }
code.k { font-family: var(--mono); font-size: 11px; background: #eef1f5; padding: 1px 5px; border-radius: 4px; word-break: break-all; }
b.ok { color: var(--ok); }
b.warn { color: var(--warn); }

/* ---- Admin -> Mining companies ------------------------------------------------ */
.mco { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 0; border-top: 1px solid var(--line, #e3e6ea); }
@media (max-width: 900px) { .mco { grid-template-columns: 1fr; } }
.mco-list { max-height: 72vh; overflow-y: auto; overflow-x: hidden; border-right: 1px solid var(--line, #e3e6ea); }
/* table.mini carries min-width: 900px for the wide admin tables; the company list is one
   column, and at 900px a click scrolls the names out of the 340px pane. */
.mco-list table.mini { min-width: 0; }
.mco-list tr.co { cursor: pointer; }
.mco-list tr.co:hover td, .mco-list tr.co.on td { background: var(--accent-soft); }
.mco-list td .sub { margin-top: 2px; }
.mco-detail { min-width: 0; max-height: 72vh; overflow: auto; padding: 0 16px 20px; }
.mco-detail h3 { margin: 14px 0 4px; font-size: 18px; }
.mco-detail h4 { margin: 20px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.mco-detail .lic { font-size: 11.5px; color: var(--muted); margin: 0 0 6px; }
.mco-detail .tablewrap { overflow-x: auto; }
.gtag { display: inline-block; font-size: 10.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 4px; background: #eef1f5; color: var(--muted); margin-left: 4px; }
.gtag.named { background: #e7eefb; color: #2b5fb0; }
.gtag.nb-gold { background: #f6eedd; color: #8a5f10; }
.cnt { display: inline-block; font-size: 11px; color: var(--muted); margin-right: 8px; white-space: nowrap; }
.cnt b { color: var(--ink); font-variant-numeric: tabular-nums; }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.pubd { display: inline-block; font-size: 11px; font-weight: 600; color: #7a560f; background: #f6eedd; border-radius: 4px; padding: 1px 6px; }

/* publish / ownership dialogs */
.mdlg { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(720px, 94vw); max-height: 90vh; }
.mdlg::backdrop { background: rgba(15, 23, 42, .45); }
.mdlg-body { padding: 18px 20px; display: grid; gap: 8px; }
.mdlg-body h3 { margin: 0; font-size: 17px; }
.mdlg-body h4 { margin: 10px 0 0; }
.mdlg-body input[type="text"], .mdlg-body input[type="number"] { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; }
.mdlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--ink); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 0; }
.picks { display: grid; gap: 2px; max-height: 150px; overflow-y: auto; }
.picks button { text-align: left; font: inherit; font-size: 12.5px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.picks button:hover { border-color: var(--accent); }
.plist { display: grid; gap: 3px; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.plist label { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.plist .sub { margin: 0; }
.rights { display: grid; gap: 6px; background: #fff8ed; border: 1px solid var(--suggest-line); border-radius: 6px; padding: 8px 10px; }
.ownline { display: flex; gap: 10px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 0; font-size: 13px; }
.gtag.former-nb { background: #eef1f5; color: #6b7280; }
.rights[hidden], .picks:empty { display: none; }
