/* =============================================================================
   TalkGhost Docs — 查看器样式
   -----------------------------------------------------------------------------
   配色沿用站点「旧纸 / 朱砂」的基调（与主题 tgd-ui.css 的设计令牌一致），
   但这里自带一份变量定义 + 回退值，保证插件单独启用时也好看。

   移动端要点：工具条必须 flex-wrap，否则在 390px 下 8 个按钮会被挤成竖排单字。
   （这个坑在 UI 阶段已经踩过一次，见交付说明。）
   ============================================================================= */

.tgd-doc {
    --tgd-ink:      #2e2a25;
    --tgd-ink-2:    #5b5348;
    --tgd-ink-3:    #8b8177;
    --tgd-paper:    #f7f5f0;
    --tgd-paper-2:  #fffdf9;
    --tgd-line:     #e6e0d4;
    --tgd-line-2:   #d8d0c0;
    --tgd-cinnabar: #a4262c;
    --tgd-cinnabar-2:#8c1f24;
    --tgd-cinnabar-soft:#f6ebe9;
    --tgd-radius:   6px;
    --tgd-shadow:   0 2px 10px rgba(60,50,40,.07);
    --tgd-shadow-lg:0 8px 30px rgba(60,50,40,.14);

    position: relative;
    margin: 22px 0;
    background: var(--tgd-paper-2);
    border: 1px solid var(--tgd-line);
    border-radius: var(--tgd-radius);
    box-shadow: var(--tgd-shadow);
    overflow: hidden;
    font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
    color: var(--tgd-ink);
}

/* 关键：下面很多元素用了 display:flex，会盖掉 UA 的 [hidden]{display:none}，
   导致 JS 里 el.hidden = true 完全没效果（加载遮罩曾经因此一直盖着画布）。
   这里统一兜住。 */
.tgd-doc [hidden] { display: none !important; }

/* ------------------------------------------------------------------ 顶部信息条 */

