/* Base styles for body and layout */
body {
    font-family: 'Inter', sans-serif;
    background-color: #f3f4f6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    color: #374151;
}

/* Header styling */
header {
    background-color: #3b82f6;
    background-image: linear-gradient(to right, #3b82f6, #8b5cf6);
    color: white;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header a {
    color: white;
    text-decoration: none;
    font-weight: 600;
}

/* Main content container */
.main-container {
    flex-grow: 1;
    max-width: 1200px;
    margin: 2rem auto;
    padding: 1.5rem;
    background-color: #ffffff;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

/* Message box styling */
.message-box {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-top: 1rem;
    display: none;
    font-size: 0.9rem;
    font-weight: 500;
    width: 100%;
    text-align: center;
}

.message-box.active {
    display: block;
}

.message-box.warning {
    background-color: #fefcbf;
    border: 1px solid #fcd34d;
    color: #92400e;
}

.message-box.error {
    background-color: #fee2e2;
    border: 1px solid #f87171;
    color: #991b1b;
}

.message-box.success {
    background-color: #d1fae5;
    border: 1px solid #34d399;
    color: #065f46;
}

.message-box.info {
    background-color: #e0f2fe;
    border: 1px solid #93c5fd;
    color: #1e40af;
}

/* File input and buttons */
.file-input-group {
    position: relative;
    overflow: hidden;
    display: inline-block;
}

.file-input-group input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.btn-primary {
    background-color: #3b82f6;
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    border: none;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-primary:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.btn-download {
    background-color: #10b981;
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 9999px;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    border: none;
}

.btn-download:hover {
    background-color: #059669;
}

/* Select element styling */
select {
    background-color: #ffffff;
    border: 1px solid #cbd5e0;
    padding: 0.4rem 0.6rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    line-height: 1;
    min-width: 30px;
    min-height: 30px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>');
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 0.8rem;
    padding-right: 1.8rem;
}

select:hover {
    background-color: #e2e8f0;
    border-color: #a0aec0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Loading Overlay copied from image-resizer.html */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Core Layout: Controls and Previews */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 2fr; /* Controls on left, Previews on right */
    gap: 1.5rem;
    width: 100%;
    flex-grow: 1; /* Allow content to fill remaining space */
}

@media (max-width: 1024px) { /* Adjust for smaller screens */
    .content-grid {
        grid-template-columns: 1fr; /* Stack columns on smaller screens */
    }
}

#controlsContainer {
    min-width: 300px; /* Ensure controls don't shrink too much */
    max-width: 100%; /* Prevent overflow on small screens */
}

#previewsPanel {
    display: flex;
    flex-direction: column;
    background-color: #f9fafb;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px dashed #d1d5db;
    min-height: 200px;
}

/* Preview Grid Container */
#previewsContainer {
    display: grid; /* THIS IS THE KEY */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); /* Responsive grid columns */
    gap: 0.75rem;
    max-height: 500px; /* Fixed height for scrolling */
    overflow-y: auto; /* Enable vertical scrolling */
    padding-right: 0.5rem; /* Space for scrollbar */
    flex-grow: 1; /* Allow grid to expand within panel */
    align-items: start; /* Align items to the start of their grid cell */
}

/* Individual Preview Card */
.preview-card {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background-color: #ffffff;
    padding: 0.75rem;
    display: flex; /* Use flexbox for internal layout of card content */
    flex-direction: column;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
    cursor: pointer;
    height: 100%; /* Important: Make card fill its grid cell height */
    justify-content: space-between; /* Distribute content vertically within card */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
}

.preview-card.selected {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.preview-card img {
    max-width: 100%;
    max-height: 90px; /* Consistent image height for all cards */
    object-fit: contain;
    margin-bottom: 0.5rem;
    border: 1px solid #eee;
    background-color: #f0f0f0;
    flex-shrink: 0; /* Prevent image from shrinking if content is long */
}

.preview-card .file-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
    text-align: center;
    word-break: break-all;
    line-height: 1.2;
    margin-bottom: 0.25rem;
    flex-grow: 1; /* Allow name to take available space */
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines for long names */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%; /* Ensure text stretches to card width if needed */
}

.preview-card .file-details {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    flex-shrink: 0; /* Prevent details from shrinking */
    width: 100%; /* Ensure text stretches to card width if needed */
}

.file-checkbox {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    transform: scale(1.1);
    z-index: 10;
}

/* Bulk Actions Bar */
#bulkActionsBar {
    background-color: #f0f4f8;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem; /* Space between upload and controls */
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

#bulkActionsBar .left-group,
#bulkActionsBar .right-group {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on small screens */
}

#bulkActionsBar .btn-primary {
    padding: 0.5rem 1rem; /* Smaller buttons for control bar */
    font-size: 0.9rem;
}
