/* ================= PDF 编辑器 · 仿 Acrobat DC 深色主题 ================= */
:root {
  --bg-menubar: #232323;
  --bg-toolbar: #2e2e2e;
  --bg-btn: #383838;
  --bg-hover: #474747;
  --bg-active: #1c1c1c;
  --bg-viewer: #565a5e;
  --bg-side: #2a2a2a;
  --bg-input: #1e1e1e;
  --accent: #e01e2b;
  --accent-hover: #ff3542;
  --text: #e8e8e8;
  --text-dim: #a8a8a8;
  --border: #464646;
  --sel: #2f80ed;
  --shadow: 0 2px 8px rgba(0,0,0,.5);
  --radius: 4px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13px; color: var(--text);
  background: var(--bg-toolbar);
  display: flex; flex-direction: column;
  user-select: none;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font-family: inherit; color: var(--text); background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--sel); }
.hidden { display: none !important; }

/* ---------------- 菜单栏 ---------------- */
#menubar {
  height: 34px; background: var(--bg-menubar);
  display: flex; align-items: center; padding: 0 10px; gap: 4px;
  border-bottom: 1px solid #1a1a1a; flex-shrink: 0; position: relative; z-index: 60;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; color: #fff; margin-right: 10px; }
.brand svg { color: var(--accent); }
.menus { display: flex; height: 100%; }
.menu-item { position: relative; }
.menu-item > button {
  height: 100%; padding: 0 12px; font-size: 13px; color: var(--text);
  border-radius: 0; background: transparent;
}
.menu-item > button:hover, .menu-item.open > button { background: var(--bg-hover); }
.menu-drop {
  position: absolute; top: 100%; left: 0; min-width: 220px;
  background: #333; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 4px 0; z-index: 100;
}
.menu-drop button {
  display: flex; width: 100%; align-items: center; gap: 8px;
  padding: 7px 16px; font-size: 13px; text-align: left; white-space: nowrap;
}
.menu-drop button:hover { background: var(--bg-hover); }
.menu-drop button .mi-key { margin-left: auto; color: var(--text-dim); font-size: 11px; }
.menu-drop .mi-sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu-drop button:disabled { color: #666; cursor: default; }
.menu-drop button:disabled:hover { background: none; }
.menubar-right { margin-left: auto; font-size: 12px; color: var(--text-dim); }
.menubar-right .dirty { color: var(--accent); }

/* ---------------- 文档标签栏 ---------------- */
#doc-tabs {
  display: none; align-items: flex-end; gap: 3px;
  height: 35px; padding: 5px 8px 0;
  background: #262626; border-bottom: 1px solid #1a1a1a;
  overflow-x: auto; overflow-y: hidden; flex-shrink: 0;
  scrollbar-width: thin;
}
body.has-docs #doc-tabs { display: flex; }
#doc-tabs::-webkit-scrollbar { height: 5px; }
#doc-tabs::-webkit-scrollbar-thumb { border: none; }
.doc-tab {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 7px 0 11px;
  min-width: 80px; max-width: 210px; flex-shrink: 0;
  background: #313131; border: 1px solid #3f3f3f; border-bottom: none;
  border-radius: 7px 7px 0 0;
  color: var(--text-dim); font-size: 12px; cursor: pointer;
  user-select: none; position: relative;
}
.doc-tab:hover { background: #3a3a3a; color: var(--text); }
.doc-tab.active {
  background: var(--bg-toolbar); color: var(--text);
  border-color: #4a4a4a;
}
.doc-tab.active::before {
  content: ""; position: absolute; top: -1px; left: 8px; right: 8px; height: 2px;
  background: var(--accent); border-radius: 1px;
}
.doc-tab .dt-dirty { color: var(--accent); font-size: 9px; flex-shrink: 0; width: 9px; text-align: center; }
.doc-tab .dt-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tab .dt-close {
  width: 18px; height: 18px; flex-shrink: 0; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 11px; line-height: 1; padding: 0;
}
.doc-tab .dt-close:hover { background: var(--bg-hover); color: #fff; }
.doc-tab-add {
  width: 28px; height: 28px; margin-bottom: 1px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); color: var(--text-dim);
}
.doc-tab-add:hover { background: var(--bg-hover); color: var(--text); }
.doc-tab-add svg { width: 16px; height: 16px; }

/* ---------------- 工具栏通用 ---------------- */
#topbar, #toolbar {
  background: var(--bg-toolbar); display: flex; align-items: stretch;
  padding: 3px 8px; gap: 2px; flex-shrink: 0; border-bottom: 1px solid #222;
}
#topbar { height: 40px; }
#toolbar { min-height: 52px; flex-wrap: wrap; }
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; background: var(--border); margin: 4px 6px; }
.tb-flex { flex: 1; }

