/*
  Invoice checker. Laid out like the bill approval screen in ordinary accounts software: an app bar,
  a table of bills, and the open bill below it as an invoice preview beside its check results.
  Type is the operating system's own UI font. The reasons are in INVOICE-DESIGN.md.
  This file sets everything the page uses, so it does not depend on the portfolio's shared styles.
*/
:root {
  --font: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #eef0f2;
  --panel: #ffffff;
  --sunken: #f4f5f7;
  --text: #1c2126;
  --muted: #555e68;
  --border: #d5d9de;
  --border-strong: #b8bec6;
  --field: #7b838d;
  --blue: #0b5ab0;
  --blue-hover: #08498f;
  --blue-ink: #ffffff;
  --blue-tint: #e6eef8;
  --green: #17703a;
  --green-ink: #ffffff;
  --amber: #8a5600;
  --amber-tint: #fdf1d8;
  --grey: #555e68;
  --grey-tint: #e7e9ec;
  --backdrop: rgba(20, 24, 28, .45);
  --shadow: rgba(20, 24, 28, .18);

  --radius: 4px;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --quick: .12s;
  --sheet: .15s;
  --open: .18s;

  --frame: 1400px;
  --gutter: clamp(12px, 2.5vw, 24px);
}
:root[data-theme="dark"] {
  --bg: #16181b;
  --panel: #202328;
  --sunken: #1a1d21;
  --text: #e3e6ea;
  --muted: #a3abb5;
  --border: #353a41;
  --border-strong: #4b525b;
  --field: #79828d;
  --blue: #7ab0f5;
  --blue-hover: #9cc4f8;
  --blue-ink: #10151b;
  --blue-tint: #1f2c3d;
  --green: #6cc788;
  --green-ink: #0f1712;
  --amber: #e4b154;
  --amber-tint: #362b14;
  --grey: #a3abb5;
  --grey-tint: #2c3036;
  --backdrop: rgba(0, 0, 0, .6);
  --shadow: rgba(0, 0, 0, .5);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 1rem; }
body { background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); font-variant-numeric: tabular-nums; }
ul, ol { list-style: none; }
a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-hover); }
img, svg { display: block; }
button, input, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
th { font-weight: 600; text-align: left; }
h1, h2, h3 { font-weight: 600; line-height: 1.3; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 1rem; top: -3rem; z-index: 50; padding: .5rem .75rem; background: var(--blue); color: var(--blue-ink); border-radius: var(--radius); }
.skip:focus { top: .75rem; }
.i { width: 16px; height: 16px; flex: none; }
.frame { max-width: var(--frame); margin: 0 auto; padding-inline: var(--gutter); }
.n { text-align: right; white-space: nowrap; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.noscript { margin-top: 1rem; padding: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--panel); color: var(--text);
  font-size: 14px; line-height: 1; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color var(--quick) var(--ease), border-color var(--quick) var(--ease), color var(--quick) var(--ease);
}
.btn:hover { background: var(--sunken); border-color: var(--field); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { border-color: var(--blue); background: var(--blue); color: var(--blue-ink); font-weight: 600; }
.btn-primary:hover { border-color: var(--blue-hover); background: var(--blue-hover); color: var(--blue-ink); }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background-color var(--quick) var(--ease), color var(--quick) var(--ease);
}
.icon-btn:hover { background: var(--sunken); color: var(--text); }
kbd { display: inline-block; min-width: 24px; padding: 2px 6px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--sunken); font: inherit; font-size: 13px; line-height: 1.3; text-align: center; }

/* Status: a word in its colour, with a small icon. No fill. */
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status .i { width: 15px; height: 15px; }
.status.is-ok { color: var(--green); }
.status.is-warn { color: var(--amber); }
.status.is-held, .status.is-note { color: var(--grey); }
.status-extra { margin-left: 6px; color: var(--muted); }

/* App bar */
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar-in { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; min-height: 52px; padding-block: 6px; }
.brand { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 12px; }
.product { font-size: 16px; }
.demo-note { color: var(--muted); }
.topnav { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-left: auto; }
.topnav a { text-decoration: none; }
.topnav a:hover { text-decoration: underline; }

/* Working area */
main { padding-bottom: 2rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 20px 0 12px; }
.page-head h2 { font-size: 20px; }
#inbox-summary { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.toolbar-end { display: inline-flex; gap: 8px; margin-left: auto; }
.tol { display: inline-flex; align-items: center; gap: 6px; }
.tol input { width: 52px; height: 32px; padding: 0 8px; border: 1px solid var(--field); border-radius: var(--radius); background: var(--panel); text-align: right; }
.tol input[aria-invalid="true"], .gst-box input[aria-invalid="true"] { border-color: var(--amber); background: var(--amber-tint); }

