.before-after-wrapper {
    position: relative;
    max-width: 100%;
    margin: 20px 0 30px;
}

.before-after-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.before-after-container img {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    pointer-events: none;
}

.before-after-overlay {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    overflow: hidden;
}

/* Ensure BEFORE image fills the container and doesn't scale with overlay width */
.before-after-overlay img {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: auto;
    min-width: 100%;
    object-fit: cover;
}

.before-after-handle {
    position: absolute;
    top: 0;
    left: calc(50% - 22px);
    width: 44px;
    height: 100%;
    cursor: ew-resize;
    display: flex;
    align-items: center;
    justify-content: center;
}

.before-after-divider {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 100%;
    background: rgba(255,255,255,0.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.12), 0 0 12px rgba(0,0,0,0.15);
}

.before-after-knob {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}

/* Chevron arrows on the handle */
.before-after-handle::before,
.before-after-handle::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    border-top: 2px solid #ffffff;
    border-right: 2px solid #ffffff;
}

.before-after-handle::before {
    transform: translateX(-18px) rotate(-135deg);
}

.before-after-handle::after {
    transform: translateX(18px) rotate(45deg);
}

/* Generated result section width control (60-70%) */
.result-images .generated-image {
    max-width: 70%;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 1024px) {
    .result-images .generated-image {
        max-width: 80%;
    }
}

@media (max-width: 640px) {
    .result-images .generated-image {
        max-width: 95%;
    }
}

/* Labels: Before / After */
.ba-label {
    position: absolute;
    top: 10px;
    z-index: 3;
    padding: 6px 10px;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.02em;
    color: #fff;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 14px;
    user-select: none;
    pointer-events: none;
}

.ba-label-before { left: 10px; }
.ba-label-after { right: 10px; }
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.header p {
    font-size: 1.2em;
    opacity: 0.9;
}

.main-content {
    padding: 40px;
}

.upload-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.upload-box {
    border: 2px dashed #e0e0e0;
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    transition: all 0.3s ease;
    background: #fafafa;
    position: relative;
}

.upload-box:hover {
    border-color: #4facfe;
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 172, 254, 0.15);
}

.upload-box.has-image {
    border-color: #4CAF50;
    background: #f8fff8;
}

.upload-box h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3em;
}

.file-input-wrapper {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-input-label {
    display: inline-block;
    padding: 12px 24px;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.file-input-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(79, 172, 254, 0.3);
}

.analyze-btn {
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
    transition: all 0.3s ease;
    font-size: 0.9em;
}

.analyze-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 154, 86, 0.3);
}

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

.image-preview {
    margin-top: 20px;
    position: relative;
}

.preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.remove-image {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.remove-image:hover {
    background: #ff3742;
    transform: scale(1.1);
}

.instruction-section {
    margin-bottom: 30px;
}

.instruction-section label {
    display: block;
    color: #333;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.instruction-textarea {
    width: 100%;
    min-height: 120px;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 14px;
    resize: vertical;
    transition: all 0.3s ease;
    font-family: inherit;
}

.instruction-textarea:focus {
    outline: none;
    border-color: #4facfe;
    box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
}

.instruction-textarea.auto-filled {
    border-color: #4CAF50;
    background: #f8fff8;
}

.generate-section {
    text-align: center;
    margin-bottom: 40px;
}

.generate-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.2em;
    font-weight: 600;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(79, 172, 254, 0.3);
}

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

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.loading-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    margin: 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #4facfe;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    width: 0%;
    transition: width 0.3s ease;
}

.result-section {
    display: none;
    background: #f8fff8;
    border: 2px solid #4CAF50;
    border-radius: 15px;
    padding: 30px;
    margin-top: 40px;
}

.result-section h2 {
    color: #2E7D32;
    margin-bottom: 20px;
    text-align: center;
    font-size: 2em;
}

.result-images {
    text-align: center;
}

.result-image {
    max-width: 100%;
    max-height: 600px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    margin: 20px 0;
}

.download-btn {
    display: inline-block;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    padding: 15px 30px;
    text-decoration: none;
    border-radius: 25px;
    margin: 20px 10px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3);
    text-decoration: none;
    color: white;
}

.restart-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    margin: 20px 10px;
    transition: all 0.3s ease;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 107, 0.3);
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 15px;
    border-radius: 10px;
    border-left: 4px solid #f44336;
    margin: 20px 0;
    display: none;
}

.info-box {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
    color: #856404;
}

.workflow-info {
    background: #e3f2fd;
    border: 1px solid #2196f3;
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
    color: #0d47a1;
}

.workflow-info h4 {
    margin-bottom: 10px;
    color: #1976d2;
}

.workflow-steps {
    list-style: none;
    padding: 0;
}

.workflow-steps li {
    padding: 5px 0;
    border-left: 3px solid #2196f3;
    padding-left: 15px;
    margin: 10px 0;
}

.debug-info {
    background: #e3f2fd;
    border: 1px solid #2196f3;
    border-radius: 10px;
    padding: 15px;
    margin: 20px 0;
    color: #0d47a1;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* Image Cropping Modal Styles */
.crop-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.crop-modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.crop-modal-header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.crop-modal-header h3 {
    margin: 0;
    font-size: 1.5em;
    font-weight: 600;
}

.crop-close {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.crop-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.crop-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    max-height: calc(90vh - 90px);
    overflow-y: auto;
}

.crop-container {
    width: 100%;
    height: clamp(280px, 55vh, 500px);
    margin-bottom: 20px;
    border-radius: 10px;
    overflow: hidden;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crop-container img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.crop-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-bottom: 10px;
    box-shadow: 0 -6px 16px rgba(0,0,0,0.06);
}

.crop-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.crop-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    padding-top: 10px;
    border-top: 1px solid #e0e0e0;
}

.crop-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    min-width: 80px;
}

.crop-reset {
    background: linear-gradient(135deg, #ff9a56 0%, #ff6b6b 100%);
    color: white;
}

.crop-rotate, .crop-flip { display: none; }

.crop-cancel {
    background: #6c757d;
    color: white;
}

.crop-apply {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
}

.crop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.crop-btn:active {
    transform: translateY(0);
}

/* Crop button in image preview */
.crop-image-btn {
    display: none;
}

.crop-image-btn:hover {
    transform: none;
    box-shadow: none;
}

/* New crop trigger under preview */
.crop-trigger-wrap {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.crop-trigger-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: #fff;
    border: none;
    border-radius: 22px;
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.crop-trigger-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(79, 172, 254, 0.25);
}

.cropped-badge {
    color: #2e7d32;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 700;
}

/* Responsive design for crop modal */
@media (max-width: 768px) {
    .crop-modal-content {
        width: 95%;
        margin: 5% auto;
    }
    
    .crop-container {
        height: clamp(240px, 50vh, 360px);
    }
    
    .crop-buttons {
        gap: 5px;
    }
    
    .crop-btn {
        padding: 8px 15px;
        font-size: 12px;
        min-width: 60px;
    }
    
    .crop-actions {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 768px) {
    .upload-section {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .header h1 {
        font-size: 2em;
    }
    
    .main-content {
        padding: 20px;
    }
}