/* Try-On Button (similar to zoom icon) */
.sf-v2-tryon-button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    vertical-align: middle !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
}

.sf-v2-tryon-button svg {
    width: 20px !important;
    height: 20px !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Ensure proper alignment in image-tools container */
.image-tools .sf-v2-tryon-button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Modal overlay */
.sf-v2-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 16px;
    animation: fadeIn 0.2s ease-in;
    overflow-y: auto; /* Allow scrolling on mobile if needed */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Modal container (two-column layout) */
.sf-v2-modal-container {
    background: #fff;
    width: 100%;
    max-width: 1000px; /* Increased from 900px to accommodate larger image */
    max-height: 90vh;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

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

@media (min-width: 768px) {
    .sf-v2-modal-container {
        flex-direction: row;
    }
}

/* Left Side: Product Showcase */
.sf-v2-modal-product {
    width: 100%;
    height: 300px;
    position: relative;
    background: #f5f5f5;
    overflow: hidden;
}

@media (min-width: 768px) {
    .sf-v2-modal-product {
        width: 50%; /* Increased from 40% to give more space to image */
        height: auto;
        min-height: 600px; /* Increased from 500px */
    }
}

.sf-v2-modal-product img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sf-v2-close-mobile {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 32px; /* Reduced from 40px */
    height: 32px; /* Reduced from 40px */
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95); /* White background instead of dark */
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1); /* Subtle border */
    font-size: 20px; /* Reduced from 24px */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); /* Subtle shadow */
    z-index: 10;
}

.sf-v2-close-mobile:hover {
    background: #fff;
    color: #000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

@media (min-width: 768px) {
    .sf-v2-close-mobile {
        display: none;
    }
}

/* Right Side: Try On Interface */
.sf-v2-modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px; /* Reduced from 24px */
}

@media (min-width: 768px) {
    .sf-v2-modal-content {
        padding: 24px; /* Reduced from 32px to give more space to image */
    }
}

.sf-v2-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px; /* Reduced to minimize gap between title and upload box */
}

.sf-v2-modal-title {
    margin: 0 0 4px 0; /* Reduced from 8px */
    font-size: 20px; /* Reduced from 24px */
    font-weight: 700;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    line-height: 1.2; /* Tighter line height */
}

.sf-v2-modal-title svg {
    color: #7c3aed;
    width: 20px; /* Reduced from 24px */
    height: 20px; /* Reduced from 24px */
    margin-right: 6px; /* Reduced from 8px */
}

.sf-v2-modal-subtitle {
    margin: 0;
    font-size: 12px; /* Reduced from 14px */
    color: #666;
    line-height: 1.3; /* Tighter line height */
}

.sf-v2-close-desktop {
    width: 32px; /* Reduced from 40px */
    height: 32px; /* Reduced from 40px */
    border-radius: 50%;
    background: #f9fafb; /* Light background */
    border: 1px solid #e5e7eb; /* Subtle border */
    color: #6b7280;
    font-size: 18px; /* Reduced from 24px */
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); /* Subtle shadow */
}

.sf-v2-close-desktop:hover {
    background: #fff;
    color: #000;
    border-color: #d1d5db;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transform: scale(1.05);
}

@media (min-width: 768px) {
    .sf-v2-close-desktop {
        display: flex;
    }
}

.sf-v2-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px; /* Reduced from 20px */
    min-height: 0; /* Allow flex child to shrink */
    overflow: hidden; /* Prevent overflow */
}

/* Notice Message Inside Upload Box */
.sf-v2-upload-notice {
    margin-top: 24px;
    padding: 12px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    max-width: 100%;
}

.sf-v2-upload-notice svg {
    color: #f97316;
    flex-shrink: 0;
    margin-top: 2px;
}

.sf-v2-upload-notice-title {
    margin: 0 0 4px 0;
    font-size: 13px;
    font-weight: 600;
    color: #9a3412;
}

.sf-v2-upload-notice-text {
    margin: 0;
    font-size: 12px;
    color: #7c2d12;
    opacity: 0.8;
    line-height: 1.4;
}

