/* PDFsmith editor — calm, quiet, fast. */
@font-face {
  font-family: "Rubik";
  src: url("fonts/Rubik_400Regular.ttf") format("truetype");
  font-weight: 400;
}
@font-face {
  font-family: "Rubik";
  src: url("fonts/Rubik_700Bold.ttf") format("truetype");
  font-weight: 700;
}

:root {
  --bg: #f0f1f5;
  --panel: #ffffff;
  --ink: #1c1e26;
  --muted: #6b7080;
  --line: #dcdfe8;
  --accent: #2450b8;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgba(20, 24, 40, 0.12), 0 8px 24px rgba(20, 24, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ── top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  z-index: 20;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
  margin-right: 6px;
  white-space: nowrap;
}
.brand-mark { color: var(--accent); margin-right: 4px; }
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-spacer { flex: 1; }
.tb-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 11px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.tb-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn.icon { padding: 6px 9px; min-width: 32px; }
.tb-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.tb-btn.primary:hover:not(:disabled) { background: #1c418f; color: var(--accent-ink); }
.tb-btn.tool.active {
  background: #e8edfb;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
#tool-options input[type="color"] {
  inline-size: 30px; block-size: 30px;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 1px; background: var(--panel); cursor: pointer;
}
#tool-options select {
  font: inherit; padding: 5px 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.linklike {
  background: none; border: none; padding: 0;
  color: var(--accent); text-decoration: underline;
  font: inherit; cursor: pointer;
}

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

.thumbs {
  width: 172px;
  overflow-y: auto;
  padding: 12px 10px 24px;
  border-right: 1px solid var(--line);
  background: #e9ebf1;
  flex-shrink: 0;
}
.thumb {
  position: relative;
  margin: 0 auto 14px;
  width: 140px;
  cursor: pointer;
  border-radius: 6px;
}
.thumb canvas, .thumb .thumb-blank {
  display: block;
  width: 100%;
  background: #fff;
  border: 2px solid transparent;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(20, 24, 40, 0.18);
}
.thumb.current canvas, .thumb.current .thumb-blank { border-color: var(--accent); }
.thumb.checked::after {
  content: "✓";
  position: absolute; top: -6px; left: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; line-height: 20px; text-align: center;
}
.thumb .thumb-num {
  display: block; text-align: center;
  font-size: 11px; color: var(--muted); margin-top: 3px;
}
.thumb .thumb-tools {
  position: absolute; top: 4px; right: 4px;
  display: none; gap: 2px;
}
.thumb:hover .thumb-tools { display: flex; }
.thumb-tools button {
  border: none; border-radius: 5px;
  background: rgba(28, 30, 38, 0.75); color: #fff;
  width: 22px; height: 22px; font-size: 12px; cursor: pointer;
}
.thumb-tools button:hover { background: var(--accent); }
.thumb.drag-over-before { box-shadow: -4px 0 0 0 var(--accent); }
.thumb.drag-over-after { box-shadow: 4px 0 0 0 var(--accent); }
.thumb.dragging { opacity: 0.4; }

.stage {
  flex: 1;
  min-width: 0;
  overflow: auto;
  position: relative;
  display: flex;
}
.dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 24px;
  border: 2px dashed #b9bfd0;
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}
.dropzone.armed { border-color: var(--accent); background: #e8edfb66; }
.dz-icon { font-size: 44px; }
.dz-inner h1 { margin: 8px 0 4px; color: var(--ink); font-size: 24px; }
.dz-note { font-size: 12px; margin-top: 14px; }

.page-holder {
  margin: auto;
  padding: 28px;
}
.page-frame {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow);
}
#page-canvas { display: block; }

/* overlay layer lives in PDF-point coordinates, scaled by transform */
.overlay-root {
  position: absolute;
  inset: 0 auto auto 0;
  transform-origin: 0 0;
  z-index: 5;
}
.overlay-root.tool-select { cursor: default; }
.overlay-root.tool-text { cursor: text; }
.overlay-root.tool-draw, .overlay-root.tool-highlight, .overlay-root.tool-whiteout { cursor: crosshair; }
.overlay-root.tool-image, .overlay-root.tool-sign { cursor: copy; }

.ov {
  position: absolute;
  touch-action: none;
}
.tool-select .ov { cursor: move; }
.ov.selected { outline: 1.5px dashed var(--accent); outline-offset: 1px; }
.ov-text {
  white-space: pre;
  unicode-bidi: plaintext;
  text-align: start;
  line-height: 1.25;
  font-family: "Rubik", sans-serif;
  min-width: 4px;
  min-height: 1em;
}
.ov-text[contenteditable] { outline: 1.5px solid var(--accent); cursor: text; }
.ov-rect-highlight { mix-blend-mode: multiply; }
.ov-img img { display: block; width: 100%; height: 100%; }
.ov-ink { pointer-events: none; }
.tool-select .ov-ink { pointer-events: auto; }
.ov-handle {
  position: absolute;
  right: -6px; bottom: -6px;
  width: 12px; height: 12px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  box-shadow: 0 0 3px rgba(0,0,0,0.4);
}

/* ── side panel ── */
.panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-body { padding: 14px; overflow-y: auto; }
.panel-body label { display: block; margin: 10px 0 4px; font-weight: 700; font-size: 12.5px; }
.panel-body input[type="text"], .panel-body input[type="number"],
.panel-body select, .panel-body textarea {
  width: 100%;
  font: inherit;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.panel-body textarea { resize: vertical; }
.panel-body .row { display: flex; gap: 8px; align-items: center; }
.panel-body .row > * { flex: 1; }
.panel-body .check { display: flex; gap: 7px; align-items: center; font-weight: 400; }
.panel-body .check input { width: auto; }
.panel-actions { margin-top: 16px; display: flex; gap: 8px; }
.panel-note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.field-row { margin-bottom: 12px; }
.field-row .f-name { font-size: 12px; font-weight: 700; margin-bottom: 3px; word-break: break-all; }

/* ── status bar ── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 12.5px;
  color: var(--muted);
}
.sb-sep { width: 1px; height: 18px; background: var(--line); }
.sb-file { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-dirty { color: var(--danger); }

/* ── modal / toast ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(18, 20, 30, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-card {
  background: var(--panel);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-width: min(640px, 92vw);
}
.modal-card h2 { margin: 0 0 12px; font-size: 17px; }
#sign-pad {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fff;
  touch-action: none;
  max-width: 100%;
}
.modal-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.modal-note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

.toast {
  position: fixed;
  left: 50%; bottom: 46px;
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 80vw;
}
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .thumbs { width: 120px; }
  .thumb { width: 96px; }
  .sb-hint { display: none; }
}
