/* ========================================
   PreviewItem 预览面板 — CSS Module
   ======================================== */

.previewPanel {
    position: relative;
    width: var(--preview-panel-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-left: 1px solid var(--overlay-light);
    padding-top: 48px;
    overflow: hidden;
    transition: width var(--duration-slow) var(--ease-out),
                border-color var(--duration-slow) var(--ease-out);
    z-index: 10;
}

.previewPanelCollapsed {
    width: 0;
    border-left: none;
}

.previewPanelInner {
    display: flex;
    flex-direction: column;
    width: var(--preview-panel-width);
    min-width: var(--preview-panel-width);
    height: 100%;
    min-height: 0;
    opacity: 1;
    transition: opacity var(--duration-fast) var(--ease-out);
}

.previewPanelCollapsed .previewPanelInner {
    opacity: 0;
    pointer-events: none;
}

.previewBodyShell {
    flex: 1;
    min-height: 0;
    position: relative;
    margin: 5px 10px 10px;
}

.previewPanelBody {
    height: 100%;
    overflow: auto;
    position: relative;
    border-radius: var(--radius-lg);
    background: var(--bg-card, var(--bg));
    border: 1px solid var(--overlay-light);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

/* iframe 预览（HTML previewItem） */
.previewPanelBody iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

/* Markdown 预览 */
.previewPanelBody :global(.preview-markdown) {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--editor-markdown-font-size);
    font-weight: 400;
    line-height: var(--editor-markdown-line-height);
    font-family: var(--font-serif);
}

.previewPanelBody :global(.preview-markdown) h1 {
    text-align: center;
    font-size: var(--editor-markdown-h1-font-size);
    font-weight: 700;
}

.previewPanelBody :global(.preview-markdown) h2 {
    font-size: var(--editor-markdown-h2-font-size);
    font-weight: 600;
}

.previewPanelBody :global(.preview-markdown) h3 {
    font-size: var(--editor-markdown-h3-font-size);
    font-weight: 600;
}

.previewPanelBody :global(.preview-markdown) h4 {
    font-size: var(--editor-markdown-h4-font-size);
    font-weight: 600;
}

.previewPanelBody :global(.preview-markdown) h5 {
    font-size: var(--editor-markdown-h5-font-size);
    font-weight: 600;
}

.previewPanelBody :global(.preview-markdown) h6 {
    font-size: var(--editor-markdown-h6-font-size);
    font-weight: 600;
}

.previewPanelBody :global(.preview-markdown) strong {
    font-weight: 700;
}

/* 代码预览 */
.previewPanelBody :global(.preview-code) {
    padding: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    color: var(--text);
    margin: 0;
}

/* docx 预览 */
.previewPanelBody :global(.preview-docx) {
    padding: var(--space-md) var(--space-lg);
    line-height: 1.8;
    overflow-y: auto;
}

.previewPanelBody :global(.preview-docx) table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
}

.previewPanelBody :global(.preview-docx) th,
.previewPanelBody :global(.preview-docx) td {
    border: 1px solid var(--overlay-light);
    padding: 6px 10px;
}

/* 图片预览 */
.previewPanelBody :global(.preview-image) {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    margin: auto;
}

/* PDF 预览：略微放大让查看器深色背景被圆角裁切掉 */
.previewPanelBody :global(.preview-pdf) {
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    margin: -4px;
    border: none;
    border-radius: inherit;
    overflow: hidden;
}

/* CSV 表格预览 */
.previewPanelBody :global(.preview-csv) {
    padding: var(--space-sm);
    overflow: auto;
    height: 100%;
}

.previewPanelBody :global(.preview-csv) table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.previewPanelBody :global(.preview-csv) th,
.previewPanelBody :global(.preview-csv) td {
    padding: 6px 10px;
    border: 1px solid var(--overlay-light);
    text-align: left;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.previewPanelBody :global(.preview-csv) thead th {
    position: sticky;
    top: 0;
    background: var(--tool-bg);
    font-weight: 600;
    z-index: 1;
}

.previewPanelBody :global(.preview-csv) tbody tr:hover {
    background: var(--overlay-subtle);
}

/* 文件信息卡 */
.previewPanelBody :global(.preview-file-info) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: var(--space-md);
    padding: var(--space-xl);
    text-align: center;
}

