/* ============================================================================
   PDF Thumbnail Grid Styles
   For visual page selection, drag-drop reordering, and page manipulation
   ============================================================================ */

/* Thumbnail Grid Container */
.pdf-thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 20px;
    max-width: 100%;
    min-height: 200px;
}

/* Individual Page Thumbnail */
.pdf-page-thumbnail {
    background: #ffffff; /* light mode */
    border-radius: 12px;
    padding: 12px;
    border: 2px solid rgba(0,0,0,.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: default;
}

[data-theme="dark"] .pdf-page-thumbnail {
    background: linear-gradient(135deg, rgba(15,23,42,0.75), rgba(30,41,59,0.55));
    border: 2px solid rgba(148,163,184,.2);
}

.pdf-page-thumbnail:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.4);
    border-color: #0ea5e9;
}

/* Thumbnail Wrapper */
.thumbnail-wrapper {
    position: relative;
    width: 100%;
}

/* Thumbnail Image */
.thumbnail-image {
    width: 100%;
    height: 220px;
    object-fit: contain;
    background: white;
    border-radius: 8px;
    transition: transform 0.3s ease;
    display: block;
}

/* Page Number Badge */
.page-number-badge {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white;
    padding: 6px 14px;
    border-radius: 16px;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
    z-index: 5;
}

/* Selection Checkbox */
.page-checkbox {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #0ea5e9;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-checkbox:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.5);
}

.page-checkbox.checked {
    background: #0ea5e9;
    border-color: #0ea5e9;
}

.page-checkbox.checked::after {
    content: '✓';
    color: white;
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
}

/* Selected Thumbnail */
.pdf-page-thumbnail.selected {
    border-color: #0ea5e9;
    border-width: 3px;
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.3);
}

/* Drag Handle */
.drag-handle {
    position: absolute;
    top: 12px;
    right: 12px;
    color: rgba(255,255,255,0.9);
    font-size: 20px;
    cursor: grab;
    background: rgba(0,0,0,0.6);
    padding: 8px 10px;
    border-radius: 8px;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.pdf-page-thumbnail:hover .drag-handle {
    opacity: 1;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Rotation Controls */
.rotation-controls {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.pdf-page-thumbnail:hover .rotation-controls {
    opacity: 1;
}

.rotate-btn {
    flex: 1;
    padding: 10px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border: none;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s ease;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.rotate-btn:hover {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.5);
}

.rotate-btn:active {
    transform: scale(0.98);
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #dc3545, #c82333);
    border: none;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.pdf-page-thumbnail:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: linear-gradient(135deg, #c82333, #bd2130);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.5);
}

/* Drag States (for Sortable.js) */
.thumbnail-ghost {
    opacity: 0.3;
    background: rgba(14, 165, 233, 0.2);
}

.thumbnail-chosen {
    transform: scale(1.08);
    box-shadow: 0 16px 32px rgba(0,0,0,0.5);
    border-color: #0ea5e9;
    z-index: 1000;
}

.thumbnail-drag {
    transform: rotate(4deg) scale(1.05);
    opacity: 0.9;
}

/* Selection Toolbar */
.selection-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 20px;
    background: #f8f9fa; /* light mode */
    border-radius: 10px;
    margin-bottom: 24px;
    border: 1px solid rgba(0,0,0,.1);
}

[data-theme="dark"] .selection-toolbar {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(148,163,184,.25);
}

.selection-toolbar button {
    padding: 10px 20px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.selection-toolbar button:hover {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.5);
}

.selection-toolbar button:active {
    transform: translateY(0);
}

.selection-count,
#selectionCount {
    margin-left: auto;
    color: #0ea5e9;
    font-weight: 700;
    font-size: 15px;
    padding: 8px 16px;
    background: rgba(14, 165, 233, 0.1);
    border-radius: 8px;
}

/* Organize Toolbar */
.organize-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 20px;
    background: #f8f9fa; /* light mode */
    border-radius: 10px;
    margin-bottom: 24px;
    border: 1px solid rgba(0,0,0,.1);
}

[data-theme="dark"] .organize-toolbar {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(148,163,184,.25);
}

.organize-toolbar button {
    padding: 10px 20px;
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
    border: 2px solid rgba(14, 165, 233, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
}

.organize-toolbar button:hover {
    background: rgba(14, 165, 233, 0.25);
    border-color: #0ea5e9;
    transform: translateY(-2px);
}

#pageOrderInfo {
    margin-left: auto;
    color: #6c757d; /* light mode */
    font-size: 14px;
}

[data-theme="dark"] #pageOrderInfo {
    color: rgba(229, 231, 235, 0.8);
}

