/* Shared payslip / invoice presentation (admin preview, front-end and print). */

/*
 * The document is rendered inside the app, so the app's own stylesheet is
 * loaded alongside this one. A class name that exists in both would otherwise
 * reach in and reshape the page — that is how the payslip's detail table once
 * inherited the payroll grid's 1640px minimum and dragged the whole document
 * off the screen. Nothing inside a document is allowed to be wider than the
 * document itself.
 */
.qg-doc table {
	min-width: 0;
	max-width: 100%;
}

.qg-doc {
	--qg-ink: #1f2937;
	--qg-muted: #6e7681;
	--qg-line: #cbd1d8;
	--qg-accent: #e93e40;
	--qg-soft: #f3f5f7;
	background: #fff;
	color: var(--qg-ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 13px;
	line-height: 1.45;
	max-width: 860px;
	margin: 0 auto;
	padding: 26px 28px 20px;
	border: 1px solid var(--qg-line);
	box-sizing: border-box;
}

.qg-doc * {
	box-sizing: border-box;
}

.qg-doc-head {
	display: flex;
	flex-wrap: wrap;
	gap: 18px;
	align-items: flex-start;
	border: 1px solid var(--qg-line);
	padding: 12px 14px;
}

.qg-doc-logo {
	flex: 0 0 auto;
	width: 130px;
}

.qg-doc-logo img {
	max-width: 130px;
	max-height: 70px;
	height: auto;
	display: block;
}

.qg-doc-org {
	/* A basis rather than auto: below roughly 480px of usable width the two
	   halves of the header cannot sit side by side, and wrapping is the only
	   honest outcome. Squeezing instead breaks the address one word per line
	   and the name paints straight over the dates. */
	flex: 1 1 260px;
	min-width: 0;
}

.qg-doc-org h2 {
	margin: 0 0 4px;
	font-size: 18px;
	line-height: 1.2;
	color: var(--qg-ink);
	padding: 0;
}

.qg-doc-org p {
	margin: 0 0 3px;
	color: var(--qg-muted);
	font-size: 12px;
}

.qg-doc-codes {
	font-size: 11.5px;
	color: var(--qg-ink) !important;
	font-weight: 600;
}

.qg-doc-meta {
	flex: 1 1 210px;
	min-width: 0;

	/*
	 * This sits in a shrink-to-fit flex item, so a fixed table layout here
	 * would be cyclic — cap the block instead and let the values wrap.
	 */
	max-width: 320px;
}

.qg-doc-meta td {
	overflow-wrap: anywhere;
}

.qg-doc-meta table {
	width: 100%;
	border-collapse: collapse;
	font-size: 12px;
}

.qg-doc-meta th {
	text-align: left;
	font-weight: 400;
	color: var(--qg-muted);
	padding: 2px 8px 2px 0;
	white-space: nowrap;
}

.qg-doc-meta td {
	text-align: right;
	font-weight: 600;
	padding: 2px 0;
}

.qg-doc-title {
	background: var(--qg-accent);
	color: #fff;
	text-align: center;
	font-weight: 700;
	letter-spacing: 0.06em;
	font-size: 13px;
	padding: 8px 10px;
	margin: 0;
}

.qg-doc-title span {
	float: right;
	font-weight: 600;
	letter-spacing: 0;
}

/* Key / value grid */

.qg-grid {
	width: 100%;
	border-collapse: collapse;
	border: 1px solid var(--qg-line);
	border-top: 0;

	/*
	 * Fixed layout is not cosmetic here. Left to size itself, this table
	 * takes its width from its longest unbreakable value — a bank account
	 * line or a long name — and grows past the 860px page, dragging the
	 * whole document out of its container with it.
	 */
	table-layout: fixed;
}

.qg-grid th,
.qg-grid td {
	border: 1px solid var(--qg-line);
	padding: 5px 8px;
	font-size: 12px;
	vertical-align: middle;

	/* A long value wraps inside its cell instead of widening the table. */
	overflow-wrap: anywhere;
	word-break: break-word;
}

.qg-grid th {
	background: var(--qg-soft);
	color: var(--qg-muted);
	font-weight: 400;
	text-align: left;
	width: 16%;
}

.qg-grid td {
	font-weight: 600;
	width: 34%;
}

/* Attendance strip */

.qg-att {
	width: 100%;
	border-collapse: collapse;
	border: 1px solid var(--qg-line);
	border-top: 0;
	table-layout: fixed;
}

.qg-att th {
	background: var(--qg-soft);
	color: var(--qg-muted);
	font-size: 10.5px;
	font-weight: 400;
	padding: 4px 2px;
	text-align: center;
	border: 1px solid var(--qg-line);
}

.qg-att td {
	text-align: center;
	font-weight: 700;
	font-size: 13px;
	padding: 5px 2px;
	border: 1px solid var(--qg-line);
	background: var(--qg-soft);
}

/* Earnings / deductions */

.qg-amounts {
	width: 100%;
	border-collapse: collapse;
	margin-top: 10px;
	table-layout: fixed;
}

.qg-amounts th {
	background: var(--qg-ink);
	color: #fff;
	font-size: 11px;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	font-weight: 700;
	padding: 6px 8px;
	text-align: left;
	border: 1px solid var(--qg-ink);
}

.qg-amounts td {
	border: 1px solid var(--qg-line);
	padding: 5px 8px;
	font-size: 12px;
	height: 22px;
}

.qg-amounts .l {
	text-align: left;
}

.qg-amounts .r {
	text-align: right;
}

.qg-amounts .b {
	font-weight: 700;
}

.qg-amounts tfoot td {
	background: var(--qg-soft);
	font-size: 12.5px;
}

.qg-amounts col:first-child {
	width: 30%;
}

/* Net pay band */

.qg-net {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	background: var(--qg-accent);
	color: #fff;
	padding: 12px 14px;
	margin-top: 10px;
}

.qg-net-l span {
	display: block;
	font-weight: 700;
	letter-spacing: 0.05em;
	font-size: 12px;
}

.qg-net-l em {
	display: block;
	font-size: 11.5px;
	opacity: 0.9;
	margin-top: 3px;
}

.qg-net-r {
	font-size: 24px;
	font-weight: 700;
	white-space: nowrap;
}

/* Secondary blocks */

.qg-sub {
	margin: 16px 0 6px;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--qg-muted);
}

