[hidden] { display: none !important; }
:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2563eb; --accent-ink: #fff; --danger: #c62828; --stage: #3a3f4a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: #c5cad3; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; }
.btn.wide { width: 100%; display: block; text-align: center; }

/* login */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.login-card .logo { font-size: 28px; color: var(--accent); }
.login-card label { display: block; margin: 10px 0 6px; font-weight: 600; }
.login-card input[type=password] { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.login-card .check { font-weight: 400; display: flex; gap: 8px; align-items: center; margin: 14px 0 18px; }
.msg.error { background: #fdecea; color: var(--danger); border-radius: 8px; padding: 10px 12px; }

/* app */
.topbar { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 700; }
.topbar .printer { color: var(--muted); font-size: 12px; margin-right: auto; }
.topbar form { margin: 0; }
.layout { display: flex; height: calc(100% - 52px); }
.panel { width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.panel section { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border: 0; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row.end { justify-content: flex-end; }
.row input[type=range] { flex: 1; }
.row input[type=number] { width: 70px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; word-break: break-word; }
#pageinfo { flex: 1; text-align: center; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { flex: 1; border: 0; background: #fff; padding: 8px; font: inherit; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

.stage { position: relative; flex: 1; overflow: hidden; background: var(--stage); touch-action: none; cursor: grab; user-select: none; }
.stage.dragging { cursor: grabbing; }
.stage.dropping { outline: 3px dashed #93c5fd; outline-offset: -8px; }
#pageimg { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.4); image-rendering: auto; pointer-events: none; }
.box { position: absolute; border: 2px solid #ef4444; box-shadow: 0 0 0 9999px rgba(20,22,28,.55); pointer-events: none; }
.box span { position: absolute; top: -24px; left: -2px; background: #ef4444; color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px 4px 0 0; white-space: nowrap; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: #d1d5db; font-size: 16px; pointer-events: none; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; padding: 16px; max-width: 95vw; max-height: 95vh; display: flex; flex-direction: column; gap: 10px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
#previewImg { max-height: 72vh; max-width: 85vw; object-fit: contain; border: 1px solid var(--line); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .layout { flex-direction: column-reverse; }
  .panel { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--line); }
  .stage { min-height: 55%; }
  .topbar .printer { display: none; }
}

/* history */
.history-card { width: 720px; }
.history-list { overflow-y: auto; max-height: 75vh; display: flex; flex-direction: column; gap: 8px; }
.job { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.job img { width: 72px; height: 96px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 4px; flex: none; }
.job .meta { flex: 1; min-width: 0; }
.job .meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn.danger { color: var(--danger); }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #e8f0fe; color: var(--accent); }
.badge.none { background: #f1f3f5; color: var(--muted); }
@media (max-width: 760px) { .job { flex-wrap: wrap; } .job .actions { width: 100%; } }
