:root {
    /* 主题色 */
    --accent: #e53935;
    --accent-hover: #c62828;
    --auto-blue: #1565c0;
    --safe: #43a047;
    --warning: #ff8f00;

    /* 背景/面板 */
    --bg: #f5f5f5;
    --panel: #fff;
    --bg-hover: #f0f0f0;
    --bg-subtle: #fafafa;
    --bg-highlight: #fff5f5;
    --bg-chip: #eee;
    --bg-chip-dark: #333;

    /* 标签色 */
    --tag-auto-bg: #ffebee;
    --tag-manual-bg: #ffcdd2;

    /* 文字 */
    --text: #333;
    --text-secondary: #888;
    --white: #fff;

    /* 边框/分割线 */
    --border: #e0e0e0;
    --divider: #ccc;

    /* 阴影 */
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.2);

    /* 半透明叠加（用于浅色微妙背景） */
    --alpha-3: rgba(0,0,0,0.03);
    --alpha-4: rgba(0,0,0,0.04);
    --alpha-5: rgba(0,0,0,0.05);
    --alpha-6: rgba(0,0,0,0.06);

    /* 遮罩/浮层 */
    --overlay: rgba(0,0,0,0.4);
    --overlay-heavy: rgba(0,0,0,0.9);
    --toast-bg: #333;

    /* Canvas 渲染颜色 */
    --canvas-zone-fill: rgba(67,160,71,0.12);
    --canvas-zone-stroke: rgba(67,160,71,0.35);
    --canvas-zone-text: rgba(67,160,71,0.3);
    --canvas-cut-auto: rgba(229,57,53,0.6);
    --canvas-cut-manual: rgba(229,57,53,0.9);
    --canvas-handle: rgba(229,57,53,0.9);
    --canvas-handle-drag: #ff8f00;
    --canvas-handle-text: #fff;
    --canvas-dist-line: rgba(255,143,0,0.5);
    --canvas-dist-bg: rgba(0,0,0,0.55);
    --canvas-dist-text: #fff;
  }

  body.dark {
    --bg: #1a1a2e;
    --panel: #16213e;
    --border: #2a3a5c;
    --text: #e0e0e0;
    --text-secondary: #8899aa;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.15);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --bg-hover: #1e2a4a;
    --bg-subtle: #1a2540;
    --bg-highlight: #2a1a2e;
    --bg-chip: #444;
    --bg-chip-dark: #111;
    --divider: #2a3a5c;
    --overlay: rgba(0,0,0,0.6);
    --overlay-heavy: rgba(0,0,0,0.95);
    --toast-bg: #0a0a1e;
    --alpha-3: rgba(255,255,255,0.03);
    --alpha-4: rgba(255,255,255,0.04);
    --alpha-5: rgba(255,255,255,0.05);
    --alpha-6: rgba(255,255,255,0.06);
    --log-detail-bg: #111;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ====== Header ====== */
  #site-header {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 0; flex-shrink: 0;
  }
  .container {
    width: 100%;
    max-width: 1738px;
    margin: 0 auto;
    padding: 0;
  }
  #site-header .container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 52px;
    padding: 0 16px;
  }
  .hdr-left { display: flex; align-items: center; gap: 10px; justify-self: start; }
  .hdr-center { display: flex; align-items: center; gap: 10px; justify-self: center; }
  .hdr-right { display: flex; justify-content: flex-end; align-items: center; justify-self: end; gap: 6px; }
  #hdr-admin-btns { display: flex; align-items: center; gap: 4px; }
  #site-header .logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
  }
  #site-header .tagline {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
  }
  .hdr-center .file-info {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
  }
  .hdr-center .file-dims {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
  }
  #header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    position: relative;
  }
  .avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    position: relative;
  }
  .user-menu {
    display: none;
    position: absolute;
    right: 0; top: 36px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    min-width: 120px;
    z-index: 100;
    overflow: hidden;
  }
  .user-menu.show { display: block; }
  .export-wrap { position: relative; }
  .export-menu {
    display: none;
    position: absolute;
    right: 0; top: 100%;
    margin-top: 4px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    min-width: 130px;
    z-index: 100;
    overflow: hidden;
  }
  .export-menu.show { display: block; }
  .export-menu .menu-item { padding: 10px 16px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
  .export-menu .menu-item:hover { background: var(--bg); }
  .menu-item {
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
  }
  .menu-item:hover { background: var(--bg); }
  .btn-sm {
    font-size: 12px; padding: 5px 12px;
  }
  #main-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
  }

  /* ====== 功能亮点 ====== */
  #features-banner {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 20px;
  }
  .feat-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .feat-num {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
  }
  .feat-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
  }

  /* ====== Legend inline (in toolbar) ====== */
  .swatch { display: inline-block; width: 24px; height: 0; border-radius: 1px; vertical-align: middle; margin: 0 4px; }
  .swatch.auto { border-bottom: 2px dashed var(--accent); }
  .swatch.manual { border-bottom: 2px solid var(--accent); }
  .legend-inline { font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
  .toolbar-tip { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

  /* ====== 上传区 ====== */
  #upload-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px;
    border: 3px dashed var(--divider);
    border-radius: 16px;
    background: var(--bg-subtle);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
  }
  #upload-zone:hover, #upload-zone.dragover {
    border-color: var(--accent);
    background: var(--bg-highlight);
  }
  #upload-zone .inner { width: 100%; text-align: center; pointer-events: none; }
  #upload-zone .icon { font-size: 48px; margin-bottom: 12px; }
  #upload-zone h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
  #upload-zone p { color: var(--text-secondary); font-size: 14px; }

  /* ====== 工作区 ====== */
  #workspace { flex: 1; display: none; flex-direction: column; overflow: hidden; }

  #toolbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 0; flex-shrink: 0; flex-wrap: wrap;
  }
  #toolbar .file-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 120px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #toolbar .info { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
  .btn { padding: 7px 16px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--panel); font-size: 13px; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
  .btn:hover { background: var(--bg-hover); }
  .btn-primary { background: var(--accent); color: var(--white); border-color: var(--accent); }
  .btn-primary:hover { background: var(--accent-hover); }
  .btn:disabled { opacity: 0.4; cursor: not-allowed; }

  #main { display: flex; flex: 1; overflow: hidden; position: relative; gap: 0; }

  #preview-wrap { flex: 1; overflow: auto; background: var(--bg); position: relative; min-width: 0; }
  #preview-wrap canvas { display: block; margin: 0 auto; box-shadow: var(--shadow); }

  /* 右侧面板 — flex 布局，不再 absolute */
  #side-panel {
    flex: 0 0 260px;
    width: 260px;
    background: var(--panel);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: -2px 0 8px var(--alpha-6);
    transition: margin-right 0.25s ease;
  }
  #side-panel.collapsed {
    margin-right: -220px;
  }
  #side-panel.collapsed > *:not(.side-toggle) { display: none; }
  .side-toggle {
    position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 22px; height: 48px; padding: 0; background: var(--panel);
    border: 1px solid var(--border); border-right: none; border-radius: 4px 0 0 4px;
    cursor: pointer; font-size: 11px; color: var(--text-secondary); z-index: 3;
    display: flex; align-items: center; justify-content: center;
  }
  .side-toggle:hover { background: var(--bg); }
  #side-panel.collapsed .side-toggle { left: auto; right: 0; border-radius: 4px; border: 1px solid var(--border); }
  #side-panel { padding-top: 12px; }
  #side-panel h3 { font-size: 14px; font-weight: 600; padding: 14px 16px 10px; flex-shrink: 0; }
  #side-panel .summary { font-size: 12px; color: var(--text-secondary); padding: 0 16px 10px; flex-shrink: 0; }
  #cut-list { flex: 1; overflow-y: auto; list-style: none; padding: 0 8px; }
  #cut-list li {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 6px; cursor: pointer;
    font-size: 13px; transition: background 0.15s; margin-bottom: 2px;
  }
  #cut-list li:hover { background: var(--bg); }
  #cut-list li .idx { font-weight: 600; min-width: 24px; }
  #cut-list li .y-pos { flex: 1; color: var(--text-secondary); font-size: 12px; }
  #cut-list li .height { font-weight: 600; min-width: 48px; text-align: right; }
  #cut-list li .tag {
    font-size: 10px; padding: 1px 5px; border-radius: 3px;
    font-weight: 600; flex-shrink: 0;
  }
  #cut-list li .tag.auto { color: var(--accent); background: var(--tag-auto-bg); }
  #cut-list li .tag.manual { color: var(--accent-hover); background: var(--tag-manual-bg); font-weight: 700; }

  #side-actions {
    padding: 10px 12px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
  }
  #side-actions .btn { width: 100%; text-align: center; }

  /* ====== 结果区 ====== */
  #result-zone { display: none; flex: 1; flex-direction: column; overflow: hidden; padding: 16px; }
  #result-zone .result-toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-shrink: 0; }
  #result-zone .result-grid {
    flex: 1; overflow-y: auto; display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; align-content: start;
  }
  .result-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
  .result-card .card-header {
    font-size: 12px; font-weight: 600; padding: 8px 12px;
    background: var(--bg-subtle); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between;
  }
  .result-card img { width: 100%; display: block; }

  /* ====== OCR 结果区 ====== */
  #ocr-zone { display: none; flex: 1; flex-direction: column; overflow: hidden; padding: 0 16px 8px; }
  .ocr-toolbar-wrap { width: 100%; flex-shrink: 0; position: relative; }
  .ocr-toolbar-wrap::after { content: ""; display: block; position: absolute; left: -50vw; right: -50vw; bottom: 0; border-bottom: 1px solid var(--border); pointer-events: none; }
  #ocr-zone .result-toolbar { display: flex; gap: 6px; margin-bottom: 0; align-items: center; padding: 2px 0; position: relative; }
  .btn-sync-center { position: absolute; left: 50%; transform: translateX(-50%); }
  .toggle-label { font-size: 12px; display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--text-secondary); user-select: none; padding: 2px 6px; border-radius: 4px; background: var(--alpha-3); }
  body.dark .toggle-label { background: var(--alpha-5); }
  .toggle-label input { accent-color: var(--accent); }
  #ocr-body { flex: 1; display: flex; overflow: hidden; gap: 0; justify-content: center; }
  #ocr-source {
    flex: 1 1 0; min-width: 0; overflow-y: auto; overflow-x: hidden;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 0; display: flex; flex-direction: column; align-items: center;
  }
  #ocr-source-label {
    display: flex; align-items: center; justify-content: center;
    width: 100%; padding: 10px 12px; flex-shrink: 0;
    font-size: 13px; font-weight: 600; color: var(--text);
    background: var(--alpha-3); border-bottom: 1px solid var(--border);
  }
  #ocr-source-img { width: 100%; }
  #ocr-source-pdf { width: 100%; flex: 1; min-height: 0; }
  #ocr-source.hidden { display: none; }
  #ocr-source.hidden + .ocr-divider { display: none; }
  .ocr-divider { width: 2px; flex-shrink: 0; background: var(--divider); margin: 0; }
  #ocr-content {
    flex: 1 1 0; min-width: 0; overflow-y: auto; padding: 20px 24px;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px; line-height: 1.7; color: var(--text);
  }
  #ocr-content.standalone {
    margin: 0 auto;
  }
  #ocr-content.full { max-width: 860px; align-self: center; }
  #ocr-content h1, #ocr-content h2, #ocr-content h3 { margin: 16px 0 8px; }
  #ocr-content h1 { font-size: 20px; }
  #ocr-content h2 { font-size: 17px; }
  #ocr-content h3 { font-size: 15px; }
  #ocr-content p { margin: 12px 0; text-wrap: pretty; }
  #ocr-content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
  #ocr-content table td, #ocr-content table th { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
  #ocr-content table th { background: var(--alpha-4); font-weight: 600; }
  body.dark #ocr-content table th { background: var(--alpha-6); }
  #ocr-content img { max-width: 100%; border-radius: 6px; margin: 12px 0; }
  #ocr-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
  #ocr-content blockquote { border-left: 3px solid var(--accent); padding: 4px 12px; margin: 8px 0; color: var(--text-secondary); }

  /* 结构化 block 样式 */
  .sb-footnote { background: var(--alpha-3); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 0 6px 6px 0; margin: 8px 0; font-size: 13px; line-height: 1.65; }
  body.dark .sb-footnote { background: var(--alpha-4); }
  .sb-figure-title { font-weight: 600; font-size: 15px; margin: 14px 0 6px; color: var(--text); }
  .sb-header { font-size: 14px; font-weight: 600; margin: 12px 0 6px; color: var(--text-secondary); }
  .sb-seal { display: inline-block; background: var(--alpha-3); border: 1px dashed var(--accent); padding: 8px 12px; border-radius: 6px; margin: 8px 0; font-size: 13px; color: var(--text-secondary); }
  body.dark .sb-seal { background: var(--alpha-4); }
  .ocr-low-conf { border-bottom: 1.5px dashed #f59e0b; cursor: help; }  /* 低置信度标记 */
  .sb-paragraph-title { font-size: 16px; font-weight: 700; margin: 16px 0 6px; }
  .sb-footer { color: var(--text-secondary); font-size: 12px; text-align: center; margin: 16px 0 4px; padding-top: 12px; border-top: 1px solid var(--border); }
  .sb-separator { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
  .sb-table { overflow-x: auto; }
  .sb-table table { border-collapse: collapse; width: 100%; font-size: 13px; }
  .sb-table td, .sb-table th { border: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }

  /* Grid 卡片样式（多列行整体包裹） */
  .grid-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--accent);
    transition: box-shadow 0.15s;
  }
  .grid-card:hover { box-shadow: var(--shadow); }
  body.dark .grid-card { background: var(--alpha-3); }

  /* 日志面板 */
  #log-panel { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--overlay); z-index: 1000; }
  #log-panel.show { display: flex; align-items: center; justify-content: center; }
  #log-inner { background: var(--panel); border-radius: 12px; width: 90%; max-width: 900px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-lg); }
  #log-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
  #log-header h3 { margin: 0; font-size: 15px; }
  #log-list { flex: 1; overflow-y: auto; padding: 8px; }
  #log-list .log-item { padding: 10px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 4px; border: 1px solid transparent; transition: all 0.15s; }
  #log-list .log-item:hover { background: var(--alpha-3); border-color: var(--border); }
  #log-list .log-item.active { background: var(--alpha-5); border-color: var(--accent); }
  #log-list .log-time { font-size: 11px; color: var(--text-secondary); }
  #log-list .log-source { font-size: 12px; color: var(--text); font-weight: 600; }
  #log-list .log-meta { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }
  #log-detail { flex: 1; overflow-y: auto; padding: 16px; display: none; background: var(--bg-subtle); border-left: 1px solid var(--border); }
  body.dark #log-detail { background: var(--log-detail-bg); }
  #log-detail.show { display: block; }
  #log-detail pre { white-space: pre-wrap; word-break: break-all; font-size: 11px; line-height: 1.5; font-family: Menlo, Monaco, monospace; margin: 0; }
  #log-body { display: flex; flex: 1; overflow: hidden; }
  .label-chip { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 3px; margin-right: 3px; background: var(--bg-chip); }
  body.dark .label-chip { background: var(--bg-chip-dark); }

  /* 头部图标按钮 */
  .btn-icon { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; color: var(--text-secondary); transition: color 0.2s; line-height: 1; }
  .btn-icon:hover { color: var(--text); }

  /* 切片灯箱 */
  #slice-lightbox { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--overlay-heavy); z-index: 2000; align-items: center; justify-content: center; }
  #slice-lightbox.show { display: flex; }
  #lb-img { max-width: 95vw; max-height: 95vh; object-fit: contain; box-shadow: var(--shadow-md); border-radius: 4px; }
  .lb-close { position: absolute; top: 16px; right: 16px; width: 40px; height: 40px; background: rgba(255,255,255,0.15); color: var(--white); border: none; border-radius: 50%; font-size: 20px; cursor: pointer; z-index: 2001; }
  .lb-close:hover { background: rgba(255,255,255,0.3); }
  .lb-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; background: rgba(255,255,255,0.1); color: var(--white); border: none; font-size: 36px; cursor: pointer; z-index: 2001; border-radius: 4px; display: flex; align-items: center; justify-content: center; line-height: 1; }
  .lb-arrow:hover { background: rgba(255,255,255,0.25); }
  .lb-prev { left: 16px; }
  .lb-next { right: 16px; }
  .result-card { cursor: pointer; transition: transform 0.15s; }
  .result-card:hover { transform: scale(1.02); }

  /* Toast */
  #toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--white); padding: 10px 24px; border-radius: 8px; font-size: 14px; z-index: 2000; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
  #toast.show { opacity: 1; }

  /* Modal */
  #modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--overlay); z-index: 1500; align-items: center; justify-content: center; }
  #modal-overlay.show { display: flex; }
  #modal-box { background: var(--panel); border-radius: 12px; padding: 24px; max-width: 400px; text-align: center; box-shadow: var(--shadow-lg); }
  #modal-box h3 { margin: 0 0 12px; font-size: 16px; }
  #modal-box p { margin: 0 0 20px; font-size: 14px; color: var(--text-secondary); }
  #modal-box .btn { margin: 0 6px; }


  @media (max-width: 768px) {
    #main { flex-direction: column; }
    #side-panel { width: 100%; min-width: unset; max-height: 40vh;
      border-left: none; border-top: 1px solid var(--border); }
    #preview-wrap { max-height: 50vh; }
  }
/* Sync toggle — 样式已在 .ocr-divider .sync-btn 中 */

