/* web-v1.5.3 切题确认工作台：布局与手势分离，桌面三栏、移动画布优先。 */

body.selection-workspace-open { overflow: hidden; }
body.selection-workspace-open .confirm-overlay { z-index: 70; }

.import-selection-workspace {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  /* 工作台是覆盖层，背景必须不透明，避免透出下层任务面板与任务记录 */
  background: var(--surface-plain);
}
.import-selection-workspace[hidden] { display: none; }
.import-selection-workspace > * { flex: 0 0 auto; }
.import-selection-workspace[data-step="preview"] .selection-mode-bar,
.import-selection-workspace[data-step="preview"] .selection-adjust-bar,
.import-selection-workspace[data-step="preview"] .selection-workspace-footer { display: none; }
.import-selection-workspace[data-step="preview"] .selection-workspace-body { display: none; }

/* ---- 顶栏：返回、标题、保存状态、页码、已选数量、更多 ---- */

.selection-workspace-header {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, .94);
}
.selection-header-title { display: grid; gap: 2px; min-width: 0; margin-right: auto; }
.selection-header-title h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "STSong", "SimSun", serif; font-size: 1.15rem; }
.selection-save-status { color: var(--text-muted); font-size: .72rem; cursor: default; }
.selection-save-status[data-state="error"] { color: var(--danger); cursor: pointer; text-decoration: underline dotted; }
.selection-save-status[data-state="saving"], .selection-save-status[data-state="pending"] { color: var(--accent); }
.selection-page-switch { display: flex; align-items: center; gap: 4px; }
.selection-page-switch .icon-button { min-width: 40px; min-height: 40px; }
.selection-page-label { min-width: 56px; color: var(--brand-strong); font-size: .84rem; font-weight: 800; text-align: center; }
.selection-count-chip { white-space: nowrap; }
.selection-more-button { font-size: 1.2rem; font-weight: 800; }
.selection-more-menu {
  position: absolute;
  z-index: 12;
  top: calc(100% + 6px);
  right: 12px;
  display: grid;
  min-width: 200px;
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(24, 79, 64, .13);
  border-radius: 12px;
  background: rgba(255, 255, 252, .99);
  box-shadow: 0 16px 38px rgba(28, 52, 43, .18);
}
.selection-more-menu[hidden] { display: none; }
.selection-more-menu .ghost-button { min-height: 40px; padding: 8px 10px; text-align: left; }
.selection-batch-summary { padding: 3px 6px 6px; color: var(--text-muted); font-size: .7rem; line-height: 1.4; }
.selection-count-inline { color: var(--brand-strong); font-size: .76rem; font-weight: 800; white-space: nowrap; }

/* ---- 模式条：浏览/调整、原图/去手写、缩放、撤销 ---- */

