/* Image to PDF Scanner — styles
   All classes prefixed .itps- to avoid theme conflicts.
   Mobile-first: base rules target small screens, larger screens are
   enhanced with a min-width media query near the bottom. */

.itps-wrapper {
	--itps-primary: #2563eb;
	--itps-primary-dark: #1d4ed8;
	--itps-success: #16a34a;
	--itps-success-dark: #15803d;
	--itps-danger: #dc2626;
	--itps-border: #e2e8f0;
	--itps-bg: #f8fafc;
	--itps-text: #1e293b;
	--itps-muted: #64748b;
	--itps-radius: 14px;

	max-width: 720px;
	margin: 0 auto;
	padding: 18px;
	background: #fff;
	border: 1px solid var(--itps-border);
	border-radius: var(--itps-radius);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var(--itps-text);
	box-sizing: border-box;
}
.itps-wrapper *,
.itps-wrapper *::before,
.itps-wrapper *::after {
	box-sizing: border-box;
}
.itps-wrapper img { max-width: none; }

.itps-header {
	margin-bottom: 16px;
	text-align: center;
}
.itps-title {
	margin: 0 0 6px;
	font-size: 19px;
	font-weight: 700;
	line-height: 1.3;
}
.itps-subtitle {
	margin: 0;
	color: var(--itps-muted);
	font-size: 13.5px;
	line-height: 1.5;
}

/* Status banner (loading / success / error) */
.itps-status {
	display: none;
	align-items: center;
	gap: 10px;
	padding: 11px 14px;
	border-radius: 10px;
	font-size: 13.5px;
	margin-bottom: 14px;
}
.itps-status.is-visible { display: flex; }
.itps-status.is-loading {
	background: #eff6ff;
	color: #1e40af;
	border: 1px solid #bfdbfe;
}
.itps-status.is-success {
	background: #f0fdf4;
	color: #166534;
	border: 1px solid #bbf7d0;
}
.itps-status.is-error {
	background: #fef2f2;
	color: #991b1b;
	border: 1px solid #fecaca;
}
.itps-status .itps-spinner-sm {
	width: 14px;
	height: 14px;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: itps-spin 0.7s linear infinite;
	flex-shrink: 0;
}