.previewPanelBody :global(.preview-file-icon) {
    width: 56px;
    height: 56px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.previewPanelBody :global(.preview-file-icon) svg {
    width: 48px;
    height: 48px;
}

.previewPanelBody :global(.preview-file-name) {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
}

.previewPanelBody :global(.preview-file-ext) {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.previewPanelBody :global(.preview-file-open-btn) {
    margin-top: var(--space-sm);
    padding: 0.5rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #fff;
    font-size: 0.88rem;
    cursor: pointer;
    transition: opacity var(--duration-fast);
}

.previewPanelBody :global(.preview-file-open-btn):hover {
    opacity: 0.85;
}

/* ── Preview 编辑器（CodeMirror 6）── */

:global(.preview-editor) {
    height: 100%;
    overflow: hidden;
}

:global(.preview-editor .cm-editor) {
    height: 100%;
    background: transparent;
}

:global(.preview-editor .cm-editor.cm-focused) {
    outline: none;
}

:global(.preview-editor .cm-scroller) {
    overflow: auto;
    padding: var(--space-lg) 0;
}

:global(.preview-editor .cm-content) {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

:global(.preview-editor .cm-gutters) {
    background: transparent;
    border-right: 1px solid var(--overlay-light);
    color: var(--text-muted);
    font-size: 0.75rem;
}

:global(.preview-editor .cm-activeLineGutter) {
    background: transparent;
    color: var(--text);
}

:global(.preview-editor .cm-activeLine) {
    background: var(--overlay-subtle);
}

:global(.preview-editor .cm-selectionBackground) {
    background: var(--accent-light, rgba(100, 140, 200, 0.15)) !important;
}

:global(.preview-editor .cm-cursor) {
    border-left-color: var(--text);
}

/* ── Markdown 模式 ── */

:global(.cm-center-line) {
    text-align: center;
}

:global(.cm-hr-widget) {
    display: inline-block;
    width: 80%;
    vertical-align: middle;
    border-top: 1px solid var(--border);
}

:global(.cm-checkbox) {
    cursor: pointer;
    accent-color: var(--accent);
    margin-right: 0.3em;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

:global(.cm-blockquote-line) {
    border-left: 3px solid var(--accent);
    padding-left: 1em;
    background: var(--overlay-subtle);
}

:global(.cm-codeblock-line) {
    background: var(--overlay-light);
}

:global(.cm-codeblock-lang) {
    float: right;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    pointer-events: none;
    user-select: none;
}

:global(.cm-image-widget) {
    display: block;
    max-width: 100%;
    margin: var(--space-xs) 0;
}

:global(.cm-image-widget img) {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

:global(.cm-image-fallback) {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85em;
}

:global(.cm-link-text) {
    color: var(--link);
    text-decoration: underline;
    text-decoration-color: rgba(var(--link-rgb), 0.55);
    text-underline-offset: 2px;
}

:global(.cm-table-widget) {
    margin: var(--space-xs) 0;
    overflow-x: auto;
}

:global(.cm-table-widget table) {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    font-family: var(--font-serif);
}

:global(.cm-table-widget th),
:global(.cm-table-widget td) {
    border: 1px solid var(--border);
    padding: 0.3em 0.6em;
    text-align: left;
}

:global(.cm-table-widget th) {
    background: var(--overlay-light);
    font-weight: 600;
}

:global(.cm-table-widget th:focus),
:global(.cm-table-widget td:focus) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    background: var(--overlay-subtle);
}

:global(.cm-table-widget th[contenteditable]),
:global(.cm-table-widget td[contenteditable]) {
    cursor: text;
}

:global(.cm-mermaid-widget) {
    display: block;
    margin: var(--space-xs) 0;
    padding: var(--space-sm);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--overlay-subtle);
    cursor: text;
    overflow-x: auto;
}

:global(.cm-mermaid-widget:hover),
:global(.cm-mermaid-widget:focus) {
    background: var(--overlay-light);
}

:global(.cm-mermaid-widget .mermaid-source[hidden]) {
    display: none;
}

:global(.cm-mermaid-widget .mermaid-rendered) {
    overflow-x: auto;
}

:global(.cm-mermaid-widget .mermaid-rendered svg) {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
}

:global(.cm-mermaid-widget.is-error .mermaid-rendered) {
    margin-bottom: var(--space-xs);
    color: var(--coral);
    font-size: 0.82em;
}

/* CSV 表格 widget（编辑器内渲染） */
:global(.cm-csv-table-widget) {
    overflow-x: auto;
}

:global(.cm-csv-table-widget table) {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
    font-family: var(--font-serif);
}

:global(.cm-csv-table-widget th),
:global(.cm-csv-table-widget td) {
    border: 1px solid var(--border);
    padding: 0.35em 0.6em;
    text-align: left;
    white-space: nowrap;
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
}

:global(.cm-csv-table-widget th) {
    background: var(--overlay-light);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

:global(.cm-csv-table-widget th:focus),
:global(.cm-csv-table-widget td:focus) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    background: var(--overlay-subtle);
    white-space: normal;
    overflow: visible;
}

:global(.cm-csv-table-widget th[contenteditable]),
:global(.cm-csv-table-widget td[contenteditable]) {
    cursor: text;
}

:global(.cm-csv-table-widget tbody tr:hover) {
    background: var(--overlay-subtle);
}

/* 拖拽中禁 transition */
:global(body.resizing) .previewPanel,
:global(body.resizing) .previewPanelInner {
    transition: none !important;
}
