/* 图档清洁 pdfclean — 浅灰 Ribbon + 双窗绿/粉 */
:root {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --chrome: #e8e8e8;
  --stroke: #c8c8c8;
  --text: #222;
  --muted: #666;
  --accent: #2b6cb0;
  --result: #6aaa6a;
  --recog: #d08090;
  --ribbon-h: minmax(72px, auto);
  --font: "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden; /* 禁止整页横向滚动条；溢出收进 ribbon/工作区 */
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; }
.app {
  display: grid;
  grid-template-rows: 28px 28px var(--ribbon-h) minmax(0, 1fr) 28px;
  height: 100vh;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  min-height: 480px;
  overflow: hidden;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: #fff;
  border-bottom: 1px solid var(--stroke);
}
.app-name { font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }
.titlebar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.rmeta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-width: 88px;
  padding: 4px 8px;
  gap: 2px;
}
.rmeta-lab {
  font-size: 11px;
  color: var(--muted, #666);
}
.rmeta-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.menubar {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  background: var(--chrome);
  border-bottom: 1px solid var(--stroke);
  align-items: flex-end;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.menu-tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  padding: 4px 14px;
  border-radius: 4px 4px 0 0;
  color: var(--text);
}
.menu-tab.active {
  background: #fff;
  border-color: var(--stroke);
  position: relative;
  bottom: -1px;
}

.ribbon {
  display: flex;
  flex-wrap: wrap; /* 分组换行，避免整页横向滚动条 */
  align-content: flex-start;
  gap: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden; /* 高度随内容撑开（grid 行 auto），不再出滚动条 */
  background: #fff;
  border-bottom: 1px solid var(--stroke);
  padding: 4px 6px;
}
.ribbon-group {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--stroke);
  padding: 0 6px 2px;
  min-width: max-content;
  flex: 0 0 auto;
}
.ribbon-group:last-child { border-right: none; }
.ribbon-group-title {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  margin-top: auto;
  padding-top: 2px;
}
.ribbon-btns {
  display: flex;
  gap: 2px;
  align-items: flex-start;
}
.rbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 52px;
  padding: 2px 1px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  flex: 0 0 auto;
}
.rbtn:hover:not(:disabled) {
  background: #e8f1fb;
  border-color: #b0cce8;
}
.rbtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.rbtn .ico {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: linear-gradient(180deg, #f7f7f7, #ddd);
  border: 1px solid #bbb;
  display: grid;
  place-items: center;
  font-size: 10px;
  color: #444;
}
.rbtn.primary .ico {
  background: linear-gradient(180deg, #6db3f2, #2b6cb0);
  color: #fff;
  border-color: #1a4f8a;
}
.rbtn .lbl {
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  max-width: 50px;
  max-height: 2.4em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.rselect-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  min-width: 72px;
  max-width: 92px;
  padding: 2px 1px;
  flex: 0 0 auto;
}
.rselect-lab {
  font-size: 10px;
  text-align: center;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rselect {
  font: inherit;
  font-size: 11px;
  padding: 3px 4px;
  border: 1px solid var(--stroke);
  border-radius: 3px;
  background: #fff;
  color: var(--text);
  max-width: 92px;
  width: 100%;
}
.rselect:disabled {
  opacity: 0.45;
}
.rcolor-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 56px;
  padding: 4px 2px;
}
.rcolor {
  width: 100%;
  height: 28px;
  padding: 0;
  border: 1px solid var(--stroke);
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.rcolor:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.workspace {
  display: grid;
  grid-template-columns: 160px 1fr 200px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: #d4d4d4;
}
.sidebar-left, .sidebar-right {
  background: var(--panel);
  border-right: 1px solid var(--stroke);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-right { border-right: none; border-left: 1px solid var(--stroke); }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--stroke);
  background: var(--chrome);
  font-weight: 600;
  font-size: 12px;
}
.side-head-actions { display: flex; gap: 4px; }
.demo-row {
  padding: 6px 8px;
  border-bottom: 1px solid var(--stroke);
}
.demo-row select {
  width: 100%;
  font: inherit;
  padding: 4px;
  border: 1px solid var(--stroke);
  border-radius: 3px;
}
.img-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  overflow: visible;
}
.guide-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}
.guide-overlay.hidden { display: none; }
.stroke-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 7;
}
.stroke-preview.hidden { display: none; }
.text-inline {
  position: absolute;
  z-index: 12;
  min-width: 8em;
  max-width: 60%;
  margin: 0;
  padding: 0 2px;
  border: 1px solid #2b6cb0;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.92);
  outline: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  line-height: 1.2;
  font-family: "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Microsoft YaHei", sans-serif;
}
.text-inline.hidden { display: none; }
.pane-body { overflow: auto; }
.sel-box {
  position: absolute;
  z-index: 5;
  border: 2px dashed #2b6cb0;
  background: rgba(43, 108, 176, 0.15);
  pointer-events: none;
  box-sizing: border-box;
}
/* 识别图侧：仅位置标识（商业红虚线框），不可交互起选 */
#sel-box-recog {
  border: 2px dashed #c43a5a;
  background: rgba(220, 80, 120, 0.1);
}
/* 区域反选：框内保留，橙虚线区分普通选区 */
.sel-box.invert {
  border-color: #c05621;
  background: rgba(192, 86, 33, 0.12);
}
#sel-box-recog.invert {
  border-color: #c05621;
  background: rgba(192, 86, 33, 0.1);
}
.sel-box.hidden { display: none; }
.deskew-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
  overflow: visible;
}
.deskew-line.hidden { display: none; }
.deskew-line line {
  stroke: #d97706;
  stroke-width: 2;
  stroke-dasharray: 6 4;
}
.keystone-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
  overflow: visible;
}
.keystone-overlay.hidden { display: none; }
.keystone-overlay polygon {
  fill: rgba(14, 116, 144, 0.12);
  stroke: #0e7490;
  stroke-width: 2;
  stroke-dasharray: 5 3;
}
.keystone-overlay circle {
  fill: #0e7490;
  stroke: #fff;
  stroke-width: 1.5;
}
.deskew-badge {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 8;
  padding: 6px 10px;
  border-radius: 3px;
  background: rgba(217, 119, 6, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 24px);
}
.deskew-badge.zero { background: rgba(80, 80, 80, 0.9); }
.deskew-badge.hidden { display: none; }
.pane-body.crosshair { cursor: crosshair; }
.pane-body.erase-cursor { cursor: cell; }
.pane-body.select-cursor { cursor: pointer; }
.tool-hint, #tool-hint { font-weight: 400; margin-left: 8px; }

