* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px -apple-system, "Segoe UI", Roboto, sans-serif; color: #1f2933; }
body { display: flex; flex-direction: column; background: #e9ecf0; }

#toolbar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 8px 12px; background: #fff; border-bottom: 1px solid #d5d9df; }
.group { display: flex; gap: 4px; align-items: center; }
.group.right { margin-left: auto; }
.group.tools { padding: 0 8px; border-left: 1px solid #e2e5e9; border-right: 1px solid #e2e5e9; }
button { font: inherit; padding: 5px 8px; border: 1px solid #cfd4da; background: #f7f8fa; border-radius: 6px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: #eef1f5; }
button:disabled { opacity: .45; cursor: default; }
button.tool.active { background: #1e5bd8; color: #fff; border-color: #1e5bd8; }
.props label { display: flex; align-items: center; gap: 4px; }
input[type=color] { width: 30px; height: 26px; padding: 0; border: 1px solid #cfd4da; border-radius: 4px; background: none; }
select { font: inherit; padding: 3px; }
#zoomLabel { min-width: 44px; text-align: center; }
.pagebox input { width: 50px; font: inherit; padding: 3px; text-align: center; }

main { flex: 1; display: flex; min-height: 0; }
#sidebar { width: 170px; background: #f4f5f7; border-right: 1px solid #d5d9df; display: flex; flex-direction: column; }
.side-actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border-bottom: 1px solid #e0e3e7; }
.side-actions button { padding: 3px 7px; }
#thumbs { flex: 1; overflow-y: auto; padding: 10px; }
.thumb { margin: 0 auto 12px; width: 120px; text-align: center; cursor: pointer; }
.thumb canvas { display: block; margin: 0 auto; max-width: 120px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); border: 3px solid transparent; }
.thumb.selected canvas { border-color: #1e5bd8; }
.thumb.dragover { outline: 2px dashed #1e5bd8; }
.thumb span { font-size: 11px; color: #555; }

#viewer { flex: 1; overflow: auto; position: relative; }
#pages { padding: 20px 20px 40px; min-width: max-content; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.page { position: relative; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.page canvas { display: block; }
.page svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
body[data-tool=select] svg.overlay { pointer-events: none; }
body[data-tool=select] svg.overlay .ann { pointer-events: all; cursor: move; }
body:not([data-tool=select]) svg.overlay { cursor: crosshair; }
body[data-tool=text] svg.overlay { cursor: text; }
.ann.selected .selbox { display: block; }
.selbox { display: none; }

.textLayer { position: absolute; inset: 0; overflow: clip; line-height: 1; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; caret-color: CanvasText; z-index: 0; }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer ::selection { background: rgba(30, 91, 216, .3); }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }

.text-editor { position: absolute; z-index: 10; border: 1px dashed #1e5bd8; background: rgba(255,255,255,.85); padding: 0; margin: 0; outline: none; resize: both; font-family: Helvetica, Arial, sans-serif; line-height: 1.2; min-width: 120px; min-height: 1.4em; overflow: hidden; }

#empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#empty.hidden { display: none; }
.empty-card { text-align: center; background: #fff; padding: 36px 48px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.empty-card .big { width: 72px; height: 72px; }
.empty-card h3 { margin: 22px 0 8px; font-size: 13px; color: #667; text-align: left; }
.empty-card h2 { margin: 6px 0; }
.empty-card p { color: #667; }
body.dragging #viewer { outline: 3px dashed #1e5bd8; outline-offset: -8px; }

#status { padding: 4px 12px; font-size: 12px; color: #555; background: #fff; border-top: 1px solid #d5d9df; }
#sidebar.hidden { display: none; }

.hidden { display: none !important; }
button.primary { background: #1e5bd8; color: #fff; border-color: #1e5bd8; }
button.primary:hover:not(:disabled) { background: #194cb6; }

/* tabs */
#tabs { display: flex; align-items: flex-end; gap: 2px; padding: 4px 8px 0; background: #dde1e7; border-bottom: 1px solid #c9ced6; min-height: 32px; overflow-x: auto; }
.tab { display: flex; align-items: center; gap: 6px; max-width: 220px; padding: 5px 6px 5px 12px; background: #eceef2; border: 1px solid #c9ced6; border-bottom: none; border-radius: 7px 7px 0 0; cursor: pointer; font-size: 12px; }
.tab.active { background: #fff; font-weight: 600; }
.tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-close { border: none; background: none; padding: 0 4px; font-size: 14px; line-height: 1; color: #666; }
.tab-close:hover { background: #e2e5ea !important; color: #c62828; }
.tab-new { border: none; background: none; font-size: 16px; padding: 2px 10px; align-self: center; }

/* find bar */
#findbar { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: #fffbe6; border-bottom: 1px solid #e8dfb0; }
#findInput { width: 280px; font: inherit; padding: 4px 8px; border: 1px solid #cfd4da; border-radius: 5px; }
#findCount { min-width: 50px; color: #555; font-size: 12px; }

/* dropdowns */
.dropdown { position: fixed; z-index: 50; background: #fff; border: 1px solid #cfd4da; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 6px; max-height: 70vh; overflow-y: auto; min-width: 260px; }
.recent-item { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: none; background: none; text-align: left; padding: 6px 10px; border-radius: 6px; }
.recent-item:hover { background: #eef1f5 !important; }
.recent-item .rn { font-weight: 600; }
.recent-item .rp { font-size: 11px; color: #778; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-empty { color: #889; font-size: 12px; padding: 8px 10px; }
#recentList { text-align: left; max-width: 480px; max-height: 260px; overflow-y: auto; }
#stampMenu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-width: 300px; }
#stampMenu.hidden { display: none !important; }
.stamp-date { grid-column: 1 / -1; font-size: 12px; padding: 2px 4px 6px; }
.stamp-item { font-weight: 800; letter-spacing: .5px; background: #fff; border: 2px solid; border-radius: 6px; padding: 6px; }

/* signature modal */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(20,24,32,.45); display: flex; align-items: center; justify-content: center; }
.modal-card { background: #fff; border-radius: 12px; padding: 18px 22px; width: 620px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-card h3 { margin: 0 0 10px; }
.modal-card h4 { margin: 12px 0 6px; font-size: 12px; color: #667; }
.sig-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.sig-tab.active { background: #1e5bd8; color: #fff; border-color: #1e5bd8; }
.sig-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.sig-row .grow { margin-left: auto; }
.sig-row input[type=text] { flex: 1; font: inherit; padding: 6px 8px; border: 1px solid #cfd4da; border-radius: 5px; }
.hint { font-size: 12px; color: #778; }
#sigPad { width: 100%; height: 200px; border: 1px dashed #aab2bd; border-radius: 8px; background: repeating-linear-gradient(transparent 0 149px, #dfe3e8 149px 150px), #fff; touch-action: none; cursor: crosshair; }
#sigSaved { display: flex; flex-wrap: wrap; gap: 8px; min-height: 30px; }
.sig-saved { position: relative; border: 1px solid #d5d9df; border-radius: 6px; padding: 4px; background: #fafbfc; }
.sig-saved img { height: 46px; max-width: 160px; display: block; cursor: pointer; }
.sig-saved button { position: absolute; top: -8px; right: -8px; padding: 0 5px; border-radius: 50%; font-size: 11px; background: #fff; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

body[data-tool=place] svg.overlay { cursor: copy; }
.handle { cursor: nwse-resize; }

/* print */
#printArea { display: none; }
@media print {
  @page { margin: 0; }
  body > *:not(#printArea) { display: none !important; }
  body { display: block; background: #fff; }
  #printArea { display: block; }
  #printArea img { display: block; width: 100%; page-break-after: always; break-after: page; }
  #printArea img:last-child { page-break-after: auto; break-after: auto; }
}

/* v2.1 */
#propBold.active { background: #1e5bd8; color: #fff; border-color: #1e5bd8; }
.side-tabs { display: flex; border-bottom: 1px solid #e0e3e7; }
.side-tabs button { flex: 1; border: none; border-radius: 0; background: none; padding: 7px 4px; font-size: 12px; color: #556; }
.side-tabs button.active { color: #1e5bd8; font-weight: 600; box-shadow: inset 0 -2px 0 #1e5bd8; }
#pagesPanel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#comments { flex: 1; overflow-y: auto; padding: 8px; }
.comment-item { display: grid; grid-template-columns: 10px 1fr; gap: 2px 6px; width: 100%; text-align: left; margin-bottom: 6px; background: #fff; padding: 6px 8px; }
.cdot { width: 10px; height: 10px; border-radius: 2px; margin-top: 3px; grid-row: span 2; }
.cmeta { font-size: 11px; color: #778; }
.ctext { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.dropdown.menu { display: flex; flex-direction: column; min-width: 240px; }
.dropdown.menu.hidden { display: none !important; }
.dropdown.menu button { border: none; background: none; text-align: left; padding: 7px 10px; border-radius: 6px; }
.dropdown.menu button:hover { background: #eef1f5; }
.dropdown.menu hr { border: none; border-top: 1px solid #e6e9ed; margin: 4px 0; }
.ask-card { width: 460px; max-height: 88vh; overflow-y: auto; }
#askIntro { margin: -4px 0 10px; }
.ask-row { display: grid; grid-template-columns: 170px 1fr; align-items: center; gap: 4px 10px; margin: 7px 0; }
.ask-row input[type=text], .ask-row input[type=number], .ask-row select { font: inherit; padding: 5px 7px; border: 1px solid #cfd4da; border-radius: 5px; width: 100%; }
.ask-row input[type=color] { width: 48px; height: 28px; }
.ask-row small { grid-column: 2; color: #778; font-size: 11px; }
.ask-row.check { display: flex; gap: 8px; }
.ask-row.heading { display: block; font-weight: 600; font-size: 12px; color: #445; margin: 14px 0 2px; border-bottom: 1px solid #eceff2; padding-bottom: 3px; }
#notePop { position: fixed; z-index: 60; width: 280px; background: #fffdf0; border: 1px solid #e3d48a; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); padding: 10px; }
#notePop.hidden { display: none; }
.note-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
#noteAuthor { flex: 1; font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid #e0d6a0; border-radius: 5px; background: #fff; }
#noteColors { display: flex; gap: 4px; }
.swatch { width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #c9c1a0; }
.swatch.active { box-shadow: 0 0 0 2px #1e5bd8; }
#noteText { width: 100%; font: inherit; padding: 6px; border: 1px solid #e0d6a0; border-radius: 6px; resize: vertical; background: #fff; }
.note-actions { display: flex; justify-content: space-between; margin-top: 8px; }
.page { overflow: hidden; }
body[data-tool=highlight] svg.overlay, body[data-tool=underline] svg.overlay, body[data-tool=strike] svg.overlay { pointer-events: none; }
body[data-tool=highlight] .page, body[data-tool=underline] .page, body[data-tool=strike] .page { cursor: text; }
body[data-tool=note] svg.overlay { cursor: cell; }
body[data-tool=crop] svg.overlay { cursor: crosshair; }
svg.overlay .decor { pointer-events: none; }

#toasts { position: fixed; right: 16px; bottom: 34px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.25); font-size: 13px; white-space: pre-line; transition: opacity .5s, transform .5s; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------- login gate ---------- */
body.locked #toolbar, body.locked #tabs, body.locked main, body.locked #status { filter: blur(2px); pointer-events: none; user-select: none; }
#authGate { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto;
  background: radial-gradient(1200px 600px at 20% 0%, #e7ecff 0%, transparent 60%), radial-gradient(900px 500px at 100% 100%, #efe6ff 0%, transparent 55%), #f5f6fa; }
#authGate.hidden { display: none; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 32px 30px 24px; box-shadow: 0 20px 60px rgba(30, 40, 90, .14); text-align: center; }
.auth-logo { width: 64px; height: 64px; border-radius: 14px; }
.auth-card h1 { font-size: 26px; margin: 10px 0 2px; letter-spacing: -.3px; }
.auth-sub { margin: 0 0 20px; color: #5b6472; font-size: 14px; }
.auth-google { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px; font-size: 15px; font-weight: 600; background: #fff; border: 1px solid #d3d8e0; border-radius: 10px; }
.auth-google:hover:not(:disabled) { background: #f6f8fb !important; }
.auth-or { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: #8a93a1; font-size: 12px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; border-top: 1px solid #e3e6eb; }
#authForm { display: flex; flex-direction: column; gap: 12px; text-align: left; }
#authForm label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #333b47; }
#authForm label.hidden { display: none; }
#authForm input { font: inherit; font-size: 16px; font-weight: 400; padding: 10px 12px; border: 1px solid #cfd5de; border-radius: 9px; width: 100%; }
#authForm input:focus { outline: 2px solid #5b4bdb; outline-offset: 0; border-color: transparent; }
.auth-pass { position: relative; display: block; }
.auth-pass input { padding-right: 64px !important; }
.auth-show { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: none; color: #5b4bdb; font-size: 12px; font-weight: 600; }
.auth-primary { padding: 12px; font-size: 15px; font-weight: 700; color: #fff; background: #5b4bdb; border: none; border-radius: 10px; margin-top: 4px; }
.auth-primary:hover:not(:disabled) { background: #4a3bc4 !important; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 6px; margin-top: 16px; font-size: 13px; color: #5b6472; }
.auth-links #authForgot { flex-basis: 100%; }
.auth-link { border: none; background: none; padding: 2px; color: #5b4bdb; font-weight: 600; font-size: 13px; }
.auth-link:hover:not(:disabled) { background: none !important; text-decoration: underline; }
.auth-msg { font-size: 13px; padding: 9px 11px; border-radius: 8px; text-align: left; }
.auth-msg.error { background: #fdecec; color: #a32020; }
.auth-msg.info { background: #edf3ff; color: #1e4fa8; }
.auth-msg.warn { background: #fff6dd; color: #7a5300; margin-bottom: 14px; }
.auth-legal { font-size: 12px; color: #7a8391; margin: 14px 0 0; }
.auth-legal a { color: #5b4bdb; }

.user-btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; background: #5b4bdb; color: #fff; border-color: #5b4bdb; font-weight: 700; margin-left: 6px; }
.user-btn:hover { background: #4a3bc4 !important; }
#userMenu { min-width: 260px; }
.user-info { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; text-align: left; }
.user-info span { font-size: 12px; color: #667; word-break: break-all; }
#userVerify { color: #a66b00 !important; }

/* ---------- optional sign-in (website) ---------- */
.auth-card { position: relative; }
.auth-close { position: absolute; top: 12px; right: 12px; border: none; background: none; font-size: 16px; color: #7a8391; padding: 4px 8px; }
.auth-skip { margin-top: 10px; color: #5b6472 !important; font-weight: 500 !important; }
.signin-btn { margin-left: 6px; background: #5b4bdb; color: #fff; border-color: #5b4bdb; font-weight: 600; }
.signin-btn:hover:not(:disabled) { background: #4a3bc4 !important; }

/* ---------- ads + Velto Plus ---------- */
#adBar { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 52px; max-height: 100px; padding: 4px 10px; background: #f7f5ff; border-top: 1px solid #e2ddf7; overflow: hidden; }
#adBar.hidden { display: none; }
#adBar .ad-label { font-size: 10px; color: #8a8f99; border: 1px solid #c9ccd3; border-radius: 3px; padding: 0 4px; }
#adBar .house { font-size: 13px; color: #3b3366; }
#adBar .ad-remove { white-space: nowrap; }
.primary-plus, .plus-card .plus-plan:hover:not(:disabled) { border-color: #5b4bdb; }
.primary-plus { background: #5b4bdb; color: #fff; font-weight: 600; }
.primary-plus:hover:not(:disabled) { background: #4a3bc4 !important; }
.plan-line { font-size: 12px; color: #5b6472; padding: 4px 10px; }
.plan-line.plus { color: #4a3bc4; font-weight: 600; }
#userExtra button { width: 100%; }
.plus-card { position: relative; width: 560px; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); overflow-y: auto; }
.plus-card h3 { font-size: 20px; color: #3d2fb0; }
.plus-close { position: absolute; top: 12px; right: 12px; border: none; background: none; font-size: 16px; color: #7a8391; }
.plus-reason { background: #fff6dd; color: #7a5300; padding: 9px 11px; border-radius: 8px; margin: 0 0 10px; }
.plus-reason.hidden, .plus-msg.hidden { display: none; }
.plus-perks { margin: 0 0 14px; padding-left: 20px; line-height: 1.8; }
.plus-perks span { color: #8a8f99; font-size: 12px; }
.plus-plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.plus-plan { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 8px 12px; border: 2px solid #e2ddf7; border-radius: 12px; background: #fff; }
.plus-plan:hover:not(:disabled) { background: #f7f5ff !important; }
.plus-name { font-weight: 600; color: #333b47; }
.plus-price { font-size: 24px; font-weight: 800; color: #3d2fb0; }
.plus-per { font-size: 12px; color: #7a8391; }
.plus-tag { position: absolute; top: -9px; background: #ff8a3d; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 8px; border-radius: 10px; }
.plus-note { font-size: 12px; color: #7a8391; margin: 12px 0 0; }
.plus-msg { margin: 10px 0 0; padding: 9px 11px; border-radius: 8px; background: #edf3ff; color: #1e4fa8; }
.plus-msg.warn { background: #fdecec; color: #a32020; }
.plus-msg.ok { background: #e8f7ee; color: #1d6b3a; }
@media (max-width: 520px) { .plus-plans { grid-template-columns: 1fr; } }
@media print { #adBar { display: none !important; } }
.web-links { margin-top: 18px; font-size: 12px; color: #8a8f99; }
.web-links a { color: #5b4bdb; text-decoration: none; }