.selection-mode-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}
.selection-mode-tabs, .selection-view-tabs, .selection-zoom-group, .selection-history-group { display: flex; align-items: center; gap: 6px; }
.selection-mode-tabs .ghost-button, .selection-view-tabs .ghost-button, .selection-zoom-group .ghost-button { min-height: 38px; padding: 7px 12px; }
.selection-mode-tabs .active, .selection-view-tabs .active { color: #fff; border-color: var(--brand-strong); background: var(--brand-strong); }
.selection-zoom-group { margin-left: auto; }
.selection-zoom-group .icon-button { min-width: 38px; min-height: 38px; }
.selection-zoom-label { min-width: 46px; color: var(--text-muted); font-size: .74rem; text-align: center; }
.selection-history-group .icon-button { min-width: 38px; min-height: 38px; }

/* ---- 调整模式动作条 ---- */

.selection-adjust-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(184, 106, 60, .28);
  background: var(--accent-soft);
}
.import-selection-workspace[data-mode="adjust"] .selection-adjust-bar { display: flex; }
.selection-adjust-hint { margin-right: auto; color: #874820; font-size: .76rem; line-height: 1.4; }
.selection-adjust-bar .primary-button { min-height: 40px; }

/* ---- 主体三栏 ---- */

.selection-workspace-body { flex: 1 1 auto; display: grid; grid-template-columns: 190px minmax(0, 1fr) 330px; min-height: 0; overflow: hidden; }
.selection-page-rail, .selection-candidate-pane { min-width: 0; min-height: 0; padding: 16px; background: rgba(255, 254, 250, .78); }
.selection-page-rail { border-right: 1px solid var(--line); overflow-y: auto; }
.selection-candidate-pane { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; border-left: 1px solid var(--line); overflow: hidden; }
.selection-rail-heading, .selection-pane-heading, .selection-preview-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.selection-rail-heading { align-items: center; margin-bottom: 10px; color: var(--text-muted); font-size: .74rem; }
.selection-page-list { display: grid; gap: 9px; }
.selection-page-thumb-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px; min-width: 0; }
.selection-page-thumb { display: grid; grid-template-columns: 30px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 52px; padding: 7px; border: 1px solid transparent; border-radius: 12px; color: var(--text-main); background: transparent; text-align: left; }
.selection-page-thumb:hover, .selection-page-thumb.active { border-color: rgba(36, 114, 95, .25); background: var(--brand-soft); }
.selection-page-thumb-row.needs-review .selection-thumb-index { color: #874820; background: var(--accent-soft); }
.selection-page-thumb-row.needs-review .selection-thumb-copy small { color: #874820; }
.selection-page-thumb-row[draggable="true"] { cursor: grab; }
.selection-page-thumb-row[draggable="true"]:active { cursor: grabbing; }
.selection-page-move { display: grid; gap: 3px; }
.selection-page-move .icon-button { width: 30px; min-height: 28px; padding: 2px; border-radius: 7px; font-size: .76rem; }
.selection-page-move .icon-button:disabled { opacity: .35; cursor: not-allowed; }
.selection-thumb-index { display: grid; width: 30px; height: 36px; place-items: center; border-radius: 8px; color: var(--brand-strong); background: var(--surface-muted); font-weight: 800; }
.selection-thumb-copy { display: grid; min-width: 0; gap: 3px; }
.selection-thumb-copy strong, .selection-thumb-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-thumb-copy strong { font-size: .78rem; }
.selection-thumb-copy small { color: var(--text-muted); font-size: .68rem; }

/* ---- 画布：transform 视图，手势期间不重建 DOM ---- */

.selection-canvas-pane { display: grid; grid-template-rows: minmax(0, 1fr) auto auto; gap: 8px; min-width: 0; min-height: 0; padding: 12px 14px; }
.selection-canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #dedbd2;
  touch-action: none;
  overscroll-behavior: contain;
}
.selection-canvas-content { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.selection-page-image { display: block; width: 100%; height: 100%; background: #fff; user-select: none; -webkit-user-drag: none; }
.selection-box-layer { position: absolute; inset: 0; pointer-events: none; }
.selection-box { position: absolute; min-width: 10px; min-height: 10px; padding: 0; border: 1.5px solid rgba(50, 66, 58, .78); border-radius: 4px; color: var(--surface-ink); background: rgba(255, 255, 255, .04); pointer-events: auto; text-align: left; cursor: pointer; }
.selection-box:hover, .selection-box:focus-visible { z-index: 4; border-color: var(--accent); background: rgba(184, 106, 60, .1); }
.selection-box.is-selected { border: 2px solid var(--brand); background: rgba(36, 114, 95, .1); }
.selection-box.is-focused { z-index: 5; box-shadow: 0 0 0 2px rgba(184, 106, 60, .55); }
.selection-box.is-adjusting { border: 2px solid var(--accent); background: rgba(184, 106, 60, .14); cursor: move; }
.selection-box-label { position: absolute; top: 2px; left: 3px; max-width: calc(100% - 46px); overflow: hidden; padding: 1px 4px; border-radius: 4px; color: #fff; background: rgba(21, 83, 65, .86); font-size: .68rem; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.selection-box:not(.is-selected) .selection-box-label { color: var(--text-main); background: rgba(255, 254, 250, .84); }
.selection-box-check { position: absolute; top: 0; right: 0; display: grid; width: 44px; height: 44px; place-items: center; cursor: pointer; }
.selection-box-check input { width: 22px; height: 22px; margin: 0; accent-color: var(--brand); }
.selection-handles { position: absolute; inset: 0; pointer-events: none; }
.selection-handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; pointer-events: auto; }
.selection-handle::after { content: ""; position: absolute; inset: 13px; border: 2px solid var(--accent); border-radius: 50%; background: var(--surface-plain); }
.selection-handle.handle-nw { left: 0; top: 0; }
.selection-handle.handle-n { left: 50%; top: 0; }
.selection-handle.handle-ne { left: 100%; top: 0; }
.selection-handle.handle-e { left: 100%; top: 50%; }
.selection-handle.handle-se { left: 100%; top: 100%; }
.selection-handle.handle-s { left: 50%; top: 100%; }
.selection-handle.handle-sw { left: 0; top: 100%; }
.selection-handle.handle-w { left: 0; top: 50%; }
.selection-add-ghost { position: absolute; border: 2px dashed var(--accent); border-radius: 4px; background: rgba(184, 106, 60, .14); pointer-events: none; }
.selection-canvas-hint { margin: 0; color: var(--text-muted); font-size: .74rem; line-height: 1.5; }
.selection-page-warning, .selection-preview-warning { margin: 0; padding: 8px 10px; border: 1px solid rgba(184, 106, 60, .3); border-radius: 9px; color: #874820; background: var(--accent-soft); font-size: .76rem; line-height: 1.5; }

/* ---- 候选题 ---- */

.selection-pane-heading { align-items: flex-start; }
.selection-pane-heading h3, .selection-preview-header h3 { margin: 3px 0 0; font-family: "STSong", "SimSun", serif; font-size: 1.1rem; }
.selection-candidate-list { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 8px; padding-right: 3px; }
.selection-candidate { display: grid; gap: 7px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-plain); }
.selection-candidate.selected { border-color: rgba(36, 114, 95, .38); background: rgba(226, 239, 223, .48); }
.selection-candidate.on-page { box-shadow: inset 3px 0 0 var(--accent); }
.selection-candidate.is-focused { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(184, 106, 60, .22); }
.selection-candidate-main { display: grid; grid-template-columns: 24px 46px minmax(0, 1fr); align-items: center; gap: 7px; min-width: 0; cursor: pointer; }
.selection-candidate-main input { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); }
.selection-candidate-label-input { width: 46px !important; height: 30px; padding: 3px 4px; border: 1px solid var(--line); border-radius: 7px; color: var(--brand-strong); background: var(--surface-muted); font-size: .74rem; font-weight: 800; }
.selection-candidate-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.selection-candidate-meta { display: flex; flex-wrap: wrap; gap: 5px 8px; color: var(--text-muted); font-size: .68rem; }
.selection-candidate-meta .badge { min-height: 20px; padding: 2px 7px; font-size: .66rem; }
.selection-candidate-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.selection-candidate-actions .icon-button { width: auto; min-height: 32px; padding: 4px 8px; border-radius: 8px; font-size: .7rem; }
.selection-candidate.is-highlight { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(184, 106, 60, .28); }
.selection-box.is-highlight { z-index: 6; border: 2px solid var(--accent); background: rgba(184, 106, 60, .16); }
.selection-add-button { width: 100%; min-height: 44px; }
.selection-empty { padding: 28px 10px; color: var(--text-muted); font-size: .78rem; line-height: 1.6; text-align: center; }
.selection-drawer-button, .selection-drawer-close { display: none; }
.selection-drawer-backdrop { display: none; }

/* ---- 底栏与预览 ---- */

.selection-workspace-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); background: rgba(255, 254, 250, .94); }
.selection-footer-summary { display: grid; gap: 2px; min-width: 0; }
.selection-footer-summary strong { color: var(--brand-strong); font-size: .82rem; }
.selection-footer-summary span { color: var(--text-muted); font-size: .7rem; }
.selection-footer-summary .primary-button { min-height: 44px; }
.selection-preview-panel { display: none; flex: 1 1 auto; min-height: 0; overflow: hidden; padding: 18px 22px; background: var(--surface-plain); }
.import-selection-workspace[data-step="preview"] .selection-preview-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 14px; }
.selection-preview-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-content: start; gap: 12px; overflow-y: auto; padding: 2px; }
.selection-preview-item { display: grid; gap: 8px; min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-plain); }
.selection-preview-heading { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.selection-preview-heading strong { color: var(--brand-strong); }
.selection-preview-heading span { overflow: hidden; color: var(--text-muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.selection-preview-image { width: 100%; max-height: 300px; object-fit: contain; background: #fff; }
.selection-preview-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* ---- 窄屏：980 折叠右侧、720 移动单栏 ---- */

@media (max-width: 980px) {
  .selection-workspace-body { grid-template-columns: 138px minmax(0, 1fr) 280px; }
  .selection-page-rail, .selection-candidate-pane { padding: 12px 9px; }
}

@media (max-width: 720px) {
  .selection-workspace-header { flex-wrap: nowrap; gap: 4px; padding: 8px 10px; }
  .selection-header-title { order: 1; margin-right: auto; max-width: none; min-width: 0; }
  .selection-header-title h2 { font-size: .98rem; }
  .selection-save-status { font-size: .66rem; white-space: nowrap; }
  .selection-page-switch { order: 2; }
  .selection-page-switch .icon-button { min-width: 36px; min-height: 36px; }
  .selection-page-label { min-width: 44px; font-size: .78rem; }
  .selection-count-chip { order: 3; font-size: .68rem; }
  .selection-more-button { order: 4; min-width: 36px; min-height: 36px; }
  .selection-mode-bar { flex-wrap: nowrap; gap: 6px; padding: 6px 10px; overflow-x: auto; scrollbar-width: none; }
  .selection-mode-bar::-webkit-scrollbar { display: none; }
  .selection-mode-bar > * { flex: 0 0 auto; }
  .selection-mode-tabs .ghost-button, .selection-view-tabs .ghost-button, .selection-zoom-group .ghost-button { min-height: 40px; padding: 7px 10px; }
  .selection-zoom-group { margin-left: 0; }
  .selection-zoom-group .icon-button, .selection-history-group .icon-button { min-width: 40px; min-height: 40px; }
  .selection-adjust-bar { flex-wrap: wrap; padding: 8px 10px; }
  .selection-adjust-hint { width: 100%; margin-right: 0; }
  .selection-adjust-bar .ghost-button, .selection-adjust-bar .primary-button { flex: 1; min-height: 44px; }

  /* 主体：画布优先，页条横滑，候选列表变底部抽屉 */
  .selection-workspace-body { display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(400px, 1fr) auto; overflow: hidden; }  .selection-canvas-pane { order: 1; grid-row: 1; min-height: 400px; padding: 6px 8px; }
  .selection-canvas-hint { display: none; }
  .selection-page-rail { order: 2; grid-row: 2; min-height: 92px; max-height: 92px; border-top: 1px solid var(--line); border-right: 0; padding: 8px 10px; overflow: hidden; }
  .selection-rail-heading { margin: 0 0 6px; }
  .selection-page-list { display: flex; min-height: 52px; overflow-x: auto; gap: 6px; }
  .selection-page-thumb-row { min-width: 150px; }
  .selection-page-thumb { min-width: 116px; min-height: 44px; }
  .selection-page-move { display: none; }

  .selection-candidate-pane {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    min-height: 220px; max-height: min(68vh, 560px);
    border-top: 1px solid var(--line); border-left: 0;
    border-radius: 18px 18px 0 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -14px 38px rgba(28, 52, 43, .22);
    transform: translateY(105%);
    transition: transform .22s ease;
  }
  .import-selection-workspace.selection-drawer-open .selection-candidate-pane { transform: translateY(0); }
  .selection-drawer-close { display: inline-flex; min-height: 40px; }
  .selection-drawer-button { display: inline-flex; flex: 1; min-height: 44px; }
  .selection-drawer-backdrop { display: block; position: absolute; inset: 0; z-index: 9; background: rgba(20, 32, 26, .42); }
  .selection-drawer-backdrop[hidden] { display: none; }
  .selection-candidate-actions .icon-button { min-height: 44px; }
  .selection-more-menu { right: 8px; left: 8px; }

  .selection-workspace-footer { gap: 8px; padding: 8px 10px max(8px, env(safe-area-inset-bottom)); }
  .selection-footer-summary { display: none; }
  .selection-workspace-footer .primary-button { flex: 1; min-height: 44px; }
  .import-selection-workspace[data-step="preview"] .selection-workspace-body { display: block; overflow-y: auto; padding: 12px; }
  .selection-preview-panel { padding: 12px; }
  .selection-preview-list { grid-template-columns: 1fr; }
}

@media (max-width: 400px) {
  .selection-header-title { max-width: calc(100% - 96px); }
  .selection-zoom-group .ghost-button { padding-inline: 8px; }
}

/* 矮屏：画布让位给可达性，控件与页条保持可滚动 */
@media (max-width: 720px) and (max-height: 720px) {
  .selection-workspace-body { grid-template-rows: minmax(320px, 1fr) auto; }
}

@media (prefers-reduced-motion: reduce) {
  .selection-candidate-pane { transition: none; }
}
