/*
 * Tainacan Impressão de Itens — folha.
 *
 * As medidas vêm em mm por variáveis (--tip-*), calculadas no PHP a partir do
 * modelo e trocadas pelo JS quando o visitante muda folha ou orientação.
 * Área útil = folha − margens − cabeçalho − rodapé.
 */

*,
*::before,
*::after { box-sizing: border-box; }

:root {
	--tip-useful-h: calc(var(--tip-ph) - var(--tip-mt) - var(--tip-mb) - var(--tip-hdr) - var(--tip-ftr));
	--tip-ink: #1b1b1b;
	--tip-muted: #5b5b5b;
	--tip-rule: #c9c9c9;
}

html { -webkit-text-size-adjust: 100%; }

body {
	margin: 0;
	color: var(--tip-ink);
	font-family: var(--tip-font);
	font-size: var(--tip-fs);
	line-height: 1.45;
	-webkit-print-color-adjust: exact;
	print-color-adjust: exact;
}

.tip-off { display: none !important; }

/* ------------------------------------------------------------------ */
/* Barra de ferramentas (só tela)                                      */
/* ------------------------------------------------------------------ */

.tip-toolbar {
	position: sticky;
	top: 0;
	z-index: 10;
	padding: 10px 16px 6px;
	background: #fff;
	border-bottom: 1px solid #ddd;
	box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
	font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	color: #222;
}

.tip-toolbar__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 14px;
	max-width: 1100px;
	margin: 0 auto;
}

.tip-toolbar__hint {
	max-width: 1100px;
	margin: 6px auto 0;
	font-size: 12px;
	color: #666;
}

