/* ============================================================
   OFD 文档预览器 — Microsoft Word 风格 UI
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 13px; color: #334155; background: #e8eaed;
    -webkit-font-smoothing: antialiased;
    display: flex; flex-direction: column;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
svg { display: block; flex-shrink: 0; }

/* ── Ribbon ── */
.ribbon {
    display: flex; align-items: center; gap: 4px;
    height: 48px; padding: 0 12px;
    background: #fafbfc; border-bottom: 1px solid #e2e5e9;
    flex-shrink: 0; user-select: none; justify-content: center;
}
.ribbon-group { display: flex; align-items: center; gap: 2px; }
.ribbon-sep { width: 1px; height: 24px; background: #e2e5e9; margin: 0 4px; }
.ribbon-btn {
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    border-radius: 6px; color: #4b5563; transition: background .12s;
}
.ribbon-btn:hover { background: #e5e7eb; }
.ribbon-btn:disabled { opacity: .28; pointer-events: none; }
.page-input-wrap { display: flex; align-items: center; gap: 2px; padding: 0 4px; }
.page-input {
    width: 44px; height: 30px; text-align: center;
    border: 1px solid #d1d5db; border-radius: 5px;
    font-size: 13px; font-weight: 500; color: #1e293b; background: #fff;
    outline: none; font-family: inherit;
}
.page-input:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.12); }
.page-input::-webkit-inner-spin-button { display: none; }
.page-total-text { font-size: 12px; color: #6b7280; white-space: nowrap; }
.zoom-display {
    font-size: 12px; font-weight: 500; color: #4b5563;
    min-width: 44px; text-align: center; font-variant-numeric: tabular-nums;
}
.ribbon-btn-fit {
    padding: 5px 10px; font-size: 12px; font-weight: 500; color: #4b5563;
    background: #fff; border: 1px solid #d1d5db; border-radius: 5px;
    transition: background .12s; margin-left: 4px;
}
.ribbon-btn-fit:hover { background: #f3f4f6; }

/* ── Document Area ── */
.doc-area {
    flex: 1; min-height: 0; overflow: auto;
    overflow-anchor: none;
    background: #e8eaed;
    position: relative;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y; /* 保留原生滚动，仅拦截双指缩放 */
}
.doc-area::-webkit-scrollbar { width: 8px; }
.doc-area::-webkit-scrollbar-thumb { background: #c1c7cd; border-radius: 4px; }
.doc-area::-webkit-scrollbar-thumb:hover { background: #a0a6ad; }
.doc-area::-webkit-scrollbar-track { background: transparent; }
.doc-area { scrollbar-width: thin; scrollbar-color: #c1c7cd transparent; }

/* ── Pages ── */
#pages-container {
    position: relative;
    margin: 0 auto;
    min-width: 100%;
}
.page-wrapper {
    position: absolute; left: 50%; transform: translateX(-50%);
    contain: layout style;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 2px 10px rgba(0,0,0,.06);
    background: #fff;
    touch-action: pan-x pan-y; /* 保留原生滚动，仅禁用浏览器缩放 */
}
.page-canvas { display: block; position: relative; z-index: 0; touch-action: pan-x pan-y; /* 保留原生滚动，仅禁用浏览器缩放 */ }

/* ── Text Layer ── */
.text-layer {
    position: absolute; left: 0; top: 0; z-index: 1;
    overflow: hidden; user-select: text; -webkit-user-select: text;
    cursor: text; line-height: 1;
    pointer-events: none; /* 空白区域穿透到底层画布，文字 span 自己接管选择 */
}
.text-layer span {
    display: inline-block;
    color: transparent; pointer-events: auto; /* 仅 span 响应事件 */
    cursor: text;
    touch-action: auto; /* 允许原生文字选择 */
}
.text-layer span::selection { color: transparent; background: rgba(37,99,235,.25); }
.doc-area.is-dragging .text-layer,
.doc-area.is-dragging .text-layer span {
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Loading & Error ── */
.loading-overlay {
    position: fixed; inset: 48px 0 28px; z-index: 20;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.loading-box {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; background: rgba(255,255,255,.94);
    backdrop-filter: blur(6px); border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    font-size: 13px; color: #4b5563;
}
.spinner {
    width: 18px; height: 18px; border: 2px solid #e2e8f0;
    border-top-color: #2563eb; border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-overlay {
    position: fixed; inset: 48px 0 28px; z-index: 20;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; color: #94a3b8; font-size: 13px;
}
.error-overlay svg { opacity: .4; }
.error-overlay a { color: #2563eb; text-decoration: none; }
.error-overlay a:hover { text-decoration: underline; }
.error-overlay button { padding: 6px 16px; background: #fff; border: 1px solid #c1c7cd; border-radius: 4px; color: #334155; }
.hidden { display: none !important; }

/* ── Status Bar ── */
.status-bar {
    display: flex; align-items: center; gap: 8px;
    height: 28px; padding: 0 12px;
    background: #fafbfc; border-top: 1px solid #e2e5e9;
    font-size: 11px; color: #6b7280; flex-shrink: 0; user-select: none;
}
.status-sep { width: 1px; height: 12px; background: #d1d5db; }

@media (max-width: 768px) {
    .ribbon { height: 40px; padding: 0 4px; gap: 1px; overflow-x: auto; justify-content: flex-start; }
    .ribbon-btn { width: 30px; height: 30px; }
    .ribbon-btn-fit { display: none; }
    .ribbon-sep { margin: 0 2px; }
    .zoom-display { min-width: 36px; font-size: 11px; }
    .page-input { width: 36px; height: 26px; font-size: 12px; }
    .page-total-text { font-size: 11px; }

    .doc-area { overflow-x: auto; overflow-y: auto; }

    .status-bar { display: none; }
    .loading-overlay, .error-overlay { inset: 40px 0 0; }
}
