/**
 * KPDF Embebido - Viewer Styles v2.2.0
 *
 * Full-width canvas, no fixed-height viewport, clean bottom toolbar.
 * Fullscreen = position:fixed overlay. Monochromatic design.
 */

/* ── CSS variables ──────────────────────────────────────────────────────────── */

.kpdf-container {
    --kpdf-accent:        #475569;
    --kpdf-accent-glow:   rgba(71,85,105,0.15);
    --kpdf-text:          #1e293b;
    --kpdf-text-muted:    #64748b;
    --kpdf-toolbar-bg:    rgba(255,255,255,0.95);
    --kpdf-toolbar-border:#e5e7eb;
    --kpdf-btn-hover:     rgba(0,0,0,0.06);
    --kpdf-btn-active:    rgba(0,0,0,0.1);
    --kpdf-radius-sm:     6px;
    --kpdf-search-bg:     #ffffff;

    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    color: var(--kpdf-text);
    background: transparent;
    display: block;
}

.kpdf-container *,
.kpdf-container *::before,
.kpdf-container *::after {
    box-sizing: border-box;
}

/* ── Loading state ──────────────────────────────────────────────────────────── */

.kpdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3em 1em;
    gap: 12px;
    opacity: 0.6;
}

.kpdf-loader {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpdf-loader-ring {
    position: absolute;
    inset: 0;
    border: 2.5px solid rgba(0,0,0,0.1);
    border-top-color: #475569;
    border-radius: 50%;
    animation: kpdf-spin 0.7s linear infinite;
}

/* Hide the document icon inside loader — only show the spinning ring */
.kpdf-loader-icon { display: none; }

@keyframes kpdf-spin {
    to { transform: rotate(360deg); }
}

.kpdf-loading-text {
    font-size: 13px;
    color: #475569;
    font-weight: 500;
}

.kpdf-ready .kpdf-loading {
    display: none;
}

/* ── Canvas area — grows naturally with PDF ─────────────────────────────────── */

.kpdf-content {
    display: flex;
    width: 100%;
}

.kpdf-canvas-wrap {
    position: relative;
    width: 100%;
    line-height: 0;
    border: 1px solid #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

.kpdf-canvas-inner {
    position: relative;
    line-height: 0;
    flex-shrink: 0;
}

.kpdf-canvas {
    display: block;
    /* Width/height set by JS via inline styles. */
}

/* ── Text layer (for search/selection) ─────────────────────────────────────── */

.kpdf-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    opacity: 0.25;
    line-height: 1;
    pointer-events: none;
}

/* When searching, raise text layer opacity so highlights are visible */
.kpdf-searching .kpdf-text-layer,
.kpdf-text-layer.kpdf-text-searching {
    opacity: 1;
}

.kpdf-text-layer span {
    position: absolute;
    white-space: pre;
    color: transparent;
    pointer-events: auto;
    cursor: text;
}

.kpdf-text-layer span::selection {
    background: rgba(71,85,105,0.25);
}

.kpdf-text-layer.kpdf-no-select {
    pointer-events: none;
}

.kpdf-text-layer.kpdf-no-select span {
    pointer-events: none;
    user-select: none;
}

/* ── Watermark ──────────────────────────────────────────────────────────────── */

.kpdf-watermark {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    overflow: hidden;
}

.kpdf-wm-text {
    font-family: Arial, sans-serif;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    user-select: none;
}

.kpdf-wm-diagonal {
    transform: rotate(-45deg);
}

.kpdf-wm-br {
    position: absolute;
    bottom: 16px;
    right: 16px;
}

/* ── Thumbnails sidebar ─────────────────────────────────────────────────────── */

.kpdf-thumbs {
    width: 130px;
    min-width: 130px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #f1f5f9;
    border-right: 1px solid rgba(0,0,0,0.08);
    padding: 10px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.kpdf-thumbs::-webkit-scrollbar { width: 3px; }
.kpdf-thumbs::-webkit-scrollbar-track { background: transparent; }
.kpdf-thumbs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }

.kpdf-thumb {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    text-align: center;
    transition: border-color 0.15s;
    background: #fff;
}

.kpdf-thumb:hover { border-color: rgba(0,0,0,0.15); }

.kpdf-thumb--active { border-color: #475569; }

.kpdf-thumb canvas { display: block; width: 100%; height: auto; }

.kpdf-thumb-num {
    display: block;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 0;
    color: var(--kpdf-text-muted);
    background: #e2e8f0;
}

.kpdf-thumb--active .kpdf-thumb-num {
    color: #fff;
    background: #475569;
}

/* ── Toolbar ────────────────────────────────────────────────────────────────── */

.kpdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    height: 46px;
    gap: 4px;
    flex-shrink: 0;
    user-select: none;
    position: relative;
    z-index: 10;
}

/* Bottom (default) — semi-transparent white with subtle top border */
.kpdf-toolbar--bottom {
    background: var(--kpdf-toolbar-bg);
    border-top: 1px solid var(--kpdf-toolbar-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Top */
.kpdf-toolbar--top {
    background: var(--kpdf-toolbar-bg);
    border-bottom: 1px solid var(--kpdf-toolbar-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Dark theme */
.kpdf-toolbar--dark {
    --kpdf-text:       #e2e8f0;
    --kpdf-text-muted: #94a3b8;
    --kpdf-btn-hover:  rgba(255,255,255,0.08);
    --kpdf-btn-active: rgba(255,255,255,0.14);
    --kpdf-toolbar-bg: rgba(22,29,49,0.92);
    --kpdf-toolbar-border: rgba(255,255,255,0.06);
    color: var(--kpdf-text);
}

/* Glass theme */
.kpdf-toolbar--glass {
    --kpdf-toolbar-bg: rgba(22,29,49,0.7);
    --kpdf-toolbar-border: rgba(255,255,255,0.1);
    --kpdf-text:       #e2e8f0;
    --kpdf-text-muted: #94a3b8;
    --kpdf-btn-hover:  rgba(255,255,255,0.08);
    --kpdf-btn-active: rgba(255,255,255,0.14);
    color: var(--kpdf-text);
}

/* Toolbar groups */
.kpdf-tb-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.kpdf-tb-left   { flex: 0 0 auto; }
.kpdf-tb-center { flex: 1 1 auto; justify-content: center; }
.kpdf-tb-right  { flex: 0 0 auto; }

.kpdf-tb-divider {
    width: 1px;
    height: 18px;
    background: rgba(0,0,0,0.1);
    margin: 0 4px;
    flex-shrink: 0;
}

.kpdf-toolbar--dark .kpdf-tb-divider,
.kpdf-toolbar--glass .kpdf-tb-divider {
    background: rgba(255,255,255,0.12);
}

/* ── Toolbar buttons ────────────────────────────────────────────────────────── */

.kpdf-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--kpdf-text-muted);
    cursor: pointer;
    border-radius: var(--kpdf-radius-sm);
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
}

.kpdf-btn-icon:hover {
    color: var(--kpdf-text);
    background: var(--kpdf-btn-hover);
}

.kpdf-btn-icon:active {
    background: var(--kpdf-btn-active);
}

.kpdf-btn-icon:focus-visible {
    outline: 2px solid #475569;
    outline-offset: 2px;
}

.kpdf-btn-icon:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

/* ── Page navigation widget ─────────────────────────────────────────────────── */

.kpdf-page-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0,0,0,0.04);
    border-radius: var(--kpdf-radius-sm);
    padding: 0 8px;
    height: 30px;
    margin: 0 2px;
}

.kpdf-toolbar--dark .kpdf-page-nav,
.kpdf-toolbar--glass .kpdf-page-nav {
    background: rgba(255,255,255,0.07);
}

.kpdf-page-input {
    width: 36px;
    height: 24px;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    padding: 0;
    background: transparent;
    color: var(--kpdf-text);
    transition: border-color 0.12s;
    appearance: textfield;
    -moz-appearance: textfield;
}

.kpdf-page-input::-webkit-inner-spin-button,
.kpdf-page-input::-webkit-outer-spin-button { display: none; }

.kpdf-page-input:focus {
    border-color: #475569;
    outline: none;
    box-shadow: none;
}

.kpdf-page-sep {
    color: var(--kpdf-text-muted);
    font-size: 12px;
    opacity: 0.5;
}

.kpdf-page-total {
    font-size: 13px;
    font-weight: 500;
    color: var(--kpdf-text-muted);
    min-width: 16px;
    text-align: center;
}

/* ── Zoom value display ─────────────────────────────────────────────────────── */

.kpdf-zoom-val {
    font-size: 12px;
    font-weight: 600;
    color: var(--kpdf-text-muted);
    min-width: 42px;
    text-align: center;
    letter-spacing: 0.01em;
    pointer-events: none;
}

/* ── Fullscreen button with text ────────────────────────────────────────────── */

.kpdf-btn-fs.kpdf-btn-fs {
    width: auto;
    padding: 0 10px;
    gap: 5px;
    color: var(--kpdf-text);
}

.kpdf-btn-fs-label {
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
}

/* Hide text label on small screens */
@media (max-width: 480px) {
    .kpdf-btn-fs-label { display: none; }
    .kpdf-btn-fs.kpdf-btn-fs { width: 34px; padding: 0; }
    .kpdf-zoom-val { display: none; }
}

/* ── Search panel ───────────────────────────────────────────────────────────── */

.kpdf-search {
    background: var(--kpdf-search-bg);
    border-top: 1px solid rgba(0,0,0,0.07);
    padding: 6px 10px;
    z-index: 9;
}

.kpdf-search-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 500px;
    margin: 0 auto;
}