.qg-mini {
	width: 100%;
	table-layout: fixed;
	border-collapse: collapse;
	font-size: 12px;
}

.qg-mini th {
	text-align: left;
	font-weight: 400;
	color: var(--qg-muted);
	padding: 3px 0;
}

.qg-mini td {
	text-align: right;
	font-weight: 600;
	padding: 3px 0;
}

.qg-mini tr.t th,
.qg-mini tr.t td {
	border-top: 1px solid var(--qg-line);
	font-weight: 700;
	color: var(--qg-ink);
	padding-top: 5px;
}

.qg-ytd,
.qg-remarks {
	font-size: 11.5px;
	color: var(--qg-muted);
	margin: 10px 0 0;
}

.qg-doc-foot {
	display: flex;
	justify-content: space-between;
	gap: 16px;
	border-top: 1px solid var(--qg-line);
	margin-top: 18px;
	padding-top: 8px;
	font-size: 10.5px;
	color: var(--qg-muted);
}

/* Invoice specifics */

.qg-billto {
	border: 1px solid var(--qg-line);
	border-top: 0;
	background: var(--qg-soft);
	padding: 10px 14px;
}

.qg-billto strong {
	font-size: 10.5px;
	letter-spacing: 0.06em;
	color: var(--qg-muted);
	display: block;
}

.qg-billto h3 {
	margin: 3px 0 4px;
	font-size: 15px;
	padding: 0;
}

.qg-billto p {
	margin: 0 0 2px;
	font-size: 12px;
	color: var(--qg-muted);
}

.qg-items {
	width: 100%;
	border-collapse: collapse;
	margin-top: 10px;

	/*
	 * Seven columns, one of them a free-text description. Sized from its
	 * content the table runs past the page on a narrow screen, so the
	 * columns are declared below and the description takes what is left.
	 */
	table-layout: fixed;
}

.qg-items th:first-child,
.qg-items td:first-child {
	width: 5%;
}

.qg-items th:nth-child(3),
.qg-items td:nth-child(3) {
	width: 11%;
}

.qg-items th:nth-child(4),
.qg-items td:nth-child(4) {
	width: 8%;
}

.qg-items th:nth-child(5),
.qg-items td:nth-child(5),
.qg-items th:last-child,
.qg-items td:last-child {
	width: 15%;
}

.qg-items th:nth-child(6),
.qg-items td:nth-child(6) {
	width: 9%;
}

