/* CalmPDF 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;
}
@font-face {
  font-family: "Frank Ruhl Libre";
  src: url("fonts/FrankRuhlLibre_400Regular.ttf") format("truetype");
  font-weight: 400;
}
@font-face {
  font-family: "Frank Ruhl Libre";
  src: url("fonts/FrankRuhlLibre_700Bold.ttf") format("truetype");
  font-weight: 700;
}
@font-face { font-family: "Heebo"; src: url("fonts/Heebo_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Heebo"; src: url("fonts/Heebo_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "Assistant"; src: url("fonts/Assistant_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Assistant"; src: url("fonts/Assistant_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "David Libre"; src: url("fonts/DavidLibre_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "David Libre"; src: url("fonts/DavidLibre_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "Alef"; src: url("fonts/Alef_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Alef"; src: url("fonts/Alef_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "Tinos"; src: url("fonts/Tinos_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Tinos"; src: url("fonts/Tinos_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "Cousine"; src: url("fonts/Cousine_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Cousine"; src: url("fonts/Cousine_700Bold.ttf") format("truetype"); font-weight: 700; }
@font-face { font-family: "Varela Round"; src: url("fonts/VarelaRound_400Regular.ttf") format("truetype"); font-weight: 400; }
@font-face { font-family: "Secular One"; src: url("fonts/SecularOne_400Regular.ttf") format("truetype"); font-weight: 400; }

html[data-dark] {
  --bg: #15171d;
  --panel: #1e2129;
  --ink: #e6e8ef;
  --muted: #99a0b3;
  --line: #333846;
}
:root {
  --bg: #f0f1f5;
  --panel: #ffffff;
  --ink: #1c1e26;
  --muted: #6b7080;
  --line: #dcdfe8;
  --accent: #2450b8;
  --accent-dark: #1c418f;
  --accent-tint: #e8edfb;
  --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: 6px;
  padding: 8px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  z-index: 20;
}
.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  margin-right: 6px;
  white-space: nowrap;
}
.brand-mark { color: var(--accent); text-decoration: none; display: inline-flex; align-items: center; }
.brand-mark img { height: 22px; max-width: 64px; object-fit: contain; display: block; border-radius: 4px; align-self: center; }
.brand-name {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.brand-name:hover::after {
  content: " ✎";
  font-size: 12px;
  color: var(--muted);
}
.brand-by { font-size: 11.5px; font-weight: 400; color: var(--muted); }
.tb-group { display: flex; align-items: center; gap: 4px; }
.tb-label { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-right: -4px; }
.tb-spacer { flex: 1; }
.tb-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 7px;
  font: inherit;
  font-size: 13px;
  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: var(--accent-dark); color: var(--accent-ink); }
.tb-btn.tool.active {
  background: var(--accent-tint);
  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);
}
/* ── dropdown menus ── */
.menu { position: relative; }
.menu-drop {
  position: absolute;
  top: calc(100% + 4px); left: 0;
  min-width: 230px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 40;
}
.menu-drop hr { border: none; border-top: 1px solid var(--line); margin: 5px 2px; }
.menu-drop .mi {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 7px 10px;
  border-radius: 7px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--ink);
}
.menu-drop .mi:hover { background: var(--accent-tint); color: var(--accent-dark); }
.menu-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

/* ── search bar ── */
.search-bar {
  position: fixed;
  top: 54px; right: 20px;
  display: flex; align-items: center; gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 7px;
  z-index: 45;
}
.search-bar input {
  font: inherit; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px;
  width: 220px;
}
.search-bar #search-count { font-size: 12px; color: var(--muted); min-width: 48px; text-align: center; }
.search-flash {
  position: absolute;
  background: rgba(255, 213, 74, 0.55);
  outline: 2px solid var(--accent);
  border-radius: 3px;
  animation: searchflash 1.6s ease-out forwards;
  pointer-events: none;
  z-index: 8;
}
@keyframes searchflash { 0%, 70% { opacity: 1; } 100% { opacity: 0.35; } }

/* ── shapes / stamps / fields ── */
.ov-shape-box { border: 2.5px solid; border-radius: 2px; }
.ov-shape-ellipse { border: 2.5px solid; border-radius: 50%; }
.ov-shape-arrow { pointer-events: none; }
.tool-select .ov-shape-arrow { pointer-events: auto; }
.ov-stamp {
  display: flex; align-items: center; justify-content: center;
  border: 2.5px solid; border-radius: 6px;
  font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; white-space: nowrap; overflow: hidden;
  background: rgba(255,255,255,0.55);
}
.ov-field {
  border: 1.5px dashed #7b2fa8;
  background: rgba(123, 47, 168, 0.06);
  border-radius: 3px;
}
.ov-field .f-tag {
  position: absolute; top: -16px; left: 0;
  font-size: 10px; color: #7b2fa8; white-space: nowrap;
}
.crop-shade { position: absolute; background: rgba(20, 24, 40, 0.45); pointer-events: none; z-index: 4; }
.snap-guide { position: absolute; background: var(--accent); opacity: 0.8; pointer-events: none; z-index: 9; }

/* selectable text layer sits under overlays; active only with Select tool.
   The layer itself never eats clicks — only its text spans do. */
