/**
 * SecurePDFViewer - 安全PDF查看器样式
 * 移动优先，响应式设计，全浏览器兼容
 */

*, *::before, *::after {
    box-sizing: border-box;
}

/* ============ 遮罩层 ============ */
.spv-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.85);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-animation: spvFadeIn 0.2s ease-out;
    animation: spvFadeIn 0.2s ease-out;
}

@-webkit-keyframes spvFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes spvFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ============ 查看器主体 ============ */
.spv-viewer {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    width: 95vw;
    max-width: 1200px;
    height: 92vh;
    max-height: 900px;
    background: #1e1e2e;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}

/* ============ 工具栏 ============ */
.spv-toolbar {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    padding: 8px 16px;
    background: rgba(30, 30, 46, 0.96);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}

.spv-toolbar-inner {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 0;
    background: rgba(20, 20, 35, 0.95);
    border-radius: 24px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,0.1);
}

/* ============ 分页控件 ============ */
.spv-page-info-box {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 2px;
    color: #9ca3af;
    font-size: 15px;
    padding: 0 8px;
    font-variant-numeric: tabular-nums;
}

.spv-page-current {
    color: #fff;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.3);
    padding: 6px 10px;
    border-radius: 8px;
    min-width: 32px;
    text-align: center;
}

.spv-page-sep {
    color: #6b7280;
    font-size: 14px;
}

.spv-total-pages {
    color: #9ca3af;
    min-width: 24px;
    text-align: center;
}

.spv-toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    margin: 0 4px;
}

/* ============ 按钮样式 ============ */
.spv-btn {
    display: -webkit-inline-box;
    display: -webkit-inline-flex;
    display: -ms-inline-flexbox;
    display: inline-flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    border: none;
    border-radius: 18px;
    background: transparent;
    color: #cfd2db;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    -webkit-transition: all 0.15s ease;
    transition: all 0.15s ease;
    min-width: 36px;
    height: 36px;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.spv-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.spv-btn:active {
    background: rgba(255,255,255,0.15);
}

.spv-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4);
}

.spv-btn-icon {
    padding: 8px;
    width: 36px;
}

.spv-btn-icon svg {
    display: block;
}