.thumbs {
  flex: 1;
  overflow: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.thumbs.hidden { display: none; }
.thumb {
  border: 2px solid transparent;
  border-radius: 2px;
  background: #eee;
  cursor: pointer;
  position: relative;
}
.thumb.active { border-color: var(--accent); }
.thumb img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 72px;
  background: #fff;
  /* 换 src 时保持占位，避免列表高度塌陷再弹回 */
  aspect-ratio: 3 / 4;
  object-fit: contain;
}
.thumb .num {
  position: absolute;
  left: 4px;
  bottom: 4px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 11px;
  padding: 0 4px;
  border-radius: 2px;
}
.side-tabs {
  display: flex;
  border-top: 1px solid var(--stroke);
}
.side-tab {
  flex: 1;
  border: none;
  background: var(--chrome);
  padding: 6px;
  border-right: 1px solid var(--stroke);
}
.side-tab.active { background: #fff; }
.recent-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
}
.recent-panel.hidden { display: none; }
.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
}
.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.recent-list li {
  padding: 6px 4px;
  border-bottom: 1px solid var(--stroke);
  cursor: pointer;
  font-size: 12px;
  word-break: break-all;
}
.recent-list li:hover { background: #eef3fa; }
.recent-list li .tag {
  color: #666;
  font-size: 11px;
  margin-left: 4px;
}
.recent-empty { font-size: 12px; margin: 8px 0; }
.recent-empty.hidden { display: none; }

.center {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  min-width: 0;
  min-height: 0;
}
.center.cascade-mode {
  display: block;
  position: relative;
  overflow: hidden;
}
.center.cascade-mode .pane:not(.hidden) {
  position: absolute;
  left: calc(10px + var(--cascade-i, 0) * 28px);
  top: calc(10px + var(--cascade-i, 0) * 28px);
  width: min(74%, calc(100% - 56px));
  height: min(80%, calc(100% - 56px));
  box-shadow: 2px 3px 10px rgba(0, 0, 0, 0.16);
}
.pane {
  background: #fff;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 2px solid #999;
}
.pane-result { border-color: var(--result); }
.pane-recog { border-color: var(--recog); }
.pane-source { border-color: #5a6a8a; }
.pane.hidden { display: none; }
.pane-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px 4px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--stroke);
  background: #fafafa;
}
.pane-bar-result { color: #2d6a2d; }
.pane-bar-recog { color: #8a3a4a; }
.pane-bar-source { color: #3a4a6a; }
.pane-close {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #666;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.pane-close:hover {
  background: #eee;
  border-color: #ccc;
  color: #222;
}
.pane-body {
  flex: 1;
  overflow: auto;
  background: #c0c0c0;
  display: flex;
  /* safe center：内容溢出时退回 start，否则左侧选区滚不到 */
  justify-content: center;
  justify-content: safe center;
  align-items: flex-start;
  padding: 8px;
  position: relative;
}
.pane-body.scroll-start {
  justify-content: flex-start;
}
.pane-body img {
  max-width: none;
  background: #fff;
  box-shadow: 0 0 0 1px #999;
  transform-origin: top center;
}

.hist-actions {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--stroke);
}
.hist-actions button {
  flex: 1;
  border: 1px solid var(--stroke);
  background: #fff;
  padding: 4px;
  border-radius: 3px;
}
.hist-actions button:disabled { opacity: 0.45; }
.hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  max-height: 40%;
  overflow: auto;
  display: block;
}
.hist-table th, .hist-table td {
  border-bottom: 1px solid var(--stroke);
  padding: 6px 8px;
  text-align: left;
}
.hist-table th { background: var(--chrome); font-weight: 600; }
.hist-del {
  border: none;
  background: transparent;
  color: #a33;
  padding: 0 4px;
}
.ocr-head { border-top: 1px solid var(--stroke); margin-top: 4px; }
.ocr-text {
  flex: 1;
  min-height: 80px;
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 8px;
  font: 12px/1.45 "Segoe UI", "PingFang SC", sans-serif;
  white-space: pre-wrap;
  word-break: break-word;
  color: #333;
  background: #fafafa;
}

.statusbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 0 10px;
  background: var(--chrome);
  border-top: 1px solid var(--stroke);
  font-size: 12px;
}
.status-msg { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-page { display: flex; gap: 6px; align-items: center; }
.status-page button, .status-zoom button {
  border: 1px solid var(--stroke);
  background: #fff;
  width: 22px;
  height: 22px;
  border-radius: 3px;
}
.status-zoom { display: flex; gap: 6px; align-items: center; }
.status-zoom input[type="range"] { width: 100px; }

/* 全局处理中遮罩（防误操作） */
.work-modal.hidden { display: none; }
.work-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 20, 0.45);
}
.work-card {
  min-width: 280px;
  max-width: 90vw;
  background: #fff;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 20px 22px 16px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
  text-align: center;
}
.work-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 3px solid #dde5ee;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: work-spin 0.8s linear infinite;
}
@keyframes work-spin { to { transform: rotate(360deg); } }
.work-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.work-text {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.work-bar {
  height: 8px;
  background: #e8e8e8;
  border-radius: 4px;
  overflow: hidden;
}
.work-bar-fill {
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, #2b6cb0, #6db3f2);
  border-radius: 4px;
  animation: work-bar-slide 1.2s ease-in-out infinite;
}
@keyframes work-bar-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(360%); }
}