/* Dropzone / upload */
.itps-dropzone {
	border: 2px dashed var(--itps-border);
	border-radius: var(--itps-radius);
	background: var(--itps-bg);
	padding: 28px 16px;
	text-align: center;
	transition: border-color 0.15s ease, background 0.15s ease;
}
.itps-dropzone.is-dragover {
	border-color: var(--itps-primary);
	background: #eff6ff;
}
.itps-dropzone-inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	color: var(--itps-muted);
}
.itps-icon { color: var(--itps-primary); margin-bottom: 2px; }
.itps-dropzone-title { margin: 0; font-size: 15px; color: var(--itps-text); }
.itps-hint { font-size: 12px; color: #94a3b8; }
.itps-hint-sub { margin-top: 4px; }

.itps-upload-actions {
	display: flex;
	flex-direction: column;
	gap: 10px;
	width: 100%;
	max-width: 320px;
	margin: 14px 0 2px;
}
.itps-btn-upload {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
}

/* Steps */
.itps-step { margin-top: 4px; }
.itps-step-hint {
	margin: 10px 2px 0;
	font-size: 12.5px;
	color: var(--itps-muted);
	text-align: center;
}

/* Stage (canvas holder for crop + enhance) */
.itps-stage {
	position: relative;
	width: 100%;
	background: repeating-conic-gradient(#0f172a 0% 25%, #16213b 0% 50%) 0 0 / 20px 20px;
	background-color: #0f172a;
	border-radius: var(--itps-radius);
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	touch-action: none;
	min-height: 220px;
}
.itps-stage-flat { touch-action: auto; }
.itps-stage canvas {
	display: block;
	width: 100%;
	height: auto;
	max-height: 62vh;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}
.itps-stage-flat canvas { touch-action: auto; }

.itps-crop-overlay {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	touch-action: none;
}
.itps-crop-poly {
	fill: rgba(37, 99, 235, 0.22);
	stroke: #38bdf8;
	stroke-width: 3;
	vector-effect: non-scaling-stroke;
}
.itps-crop-edge {
	stroke: transparent;
	stroke-width: 26;
	fill: none;
	vector-effect: non-scaling-stroke;
	cursor: move;
}
.itps-crop-handle {
	fill: #ffffff;
	stroke: #2563eb;
	stroke-width: 3;
	vector-effect: non-scaling-stroke;
	cursor: grab;
	touch-action: none;
}
.itps-crop-handle:active { cursor: grabbing; }
.itps-crop-handle-hit {
	fill: transparent;
	cursor: grab;
	touch-action: none;
}

.itps-stage-loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(15, 23, 42, 0.55);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease;
}
.itps-stage-loading.is-active,
.itps-stage-loading:not([hidden]) {
	opacity: 1;
	pointer-events: auto;
}
.itps-spinner {
	width: 34px;
	height: 34px;
	border: 3px solid #fff;
	border-right-color: transparent;
	border-radius: 50%;
	animation: itps-spin 0.7s linear infinite;
}
@keyframes itps-spin {
	to { transform: rotate(360deg); }
}

/* Toolbar (rotate / auto-detect / reset) */
.itps-toolbar {
	display: flex;
	gap: 8px;
	margin-top: 12px;
	flex-wrap: wrap;
}
.itps-toolbar .itps-btn { flex: 1 1 auto; }
.itps-btn-icon {
	flex: 0 0 auto !important;
	width: 42px;
	padding: 10px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

/* Enhance modes */
.itps-modes {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	gap: 8px;
	margin-top: 16px;
}
.itps-mode {
	appearance: none;
	background: transparent;
	border: 2px solid transparent;
	border-radius: 10px;
	padding: 6px 2px 8px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	cursor: pointer;
	font-size: 10.5px;
	color: var(--itps-muted);
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
}
.itps-mode:hover { background: var(--itps-bg); }
.itps-mode.is-active {
	border-color: var(--itps-primary);
	background: #eff6ff;
	color: var(--itps-primary-dark);
}
.itps-mode-swatch {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 1px solid rgba(0,0,0,0.08);
}
.itps-swatch-magic { background: linear-gradient(135deg,#fca5a5,#fcd34d,#86efac,#93c5fd); }
.itps-swatch-bw { background: linear-gradient(135deg,#000,#fff 55%); }
.itps-swatch-gray { background: linear-gradient(135deg,#334155,#cbd5e1); }
.itps-swatch-lighten { background: linear-gradient(135deg,#fef9c3,#ffffff); }
.itps-swatch-original { background: linear-gradient(135deg,#a78bfa,#f472b6); }

/* Sliders */
.itps-controls {
	margin-top: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.itps-control {
	display: flex;
	flex-direction: column;
	gap: 6px;
	font-size: 12.5px;
	font-weight: 600;
	color: var(--itps-muted);
}
.itps-control input[type="range"] {
	width: 100%;
	accent-color: var(--itps-primary);
	height: 30px;
}

/* Step action rows */
.itps-step-actions {
	display: flex;
	gap: 10px;
	margin-top: 16px;
}
.itps-step-actions .itps-btn { flex: 1 1 0; }

/* Buttons */
.itps-btn {
	appearance: none;
	border: none;
	border-radius: 10px;
	padding: 13px 16px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.05s ease, opacity .15s ease;
	line-height: 1.2;
}
.itps-btn:active { transform: scale(0.98); }
.itps-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.itps-btn-primary { background: var(--itps-primary); color: #fff; }
.itps-btn-primary:hover:not(:disabled) { background: var(--itps-primary-dark); }

.itps-btn-secondary { background: #f1f5f9; color: var(--itps-text); }
.itps-btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.itps-btn-outline { background: #fff; color: var(--itps-primary); border: 1.5px solid var(--itps-primary); }
.itps-btn-outline:hover:not(:disabled) { background: #eff6ff; }

.itps-btn-ghost { background: transparent; color: var(--itps-muted); }
.itps-btn-ghost:hover:not(:disabled) { background: var(--itps-bg); }

.itps-btn-success { background: var(--itps-success); color: #fff; }
.itps-btn-success:hover:not(:disabled) { background: var(--itps-success-dark); }

.itps-btn .itps-spinner-sm { margin-right: 6px; vertical-align: -2px; }

/* Page thumbnails */
.itps-pages { margin-top: 22px; }
.itps-pages-title {
	font-size: 13px;
	font-weight: 700;
	color: var(--itps-muted);
	margin: 0 0 10px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}
.itps-page-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
	gap: 10px;
}
.itps-page-item {
	position: relative;
	border: 1px solid var(--itps-border);
	border-radius: 8px;
	overflow: hidden;
	background: var(--itps-bg);
}
.itps-page-item img {
	display: block;
	width: 100%;
	height: 118px;
	object-fit: cover;
}
.itps-page-number {
	position: absolute;
	top: 4px;
	left: 4px;
	background: rgba(15, 23, 42, 0.75);
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	padding: 2px 6px;
	border-radius: 4px;
}
.itps-page-remove {
	position: absolute;
	top: 4px;
	right: 4px;
	width: 26px;
	height: 26px;
	border: none;
	border-radius: 50%;
	background: rgba(220, 38, 38, 0.92);
	color: #fff;
	font-size: 15px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Footer actions */
.itps-footer {
	margin-top: 20px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.itps-export-group {
	display: flex;
	gap: 10px;
}
.itps-export-group .itps-btn { flex: 1 1 0; }

/* Larger screens */
@media (min-width: 601px) {
	.itps-wrapper { padding: 28px; }
	.itps-title { font-size: 22px; }
	.itps-dropzone { padding: 40px 24px; }
	.itps-upload-actions { flex-direction: row; max-width: 420px; }
	.itps-mode { font-size: 11.5px; }
	.itps-mode-swatch { width: 40px; height: 40px; }
	.itps-footer { flex-direction: row; }
	.itps-footer .itps-export-group { flex: 1 1 auto; }
	.itps-footer #itps-add-more { flex: 0 0 auto; }
}

@media (min-width: 900px) {
	.itps-wrapper { max-width: 780px; }
}