.qg-items th,
.qg-items td {
	overflow-wrap: anywhere;
	word-break: break-word;
}

.qg-items th {
	background: var(--qg-ink);
	color: #fff;
	font-size: 10.5px;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	padding: 7px 8px;
	text-align: center;
	border: 1px solid var(--qg-ink);
}

.qg-items th.l {
	text-align: left;
}

.qg-items th.r,
.qg-items td.r {
	text-align: right;
}

.qg-items td {
	border: 1px solid var(--qg-line);
	padding: 7px 8px;
	font-size: 12px;
	text-align: center;
	vertical-align: top;
}

.qg-items td.l {
	text-align: left;
}

.qg-items td.b {
	font-weight: 700;
}

.qg-inv-bottom {
	display: flex;
	gap: 24px;
	margin-top: 12px;
	align-items: flex-start;

	/* On a narrow screen the totals drop under the notes rather than
	   pushing the invoice off the side of the page. */
	flex-wrap: wrap;
}

.qg-inv-left {
	flex: 1 1 240px;
	min-width: 0;
	font-size: 12px;
}

.qg-inv-left strong {
	display: block;
	font-size: 10.5px;
	letter-spacing: 0.06em;
	color: var(--qg-muted);
	margin-top: 10px;
}

.qg-inv-left strong:first-child {
	margin-top: 0;
}

.qg-inv-left p {
	margin: 3px 0 0;
}

.qg-words {
	font-weight: 700;
}

.qg-inv-right {
	/* 300px when there is room, narrower when there is not. */
	flex: 0 1 300px;
	min-width: 0;
}

.qg-tot {
	width: 100%;
	table-layout: fixed;
	border-collapse: collapse;
	font-size: 12.5px;
}

.qg-tot th {
	text-align: left;
	font-weight: 400;
	color: var(--qg-muted);
	padding: 4px 8px;
}

.qg-tot td {
	text-align: right;
	font-weight: 600;
	padding: 4px 8px;
}

.qg-tot tr.t th,
.qg-tot tr.t td {
	background: var(--qg-accent);
	color: #fff;
	font-weight: 700;
	font-size: 14px;
	padding: 8px;
}

.qg-terms {
	margin-top: 14px;
	font-size: 11.5px;
	color: var(--qg-muted);
}

.qg-terms strong {
	display: block;
	letter-spacing: 0.06em;
	font-size: 10.5px;
	margin-bottom: 3px;
}

.qg-sign {
	margin-top: 26px;
	text-align: right;
	font-size: 12px;
}

.qg-sign span {
	display: block;
	color: var(--qg-muted);
}

.qg-sign em {
	display: inline-block;
	margin-top: 44px;
	border-top: 1px solid var(--qg-line);
	padding-top: 4px;
	min-width: 190px;
	font-style: normal;
	font-weight: 600;
}

/* Print */

/* ------------------------------------------------- Wide tables on a phone */

/*
 * A payslip and a GST invoice are A4 documents: the detail grid, the
 * attendance strip and the item table need more width than a phone has. Left
 * alone they do not shrink gracefully — the columns collapse until headings
 * read one letter per line and the figures overlap. Each sits in a scroller
 * so the page itself still fits the screen while the table keeps its real
 * column widths and slides sideways. On a wide screen nothing scrolls,
 * because the table already fits.
 */

