/* --- Root Variables & Reset --- */
:root {
    --primary-color: #e74c3c;
    --primary-hover: #c0392b;
    --bg-light: #f4f7f6;
    --card-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

body {
    background-color: var(--bg-light);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #333;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* --- Layout Containers --- */
.container {
    max-width: 1000px;
    padding: 15px;
}

/* --- Upload Zone (Responsive) --- */
.upload-zone {
    border: 2px dashed #bdc3c7;
    border-radius: 12px;
    padding: 30px 15px;
    text-align: center;
    background: white;
    transition: all 0.3s ease;
    cursor: pointer;
    margin-bottom: 20px;
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background-color: #fff9f8;
}

.upload-zone i {
    color: #95a5a6;
    margin-bottom: 10px;
}

/* --- File Grid System --- */
#file-grid {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -8px; 
}

/* Page Card Styling */
.file-card {
    padding: 8px;
    /* Default: 2 columns on small mobile */
    flex: 0 0 50%;
    max-width: 50%;
}

@media (min-width: 576px) {
    .file-card { flex: 0 0 33.33%; max-width: 33.33%; } /* 3 cols */
}

@media (min-width: 992px) {
    .file-card { flex: 0 0 20%; max-width: 20%; } /* 5 cols */
}

.file-card .card {
    border: none;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    overflow: hidden;
    height: 100%;
    background: #fff;
}

/* --- Thumbnail Logic (Updated Fix) --- */
.thumbnail-wrapper {
    position: relative;
    width: 100%;
    padding-top: 130%; /* Maintains Portrait Ratio */
    background: #fdfdfd;
    border-bottom: 1px solid #eee;
    
    /* ADD THESE: Use flex to center the child naturally */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; 
}

.thumbnail-wrapper img {
    /* REMOVE top: 50%, left: 50%, and translate(-50%, -50%) */
    position: absolute; 
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto; /* This centers absolute elements inside flex/relative */
    
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center center; /* Forces rotation around the exact middle */
}

.page-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: bold;
    z-index: 10;
}

/* --- Control Buttons --- */
.card-body .btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

/* --- PDF Preview Frame --- */
#pdfPreviewContainer {
    margin-top: 20px;
}

#pdfFrame {
    width: 100%;
    height: 80vh; /* Uses 80% of screen height */
    border-radius: 0 0 10px 10px;
}

/* --- Sorting States --- */
.card.sorting {
    opacity: 0.4;
    transform: scale(0.95);
    border: 2px solid var(--primary-color);
}

/* --- Animations --- */
.animate-in {
    animation: fadeInUp 0.4s ease forwards;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Mobile Specific Fixes --- */
@media (max-width: 480px) {
    .upload-zone h4 { font-size: 1.1rem; }
    .upload-zone p { font-size: 0.85rem; }
    
    /* Make buttons slightly larger for thumbs on mobile */
    .card-body .btn {
        padding: 8px 10px;
    }
    
    #pdfFrame {
        height: 500px;
    }

    /* Prevent text clipping in cards */
    .card-body p {
        font-size: 11px;
    }
}

.custom-alert {
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}