.tip-tb-back { color: #333; text-decoration: none; margin-right: auto; }
.tip-tb-back:hover { text-decoration: underline; }

.tip-tb-field { display: inline-flex; align-items: center; gap: 6px; }
.tip-tb-field > span { color: #666; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.tip-toolbar select,
.tip-tb-fs button,
.tip-tb-pick summary {
	font: inherit;
	padding: 5px 8px;
	border: 1px solid #c8c8c8;
	border-radius: 6px;
	background: #fff;
	color: #222;
	cursor: pointer;
}

.tip-tb-fs output { min-width: 3.4em; text-align: center; font-variant-numeric: tabular-nums; }

.tip-tb-pick { position: relative; }
.tip-tb-pick summary { list-style: none; }
.tip-tb-pick summary::-webkit-details-marker { display: none; }
.tip-tb-pick summary::after { content: " ▾"; color: #888; }

.tip-tb-panel {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 20;
	width: max-content;
	min-width: 240px;
	max-width: min(420px, 90vw);
	max-height: 60vh;
	overflow: auto;
	padding: 8px 10px;
	background: #fff;
	border: 1px solid #ccc;
	border-radius: 8px;
	box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
}

.tip-tb-panel label { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.tip-tb-panel--img { display: grid; grid-template-columns: repeat(3, 96px); gap: 6px; }
.tip-tb-panel--img img { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; }

.tip-tb-check { display: inline-flex; align-items: center; gap: 5px; }

.tip-tb-print {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 8px 16px;
	border: 0;
	border-radius: 999px;
	background: var(--tip-accent);
	color: #fff;
	font: 600 14px/1 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.tip-tb-print:hover { filter: brightness(1.08); }
.tip-tb-print:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; }
.tip-tb-print[disabled] { opacity: .6; cursor: progress; }

/* ------------------------------------------------------------------ */
/* Folha na tela: simula o papel                                        */
/* ------------------------------------------------------------------ */

@media screen {
	body { background: #e8e6e1; }

	.tip-sheet {
		position: relative;
		width: var(--tip-pw);
		min-height: var(--tip-ph);
		margin: 24px auto 48px;
		padding: var(--tip-mt) var(--tip-mr) var(--tip-mb) var(--tip-ml);
		background: #fff;
		box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 10px 30px rgba(0, 0, 0, .08);
	}

	.tip-footer { margin-top: 6mm; }
	.tip-footer-space { display: none; }

	/* Quebras forçadas viram uma linha tracejada na pré-visualização. */
	.tip-fullpage { margin-top: 10mm; padding-top: 10mm; border-top: 1px dashed #bbb; }
}

@media screen and (max-width: 900px) {
	.tip-sheet { width: auto; min-height: 0; margin: 12px; padding: 16px; }
}

/* ------------------------------------------------------------------ */
/* Papel                                                               */
/* ------------------------------------------------------------------ */

@media print {
	.tip-toolbar { display: none !important; }

	html,
	body { background: none; }

	.tip-sheet { width: auto; margin: 0; padding: 0; }

	/* O rodapé fixo se repete em cada página; o espaço no <tfoot> impede que
	   o texto corra por baixo dele. No lote o rodapé já está no <tfoot> de
	   cada item (a URL muda de item para item), então não é fixo. */
	.tip-sheet:not(.tip-sheet--batch) > .tip-footer {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		height: var(--tip-ftr);
		background: #fff;
	}

	.tip-footer-space { height: var(--tip-ftr); }
}

/* Moldura: <thead> se repete no topo de cada página impressa. */
.tip-frame {
	width: 100%;
	border-collapse: collapse;
	border-spacing: 0;
}

.tip-frame > thead { display: table-header-group; }
.tip-frame > tfoot { display: table-footer-group; }
.tip-frame > * > tr > td { padding: 0; vertical-align: top; }

/* ------------------------------------------------------------------ */
/* Cabeçalho institucional                                             */
/* ------------------------------------------------------------------ */

.tip-header {
	display: flex;
	align-items: center;
	gap: 5mm;
	padding-bottom: 3mm;
	margin-bottom: 5mm;
	border-bottom: .6pt solid var(--tip-accent);
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	break-inside: avoid;
}

.tip--no-rule .tip-header { border-bottom: 0; }

.tip-header__logo {
	display: block;
	height: var(--tip-logo-h);
	width: auto;
	max-width: 60mm;
	object-fit: contain;
}

.tip-header__text { flex: 1 1 auto; min-width: 0; }
.tip-header__name { font-size: 1.15em; font-weight: 700; color: var(--tip-accent); line-height: 1.2; }
.tip-header__subtitle { font-size: .85em; color: var(--tip-muted); }
.tip-header__line { font-size: .75em; color: var(--tip-muted); }

.tip-header__aside {
	flex: 0 1 48%;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 1.5mm;
	text-align: right;
}

.tip-header__logo2 { display: block; height: calc(var(--tip-logo-h) * .8); width: auto; max-width: 45mm; object-fit: contain; }
.tip-header__source { font-size: .8em; font-weight: 600; color: var(--tip-ink); line-height: 1.25; text-wrap: balance; }

.tip--header-center .tip-header { flex-direction: column; text-align: center; gap: 2mm; }
.tip--header-center .tip-header__aside { align-items: center; text-align: center; }
.tip--header-split .tip-header__text { text-align: center; }

/* ------------------------------------------------------------------ */
/* Título                                                              */
/* ------------------------------------------------------------------ */

.tip-title {
	display: flex;
	align-items: flex-start;
	gap: 6mm;
	margin-bottom: 5mm;
	break-inside: avoid;
	break-after: avoid;
}

.tip-title__text { flex: 1 1 auto; min-width: 0; }

.tip-title__kicker {
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: .72em;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--tip-muted);
	margin-bottom: 1mm;
}

.tip-title h1 {
	margin: 0;
	font-size: 1.75em;
	line-height: 1.15;
	font-weight: 700;
	overflow-wrap: anywhere;
}

.tip-qr {
	flex: 0 0 auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1mm;
	width: var(--tip-qr);
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: 6.5pt;
	color: var(--tip-muted);
	text-align: center;
}

.tip-qr svg { display: block; width: var(--tip-qr); height: var(--tip-qr); }
.tip-qr--footer,
.tip-qr--footer svg { width: 12mm; height: 12mm; }
.tip--no-qr .tip-qr { display: none; }

/* ------------------------------------------------------------------ */
/* Imagens                                                             */
/* ------------------------------------------------------------------ */

.tip-media { margin-bottom: 6mm; }

.tip-figure {
	margin: 0;
	break-inside: avoid;
	text-align: center;
}

.tip-figure img {
	display: block;
	margin: 0 auto;
	max-width: 100%;
	height: auto;
	object-fit: contain;
}

.tip-figure--main img { max-height: calc((var(--tip-useful-h) - 22mm) * var(--tip-img-pct) / 100); }

.tip-figure figcaption {
	margin-top: 1.5mm;
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: .75em;
	color: var(--tip-muted);
}

.tip-grid {
	display: grid;
	grid-template-columns: repeat(var(--tip-grid), minmax(0, 1fr));
	gap: 3mm;
	margin-top: 4mm;
}

.tip-figure--thumb img { max-height: 45mm; }

.tip-fullpage { break-before: page; }
.tip-figure--page img { max-height: calc(var(--tip-useful-h) - 12mm); }

.tip-note {
	margin: 2mm 0 0;
	font-size: .8em;
	font-style: italic;
	color: var(--tip-muted);
	text-align: center;
	overflow-wrap: anywhere;
}

.tip--gray img { filter: grayscale(1); }

/* Imagem ao lado dos metadados. Float, não grade: depois que a imagem acaba,
   o texto volta a ocupar a largura toda — com grade, a coluna da imagem
   ficava vazia em todas as páginas seguintes. */
.tip-body--side::after { content: ""; display: block; clear: both; }

.tip-body--side .tip-media {
	float: left;
	width: 45%;
	margin: 0 8mm 4mm 0;
}

.tip-body--side .tip-section__name { overflow: hidden; }
.tip-body--side .tip-figure--main img { max-height: calc((var(--tip-useful-h) - 22mm) * var(--tip-img-pct) / 100); }
.tip-body--side .tip-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tip-body--side .tip-figure--thumb img { max-height: 25mm; }

/* ------------------------------------------------------------------ */
/* Metadados                                                           */
/* ------------------------------------------------------------------ */

.tip-section { margin-bottom: 4mm; }

.tip-section__name {
	margin: 0 0 2.5mm;
	padding-bottom: 1mm;
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: .95em;
	font-weight: 700;
	color: var(--tip-accent);
	border-bottom: .4pt solid var(--tip-rule);
	break-after: avoid;
	column-span: all;
}

.tip-list { margin: 0; }

.tip--cols-2 .tip-list { column-count: 2; column-gap: 8mm; }
.tip--layout-side .tip-list { column-count: 1; }

.tip-md {
	margin: 0 0 2.6mm;
	break-inside: avoid;
	orphans: 3;
	widows: 3;
}

/* Texto longo (descrição) ocupa a largura toda e pode quebrar de página. */
.tip-md--long { column-span: all; break-inside: auto; margin-top: 2.6mm; }

.tip-md dt {
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: .72em;
	font-weight: 700;
	letter-spacing: .05em;
	text-transform: uppercase;
	color: var(--tip-muted);
	break-after: avoid;
}

.tip-md dd {
	margin: .3mm 0 0;
	overflow-wrap: anywhere;
}

.tip-md p { margin: 0 0 1.5mm; }
.tip-md p:last-child { margin-bottom: 0; }
.tip-md dd label { font-weight: 700; }
.tip-md dd .tip-sep,
.tip-md dd .multivalue-separator { color: var(--tip-muted); }

/* Rótulo na linha: "Rótulo: valor". */
.tip--labels-inline .tip-md dt { display: inline; font-size: .8em; }
.tip--labels-inline .tip-md dt::after { content: ": "; }
.tip--labels-inline .tip-md dd { display: inline; margin: 0; }

/* Sem rótulo (etiqueta de exposição): o primeiro valor em destaque. */
.tip--labels-hidden .tip-md dt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.tip--labels-hidden .tip-md { margin-bottom: 1mm; }
.tip--labels-hidden .tip-list { column-count: 1; }

/* Tabela (ficha catalográfica). */
.tip-table {
	width: 100%;
	border-collapse: collapse;
	font-size: .95em;
}

.tip-table th,
.tip-table td {
	padding: 1.6mm 2mm;
	border: .4pt solid var(--tip-rule);
	vertical-align: top;
	text-align: left;
	overflow-wrap: anywhere;
}

.tip-table th {
	width: 32%;
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: .82em;
	font-weight: 700;
	background: #f4f4f2;
}

.tip-table tr { break-inside: avoid; }
.tip-table tr.tip-md--long { break-inside: auto; }

.tip-text-document { font-size: .95em; }

/* ------------------------------------------------------------------ */
/* Citação e rodapé                                                    */
/* ------------------------------------------------------------------ */

.tip-citation {
	margin-top: 4mm;
	padding-top: 2.5mm;
	border-top: .4pt solid var(--tip-rule);
	font-size: .78em;
	color: var(--tip-muted);
	overflow-wrap: anywhere;
	/* Pode quebrar: com "avoid", uma citação de 3 linhas empurrava uma folha
	   inteira a mais — em lote, centenas de folhas desperdiçadas. */
	orphans: 2;
	widows: 2;
}

.tip-citation strong { display: block; color: var(--tip-ink); margin-bottom: .5mm; break-after: avoid; }

.tip-footer {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 6mm;
	padding-top: 1.5mm;
	border-top: .4pt solid var(--tip-rule);
	font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	font-size: 7.5pt;
	line-height: 1.3;
	color: var(--tip-muted);
}

.tip-footer__left { display: flex; flex-direction: column; min-width: 0; }
.tip-footer__right { display: flex; align-items: flex-end; gap: 3mm; text-align: right; }
.tip-footer__url { overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ */
/* Lote: um item por folha                                             */
/* ------------------------------------------------------------------ */

.tip-sheet--batch + .tip-sheet--batch { break-before: page; }
.tip-sheet--batch .tip-footer { margin-top: 4mm; }

.tip--no-img .tip-media,
.tip--no-img .tip-fullpage,
.tip--no-img .tip-note { display: none !important; }

.tip-toolbar__row--opts { margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee; }

.tip-batch-status {
	display: grid;
	gap: 3px;
	flex: 1 1 280px;
	min-width: 220px;
}

.tip-batch-status__text { font-weight: 600; }
.tip-batch-status__meta { font-size: 12px; color: #666; }
.tip-batch-status progress { width: 100%; height: 8px; accent-color: var(--tip-accent); }

.tip-tb-stop {
	font: inherit;
	padding: 7px 14px;
	border: 1px solid #c8c8c8;
	border-radius: 999px;
	background: #fff;
	color: #222;
	cursor: pointer;
}

@media screen {
	.tip-batch { padding-bottom: 40px; }
	.tip-batch .tip-sheet { margin: 18px auto; }
}

/* Baixar planilha (XLSX/CSV), ao lado de "Imprimir / salvar PDF". */
.tip-tb-export { display: inline-flex; gap: 6px; }
.tip-tb-export a {
	display: inline-flex;
	align-items: center;
	padding: 7px 12px;
	border: 1.5px solid var(--tip-accent);
	border-radius: 999px;
	color: var(--tip-accent);
	font: 600 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	letter-spacing: .03em;
	text-decoration: none;
}
.tip-tb-export a:hover { background: var(--tip-accent); color: #fff; }
.tip-tb-export a:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; }