/* 批量处理对话框 */
.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 30, 30, 0.35);
}
.modal-card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--stroke);
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 14px 16px 12px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.modal-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.modal-x {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  padding: 0 4px;
}
.modal-desc {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}
.batch-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.batch-preset {
  border: 1px solid var(--stroke);
  background: var(--chrome);
  border-radius: 3px;
  padding: 4px 10px;
  font-size: 12px;
}
.batch-preset.active {
  border-color: var(--accent);
  background: #e8f1fb;
  color: #1a4a7a;
}
.batch-groups {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.batch-group {
  border: 1px solid var(--stroke);
  border-radius: 3px;
  padding: 8px 10px;
  background: #fafafa;
}
.batch-group h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: #444;
}
.batch-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}
.batch-checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.batch-checks input { margin: 0; }
.batch-progress {
  margin-bottom: 10px;
}
.batch-progress.hidden,
.batch-presets.hidden,
.batch-groups.hidden,
#batch-start.hidden { display: none; }
.batch-progress-bar {
  height: 8px;
  background: #e5e5e5;
  border-radius: 4px;
  overflow: hidden;
}
.batch-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.batch-progress-text {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--stroke);
}
.modal-actions { display: flex; gap: 8px; }
.btn-primary, .btn-secondary {
  border-radius: 3px;
  padding: 5px 14px;
  font-size: 12px;
}
.btn-primary {
  border: 1px solid #245a96;
  background: var(--accent);
  color: #fff;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  border: 1px solid var(--stroke);
  background: #fff;
}
.modal-card-sm { max-width: 420px; }
.modal-card-md { max-width: 520px; }
.rcustom-list {
  max-height: min(52vh, 420px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 2px 12px;
}
.rcustom-tab {
  margin-top: 8px;
  padding: 4px 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: #3a5a7a;
  border-bottom: 1px solid var(--stroke);
}
.rcustom-tab:first-child { margin-top: 0; }
.rcustom-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 3px;
}
.rcustom-row:hover { background: #f0f4f8; }
.rcustom-row input { margin: 0; }
.ribbon-group-more .rbtn { min-width: 56px; }
.fset-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 4px 12px;
}
.fset-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.fset-row select {
  min-width: 140px;
  padding: 4px 6px;
  border: 1px solid var(--stroke);
  border-radius: 3px;
  background: #fff;
}
.scan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 0 12px;
}
.scan-actions .btn-primary,
.scan-actions .btn-secondary {
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 8px 14px;
  border-radius: 4px;
  z-index: 20;
  font-size: 12px;
}
.toast.hidden { display: none; }
.toast.err { background: #8b2e2e; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 120px 1fr; }
  .sidebar-right { display: none; }
  .center { grid-template-columns: 1fr; }
}
