/* ============================================================
   FreshPDF — Editor styles
   ============================================================ */

.editor-body {
  height: 100vh; height: 100dvh; /* dvh: correct height under mobile browser chrome */
  overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg);
  /* The landing page uses bold hard-offset shadows; the editor is a working
     tool, so soften them here for clean, calm chrome (accent colour stays). */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 6px 20px rgba(0,0,0,.12);
  --shadow-lg: 0 22px 50px -14px rgba(0,0,0,.32);
}

/* ---------- Top bar ---------- */
.ed-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  z-index: 30;
}
.ed-topbar-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.ed-brand .brand-name { font-size: 18px; }
.ed-filename { font-size: 14px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.ed-topbar-actions { display: flex; align-items: center; gap: 8px; }

.ed-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text-soft);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 13px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.ed-btn:hover { border-color: var(--sky-300); color: var(--text); background: var(--surface-2); }
.ed-btn-icon { padding: 8px 10px; }
.ed-btn-primary { background: linear-gradient(135deg, var(--sky-400), var(--sky-500)); color: #fff; border-color: transparent; box-shadow: 0 4px 12px -3px rgba(53,121,194,.45); }
.ed-btn-primary:hover { color: #fff; filter: brightness(1.05); }
.caret { font-size: 10px; opacity: .7; }

.ed-menu { position: relative; }
.ed-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 240px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 8px; display: none;
  max-height: 70vh; overflow-y: auto;
}
.ed-dropdown.open { display: block; }
.ed-dropdown .ed-drop-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); padding: 8px 10px 4px; font-weight: 700; }
.ed-dropdown button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  font-family: inherit; font-size: 14px; color: var(--text); background: none; border: 0; border-radius: 8px;
  padding: 9px 10px; cursor: pointer;
}
.ed-dropdown button:hover { background: var(--brand-soft); color: var(--brand-strong); }
.ed-dropdown button svg { flex-shrink: 0; color: var(--brand); }

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

/* Tool rail */
.ed-toolrail {
  width: 60px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0;
  overflow: visible; /* grouped flyouts pop out beside the rail */
}
.ed-tool {
  position: relative; flex-shrink: 0; width: 44px; height: 44px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text-soft); cursor: pointer; transition: all .14s;
}
.ed-tool:hover { background: var(--surface-2); color: var(--text); }
.ed-tool.is-active { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--sky-200); }
.ed-tool[aria-expanded="true"][data-tip]:hover::after { display: none; }
.ed-tool[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
  background: var(--text); color: var(--bg-alt); font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 6px;
  white-space: nowrap; z-index: 50; pointer-events: none;
}
.ed-tool-sep { flex-shrink: 0; width: 30px; height: 1px; background: var(--border); margin: 6px 0; }

/* Grouped tools: corner caret + flyout submenu */
.ed-tool-group { position: relative; }
.ed-tool-caret {
  position: absolute; right: 5px; bottom: 5px; width: 0; height: 0;
  border-left: 5px solid transparent; border-top: 5px solid transparent;
  border-bottom: 5px solid currentColor; border-right: 5px solid currentColor;
  border-bottom-right-radius: 3px; opacity: .45; transform: scale(.62); transform-origin: bottom right;
}
.ed-tool-group.is-active .ed-tool-caret, .ed-tool-group[aria-expanded="true"] .ed-tool-caret { opacity: .9; }
.ed-flyout {
  position: absolute; left: calc(100% + 10px); top: 0; z-index: 60; min-width: 208px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; gap: 2px;
  animation: flyIn .12s ease;
}
@keyframes flyIn { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }
.ed-flyout-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--text-soft);
  background: none; border: 0; border-radius: 8px; padding: 9px 10px; cursor: pointer;
}
.ed-flyout-item:hover { background: var(--surface-2); color: var(--text); }
.ed-flyout-item.is-active { background: var(--brand-soft); color: var(--brand-strong); }
.ed-flyout-item svg { flex-shrink: 0; }
.ed-flyout-item span { flex: 1; white-space: nowrap; }
.ed-flyout-item kbd {
  font-family: var(--mono); font-size: 11px; color: var(--text-mute);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px;
}
.ed-flyout-item.is-active kbd { color: var(--brand-strong); border-color: var(--sky-200); background: transparent; }
.ed-flyout-item:focus-visible { outline: 2px solid var(--sky-500); outline-offset: -2px; }

