* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; height: 100vh; display: flex; flex-direction: column; }

.header { background: #1a1a2e; color: #fff; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.header h1 { font-size: 18px; font-weight: 600; }
.header h1 span { color: #4fc3f7; }

.upload-bar { background: #fff; padding: 12px 24px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #e0e0e0; flex-shrink: 0; }
.upload-bar .file-info { color: #666; font-size: 13px; }
.upload-bar .file-info strong { color: #333; }
.upload-btn { background: #4fc3f7; color: #fff; border: none; padding: 8px 20px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.upload-btn:hover { background: #29b6f6; }
.upload-btn:disabled { background: #ccc !important; cursor: not-allowed !important; opacity: 0.6; }

.main { display: flex; flex: 1; overflow: hidden; }

.left-panel { flex: 1; display: flex; flex-direction: column; background: #e8e8e8; min-width: 0; }
.panel-header { background: #fff; padding: 8px 16px; font-size: 13px; font-weight: 600; color: #333; border-bottom: 1px solid #ddd; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.panel-header .tab-bar { display: flex; gap: 0; }
.panel-header .tab-bar .tab { padding: 4px 14px; cursor: pointer; border-radius: 4px 4px 0 0; font-size: 13px; color: #999; transition: all 0.2s; user-select: none; }
.panel-header .tab-bar .tab:hover { color: #555; background: #f5f5f5; }
.panel-header .tab-bar .tab.tab-active { color: #1a1a2e; background: #e8e8e8; font-weight: 600; }
.panel-header .page-info { color: #999; font-weight: 400; font-size: 12px; }
.canvas-wrap { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 20px; position: relative; }
.canvas-wrap .page-container { position: relative; box-shadow: 0 2px 12px rgba(0,0,0,0.15); background: #fff; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; }

/* 标注框 — 默认极淡轮廓，悬停/选中才完整显示 */
.bbox { position: absolute; border: 1px solid rgba(0,0,0,0.06); cursor: pointer; transition: opacity 0.25s, border-color 0.25s, background 0.2s; opacity: 0.15; }
.bbox.show { opacity: 1; border-color: inherit; border-width: 2px; }
.bbox.show .label { opacity: 1; transform: translateY(0); }
.bbox:hover { opacity: 1; background: rgba(255,255,255,0.12); }
.bbox.selected { opacity: 1 !important; border-width: 3px; background: rgba(255,255,255,0.18); }
.bbox.selected::after { content: '✓'; position: absolute; top: -20px; right: -18px; font-size: 12px; color: #fff; background: #4caf50; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; z-index: 5; }
.bbox .label { position: absolute; top: -18px; left: 0; font-size: 10px; padding: 1px 6px; border-radius: 3px; color: #fff; white-space: nowrap; opacity: 0; transform: translateY(4px); transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.bbox.show .label { opacity: 1; transform: translateY(0); }
/* 显示所有模式 */
.bbox.show-all { opacity: 0.3 !important; border-width: 1px; }
.bbox.show-all .label { opacity: 0.6; }

.right-panel { flex: 1; display: flex; flex-direction: column; background: #fff; min-width: 0; border-left: 1px solid #ddd; }
.right-panel .json-wrap { flex: 1; overflow: auto; position: relative; }
.right-panel .json-wrap pre { margin: 0; padding: 16px 20px; font-size: 12px; line-height: 1.6; font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace; white-space: pre-wrap; word-break: break-all; color: #333; }
.right-panel .copy-json-btn { position: absolute; top: 12px; right: 12px; background: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; padding: 4px 10px; cursor: pointer; font-size: 14px; opacity: 0.6; transition: opacity 0.2s; }
.right-panel .copy-json-btn:hover { opacity: 1; background: #eee; }
.markdown-wrap { flex: 1; overflow: auto; padding: 20px 24px; }
.markdown-wrap:focus { outline: none; }
.md-line { padding: 2px 4px; border-radius: 3px; cursor: text; min-height: 1.5em; transition: background 0.15s; position: relative; }
.md-line:hover { background: #f5f5f5; }
.md-line:focus { background: #e3f2fd; outline: none; }
.md-line.bbox-hover { background: #e8f5e9; }
.md-line.linked-active { background: #fff9c4; }
.md-line.right-mark { position: relative; }
.md-line.right-mark::before { content: ''; position: absolute; left: -20px; top: 2px; bottom: 2px; width: 4px; border-radius: 2px; }
.md-line.right-mark.mark-title::before { background: #e53935; }
.md-line.right-mark.mark-text::before { background: #1e88e5; }
.md-line.right-mark.mark-table::before { background: #43a047; }
.md-line.right-mark.mark-formula::before { background: #fb8c00; }
.md-line.right-mark.mark-figure::before { background: #8e24aa; }
.md-figure.right-mark { position: relative; outline: 3px solid #8e24aa; outline-offset: 2px; border-radius: 8px; }
.md-line[data-type="h1"] { font-size: 24px; font-weight: 700; margin: 16px 0 8px; color: #1a1a2e; }
.md-line[data-type="h2"] { font-size: 20px; font-weight: 600; margin: 12px 0 6px; color: #333; }
.md-line[data-type="h3"] { font-size: 16px; font-weight: 600; margin: 8px 0 4px; color: #444; }
.md-line[data-type="text"] { font-size: 14px; line-height: 1.8; color: #333; margin: 2px 0; }
.md-line[data-type="table"] { font-family: monospace; font-size: 13px; background: #f8f9fa; padding: 8px 12px; border-radius: 6px; margin: 8px 0; border: 1px solid #e0e0e0; white-space: pre; overflow-x: auto; }
.md-line[data-type="formula"] { font-family: 'Times New Roman', serif; font-size: 15px; font-style: italic; background: #f3f4f6; padding: 4px 12px; border-radius: 4px; margin: 4px 0; text-align: center; color: #1565c0; }
.md-line.error-highlight { background: #ffebee; border-left: 3px solid #e53935; }
.md-line.saving { background: #fff8e1; }

/* 图片块 */
.md-figure { margin: 12px 0; border: 1px solid #e0e0e0; border-radius: 8px; overflow: hidden; background: #fafafa; cursor: pointer; transition: background 0.2s; }
.md-figure:hover { background: #f0f0f0; }
.md-figure .fig-preview { display: flex; align-items: flex-start; gap: 16px; padding: 12px 16px; }
.md-figure .fig-thumb { width: 80px; height: 60px; border-radius: 4px; border: 1px solid #ddd; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 28px; }
.md-figure .fig-info { flex: 1; min-width: 0; }
.md-figure .fig-info .fig-type { font-size: 11px; color: #8e24aa; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.md-figure .fig-ocr-text { margin-top: 8px; padding: 6px 10px; background: #fff; border: 1px solid #e0e0e0; border-radius: 4px; font-size: 13px; line-height: 1.6; color: #333; cursor: text; transition: background 0.15s, border-color 0.15s; }
.md-figure .fig-ocr-text:hover { background: #fafafa; border-color: #bbb; }
.md-figure .fig-ocr-text:focus { background: #fff; border-color: #8e24aa; outline: none; box-shadow: 0 0 0 2px rgba(142,36,170,0.1); }
.md-figure .fig-ocr-text.saving { background: #fff8e1; }
.md-figure .fig-ocr-text .fig-ocr-label { font-size: 10px; color: #999; display: block; margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.5px; }
.md-figure .fig-ocr-text .fig-ph { color: #ccc; font-style: italic; font-size: 12px; }
.md-figure .fig-actions { margin-top: 8px; }
.md-figure .fig-info .fig-actions button { background: none; border: 1px solid #8e24aa; color: #8e24aa; padding: 2px 12px; border-radius: 4px; font-size: 11px; cursor: pointer; }
.md-figure .fig-info .fig-actions button:hover { background: #8e24aa; color: #fff; }

.status-bar { background: #fff; padding: 6px 24px; font-size: 12px; color: #999; border-top: 1px solid #e0e0e0; display: flex; justify-content: space-between; flex-shrink: 0; }
.status-bar .stat span { color: #333; font-weight: 600; }

.toast { position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 10px 24px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 100; }
.toast.show { opacity: 1; }

/* 加载遮罩 — 毛玻璃（仅限于左侧原文预览区） */
.upload-overlay { position: absolute; inset: 0; z-index: 100; background: rgba(255,255,255,0.2); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: none; align-items: center; justify-content: center; flex-direction: column; gap: 12px; border-radius: 4px; }
.upload-overlay.show { display: flex; }
.upload-overlay .spinner { width: 36px; height: 36px; border: 3px solid rgba(79,195,247,0.2); border-top-color: #4fc3f7; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.upload-overlay .msg { color: #333; font-size: 14px; font-weight: 500; }
.upload-overlay .sub { color: #999; font-size: 12px; }

.color-title { border-color: #e53935; } .color-title .label { background: #e53935; }
.color-text { border-color: #1e88e5; } .color-text .label { background: #1e88e5; }
.color-table { border-color: #43a047; } .color-table .label { background: #43a047; }
.color-formula { border-color: #fb8c00; } .color-formula .label { background: #fb8c00; }
.color-figure { border-color: #8e24aa; } .color-figure .label { background: #8e24aa; }
.color-header { border-color: #78909c; } .color-header .label { background: #78909c; }
.color-footer { border-color: #bdbdbd; } .color-footer .label { background: #bdbdbd; }

/* 欢迎页 */
.welcome { flex:1; display:flex; align-items:center; justify-content:center; background:#f0f2f5; }
.welcome-inner { text-align:center; padding:48px; }
.welcome-icon { font-size:64px; margin-bottom:16px; }
.welcome-inner h2 { font-size:24px; color:#333; margin-bottom:8px; }
.welcome-inner p { font-size:15px; color:#888; }
.welcome-hint { font-size:12px; color:#bbb; margin-top:12px; }

@media (max-width: 768px) { .main { flex-direction: column; } .right-panel { border-left: none; border-top: 1px solid #ddd; } }
