/* 1. Global Reset & Fonts */
.cpdfv-root * { box-sizing: border-box; margin: 0; padding: 0; }

.cpdfv-root {
    --cpdfv-sidebar-w: 240px;
    --cpdfv-toolbar-h: 52px;
    --cpdfv-bg: #f4f5f7;
    --cpdfv-surface: #ffffff;
    --cpdfv-surface-2: #edeef1;
    --cpdfv-border: rgba(0,0,0,0.07);
    --cpdfv-text: #1a1c24;
    --cpdfv-text-muted: #6b6f7e;
    --cpdfv-accent: #4f7df3;

    font-family: inherit;
    background: var(--cpdfv-bg);
    color: var(--cpdfv-text);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--cpdfv-border);
    border-radius: 8px;
    height: 80vh; /* Default height */
    min-height: 400px;
}

/* Dark Theme */
.cpdfv-dark {
    --cpdfv-bg: #0f1117;
    --cpdfv-surface: #181a22;
    --cpdfv-surface-2: #22252f;
    --cpdfv-border: rgba(255,255,255,0.06);
    --cpdfv-text: #e8e9ed;
    --cpdfv-text-muted: #8a8d9b;
}

/* --- FULLSCREEN FIX --- */
div.cpdfv-root.fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
    background: #e5e5e5;
    top: 0;
    left: 0;
}

