*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Nirmala UI", system-ui, -apple-system, sans-serif;
  background: #e9edf3;
  color: #17202e;
  height: 100vh;
  display: flex;
  overflow: hidden;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ---------------- panel ---------------- */
.panel {
  width: 360px;
  flex: 0 0 360px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: #fff;
  border-right: 1px solid #dbe1ea;
  padding: 14px 14px 30px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  scrollbar-width: thin;
}
.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; border: 2px solid #fff; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
}
.brand h1 { font-size: 14.5px; margin: 0; line-height: 1.25; }
.brand p { margin: 2px 0 0; font-size: 11px; color: #6b7a90; }

.tabs { display: flex; gap: 5px; background: #eef2f8; padding: 4px; border-radius: 10px; }
.tabs button {
  flex: 1; font: inherit; font-size: 12.5px; font-weight: 600; padding: 8px 4px;
  border: 0; border-radius: 7px; background: transparent; color: #5c6c84; cursor: pointer;
}
.tabs button.on { background: #fff; color: #1d4ed8; box-shadow: 0 1px 3px rgba(16, 30, 54, .13); }

.section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: #8090a6; font-weight: 700; margin: 0 0 6px;
}
.block { border-top: 1px solid #eef2f8; padding-top: 11px; }
.block:first-of-type { border-top: 0; padding-top: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.seg.three { grid-template-columns: 1fr 1fr 1fr; }
.seg button {
  font: inherit; font-size: 11.5px; padding: 7px 4px; cursor: pointer;
  border: 1px solid #d7dfeb; background: #fff; color: #33445c;
  border-radius: 7px; transition: all .12s; line-height: 1.2;
}
.seg button:hover { border-color: #93b4ea; }
.seg button.on { background: #2563eb; border-color: #2563eb; color: #fff; font-weight: 600; }

.row { display: flex; align-items: center; gap: 9px; margin-top: 8px; }
.row > label { font-size: 11px; color: #4a5a72; width: 58px; flex: 0 0 58px; }
.row input[type=range] { flex: 1; min-width: 0; accent-color: #2563eb; height: 16px; }
.row output { font-size: 10.5px; color: #6b7a90; width: 42px; text-align: right; font-variant-numeric: tabular-nums; flex: 0 0 42px; }

.check { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: #33445c; margin-top: 7px; cursor: pointer; }
.check input { accent-color: #2563eb; width: 14px; height: 14px; flex: 0 0 14px; }

/* ---------------- image slots ---------------- */
#slots { display: flex; flex-direction: column; gap: 10px; }
.slot { border: 1px solid #e4eaf3; border-radius: 10px; padding: 9px; background: #fbfcfe; }
.slot-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.slot-title { font-size: 12px; font-weight: 600; }
.slot-actions { display: flex; gap: 8px; }

.linkbtn {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  font-size: 11px; color: #2563eb; text-decoration: underline;
}
.linkbtn:hover { color: #1d4ed8; }
.linkbtn.danger { color: #b91c1c; }

.drop {
  display: block; border: 1.5px dashed #c6d2e2; border-radius: 8px;
  background: #fff; cursor: pointer; overflow: hidden;
  transition: border-color .15s, background .15s; position: relative;
}
.drop:hover, .drop.over { border-color: #2563eb; background: #f4f9ff; }
.drop .ph { padding: 14px 8px; text-align: center; font-size: 10.5px; color: #8090a6; line-height: 1.4; }
.drop .ph b { display: block; font-size: 12px; color: #33445c; margin-bottom: 2px; }
.drop img { width: 100%; height: 86px; object-fit: contain; display: block; background: #fff; }

.editor { margin-top: 8px; }
.editor .row { margin-top: 5px; }
.editor .row > label { width: 48px; flex: 0 0 48px; font-size: 10.5px; }
.editor .row output { width: 34px; flex: 0 0 34px; font-size: 10px; }

.tools { display: flex; gap: 5px; margin-top: 7px; }
.tools button {
  flex: 1; font: inherit; font-size: 10.5px; padding: 5px 2px; cursor: pointer;
  border: 1px solid #d7dfeb; background: #fff; color: #33445c; border-radius: 6px;
}
.tools button:hover { border-color: #93b4ea; background: #f5f9ff; }
.tools button.on { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }

.dpi { margin-top: 6px; font-size: 10px; line-height: 1.3; }
.dpi.ok { color: #15803d; }
.dpi.mid { color: #b45309; }
.dpi.low { color: #b91c1c; }

/* ---------------- action buttons ---------------- */
.printbtn {
  width: 100%; padding: 11px; border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #4f46e5); color: #fff;
  font: inherit; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .28);
}
.printbtn:hover { filter: brightness(1.06); }
.printbtn:active { transform: translateY(1px); }

.btnrow { display: flex; gap: 7px; }
.btnrow > * { flex: 1; }
.btn2 {
  padding: 9px; border: 1px solid #d7dfeb; border-radius: 9px; background: #fff;
  color: #33445c; font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.btn2:hover { border-color: #93b4ea; background: #f5f9ff; }
.btn2.danger { color: #b91c1c; border-color: #e5c0c0; }
.btn2.danger:hover { background: #fdf5f5; border-color: #d99b9b; }

.hint {
  font-size: 10.5px; line-height: 1.5; color: #6b7a90;
  background: #f4f7fb; border: 1px solid #e2e8f1; border-radius: 8px; padding: 8px 9px;
}
.hint b { color: #33445c; }
.hint ul { margin: 3px 0 0; padding-left: 14px; }

.sig { margin-top: auto; font-size: 10px; color: #93a2b8; text-align: center; padding-top: 8px; }

/* ---------------- stage ---------------- */
.stage {
  flex: 1; min-width: 0; height: 100vh; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center; padding: 22px;
}
.holder { position: relative; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page-holder { position: relative; flex: 0 0 auto; }
.sheet {
  background: #fff; position: relative; overflow: hidden;
  transform-origin: top left;
  box-shadow: 0 6px 28px rgba(23, 32, 46, .16);
}

.cell { position: absolute; overflow: hidden; background: #fff; }
.cell .imgwrap { position: absolute; inset: 0; transform-origin: center center; will-change: transform; }
.cell img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  user-select: none; -webkit-user-drag: none;
}
.cell.empty { background: #f6f8fc; border: 0.3mm dashed #c2cddc; }
.cell.empty::after {
  content: attr(data-label); position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 3.2mm; letter-spacing: .16em; color: #a8b6c8; font-weight: 600;
}
.cell.cut { outline: 0.15mm dashed #b9c4d2; outline-offset: 1.4mm; }
.sheet.dragging { cursor: grabbing; }
.sheet.dragging .cell { cursor: grabbing; }
.cell.pannable { cursor: grab; }

/* align overlay */
.alignline {
  position: absolute; height: 0; border-top: 0.3mm solid #ef4444;
  transform-origin: 0 0; pointer-events: none; z-index: 5;
}
.cell.aligning { cursor: crosshair; }

/* ---------------- modal ---------------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(12, 20, 33, .62);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 18px;
}
.modal {
  background: #fff; border-radius: 14px; width: min(980px, 100%); max-height: 94vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px rgba(8, 15, 28, .35);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid #eef2f8;
}
.modal-head h2 { margin: 0; font-size: 14.5px; }
.modal-head p { margin: 2px 0 0; font-size: 11px; color: #7b8ba1; }
.modal-body { padding: 14px 16px; overflow: auto; flex: 1; }
.modal-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 16px; border-top: 1px solid #eef2f8; background: #fbfcfe;
}
.modal-foot .spacer { flex: 1; }

.closebtn {
  border: 0; background: #f1f5f9; width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; font-size: 15px; color: #4a5a72; line-height: 1;
}
.closebtn:hover { background: #e2e8f0; }

.zoombar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.zoombar button {
  font: inherit; font-size: 12px; min-width: 30px; height: 28px; padding: 0 9px;
  border: 1px solid #d7dfeb; background: #fff; border-radius: 7px;
  cursor: pointer; color: #33445c; line-height: 1;
}
.zoombar button:hover { border-color: #93b4ea; background: #f5f9ff; }
.zoombar span { font-size: 11.5px; color: #4a5a72; min-width: 42px; text-align: center; }

.croptools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.croptools button {
  font: inherit; font-size: 11.5px; height: 28px; padding: 0 10px;
  border: 1px solid #d7dfeb; background: #fff; border-radius: 7px;
  cursor: pointer; color: #33445c; line-height: 1;
}
.croptools button:hover { border-color: #93b4ea; background: #f5f9ff; }
.croptools button.on { border-color: #2563eb; background: #e8f0ff; color: #1d4ed8; font-weight: 600; }
.croptools button:disabled { opacity: .45; cursor: default; }

.masklayer { position: absolute; inset: 0; pointer-events: none; }
.maskrect {
  position: absolute; background: #000; border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .8);
}
.cropscene.maskmode { cursor: crosshair; }
.cropscene.maskmode .cropbox { cursor: crosshair; }

.cropwrap {
  position: relative; display: block; max-width: 100%; max-height: 58vh;
  overflow: auto; background: #eef2f7; border-radius: 8px;
}
.cropscene { position: relative; width: 100%; line-height: 0; }
.cropscene canvas { display: block; width: 100%; height: auto; }
.cropbox {
  position: absolute; border: 1.5px solid #2563eb;
  background: rgba(37, 99, 235, .12); cursor: move;
  box-shadow: 0 0 0 9999px rgba(10, 18, 30, .45);
}
.cropbox .h {
  position: absolute; width: 11px; height: 11px; background: #2563eb;
  border: 2px solid #fff; border-radius: 2px;
}
.cropbox .h.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.cropbox .h.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.cropbox .h.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.cropbox .h.se { right: -6px; bottom: -6px; cursor: nwse-resize; }

.presets { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.presets button {
  font: inherit; font-size: 11px; padding: 5px 9px; cursor: pointer;
  border: 1px solid #d7dfeb; background: #fff; border-radius: 999px; color: #33445c;
}
.presets button:hover { border-color: #93b4ea; background: #f5f9ff; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 11.5px; color: #4a5a72; margin-bottom: 4px; }
.field input[type=password], .field input[type=text] {
  width: 100%; padding: 9px 10px; border: 1px solid #d7dfeb; border-radius: 8px;
  font: inherit; font-size: 13px;
}
.field input:focus { outline: 2px solid #bfdbfe; border-color: #2563eb; }
.err { color: #b91c1c; font-size: 11.5px; margin-top: 6px; }

.pagethumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.pagethumbs button {
  font: inherit; font-size: 11px; width: 30px; height: 28px; cursor: pointer;
  border: 1px solid #d7dfeb; background: #fff; border-radius: 6px; color: #33445c;
}
.pagethumbs button.on { background: #2563eb; border-color: #2563eb; color: #fff; }

/* ---------------- passport list ---------------- */
.plist { display: flex; flex-direction: column; gap: 7px; }
.pitem { display: flex; gap: 8px; align-items: center; border: 1px solid #e4eaf3; border-radius: 8px; padding: 6px; background: #fff; }
.pitem img { width: 42px; height: 52px; object-fit: cover; border-radius: 4px; background: #f1f5f9; flex: 0 0 42px; }
.pitem .meta { flex: 1; min-width: 0; font-size: 10.5px; color: #6b7a90; }
.pitem .qty { display: flex; align-items: center; gap: 4px; }
.pitem .qty input {
  width: 42px; text-align: center; font: inherit; font-size: 12px; padding: 3px;
  border: 1px solid #d7dfeb; border-radius: 5px;
}
.pitem .qty button {
  width: 20px; height: 20px; border: 1px solid #d7dfeb; background: #fff;
  border-radius: 5px; cursor: pointer; font-size: 12px; line-height: 1; color: #4a5a72;
}

.fitwarn {
  font-size: 11px; line-height: 1.45; color: #b91c1c;
  background: #fef2f2; border: 1px solid #fecaca; border-radius: 7px;
  padding: 7px 9px; margin-bottom: 9px;
}

/* ---------------- login gate ---------------- */
.gate {
  position: fixed; inset: 0; z-index: 9999; background: #eef2f8;
  display: grid; place-items: center; padding: 20px;
}
.gate-card {
  width: min(380px, 100%); background: #fff; border-radius: 14px; padding: 24px;
  box-shadow: 0 18px 60px rgba(23, 32, 46, .18);
  display: flex; flex-direction: column; gap: 12px;
}
.gate-card .logo {
  width: 44px; height: 44px; border-radius: 12px; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  display: grid; place-items: center;
}
.gate-card h2 { margin: 0; font-size: 18px; }
.gate-card .gate-sub { margin: 0; font-size: 12px; color: #6b7a90; }
.gate-card label { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; font-weight: 600; color: #4a5a72; }
.gate-card input {
  font: inherit; font-size: 13.5px; padding: 9px 10px;
  border: 1px solid #d7dfeb; border-radius: 8px; background: #fff;
}
.gate-card input:focus { outline: 2px solid #bfd3f7; border-color: #2563eb; }
.gate-msg { font-size: 11.5px; min-height: 15px; color: #6b7a90; }
.gate-msg.err { color: #b91c1c; }
body.locked .stage, body.locked .panel { filter: blur(3px); pointer-events: none; user-select: none; }

/* ---------------- consent gate ---------------- */
.consent {
  position: fixed; inset: 0; z-index: 10000; background: #eef2f8;
  display: grid; place-items: center; padding: 20px;
}
.consent-card {
  width: min(440px, 100%); background: #fff; border-radius: 14px; padding: 22px;
  box-shadow: 0 18px 60px rgba(23, 32, 46, .18);
  display: flex; flex-direction: column; gap: 10px;
}
.consent-logo {
  width: 38px; height: 38px; border-radius: 11px; color: #fff; font-weight: 700; font-size: 20px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  display: grid; place-items: center;
}
.consent-card h2 { margin: 0; font-size: 17px; }
.consent-sub { margin: 0; font-size: 12px; color: #6b7a90; }
.consent-yes {
  display: flex; gap: 9px; align-items: flex-start; font-size: 12.5px; line-height: 1.5;
  color: #33445c; background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 9px; padding: 10px 11px; cursor: pointer;
}
.consent-yes input { margin-top: 2px; width: 16px; height: 16px; flex: 0 0 16px; accent-color: #2563eb; }
.consent-foot { margin: 0; font-size: 11px; color: #7b8ba1; }
.consent-btn { width: 100%; }
.consent-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- small screens / phone ---------------- */
@media (max-width: 860px) {
  body { display: block; height: auto; min-height: 100vh; overflow: auto; }
  .panel {
    width: auto; flex: 0 0 auto; height: auto; overflow: visible;
    border-right: 0; border-bottom: 1px solid #dbe1ea;
  }
  .stage { height: auto; min-height: 60vh; padding: 14px; }
}

/* ---------------- print ---------------- */
@media print {
  @page { margin: 0; }
  html, body {
    display: block !important; height: auto !important;
    overflow: visible !important; background: #fff !important;
  }
  .panel, .modal-bg { display: none !important; }
  .stage { display: block !important; padding: 0 !important; overflow: visible !important; height: auto !important; }
  #pages { display: block !important; }
  .page-holder {
    width: auto !important; height: auto !important; margin: 0 !important;
    page-break-after: always; break-after: page;
  }
  .page-holder:last-child { page-break-after: auto; break-after: auto; }
  .sheet {
    transform: none !important; box-shadow: none !important; margin: 0 !important;
    /* 0.5mm short so Chrome never spills onto a blank extra page */
    height: calc(var(--h) - 0.5mm) !important;
  }
  .cell.empty { visibility: hidden; }
  .alignline { display: none !important; }
  body.locked .stage { display: none !important; }
}