/* Bills to pay */
.bill-table th, .bill-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.bill-table thead th { padding-block: 7px; background: var(--sunken); color: var(--muted); font-size: 13px; }
.bill-table th.n { text-align: right; }
.bill-table tbody tr { cursor: pointer; transition: background-color var(--quick) var(--ease); }
.bill-table tbody tr:hover { background: var(--sunken); }
.bill-table tbody tr.is-current { background: var(--blue-tint); }
.bill { padding: 0; border: 0; background: none; color: var(--blue); text-align: left; cursor: pointer; }
.bill:hover { text-decoration: underline; }
.bill-date { color: var(--muted); }
.panel-foot { padding: 8px 12px; color: var(--muted); font-size: 13px; }

/* The open bill */
.open-bill { display: grid; gap: 16px; margin-top: 16px; }
/* Each panel has a plain grey title strip, with any extra detail on the right. */
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; padding: 8px 16px; background: var(--sunken); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.panel-head h2 { font-size: 15px; }
.panel-head > span { color: var(--muted); font-size: 13px; }
.panel-body { padding: 16px; }

/* The invoice preview: a plain document on a grey viewer */
.viewer { padding: 16px; background: var(--sunken); border-radius: 0 0 var(--radius) var(--radius); }
.viewer-note { max-width: 760px; margin: 0 auto 10px; color: var(--muted); font-size: 13px; }
.paper { max-width: 760px; margin: 0 auto; padding: 24px; background: var(--panel); border: 1px solid var(--border); }
.paper-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 24px; }
.paper-sup { font-size: 16px; font-weight: 600; }
.paper-addr { color: var(--muted); }
.paper-title { text-align: right; }
.paper-title h3 { font-size: 18px; }
.paper-title p { color: var(--muted); }
.paper-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; margin-top: 20px; }
.paper-meta div { display: grid; gap: 2px; align-content: start; }
.paper-meta dt { color: var(--muted); font-size: 13px; }
.paper-meta .billto { grid-column: 1 / -1; }
.paper-meta .billto strong { font-weight: 600; }

.lines { margin-top: 20px; }
.lines th { padding: 6px 8px; border-bottom: 1px solid var(--border-strong); color: var(--muted); font-size: 13px; }
.lines td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lines th.n { text-align: right; }
.lines tr.is-check { background: var(--amber-tint); }
.line-code { display: block; font-weight: 600; }
.line-desc { display: block; color: var(--muted); font-size: 13px; }
.line-amt { white-space: nowrap; }
.lines .mark-h, .lines .mark-cell { width: 28px; padding-left: 0; text-align: right; }

/* A warning or note icon beside a figure that needs a look. Nothing beside a figure that matches. */
.mark { display: inline-flex; justify-content: flex-end; vertical-align: middle; }
.mark .i { width: 15px; height: 15px; }
.mark[data-st="check"] { color: var(--amber); }
.mark[data-st="note"] { color: var(--grey); }

/* The figures on the invoice are ordinary input boxes, so it is clear they can be changed. */
.cell { width: 100%; max-width: 104px; height: 30px; padding: 0 6px; border: 1px solid var(--field); border-radius: var(--radius); background: var(--panel); text-align: right; }
.cell[aria-invalid="true"] { border-color: var(--amber); background: var(--amber-tint); }
.cell-qty { max-width: 64px; min-width: 48px; }
.cell-text { max-width: 180px; text-align: left; }

.totals { display: grid; width: min(100%, 300px); margin: 16px 0 0 auto; }
.totals div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 3px 0; }
.totals dt { color: var(--muted); }
.totals dd { display: flex; align-items: center; gap: 6px; flex: 0 0 140px; justify-content: flex-end; }
.totals dd .mark { flex: 0 0 16px; }
.totals .cell { max-width: none; }
.totals .is-total { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border-strong); }
.totals .is-total dt { color: var(--text); font-weight: 600; }
.totals .is-total .cell { font-weight: 600; }

/* Check results */
.review-body { padding: 16px; }
.summary { display: flex; align-items: flex-start; gap: 8px; font-size: 15px; font-weight: 600; }
.summary .i { width: 18px; height: 18px; margin-top: 2px; }
.summary.v-check { color: var(--amber); }
.summary.v-notes, .summary.v-match { color: var(--green); }
.summary span { color: var(--text); }
.raise { margin-top: 6px; }
.review h3 { margin: 20px 0 6px; font-size: 14px; }
.cmp th, .cmp td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cmp thead th { border-bottom-color: var(--border-strong); color: var(--muted); font-size: 13px; }
.cmp th:first-child, .cmp td:first-child { padding-left: 0; }
.cmp th:last-child, .cmp td:last-child { padding-right: 0; }
.cmp th.n { text-align: right; }
.cmp .code { font-weight: 600; white-space: nowrap; }
.cmp .zero { color: var(--muted); }
.cmp .status { white-space: normal; }