.kpdf-search-input {
    flex: 1;
    height: 32px;
    padding: 0 10px;
    border: 1px solid #d1d5db;
    border-radius: var(--kpdf-radius-sm);
    background: #f9fafb;
    color: #1e293b;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.12s;
}

.kpdf-search-input::placeholder { color: #9ca3af; }

.kpdf-search-input:focus,
.kpdf-search-input:focus-visible {
    border-color: #1e293b;
    box-shadow: none;
    outline: 2px solid #1e293b;
    outline-offset: -1px;
    background: #fff;
}

/* Search highlight — only the exact matched word */
.kpdf-text-layer mark.kpdf-highlight {
    background: rgba(250, 204, 21, 0.45);
    color: transparent;
    border-radius: 2px;
    padding: 2px 0;
}

.kpdf-search-count {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    font-weight: 500;
    min-width: 80px;
}

.kpdf-search-prev,
.kpdf-search-next,
.kpdf-search-close {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}

/* ── Error state ────────────────────────────────────────────────────────────── */

.kpdf-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2em;
    color: #dc2626;
    background: rgba(220,38,38,0.05);
    border: 1px solid rgba(220,38,38,0.15);
    border-radius: var(--kpdf-radius-sm);
    margin: 1em 0;
    font-size: 13px;
}