/* Pages panel */
.ed-pages {
  width: 168px; flex-shrink: 0; background: var(--bg-alt); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.ed-pages-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-size: 13px; font-weight: 700; color: var(--text-soft); border-bottom: 1px solid var(--border); }
.ed-thumbs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.ed-thumb {
  position: relative; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer;
  background: #fff; transition: border-color .15s; box-shadow: var(--shadow-sm);
}
.ed-thumb.is-active { border-color: var(--sky-400); }
.ed-thumb canvas { display: block; width: 100%; height: auto; }
.ed-thumb-num { position: absolute; bottom: 4px; left: 4px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(15,42,67,.72); padding: 1px 7px; border-radius: 6px; }
.ed-thumb-tools { position: absolute; top: 4px; right: 4px; display: flex; gap: 3px; opacity: 0; transition: opacity .15s; }
.ed-thumb:hover .ed-thumb-tools, .ed-thumb:focus-within .ed-thumb-tools { opacity: 1; }
.ed-thumb-tools button {
  width: 22px; height: 22px; border: 0; border-radius: 6px; background: rgba(15,42,67,.8); color: #fff;
  font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.ed-thumb-tools button:hover { background: var(--sky-500); }

/* Canvas workspace */
/* pan-x pan-y: allow one-finger scrolling but disable the browser's native
   pinch-zoom so our own pinch-to-zoom controls the document scale */
.ed-canvas-wrap { flex: 1; position: relative; overflow: auto; background: var(--surface-2); min-width: 0; touch-action: pan-x pan-y; }
[data-theme="dark"] .ed-canvas-wrap { background: #0a1420; }
.ed-pageview { display: none; flex-direction: column; align-items: center; gap: 22px; padding: 28px 20px 60px; min-height: 100%; }
.ed-pageview.active { display: flex; }

.ed-page {
  position: relative; background: #fff; box-shadow: var(--shadow-lg); border-radius: 2px;
  /* size set inline */
}
.ed-page canvas.ed-page-canvas { display: block; position: absolute; inset: 0; }
.ed-page canvas.ed-draw-layer { position: absolute; inset: 0; z-index: 2; touch-action: none; }
.ed-annot-layer { position: absolute; inset: 0; z-index: 3; }
/* Alignment grid overlay */
.ed-pageview.show-grid .ed-annot-layer {
  background-image:
    linear-gradient(rgba(20,184,166,.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20,184,166,.18) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* Annotations */
.annot {
  position: absolute; cursor: move; box-sizing: border-box;
  touch-action: none; /* so touch-dragging an annotation doesn't scroll the page */
}
.annot.selected { outline: 1.5px dashed var(--sky-500); outline-offset: 2px; }
/* The editable text sits in a child of the wrapper (never contains the ✕
   button), sized to its content so it grows as you type and never collapses
   into one-character-per-line wrapping. Line breaks only via Enter. */
.annot-text {
  display: block; width: max-content; min-width: 8px; min-height: 1em;
  padding: 2px 4px; outline: none;
  font-family: Helvetica, Arial, sans-serif; white-space: pre; line-height: 1.25;
}
.annot-text:focus { cursor: text; }
/* an empty, unfocused text box stays visible & tappable */
.annot-text:empty::before { content: "Type…"; color: var(--text-mute); opacity: .65; }
.annot-text:focus:empty::before { content: ""; }
.annot-image img, .annot-sig img { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; }
/* Sticky notes */
.annot-note { border-radius: 3px; box-shadow: 0 6px 16px -4px rgba(0,0,0,.28); min-height: 46px; }
.annot-note-head { height: 14px; background: rgba(0,0,0,.08); border-radius: 3px 3px 0 0; cursor: move; display: flex; align-items: center; justify-content: center; }
.annot-note-dots { font-size: 9px; color: rgba(0,0,0,.35); letter-spacing: 1px; line-height: 1; }
.annot-note-body { padding: 7px 10px; min-height: 30px; outline: none; color: #5b4708; font-family: Helvetica, Arial, sans-serif; line-height: 1.35; word-break: break-word; }
.annot-handle {
  position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid var(--sky-500);
  border-radius: 50%; right: -7px; bottom: -7px; cursor: nwse-resize; z-index: 5;
}
.annot-del {
  position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; border-radius: 50%;
  background: #ef4444; color: #fff; border: 2px solid #fff; font-size: 12px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center; z-index: 6;
}
.annot.selected .annot-del { display: inline-flex; }
.annot.selected .annot-handle { display: block; }
.annot-handle { display: none; }

/* Interactive widgets: hyperlink, form text field, checkbox */
.annot-widget { display: flex; align-items: center; padding: 0 6px; overflow: hidden; box-sizing: border-box; border-radius: 4px; }
.widget-link { border: 1.5px dashed #2563eb; background: rgba(37,99,235,.08); }
.widget-field { border: 1.5px solid #2563eb; background: rgba(37,99,235,.05); }
.widget-check { border: 1.5px solid #1f9e6f; background: rgba(31,158,111,.08); justify-content: center; padding: 0; }
.annot-wlabel { font-family: var(--mono); font-size: 11px; color: #1d4ed8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.widget-check .annot-wlabel { color: #1f9e6f; font-size: 14px; }

/* Compare (diff) output */
.cmp-legend { display: flex; gap: 14px; font-size: 12px; margin-bottom: 10px; }
.cmp-legend span { padding: 1px 8px; border-radius: 5px; }
.cmp-out { max-height: 340px; overflow-y: auto; line-height: 1.7; font-size: 14px; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.cmp-add { background: #c9f0dc; color: #0d7a4f; border-radius: 3px; }
.cmp-del { background: #f6d9d1; color: #b23a1c; text-decoration: line-through; border-radius: 3px; }
.cmp-same { color: var(--text-soft); }

/* Empty state */
.ed-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ed-empty.hidden { display: none; }
.ed-empty-card {
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 48px 44px; text-align: center; max-width: 460px; transition: border-color .2s, background .2s;
}
.ed-empty-card.dragover { border-color: var(--sky-400); background: var(--brand-soft); }
.ed-empty-ico { color: var(--sky-400); margin-bottom: 18px; }
.ed-empty-card h2 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.ed-empty-card p { color: var(--text-soft); margin: 0 0 22px; }
.ed-empty-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.ed-empty-hint { font-size: 13px; color: var(--text-mute); margin: 0; }

/* Properties panel */
.ed-props { width: 240px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.ed-props-head { padding: 14px 16px; font-size: 13px; font-weight: 700; color: var(--text-soft); border-bottom: 1px solid var(--border); }
.ed-props-body { flex: 1; overflow-y: auto; padding: 16px; }
.ed-props-empty { color: var(--text-mute); font-size: 14px; text-align: center; margin-top: 30px; }
.ed-field { margin-bottom: 16px; }
.ed-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.ed-input, .ed-props select, .ed-props input[type="text"], .ed-props input[type="number"] {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px;
}
.ed-input:focus { outline: none; border-color: var(--sky-400); box-shadow: 0 0 0 3px var(--brand-soft); }
.ed-row { display: flex; gap: 10px; align-items: center; }
.ed-row > * { flex: 1; }
.ed-color-row { display: flex; gap: 8px; align-items: center; }
.ed-color-row input[type="color"] { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); cursor: pointer; }
.ed-swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ed-swatch { width: 24px; height: 24px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.ed-swatch.is-active { border-color: var(--text); }
.ed-range { width: 100%; accent-color: var(--sky-500); }
.ed-hint { font-size: 12px; color: var(--text-mute); margin: 4px 0 0; }
.ed-prop-btn { width: 100%; margin-top: 4px; }

/* Segmented button group (bold / alignment / orientation) */
.ed-btn-group { display: flex; gap: 6px; }
.ed-seg { flex: 1; font-family: inherit; font-size: 14px; color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 8px 6px; cursor: pointer; transition: all .14s; }
.ed-seg:hover { border-color: var(--sky-300); color: var(--text); }
.ed-seg.on { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--sky-300); }

/* Stamp picker */
.stamp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stamp-choice { font-family: Arial, sans-serif; font-weight: 700; font-size: 14px; letter-spacing: .04em; background: var(--surface); border: 2px solid; border-radius: 8px; padding: 12px 8px; cursor: pointer; transition: transform .12s; }
.stamp-choice:hover { transform: scale(1.04); }

/* OCR progress */
.ocr-track { height: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 4px 0; }
.ocr-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--sky-400), var(--sky-500)); transition: width .25s ease; }

/* Find results */
.find-results { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.find-count { font-size: 13px; font-weight: 700; color: var(--brand-strong); margin: 4px 0; }
.find-hit { text-align: left; font-family: inherit; font-size: 13.5px; color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; cursor: pointer; line-height: 1.4; }
.find-hit:hover { border-color: var(--sky-300); color: var(--text); }
.find-hit mark { background: var(--sky-200); color: var(--text); border-radius: 3px; padding: 0 2px; }
.find-pg { display: inline-block; font-size: 11px; font-weight: 700; color: var(--brand-strong); background: var(--brand-soft); border-radius: 5px; padding: 1px 6px; margin-right: 6px; }

/* Status bar */
.ed-statusbar {
  height: calc(40px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px; background: var(--surface); border-top: 1px solid var(--border); font-size: 13px; color: var(--text-mute);
}
.ed-status-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ed-status-tools { display: flex; gap: 6px; }
.ed-status-tools .ed-icon-btn.on { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--sky-300); }
.ed-zoom { display: flex; align-items: center; gap: 6px; }
.ed-zoom span { min-width: 46px; text-align: center; font-weight: 600; color: var(--text-soft); }
.ed-icon-btn {
  width: 30px; height: 28px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2);
  color: var(--text-soft); font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.ed-icon-btn:hover { border-color: var(--sky-300); color: var(--brand-strong); }
.ed-zoom .ed-icon-btn:last-child { width: auto; padding: 0 10px; font-size: 13px; font-weight: 600; }
.ed-pageinfo { white-space: nowrap; }

/* ---------- Modals ---------- */
.ed-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(10,22,34,.55); backdrop-filter: blur(3px); }
.ed-modal[hidden] { display: none; }
.ed-modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.ed-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.ed-modal-head h3 { font-size: 18px; font-weight: 700; }
.ed-modal-close { width: 32px; height: 32px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text-soft); font-size: 15px; cursor: pointer; }
.ed-modal-close:hover { color: var(--text); }
.ed-modal-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.ed-modal-body .ed-field { margin: 0; }
.ed-modal-body p { margin: 0; color: var(--text-soft); font-size: 14.5px; }
.ed-modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* Signature modal */
.ed-sig-tabs { display: flex; gap: 6px; padding: 16px 22px 0; }
.ed-tab { flex: 1; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px; cursor: pointer; }
.ed-tab.is-active { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--sky-300); }
.ed-sig-panel { padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }
#sigCanvas { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; }
.ed-sig-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ed-sig-row label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.ed-sig-preview { min-height: 90px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: #0f2a43; font-size: 38px; font-family: 'Segoe Script', cursive; padding: 10px; }
.ed-sig-preview img { max-height: 120px; max-width: 100%; }

/* Toast */
.ed-toast {
  position: fixed; left: 50%; bottom: 58px; transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg-alt); font-size: 14px; font-weight: 600;
  padding: 11px 20px; border-radius: 999px; box-shadow: var(--shadow-lg); z-index: 120; opacity: 0;
  transition: opacity .25s, transform .25s; pointer-events: none; max-width: 90vw;
}
.ed-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ed-toast[hidden] { display: none; }
.ed-toast.err { background: #dc2626; color: #fff; }
.ed-toast.ok { background: #0d7a4f; color: #fff; }

/* Loading spinner */
.ed-spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--sky-500); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ed-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text-soft); z-index: 20; }
#busyOverlay { position: fixed; inset: 0; z-index: 130; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--text); font-weight: 600; background: color-mix(in srgb, var(--bg) 72%, transparent); backdrop-filter: blur(2px); }

/* Selection badge in the properties panel */
.ed-sel-badge {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; font-weight: 700; color: var(--brand-strong);
  background: var(--brand-soft); border: 1px solid var(--sky-300); border-radius: 10px;
  padding: 8px 10px 8px 12px; margin-bottom: 16px;
}
.ed-sel-badge .ed-seg { flex: 0 0 auto; font-size: 12.5px; padding: 5px 10px; }

/* Session-restore bar in the empty state */
.ed-restore {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  text-align: left; font-size: 14px; color: var(--text);
  background: var(--brand-soft); border: 1.5px solid var(--sky-300); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 20px;
}
.ed-restore em { color: var(--text-mute); font-style: normal; font-size: 12.5px; }
.ed-restore-actions { display: flex; gap: 8px; }

/* Lazy-loading page shimmer */
.ed-page-loading { background: linear-gradient(100deg, #fff 40%, #e9f1f9 50%, #fff 60%); background-size: 200% 100%; animation: pageShimmer 1.2s linear infinite; }
[data-theme="dark"] .ed-page-loading { background: linear-gradient(100deg, #f0f5fa 40%, #dfe9f3 50%, #f0f5fa 60%); background-size: 200% 100%; }
@keyframes pageShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .ed-page-loading { animation: none; } }

/* Thumbnail drag-to-reorder */
.ed-thumb.is-dragging { opacity: .45; outline: 2px dashed var(--sky-400); }
.ed-thumb-marker { height: 4px; border-radius: 2px; background: var(--sky-500); margin: -4px 0 0; }

/* Keyboard focus visibility */
.ed-btn:focus-visible, .ed-tool:focus-visible, .ed-icon-btn:focus-visible, .btn:focus-visible,
.ed-seg:focus-visible, .ed-tab:focus-visible, .ed-swatch:focus-visible, .theme-toggle:focus-visible {
  outline: 2px solid var(--sky-500); outline-offset: 2px;
}

/* Recent-colour history row */
.ed-recent { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.ed-recent-label { font-size: 11px; color: var(--text-mute); margin: 8px 0 2px; }

/* Properties panel head close (mobile bottom-sheet only) */
.ed-props-head { display: flex; align-items: center; justify-content: space-between; }
.ed-props-grab { display: none; }
.ed-props-close { display: none; width: 30px; height: 30px; border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text-soft); font-size: 15px; cursor: pointer; }

/* Floating "Options" button (mobile) */
.ed-fab {
  position: fixed; right: 14px; bottom: calc(52px + env(safe-area-inset-bottom)); z-index: 70;
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: linear-gradient(135deg, var(--sky-400), var(--sky-500)); color: #fff;
  box-shadow: var(--shadow-md); display: none; align-items: center; justify-content: center; cursor: pointer;
}
.ed-fab.show { display: inline-flex; }
.ed-fab:active { transform: scale(.94); }
.ed-sheet-backdrop { position: fixed; inset: 0; background: rgba(10,22,34,.12); z-index: 79; opacity: 0; pointer-events: none; transition: opacity .2s; }
.ed-sheet-backdrop.show { opacity: 1; pointer-events: auto; }

/* Keyboard-shortcut help grid */
.sk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; }
.sk-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--text-soft); }
.sk-row kbd { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: 2px 7px; color: var(--text); white-space: nowrap; }
.sk-cat { grid-column: 1 / -1; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-strong); margin-top: 6px; font-weight: 700; }
@media (max-width: 560px) { .sk-grid { grid-template-columns: 1fr; } }

/* Bigger touch targets on touch devices */
@media (pointer: coarse) {
  .annot-handle { width: 20px; height: 20px; right: -12px; bottom: -12px; }
  .annot-del { width: 30px; height: 30px; top: -16px; right: -16px; font-size: 15px; }
  .ed-tool { width: 46px; height: 46px; }
  .ed-thumb-tools button { width: 30px; height: 30px; font-size: 15px; }
  .ed-icon-btn { width: 36px; height: 34px; }
}

/* ---------- Responsive editor ---------- */
@media (max-width: 1024px) {
  /* Properties become a slide-up bottom sheet instead of vanishing */
  .ed-props {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 80;
    max-height: 62vh; border-left: 0; border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.22);
    transform: translateY(105%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  }
  .ed-props.sheet-open { transform: translateY(0); }
  .ed-props-grab { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 2px; }
  .ed-props-head { padding: 4px 16px 12px; }
  .ed-props-close { display: inline-flex; }
  .ed-props-body { padding: 4px 18px calc(24px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  .ed-pages { display: none; }
  .ed-filename { max-width: 22vw; }
  .ed-topbar { padding: 0 10px; gap: 8px; }
  .ed-topbar-actions { gap: 6px; }
  .ed-btn { padding: 8px 10px; }
  .ed-btn-label { display: none; }   /* icon-only Open / Download */
  #btnPrint, #btnNew { display: none; } /* New lives in the empty state; Print via Ctrl+P */
}
@media (max-width: 480px) {
  .ed-brand .brand-name { display: none; } /* logo mark only */
  .ed-filename { display: none; }
  .ed-statusbar { padding: 0 8px; gap: 8px; }
  #btnZoomPage, #btnHelp { display: none; }
  .ed-pageinfo { font-size: 12px; }
}
/* Keep toasts clear of the floating Options button on mobile */
@media (max-width: 1024px) {
  .ed-toast { bottom: 118px; }
}
/* Pointer-fine (desktop) never shows the mobile-only chrome */
@media (min-width: 1025px) {
  .ed-fab, .ed-sheet-backdrop { display: none !important; }
}

/* ---------- Signature vault ---------- */
.ed-sig-saved { padding: 10px 22px 0; }
.ed-sig-saved-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); margin-bottom: 8px; }
.ed-sig-saved-row { display: flex; gap: 10px; flex-wrap: wrap; }
.ed-sig-chip { position: relative; display: inline-flex; }
.ed-sig-use {
  height: 46px; min-width: 84px; max-width: 150px; padding: 4px 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; transition: border-color .14s, box-shadow .14s;
}
.ed-sig-use:hover { border-color: var(--sky-300); box-shadow: var(--shadow-sm); }
.ed-sig-use img { max-height: 34px; max-width: 128px; object-fit: contain; }
[data-theme="dark"] .ed-sig-use { background: #f5f8fb; }
.ed-sig-rm {
  position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%;
  border: 0; background: var(--text-mute); color: #fff; font-size: 10px; line-height: 1; cursor: pointer; display: none;
  align-items: center; justify-content: center;
}
.ed-sig-chip:hover .ed-sig-rm { display: inline-flex; }
.ed-sig-rm:hover { background: #c2410c; }

/* ---------- Version history ---------- */
.ed-verlist { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.ed-ver { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 14px; background: var(--surface-2); border-radius: 10px; }
.ed-ver-meta { display: flex; flex-direction: column; min-width: 0; }
.ed-ver-meta strong { font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-ver-meta span { font-size: 12px; color: var(--text-mute); }

/* ---------- Command palette ---------- */
.ed-palette-card { width: min(560px, 92vw); padding: 10px !important; align-self: flex-start; margin-top: 12vh; }
.ed-palette-input { width: 100%; font-size: 15px; padding: 12px 14px; border-radius: 10px; }
.ed-palette-list { margin-top: 8px; max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.ed-palette-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text-soft);
}
.ed-palette-item svg { flex-shrink: 0; color: var(--brand); }
.ed-palette-item span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-palette-item kbd { font-family: var(--mono); font-size: 11px; color: var(--text-mute); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }
.ed-palette-item:hover { background: var(--surface-2); color: var(--text); }
.ed-palette-item.is-sel { background: var(--brand-soft); color: var(--brand-strong); }
.ed-palette-item.is-sel kbd { background: transparent; border-color: var(--sky-200); color: var(--brand-strong); }
.ed-palette-empty { padding: 18px; text-align: center; color: var(--text-mute); font-size: 14px; }

/* ---------- Starter templates ---------- */
.ed-templates { margin: 18px 0 4px; }
.ed-templates-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mute); margin-bottom: 10px; }
.ed-templates-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ed-template {
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--brand-strong); cursor: pointer;
  background: var(--brand-soft); border: 1px solid var(--sky-200); border-radius: 999px; padding: 9px 18px;
  transition: background .14s, border-color .14s, box-shadow .14s, transform .12s;
}
.ed-template:hover { background: var(--sky-200); border-color: var(--sky-300); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.ed-template:active { transform: translateY(0); }
[data-theme="dark"] .ed-template { border-color: var(--border); }


/* ---------- Guided form filling ---------- */
.annot.is-fill .annot-text {
  outline: 2px dashed var(--sky-400); outline-offset: 1px; border-radius: 3px;
  min-width: 60px; background: rgba(91,156,214,.07);
}
.annot.is-fill .annot-text:focus { outline-style: solid; background: rgba(91,156,214,.12); }

/* Password dialog: inline checkbox row */
.ed-check-row { display: flex; align-items: flex-start; gap: 9px; font-size: 13.5px; color: var(--text-soft); margin: 4px 0 2px; cursor: pointer; line-height: 1.4; }
.ed-check-row input { margin-top: 2px; flex-shrink: 0; }

/* ============================================================
   Page organizer (full-screen)
   ============================================================ */
body.org-open { overflow: hidden; }
.ed-organizer { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: flex; flex-direction: column; }
.ed-organizer[hidden] { display: none; }
.ed-org-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.ed-org-title { font-size: 16px; font-weight: 700; color: var(--text); }
.ed-org-sel { font-size: 13px; color: var(--text-mute); }
.ed-org-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ed-org-right { margin-left: auto; display: flex; gap: 8px; }
.ed-btn-danger { color: #c2410c; }
.ed-btn-danger:hover:not(:disabled) { border-color: #f0b6a0; background: #fdeee8; }
[data-theme="dark"] .ed-btn-danger:hover:not(:disabled) { background: rgba(194,65,12,.16); border-color: #7c3a24; }
.ed-btn:disabled { opacity: .42; cursor: default; }
.ed-org-grid {
  flex: 1; overflow-y: auto; padding: 22px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; align-content: start;
}
.ed-org-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; cursor: pointer; transition: border-color .14s, box-shadow .14s, transform .1s;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.ed-org-card:hover { border-color: var(--sky-300); box-shadow: var(--shadow-sm); }
.ed-org-card.is-sel { border-color: var(--sky-500); box-shadow: 0 0 0 2px var(--brand-soft); }
.ed-org-card.dragging { opacity: .4; }
.ed-org-card.drop-target { border-color: var(--sky-500); border-style: dashed; }
.ed-org-thumb { width: 100%; aspect-ratio: 1 / 1.3; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--surface-2); border-radius: 6px; }
.ed-org-thumb canvas { max-width: 100%; max-height: 100%; box-shadow: var(--shadow-sm); background: #fff; }
.ed-org-num { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.ed-org-check {
  position: absolute; top: 14px; left: 14px; width: 20px; height: 20px; border-radius: 6px;
  border: 2px solid var(--border); background: var(--surface); z-index: 2; transition: all .12s;
}
.ed-org-card.is-sel .ed-org-check { background: var(--sky-500); border-color: var(--sky-500); }
.ed-org-card.is-sel .ed-org-check::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 800; position: absolute; top: -2px; left: 3px; }
@media (max-width: 560px) {
  .ed-org-bar { padding: 10px 12px; }
  .ed-org-right { margin-left: 0; width: 100%; }
  .ed-org-right .ed-btn { flex: 1; }
  .ed-org-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; padding: 14px; }
}

/* ---------- Service-worker update prompt ---------- */
.ed-update {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 140%);
  z-index: 120; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 10px 8px 18px; box-shadow: var(--shadow-lg); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  max-width: calc(100vw - 24px);
}
.ed-update.show { transform: translate(-50%, 0); }
.ed-update span { font-size: 13.5px; font-weight: 600; color: var(--text); }
.ed-update-x { border: 0; background: none; color: var(--text-mute); font-size: 14px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.ed-update-x:hover { background: var(--surface-2); color: var(--text); }
@media (max-width: 1024px) { .ed-update { bottom: calc(118px + env(safe-area-inset-bottom)); } }

/* ---------- Keyboard focus for annotations ---------- */
.annot:focus-visible,
.annot-text:focus-visible,
.annot-note-body:focus-visible { outline: 2px solid var(--sky-500); outline-offset: 2px; border-radius: 4px; }
.annot[tabindex]:focus { outline: 2px solid var(--sky-500); outline-offset: 2px; }

/* ---------- Respect reduced-motion across editor chrome ---------- */
@media (prefers-reduced-motion: reduce) {
  .ed-flyout, .ed-palette-card, .ed-props, .ed-update, .ed-toast,
  .ed-sheet-backdrop, .ed-fab, .ed-page-loading, .ed-spinner,
  .ed-org-card, .btn, .ed-btn, .ed-tool, .theme-toggle {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  /* keep the busy spinner meaningful even without spin — show a static ring */
  .ed-spinner { animation: none !important; }
}

/* ---------- OCR language picker ---------- */
.ocr-langs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 12px 0 6px; }
.ocr-lang { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-soft); cursor: pointer; }
.ocr-lang input { flex-shrink: 0; }
.ocr-offline { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--grass); background: color-mix(in srgb, var(--grass) 14%, transparent); border-radius: 999px; padding: 1px 7px; }
@media (max-width: 560px) { .ocr-langs { grid-template-columns: 1fr; } }
