/* ------------------------------------------------------------------ *
 * Labelprinter – modern, build-free UI
 * ------------------------------------------------------------------ */

:root {
	--bg: #0f172a;
	--surface: #ffffff;
	--surface-2: #f1f5f9;
	--border: #e2e8f0;
	--text: #0f172a;
	--muted: #64748b;
	--primary: #2563eb;
	--primary-600: #1d4ed8;
	--accent: #10b981;
	--danger: #ef4444;
	--radius: 10px;
	--shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .08);
	--font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
}

body {
	font-family: var(--font);
	color: var(--text);
	background: var(--surface-2);
	display: flex;
	flex-direction: column;
}

/* ----------------------------- Topbar ----------------------------- */

.topbar {
	display: flex;
	align-items: center;
	gap: 20px;
	padding: 10px 16px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow);
	z-index: 5;
}

.brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 16px;
	white-space: nowrap;
}

.logo-dot {
	width: 20px;
	height: 20px;
	display: block;
}

.toolbar {
	display: flex;
	align-items: center;
	gap: 14px;
	flex: 1;
	flex-wrap: wrap;
}

.group {
	display: flex;
	gap: 6px;
}

.group.grow { flex: 1; }

button {
	font: inherit;
	font-size: 13px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 7px 12px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	border-radius: 8px;
	cursor: pointer;
	transition: background .12s, border-color .12s, transform .04s;
}

button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }

button.primary {
	background: var(--primary);
	border-color: var(--primary);
	color: #fff;
}
button.primary:hover { background: var(--primary-600); }

button.danger {
	color: var(--danger);
	border-color: #fecaca;
	background: #fef2f2;
}

.ic {
	font-size: 13px;
	line-height: 1;
	opacity: .8;
}

/* --------------------------- Workspace ---------------------------- */

.workspace {
	flex: 1;
	display: flex;
	min-height: 0;
}

.stage-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.stage-scroll {
	flex: 1;
	overflow: auto;
	padding: 32px;
	display: flex;
	align-items: flex-start;
	justify-content: center;
}

.stage {
	position: relative;
	background:
		linear-gradient(45deg, #fafafa 25%, transparent 25%, transparent 75%, #fafafa 75%) 0 0/20px 20px,
		linear-gradient(45deg, #fafafa 25%, #fff 25%, #fff 75%, #fafafa 75%) 10px 10px/20px 20px,
		#fff;
	border: 1px solid #94a3b8;
	box-shadow: var(--shadow);
	flex: none;
}

.status {
	padding: 8px 16px;
	font-size: 12px;
	color: var(--muted);
	background: var(--surface);
	border-top: 1px solid var(--border);
}

/* --------------------------- Elements ----------------------------- */

.el {
	position: absolute;
	overflow: hidden;
	cursor: grab;
	touch-action: none;
	border: 1px dashed transparent;
}

.el:hover { border-color: #cbd5e1; }

.el.selected {
	border: 1px solid var(--primary);
	box-shadow: 0 0 0 2px rgba(37, 99, 235, .2);
}

.el.text {
	display: flex;
	align-items: center;
	line-height: 1.1;
	white-space: pre-wrap;
	word-break: break-word;
}

.el.qr { display: flex; }
.el.qr img, .el.qr canvas, .el.qr table { width: 100% !important; height: 100% !important; }

.el.logo img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	pointer-events: none;
}

.handle {
	position: absolute;
	right: -5px;
	bottom: -5px;
	width: 12px;
	height: 12px;
	background: var(--primary);
	border: 2px solid #fff;
	border-radius: 50%;
	cursor: nwse-resize;
}
.el:not(.selected) .handle { display: none; }

/* --------------------------- Inspector ---------------------------- */

.inspector {
	width: 290px;
	flex: none;
	background: var(--surface);
	border-left: 1px solid var(--border);
	padding: 16px;
	overflow: auto;
}

.inspector h2 {
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
	margin: 0 0 12px;
}

.field {
	margin-bottom: 12px;
}

.field label {
	display: block;
	font-size: 12px;
	color: var(--muted);
	margin-bottom: 4px;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
	width: 100%;
	font: inherit;
	font-size: 13px;
	padding: 7px 9px;
	border: 1px solid var(--border);
	border-radius: 8px;
	background: var(--surface);
	color: var(--text);
}

.field textarea { resize: vertical; min-height: 56px; }

.row2 { display: flex; gap: 8px; }
.row2 .field { flex: 1; }

.check {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	margin-bottom: 12px;
	cursor: pointer;
}

.seg {
	display: flex;
	border: 1px solid var(--border);
	border-radius: 8px;
	overflow: hidden;
}
.seg button {
	flex: 1;
	border: none;
	border-radius: 0;
	border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--primary); color: #fff; }

.hint {
	font-size: 12px;
	color: var(--muted);
	line-height: 1.5;
}

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ----------------------------- Output ----------------------------- */

.overlay {
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, .55);
	z-index: 20;
	display: flex;
	flex-direction: column;
}

.overlay-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}
.overlay-bar .spacer { flex: 1; }
.overlay-bar #outputInfo { font-size: 13px; color: var(--muted); }

.print-area {
	flex: 1;
	overflow: auto;
	padding: 24px;
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-content: flex-start;
	justify-content: center;
}

