:root {
    --primary-color: #1a1a1a;
    --secondary-color: #e74c3c;
    /* Red accent */
    --accent-color: #3498db;
    --bg-color: #e9ecef;
    --panel-bg: #ffffff;
    --text-color: #333;
    --border-color: #ddd;
    --header-height: 80px;
    --toolbar-height: 60px;
    --sidebar-width: 250px;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    /* Window scroll enabled */
}

/* Header */
.main-header {
    background: #fff;
    height: var(--header-height);
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    z-index: 1000;
}

.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 20px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.logo-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-text h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.logo-text span {
    font-size: 1rem;
    color: var(--secondary-color);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.main-nav {
    display: flex;
    gap: 25px;
}

.nav-link {
    text-decoration: none;
    color: #555;
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link:hover {
    color: var(--secondary-color);
}

.admin-btn {
    background: var(--primary-color);
    color: #fff !important;
    padding: 8px 16px;
    border-radius: 4px;
}

/* Toolbar */
.toolbar-wrapper {
    background: #fff;
    height: var(--toolbar-height);
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    z-index: 900;
}

.toolbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-tool {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-tool:hover {
    background: #f8f9fa;
    border-color: #bbb;
    color: var(--primary-color);
}

.btn-clip {
    color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-clip:hover {
    background: var(--secondary-color);
    color: #fff;
}

/* Pagination */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8f9fa;
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid #eee;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8f9fa;
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid #eee;
    margin-left: 15px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
}

.btn-icon:hover {
    transform: scale(1.1);
    color: var(--primary-color);
}

#page-num-display,
#zoom-level {
    font-weight: 700;
    min-width: 60px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
}

.page-select {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    position: relative;
    /* Allow sidebar sticky to work */
    align-items: flex-start;
}

/* Sidebar */
.sidebar-thumbnails {
    width: var(--sidebar-width);
    background: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 800;

    /* Sticky Positioning */
    position: sticky;
    top: 0;
    height: 100vh;
    /* Occupy full viewport height */
    overflow-y: auto;
    /* Internal scroll for thumbnails */
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
    background: #fdfdfd;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar-header h3 {
    font-size: 1rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 1px;
}

.thumbnails-grid {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.thumb-item {
    cursor: pointer;
    border: 3px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    transition: all 0.2s;
    background: #eee;
    flex-shrink: 0;
}

.thumb-item:hover {
    border-color: #ddd;
    transform: translateY(-2px);
}

.thumb-item.active {
    border-color: var(--secondary-color);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.2);
}

.thumb-item canvas {
    display: block;
    width: 100%;
    height: auto;
}

.thumb-label {
    position: absolute;
    bottom: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 3px 8px;
    font-size: 0.75rem;
    border-top-left-radius: 4px;
}

/* Viewer Area */
.viewer-area {
    flex: 1;
    position: relative;
    background: #525659;
    /* Standard PDF viewer bg */
    display: flex;
    /* Use overflow: auto to allow generic scrolling */
    overflow: auto;
}

.viewer-area:fullscreen {
    padding: 0;
    /* Remove padding to avoid jump */
    background: #525659;
    display: flex;
    justify-content: center;
    overflow: auto;
    align-items: center;
    /* Center vertically if zoom is small */
}

/* Hide FS controls by default */
.fullscreen-controls {
    display: none;
}

/* Show FS controls in fullscreen */
.viewer-area:fullscreen .fullscreen-controls {
    display: block;
    position: fixed;
    /* Fixed relative to screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas/scrolling */
    z-index: 1000;
}

.btn-fs-action {
    pointer-events: auto;
    /* Re-enable clicks for buttons */
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    font-size: 1.2rem;
}

.btn-fs-action:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.btn-fs-close {
    position: absolute;
    top: 20px;
    right: 20px;
}

.fs-nav-wrapper {
    position: absolute;
    top: 50%;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    transform: translateY(-50%);
}

.pdf-container {
    /* Use margin: auto to center when smaller than viewport,
       and align purely top-left when larger (allowing scroll) */
    margin: 20px auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    position: relative;
    /* For Cropper absolute positioning if needed */
    height: fit-content;
    width: fit-content;
    /* Ensure it takes necessary width */
    flex-shrink: 0;
    /* Prevent shrinking */
}

.pdf-viewer {
    background: #fff;
    line-height: 0;
    /* Remove gap under canvas */
}

#pdf-canvas {
    display: block;
    /* Ensure it behaves as a block */
}

/* Cropper Overlay */
.crop-overlay-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    /* Transparent to show image */
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.cropper-controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 10px 20px;
    border-radius: 50px;
    display: flex;
    gap: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.btn-crop-action {
    border: none;
    padding: 10px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.confirm {
    background: var(--secondary-color);
    color: #fff;
}

.cancel {
    background: #eee;
    color: #333;
}

/* Share Floating Sidebar */
.share-sidebar {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    display: flex;
    flex-direction: column;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 100;
    gap: 10px;
}

/* Hide Share Sidebar in Fullscreen to prevent overlap */
.viewer-area:fullscreen .share-sidebar {
    display: none;
}

.share-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: #fff;
    font-size: 1.2rem;
    text-decoration: none;
    transition: transform 0.2s;
}

.share-icon:hover {
    transform: translateX(-3px);
}

.facebook {
    background: #3b5998;
}

.x-twitter {
    background: #000;
    color: #fff;
}

.whatsapp {
    background: #25d366;
}

.telegram {
    background: #0088cc;
}

.tiktok {
    background: #010101;
}

.print {
    background: #7f8c8d;
}

.email {
    background: #ea4335;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #eee;
    border-top-color: var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Footer */
.main-footer {
    background: #222;
    color: #fff;
    padding: 10px 0;
    text-align: center;
    font-size: 0.85rem;
    z-index: 1000;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    position: relative;
    text-align: center;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #888;
}

.clip-result-container {
    margin: 20px 0;
    border: 1px solid #eee;
    padding: 10px;
    background: #f9f9f9;
    max-height: 400px;
    overflow: auto;
}

.clip-result-container img {
    max-width: 100%;
    height: auto;
}

.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.btn-action {
    display: inline-block;
    background: var(--primary-color);
    color: #fff;
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
}

.share-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.share-btn {
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    text-decoration: none;
}

.share-btn.fb {
    background: #3b5998;
}

.share-btn.tw {
    background: #1da1f2;
}

.share-btn.wa {
    background: #25d366;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar-thumbnails {
        display: none;
    }

    .toolbar-left,
    .toolbar-right {
        gap: 8px;
    }

    .logo-text h1 {
        font-size: 1.2rem;
    }

    .logo-text span {
        font-size: 0.8rem;
    }

    .share-sidebar {
        display: none;
    }

    /* Hide share sidebar on mobile */

    .main-nav {
        display: none;
    }

    /* Simplified mobile handling */
}