/* Upload Box */
.sf-v2-upload-box {
    flex: 1;
    min-height: 300px;
    height: 100%; /* Use full available height */
    border: 2px dashed #d1d5db;
    border-radius: 16px;
    background: #f9fafb;
    transition: all 0.3s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sf-v2-upload-box:hover {
    border-color: #9ca3af;
    background: #f3f4f6;
}

.sf-v2-upload-box.sf-v2-drag-over {
    border-color: #7c3aed;
    background: #f3e8ff;
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
}

.sf-v2-upload-placeholder {
    width: 100%;
    height: 100%;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}

.sf-v2-upload-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
}

.sf-v2-upload-box:hover .sf-v2-upload-icon {
    transform: scale(1.1);
    background: #f3f4f6;
}

.sf-v2-upload-icon svg {
    color: #6b7280;
}

.sf-v2-upload-label {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}

.sf-v2-upload-sublabel {
    display: block;
    font-size: 14px;
    color: #6b7280;
}

.sf-v2-upload-preview {
    width: 100%;
    height: 100%;
    min-height: 300px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.sf-v2-upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Shows full image without cropping */
    max-width: 100%;
    max-height: 100%;
}

.sf-v2-remove-image {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px; /* Reduced from 32px */
    height: 28px; /* Reduced from 32px */
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95); /* White background */
    color: #dc2626; /* Red color for delete */
    border: 1px solid rgba(220, 38, 38, 0.2); /* Subtle red border */
    font-size: 18px; /* Reduced from 20px */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); /* Subtle shadow */
    z-index: 10;
}

.sf-v2-remove-image:hover {
    background: #fee2e2; /* Light red background on hover */
    color: #991b1b; /* Darker red */
    border-color: #dc2626;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
    transform: scale(1.05);
}

/* Error Message */
.sf-v2-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 14px;
}

.sf-v2-error svg {
    flex-shrink: 0;
}

/* Button Wrapper */
.sf-v2-button-wrapper {
    display: none; /* Hide the separate button wrapper - button is now on image */
}

/* Button overlay on uploaded image and result image */
.sf-v2-upload-preview .sf-v2-btn-overlay,
.sf-v2-result-image-container .sf-v2-btn-overlay {
    position: absolute !important; /* Ensure positioning */
    bottom: 16px !important; /* Position from bottom of container */
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 100 !important; /* High z-index to ensure visibility */
    background: #7c3aed !important;
    color: #fff !important;
    padding: 12px 24px !important;
    border: none !important;
    border-radius: 10px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.2s !important;
    display: inline-flex !important; /* Ensure button is displayed */
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    max-width: calc(100% - 32px) !important; /* Ensure button doesn't overflow horizontally */
    white-space: nowrap !important; /* Prevent text wrapping */
    visibility: visible !important; /* Ensure visibility */
    opacity: 1 !important; /* Ensure opacity */
}

.sf-v2-upload-preview .sf-v2-btn-overlay:hover:not(:disabled),
.sf-v2-result-image-container .sf-v2-btn-overlay:hover:not(:disabled) {
    background: #6d28d9;
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.sf-v2-upload-preview .sf-v2-btn-overlay:active:not(:disabled),
.sf-v2-result-image-container .sf-v2-btn-overlay:active:not(:disabled) {
    transform: translateX(-50%) translateY(0);
}

.sf-v2-upload-preview .sf-v2-btn-overlay:disabled,
.sf-v2-result-image-container .sf-v2-btn-overlay:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    transform: translateX(-50%);
}

/* Button */
.sf-v2-btn {
    background: #7c3aed;
    color: #fff;
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 140px;
}

.sf-v2-btn:hover:not(:disabled) {
    background: #6d28d9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.sf-v2-btn:active:not(:disabled) {
    transform: translateY(0);
}

.sf-v2-btn:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.sf-v2-btn-secondary {
    background: transparent;
    color: #374151;
    padding: 10px 20px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    min-width: 140px;
}

.sf-v2-btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    transform: translateY(-1px);
}