.issues li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.issues li:first-child { border-top: 1px solid var(--border); }
.issue-title { display: flex; align-items: flex-start; gap: 6px; font-weight: 600; }
.issue-title .i { width: 15px; height: 15px; margin-top: 2px; }
.sev-check .issue-title .i { color: var(--amber); }
.sev-note .issue-title .i { color: var(--grey); }
.issue-detail { margin-top: 2px; padding-left: 21px; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 20px; }
.actions .decide { display: inline-flex; gap: 8px; margin-left: auto; }
.btn .copy-label { display: inline-flex; align-items: center; gap: 6px; }
.btn.is-copied .copy-label { animation: fade-in var(--sheet) var(--ease); }
#hold[aria-pressed="true"] { background: var(--grey-tint); border-color: var(--field); }
#approve[aria-pressed="true"] { border-color: var(--green); background: var(--green); color: var(--green-ink); }
.decide-note { margin-top: 8px; color: var(--muted); font-size: 13px; }

/* About this demo */
.about { display: grid; gap: 16px; margin-top: 32px; }
.about-text p { max-width: 70ch; }
.about-text p + p { margin-top: 8px; }
.gst-box .panel-body { display: grid; align-content: start; gap: 6px; }
.gst-box label { margin-top: 4px; }
.gst-help { max-width: 60ch; }
.gst-box input { width: min(100%, 240px); height: 32px; padding: 0 8px; border: 1px solid var(--field); border-radius: var(--radius); background: var(--panel); }
.gst-box input::placeholder { color: var(--muted); opacity: 1; }
#gst-result { color: var(--muted); }
#gst-result[data-state="valid"] { color: var(--green); }
#gst-result[data-state="invalid"] { color: var(--amber); }
.how-table th, .how-table td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.how-table thead th { border-bottom-color: var(--border-strong); color: var(--muted); font-size: 13px; }
.how-table tbody th { width: 22%; }
.how h3 { margin-top: 20px; font-size: 14px; }
.plain-list { margin-top: 6px; padding-left: 20px; list-style: disc; }
.plain-list li { margin-top: 4px; max-width: 80ch; }

/* Footer */
.foot { border-top: 1px solid var(--border); background: var(--panel); }
.foot-in { display: flex; flex-wrap: wrap; gap: 4px 24px; padding-block: 16px 24px; color: var(--muted); font-size: 13px; }
.foot .support { flex-basis: 100%; }
.print-only { display: none; }