/* 2. Toolbar Layout */
.cpdfv-toolbar {
    height: var(--cpdfv-toolbar-h);
    background: var(--cpdfv-surface);
    border-bottom: 1px solid var(--cpdfv-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 20;
}

.cpdfv-toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cpdfv-btn {
    width: 34px;
    height: 34px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--cpdfv-text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.cpdfv-btn:hover, .cpdfv-btn.active {
    background: var(--cpdfv-surface-2);
    color: var(--cpdfv-text);
}

.cpdfv-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Page Number Input */
.cpdfv-page-input {
    width: 40px;
    height: 28px;
    text-align: center;
    border: 1px solid var(--cpdfv-border);
    border-radius: 4px;
    background: var(--cpdfv-bg);
    color: var(--cpdfv-text);
    font-size: 14px;
}

/* --- SEARCH BAR HORIZONTAL FIX --- */
.cpdfv-search-bar {
    display: none;
    align-items: center;
    gap: 8px; /* Spaces out input, arrows, and X horizontally */
    background: var(--cpdfv-surface-2);
    padding: 4px 8px;
    border-radius: 6px;
    margin-left: 8px;
}
.cpdfv-search-bar.open {
    display: flex; /* Forces items into a row */
}
.cpdfv-search-input {
    border: 1px solid var(--cpdfv-border);
    background: var(--cpdfv-surface);
    color: var(--cpdfv-text);
    padding: 4px 8px;
    border-radius: 4px;
    width: 150px;
}

/* 3. Main Body & Sidebar (Fixes the "All Pages on Screen" issue) */
.cpdfv-body {
    display: flex; /* Prevents vertical stacking of sidebar and canvas */
    flex: 1;
    overflow: hidden;
    position: relative;
}

.cpdfv-sidebar {
    width: var(--cpdfv-sidebar-w);
    background: var(--cpdfv-surface);
    border-right: 1px solid var(--cpdfv-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 10;
}
.cpdfv-sidebar.open {
    transform: translateX(0);
    position: relative; /* Pushes the canvas to the right when open */
}

/* Thumbnails */
/* Replace .cpdfv-thumbs with the data attribute selector */
[data-el="thumbs"] {
    flex: 1 1 0%;      /* Forces the container to absorb exact remaining space */
    min-height: 0;     /* Overrides the flexbox 'auto' height protection */
    overflow-y: auto;  /* Triggers the scrollbar */
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* You will also need to update the thumbnail item selectors if they are missing classes */
[data-el="thumbs"] > div {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    padding: 4px;
    text-align: center;
    background: var(--cpdfv-bg);
}

[data-el="thumbs"] > div.active {
    border-color: var(--cpdfv-accent);
}

[data-el="thumbs"] canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.cpdfv-thumb-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    padding: 4px;
    text-align: center;
    background: var(--cpdfv-bg);
}
.cpdfv-thumb-item.active { border-color: var(--cpdfv-accent); }
.cpdfv-thumb-item canvas { max-width: 100%; height: auto; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.cpdfv-thumb-label { display: block; font-size: 12px; margin-top: 4px; color: var(--cpdfv-text-muted); }

/* Main Canvas Area */
.cpdfv-canvas-wrap {
    flex: 1;
    overflow: auto;
    padding: 24px;
    background: var(--cpdfv-bg);
    display: flex;
    justify-content: center;
    align-items: flex-start;
}
.cpdfv-canvas-wrap canvas {
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    background: #fff;
}

/* Loader / Error */
.cpdfv-loader, .cpdfv-error {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--cpdfv-bg);
    z-index: 30;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.cpdfv-loader.active, .cpdfv-error.active { display: flex; }

/* 4. Status Bar (Footer) */
.cpdfv-status {
    height: 32px;
    background: var(--cpdfv-surface-2);
    border-top: 1px solid var(--cpdfv-border);
    display: flex;
    align-items: center;
    justify-content: space-between; /* Pushes 'Loaded' left and '3 pages' right */
    padding: 0 16px;
    font-size: 13px;
    color: var(--cpdfv-text-muted);
    z-index: 20;
}

/* Optional: If they are right next to each other on the left instead of split */
.cpdfv-status-group {
    display: flex;
    align-items: center;
    gap: 12px; /* Adds space if they are in the same flex group */
}

/* --- CONTINUOUS SCROLL BULLETPROOF FIX --- */

/* 1. Prevent the wrapper from using Flexbox centering */
div.cpdfv-root .cpdfv-continuous-wrap {
    display: block;
    text-align: center;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 0;
    align-items: normal;
    justify-content: normal;
}

/* 2. Force canvases to stack vertically and maintain aspect ratio */
div.cpdfv-root .cpdfv-continuous-wrap canvas.cpdfv-cont-page {
    position: relative;
    display: block;
    margin: 0 auto 20px auto;
    top: auto;
    left: auto;
    transform: none;
    /* !important is used here specifically to override the PDF engine's inline style stretch */
    max-width: 100% !important; 
    height: auto !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* --- FULLSCREEN CONTINUOUS FIXES --- */

/* 1. Ensure the root acts as a strict column in fullscreen */
div.cpdfv-root.fullscreen {
    display: flex;
    flex-direction: column;
    background: #e5e5e5;
}

/* 2. Force the toolbar and paging controls to stay visible */
div.cpdfv-root.fullscreen .cpdfv-toolbar,
div.cpdfv-root.fullscreen .cpdfv-page-nav {
    display: flex;
}

/* 3. Ensure the body takes up the rest of the screen without overflowing */
div.cpdfv-root.fullscreen .cpdfv-body {
    flex-grow: 1;
    height: auto;
    min-height: 0;
}

/* 4. Force the continuous wrapper to handle the scrolling */
div.cpdfv-root.fullscreen .cpdfv-continuous-wrap {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
/* --- DISABLED BUTTON STATES --- */
div.cpdfv-root .cpdfv-btn:disabled,
div.cpdfv-root .cpdfv-btn[disabled] {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* --- SEARCH BAR SIZING FIX --- */

/* Target the wrapper using its exact data attribute */
div.cpdfv-root [data-el="searchBar"] {
    gap: 8px;
    display: flex;
}

/* Target the input field using its exact data attribute */
div.cpdfv-root [data-el="searchInput"] {
    width: 240px;
    min-width: 200px;
    padding: 6px 12px;
    font-size: 14px;
}

/* Mobile Optimization */
@media (max-width: 650px) {
    div.cpdfv-root .cpdfv-toolbar {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        height: auto;
        padding: 8px 5px;
        gap: 5px;
    }

    div.cpdfv-root .cpdfv-toolbar .cpdfv-sep,
    div.cpdfv-root .cpdfv-toolbar .cpdfv-spacer,
    div.cpdfv-root .cpdfv-btn[data-action="print"],
    div.cpdfv-root .cpdfv-btn[data-action="sidebar"],
    div.cpdfv-root .cpdfv-btn[data-action="download"] {
        display: none;
    }

    div.cpdfv-root .cpdfv-toolbar .cpdfv-btn {
        flex: 0 0 40px;
        height: 40px;
        margin: 2px;
    }
    div.pv_root .cpdfv-thumbs {
        display: none;
    }
    
    /* This forces the PDF to use the full width in portrait */
    div.pv_root .cpdfv-main { 
        margin-left: 0 !important; 
        margin-right: 0 !important; 
        width: 100% !important; 
    }
}

div.cpdfv-viewer-tip {
    background: var(--cpdfv-surface-2);
    border-bottom: 1px solid var(--cpdfv-border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--cpdfv-text);
}

div.cpdfv-viewer-tip .cpdfv-tip-icon {
    font-size: 16px;
}

div.cpdfv-viewer-tip .cpdfv-tip-text strong {
    color: var(--cpdfv-accent);
    font-weight: 600;
}

/* Hide the tip when in Full Screen to save space if you prefer */
div.cpdfv-root.fullscreen .cpdfv-viewer-tip {
    display: none;
}
.cpdfv-tip-link {
    color: var(--cpdfv-accent);
    text-decoration: underline;
    font-weight: 600;
    cursor: pointer;
}

.cpdfv-tip-link:hover {
    color: var(--cpdfv-text);
}

/* Hide the tip entirely when in fullscreen mode */
:fullscreen .cpdfv-viewer-tip,
:-webkit-full-screen .cpdfv-viewer-tip {
    display: none !important;
    visibility: hidden !important;
}