/* Loader */
.sf-v2-loader {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    color: #666;
}

.sf-v2-loader-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.sf-v2-loader p {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
}

/* Result View */
.sf-v2-result-image-container {
    width: 100%;
    height: 100%;
    min-height: 300px;
    flex: 1;
    background: #f5f5f5;
    border-radius: 16px;
    overflow: hidden; /* Keep hidden to maintain border radius */
    border: 1px solid #e5e7eb;
    position: relative !important; /* Ensure positioning context */
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.sf-v2-result-image-container img {
    width: 100%;
    height: calc(100% - 70px); /* Reserve space for button at bottom */
    object-fit: contain; /* Same as upload preview - shows full image */
    max-width: 100%;
    max-height: calc(100% - 70px); /* Reserve space for button */
}

.sf-v2-result-actions {
    display: none; /* Hide separate button wrapper - button is now on image */
}

/* Responsive - Tablet */
@media (max-width: 1024px) and (min-width: 768px) {
    .sf-v2-modal-container {
        max-width: 95%;
        max-height: 95vh;
    }
    
    .sf-v2-modal-product {
        width: 45%; /* Slightly smaller on tablet */
        min-height: 500px;
    }
    
    .sf-v2-modal-content {
        padding: 24px;
    }
    
    .sf-v2-modal-title {
        font-size: 18px;
    }
    
    .sf-v2-modal-subtitle {
        font-size: 11px;
    }
}

/* Responsive - Mobile */
@media (max-width: 767px) {
    .sf-v2-modal-overlay {
        padding: 8px;
    }
    
    .sf-v2-modal-container {
        max-width: 100%;
        max-height: 98vh;
        border-radius: 16px; /* Smaller radius on mobile */
        flex-direction: column;
    }
    
    .sf-v2-modal-product {
        width: 100%;
        height: 200px; /* Reduced height on mobile */
        min-height: 200px;
        border-radius: 16px 16px 0 0; /* Rounded top only */
    }
    
    .sf-v2-modal-content {
        padding: 16px;
        max-height: calc(98vh - 200px); /* Account for product image height */
        overflow-y: auto;
    }
    
    .sf-v2-modal-header {
        margin-bottom: 12px;
    }
    
    .sf-v2-modal-title {
        font-size: 18px;
    }
    
    .sf-v2-modal-subtitle {
        font-size: 11px;
    }
    
    .sf-v2-modal-body {
        gap: 12px;
    }
    
    .sf-v2-upload-box {
        min-height: 250px;
        max-height: calc(98vh - 350px); /* Ensure it fits on screen */
    }
    
    .sf-v2-upload-placeholder {
        min-height: 250px;
        padding: 30px 16px;
    }
    
    .sf-v2-upload-preview {
        min-height: 250px;
        max-height: calc(98vh - 350px);
    }
    
    .sf-v2-result-image-container {
        min-height: 250px;
        max-height: calc(98vh - 350px);
        padding-bottom: 50px; /* Reduced padding on mobile */
    }
    
    /* Button overlay adjustments for mobile */
    .sf-v2-upload-preview .sf-v2-btn-overlay,
    .sf-v2-result-image-container .sf-v2-btn-overlay {
        bottom: 12px; /* Closer to bottom on mobile */
        padding: 10px 20px; /* Slightly smaller padding */
        font-size: 13px;
        max-width: calc(100% - 24px); /* More margin on mobile */
    }
    
    /* Close button adjustments */
    .sf-v2-close-mobile {
        width: 28px;
        height: 28px;
        font-size: 18px;
        top: 8px;
        left: 8px;
    }
    
    .sf-v2-remove-image {
        width: 24px;
        height: 24px;
        font-size: 16px;
        top: 8px;
        right: 8px;
    }
    
    /* Upload notice adjustments */
    .sf-v2-upload-notice {
        margin-top: 12px;
        padding: 10px;
        font-size: 11px;
    }
    
    .sf-v2-upload-notice-title {
        font-size: 12px;
    }
    
    .sf-v2-upload-notice-text {
        font-size: 11px;
    }
}