/* ── Fullscreen overlay (position:fixed) ────────────────────────────────────── */

.kpdf-fs-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

.kpdf-fs-canvas-wrap {
    flex: 1;
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    position: relative;
}

/* Border on the PDF page in fullscreen */
.kpdf-fs-canvas-wrap .kpdf-canvas-inner {
    border: 1px solid #000;
}

/* In fullscreen, canvas size is set by JS */

/* Fullscreen toolbar at bottom */
.kpdf-fs-toolbar.kpdf-fs-toolbar {
    flex-shrink: 0;
    width: 100%;
    background: rgba(255,255,255,0.95);
    border-top: 1px solid #e5e7eb;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Close button corner — hidden, "Salir" is in the toolbar */
.kpdf-fs-close { display: none; }

/* Fullscreen exit button — visible and prominent */
.kpdf-fs-exit-btn.kpdf-fs-exit-btn {
    background: #1e293b;
    color: #fff;
    border-radius: 6px;
    padding: 0 14px;
    height: 36px;
    gap: 6px;
    width: auto;
    margin-left: 8px;
}
.kpdf-fs-exit-btn.kpdf-fs-exit-btn:hover {
    background: #334155;
}
.kpdf-fs-exit-btn .kpdf-btn-fs-label {
    color: #fff;
}

/* Prevent body scroll when overlay is open */
body.kpdf-no-scroll {
    overflow: hidden;
}

/* ── Security: hidden elements ──────────────────────────────────────────────── */

/* Secure badge — never shown to users */
.kpdf-secure-badge { display: none !important; }

/* Mobile button — fullscreen is in toolbar, this is unused */
.kpdf-mobile-btn { display: none !important; }

/* ── Anti-screenshot ────────────────────────────────────────────────────────── */

.kpdf-screenshot-shield { display: none; }

.kpdf-anti-ss .kpdf-screenshot-shield {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    mix-blend-mode: difference;
    background: rgba(0,0,0,0.001);
}

.kpdf-ss-flash .kpdf-canvas {
    filter: brightness(0) !important;
    transition: filter 0.1s;
}

.kpdf-blurred .kpdf-canvas {
    filter: blur(20px);
    transition: filter 0.15s;
}

.kpdf-anti-ss .kpdf-canvas {
    -webkit-user-drag: none;
    user-select: none;
}

/* ── Utility ────────────────────────────────────────────────────────────────── */

.kpdf-hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */

/* Tablet and below */
@media (max-width: 768px) {
    .kpdf-toolbar { padding: 0 8px; height: 48px; }
    .kpdf-btn-icon { width: 44px; height: 44px; }
    .kpdf-search-prev,
    .kpdf-search-next,
    .kpdf-search-close { width: 44px; height: 44px; }
    .kpdf-page-nav { padding: 0 6px; height: 32px; }
    .kpdf-thumbs { width: 90px; min-width: 90px; }
    .kpdf-fs-canvas-wrap { padding: 8px; }
    .kpdf-search-inner {
        max-width: 100%;
        flex-wrap: wrap;
    }
    .kpdf-search-input {
        flex: 1 1 100%;
        min-width: 0;
    }
    .kpdf-search-count {
        flex: 1 1 auto;
        min-width: 60px;
    }
}

/* Phone */
@media (max-width: 480px) {
    .kpdf-toolbar { padding: 0 4px; }
    .kpdf-page-input { width: 28px; font-size: 12px; }
    .kpdf-page-total, .kpdf-page-sep { font-size: 11px; }
    .kpdf-zoom-val { display: none; }
    .kpdf-tb-divider { margin: 0 1px; }
    .kpdf-fs-close { top: 8px; right: 8px; width: 44px; height: 44px; }
    .kpdf-canvas-wrap { border: none; }
    .kpdf-search { padding: 8px; }
    .kpdf-search-input { height: 40px; font-size: 15px; }
}

@media (max-width: 380px) {
    .kpdf-tb-divider { display: none; }
}

/* ── Print ──────────────────────────────────────────────────────────────────── */

@media print {
    .kpdf-toolbar,
    .kpdf-search,
    .kpdf-thumbs,
    .kpdf-mobile-btn,
    .kpdf-fs-close {
        display: none !important;
    }
    .kpdf-container { background: transparent !important; }
    .kpdf-canvas { width: 100% !important; }
}

/* ── Reduced motion ─────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .kpdf-loader-ring { animation-duration: 2s; }
    .kpdf-btn-icon { transition: none; }
    .kpdf-thumb { transition: none; }
}