.spv-btn-close {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.spv-btn-close:hover {
    background: rgba(239, 68, 68, 0.35);
}

.spv-fit-btn {
    width: 36px;
}

/* ============ 缩放控件 ============ */
.spv-zoom-control {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    gap: 6px;
}

.spv-zoom-label {
    display: none;
}

/* ============ Canvas 区域（连续滚动模式）============ */
.spv-canvas-wrap {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    padding: 16px 24px;
    background:
        -webkit-repeating-conic-gradient(#2d2d44 0% 25%, transparent 0% 50%) 50% / 20px 20px;
        repeating-conic-gradient(#2d2d44 0% 25%, transparent 0% 50%) 50% / 20px 20px;
    cursor: grab;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-overflow-scrolling: touch;
    -webkit-scroll-behavior: auto;
    scroll-behavior: auto;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
}
.spv-canvas-wrap.spv-fit-width-mode {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.spv-canvas-wrap.spv-fit-width-mode::-webkit-scrollbar {
    display: none;
}
.spv-canvas-wrap.spv-fit-page-mode {
    padding-left: 48px;
    padding-right: 48px;
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .spv-canvas-wrap.spv-fit-page-mode {
        padding-left: 12px;
        padding-right: 12px;
    }
}

@media (max-width: 480px) {
    .spv-canvas-wrap.spv-fit-page-mode {
        padding-left: 8px;
        padding-right: 8px;
    }
}

.spv-canvas-wrap:active {
    cursor: grabbing;
}

.spv-canvas-wrap.grabbing {
    cursor: grabbing;
}

.spv-footer {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    background: #2a2a3e;
    border-top: 1px solid rgba(255,255,255,0.08);
    -webkit-flex-shrink: 0;
    -ms-flex-negative: 0;
    flex-shrink: 0;
}
.spv-footer-row {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    padding: 10px 16px;
    gap: 12px;
}
.spv-footer-info {
    font-size: 12px;
    color: rgba(255,255,255,0.4);
}

/* ============ 多页容器（连续滚动）============ */
.spv-pages-container {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    min-height: 100%;
    padding: 8px 0;
    margin: 0 auto;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    width: -webkit-max-content;
    width: -moz-max-content;
    width: max-content;
    min-width: 100%;
    position: relative;
}

.spv-page-container {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    width: 100%;
    min-width: -webkit-fit-content;
    min-width: -moz-fit-content;
    min-width: fit-content;
    margin: 0 0 16px 0;
    overflow: hidden;
}

.spv-page-container:last-child {
    margin-bottom: 0;
}

.spv-page-wrapper {
    position: relative;
    display: block;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    border-radius: 4px;
    background: #fff;
    overflow: hidden;
    clip-path: inset(0);
}

.spv-page-canvas,
.spv-page-watermark {
    display: block;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    border-radius: 4px;
}

.spv-page-watermark-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    clip-path: inset(0);
    pointer-events: none;
}

.spv-page-watermark {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10;
    overflow: hidden;
    clip-path: inset(0);
}

.spv-page-placeholder {
    background: #f5f5f5;
    background-image: -webkit-linear-gradient(45deg, #eee 25%, transparent 25%), -webkit-linear-gradient(-45deg, #eee 25%, transparent 25%), -webkit-linear-gradient(45deg, transparent 75%, #eee 75%), -webkit-linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    border-radius: 4px;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* ============ 加载状态 ============ */
.spv-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    gap: 10px;
    color: #6b7280;
    font-size: 13px;
    z-index: 5;
}

.spv-loading-text {
    font-size: 13px;
    color: #9ca3af;
}

.spv-loading-progress {
    width: 180px;
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    overflow: hidden;
}

.spv-loading-progress-bar {
    width: 0;
    height: 100%;
    background: -webkit-gradient(linear, left top, right top, from(#6366f1), to(#8b5cf6));
    background: -webkit-linear-gradient(left, #6366f1, #8b5cf6);
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    border-radius: 2px;
    -webkit-transition: width 0.2s ease;
    transition: width 0.2s ease;
}

.spv-loading-percent {
    font-size: 11px;
    color: #6b7280;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: center;
}

.spv-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: #6366f1;
    border-radius: 50%;
    -webkit-animation: spvSpin 0.6s linear infinite;
    animation: spvSpin 0.6s linear infinite;
}

@-webkit-keyframes spvSpin {
    to { -webkit-transform: rotate(360deg); }
}

@keyframes spvSpin {
    to { transform: rotate(360deg); }
}

/* ============ 错误状态 ============ */
.spv-error {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    padding: 16px 24px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 12px;
    color: #fca5a5;
    font-size: 14px;
    text-align: center;
    z-index: 20;
    max-width: 80%;
    word-wrap: break-word;
}


/* ============ 内嵌模式（无全屏遮罩）============ */
.spv-overlay.spv-inline {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-radius: inherit;
    width: 100%;
    height: 100%;
}

.spv-overlay.spv-inline .spv-viewer {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: inherit;
}

/* ============ 安全防护 ============ */
.spv-viewer,
.spv-viewer * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.spv-viewer input,
.spv-viewer textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ============ 桌面端大屏优化 ============ */
@media (min-width: 1025px) {
    .spv-toolbar-inner {
        padding: 6px;
    }
    
    .spv-btn {
        height: 40px;
        min-width: 40px;
        padding: 10px;
    }
    
    .spv-btn-icon {
        width: 40px;
        padding: 10px;
    }
    
    .spv-fit-btn {
        width: 40px;
    }
    
    .spv-page-info-box {
        font-size: 16px;
        padding: 0 12px;
    }
    
    .spv-page-current {
        padding: 8px 14px;
        font-size: 16px;
    }
}

/* ============ 响应式 - 平板 ============ */
@media (max-width: 1024px) {
    .spv-viewer {
        width: 98vw;
        height: 95vh;
        max-height: none;
    }
}

/* ============ 响应式 - 手机 ============ */
@media (max-width: 768px) {
    .spv-viewer {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .spv-toolbar-inner {
        padding: 3px;
    }

    .spv-btn {
        height: 34px;
        min-width: 34px;
        padding: 6px;
    }

    .spv-btn-icon {
        width: 34px;
        padding: 6px;
    }

    .spv-fit-btn {
        width: 34px;
    }

    .spv-page-info-box {
        font-size: 13px;
        padding: 0 6px;
    }

    .spv-page-current {
        padding: 5px 8px;
        font-size: 13px;
    }

    .spv-canvas-wrap {
        padding: 8px;
    }
}

/* ============ 响应式 - 小屏手机 ============ */
@media (max-width: 480px) {
    .spv-toolbar-inner {
        padding: 2px;
    }

    .spv-btn {
        height: 32px;
        min-width: 32px;
        font-size: 12px;
        padding: 5px;
    }

    .spv-btn-icon {
        width: 32px;
        padding: 5px;
    }

    .spv-fit-btn {
        width: 32px;
    }

    .spv-page-info-box {
        font-size: 12px;
        padding: 0 4px;
        gap: 2px;
    }

    .spv-page-current {
        padding: 4px 6px;
        font-size: 12px;
    }

    .spv-canvas-wrap {
        padding: 6px;
    }
}

/* ============ 横屏模式优化 ============ */
@media (max-height: 500px) and (orientation: landscape) {
    .spv-toolbar {
        padding: 6px 12px;
    }

    .spv-toolbar-inner {
        padding: 2px;
    }

    .spv-btn {
        height: 30px;
        min-width: 30px;
        padding: 4px;
    }

    .spv-btn-icon {
        width: 30px;
        padding: 4px;
    }

    .spv-fit-btn {
        width: 30px;
    }

    .spv-page-info-box {
        font-size: 12px;
        padding: 0 4px;
    }

    .spv-page-current {
        padding: 4px 6px;
        font-size: 12px;
    }

    .spv-canvas-wrap {
        padding: 8px;
    }
}

/* ============ 高DPI屏幕优化 ============ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .spv-page-canvas,
    .spv-page-watermark {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ============ 打印样式 ============ */
@media print {
    .spv-overlay {
        display: none !important;
    }
}
