/* ========================================
   文件在线预览组件样式 - FilePreview.css
   支持: PDF, Word, Excel, 图片, 文本等
   ======================================== */

/* 遮罩层 */
.file-preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.file-preview-overlay.active {
    opacity: 1;
}

/* 预览容器 */
.file-preview-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.file-preview-overlay.active .file-preview-container {
    transform: scale(1);
}

/* 头部工具栏 */
.file-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    min-height: 50px;
    flex-shrink: 0;
}

.file-preview-title {
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

.file-preview-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-preview-toolbar .btn-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
}

.file-preview-toolbar .btn-tool:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.5);
}

.file-preview-toolbar .btn-tool.btn-close-preview {
    background: rgba(220, 53, 69, 0.8);
    color: #fff;
    border-color: rgba(220, 53, 69, 0.8);
}

.file-preview-toolbar .btn-tool.btn-close-preview:hover {
    background: rgba(200, 35, 51, 0.9);
    border-color: rgba(189, 33, 48, 0.9);
}

/* 内容区域 */
.file-preview-body {
    flex: 1;
    overflow: auto;
    position: relative;
    background: #f0f4f8;
}

/* 加载状态 */
.file-preview-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 10;
}

.file-preview-loading .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e9ecef;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: file-preview-spin 0.8s linear infinite;
}

@keyframes file-preview-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.file-preview-loading .loading-text {
    margin-top: 16px;
    font-size: 14px;
    color: #6c757d;
}

/* 错误状态 */
.file-preview-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
    text-align: center;
}

.file-preview-error .error-icon {
    font-size: 64px;
    color: #dc3545;
    margin-bottom: 16px;
}

.file-preview-error .error-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.file-preview-error .error-message {
    font-size: 14px;
    color: #6c757d;
    margin-bottom: 20px;
}

.file-preview-error .btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.file-preview-error .btn-download:hover {
    background: #0056b3;
}

/* 不支持预览 */
.file-preview-unsupported {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
    text-align: center;
}

.file-preview-unsupported .unsupported-icon {
    width: 80px;
    height: 80px;
    background: #f8f9fa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: #adb5bd;
    margin-bottom: 20px;
}

.file-preview-unsupported .unsupported-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.file-preview-unsupported .unsupported-message {
    font-size: 14px;
    color: #6c757d;
    margin-bottom: 20px;
}

.file-preview-unsupported .btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.file-preview-unsupported .btn-download:hover {
    background: #0056b3;
}

/* ===== PDF 预览 ===== */
.file-preview-pdf-container {
    width: 100%;
    height: 100%;
}

.file-preview-pdf-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* PDF 页面渲染 */
.file-preview-pdf-pages {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.file-preview-pdf-pages canvas {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    max-width: 100%;
}

/* PDF 页面容器（包含canvas和文本层） */
.pdf-page-container {
    position: relative;
    margin-bottom: 10px;
    display: inline-block;
}

/* PDF 文本层样式 - 支持文本选择和复制 */
.pdf-page-container .textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 0.2;
    line-height: 1.0;
}

.pdf-page-container .textLayer > span {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

.pdf-page-container .textLayer ::selection {
    background: rgba(0, 100, 255, 0.6);
}

.pdf-page-container .textLayer ::-moz-selection {
    background: rgba(0, 100, 255, 0.6);
}

/* PDF 分页工具栏 */
.file-preview-pdf-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    justify-content: center;
    flex-shrink: 0;
}

.file-preview-pdf-toolbar .page-info {
    font-size: 14px;
    color: #495057;
}

.file-preview-pdf-toolbar .btn-page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #fff;
    color: #495057;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.file-preview-pdf-toolbar .btn-page:hover:not(:disabled) {
    background: #e9ecef;
}

.file-preview-pdf-toolbar .btn-page:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== 图片预览 ===== */
.file-preview-image-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
    background: #f0f0f0;
}

.file-preview-image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
    cursor: grab;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.file-preview-image-container img.zoomed {
    max-width: none;
    max-height: none;
    cursor: move;
}

/* ===== Word/HTML 预览 ===== */
.file-preview-word-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: #fff;
}

.file-preview-word-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.file-preview-word-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px;
    background: #fff;
    min-height: 100%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}

.file-preview-word-content img {
    max-width: 100%;
    height: auto;
}

.file-preview-word-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

.file-preview-word-content table td,
.file-preview-word-content table th {
    border: 1px solid #ddd;
    padding: 8px;
}

/* ===== Excel 预览 ===== */
.file-preview-excel-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: #fff;
}

.file-preview-excel-tabs {
    display: flex;
    gap: 0;
    padding: 0 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    overflow-x: auto;
    flex-shrink: 0;
}

.file-preview-excel-tabs .sheet-tab {
    padding: 8px 20px;
    font-size: 13px;
    color: #495057;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.2s;
}

.file-preview-excel-tabs .sheet-tab:hover {
    background: #e9ecef;
}

.file-preview-excel-tabs .sheet-tab.active {
    color: #007bff;
    border-bottom-color: #007bff;
    background: #fff;
}

.file-preview-excel-content {
    padding: 16px;
    overflow: auto;
    flex: 1;
}

.file-preview-excel-content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}

.file-preview-excel-content table th {
    background: #f8f9fa;
    font-weight: 600;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
}

.file-preview-excel-content table th,
.file-preview-excel-content table td {
    border: 1px solid #dee2e6;
    padding: 6px 10px;
    white-space: nowrap;
}

.file-preview-excel-content table tr:hover {
    background: #f8f9fa;
}

/* ===== 文本预览 ===== */
.file-preview-text-container {
    width: 100%;
    height: 100%;
    overflow: auto;
    background: #fff;
}

.file-preview-text-content {
    padding: 24px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 4;
}

/* ===== 底部状态栏 ===== */
.file-preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    font-size: 12px;
    color: #6c757d;
    flex-shrink: 0;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .file-preview-container {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .file-preview-header {
        padding: 10px 12px;
    }

    .file-preview-title {
        font-size: 13px;
        max-width: 50%;
    }

    .file-preview-word-content {
        padding: 16px;
    }
}
