/* 全站文件预览 Modal（与 AI 知识库 document.html 对齐） */
:root {
  --kb-text: #1e2533;
  --kb-text-sub: #5a6480;
  --kb-border: #e4e8ef;
  --kb-border-inner: #edf0f4;
  --kb-radius: 6px;
  --kb-radius-sm: 4px;
  --kb-shadow-md: 0 3px 12px rgba(0, 0, 0, .10);
}

/* 桌面端 modal 外壳（my_computer / NAS 等页无 document.html 局部样式，在此补齐） */
#modal_preview .modal-content,
#modal_preview_ofd .modal-content {
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius);
  box-shadow: var(--kb-shadow-md);
  overflow: hidden;
}

#modal_preview .modal-header,
#modal_preview_ofd .modal-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  background: #fbfbfc;
  border-bottom: 1px solid var(--kb-border-inner);
}

#modal_preview .modal-header .modal-title,
#modal_preview_ofd .modal-header .modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--kb-text);
  margin: 0;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  letter-spacing: -0.01em;
}

/* 覆盖 base.html 全局隐藏滚动条，预览区需可滚动且显示滚动条 */
#modal_preview,
#modal_preview_ofd {
  scrollbar-width: thin !important;
  -ms-overflow-style: auto !important;
}

#modal_preview .modal-body,
#modal_preview_ofd .modal-body,
#modal_preview_ofd #flyfish_viewer_mount,
#modal_preview_ofd #ofd_container {
  scrollbar-width: thin !important;
  -ms-overflow-style: auto !important;
}

#modal_preview ::-webkit-scrollbar,
#modal_preview_ofd ::-webkit-scrollbar {
  display: block !important;
  width: 8px !important;
  height: 8px !important;
}

#modal_preview ::-webkit-scrollbar-thumb,
#modal_preview_ofd ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .22);
  border-radius: 4px;
}

#modal_preview ::-webkit-scrollbar-track,
#modal_preview_ofd ::-webkit-scrollbar-track {
  background: transparent;
}

#modal_preview .modal-header .close,
#modal_preview_ofd .modal-header .close {
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1 !important;
  font-size: 0;
  font-weight: 400;
  color: var(--kb-text-sub);
  opacity: 1;
  border-radius: 50%;
  background: transparent;
  text-shadow: none;
  transition: background .12s, color .12s;
}

#modal_preview .modal-header .close i,
#modal_preview_ofd .modal-header .close i {
  font-size: 13px;
  line-height: 1;
}

#modal_preview .modal-header .close:hover,
#modal_preview_ofd .modal-header .close:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--kb-text);
}

#modal_preview .modal-header .close:focus,
#modal_preview_ofd .modal-header .close:focus,
#modal_preview .modal-header .close:active,
#modal_preview_ofd .modal-header .close:active,
#modal_preview .modal-header-actions .close:focus,
#modal_preview_ofd .modal-header-actions .close:focus,
#modal_preview .modal-header-actions .close:active,
#modal_preview_ofd .modal-header-actions .close:active,
#modal_preview .modal-header-actions .btn-modal-fs:focus,
#modal_preview_ofd .modal-header-actions .btn-modal-fs:focus,
#modal_preview .modal-header-actions .btn-modal-fs:active,
#modal_preview_ofd .modal-header-actions .btn-modal-fs:active {
  outline: none;
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}

#modal_preview .modal-header-actions,
#modal_preview_ofd .modal-header-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  flex-shrink: 0;
  padding: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .04);
}

#modal_preview .modal-header-actions .btn-modal-fs,
#modal_preview_ofd .modal-header-actions .btn-modal-fs {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none !important;
  background: transparent !important;
  color: var(--kb-text-sub) !important;
  box-shadow: none !important;
}

#modal_preview .modal-header-actions .btn-modal-fs:hover,
#modal_preview_ofd .modal-header-actions .btn-modal-fs:hover {
  background: rgba(255, 255, 255, .85) !important;
  color: var(--kb-text) !important;
}

#modal_preview .modal-header-actions .btn-modal-fs i,
#modal_preview_ofd .modal-header-actions .btn-modal-fs i {
  font-size: 13px;
  line-height: 1;
}

#modal_preview .modal-header-actions .close:hover,
#modal_preview_ofd .modal-header-actions .close:hover {
  background: rgba(255, 255, 255, .9) !important;
  color: var(--kb-text) !important;
}

#modal_preview #iframe_preview,
#modal_preview #img,
#modal_preview_ofd #flyfish_viewer_mount,
#modal_preview_ofd #ofd_container {
  border-bottom-left-radius: calc(var(--kb-radius) - 1px);
  border-bottom-right-radius: calc(var(--kb-radius) - 1px);
}

#modal_preview_ofd .modal-body {
  position: relative;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.flyfish-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  min-height: 55vh;
}

.flyfish-preview-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--kb-text-sub, #5a6480);
  text-align: center;
  padding: 24px;
}

.flyfish-preview-loading-inner .fa-spinner {
  font-size: 28px;
  color: var(--kb-text, #1e2533);
}

.flyfish-preview-loading-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

#flyfish_viewer_mount .file-viewer,
#flyfish_viewer_mount .excel-wrapper {
  width: 100%;
  height: 100%;
  min-height: 0;
}