/* Rotation Toolbar */
.rotation-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 20px;
    background: #f8f9fa; /* light mode */
    border-radius: 10px;
    margin-bottom: 24px;
    border: 1px solid rgba(0,0,0,.1);
}

[data-theme="dark"] .rotation-toolbar {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(148,163,184,.25);
}

.rotation-toolbar button {
    padding: 10px 20px;
    background: rgba(14, 165, 233, 0.15);
    color: #0ea5e9;
    border: 2px solid rgba(14, 165, 233, 0.3);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
}

.rotation-toolbar button:hover {
    background: rgba(14, 165, 233, 0.25);
    border-color: #0ea5e9;
}

#rotationInfo {
    margin-left: auto;
    color: #6c757d; /* light mode */
    font-size: 14px;
}

[data-theme="dark"] #rotationInfo {
    color: rgba(229, 231, 235, 0.8);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 80px 40px;
    color: #6c757d; /* light mode */
    grid-column: 1 / -1;
}

[data-theme="dark"] .empty-state {
    color: #ffffff !important; /* white in dark mode instead of gray */
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
    margin: 0;
}

/* Loading Spinner */
.loading-spinner {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #6c757d; /* light mode */
}

[data-theme="dark"] .loading-spinner {
    color: rgba(229, 231, 235, 0.7);
}

.loading-spinner i {
    color: #0ea5e9;
    margin-bottom: 16px;
}

.loading-spinner p {
    font-size: 15px;
    margin-top: 12px;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .pdf-thumbnail-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 16px;
    }
}

@media (max-width: 768px) {
    .pdf-thumbnail-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        padding: 12px;
    }
    
    .thumbnail-image {
        height: 180px;
    }
    
    .selection-toolbar,
    .organize-toolbar,
    .rotation-toolbar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }
    
    .selection-toolbar button,
    .organize-toolbar button,
    .rotation-toolbar button {
        font-size: 13px;
        padding: 8px 14px;
    }
    
    /* Mobile-optimized drag handle */
    .drag-handle {
        font-size: 18px;
        padding: 6px 8px;
    }
    
    /* Larger touch targets for mobile */
    .page-checkbox {
        width: 36px;
        height: 36px;
    }
    
    .delete-btn {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 480px) {
    .pdf-thumbnail-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .page-number-badge {
        font-size: 11px;
        padding: 4px 10px;
    }
    
    .rotate-btn {
        font-size: 13px;
        padding: 8px;
    }
    
    /* Stack toolbar buttons vertically on very small screens */
    .selection-toolbar,
    .organize-toolbar,
    .rotation-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .selection-toolbar button,
    .organize-toolbar button,
    .rotation-toolbar button {
        width: 100%;
    }
    
    .selection-count,
    #selectionCount,
    #pageOrderInfo,
    #rotationInfo {
        margin-left: 0;
        text-align: center;
        margin-top: 8px;
    }
    
    /* Optimize thumbnail display for small screens */
    .pdf-page-thumbnail {
        padding: 8px;
    }
    
    .thumbnail-image {
        height: 160px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .thumbnail-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Always show controls on touch devices */
    .drag-handle,
    .rotation-controls,
    .delete-btn {
        opacity: 1 !important;
    }
    
    /* Larger touch targets */
    .pdf-page-thumbnail {
        min-height: 180px;
    }
    
    .page-checkbox {
        width: 40px;
        height: 40px;
    }
    
    .rotate-btn {
        padding: 12px;
        font-size: 16px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pdf-page-thumbnail {
    animation: fadeIn 0.3s ease-out;
}

.pdf-page-thumbnail:nth-child(1) { animation-delay: 0.05s; }
.pdf-page-thumbnail:nth-child(2) { animation-delay: 0.1s; }
.pdf-page-thumbnail:nth-child(3) { animation-delay: 0.15s; }
.pdf-page-thumbnail:nth-child(4) { animation-delay: 0.2s; }
.pdf-page-thumbnail:nth-child(5) { animation-delay: 0.25s; }

/* Accessibility */
.page-checkbox:focus,
.rotate-btn:focus,
.delete-btn:focus {
    outline: 3px solid #0ea5e9;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .pdf-thumbnail-grid {
        display: none;
    }
}

/* Dark Mode Support - Now handled by data-theme attribute */

