/* AI Background Remover Premium Stylesheet */

.main-container-app {
    position: relative;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 48px 24px 60px;
    width: 100%;
    max-width: 1000px !important;
    margin: 0 auto !important;
    box-sizing: border-box;
}

.converter-box {
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
    align-self: center;
    background: var(--card-bg, #fff);
    border: 1px solid color-mix(in srgb, var(--border, #e5e7eb) 100%, #e5e7eb);
    border-radius: calc(var(--radius, 10px) + 6px);
    padding: 40px 36px;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.04);
    box-sizing: border-box;
}

.converter-header {
    text-align: center;
    margin-bottom: 28px;
}

.converter-header h1 {
    font-size: clamp(24px, 3vw, 32px);
    font-weight: 700;
    color: var(--text);
    margin: 0 0 8px;
}

.converter-header p {
    font-size: 14px;
    color: var(--muted-foreground);
    margin: 0;
}

.drop-zone {
    display: block;
    border: 2px dashed color-mix(in srgb, var(--border, #e5e7eb) 100%, #d1d5db);
    border-radius: calc(var(--radius, 10px) + 4px);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: var(--bg-3, #f9fafb);
    pointer-events: auto;
    -webkit-user-select: none;
    user-select: none;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 4%, transparent);
}

.drop-zone-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    color: var(--primary);
}

.drop-zone-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px;
}

.drop-zone-hint {
    display: block;
    font-size: 13px;
    color: var(--muted-foreground);
    margin: 0;
}

.bgr-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.file-name-display {
    margin-top: 12px;
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    word-break: break-all;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 46px;
    margin-top: 20px;
    border: none;
    border-radius: var(--radius, 10px);
    background: var(--grad);
    background-clip: border-box;
    -webkit-background-clip: border-box;
    color: var(--primary-foreground);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-sizing: border-box;
    overflow: hidden;
    isolation: isolate;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: auto;
}

.action-btn:hover:not(:disabled) {
    opacity: 0.92;
    transform: translateY(-1px);
}

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

.error-message {
    display: none;
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius, 10px);
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    font-size: 13px;
    text-align: center;
}

.error-message.is-rate-limit {
    background: #fee2e2;
    border: 2px solid #ef4444;
    color: #b91c1c;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.22);
}


.progress-container {
    display: none;
    margin-top: 28px;
}

.progress-bar-wrapper {
    width: 100%;
    height: 10px;
    background-color: #f1f5f9;
    border-radius: 100px;
    overflow: hidden;
    position: relative;
    border: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #8b5cf6, #d946ef, #4f46e5);
    background-size: 200% 100%;
    border-radius: 100px;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5), 0 0 4px rgba(217, 70, 239, 0.3);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: progress-gradient-shimmer 2s linear infinite;
}

@keyframes progress-gradient-shimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.progress-status-text {
    display: none !important;
}

/* Tia quét sáng AI (AI Scan Line) */
.drop-zone {
    position: relative;
    overflow: hidden;
}

.scan-line {
    display: none;
    position: absolute;
    left: 0;
    width: 100%;
    height: 5px;
    background: linear-gradient(90deg, 
        rgba(99, 102, 241, 0) 0%, 
        rgba(99, 102, 241, 0.8) 20%, 
        rgba(168, 85, 247, 1) 50%, 
        rgba(99, 102, 241, 0.8) 80%, 
        rgba(99, 102, 241, 0) 100%
    );
    box-shadow: 0 0 15px 4px rgba(168, 85, 247, 0.7);
    z-index: 10;
    pointer-events: none;
}

/* Hiệu ứng làm mờ và đồng bộ giao diện lúc loading */
.converter-box.is-processing .drop-zone {
    opacity: 0.65;
    filter: blur(1px);
    pointer-events: none;
    transition: all 0.4s ease;
}

