/* Edit PDF (templates/edit-pdf.html, static/edit-pdf.js): a toolbar that stays in view, the pages as paper, and what you
   add on top of them. Built on style.css's tokens. */

.edit-pdf.open .lede, .edit-pdf.open .device { display: none; }
.edit-pdf.open { padding-bottom: 0; }
.ep-note:empty { display: none; }
.ep-note { text-align: center; color: var(--bad); font-weight: 560; margin: var(--s4) 0 0; }

.ep { max-width: 1040px; margin: 0 auto; padding: 0 clamp(12px, 3vw, 24px) var(--s8); }

/* ── the toolbar ── */
.ep-bar { position: sticky; top: 68px; z-index: 4; display: flex; align-items: center; gap: var(--s2); padding: 6px;
          background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
          border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-2); }
.ep-tools, .ep-acts { display: flex; align-items: center; gap: 2px; }
.ep-tools { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.ep-tools::-webkit-scrollbar { display: none; }
.ep-acts { padding-left: var(--s2); border-left: 1px solid var(--line); }
.ep-tool { display: grid; justify-items: center; align-content: center; gap: 3px; flex: none; min-width: 64px; height: 56px; padding: 0 8px;
           border: 0; border-radius: var(--r); background: none; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
           cursor: pointer; transition: background .15s, color .15s, transform .15s var(--ease); }
.ep-tool svg { width: 22px; height: 22px; }
.ep-tool:hover:not(:disabled) { background: var(--soft); color: var(--ink); }
.ep-tool:active:not(:disabled) { transform: scale(.96); }
.ep-tool[aria-pressed="true"] { background: color-mix(in srgb, var(--k) 11%, transparent); color: var(--k);
                                box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--k) 45%, transparent); }
.ep-tool:disabled { opacity: .35; cursor: default; }
.ep-save { height: 48px; padding: 0 20px; margin-left: 4px; white-space: nowrap; }

/* ── options for the tool or the thing chosen ── */
.ep-opts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s5); min-height: 52px; padding: var(--s3) var(--s2) var(--s2); }
.ep-opt { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.ep-swatch { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--c); cursor: pointer;
             box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14); transition: transform .15s var(--spring), box-shadow .15s; }
.ep-swatch:hover { transform: scale(1.08); }
.ep-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.ep-opt select { height: 36px; padding: 0 30px 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line-strong); background: var(--card);
                 color: var(--ink); font: inherit; font-size: 14px; }
.ep-opt .seg button { height: 30px; font-size: 13px; }
.ep-tip { flex: 1 1 260px; margin: 0; text-align: right; color: var(--faint); font-size: 13px; }

/* ── the pages ── */
.ep-pages { display: grid; justify-items: center; gap: 28px; padding: var(--s2) 0; }
.ep-page { position: relative; width: min(100%, 880px); background: #fff; border-radius: 3px; box-shadow: var(--sh-3), 0 0 0 1px var(--line);
           user-select: none; -webkit-user-select: none; touch-action: pan-y; --pt: 1; }