.tgd-doc-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    background: linear-gradient(180deg, #fdfbf7, #f4f0e8);
    border-bottom: 1px solid var(--tgd-line);
    font-size: 13.5px;
}
.tgd-doc-name {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    font-weight: 600;
    color: var(--tgd-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tgd-doc-meta {
    margin-left: auto;
    flex: 0 0 auto;
    color: var(--tgd-ink-3);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- 图标 */

.tgd-i {
    display: inline-block;
    width: 15px; height: 15px;
    flex: 0 0 auto;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 15px 15px;
    opacity: .75;
    /* 用内联 SVG 做图标，避免依赖图标字体（主题里图标字体被覆盖过） */
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-position: center;  mask-position: center;
    -webkit-mask-size: 15px 15px;   mask-size: 15px 15px;
    background-color: currentColor;
    -webkit-mask-image: var(--ico); mask-image: var(--ico);
}
.tgd-i-file   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3C/svg%3E"); }
.tgd-i-sheet  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Cpath d='M3 9h18M3 15h18M9 3v18M15 3v18'/%3E%3C/svg%3E"); }
.tgd-i-left   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M15 18l-6-6 6-6'/%3E%3C/svg%3E"); }
.tgd-i-right  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M9 18l6-6-6-6'/%3E%3C/svg%3E"); }
.tgd-i-up     { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 15l-6-6-6 6'/%3E%3C/svg%3E"); }
.tgd-i-down   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
.tgd-i-plus   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.tgd-i-minus  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.tgd-i-rotate { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M23 4v6h-6'/%3E%3Cpath d='M20.5 15a9 9 0 1 1-2.1-9.4L23 10'/%3E%3C/svg%3E"); }
.tgd-i-search { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E"); }
.tgd-i-close  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E"); }
.tgd-i-print  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M6 9V2h12v7'/%3E%3Cpath d='M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E"); }
.tgd-i-expand { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M3 16v3a2 2 0 0 0 2 2h3M16 21h3a2 2 0 0 0 2-2v-3'/%3E%3C/svg%3E"); }
.tgd-i-lock   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E"); }
.tgd-i-info   { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 16v-5M12 8h.01'/%3E%3C/svg%3E"); }
.tgd-i-theme  { --ico: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 3v18'/%3E%3Cpath d='M12 3a9 9 0 0 1 0 18z' fill='black'/%3E%3C/svg%3E"); }

/* ------------------------------------------------------------------- 工具条 */

.tgd-pdf-toolbar,
.tgd-text-toolbar {
    display: flex;
    flex-wrap: wrap;                /* ← 关键：窄屏换行，不要挤成竖排单字 */
    align-items: center;
    gap: 4px;
    padding: 7px 10px;
    background: var(--tgd-paper-2);
    border-bottom: 1px solid var(--tgd-line);
}

.tgd-tb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--tgd-ink-2);
    font: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;            /* ← 防止「上一页」被拆成竖排 */
    user-select: none;
    transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.tgd-tb:hover {
    background: var(--tgd-cinnabar-soft);
    border-color: #f0ded9;
    color: var(--tgd-cinnabar);
}
.tgd-tb:active { transform: translateY(1px); }
.tgd-tb[disabled] { opacity: .35; cursor: default; }
.tgd-tb[disabled]:hover { background: transparent; border-color: transparent; color: var(--tgd-ink-2); }

.tgd-tb-text { font-size: 13px; padding: 0 10px; }
.tgd-tb-sep {
    width: 1px; height: 18px;
    background: var(--tgd-line);
    margin: 0 4px;
    flex: 0 0 auto;
}
.tgd-tb-spacer { flex: 1 1 auto; min-width: 4px; }

.tgd-zoom-label {
    min-width: 46px;
    text-align: center;
    font-size: 12.5px;
    color: var(--tgd-ink-2);
    font-variant-numeric: tabular-nums;
}

.tgd-pager {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--tgd-ink-2);
}
.tgd-page-input {
    width: 46px;
    height: 30px;
    padding: 0 6px;
    text-align: center;
    border: 1px solid var(--tgd-line);
    border-radius: 4px;
    background: #fff;
    font: inherit;
    font-size: 13px;
    color: var(--tgd-ink);
    font-variant-numeric: tabular-nums;
}
.tgd-page-input:focus { outline: 2px solid var(--tgd-cinnabar-soft); border-color: var(--tgd-cinnabar); }
.tgd-pager-sep { color: var(--tgd-ink-3); }

.tgd-find {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 0 4px;
    border: 1px solid var(--tgd-line);
    border-radius: 4px;
    background: var(--tgd-paper);
}
.tgd-find input {
    width: 120px;
    height: 28px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 13px;
    color: var(--tgd-ink);
    outline: none;
}
.tgd-find-count {
    min-width: 46px;
    text-align: center;
    font-size: 12px;
    color: var(--tgd-ink-3);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- 舞台 */

.tgd-pdf-stage {
    position: relative;
    overflow: auto;
    background: #6f6a63;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.tgd-pdf-pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    min-height: 100%;
}

.tgd-page {
    position: relative;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.28);
    flex: 0 0 auto;
    overflow: hidden;
}
.tgd-page-canvas { display: block; }
.tgd-page.is-error::after {
    content: "本页渲染失败";
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #999; font-size: 13px; background: #fafafa;
}

.tgd-pdf-loading {
    position: absolute; inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--tgd-paper-2);
    color: var(--tgd-ink-3);
    font-size: 13.5px;
    z-index: 5;
}
.tgd-spinner {
    width: 26px; height: 26px;
    border: 2.5px solid var(--tgd-line);
    border-top-color: var(--tgd-cinnabar);
    border-radius: 50%;
    animation: tgd-spin .8s linear infinite;
}
@keyframes tgd-spin { to { transform: rotate(360deg); } }

.tgd-pdf-error {
    margin: 40px auto;
    max-width: 380px;
    padding: 22px;
    background: #fff;
    border-radius: 6px;
    text-align: center;
    color: var(--tgd-ink-2);
    font-size: 13.5px;
}
.tgd-pdf-error p { margin: 0 0 8px; }
.tgd-err-detail {
    color: var(--tgd-ink-3) !important;
    font-size: 12px !important;
    word-break: break-all;
}
.tgd-btn-retry {
    margin-top: 6px;
    padding: 7px 18px;
    border: 1px solid var(--tgd-cinnabar);
    border-radius: 4px;
    background: var(--tgd-cinnabar);
    color: #fff;
    font: inherit; font-size: 13px;
    cursor: pointer;
}

/* -------------------------------------------------------- 文本查看器舞台 */

.tgd-text-stage {
    overflow: auto;
    background: var(--tgd-paper);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 20px 16px;
}

.tgd-paper {
    max-width: 820px;
    margin: 0 auto;
    padding: 40px 46px 56px;
    background: var(--tgd-paper-2);
    border: 1px solid var(--tgd-line);
    border-radius: 3px;
    box-shadow: var(--tgd-shadow);
    color: var(--tgd-ink);
    font-family: "Songti SC", "SimSun", "Noto Serif CJK SC", serif;
    font-size: 16px;
    line-height: 1.9;
    word-wrap: break-word;
}
.tgd-paper h1,
.tgd-paper h2,
.tgd-paper h3 {
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    line-height: 1.45;
    color: var(--tgd-ink);
}
.tgd-paper h1 { font-size: 1.5em; margin: .2em 0 1em; text-align: center; letter-spacing: .04em; }
.tgd-paper h2 {
    font-size: 1.22em;
    margin: 1.8em 0 .7em;
    padding-bottom: .3em;
    border-bottom: 1px solid var(--tgd-line);
}
.tgd-paper h3 { font-size: 1.08em; margin: 1.5em 0 .5em; color: var(--tgd-cinnabar-2); }
.tgd-paper p { margin: .7em 0; text-align: justify; }
.tgd-paper strong { font-weight: 700; }
.tgd-paper em { font-style: italic; }
.tgd-paper u { text-decoration: underline; text-underline-offset: 2px; }
.tgd-paper sup { font-size: .72em; vertical-align: super; }
.tgd-paper sub { font-size: .72em; vertical-align: sub; }

.tgd-li { position: relative; padding-left: 1.35em; }
.tgd-li-dot {
    position: absolute;
    left: .35em; top: .82em;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--tgd-cinnabar);
    opacity: .65;
}

.tgd-docx-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1em auto;
    border-radius: 3px;
}
.tgd-img-skip {
    display: inline-block;
    padding: 2px 8px;
    background: var(--tgd-paper);
    border: 1px dashed var(--tgd-line-2);
    border-radius: 3px;
    color: var(--tgd-ink-3);
    font-size: .85em;
}

.tgd-docx-table,
.tgd-xlsx-table {
    width: 100%;
    margin: 1.2em 0;
    border-collapse: collapse;
    font-family: "Microsoft YaHei", sans-serif;
    font-size: .86em;
}
.tgd-docx-table td,
.tgd-xlsx-table td,
.tgd-xlsx-table th {
    border: 1px solid var(--tgd-line-2);
    padding: 6px 9px;
    vertical-align: top;
}
.tgd-xlsx-table th {
    background: var(--tgd-paper);
    font-weight: 600;
    white-space: nowrap;
}
.tgd-docx-table p { margin: 0; text-align: left; }

/* 阅读底色 */
.tgd-doc--text.is-sepia .tgd-text-stage { background: #efe6d4; }
.tgd-doc--text.is-sepia .tgd-paper { background: #fbf3e2; border-color: #e0d3ba; color: #4a3f2e; }
.tgd-doc--text.is-dark .tgd-text-stage { background: #24211e; }
.tgd-doc--text.is-dark .tgd-paper { background: #2c2925; border-color: #3b3630; color: #cfc7bb; }
.tgd-doc--text.is-dark .tgd-paper h3 { color: #d98a84; }

.tgd-text-stage--sheet { padding: 14px; }
.tgd-sheet-wrap { background: #fff; border: 1px solid var(--tgd-line); border-radius: 3px; padding: 10px; overflow: auto; }
.tgd-xlsx-sheet-title {
    margin: 14px 0 6px;
    font: 600 13px/1.4 "Microsoft YaHei", sans-serif;
    color: var(--tgd-ink-2);
}
.tgd-xlsx-sheet-title:first-child { margin-top: 0; }
.tgd-xlsx-note { margin: 8px 0 0; font-size: 12.5px; color: var(--tgd-ink-3); }

/* --------------------------------------------------------------- 底部提示 */

.tgd-doc-foot {
    padding: 8px 14px;
    background: var(--tgd-paper);
    border-top: 1px solid var(--tgd-line);
}
.tgd-doc-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tgd-ink-3);
}
.tgd-doc-hint .tgd-i { width: 13px; height: 13px; opacity: .6; }

/* ------------------------------------------------------------------ 提示条 */

.tgd-doc--notice { border-style: dashed; box-shadow: none; }
.tgd-notice {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 16px 18px;
    font-size: 13.5px;
    color: var(--tgd-ink-2);
    line-height: 1.7;
}
.tgd-notice .tgd-i { margin-top: 3px; color: var(--tgd-cinnabar); opacity: .8; }

/* ------------------------------------------------------------- 全屏 / toast */

.tgd-doc:fullscreen,
.tgd-doc:-webkit-full-screen {
    display: flex;
    flex-direction: column;
    border-radius: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    background: var(--tgd-paper-2);
}
.tgd-doc:fullscreen .tgd-pdf-stage,
.tgd-doc:fullscreen .tgd-text-stage,
.tgd-doc:-webkit-full-screen .tgd-pdf-stage,
.tgd-doc:-webkit-full-screen .tgd-text-stage {
    flex: 1 1 auto;
    height: auto !important;
}

/* 「铺满窗口」伪全屏。
   iOS Safari、微信 X5、QQ 浏览器根本没有 Element.requestFullscreen，
   老代码在这种情况下是静默失败 —— 用户点全屏毫无反应。
   这里用固定定位铺满视口来兜底。 */
.tgd-doc.is-fs {
    position: fixed;
    inset: 0;
    z-index: 999990;
    display: flex;
    flex-direction: column;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--tgd-paper-2);
}
.tgd-doc.is-fs .tgd-pdf-stage,
.tgd-doc.is-fs .tgd-text-stage {
    flex: 1 1 auto;
    height: auto !important;
}
/* 伪全屏时锁住背景滚动，否则"铺满"了背景页面还会跟着滚 */
html.tgd-fs-lock,
html.tgd-fs-lock body {
    overflow: hidden;
}

/* 全屏按钮的激活态 */
.tgd-tb.is-on {
    background: var(--tgd-cinnabar);
    border-color: var(--tgd-cinnabar);
    color: #fff;
}

.tgd-toast {
    position: absolute;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    z-index: 40;
    max-width: 86%;
    padding: 9px 18px;
    background: rgba(38,34,30,.92);
    color: #fff;
    font-size: 13px;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    transition: opacity .35s ease, transform .35s ease;
    pointer-events: none;
}
.tgd-toast.is-out { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* 打印用 iframe：不能 display:none，否则部分浏览器不触发打印 */
.tgd-print-frame {
    position: fixed;
    right: 0; bottom: 0;
    width: 1px; height: 1px;
    border: 0;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* ------------------------------------------------------------------ 响应式 */

@media (max-width: 767px) {
    .tgd-doc { margin: 16px 0; border-radius: 5px; }
    .tgd-doc-bar { padding: 8px 11px; font-size: 13px; }
    .tgd-pdf-toolbar,
    .tgd-text-toolbar { padding: 6px 7px; gap: 3px; }
    .tgd-tb { min-width: 30px; height: 30px; padding: 0 6px; font-size: 12.5px; }
    .tgd-tb-text { padding: 0 8px; }
    .tgd-tb-label { display: none; }        /* 窄屏只留图标，省空间 */
    .tgd-page-input { width: 40px; height: 28px; }
    .tgd-zoom-label { min-width: 40px; font-size: 12px; }
    .tgd-find input { width: 84px; }
    .tgd-find-count { min-width: 38px; }
    .tgd-text-stage { padding: 12px 8px; }
    .tgd-paper { padding: 24px 18px 34px; border-radius: 2px; }
    .tgd-docx-table, .tgd-xlsx-table { font-size: .8em; }
    .tgd-docx-table td, .tgd-xlsx-table td, .tgd-xlsx-table th { padding: 5px 6px; }
}

@media (max-width: 420px) {
    .tgd-tb-sep { margin: 0 2px; }
    .tgd-zoom-label { display: none; }      /* 更窄时连百分比也省掉 */
    .tgd-doc-hint { font-size: 11.5px; }
}
