:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --border: #e3e7ee;
  --ink: #1e2430;
  --muted: #687283;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .14);
  --radius: 8px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  flex: none;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: 10px; }
.brand-icon { width: 26px; height: 26px; color: var(--accent); stroke-width: 1.8; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: -.01em; white-space: nowrap; }
.brand-free { color: var(--accent); }
.brand-sub { font-size: 10px; color: var(--muted); display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.brand-sub svg { width: 10px; height: 10px; }

.tb-group { display: flex; align-items: center; gap: 3px; }
.tb-sep { width: 1px; height: 26px; background: var(--border); margin: 0 7px; flex: none; }
.tb-spacer { flex: 1; }

.tb-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 11px;
  border-radius: var(--radius);
  font-weight: 500;
  color: var(--ink);
  transition: background .12s;
  white-space: nowrap;
}
.tb-btn:hover:not(:disabled) { background: #f1f3f8; }
.tb-btn.accent { background: var(--accent); color: #fff; }
.tb-btn.accent:hover:not(:disabled) { background: var(--accent-hover); }
.tb-btn.sig { border: 1.5px dashed #b9b3f5; color: var(--accent); }
.tb-btn.sig:hover:not(:disabled) { background: var(--accent-soft); }

.tb-icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: #4b5565;
  transition: background .12s, color .12s;
}
.tb-icon:hover:not(:disabled) { background: #f1f3f8; color: var(--ink); }
.tb-icon.tool.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

.zoom-label { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }

.page-ind { display: flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; margin-right: 2px; }
.page-ind input {
  width: 42px; padding: 5px 4px; text-align: center;
  border: 1px solid var(--border); border-radius: 6px; font: inherit;
  font-variant-numeric: tabular-nums;
}
.page-ind input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* dropdowns */
.dd { position: relative; }
.dd-toggle { width: 46px; gap: 0; }
.dd-caret { width: 11px; height: 11px; margin-left: 1px; opacity: .6; }
.dd-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 4px; min-width: 150px;
  display: none; flex-direction: column; z-index: 60;
}
.dd.open .dd-menu { display: flex; }
.dd-menu button {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 6px; text-align: left;
}
.dd-menu button:hover { background: #f1f3f8; }
.dd-menu svg { width: 16px; height: 16px; color: #4b5565; }

/* ---------- Options bar ---------- */
.optionsbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  display: flex; align-items: center; gap: 18px;
  flex: none; min-height: 42px;
  z-index: 30;
  flex-wrap: wrap;
}
.optionsbar.hidden { display: none; }
.opt-group { display: flex; align-items: center; gap: 8px; }
.opt-group.hidden { display: none; }
.opt-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.opt-val { font-size: 12px; color: var(--muted); min-width: 18px; font-variant-numeric: tabular-nums; }
.opt-hint { font-size: 12px; color: var(--muted); margin-left: auto; }

.swatches { display: flex; gap: 5px; }
.swatch {
  width: 21px; height: 21px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.12); cursor: pointer;
  transition: transform .1s;
  position: relative;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.swatch.custom { overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }

input[type="range"] { accent-color: var(--accent); width: 110px; }

#optFont select, #optFont input[type="number"] {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; background: #fff;
}
#optFont input[type="number"] { width: 58px; }

.opt-toggle {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--border); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.opt-toggle.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.opt-check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.opt-check input { accent-color: var(--accent); }

.opt-danger {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 6px;
  color: var(--danger); font-weight: 500;
}
.opt-danger:hover { background: #fee8e8; }
.opt-danger svg { width: 15px; height: 15px; }

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

.sidebar {
  width: 178px; flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: margin-left .18s ease;
}
.sidebar.collapsed { margin-left: -178px; }
.sidebar-head {
  padding: 10px 14px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.thumbs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }

.thumb { position: relative; cursor: pointer; }
.thumb canvas {
  display: block; width: 100%; background: #fff;
  border: 1px solid var(--border); border-radius: 4px;
  box-shadow: var(--shadow);
}
.thumb.current canvas { outline: 2.5px solid var(--accent); outline-offset: 1px; }
.thumb .t-num {
  position: absolute; bottom: 26px; right: 5px;
  background: rgba(30,36,48,.75); color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 99px;
}
.t-actions {
  display: flex; justify-content: center; gap: 2px; padding-top: 3px;
  opacity: 0; transition: opacity .12s;
}
.thumb:hover .t-actions, .thumb.current .t-actions { opacity: 1; }
.t-actions button {
  width: 24px; height: 22px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.t-actions button:hover { background: #eceef4; color: var(--ink); }
.t-actions button.t-del:hover { background: #fee8e8; color: var(--danger); }
.t-actions svg { width: 13px; height: 13px; }

/* ---------- Viewer ---------- */
.viewer { flex: 1; overflow: auto; position: relative; scroll-behavior: smooth; }

.pages { padding: 28px 40px 60px; display: flex; flex-direction: column; align-items: center; gap: 26px; }

.page-wrap { position: relative; flex: none; }
.page-inner {
  position: relative; transform-origin: 0 0;
  background: #fff; box-shadow: 0 2px 10px rgba(16,24,40,.12), 0 0 1px rgba(16,24,40,.2);
  border-radius: 2px;
}
.page-inner canvas.pdfc { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.hl-layer, .vec-layer { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hl-layer { mix-blend-mode: multiply; }
.anno-layer { position: absolute; inset: 0; pointer-events: none; }
.anno-layer .anno { pointer-events: auto; }
.page-inner:not(.tool-select) .anno-layer .anno:not(.editing) { pointer-events: none; }
.page-inner:not(.tool-select) .vec-layer [data-id],
.page-inner:not(.tool-select) .hl-layer [data-id] { pointer-events: none; }

.hl-layer, .vec-layer { pointer-events: none; }
.hl-layer path, .vec-layer path { pointer-events: stroke; }
.vec-layer rect, .vec-layer ellipse { pointer-events: visiblePainted; }
.vec-layer [data-id], .hl-layer [data-id] { cursor: default; }
.page-inner.tool-select .vec-layer [data-id],
.page-inner.tool-select .hl-layer [data-id] { cursor: move; }

/* DOM annotations */
.anno { position: absolute; }
.anno.txt {
  white-space: pre; line-height: 1.3; padding: 3px 4px;
  outline: none; min-width: 8px; cursor: default;
  border: 1px dashed transparent; border-radius: 2px;
}
.anno.txt.editing { border-color: #8f9bff; background: rgba(255,255,255,.5); cursor: text; }
.anno.img { display: block; user-select: none; -webkit-user-drag: none; }
.tool-select .anno { cursor: move; }

/* Selection box */
.selbox { position: absolute; pointer-events: none; z-index: 20; --hs: calc(9px / var(--z, 1)); }
.selbox .sel-rect {
  position: absolute; inset: -2px;
  border: calc(1.5px / var(--z, 1)) solid var(--accent); border-radius: 1px;
}
.handle {
  position: absolute; width: var(--hs); height: var(--hs);
  background: #fff; border: calc(1.5px / var(--z, 1)) solid var(--accent); border-radius: 50%;
  pointer-events: auto;
}
.handle.nw { top: calc(var(--hs) / -1.3); left: calc(var(--hs) / -1.3); cursor: nwse-resize; }
.handle.ne { top: calc(var(--hs) / -1.3); right: calc(var(--hs) / -1.3); cursor: nesw-resize; }
.handle.sw { bottom: calc(var(--hs) / -1.3); left: calc(var(--hs) / -1.3); cursor: nesw-resize; }
.handle.se { bottom: calc(var(--hs) / -1.3); right: calc(var(--hs) / -1.3); cursor: nwse-resize; }
.handle.n { top: calc(var(--hs) / -1.3); left: calc(50% - var(--hs) / 2); cursor: ns-resize; }
.handle.s { bottom: calc(var(--hs) / -1.3); left: calc(50% - var(--hs) / 2); cursor: ns-resize; }
.handle.w { left: calc(var(--hs) / -1.3); top: calc(50% - var(--hs) / 2); cursor: ew-resize; }
.handle.e { right: calc(var(--hs) / -1.3); top: calc(50% - var(--hs) / 2); cursor: ew-resize; }
.handle.pt { width: calc(11px / var(--z, 1)); height: calc(11px / var(--z, 1)); }

/* tool cursors */
.page-inner.tool-text { cursor: text; }
.page-inner.tool-pen, .page-inner.tool-highlighter { cursor: crosshair; }
.page-inner.tool-rect, .page-inner.tool-ellipse, .page-inner.tool-line,
.page-inner.tool-arrow, .page-inner.tool-whiteout { cursor: crosshair; }
.page-inner.tool-check, .page-inner.tool-cross, .page-inner.tool-date,
.page-inner.tool-image, .page-inner.tool-place { cursor: copy; }

/* ---------- Empty state / SEO landing ---------- */
.empty-state { position: absolute; inset: 0; overflow-y: auto; display: flex; justify-content: center; padding: 48px 24px; }
.empty-state.hidden, .hidden { display: none !important; }
.landing { width: 100%; max-width: 880px; display: flex; flex-direction: column; align-items: center; }

.empty-card {
  background: var(--panel); border: 1.5px dashed #c4cbd8; border-radius: 16px;
  padding: 48px 56px; text-align: center; max-width: 560px; width: 100%;
  transition: border-color .15s, background .15s;
}
.empty-card.over { border-color: var(--accent); background: var(--accent-soft); }
.empty-icon { width: 54px; height: 54px; color: var(--accent); stroke-width: 1.4; margin-bottom: 18px; }
.empty-card h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 10px; }
.empty-card h1 .kw { color: var(--accent); }
.hero-sub { color: var(--muted); margin-bottom: 20px; font-size: 15px; line-height: 1.5; max-width: 440px; margin-left: auto; margin-right: auto; }

/* SEO content (visible on the landing screen, hidden once a PDF is open) */
.seo-content { width: 100%; max-width: 760px; margin-top: 40px; color: var(--ink); }
.seo-intro { color: #4b5565; font-size: 15px; line-height: 1.7; margin-bottom: 36px; text-align: center; }
.seo-content h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; text-align: center; margin-bottom: 20px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 44px; }
.feat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
.feat h3 { font-size: 14.5px; font-weight: 600; margin-bottom: 5px; }
.feat p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.faq { max-width: 640px; margin: 0 auto 40px; }
.qa { border-bottom: 1px solid var(--border); padding: 16px 2px; }
.qa h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.qa p { color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.seo-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 24px 0 8px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--border); }

.big-open {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14.5px;
  padding: 12px 26px; border-radius: 10px;
  box-shadow: var(--shadow); transition: background .12s, transform .12s;
  margin-bottom: 22px;
}
.big-open:hover { background: var(--accent-hover); transform: translateY(-1px); }
.big-open.subtle { background: #fff; color: var(--ink); border: 1px solid var(--border); margin-bottom: 12px; }
.big-open.subtle:hover { background: #f7f8fb; }

.privacy {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px !important; color: #16a34a !important; margin-bottom: 4px !important;
}
.privacy svg { width: 12px; height: 12px; }
.cap-note { font-size: 11.5px !important; color: var(--muted) !important; margin: 0 !important; }

/* ---------- Modals ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20, 24, 33, .5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 700px; max-width: calc(100vw - 32px); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.slim { width: 560px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; }
.modal-head h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.modal-x { width: 30px; height: 30px; border-radius: 7px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.modal-x:hover { background: #f1f3f8; color: var(--ink); }

.tabs { display: flex; gap: 2px; padding: 0 20px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 14px; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-page { padding: 18px 20px; overflow-y: auto; }

#sigCanvas {
  display: block; width: 100%; aspect-ratio: 640 / 240;
  border: 1.5px dashed #c4cbd8; border-radius: 10px;
  background: repeating-linear-gradient(transparent 0 56px, transparent 56px 57px),
              linear-gradient(#fff, #fff);
  cursor: crosshair; touch-action: none;
}
.sig-row { display: flex; align-items: center; gap: 18px; margin-top: 12px; }
.sig-thick { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.ghost-btn { padding: 7px 14px; border: 1px solid var(--border); border-radius: 8px; font-weight: 500; }
.ghost-btn:hover { background: #f1f3f8; }
.primary-btn {
  padding: 8px 18px; background: var(--accent); color: #fff;
  border-radius: 8px; font-weight: 600;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { background: #b6b3e8; }

#sigText {
  width: 100%; padding: 10px 14px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px;
}
#sigText:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.sig-fonts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; }
.sig-font {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 21px; text-align: center; white-space: nowrap; overflow: hidden;
  background: #fff;
}
.sig-font.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.sig-preview {
  margin-top: 14px; min-height: 86px; border-radius: 10px;
  background: #f7f8fb; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 44px; padding: 10px 16px; overflow: hidden; text-align: center;
}
.sig-preview.img img { max-height: 130px; max-width: 100%; }

.sig-saved { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; min-height: 100px; }
.sig-saved .empty { grid-column: 1/-1; color: var(--muted); text-align: center; padding: 30px 0; }
.sig-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  background: #fff; cursor: pointer; position: relative;
}
.sig-card:hover { border-color: var(--accent); }
.sig-card.active { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }
.sig-card img { max-width: 100%; height: 52px; object-fit: contain; }
.sig-card .del {
  position: absolute; top: 5px; right: 5px; width: 22px; height: 22px;
  border-radius: 6px; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.sig-card .del:hover { background: #fee8e8; color: var(--danger); }
.sig-card .del svg { width: 12px; height: 12px; }

.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-top: 1px solid var(--border); background: #fafbfd;
}
.modal-foot > div { display: flex; gap: 8px; }

.keys { width: 100%; border-collapse: collapse; margin: 6px 20px 22px; width: calc(100% - 40px); }
.keys td { padding: 7px 8px; font-size: 12.5px; color: var(--muted); }
.keys td:nth-child(even) { color: var(--ink); }
kbd {
  background: #f1f3f8; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1.5px 6px; font-family: inherit; font-size: 11px; color: var(--ink);
}

/* ---------- Drop overlay / toasts ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(79, 70, 229, .12); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  border: 3px dashed var(--accent);
}
.drop-inner {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 26px 44px; font-size: 17px; font-weight: 600;
  display: flex; align-items: center; gap: 12px; color: var(--accent);
}
.drop-inner svg { width: 28px; height: 28px; }

.toasts {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300;
  pointer-events: none;
}
.toast {
  background: #1e2430; color: #fff; padding: 10px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 9px; max-width: 480px;
  animation: toast-in .22s ease;
}
.toast.ok svg { color: #4ade80; }
.toast.err svg { color: #f87171; }
.toast svg { width: 16px; height: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1200px) {
  .tb-btn span { display: none; }
  .brand-sub { display: none; }
  .tb-btn { padding: 7px 9px; }
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: #c2c9d6; border-radius: 99px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #aab2c2; }
.sidebar ::-webkit-scrollbar-thumb, .modal ::-webkit-scrollbar-thumb { border-color: #fff; }
