:root {
  --bg: #eef0f4;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #d9dde5;
  --hover: #f2f4f7;
  --accent: #e5322d;
  --accent-soft: #fdecec;
  --accent-line: #f7c3c1;
  --sel: #2563eb;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
body.busy, body.busy * { cursor: progress !important; }
[hidden] { display: none !important; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.tools { display: flex; gap: 2px; padding-left: 14px; border-left: 1px solid var(--line); }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px;
  padding: 5px 8px; border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--ink); font: inherit; font-size: 11.5px; cursor: pointer;
}
.tool svg { width: 20px; height: 20px; }
.tool:hover { background: var(--hover); }
.tool[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.tool-wrap { position: relative; }
.stamp-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 300px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px;
  box-shadow: 0 12px 32px rgba(16,24,40,.18);
}
.stamp-pop h4 { margin: 8px 0 6px; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stamp-pop h4:first-child { margin-top: 0; }
.stamp-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.stamp-grid button {
  height: 32px; border: 0; border-radius: 6px; background: none; cursor: pointer; padding: 0;
  font-size: 19px; line-height: 32px; color: var(--ink);
  font-family: "Segoe UI Symbol", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.stamp-grid.emoji button { font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.stamp-grid button:hover, .stamp-grid button[aria-pressed="true"] { background: var(--accent-soft); }
.opts { display: flex; align-items: center; gap: 8px; }
.opt { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.opts input[type="number"] { width: 58px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.opts input[type="color"] { width: 32px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; cursor: pointer; }
.zoom { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; color: var(--muted); }
.zoom button { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: 16px; color: var(--ink); }
.zoom button:hover { background: var(--hover); }
#zoomVal { min-width: 42px; text-align: center; }
.right { margin-left: auto; display: flex; gap: 8px; }

button.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
button.primary:hover { filter: brightness(0.94); }
button.primary.big { padding: 12px 28px; font-size: 16px; }
button.ghost {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font: inherit; color: var(--ink); cursor: pointer;
}
button.ghost:hover { background: var(--hover); }
button.small { padding: 5px 10px; font-size: 12.5px; }

.hint {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%); z-index: 6;
  background: #1d2433; color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px;
  pointer-events: none; opacity: 0.92;
}

/* Main area */
main { flex: 1; min-height: 0; position: relative; }
.drop { height: 100%; display: grid; place-items: center; padding: 24px; }
.drop-card {
  background: var(--panel); border: 2px dashed var(--line); border-radius: 16px;
  padding: 48px 40px; text-align: center; max-width: 560px; width: 100%;
  transition: border-color .15s, background .15s;
}
body.dragging .drop-card { border-color: var(--accent); background: #fff7f7; }
.drop-icon { width: 64px; height: 64px; }
.drop-card h1 { font-size: 24px; margin: 16px 0 8px; letter-spacing: -0.01em; }
.drop-card p { color: var(--muted); margin: 0 0 22px; }
.drop-card .privacy {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px; margin: 22px 0 0; color: #027a48;
}
.drop-card .privacy svg { width: 16px; height: 16px; flex: none; }

#viewer { height: 100%; overflow: auto; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 28px 24px 60px; width: max-content; min-width: 100%; }
.page {
  position: relative; background: #fff; flex: none;
  box-shadow: 0 1px 3px rgba(16,24,40,.14), 0 1px 2px rgba(16,24,40,.08);
}
.page canvas { display: block; }
.layer { position: absolute; inset: 0; }
#pages[data-tool="text"] .layer { cursor: text; }
#pages[data-tool="whiteout"] .layer,
#pages[data-tool="highlight"] .layer { cursor: crosshair; }
#pages[data-tool="signature"] .layer { cursor: copy; }

/* Form fields from the PDF */
.field {
  position: absolute; margin: 0; padding: 0 3px;
  background: rgba(37,99,235,.07); border: 1px solid rgba(37,99,235,.35); border-radius: 2px;
  font-family: Helvetica, Arial, sans-serif; color: #000;
}
.field:hover { background: rgba(37,99,235,.12); }
.field:focus { outline: 2px solid var(--sel); outline-offset: 0; background: rgba(37,99,235,.12); }
textarea.field { resize: none; padding: 2px 3px; }
input.field-checkbox, input.field-radio { accent-color: var(--sel); padding: 0; cursor: pointer; }

/* Things the user adds */
.item { position: absolute; }
.item:not(.item-text) { cursor: move; }
.item-whiteout { background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.06); }
.item-highlight { mix-blend-mode: multiply; opacity: .4; }
.item-image img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.item.selected { outline: 1.5px dashed var(--sel); outline-offset: 2px; }
.text-body {
  font-family: Helvetica, Arial, sans-serif; line-height: 1.2; white-space: pre;
  min-width: 6px; min-height: 1.2em; outline: none; padding: 0; cursor: text;
}
.item-text:hover .text-body { box-shadow: 0 0 0 1px rgba(37,99,235,.45); }
.item-text.selected { outline: none; }
.item-text.selected .text-body { box-shadow: 0 0 0 1.5px var(--sel); }
.handle {
  position: absolute; width: 10px; height: 10px; display: none;
  background: var(--sel); border: 1.5px solid #fff; border-radius: 2px;
}
.item.selected .handle, .item:hover .handle { display: block; }
.handle.move { left: -18px; top: 50%; margin-top: -7px; width: 14px; height: 14px; border-radius: 3px; cursor: move; }
.handle.resize { right: -6px; bottom: -6px; cursor: nwse-resize; }
.del {
  position: absolute; top: -12px; right: -12px; width: 20px; height: 20px; display: none;
  border: 0; border-radius: 50%; padding: 0; background: #344054; color: #fff;
  font-size: 14px; line-height: 20px; cursor: pointer;
}
.item.selected .del { display: block; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16,24,40,.2); max-width: min(560px, 90vw); text-align: center;
}

/* Signature dialog */
dialog {
  border: 0; border-radius: 14px; padding: 22px 24px; width: min(660px, 94vw);
  box-shadow: 0 20px 50px rgba(16,24,40,.3);
}
dialog::backdrop { background: rgba(16,24,40,.45); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog .muted { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
#sigCanvas {
  width: 100%; aspect-ratio: 3 / 1; display: block; touch-action: none; cursor: crosshair;
  border: 1px solid var(--line); border-radius: 10px;
  background: linear-gradient(to bottom, transparent 74%, #d0d5dd 74%, #d0d5dd calc(74% + 1px), transparent calc(74% + 1px));
}
.upload-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; }
.upload-row .ghost { display: inline-flex; align-items: center; gap: 6px; }
.upload-row svg { width: 16px; height: 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.row { display: flex; gap: 8px; margin-top: 16px; }
.spacer { flex: 1; }

/* ---------- Pro ---------- */
.pro-group { position: relative; }
.pro-group .tool { position: relative; }
.pro-tag {
  position: absolute; top: 1px; right: 2px; font-style: normal; font-size: 8.5px; font-weight: 800; letter-spacing: .03em;
  padding: 1px 4px; border-radius: 4px; background: #141a26; color: #fff;
}
body.is-pro .pro-tag { display: none; }
.pro-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  font: inherit; font-weight: 650; color: #fff; background: linear-gradient(135deg, #141a26, #2b3350);
}
.pro-btn .star { color: #ffd166; }
.pro-btn:hover { filter: brightness(1.15); }
body.is-pro .pro-btn { background: #ecfdf3; color: #027a48; }
body.is-pro .pro-btn .star { color: #12b76a; }

.sig-list { display: flex; gap: 4px; align-items: center; }
.sig-thumb {
  position: relative; width: 64px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer;
}
.sig-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sig-thumb[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.sig-thumb .sig-del {
  position: absolute; top: -7px; right: -7px; width: 16px; height: 16px; border-radius: 50%; border: 0; padding: 0;
  background: #344054; color: #fff; font-size: 11px; line-height: 16px; cursor: pointer; display: none;
}
.sig-thumb:hover .sig-del { display: block; }

.pro-dialog { width: min(520px, 94vw); position: relative; }
.pro-dialog .x { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 24px; color: var(--muted); cursor: pointer; }
.pro-head { text-align: center; margin-bottom: 14px; }
.pro-pill { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; background: linear-gradient(135deg, #141a26, #2b3350); color: #ffd166; }
.pro-head h2 { margin: 8px 0 4px; font-size: 22px; }
.pro-head p { margin: 0; }
.nag-box { display: flex; justify-content: center; margin: -4px 0 16px; }
.nag-box button { min-width: 220px; }
.nag-box button:disabled { opacity: .55; cursor: default; }
.pro-list { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 8px; }
.pro-list li { display: flex; gap: 8px; }
.pro-list li::before { content: "✓"; color: #027a48; font-weight: 800; }
.pro-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pro-plan {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: var(--ink); background: #fff;
}
.pro-plan.featured { border: 2px solid var(--accent); }
.pro-plan span { color: var(--muted); font-size: 13px; }
.pro-plan:hover { background: var(--hover); }
.pro-plan[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.activate { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.activate label { display: block; font-weight: 600; margin-bottom: 8px; }
.activate-row { display: flex; gap: 8px; }
.activate-row input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: 13px ui-monospace, Consolas, monospace; }
.lic-msg { min-height: 20px; margin: 8px 0 0; font-size: 13.5px; font-weight: 600; }
.lic-msg.ok { color: #027a48; }
.lic-msg.err { color: #b42318; }
.pro-ok { font-weight: 700; color: #027a48; font-size: 16px; text-align: center; }
.small { font-size: 12.5px; }

.pages-dialog { width: min(980px, 96vw); }
.pages-head h2 { margin: 0 0 4px; }
.thumbs {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px;
  max-height: 58vh; overflow: auto; padding: 14px; margin: 12px 0; background: var(--bg); border-radius: 10px;
}
.thumb {
  position: relative; background: #fff; border: 2px solid transparent; border-radius: 10px; padding: 8px; cursor: grab;
  box-shadow: 0 1px 3px rgba(16,24,40,.12); display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.thumb.selected { border-color: var(--sel); }
.thumb.dragging { opacity: .4; }
.thumb.drop-before { box-shadow: -4px 0 0 var(--accent); }
.thumb .img-box { width: 100%; height: 150px; display: grid; place-items: center; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; transition: transform .2s; box-shadow: 0 0 0 1px var(--line); pointer-events: none; }
.thumb .meta { display: flex; align-items: center; gap: 6px; width: 100%; font-size: 12px; color: var(--muted); }
.thumb .meta input { accent-color: var(--sel); margin: 0; }
.thumb .meta .src { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .acts { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.thumb:hover .acts { opacity: 1; }
.thumb .acts button { width: 26px; height: 26px; border-radius: 6px; border: 0; background: rgba(20,26,38,.85); color: #fff; cursor: pointer; font-size: 14px; line-height: 26px; padding: 0; }

.level { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.level:has(input:checked) { border-color: var(--accent); background: #fffafa; }
.level input { margin-top: 4px; accent-color: var(--accent); }
.level span { display: flex; flex-direction: column; }
.level small { color: var(--muted); }
.split-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#splitN { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.split-text { margin-top: 6px; width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; box-sizing: border-box; }