.ep-page img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.ep-ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ep-ink polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: visibleStroke; cursor: move; touch-action: none; }
.ep-ink polyline.on { filter: drop-shadow(0 0 1.5px var(--pdf)); }
.ep-layer { position: absolute; inset: 0; }
.ep-num { position: absolute; right: 8px; bottom: -22px; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.ep.drawing .ep-page { touch-action: none; cursor: crosshair; }
.ep.writing .ep-page { cursor: text; }

/* ── what you add ── */
.ep-item { position: absolute; touch-action: none; cursor: move; }
.ep-item { transform-origin: 50% 50%; }
.ep-item.on:not(.ep-text) { outline: 0; }   /* the frame shows the chosen thing */
.ep-text { white-space: pre; line-height: 1.2; min-width: 4px; padding: 0; font-family: Helvetica, Arial, "Noto Sans Gujarati", "Noto Sans Devanagari", sans-serif;
           outline-offset: 3px; user-select: text; -webkit-user-select: text; }
.ep-text:focus { cursor: text; outline: 2px dashed var(--pdf); }
.ep-text:empty::before { content: "Type here"; color: #9a9a9a; }
.ep-image { overflow: hidden; }
.ep-image img { position: absolute; left: 0; top: 0; display: block; width: 100%; height: 100%; max-width: none; pointer-events: none; }
.ep-whiteout { background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12); }
.ep-highlight { mix-blend-mode: multiply; }
.ep-rect { border-style: solid; }
/* ── the chosen thing's frame: eight handles, a turn handle above, the angle while turning ── */
.ep-frame { position: absolute; z-index: 3; pointer-events: none; transform-origin: 50% 50%; outline: 1.5px solid var(--pdf);
            box-shadow: 0 0 0 4px color-mix(in srgb, var(--pdf) 12%, transparent); }
.ep-frame.cropping { outline-style: dashed; }
.ep-h { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 3px; background: #fff; border: 1.5px solid var(--pdf);
        box-shadow: 0 1px 3px rgba(0, 0, 0, .25); pointer-events: auto; touch-action: none; }
.ep-h::before { content: ""; position: absolute; inset: -8px; }   /* a bigger target than it looks */
.ep-h[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; } .ep-h[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.ep-h[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; } .ep-h[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.ep-h[data-h="n"], .ep-h[data-h="s"] { width: 20px; height: 8px; margin: -4px 0 0 -10px; left: 50%; cursor: ns-resize; border-radius: 4px; }
.ep-h[data-h="n"] { top: 0; } .ep-h[data-h="s"] { top: 100%; }
.ep-h[data-h="e"], .ep-h[data-h="w"] { width: 8px; height: 20px; margin: -10px 0 0 -4px; top: 50%; cursor: ew-resize; border-radius: 4px; }
.ep-h[data-h="e"] { left: 100%; } .ep-h[data-h="w"] { left: 0; }
.ep-frame.cropping .ep-h { background: var(--pdf); border-color: #fff; }
.ep-frame.text .ep-h[data-h="n"], .ep-frame.text .ep-h[data-h="s"], .ep-frame.text .ep-h[data-h="e"], .ep-frame.text .ep-h[data-h="w"] { display: none; }
.ep-turn { position: absolute; left: 50%; top: -38px; width: 26px; height: 26px; margin-left: -13px; display: grid; place-items: center; border-radius: 50%;
           background: #fff; color: var(--pdf); border: 1.5px solid var(--pdf); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); pointer-events: auto;
           touch-action: none; cursor: grab; }
.ep-turn svg { width: 14px; height: 14px; }
.ep-turn::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1.5px; height: 11px; margin-left: -.75px; background: var(--pdf); }
.ep-turn::before { content: ""; position: absolute; inset: -9px; border-radius: 50%; }
.ep-frame.cropping .ep-turn { display: none; }
.ep-angle { position: absolute; left: 50%; top: -70px; transform: translateX(-50%); display: none; padding: 3px 8px; border-radius: 7px;
            background: var(--ink); color: var(--paper); font: 600 12px/1.2 inherit; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ep-frame.turning .ep-angle { display: block; }

/* ── the bar of actions above the chosen thing ── */
.ep-float { position: absolute; z-index: 5; display: flex; align-items: center; gap: 2px; padding: 4px; transform: translate(-50%, calc(-100% - 50px));
            background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--sh-3); white-space: nowrap;
            user-select: none; -webkit-user-select: none; }
.ep-float.below { transform: translate(-50%, 18px); }
.ep-float button, .ep-alpha { display: inline-grid; place-items: center; height: 36px; min-width: 36px; padding: 0 7px; border: 0; border-radius: 9px;
                              background: none; color: inherit; cursor: pointer; }
.ep-float button:hover, .ep-alpha:hover { background: var(--soft); }
.ep-float button[aria-pressed="true"] { background: color-mix(in srgb, var(--pdf) 13%, transparent); color: var(--pdf); }
.ep-float button.danger:hover { color: var(--bad); }
.ep-float svg { width: 19px; height: 19px; }
.ep-alpha { display: inline-flex; gap: 5px; cursor: default; }
.ep-alpha input { width: 78px; accent-color: var(--pdf); }
.ep-float .sep { width: 1px; align-self: stretch; margin: 6px 3px; background: var(--line); }
.ep-float:not(.pic) .for-pic { display: none; }
.ep-page.dropping { box-shadow: var(--sh-3), 0 0 0 3px var(--pdf); }

/* ── the text and pictures that came with the PDF: tap to edit; scrolling over them still scrolls the page ── */
.ep-run:not(.on), .ep-orig:not(.on) { touch-action: pan-y; }
.ep-run:hover:not(.on):not(:focus), .ep-orig:hover:not(.on) { outline: 1px dashed color-mix(in srgb, var(--pdf) 55%, transparent); outline-offset: 1px; }
.ep.drawing .ep-run, .ep.drawing .ep-orig { pointer-events: none; }   /* drawing tools draw over them */
.ep-run { line-height: 1.2; }
.ep-replace { height: 36px; padding: 0 12px; font-size: 13px; gap: 6px; }
.ep-replace svg { width: 17px; height: 17px; }

/* ── the signature pad ── */
.ep-sign { width: min(620px, calc(100vw - 32px)); border: 0; border-radius: var(--r-xl); padding: var(--s5); background: var(--card); color: var(--ink);
           box-shadow: var(--sh-3); }
.ep-sign::backdrop { background: rgba(15, 15, 14, .45); backdrop-filter: blur(3px); }
.ep-sign h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.ep-sign p { margin: 0 0 var(--s4); color: var(--muted); font-size: 14px; }
.ep-sign canvas { display: block; width: 100%; aspect-ratio: 3 / 1; background: #fff; border: 2px dashed var(--line-strong); border-radius: var(--r);
                  touch-action: none; cursor: crosshair; }
.ep-sign-acts { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.ep-sign-acts span { flex: 1; }
.ep-sign-acts .btn { height: 44px; padding: 0 16px; }

@media (pointer: coarse) {   /* fingers: bigger handles */
  .ep-h { width: 18px; height: 18px; margin: -9px 0 0 -9px; }
  .ep-h[data-h="n"], .ep-h[data-h="s"] { width: 28px; height: 12px; margin: -6px 0 0 -14px; }
  .ep-h[data-h="e"], .ep-h[data-h="w"] { width: 12px; height: 28px; margin: -14px 0 0 -6px; }
  .ep-turn { width: 34px; height: 34px; margin-left: -17px; top: -46px; }
}
@media (max-width: 640px) {
  .ep-float { max-width: calc(100vw - 24px); overflow-x: auto; scrollbar-width: none; }
  .ep-alpha input { width: 60px; }
  .ep { padding-inline: 8px; }
  .ep-bar { top: 64px; flex-wrap: wrap; }
  .ep-tools { flex-basis: 100%; }
  .ep-acts { flex-basis: 100%; border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 4px; }
  .ep-save { margin-left: auto; }
  .ep-tool { min-width: 58px; height: 52px; }
  .ep-tip { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { .ep-tool, .ep-swatch { transition: none; } }