.tbtn {
  min-width: 30px; height: 32px; padding: 0 7px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border-radius: var(--radius); color: var(--text); font-size: 12px;
  position: relative;
}
.tbtn:hover { background: var(--bg-hover); }
.tbtn:disabled { color: #5f5f5f; cursor: default; }
.tbtn:disabled:hover { background: none; }
.tbtn svg { width: 19px; height: 19px; }
.tbtn.text-btn { padding: 0 10px; }

/* 工具条大按钮（图标+下方文字，仿 Acrobat 工具区） */
.tool-btn {
  min-width: 56px; height: 46px; padding: 2px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border-radius: var(--radius); color: var(--text-dim); font-size: 11px;
}
.tool-btn svg { width: 21px; height: 21px; color: var(--text); }
.tool-btn:hover { background: var(--bg-hover); color: var(--text); }
.tool-btn.active {
  background: var(--bg-active); color: #fff;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.tool-btn.active svg { color: #fff; }

/* 属性条（工具栏右侧 / 选中注释属性） */
.prop-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 0 4px; }
.prop-item { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-dim); }
.prop-item select { max-width: 110px; }
.color-swatch {
  width: 26px; height: 26px; border-radius: var(--radius);
  border: 2px solid #6a6a6a; cursor: pointer; padding: 0;
  position: relative;
}
.color-swatch:hover { border-color: #9a9a9a; }
.color-pop {
  position: fixed; background: #333; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px; z-index: 200; width: 204px;
}
.color-grid { display: grid; grid-template-columns: repeat(8, 22px); gap: 5px; }
.color-cell { width: 22px; height: 22px; border-radius: 3px; border: 1px solid rgba(255,255,255,.15); }
.color-cell:hover { outline: 2px solid #fff; }
.color-custom-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.color-custom-row input[type=color] { width: 40px; height: 24px; padding: 1px; }
.num-input { width: 52px; text-align: center; }
.range-input { width: 90px; accent-color: var(--accent); }

.prop-del-btn { color: #ff8080; }

/* ---------------- 主体布局 ---------------- */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

/* 搜索面板 */
#search-panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: 270px; z-index: 30;
  background: var(--bg-side); border-right: 1px solid #1e1e1e;
  display: flex; flex-direction: column;
}
.sp-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.sp-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.sp-input-row { display: flex; gap: 6px; }
.sp-input-row input { flex: 1; }
.sp-result { color: var(--text-dim); font-size: 12px; line-height: 1.6; }
.sp-nav { display: flex; align-items: center; justify-content: center; gap: 12px; }

/* 视图区 */
#viewer-wrap { flex: 1; overflow: auto; background: var(--bg-viewer); position: relative; }
#pages-container { padding: 24px 0 60px; display: flex; flex-direction: column; align-items: center; gap: 22px; }

.page-wrap { position: relative; }
.page-box {
  position: relative; background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.55), 0 0 0 1px rgba(0,0,0,.25);
  margin: 0 auto;
}
.page-box canvas.page-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 文本层：可选中复制 */
.text-layer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1;
  text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 2;
  opacity: .5;
}
.text-layer span { color: transparent; cursor: text; position: absolute; white-space: pre; transform-origin: 0% 0%; }
body.tool-select .text-layer { pointer-events: auto; }
.text-layer ::selection { background: rgba(47,128,237,.45); }

/* 注释 SVG 层 */
.annot-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; touch-action: none; overflow: visible; }
.annot-layer [data-id] { pointer-events: all; }
.annot-layer [data-dir] { pointer-events: auto; }
.annot-layer.creating { pointer-events: auto; cursor: crosshair; }
.annot-layer [data-id].hover-del { opacity: .35; }
body.tool-select .annot-layer [data-id] { cursor: move; }
body.tool-select .annot-layer g[data-id]:hover { filter: brightness(1.15); }

