/* LocalPDF Sign — editor styles. No remote fonts, no remote images. */
:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-weak: #eff6ff;
  --danger: #dc2626;
  --ok: #059669;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .10), 0 2px 4px rgba(16, 24, 40, .06);
  --shadow-lg: 0 24px 48px rgba(16, 24, 40, .18), 0 4px 12px rgba(16, 24, 40, .08);
  --radius: 10px;
}

* { box-sizing: border-box; }

/* the `hidden` attribute must win over component display rules */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Liberation Sans", "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.badge-local {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #a7f3d0;
  white-space: nowrap;
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.top-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; border-color: #b9bfc9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
}
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f3f4f6; }
.btn.ghost.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 11.5px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 10px; }
.btn.icon-only { width: 30px; justify-content: center; padding: 7px 0; }

.chip-pro {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #7c3aed;
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 5px;
  padding: 1px 4px;
  line-height: 1.5;
}
.btn.primary .chip-pro { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.45); color: #fff; }

/* ---------- shell ---------- */
.shell { flex: 1 1 auto; display: flex; min-height: 0; }

.rail {
  width: 208px;
  flex: 0 0 208px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.rail-count {
  background: #f3f4f6;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10.5px;
  color: var(--ink-2);
  letter-spacing: 0;
}
.thumbs { flex: 1 1 auto; overflow-y: auto; padding: 12px 12px 4px; }
.rail-foot { padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.rail-tip { font-size: 10.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.rail.hide { display: none; }

.thumb {
  position: relative;
  margin-bottom: 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 4px 4px 2px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  background: #fafafa;
}
.thumb:hover { background: #f3f4f6; }
.thumb.current { border-color: var(--accent); background: var(--accent-weak); }
.thumb.dragging { opacity: .4; }
.thumb.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.thumb.drop-after { box-shadow: 0 3px 0 var(--accent); }
.thumb canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
}
.thumb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 1px;
  font-size: 10.5px;
  color: var(--muted);
}
.thumb-ops { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.thumb:hover .thumb-ops, .thumb.current .thumb-ops { opacity: 1; }
.thumb-op {
  border: 0;
  background: transparent;
  border-radius: 4px;
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}
.thumb-op:hover { background: #e5e7eb; color: var(--ink); }
.thumb-op.danger:hover { background: #fee2e2; color: var(--danger); }

/* ---------- stage ---------- */
.stage { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; position: relative; }

.toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 5px 7px;
  box-shadow: var(--shadow-md);
  max-width: calc(100% - 24px);
}
.tools { display: flex; gap: 1px; }
.tool {
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 6px 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.tool svg { color: var(--muted); }
.tool:hover { background: #f3f4f6; }
.tool.active { background: var(--accent-weak); color: var(--accent-ink); }
.tool.active svg { color: var(--accent); }
.tool-sep { width: 1px; height: 20px; background: var(--line); }

.zoom { display: flex; align-items: center; gap: 1px; }
.zoom-btn {
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  color: var(--ink-2);
}
.zoom-btn:hover { background: #f3f4f6; }
.zoom-value {
  border: 0;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  min-width: 42px;
  cursor: pointer;
  padding: 4px 2px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.zoom-value:hover { background: #f3f4f6; }

.counter {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding-right: 4px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.counter.over { color: #b45309; }

.scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 58px 24px 120px;
  scroll-behavior: smooth;
}
.pages { display: flex; flex-direction: column; align-items: center; gap: 22px; }

.page {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-md);
  border-radius: 2px;
}
.page-surface { position: relative; }
.page canvas { display: block; border-radius: 2px; }
.page-tag {
  position: absolute;
  left: 0;
  top: -19px;
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
}
.layer { position: absolute; inset: 0; }

.el {
  position: absolute;
  min-width: 8px;
  min-height: 8px;
  cursor: move;
  user-select: none;
  outline: 1px solid transparent;
  border-radius: 2px;
}
.el:hover { outline: 1px dashed rgba(37, 99, 235, .55); }
.el.selected { outline: 1.5px solid var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.el .el-text {
  width: 100%;
  height: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.25;
  pointer-events: none;
}
.el.editing .el-text {
  pointer-events: auto;
  outline: 1.5px solid var(--accent);
  background: rgba(255, 255, 255, .92);
  cursor: text;
  user-select: text;
}
.el img { width: 100%; height: 100%; display: block; pointer-events: none; }
.el .el-box {
  width: 100%;
  height: 100%;
  border: 1px solid currentColor;
  display: grid;
  place-items: center;
}
.el .el-box svg { width: 100%; height: 100%; display: block; }

.handle {
  position: absolute;
  width: 9px;
  height: 9px;
  right: -5px;
  bottom: -5px;
  background: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  cursor: nwse-resize;
  display: none;
}
.el.selected .handle { display: block; }
.handle.text-handle { right: -5px; top: 50%; bottom: auto; margin-top: -5px; cursor: ew-resize; }

/* ---------- empty ---------- */
.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}
.empty.hide { display: none; }
.empty-card {
  pointer-events: auto;
  width: min(520px, 100%);
  background: var(--panel);
  border: 1.5px dashed var(--line-2);
  border-radius: 16px;
  padding: 30px 32px 26px;
  text-align: center;
  color: var(--ink-2);
  transition: border-color .15s, background .15s;
}
.empty-card.drag { border-color: var(--accent); background: var(--accent-weak); }
.empty-card svg { color: var(--accent); }
.empty-card h1 { margin: 10px 0 2px; font-size: 19px; color: var(--ink); letter-spacing: -.01em; }
.empty-card p { margin: 0 0 14px; color: var(--muted); }
.empty-points {
  text-align: left;
  margin: 16px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  display: grid;
  gap: 7px;
}
.empty-points li { font-size: 12px; color: var(--muted); padding-left: 18px; position: relative; }
.empty-points li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--ok);
  font-weight: 700;
}
.empty-points strong { color: var(--ink-2); }
.link {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ---------- inspector ---------- */
.inspector {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, .98);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100% - 24px);
}
.insp { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.inspector[hidden] { display: none; }
.toolbar[hidden] { display: none; }
.field[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field.block { display: block; margin-bottom: 12px; }
.field.block > span { display: block; margin-bottom: 5px; }
.field select, .field input[type=number] {
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  font-size: 12px;
  background: #fff;
  min-width: 62px;
}
.seg { display: flex; gap: 2px; }
.seg-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.seg-btn.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-ink); }
.swatches { display: flex; gap: 4px; }
.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .15);
  cursor: pointer;
  padding: 0;
}
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--accent); }
.insp-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 13px;
  color: var(--ink-2);
}
.icon-btn:hover { background: #f3f4f6; }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); border-color: #fecaca; }

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, .42);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade .14s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: min(680px, 100%);
  max-height: 92vh;
  overflow: auto;
}
.modal-card.narrow { width: min(460px, 100%); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.modal-head h2 { margin: 0; font-size: 15.5px; letter-spacing: -.01em; }
.modal-close { border-color: transparent; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  margin-top: 10px;
}
.modal-foot-actions { display: flex; gap: 8px; margin-left: auto; }

.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab-body { padding: 16px 18px 4px; }
.tab-body[hidden] { display: none; }

#sigPad {
  width: 100%;
  height: auto;
  aspect-ratio: 640 / 240;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(0deg, transparent, transparent 39px, #f1f5f9 39px, #f1f5f9 40px);
  touch-action: none;
  cursor: crosshair;
  display: block;
}
.sig-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.sig-row-actions { display: flex; gap: 6px; }
.hint { font-size: 11px; color: var(--muted); }

.text-input {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
}
.text-input:focus { outline: 2px solid rgba(37, 99, 235, .35); outline-offset: 1px; border-color: var(--accent); }

.sig-fonts { display: flex; gap: 8px; margin: 12px 0 0; }
.sig-font {
  flex: 1;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 8px;
  padding: 10px 8px;
  font-size: 17px;
  cursor: pointer;
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
}
.sig-font.active { border-color: var(--accent); background: var(--accent-weak); }
.sig-preview {
  margin-top: 12px;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  padding: 18px;
  font-size: 34px;
  text-align: center;
  word-break: break-word;
  min-height: 84px;
  display: grid;
  place-items: center;
}
.saved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.saved-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: #fff;
  cursor: pointer;
  position: relative;
}
.saved-item img { width: 100%; height: 52px; object-fit: contain; display: block; }
.saved-item.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.saved-item .del {
  position: absolute;
  top: 2px;
  right: 2px;
  border: 0;
  background: rgba(255,255,255,.9);
  color: var(--danger);
  border-radius: 4px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.hide { display: none !important; }

.check { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }

.pro-body { padding: 4px 18px 18px; }
.pro-price { font-size: 26px; font-weight: 700; margin: 2px 0 12px; letter-spacing: -.02em; }
.pro-price span { font-size: 13px; font-weight: 600; color: var(--muted); }
.pro-list { margin: 0 0 16px; padding-left: 18px; color: var(--ink-2); display: grid; gap: 6px; font-size: 12.5px; }
.pro-active {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
}
.pro-active span { color: #047857; font-size: 11.5px; }

.help-body { padding: 4px 20px 20px; font-size: 12.5px; color: var(--ink-2); }
.help-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.help-body ol { padding-left: 18px; display: grid; gap: 7px; }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.keys td:first-child { white-space: nowrap; width: 1%; }
kbd {
  display: inline-block;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #fafafa;
  color: var(--ink-2);
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 150px;
  transform: translateX(-50%);
  z-index: 200;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}
.toast {
  background: #111827;
  color: #f9fafb;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 520px;
  animation: toast-in .16s ease;
}
.toast.ok::before { content: "✓"; color: #4ade80; font-weight: 700; }
.toast.err { background: #7f1d1d; }
.toast.err::before { content: "!"; color: #fca5a5; font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

/* ---------- busy overlay ---------- */
.busy {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(249, 250, 251, .72);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
}
.busy[hidden] { display: none; }
.busy-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #dbeafe;
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

@media (max-width: 900px) {
  .rail { width: 150px; flex-basis: 150px; }
  .tool span { display: none; }
  .tool { padding: 6px 7px; }
  .counter { display: none; }
}
