:root {
  --bg: #e9ecf1; --panel: #ffffff; --line: #d5dbe4; --text: #1c2430; --muted: #5f6b7a;
  --accent: #1d6fa5; --accent-ink: #ffffff; --danger: #b42318; --sel: #0b84ff; --hover: #eef3f9;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font: 13px/1.4 "Segoe UI", system-ui, Arial, sans-serif; color: var(--text); background: var(--bg); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.grow { flex: 1; }

#bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.grp { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 6px; }
.tb { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px; padding: 5px 8px; border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; font-size: 11.5px; }
.tb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tb:hover { background: var(--hover); }
.tb.on { background: #dcebf7; border-color: #9cc3e2; color: #0d4a73; }
.tb:disabled { opacity: 0.4; cursor: default; background: none; }
.tb.sq { min-width: 30px; font-size: 18px; line-height: 1; padding: 6px 8px; }
#zoomLabel { min-width: 44px; text-align: center; }
#pageInfo { margin-right: 10px; }

#opts { height: 42px; flex: none; display: flex; gap: 14px; align-items: center; padding: 5px 14px; background: #f6f8fb; border-bottom: 1px solid var(--line); overflow: hidden; }
#textCtl { display: flex; align-items: center; gap: 12px; flex: none; }
#textCtl[hidden] { display: none; }
.opt { display: none; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.opt.on { display: flex; }
.opt > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.opt > *:not(span) { flex: none; }
#opts label { display: flex; align-items: center; gap: 6px; }
#opts input[type=number] { width: 62px; }
#opts select, #opts input[type=number] { padding: 4px 6px; border: 1px solid #b8c1cd; border-radius: 5px; background: #fff; }
#opts input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid #b8c1cd; border-radius: 5px; background: #fff; }
.opt label { display: flex; align-items: center; gap: 6px; }
.opt input[type=number] { width: 62px; }
.opt select, .opt input[type=number], dialog input[type=text], dialog input[type=password], dialog select { padding: 4px 6px; border: 1px solid #b8c1cd; border-radius: 5px; background: #fff; }
.opt input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid #b8c1cd; border-radius: 5px; background: #fff; }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; outline: 1px solid #aab3c0; cursor: pointer; }
.swatches button.on { outline: 2px solid var(--sel); }
.seg { display: flex; border: 1px solid #b8c1cd; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid #b8c1cd; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
#sigPreview { max-height: 30px; max-width: 160px; background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; display: none; }

.btn { padding: 5px 14px; border: 1px solid #b8c1cd; border-radius: 6px; background: #fff; cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #185d8b; }
.btn.danger { color: var(--danger); border-color: #e3b2ac; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.big { font-size: 15px; padding: 9px 22px; }
.opt .btn.primary, .opt .btn.danger { margin-left: auto; }

#work { flex: 1; display: flex; min-height: 0; }
#thumbs { flex: none; width: 168px; overflow-y: auto; background: #dde2ea; border-right: 1px solid var(--line); padding: 10px 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#thumbs[hidden] { display: none; }
.thumb { flex: none; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 8px 4px; border: 2px solid transparent; border-radius: 8px; cursor: pointer; font-size: 11px; color: var(--muted); }
.thumb:hover { background: rgba(255, 255, 255, 0.5); }
.thumb.on { border-color: var(--sel); background: rgba(11, 132, 255, 0.10); color: #0d4a73; font-weight: 600; }
.thumb .tbox { background: #fff; box-shadow: 0 1px 3px rgba(20, 30, 50, 0.3); }
.thumb .tbox canvas { display: block; width: 100%; height: 100%; }
#viewer { flex: 1; min-width: 0; overflow: auto; position: relative; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px; min-width: min-content; }
.page { position: relative; background: #fff; box-shadow: 0 1px 4px rgba(20, 30, 50, 0.25); flex: none; }
.page .cv, .page .cv canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .ovl { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#viewer.t-hand { cursor: grab; } #viewer.t-hand.panning, #viewer.panning { cursor: grabbing; }
#viewer.t-text .ovl { cursor: text; }
#viewer.t-highlight .ovl, #viewer.t-redact .ovl, #viewer.t-sigplace .ovl, #viewer.t-crop .ovl { cursor: crosshair; }
.item.crop { outline: 2px dashed var(--sel); box-shadow: 0 0 0 9999px rgba(20, 30, 50, 0.38); }
.opt .check { margin: 0; white-space: nowrap; }

.item { position: absolute; pointer-events: none; user-select: none; }
#viewer.t-select .item { pointer-events: auto; cursor: move; }
#viewer.t-text .item.text { pointer-events: auto; cursor: text; }
.item.sel { outline: 1.5px solid var(--sel); outline-offset: 1px; }
.item.text { white-space: pre; line-height: 1.2; min-width: 4px; min-height: 1em; }
.item.text[contenteditable] { outline: 1.5px dashed var(--sel); outline-offset: 2px; user-select: text; background: rgba(255, 255, 255, 0.6); }
.item.highlight { mix-blend-mode: multiply; }
.item.redact { outline: 1.5px dashed #d92d20; }
.item.redact.black { background: rgba(0, 0, 0, 0.55); }
.item.redact.white { background: rgba(255, 255, 255, 0.75); }
.item.redact.ellipse { border-radius: 50%; }
.item.image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.item.sigstamp { border: 1px solid #5b7fa3; font-size: 9px; color: #1c2430; overflow: hidden; padding: 2px 4px; background: rgba(255, 255, 255, 0.6); }
.handle { position: absolute; right: -6px; bottom: -6px; width: 11px; height: 11px; background: #fff; border: 1.5px solid var(--sel); border-radius: 2px; cursor: nwse-resize; pointer-events: auto; }
.rubber { position: absolute; border: 1.5px dashed var(--sel); background: rgba(11, 132, 255, 0.10); pointer-events: none; }
.rubber.ellipse { border-radius: 50%; }
.rubber.redact { border-color: #d92d20; background: rgba(0, 0, 0, 0.35); }
.rubber.highlight { border: 0; background: rgba(255, 228, 92, 0.6); }
.objbox { position: absolute; pointer-events: none; }
.objbox.hover { outline: 1px dashed #6b7a8c; background: rgba(11, 132, 255, 0.05); }
.objbox.sel { outline: 1.5px solid #e0491f; background: rgba(224, 73, 31, 0.12); }

#empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#empty[hidden] { display: none; }
#empty .drop { text-align: center; padding: 44px 60px; border: 2px dashed #aab3c0; border-radius: 14px; background: rgba(255, 255, 255, 0.6); }
#empty h1 { margin: 0 0 6px; font-size: 26px; color: #0f2a43; }
#empty p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
body.dragover #empty .drop, body.dragover #viewer { outline: 3px dashed var(--sel); outline-offset: -8px; }

#status { display: flex; justify-content: space-between; gap: 20px; padding: 4px 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; min-height: 26px; }
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#busy { position: fixed; inset: 0; background: rgba(233, 236, 241, 0.72); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 50; font-size: 14px; }
#busy[hidden] { display: none; }
.spin { width: 34px; height: 34px; border: 4px solid #c3cdd9; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

dialog { border: 0; border-radius: 12px; padding: 20px 22px; width: min(600px, 92vw); box-shadow: 0 12px 40px rgba(20, 30, 50, 0.35); color: var(--text); }
dialog::backdrop { background: rgba(20, 30, 50, 0.35); }
dialog h2 { margin: 0 0 10px; font-size: 17px; color: #0f2a43; }
dialog p { margin: 8px 0; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; cursor: pointer; }
.choice input { margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.indent { margin: 4px 0 8px 30px; display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 8px 0; }
.indent.grid { display: grid; }
.indent[hidden], .grid[hidden] { display: none; }
.grid label, .indent label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
#msgBody p { margin: 6px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { border: 0; background: none; padding: 6px 14px; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
#sigPad { width: 520px; max-width: 100%; height: 180px; border: 1px solid #b8c1cd; border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; display: block; }
#sigImgPreview { width: 520px; max-width: 100%; height: 180px; border: 1px solid var(--line); border-radius: 8px; background: repeating-conic-gradient(#f1f3f6 0% 25%, #fff 0% 50%) 50% / 16px 16px; display: block; margin-top: 8px; }
#sigText { width: 100%; font-size: 15px; padding: 7px 9px !important; }
#sigTypePreview { height: 110px; display: flex; align-items: center; justify-content: center; font-size: 44px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; overflow: hidden; white-space: nowrap; }
#hiddenList label { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 6px; align-items: start; padding: 6px 4px; border-bottom: 1px solid #eef1f5; }
#hiddenList label.none { color: #9aa4b1; }
#hiddenList .cnt { font-variant-numeric: tabular-nums; font-weight: 600; }
#hiddenList small { grid-column: 2 / 4; color: var(--muted); }
#hiddenList label.none small { color: #b3bbc6; }