.text-select-layer { position: absolute; inset: 0; pointer-events: none; }
.text-select-layer span {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
  font-family: "Rubik", sans-serif;
  user-select: text;
  pointer-events: auto;
}
.text-select-layer span::selection { background: rgba(36, 80, 184, 0.30); }
.overlay-root:not(.tool-select) .text-select-layer span { pointer-events: none; }

.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: var(--accent-tint); }
.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-edit { cursor: text; }
.overlay-root.tool-draw, .overlay-root.tool-highlight, .overlay-root.tool-whiteout { cursor: crosshair; }
.overlay-root.tool-image, .overlay-root.tool-sign, .overlay-root.tool-note { cursor: copy; }
.overlay-root.tool-link, .overlay-root.tool-shape, .overlay-root.tool-crop,
.overlay-root.tool-field-text { cursor: crosshair; }
.overlay-root.tool-stamp, .overlay-root.tool-field-check { 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-link {
  background: rgba(36, 80, 184, 0.10);
  border: 1.5px dashed rgba(36, 80, 184, 0.55);
  border-radius: 3px;
}
.ov-note { font-size: 18px; line-height: 1; cursor: pointer; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.ov-img img { display: block; width: 100%; height: 100%; }
.ov-ink { pointer-events: none; }
.tool-select .ov-ink { pointer-events: auto; }
.text-hints { position: absolute; inset: 0; pointer-events: none; }
.text-hint {
  position: absolute;
  outline: 1.5px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 3px;
}
.text-hint:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.ov-grip {
  position: absolute;
  width: 16px; height: 16px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: move;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
  z-index: 7;
  touch-action: none;
}
.ov-grip:hover { transform: scale(1.15); }

.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); }
.sb-version {
  border: none; background: none; padding: 2px 4px;
  font: inherit; font-size: 11.5px; color: var(--muted);
  cursor: pointer; white-space: nowrap;
}
.sb-version:hover { color: var(--accent); text-decoration: underline; }
.sb-version .vnew {
  background: var(--accent); color: #fff;
  border-radius: 999px; padding: 1px 7px; margin-left: 5px;
  font-size: 10.5px; font-weight: 700;
}
.changelog-entry { margin-bottom: 14px; }
.changelog-entry h3 { margin: 0 0 4px; font-size: 13.5px; }
.changelog-entry ul { margin: 0; padding-left: 18px; }
.changelog-entry li { font-size: 13px; margin-bottom: 2px; }

/* ── 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-saved { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.sign-saved:empty { display: none; }
.sign-saved .sig {
  height: 46px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.sign-saved .sig:hover { border-color: var(--accent); }
.sign-saved .sig img { max-height: 36px; max-width: 130px; display: block; }
.sign-saved .sig .sig-del {
  border: none; background: none; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 2px;
}
.sign-saved .sig .sig-del:hover { color: var(--danger); }
#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; }

/* ── license lock ── */
.lock {
  position: fixed; inset: 0;
  background: rgba(240, 241, 245, 0.96);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.lock-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 34px;
  max-width: 420px;
  text-align: center;
}
.lock-logo { font-size: 40px; color: var(--accent); }
.lock-card h2 { margin: 8px 0 6px; font-size: 20px; }
.lock-card p { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.lock-card input {
  width: 100%;
  font: inherit;
  text-align: center;
  letter-spacing: 0.5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
}
.lock-card input:focus { border-color: var(--accent); outline: none; }
.lock-card .tb-btn.primary { width: 100%; padding: 10px; font-size: 15px; }
.lock-error { color: var(--danger) !important; font-weight: 700; }
.lock-note { font-size: 12px !important; margin-top: 12px !important; }

.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); }
.toast.ok { background: #2e7d32; color: #fff; }

@media (max-width: 1460px) {
  .tb-label, .brand-by { display: none; }
  .tb-btn { padding: 6px 6px; font-size: 12.5px; }
  #tool-options select { padding: 4px 4px; }
}
@media (max-width: 900px) {
  .thumbs { width: 120px; }
  .thumb { width: 96px; }
  .sb-hint { display: none; }
}

/* dark-mode refinements: paper stays white, chrome goes dark */
html[data-dark] .thumbs { background: #191c23; }
html[data-dark] .dropzone { border-color: #3a4052; }
html[data-dark] .dz-inner h1 { color: var(--ink); }
html[data-dark] .lock { background: rgba(15, 17, 22, 0.94); }
.sb-ocr {
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 8px;
  padding: 1px 7px;
}

html[data-dark] .toast { background: #dfe3ee; color: #1c1e26; }
html[data-dark] .toast.ok { background: #2e7d32; color: #fff; }
html[data-dark] .thumb-tools button { background: rgba(230, 232, 239, 0.25); }

/* ── RTL (Hebrew UI) ── */
html[dir="rtl"] .menu-drop { left: auto; right: 0; }
html[dir="rtl"] .menu-drop .mi { text-align: right; }
html[dir="rtl"] .search-bar { right: auto; left: 20px; }
html[dir="rtl"] .thumbs { border-right: none; border-left: 1px solid var(--line); }
html[dir="rtl"] .panel { border-left: none; border-right: 1px solid var(--line); }
html[dir="rtl"] .brand-name:hover::after { content: " ✎"; }
html[dir="rtl"] .sb-file { direction: ltr; }
html[dir="rtl"] .lock-card input { direction: ltr; }
