/* ---------- PDF editor ---------- */
body.editor-body { background:#e6eaf2; }
#start { width:100%; max-width:720px; margin:-64px auto 40px; padding:0 16px; }
#pdfIn, #imgIn { display:none; }

/* toolbar */
.etoolbar { position:sticky; top:0; z-index:20; background:#fff; border-bottom:1px solid var(--line); box-shadow:0 2px 10px rgba(10,30,80,.06); }
.etoolbar .in { max-width:1300px; margin:0 auto; padding:8px 12px; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.tools { display:flex; gap:4px; background:var(--soft); padding:4px; border-radius:11px; border:1px solid var(--line); flex-wrap:wrap; }
.tool { display:flex; align-items:center; gap:6px; border:0; background:transparent; color:var(--text); font-weight:600; font-size:.86rem;
        padding:8px 11px; border-radius:8px; cursor:pointer; white-space:nowrap; }
.tool:hover { background:#e6ebf5; }
.tool.on { background:var(--brand); color:#fff; }
.tool svg { flex:none; }

.props { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.props[hidden] { display:none; }
/* floating mini-toolbar above the selected text / item */
.props.pop { position:fixed; z-index:35; flex-wrap:nowrap; gap:4px; padding:5px; background:#fff; border:1px solid var(--line);
             border-radius:10px; box-shadow:0 8px 24px rgba(10,30,80,.18), 0 1px 3px rgba(10,30,80,.1); }
.props.pop::after { content:""; position:absolute; left:var(--arrow, 20px); width:10px; height:10px; background:#fff;
                    border:1px solid var(--line); transform:rotate(45deg); }
.props.pop.above::after { bottom:-6px; border-top:0; border-left:0; }
.props.pop.below::after { top:-6px; border-bottom:0; border-right:0; }
.props.pop select, .props.pop input[type=number] { height:30px; font-size:.8rem; padding:0 6px; }
.props.pop input[type=number] { width:56px; }
.props.pop input[type=color] { width:30px; height:30px; }
.props.pop .pbtn.restore { color:var(--accent); }
.props.pop .pbtn { height:30px; min-width:30px; padding:0 8px; display:inline-grid; place-items:center; }
.props select, .props input[type=number] { height:34px; border:1px solid var(--line); border-radius:8px; padding:0 8px; font-size:.86rem; background:#fff; color:var(--text); }
.props input[type=number] { width:66px; }
.props input[type=color] { width:36px; height:34px; border:1px solid var(--line); border-radius:8px; padding:2px; background:#fff; cursor:pointer; }
.pbtn { height:34px; min-width:34px; border:1px solid var(--line); border-radius:8px; background:#fff; cursor:pointer; font-size:.86rem; font-weight:600; color:var(--text); padding:0 10px; }
.pbtn:hover { background:var(--soft); }
.pbtn.on { background:#dfe6f7; border-color:var(--brand-2); color:var(--brand); }
.pbtn.danger { color:var(--danger); }
.pbtn.danger:hover { background:#fdecec; }
.sep { width:1px; height:26px; background:var(--line); }

.eright { margin-left:auto; display:flex; align-items:center; gap:8px; }
.eright .btn { padding:9px 14px; font-size:.9rem; }
.zoom { display:flex; align-items:center; gap:2px; }
.zoom span { font-size:.8rem; color:var(--muted); min-width:40px; text-align:center; }
.fname { font-size:.85rem; color:var(--muted); max-width:200px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.hintbar { text-align:center; font-size:.84rem; color:var(--muted); padding:10px 16px 0; }
.hintbar b { color:var(--text); }

/* pages */
.pages { padding:16px 12px 60px; display:flex; flex-direction:column; align-items:center; gap:22px; }
.pwrap { width:100%; display:flex; flex-direction:column; align-items:center; gap:6px; }
.plabel { font-size:.75rem; color:var(--muted); display:flex; align-items:center; gap:10px; }
.pdel { display:inline-flex; align-items:center; gap:5px; border:1px solid var(--line); background:#fff; color:var(--muted);
        border-radius:7px; padding:4px 9px; font-size:.75rem; font-weight:600; cursor:pointer; }
.pdel:hover { color:var(--danger); border-color:#f3b4b4; background:#fff5f5; }
.pwrap.deleted .pdel { color:var(--accent); border-color:#b7e1c3; background:#effaf2; }
.pdel-mark { display:none; position:absolute; inset:0; z-index:9; place-items:center; font-weight:700; font-size:1.1rem;
             color:var(--danger); background:rgba(255,255,255,.72) repeating-linear-gradient(45deg,transparent 0 14px,rgba(220,38,38,.07) 14px 28px); }
.pwrap.deleted .pdel-mark { display:grid; }
.pwrap.deleted .page { outline:2px dashed rgba(220,38,38,.6); }
.page { position:relative; width:100%; background:#fff; box-shadow:0 4px 18px rgba(10,30,80,.12); user-select:none; }
.page > img { position:absolute; inset:0; width:100%; height:100%; display:block; pointer-events:none; }
.layer { position:absolute; inset:0; }
.layer.t-text, .layer.t-whiteout, .layer.t-erase { cursor:crosshair; }
.layer.t-text > *, .layer.t-whiteout > *, .layer.t-erase > * { pointer-events:none; }

/* existing text runs */
/* .run   = patch over the original glyphs. When the text is edited/deleted the patch shows the
            same page rendered WITHOUT text, so the old letters vanish but table shading etc. stays.
   .txt   = live text, positioned on the original baseline; invisible until the run is edited. */
.run { position:absolute; z-index:2; cursor:text; border-radius:1px; background-repeat:no-repeat; }
.run .txt { position:absolute; white-space:pre; color:transparent; outline:none; caret-color:#000; }
.layer.t-select .run:hover { box-shadow:0 0 0 1px rgba(19,60,158,.35); background-color:rgba(19,60,158,.05); }
.run.mod, .run.editing, .run.deleted { background-image:var(--bg); background-size:var(--bgsize); }
.run.mod .txt, .run.editing .txt { color:var(--c); }
.run.editing { z-index:6; box-shadow:0 0 0 1px rgba(19,60,158,.55) !important; background-color:transparent !important; }
.run.editing .txt { user-select:text; }
.run.deleted .txt { color:transparent !important; }
.layer.t-select .run.deleted:hover { box-shadow:0 0 0 1px rgba(220,38,38,.5); }
.run.selected { outline:none !important; box-shadow:0 0 0 1px rgba(19,60,158,.55); }

/* existing images */
.eimg { position:absolute; z-index:1; outline:1px solid transparent; cursor:pointer; }
.layer.t-select .eimg:hover { outline:2px dashed rgba(19,60,158,.6); }
.eimg.deleted { background:#fff repeating-linear-gradient(45deg,transparent 0 8px,rgba(220,38,38,.08) 8px 16px); outline:1px dashed rgba(220,38,38,.6); }

/* user items */
.item { position:absolute; z-index:4; touch-action:none; }
.layer.t-select .item { cursor:move; }
.item.whiteout { background:#fff; outline:1px dashed rgba(100,116,139,.6); }
.item.erase { background:rgba(220,38,38,.07); outline:1px dashed rgba(220,38,38,.75); }
.item.erase::after { content:"erase text"; position:absolute; left:3px; top:2px; font:600 9px system-ui,sans-serif; color:rgba(220,38,38,.8); }
.item.newimage img { width:100%; height:100%; display:block; pointer-events:none; }
.item.newtext { color:var(--c); white-space:pre; line-height:1.2; padding:0; min-width:4px; outline:1px dashed rgba(19,60,158,.45); }
.item.newtext.editing { cursor:text; outline:2px solid var(--brand-2); user-select:text; }
.item.newtext:empty::before { content:"Type here"; color:#94a3b8; }

.selected { outline:2px solid var(--brand-2) !important; }
.rz { position:absolute; right:-6px; bottom:-6px; width:12px; height:12px; background:#fff; border:2px solid var(--brand-2); border-radius:3px; cursor:nwse-resize; display:none; }
.item.selected .rz { display:block; }
.drawing { position:absolute; z-index:7; outline:1px dashed var(--brand-2); background:rgba(19,60,158,.08); pointer-events:none; }

/* loading overlay */
.busy { position:fixed; inset:0; background:rgba(238,241,247,.75); display:none; place-items:center; z-index:50; }
.busy.show { display:grid; }
.busy .box { background:#fff; padding:18px 22px; border-radius:12px; box-shadow:var(--shadow); display:flex; align-items:center; gap:12px; font-weight:600; }
.toast { position:fixed; left:50%; bottom:24px; transform:translateX(-50%); background:#1f2937; color:#fff; padding:11px 16px; border-radius:10px;
         font-size:.9rem; z-index:60; display:none; max-width:min(560px, calc(100vw - 32px)); box-shadow:var(--shadow); }
.toast.show { display:block; }
.toast.err { background:var(--danger); }

@media (max-width:760px) {
  .tool .lbl { display:none; }
  .eright { margin-left:0; width:100%; justify-content:space-between; }
  .fname { display:none; }
}
