* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border-strong); }
.brand { display: flex; align-items: center; gap: .5rem; }
.brand img { width: 28px; height: 28px; border-radius: 6px; }
.actions, .toolbar, .group { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.btn, .tool { font: inherit; font-size: .9rem; padding: .45rem .8rem; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover:not(:disabled), .tool:hover { background: var(--primary-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn.big { padding: .7rem 1.4rem; font-size: 1rem; }
.btn.danger { color: #b42318; }
.tool.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.toolbar { padding: .5rem 1rem; background: var(--surface-soft); border-bottom: 1px solid var(--border); gap: 1.25rem; }
.props label { font-size: .85rem; display: flex; align-items: center; gap: .3rem; color: var(--text-secondary); }
.props input[type=number] { width: 4.2rem; } 
.props select, .props input[type=number] { font: inherit; padding: .25rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
.props input[type=color] { width: 2rem; height: 1.7rem; padding: 0; border: 1px solid var(--border-strong); border-radius: 6px; background: none; }
.workspace { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 170px; flex: none; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--border-strong); padding: .5rem; }
.side-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin: .25rem .25rem .5rem; }
.thumb { border: 2px solid transparent; border-radius: 8px; padding: .3rem; margin-bottom: .5rem; text-align: center; cursor: pointer; }
.thumb.current { border-color: var(--primary); background: var(--primary-soft); }
.thumb.dragover { border-color: var(--accent); }
.thumb canvas { max-width: 100%; box-shadow: var(--shadow-sm); background: #fff; }
.thumb .num { font-size: .75rem; color: var(--text-secondary); }
.thumb .ops { display: flex; justify-content: center; gap: .15rem; margin-top: .2rem; }
.thumb .ops button { font-size: .8rem; line-height: 1; width: 1.7rem; height: 1.6rem; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: var(--text); cursor: pointer; }
.thumb .ops button:hover:not(:disabled) { background: var(--primary-soft); }
.thumb .ops button:disabled { opacity: .35; cursor: default; }
.meta { font-size: .8rem; margin-top: 1rem; }
.meta label { display: block; margin-top: .4rem; color: var(--text-secondary); }
.meta input { width: 100%; font: inherit; padding: .25rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
.viewer { flex: 1; overflow: auto; padding: 1rem; background: #6b7a72; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.empty { max-width: 34rem; margin: 4rem auto; text-align: center; background: var(--surface); padding: 2rem; border-radius: 16px; box-shadow: var(--shadow-md); }
.empty h1 { margin-top: 0; font-size: 1.5rem; }
.hint { color: var(--text-secondary); font-size: .85rem; }
.page { position: relative; background: #fff; box-shadow: var(--shadow-lg); flex: none; }
.page canvas { display: block; }
.layer { position: absolute; inset: 0; overflow: hidden; }
.layer.t-text { cursor: text; }
.layer.t-ellipse, .layer.t-line, .layer.t-draw, .layer.t-rect, .layer.t-whiteout, .layer.t-highlight, .layer.t-image { cursor: crosshair; }
.annot { position: absolute; cursor: move; outline: 1px dashed transparent; }
.annot:hover { outline-color: rgba(0,127,63,.6); }
.annot.sel { outline: 2px solid var(--primary); }
.annot.text { white-space: pre; line-height: 1.2; min-width: 1em; min-height: 1em; padding: 0; }
.annot.text[contenteditable=true] { cursor: text; background: rgba(255,255,200,.5); }
.annot.image .imgwrap { position: absolute; overflow: hidden; pointer-events: none; }
.annot.image img { position: absolute; display: block; max-width: none; pointer-events: none; -webkit-user-drag: none; }
.annot .handle { display: none; position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: var(--primary); border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize; }
.annot.sel:not(.text) .handle { display: block; }
.draft { position: absolute; border: 1px dashed var(--primary); background: rgba(0,127,63,.12); pointer-events: none; }
#toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: #1a2e1f; color: #fff; padding: .6rem 1rem; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
.dropping .viewer { outline: 3px dashed var(--accent); outline-offset: -8px; }
@media (max-width: 700px) { .sidebar { width: 96px; } .toolbar { gap: .6rem; } }

.thumb .ops { flex-wrap: wrap; }
.thumb .num { display: flex; align-items: center; justify-content: center; gap: .3rem; cursor: pointer; }
.btn.wide { width: 100%; margin-bottom: .5rem; }
.mt-sm { margin-top: .5rem; }
.meta select { width: 100%; font: inherit; padding: .25rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
.meta label.inline { display: flex; align-items: center; gap: .4rem; }
.meta summary { cursor: pointer; }
.form-src { font-weight: 600; margin: .5rem 0 .2rem; word-break: break-all; }
.form-row { display: block; }
.form-row span { display: block; font-size: .75rem; word-break: break-all; }
.form-row input[type=checkbox] { width: auto; }
.annot.line, .annot.ink { outline: none; }
.annot.line.sel, .annot.ink.sel { outline: 1px dashed var(--primary); }
.sidebar { width: 190px; }

.cropui { position: absolute; inset: 0; z-index: 5; }
.cropdim { position: absolute; background: rgba(0,0,0,.55); pointer-events: none; }
.cropframe { position: absolute; border: 2px solid #fff; outline: 1px solid rgba(0,0,0,.5); cursor: move; touch-action: none; }
.croph { position: absolute; width: 14px; height: 14px; background: #fff; border: 2px solid var(--primary); border-radius: 3px; }
.h-nw { left: -8px; top: -8px; cursor: nwse-resize; } .h-ne { right: -8px; top: -8px; cursor: nesw-resize; }
.h-sw { left: -8px; bottom: -8px; cursor: nesw-resize; } .h-se { right: -8px; bottom: -8px; cursor: nwse-resize; }
.h-n { left: calc(50% - 7px); top: -8px; cursor: ns-resize; } .h-s { left: calc(50% - 7px); bottom: -8px; cursor: ns-resize; }
.h-w { left: -8px; top: calc(50% - 7px); cursor: ew-resize; } .h-e { right: -8px; top: calc(50% - 7px); cursor: ew-resize; }
.cropbar { position: absolute; right: 8px; top: 8px; display: flex; gap: .4rem; z-index: 6; }

.search { gap: .3rem; }
.search input { font: inherit; font-size: .85rem; padding: .3rem .5rem; width: 11rem; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); }
#s-count { font-size: .8rem; color: var(--text-secondary); }
.hits { position: absolute; inset: 0; pointer-events: none; }
.hits div { position: absolute; background: rgba(255, 200, 0, .45); mix-blend-mode: multiply; border-radius: 2px; }
.textLayer { position: absolute; inset: 0; overflow: hidden; line-height: 1; pointer-events: none; }
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; transform-origin: 0 0; cursor: text; }
.textLayer ::selection { background: rgba(0, 90, 255, .3); }
body[data-tool^="mk-"] .textLayer, body[data-tool="edittext"] .textLayer { pointer-events: auto; }
body[data-tool^="mk-"] .layer, body[data-tool="edittext"] .layer { pointer-events: none; }
body[data-tool="edittext"] .textLayer span { cursor: pointer; }
body[data-tool="edittext"] .textLayer span:hover { background: rgba(0, 127, 63, .2); outline: 1px solid var(--primary); }
.notepop { position: absolute; z-index: 8; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: .4rem; box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: .3rem; width: 220px; }
.notepop textarea { font: inherit; font-size: .85rem; resize: vertical; border: 1px solid var(--border-strong); border-radius: 6px; padding: .3rem; background: var(--surface); color: var(--text); }
.annot.note { font-size: 13px; }
.annot.redact { }
.layer.t-note, .layer.t-sign, .layer.t-redact { cursor: crosshair; }