.qg-docscroll {
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

.qg-docscroll > table {
	min-width: 520px;
}

/* The item table declares its own column widths and relies on the fixed
   layout, so it needs the room those widths add up to. */
.qg-docscroll > .qg-items {
	min-width: 580px;
}

/* The attendance strip is a single row of many small columns. */
.qg-docscroll > .qg-att {
	min-width: 560px;
}

/* A column cut off at the edge of the page reads as a broken layout unless
   the reader is told it slides. Only shown where the tables genuinely do not
   fit; never on paper. */
.qg-scrollhint {
	display: none;
	margin: 4px 0 0;
	font-size: 10px;
	color: var(--qg-muted);
}

@media screen and (max-width: 600px) {
	.qg-scrollhint {
		display: block;
	}
}

@media print {
	body * {
		visibility: hidden !important;
	}

	.qg-doc,
	.qg-doc * {
		visibility: visible !important;
	}

	.qg-doc {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		max-width: none;
		border: 0;
		padding: 0;
	}

	/* On paper there is no scrolling: a scroller would simply cut the right
	   of every wide table off the page. */
	.qg-docscroll {
		overflow: visible !important;
	}

	.qg-docscroll > table {
		min-width: 0 !important;
	}

	.qg-scrollhint {
		display: none !important;
	}

	@page {
		size: A4;
		margin: 12mm;
	}
}

/* ---------------------------------------------------------------------
   Template variants
   The inline style attribute supplies --qg-primary / --qg-accent /
   --qg-ink / --qg-soft / --qg-line and the font family per client.
   --------------------------------------------------------------------- */

.qg-doc {
	--qg-primary: var(--qg-accent);
}

/* Modern — a brand bar on top, filled headers in the primary colour,
   zebra rows and no heavy boxes. */

.qg-tpl-modern {
	border: 0;
	border-top: 5px solid var(--qg-primary);
	box-shadow: 0 1px 0 var(--qg-line);
}

.qg-tpl-modern .qg-doc-head {
	border: 0;
	border-bottom: 1px solid var(--qg-line);
	padding-left: 0;
	padding-right: 0;
}

.qg-tpl-modern .qg-doc-title {
	background: var(--qg-primary);
}

.qg-tpl-modern .qg-amounts th,
.qg-tpl-modern .qg-items th {
	background: var(--qg-primary);
	border-color: var(--qg-primary);
}

.qg-tpl-modern .qg-amounts td,
.qg-tpl-modern .qg-items td,
.qg-tpl-modern .qg-grid th,
.qg-tpl-modern .qg-grid td,
.qg-tpl-modern .qg-att th,
.qg-tpl-modern .qg-att td {
	border-left: 0;
	border-right: 0;
}

.qg-tpl-modern .qg-amounts tbody tr:nth-child(odd) td,
.qg-tpl-modern .qg-items tbody tr:nth-child(odd) td {
	background: var(--qg-soft);
}

.qg-tpl-modern .qg-billto {
	border-left: 0;
	border-right: 0;
}

/* Minimal — hairlines, no filled bars, colour carried by the type. */

.qg-tpl-minimal {
	border: 0;
}

.qg-tpl-minimal .qg-doc-head {
	border: 0;
	border-bottom: 1px solid var(--qg-line);
	padding-left: 0;
	padding-right: 0;
}

.qg-tpl-minimal .qg-doc-title {
	background: none;
	color: var(--qg-primary);
	text-align: left;
	padding: 14px 0 6px;
	font-size: 15px;
	border-bottom: 2px solid var(--qg-primary);
}

.qg-tpl-minimal .qg-doc-title span {
	color: var(--qg-ink);
}

.qg-tpl-minimal .qg-grid,
.qg-tpl-minimal .qg-att {
	border-left: 0;
	border-right: 0;
}

.qg-tpl-minimal .qg-grid th,
.qg-tpl-minimal .qg-grid td,
.qg-tpl-minimal .qg-att th,
.qg-tpl-minimal .qg-att td {
	border-left: 0;
	border-right: 0;
	background: none;
}

.qg-tpl-minimal .qg-att td {
	border-bottom: 1px solid var(--qg-line);
}

.qg-tpl-minimal .qg-amounts th,
.qg-tpl-minimal .qg-items th {
	background: none;
	color: var(--qg-ink);
	border: 0;
	border-bottom: 2px solid var(--qg-ink);
}

.qg-tpl-minimal .qg-amounts td,
.qg-tpl-minimal .qg-items td {
	border-left: 0;
	border-right: 0;
}

.qg-tpl-minimal .qg-net {
	background: none;
	color: var(--qg-ink);
	border: 1.5px solid var(--qg-primary);
}

.qg-tpl-minimal .qg-net-r {
	color: var(--qg-primary);
}

.qg-tpl-minimal .qg-net-l em {
	opacity: 1;
	color: var(--qg-muted, #6e7681);
}

.qg-tpl-minimal .qg-tot tr.t th {
	background: none;
	color: var(--qg-muted, #6e7681);
	border-top: 1.5px solid var(--qg-primary);
	border-bottom: 1.5px solid var(--qg-primary);
}

.qg-tpl-minimal .qg-tot tr.t td {
	background: none;
	color: var(--qg-primary);
	border-top: 1.5px solid var(--qg-primary);
	border-bottom: 1.5px solid var(--qg-primary);
}

.qg-tpl-minimal .qg-billto {
	background: none;
	border-left: 0;
	border-right: 0;
}