.converter-box.is-processing .scan-line {
    display: block;
    animation: ai-scan-anim 2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes ai-scan-anim {
    0% { top: 0%; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

.converter-box.is-processing .action-btn {
    opacity: 0.6;
    pointer-events: none;
    box-shadow: none;
    background: #e2e8f0 !important;
    color: #94a3b8 !important;
}

@keyframes progress-pulse {
    0% { box-shadow: 0 0 8px rgba(139, 92, 246, 0.4); }
    50% { box-shadow: 0 0 16px rgba(139, 92, 246, 0.7), 0 0 6px rgba(217, 70, 239, 0.3); }
    100% { box-shadow: 0 0 8px rgba(139, 92, 246, 0.4); }
}

.converter-box.is-processing .progress-bar-fill {
    animation: progress-gradient-shimmer 2s linear infinite, progress-pulse 2s ease-in-out infinite;
}

/* Before/After Split-screen Comparison Slider */
.comparison-container {
    display: none;
    position: relative;
    width: 100%;
    min-height: 280px;
    max-height: 520px;
    aspect-ratio: auto;
    border-radius: var(--radius, 10px);
    overflow: hidden;
    margin-top: 0;
    margin-bottom: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    background: #f8fafc;
}

.comparison-container.is-visible {
    display: block !important;
    width: 100%;
    min-height: 320px;
    max-height: min(520px, 70vh);
    aspect-ratio: var(--cmp-ratio, 4 / 3);
}

.comparison-container.is-ready {
    aspect-ratio: var(--cmp-ratio, 4 / 3);
}

.comparison-hint {
    display: none;
    margin: 10px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--muted-foreground, #64748b);
}

.comparison-hint.is-visible {
    display: block;
}

/* Checked grid background for transparent image */
.bg-transparency-grid {
    background-color: #fff;
    background-image: 
        linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
        linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.comparison-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
}

.before-image {
    z-index: 10;
}

.after-image-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    overflow: hidden;
    clip-path: inset(0 0 0 50%);
    -webkit-clip-path: inset(0 0 0 50%);
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #d1d5db 25%, transparent 25%),
        linear-gradient(-45deg, #d1d5db 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d1d5db 75%),
        linear-gradient(-45deg, transparent 75%, #d1d5db 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.after-image {
    pointer-events: none;
}

/* Slider Input Overlay */
.comparison-slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 30;
    margin: 0;
    opacity: 0;
    cursor: ew-resize;
}

/* Divider line & handle indicator */
.slider-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: #ffffff;
    z-index: 25;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
    transform: translateX(-50%);
}

.slider-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 38px;
    height: 38px;
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary, #5100D6);
}

.slider-button svg {
    width: 16px;
    height: 16px;
}

/* Labels */
.image-label {
    position: absolute;
    bottom: 16px;
    padding: 6px 12px;
    background: rgba(15, 23, 42, 0.7);
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    z-index: 28;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
}

.label-before {
    left: 16px;
}

.label-after {
    right: 16px;
}

.output-action-group {
    display: none;
    margin-top: 24px;
    width: 100%;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.output-action-group.is-visible {
    display: flex;
}

.download-btn {
    background-color: #16a34a;
    color: #ffffff;
    border: none;
    padding: 14px 32px;
    border-radius: var(--radius, 10px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.download-btn:hover {
    background-color: #15803d;
}

.reset-btn {
    background-color: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    padding: 14px 24px;
    border-radius: var(--radius, 10px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background-color: #e2e8f0;
}

.enhance-btn {
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    color: #ffffff;
    border: none;
    padding: 14px 24px;
    border-radius: var(--radius, 10px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(124, 58, 237, 0.15);
}

.enhance-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #b55fe6 0%, #8b5cf6 100%);
    box-shadow: 0 6px 14px rgba(124, 58, 237, 0.25);
    transform: translateY(-1px);
}

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

.enhance-btn.is-loading svg {
    animation: spin 1s linear infinite;
}

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

@media (max-width: 992px) {
    .main-container-app { padding: 24px 16px 40px; }
    .converter-box { padding: 32px 20px; }
    .converter-header h1 { font-size: 24px; }
    .drop-zone { padding: 36px 16px; }
    .output-action-group { flex-direction: column; width: 100%; }
    .download-btn, .reset-btn, .enhance-btn { width: 100%; justify-content: center; }
}

.converter-box[data-view="auto-result"] #dropZone {
    display: none !important;
}

.converter-box[data-view="auto-result"] .comparison-container.is-visible {
    display: block !important;
}

/* Giao diện chỉnh sửa thủ công (Restore/Erase) */
.manual-editor-container {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    margin-top: 16px;
}

.converter-box[data-view="edit-mode"] .manual-editor-container {
    display: flex;
}

.converter-box[data-view="edit-mode"] #dropZone,
.converter-box[data-view="edit-mode"] .comparison-container,
.converter-box[data-view="edit-mode"] .comparison-hint,
.converter-box[data-view="edit-mode"] #processBtn,
.converter-box[data-view="edit-mode"] #outputActionGroup {
    display: none !important;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius, 10px);
    box-sizing: border-box;
    flex-wrap: wrap;
}

.tool-select-group {
    display: flex;
    gap: 8px;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tool-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.tool-btn.is-active {
    border-color: var(--primary, #5100D6);
    background: color-mix(in srgb, var(--primary, #5100D6) 8%, #ffffff);
    color: var(--primary, #5100D6);
}

.brush-size-control {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 150px;
    max-width: 280px;
}

.brush-label {
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

#editorBrushSlider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    accent-color: var(--primary, #5100D6);
}

#editorBrushValue {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary, #5100D6);
    min-width: 38px;
    text-align: right;
}

.editor-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.editor-btn:hover:not(:disabled) {
    background: #f1f5f9;
    color: #1e293b;
}

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

.editor-canvas-wrap {
    position: relative;
    width: 100%;
    max-height: min(520px, 68vh);
    border: 1px solid #e2e8f0;
    border-radius: var(--radius, 10px);
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f8fafc;
    aspect-ratio: var(--cmp-ratio, 4 / 3);
    cursor: crosshair;
    touch-action: pan-x pan-y;
}

.editor-canvas-wrap.is-zoomed {
    justify-content: flex-start !important;
    align-items: flex-start !important;
}

#editorCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: width 0.15s ease-out, height 0.15s ease-out;
}

.editor-canvas-wrap.is-zoomed #editorCanvas {
    margin: auto !important;
}

.editor-brush-cursor {
    position: absolute;
    border: 1px solid #ffffff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 100;
    display: none;
}

.editor-action-group {
    display: flex;
    gap: 16px;
    width: 100%;
    justify-content: center;
}

.cancel-btn {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    padding: 12px 28px;
    font-size: 14px;
}

.cancel-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.apply-btn {
    background: #16a34a;
    color: #ffffff;
    border: none;
    padding: 12px 32px;
    font-size: 14px;
}

.apply-btn:hover {
    background: #15803d;
}

/* Nút Chỉnh sửa nét vẽ trong output group */
.edit-btn {
    background-color: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    padding: 14px 24px;
    border-radius: var(--radius, 10px);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.edit-btn:hover {
    background-color: #e2e8f0;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 2px;
}

.zoom-control #zoomValue {
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    min-width: 44px;
    text-align: center;
    user-select: none;
}

.zoom-btn, .reset-zoom-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 26px !important;
    height: 26px !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    color: #64748b !important;
    border-radius: 6px !important;
    cursor: pointer;
    transition: all 0.2s ease;
}

.zoom-btn:hover, .reset-zoom-btn:hover {
    background: #f1f5f9 !important;
    color: #1e293b !important;
}

.zoom-btn svg, .reset-zoom-btn svg {
    display: block;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.brush-type-control {
    display: flex;
    gap: 4px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 2px;
}

.brush-type-btn {
    padding: 6px 12px !important;
    border: none !important;
    background: transparent !important;
    color: #64748b !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    white-space: nowrap;
}

.brush-type-btn:hover {
    background: #f1f5f9 !important;
    color: #1e293b !important;
}

.brush-type-btn.is-active {
    background: var(--primary, #5100D6) !important;
    color: #ffffff !important;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 10px;
    }
    
    .tool-select-group {
        display: flex;
        width: 100%;
    }
    
    .tool-btn {
        flex: 1;
        justify-content: center;
        padding: 10px;
        font-size: 12px;
    }
    
    .brush-size-control {
        max-width: 100%;
        width: 100%;
        padding: 4px 0;
    }

    .brush-type-control {
        width: 100%;
        justify-content: stretch;
    }

    .brush-type-btn {
        flex: 1;
        justify-content: center;
    }
    
    .zoom-control {
        width: 100%;
        justify-content: space-between;
        padding: 4px 8px;
    }

    .zoom-control #zoomValue {
        flex: 1;
    }
    
    .undo-btn {
        width: 100%;
        justify-content: center;
        padding: 10px;
    }

    .editor-action-group {
        flex-direction: column;
        gap: 10px;
    }

    .cancel-btn, .apply-btn {
        width: 100%;
        justify-content: center;
    }
}


