/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
    background: #000000;
    color: white;
    border-radius: 12px;
    border: 2px solid #e9ecef;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 20px;
}

/* Section styling */
section {
    background: white;
    margin-bottom: 30px;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #000000;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 10px;
}

/* Upload Section */
.upload-area {
    border: 2px dashed #6c757d;
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: #ffffff;
}

.upload-area:hover, .upload-area.dragover {
    border-color: #000000;
    background: #f8f9fa;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.upload-icon {
    font-size: 48px;
    color: #6c757d;
    margin-bottom: 16px;
}

.upload-placeholder p {
    font-size: 1.1rem;
    color: #495057;
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 0.9rem;
    color: #6c757d;
}

.uploaded-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-top: 20px;
    padding: 20px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.image-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    cursor: grab;
    transition: transform 0.2s ease;
}

.image-item:hover {
    transform: scale(1.05);
}

.image-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.image-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.image-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.image-count {
    margin-top: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    text-align: center;
    font-weight: 600;
    color: #000000;
    border: 1px solid #e9ecef;
}

/* Layout Selection */
.layout-filter {
    margin-bottom: 25px;
    padding: 15px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.layout-filter label {
    display: inline-block;
    margin-right: 10px;
    font-weight: 600;
    color: #000000;
}

.layout-filter select {
    padding: 8px 12px;
    border: 1px solid #6c757d;
    border-radius: 6px;
    font-size: 1rem;
    background: white;
}

.layout-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    min-height: 100px; /* Ensure minimum height */
}

.layout-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 40px;
}

.layout-option {
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #ffffff;
    text-align: center;
    min-height: 120px; /* Ensure minimum height for visibility */
}

.layout-option:hover {
    border-color: #000000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.layout-option.selected {
    border-color: #000000;
    background: #f8f9fa;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.layout-preview {
    width: 100%;
    height: 80px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 10px;
    display: grid;
    gap: 3px;
    padding: 8px;
}

.layout-preview-cell {
    background: #6c757d;
    border-radius: 3px;
    position: relative;
}

.layout-preview-cell.empty {
    background: #e9ecef;
    border: 1px dashed #6c757d;
}

.layout-name {
    font-weight: 600;
    color: #000000;
    font-size: 0.9rem;
}

.layout-description {
    font-size: 0.8rem;
    color: #718096;
    margin-top: 5px;
}

/* Collage Preview */
.preview-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.collage-canvas {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 4/3;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    overflow: hidden;
    position: relative;
}

.canvas-placeholder {
    text-align: center;
    color: #a0aec0;
    font-style: italic;
}

.collage-grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: var(--spacing, 5px);
    padding: var(--spacing, 5px);
}

.collage-cell {
    border-radius: var(--border-radius, 0px);
    overflow: hidden;
    position: relative;
    background: #f7fafc;
    border: 1px dashed #cbd5e0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.collage-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.collage-cell.empty::after {
    content: 'Empty';
    color: #a0aec0;
    font-size: 0.8rem;
}

.preview-controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #000000;
    color: white;
    border: 2px solid #000000;
}

.btn-primary:hover:not(:disabled) {
    background: #333333;
    border-color: #333333;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: 2px solid #6c757d;
}

.btn-secondary:hover:not(:disabled) {
    background: #5a6268;
    border-color: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-outline {
    background: transparent;
    color: #000000;
    border: 2px solid #000000;
}

.btn-outline:hover {
    background: #000000;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Options Section */
.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-group label {
    font-weight: 600;
    color: #000000;
}

.option-group input, .option-group select {
    padding: 8px 12px;
    border: 1px solid #6c757d;
    border-radius: 6px;
    font-size: 1rem;
    background: #ffffff;
}

.option-group input[type="range"] {
    padding: 0;
}

.option-group input[type="color"] {
    width: 60px;
    height: 40px;
    padding: 2px;
    border-radius: 6px;
    border: 1px solid #6c757d;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    section {
        padding: 20px;
    }
    
    .uploaded-images {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }
    
    .layout-options {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
    }
    
    .preview-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    header {
        padding: 20px 0;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    section {
        padding: 15px;
    }
    
    .upload-area {
        padding: 30px 20px;
    }
    
    .uploaded-images {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
    
    .image-item img {
        height: 80px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.btn:focus,
select:focus,
input:focus {
    outline: 2px solid #000000;
    outline-offset: 2px;
}

.layout-option:focus {
    outline: 2px solid #000000;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .upload-area {
        border-color: currentColor;
    }
    
    .layout-option {
        border-color: currentColor;
    }
}

/* Loading state */
.loading {
    position: relative;
    overflow: hidden;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { left: -100%; }
    100% { left: 100%; }
}