/* 搜索高亮层 */
.search-layer { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.search-hit { position: absolute; background: rgba(255,213,0,.4); border: 1px solid rgba(240,170,0,.9); }
.search-hit.current { background: rgba(255,120,0,.5); border-color: #ff7b00; }

/* 选择框与手柄 */
.sel-outline { fill: none; stroke: var(--sel); stroke-dasharray: 4 3; stroke-width: 1; pointer-events: none; }
.sel-handle { fill: #fff; stroke: var(--sel); stroke-width: 1.2; }

/* 注释编辑器（文本框工具） */
.text-editor {
  position: absolute; z-index: 10; background: transparent;
  border: 1.5px dashed var(--sel); padding: 0; margin: 0;
  resize: none; outline: none; overflow: hidden; line-height: 1.3;
  box-sizing: content-box; border-radius: 0;
}
.note-popup {
  position: absolute; z-index: 11; width: 250px;
  background: #fffbe8; color: #333; border: 1px solid #d0c060;
  border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
  font-size: 12px; user-select: text;
}
.note-popup .np-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-bottom: 1px solid #e4dca0; cursor: default;
  background: #faf5cd; border-radius: 6px 6px 0 0;
}
.note-popup .np-dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.3); }
.note-popup .np-head .np-title { flex: 1; font-weight: 600; }
.note-popup .np-head button { color: #777; font-size: 13px; padding: 0 3px; }
.note-popup .np-head button:hover { color: #000; }
.note-popup textarea {
  width: 100%; border: none; background: transparent; resize: vertical;
  min-height: 70px; padding: 8px; font-size: 12px; color: #333;
}

/* 空状态 */
#empty-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
body.has-doc #empty-state { display: none; }
.es-card { text-align: center; max-width: 420px; padding: 20px; }
.es-card h1 { font-size: 22px; margin: 18px 0 8px; color: #fff; font-weight: 600; }
.es-card p { color: #cfcfcf; margin-bottom: 16px; }
.es-actions { display: flex; gap: 10px; justify-content: center; margin-bottom: 22px; }
.es-features { list-style: none; color: #b8b8b8; font-size: 12px; line-height: 2; }

/* 按钮 */
.btn {
  padding: 7px 16px; border-radius: var(--radius); background: var(--bg-btn);
  border: 1px solid var(--border); font-size: 13px;
}
.btn:hover { background: var(--bg-hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.accent:hover { background: var(--accent-hover); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-hover); }

.icon-btn {
  width: 26px; height: 26px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:disabled { color: #555; cursor: default; }
.icon-btn:disabled:hover { background: none; }

/* 页码输入 */
.page-nav-input { width: 52px; text-align: center; height: 26px; }
.zoom-select { height: 27px; }

/* ---------------- 缩略图面板 ---------------- */
#thumb-panel {
  width: 172px; background: var(--bg-side); border-left: 1px solid #1e1e1e;
  display: flex; flex-direction: column; flex-shrink: 0;
}
body.thumbs-collapsed #thumb-panel { display: none; }
.tp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; font-size: 12px; font-weight: 600; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
#thumb-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.thumb-item { position: relative; width: 132px; cursor: pointer; }
.thumb-box {
  position: relative; width: 132px; background: #fff; border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 2px 6px rgba(0,0,0,.5);
  overflow: hidden;
}
.thumb-item.current .thumb-box { box-shadow: 0 0 0 2.5px var(--accent), 0 2px 8px rgba(0,0,0,.5); }
.thumb-item.selected .thumb-box { box-shadow: 0 0 0 2.5px var(--sel), 0 2px 8px rgba(0,0,0,.5); }
.thumb-box canvas { display: block; width: 100%; height: auto; }
.thumb-num {
  text-align: center; font-size: 11px; color: var(--text-dim); padding: 4px 0 0;
}
.thumb-acts {
  position: absolute; top: 4px; right: 4px; display: none; gap: 1px;
  background: rgba(30,30,30,.9); border-radius: var(--radius); padding: 1px;
}
.thumb-item:hover .thumb-acts { display: flex; }
.thumb-acts button { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; color: #ddd; border-radius: 3px; }
.thumb-acts button:hover { background: var(--bg-hover); color: #fff; }
.thumb-acts svg { width: 14px; height: 14px; }
.thumb-insert-mark { height: 3px; background: var(--sel); border-radius: 2px; margin: -2px 0; }

/* ---------------- 状态栏 ---------------- */
#statusbar {
  height: 26px; background: var(--bg-menubar); display: flex; align-items: center;
  padding: 0 12px; gap: 16px; font-size: 12px; color: var(--text-dim); flex-shrink: 0;
}
.st-flex { flex: 1; }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: #333; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6); min-width: 360px; max-width: 640px;
  max-height: 85vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--border);
}
.modal-body { padding: 16px 18px; overflow: auto; user-select: text; }
.modal-foot { padding: 12px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.form-row label { width: 90px; text-align: right; color: var(--text-dim); flex-shrink: 0; }
.form-row input[type=text], .form-row select { flex: 1; }
.form-row .hint { font-size: 11px; color: var(--text-dim); }
.check-row { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; cursor: pointer; }
.check-row input { accent-color: var(--accent); }

/* 签名板 */
#sign-canvas { background: #fff; border-radius: 4px; cursor: crosshair; touch-action: none; display: block; width: 100%; }

/* 表单列表 */
.fields-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fields-table th { text-align: left; color: var(--text-dim); padding: 6px 8px; border-bottom: 1px solid var(--border); font-weight: 500; }
.fields-table td { padding: 5px 8px; border-bottom: 1px solid #3d3d3d; }
.fields-table td:first-child { color: var(--text-dim); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fields-table input[type=text], .fields-table select { width: 100%; }

/* ---------------- Toast ---------------- */
#toast-root { position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); z-index: 900; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #262626; color: #eee; border: 1px solid var(--border); border-left: 3px solid var(--sel);
  border-radius: 6px; padding: 10px 16px; font-size: 13px; box-shadow: var(--shadow);
  animation: toast-in .2s ease; max-width: 480px;
}
.toast.warn { border-left-color: #f0a000; }
.toast.error { border-left-color: var(--accent); }
.toast.ok { border-left-color: #2ea86e; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- 右键菜单 ---------------- */
.ctx-menu {
  position: fixed; z-index: 800; min-width: 190px;
  background: #333; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 4px 0;
}
.ctx-menu button { display: flex; width: 100%; padding: 7px 14px; font-size: 13px; text-align: left; gap: 8px; align-items: center; }
.ctx-menu button:hover { background: var(--bg-hover); }
.ctx-menu button:disabled { color: #666; }
.ctx-menu .mi-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------------- 工具光标 ---------------- */
body.tool-highlight #pages-container, body.tool-underline #pages-container, body.tool-strike #pages-container,
body.tool-rect #pages-container, body.tool-ellipse #pages-container, body.tool-line #pages-container,
body.tool-arrow #pages-container, body.tool-redact #pages-container, body.tool-text #pages-container,
body.tool-note #pages-container, body.tool-eraser #pages-container, body.tool-place-image #pages-container { cursor: crosshair; }
body.tool-editText #pages-container { cursor: text; }
body.tool-pencil #pages-container { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><path d='M3 21l1.5-4.5L17 4a2 2 0 0 1 3 3L7.5 19.5z' fill='%23393' stroke='%23fff' stroke-width='1.4'/></svg>") 2 22, crosshair; }
body.tool-eraser .annot-layer [data-id] { cursor: not-allowed; }

/* 拖放遮罩 */
#drop-overlay {
  position: fixed; inset: 0; z-index: 950; background: rgba(224,30,43,.15);
  border: 3px dashed var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; font-weight: 600; pointer-events: none;
}

/* 进度遮罩 */
#busy-mask { position: fixed; inset: 0; z-index: 940; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.busy-box { background: #2e2e2e; border: 1px solid var(--border); border-radius: 8px; padding: 22px 34px; text-align: center; box-shadow: var(--shadow); }
.spinner { width: 30px; height: 30px; border: 3px solid #555; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 滚动条 */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: #3a3a3a; }
::-webkit-scrollbar-thumb { background: #5c5c5c; border-radius: 6px; border: 2px solid #3a3a3a; }
::-webkit-scrollbar-thumb:hover { background: #6f6f6f; }

/* 打印 */
@media print { body > *:not(#print-frame-wrap) { display: none !important; } }
