:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1c2630;
  --muted: #687786;
  --line: #d8e0e7;
  --accent: #1368a8;
  --accent-2: #0c4f83;
  --danger: #ba2f2f;
  --soft: #eef4f8;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(23, 41, 58, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-width: 320px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 28px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 24px; margin-bottom: 3px; }
.topbar p { margin-bottom: 0; color: var(--muted); }
.scale-lock { padding: 9px 12px; border-radius: 999px; background: #eaf5ed; color: #24633a; white-space: nowrap; }
.layout { width: min(1500px, calc(100% - 32px)); margin: 18px auto 32px; display: grid; grid-template-columns: minmax(310px, 390px) minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls { overflow: hidden; }
.controls section { padding: 18px; border-bottom: 1px solid var(--line); }
.controls section:last-child { border-bottom: 0; }
h2 { font-size: 16px; margin-bottom: 13px; }
label { display: block; font-size: 12px; font-weight: 700; color: #435362; margin-top: 11px; }
input[type="text"], input[type="number"], select { width: 100%; margin-top: 6px; border: 1px solid #c9d4dd; border-radius: 9px; background: #fff; color: var(--text); padding: 10px 11px; min-height: 41px; outline: none; font: inherit; font-size: 14px; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(19,104,168,.12); }
input:disabled, select:disabled { opacity: .58; background: #f3f5f7; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dropzone { margin-top: 0; min-height: 112px; border: 2px dashed #9fb3c3; border-radius: 11px; background: #f8fbfd; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; text-align: center; cursor: pointer; transition: .15s ease; }
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: #edf6fc; }
.dropzone input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }
.drop-title { font-size: 14px; color: var(--text); }
.drop-help { margin-top: 4px; color: var(--muted); font-weight: 500; }
.file-info { font-size: 12px; margin-top: 10px; line-height: 1.5; }
.button-row { display: flex; gap: 8px; margin-top: 10px; }
button { border: 0; border-radius: 9px; padding: 10px 13px; font: inherit; font-size: 13px; font-weight: 750; cursor: pointer; transition: .15s ease; }
button:disabled { cursor: not-allowed; opacity: .48; }
button.primary { color: #fff; background: var(--accent); }
button.primary:not(:disabled):hover { background: var(--accent-2); transform: translateY(-1px); }
button.secondary { color: #364958; background: #eef2f5; }
button.secondary:not(:disabled):hover { background: #e2e8ed; }
button.full { width: 100%; margin-top: 14px; padding: 12px; }
.check-line { display: flex; gap: 9px; align-items: center; cursor: pointer; }
.check-line input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.important-check { padding: 10px; border-radius: 9px; background: var(--soft); }
.hint { margin: 8px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted); }
.muted { color: var(--muted); }
.status { min-height: 17px; margin-top: 9px; font-size: 12px; color: var(--muted); }
.status.error { color: var(--danger); }
.status.success { color: #24703e; }
.preview { min-height: 720px; padding: 18px; position: sticky; top: 96px; }
.preview-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.preview-head h2 { margin-bottom: 4px; font-size: 18px; }
.preview-head p { margin-bottom: 0; font-size: 12px; }
.page-picker { margin: 0; width: 150px; }
.canvas-wrap { min-height: 610px; border-radius: 11px; border: 1px solid var(--line); background: #dfe5e9; display: grid; place-items: center; overflow: hidden; position: relative; padding: 16px; }
#previewCanvas { display: none; max-width: 100%; max-height: 690px; box-shadow: 0 8px 25px rgba(0,0,0,.18); background: #fff; }
.empty-preview { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; color: var(--muted); }
.empty-icon { width: 68px; height: 68px; display: grid; place-items: center; border-radius: 13px; border: 2px solid #b8c5cf; font-size: 18px; font-weight: 900; }
.empty-preview strong { color: #435362; }
.empty-preview span { font-size: 12px; }
.legend { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 15px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.crop { background: rgba(30, 157, 89, .22); border: 2px solid #1e9d59; }
.swatch.original { background: #fff; border: 2px solid #246ca5; }
.swatch.blank { background: #e7ecef; border: 1px solid #c8d1d7; }
.swatch.removed { background: rgba(170, 34, 34, .28); border: 1px solid rgba(176,42,42,.65); }
@media (max-width: 950px) {
  .layout { grid-template-columns: 1fr; }
  .preview { position: static; min-height: 560px; }
  .canvas-wrap { min-height: 470px; }
}
@media (max-width: 560px) {
  .topbar { align-items: flex-start; padding: 15px; }
  .scale-lock { font-size: 11px; }
  .layout { width: min(100% - 16px, 1500px); margin-top: 8px; }
  .two-col { grid-template-columns: 1fr; }
  .preview-head { align-items: start; flex-direction: column; }
  .page-picker { width: 100%; }
}

.position-row { margin-top: 2px; }
.drag-instruction {
  margin: -2px 0 12px;
  padding: 9px 11px;
  border-radius: 9px;
  background: #eef4f8;
  color: #526574;
  font-size: 12px;
  line-height: 1.4;
}
#previewCanvas.draggable { cursor: grab; touch-action: none; user-select: none; }
#previewCanvas.dragging { cursor: grabbing; }

.button-row-wrap { flex-wrap: wrap; }
button.danger-soft { color: #8a2d2d; background: #f8eaea; }
button.danger-soft:not(:disabled):hover { background: #f1dada; }
.preview-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; min-width: 300px; }
.zoom-control { display: flex; align-items: center; justify-content: flex-end; gap: 7px; width: 100%; }
.zoom-control input[type="range"] { width: min(190px, 32vw); min-height: 0; margin: 0; padding: 0; border: 0; box-shadow: none; background: transparent; }
.zoom-button { min-width: 38px; min-height: 38px; padding: 6px 10px; font-size: 18px; line-height: 1; }
#zoomValue { min-width: 48px; text-align: center; font-size: 12px; font-weight: 800; color: #435362; }
.zoom-note { color: var(--muted); font-size: 11px; text-align: right; }
.canvas-wrap { overflow: auto; display: block; padding: 16px; }
.canvas-stage { min-width: 100%; min-height: 610px; display: flex; align-items: flex-start; justify-content: center; }
#previewCanvas { max-width: none; max-height: none; flex: 0 0 auto; }
@media (max-width: 700px) {
  .preview-tools { width: 100%; min-width: 0; align-items: stretch; }
  .zoom-control { justify-content: flex-start; flex-wrap: wrap; }
  .zoom-control input[type="range"] { flex: 1 1 130px; width: auto; }
  .zoom-note { text-align: left; }
}