#flyfish_viewer_mount .excel-wrapper .table-wrapper,
#flyfish_viewer_mount .excel-wrapper .table-host,
#flyfish_viewer_mount .excel-wrapper .table-target,
#flyfish_viewer_mount .excel-wrapper .e-virt-table-container,
#flyfish_viewer_mount .excel-wrapper .e-virt-table-stage {
  width: 100% !important;
  max-width: 100%;
}

#flyfish_viewer_mount .excel-wrapper .e-virt-table-container {
  height: 100% !important;
}

#flyfish_viewer_mount .excel-wrapper .e-virt-table-stage {
  overflow: hidden;
}


/* OFD：去掉 Flyfish 原生 transform 过渡（分页/首次布局时的右滑动画） */
#modal_preview_ofd .ofd-page,
#flyfish_viewer_mount .ofd-page,
#modal_preview_ofd .ofd-page-frame,
#flyfish_viewer_mount .ofd-page-frame {
  transition: none !important;
  animation: none !important;
}

#ofd_container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  word-wrap: break-word;
  padding: 20px;
  line-height: 1.6;
  font-family: "Microsoft YaHei", Arial, sans-serif;
}

#ofd_container.office_container {
  padding: 20px 40px;
}

#flyfish_viewer_mount {
  width: 100%;
  min-height: 55vh;
  height: 720px;
  max-height: calc(100vh - 120px);
  overflow-x: hidden;
  overflow-y: auto;
  background: #fff;
}

/* Excel 依赖固定高度链渲染 canvas，不能用 auto 高度 + 外层滚动 */
#flyfish_viewer_mount:has(.excel-wrapper) {
  overflow: hidden;
}

#modal_preview_ofd.modal-fullscreen #flyfish_viewer_mount,
#modal_preview_ofd.modal-fullscreen #ofd_container {
  flex: 1 1 auto;
  min-height: 0;
  height: 100% !important;
  max-height: none !important;
}

#modal_preview_ofd.modal-fullscreen #flyfish_viewer_mount:has(.excel-wrapper) {
  overflow: hidden !important;
}

#modal_preview_ofd.modal-fullscreen #flyfish_viewer_mount:not(:has(.excel-wrapper)) {
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

#ofd_container img {
  max-width: 100% !important;
  height: auto !important;
  display: block;
  margin: 10px auto;
  border-radius: var(--kb-radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
}

#ofd_container table {
  max-width: 100% !important;
  width: 100%;
  table-layout: auto;
  border-collapse: collapse;
  margin: .65em 0;
  font-size: inherit;
  line-height: 1.45;
}

#ofd_container table td,
#ofd_container table th {
  border: 1px solid #cfd4da;
  padding: .4em .55em;
  vertical-align: top;
  word-break: break-word;
}

#ofd_container table th {
  font-weight: 600;
  background: rgba(0, 0, 0, .04);
  text-align: left;
}

#modal_preview.modal-fullscreen .modal-dialog,
#modal_preview_ofd.modal-fullscreen .modal-dialog {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
}

#modal_preview.modal-fullscreen .modal-content,
#modal_preview_ofd.modal-fullscreen .modal-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  height: auto !important;
  max-height: none !important;
}

#modal_preview.modal-fullscreen .modal-header,
#modal_preview_ofd.modal-fullscreen .modal-header {
  flex-shrink: 0;
  margin-top: 0;
}

#modal_preview.modal-fullscreen .modal-body,
#modal_preview_ofd.modal-fullscreen .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

#modal_preview.modal-fullscreen .modal-body#iframe_modal_body {
  overflow: hidden;
}

@media (max-width: 768px) {
  #modal_preview .modal-header-actions .btn-modal-fs,
  #modal_preview_ofd .modal-header-actions .btn-modal-fs {
    display: none !important;
  }

  #modal_preview .modal-header-actions,
  #modal_preview_ofd .modal-header-actions {
    background: transparent;
    padding: 0;
    gap: 0;
  }

  #modal_preview .modal-header .close,
  #modal_preview_ofd .modal-header .close {
    display: inline-flex !important;
  }

  #modal_preview .modal-dialog,
  #modal_preview_ofd .modal-dialog {
    margin: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh;
    height: 100dvh;
  }

  #modal_preview .modal-content,
  #modal_preview_ofd .modal-content {
    height: 100vh;
    height: 100dvh;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
  }

  #modal_preview .modal-body#iframe_modal_body {
    padding: 0 !important;
    height: calc(100vh - 44px);
    height: calc(100dvh - 44px);
    overflow: hidden !important;
  }

  #modal_preview_ofd .modal-body {
    padding: 0 !important;
    max-height: none !important;
    height: calc(100vh - 44px);
    height: calc(100dvh - 44px);
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
  }

  #modal_preview #iframe_preview,
  #modal_preview #img,
  #modal_preview #file_preview_video {
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    max-height: none !important;
    border-radius: 0 !important;
  }

  #modal_preview_ofd #flyfish_viewer_mount,
  #modal_preview_ofd #ofd_container {
    flex: 1 1 auto;
    max-height: none !important;
    height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  #modal_preview_ofd #flyfish_viewer_mount:not(:has(.excel-wrapper)) {
    overflow-y: auto !important;
  }
}