/* Dialogs: the New check form and the shortcut list */
dialog.sheet { margin: auto; width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); overflow: auto; box-shadow: 0 8px 28px var(--shadow); }
dialog.sheet-sm { width: min(400px, calc(100vw - 24px)); }
dialog.sheet::backdrop { background: var(--backdrop); }
dialog.sheet[open] { animation: sheet-in var(--sheet) var(--ease); }
dialog.sheet[open]::backdrop { animation: fade-in var(--sheet) var(--ease); }
@keyframes sheet-in {
  from { opacity: 0; transform: scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { font-size: 18px; }
.sheet-note { margin-top: 10px; color: var(--muted); }
.sheet-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 16px; }
.entry-error { min-height: 20px; margin-top: 10px; color: var(--amber); white-space: pre-line; }
#entry-grid h3 { margin-top: 20px; font-size: 14px; }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 16px; }
.field { display: grid; gap: 4px; align-content: start; }
.field.wide { grid-column: 1 / -1; }
.field > span, .eg-head span { color: var(--muted); font-size: 13px; }
.field input, .eg-row input { width: 100%; min-width: 0; height: 32px; padding: 0 8px; border: 1px solid var(--field); border-radius: var(--radius); background: var(--panel); }
.eg-head, .eg-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(4, 96px) 32px; gap: 8px; align-items: center; }
.eg-head { margin-top: 10px; padding-bottom: 4px; }
#entry-rows { display: grid; gap: 8px; margin-bottom: 8px; }
.eg-cell { display: block; min-width: 0; }
.eg-cell > span { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eg-cell.num input { text-align: right; }

.keys { margin-top: 12px; }
.keys th, .keys td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.keys th { font-weight: 400; white-space: nowrap; padding-right: 16px; }
.keys td { color: var(--muted); }

/* Opening a bill: the two panels fade in when you pick a different bill. Never on page load. */
.open-bill.is-opening > .panel { animation: open-in var(--open) var(--ease); }
@keyframes open-in {
  from { opacity: .4; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Wide screens: the invoice and its check results side by side */
@media (min-width: 72rem) {
  .open-bill { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .about { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .about .how { grid-column: 1 / -1; }
}

/* Phones: the bills table and the line results become stacked lists */
@media (max-width: 40rem) {
  .brand { flex: 1; }
  .topnav { order: 3; margin-left: 0; width: 100%; padding-bottom: 4px; }
  .toolbar { padding: 10px; }
  .toolbar .btn-primary { width: 100%; }
  .toolbar-end { width: 100%; margin-left: 0; }
  .toolbar-end .btn { flex: 1; }

  .bill-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .bill-table tbody tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "sup sup total" "num date date" "status status status"; gap: 2px 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .bill-table tbody td { padding: 0; border: 0; }
  .bill-table td.sup { grid-area: sup; }
  .bill-table td.num { grid-area: num; }
  .bill-table td.bill-date { grid-area: date; }
  .bill-table td.n { grid-area: total; }
  .bill-table td.st { grid-area: status; }

  .viewer { padding: 0; }
  .viewer-note { margin: 0; padding: 10px 12px 0; }
  .paper { padding: 14px 12px; border: 0; }
  .paper-head { flex-direction: column; }
  .paper-title { text-align: left; }
  .paper-meta { gap: 10px 12px; }
  .cell-text { max-width: none; }
  .lines thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .lines tbody tr { display: grid; grid-template-columns: 72px 104px minmax(0, 1fr) 20px; grid-template-areas: "item item item mark" "qty price amt amt"; gap: 4px 10px; padding: 8px; border-bottom: 1px solid var(--border); }
  .lines tbody td { padding: 0; border: 0; }
  .lines td.line-item { grid-area: item; }
  .lines td.line-qty { grid-area: qty; text-align: left; }
  .lines td.line-price { grid-area: price; text-align: left; }
  .lines td.line-amt { grid-area: amt; line-height: 30px; }
  .lines td.mark-cell { grid-area: mark; width: auto; }
  .lines td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font-size: 13px; line-height: 1.5; }
  .lines .cell { max-width: none; }
  .totals dd { flex-basis: 130px; }

  .review-body { padding: 12px; }
  .cmp-lines thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cmp-lines tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .cmp-lines td { padding: 0; border: 0; text-align: left; }
  .cmp-lines td.code { grid-column: 1; }
  .cmp-lines td.res { grid-column: 2; grid-row: 1; text-align: right; }
  .cmp-lines td[data-label] { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px; }
  .cmp-lines td[data-label]::before { content: attr(data-label); color: var(--muted); }
  .actions .decide { width: 100%; margin-left: 0; }
  .actions .decide .btn { flex: 1; }
  .how-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .how-table tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); }
  .how-table tbody th, .how-table td { display: block; width: auto; padding: 0; border: 0; }
  .how-table td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
  .gst-box input { width: 100%; }

  dialog.sheet { padding: 14px; }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .eg-head { display: none; }
  .eg-row { position: relative; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); }
  .eg-row .eg-item { grid-column: 1 / -1; padding-right: 40px; }
  .eg-row .eg-del { position: absolute; top: 6px; right: 6px; }
  .eg-cell > span { position: static !important; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal; display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
  dialog.sheet[open], dialog.sheet[open]::backdrop, .btn.is-copied .copy-label, .open-bill.is-opening > .panel { animation: none; }
}

@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fcfcfd; --panel: #fcfcfd; --sunken: #fcfcfd; --text: #1c2126; --muted: #3e454d;
    --border: #b8bec6; --border-strong: #6f7782; --field: #fcfcfd; --blue: #0b5ab0;
    --green: #17703a; --amber: #8a5600; --amber-tint: #fcfcfd; --grey: #3e454d; --blue-tint: #fcfcfd;
  }
  body { background: #fcfcfd; color: #1c2126; font-size: 10.5pt; }
  .skip, .topbar, .page-head, .bills, .panel-head, .viewer-note, .actions, .decide-note, .about, .foot, dialog, noscript { display: none !important; }
  .print-only { display: block; margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid #1c2126; }
  .print-only h2 { font-size: 16pt; }
  .print-only p { color: #3e454d; }
  .frame { max-width: none; padding-inline: 0; }
  .open-bill { display: block; margin: 0; }
  .panel { border: 0; }
  .viewer { padding: 0; }
  .paper { max-width: none; padding: 0; border: 0; }
  .cell { border: 0; background: none; padding: 0; appearance: none; }
  .review-body { padding: 12px 0 0; }
  .issues li, .cmp tr { break-inside: avoid; }
  a { text-decoration: none; }
}