.label {
	position: relative;
	background: #fff;
	box-shadow: var(--shadow);
}

.label .l-text {
	position: absolute;
	display: flex;
	align-items: center;
	line-height: 1.1;
	white-space: pre-wrap;
	word-break: break-word;
	overflow: hidden;
}
.label .l-qr { position: absolute; }
.label .l-qr img, .label .l-qr canvas, .label .l-qr table { width: 100% !important; height: 100% !important; }
.label .l-logo { position: absolute; }
.label .l-logo img { width: 100%; height: 100%; object-fit: contain; }

/* ----------------------------- Toast ------------------------------ */

.toast {
	position: fixed;
	left: 50%;
	bottom: 28px;
	transform: translateX(-50%);
	background: var(--bg);
	color: #fff;
	padding: 12px 18px;
	border-radius: 10px;
	font-size: 13px;
	box-shadow: var(--shadow);
	z-index: 50;
	max-width: 80vw;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--accent); }

.hidden { display: none !important; }

/* ----------------------------- Footer ----------------------------- */

.appfoot {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 8px 16px;
	background: var(--surface);
	border-top: 1px solid var(--border);
	font-size: 12px;
	color: var(--muted);
}

.footer-links {
	display: flex;
	gap: 6px;
}

.footer-links button {
	border: none;
	background: none;
	padding: 4px 6px;
	font-size: 12px;
	color: var(--muted);
	text-decoration: underline;
	cursor: pointer;
}
.footer-links button:hover { color: var(--primary); background: none; }

.footer-links .donate-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 12px;
	border-radius: 999px;
	background: var(--primary);
	color: #fff;
	text-decoration: none;
}
.footer-links .donate-btn:hover { background: var(--primary-600); color: #fff; }

/* ----------------------------- Modal ------------------------------ */

.modal {
	position: fixed;
	inset: 0;
	z-index: 100;
}
.modal[hidden] { display: none; }

.modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(15, 23, 42, .55);
	backdrop-filter: blur(3px);
}

.modal-box {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: min(760px, calc(100vw - 32px));
	max-height: calc(100vh - 64px);
	overflow-y: auto;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	box-shadow: var(--shadow);
	padding: 28px 30px;
}

.modal-close {
	position: absolute;
	top: 14px;
	right: 14px;
	width: 32px;
	height: 32px;
	border: none;
	border-radius: 50%;
	background: var(--surface-2);
	color: var(--muted);
	cursor: pointer;
	font-size: 15px;
	line-height: 1;
}
.modal-close:hover { background: var(--primary); color: #fff; }

.legal h2 { margin: 0 0 4px; font-size: 22px; color: var(--text); }
.legal h3 { margin: 22px 0 4px; font-size: 15px; color: var(--text); }
.legal p, .legal li { color: var(--text); line-height: 1.6; font-size: 14px; }
.legal .muted { color: var(--muted); }
.legal a { color: var(--primary); }
.legal ul { margin: 8px 0; padding-left: 22px; list-style: disc outside; }
.legal li { margin: 3px 0; }

/* ----------------------------- Donate ----------------------------- */

.modal-box--narrow { width: min(420px, calc(100vw - 32px)); }

.donate { text-align: center; }
.donate-icon {
	width: 48px;
	height: 48px;
	margin: 0 auto 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 14px;
	background: rgba(37, 99, 235, .1);
	color: var(--primary);
	font-size: 22px;
}
.donate h2 { margin: 0 0 8px; font-size: 20px; color: var(--text); }
.donate > p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.donate-paypal {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	background: #0070ba;
	color: #fff;
	padding: 12px;
	border-radius: 12px;
	font-weight: 700;
	text-decoration: none;
	margin-bottom: 12px;
}
.donate-paypal:hover { background: #005a96; }
.crypto {
	display: flex;
	align-items: center;
	gap: 8px;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 8px 10px;
	margin-top: 8px;
}
.crypto .sym {
	font-size: 11px;
	font-weight: 800;
	letter-spacing: .05em;
	color: var(--primary);
	width: 30px;
	flex: none;
}
.crypto code {
	font-size: 12px;
	color: var(--text);
	font-family: ui-monospace, monospace;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
	user-select: all;
}
.copy-btn {
	border: none;
	background: none;
	color: var(--muted);
	cursor: pointer;
	padding: 2px 6px;
	flex: none;
	font-size: 12px;
}
.copy-btn:hover { color: var(--primary); }

/* ----------------------------- Print ------------------------------ */

@media print {
	/* Remove ALL app chrome from the layout (display:none, not visibility:hidden,
	   so nothing reserves space and produces blank pages). Print the labels only. */
	.topbar, .workspace, .appfoot, .toast, .modal, .overlay-bar { display: none !important; }

	#output {
		position: static;
		inset: auto;
		display: block !important;
		background: #fff;
	}
	.print-area {
		display: block;
		padding: 0;
		margin: 0;
		gap: 0;
		overflow: visible;
	}
	/* Tile labels in rows/columns (float, like the old code) to pack as many
	   per page as fit – minimum paper. Each label is kept whole across pages. */
	.label {
		float: left;
		box-shadow: none;
		margin: 0;
		page-break-inside: avoid;
		break-inside: avoid;
	}
}
