/* AI修图组件样式 */
.ai-retouch-component {
    width: 100%;
    max-width: 100%; /* 确保不超出父容器 */
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-sizing: border-box; /* 包含内边距和边框 */
    overflow: visible; /* 确保下拉框可以显示 */
}

/* 通用标签样式 */
.ai-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4a5568;
    margin-bottom: 0.5rem;
}

/* 图片上传区域 */
.ai-upload-section {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* 上传区域头部 */
.ai-upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* 参考图开关样式 */
.ai-reference-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-toggle-input {
    display: none;
}

.ai-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.ai-toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: #e2e8f0;
    border-radius: 12px;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.ai-toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ai-toggle-input:checked + .ai-toggle-label .ai-toggle-slider {
    background: #667eea;
}

.ai-toggle-input:checked + .ai-toggle-label .ai-toggle-slider::before {
    transform: translateX(20px);
}

.ai-toggle-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: #4a5568;
    white-space: nowrap;
}

.ai-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 固定两列布局 */
    grid-template-rows: auto auto; /* 两行布局 */
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.ai-upload-slot {
    aspect-ratio: 1;
    border: 2px dashed #e2e8f0;
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: visible; /* 允许刷新按钮显示在外面 */
    margin-bottom: 20px; /* 为更新按钮留出空间 */
}

/* 主图框样式 */
.ai-upload-slot[data-slot="0"] {
    grid-column: 1 / 3; /* 跨两列 */
    grid-row: 1;
    width: 45%; /* 主图框宽度 */
    justify-self: center; /* 居中显示 */
    margin-bottom: 35px; /* 主图片需要更多空间给更新按钮 */
    cursor: default; /* 主图片不可点击 */
    border-style: solid; /* 使用实线边框区别于可上传的插槽 */
}

/* 参考图框在第二行，各占一列 */
.ai-upload-slot[data-slot="1"] {
    grid-column: 1;
    grid-row: 2;
}

.ai-upload-slot[data-slot="2"] {
    grid-column: 2;
    grid-row: 2;
}

/* 参考图框隐藏状态 */
.ai-upload-slot[data-slot="1"].hidden,
.ai-upload-slot[data-slot="2"].hidden {
    display: none;
}

.ai-upload-slot[data-slot="0"]:hover {
    border-color: #e2e8f0; /* 悬停时不改变颜色 */
    background: transparent; /* 悬停时不改变背景 */
}

.ai-upload-slot:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.ai-upload-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #9ca3af;
    font-size: 0.875rem;
    font-weight: 500;
}

.ai-upload-placeholder svg {
    color: #d1d5db;
    transition: color 0.2s ease;
}

.ai-upload-slot:hover .ai-upload-placeholder svg {
    color: #667eea;
}

.ai-upload-preview {
    position: absolute;
    inset: 0;
    display: none;
}

.ai-upload-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

.ai-upload-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ai-upload-remove:hover {
    background: rgba(220, 38, 38, 0.9);
    transform: scale(1.1);
}

/* 更新主图按钮 */
.ai-update-main-image {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2px 4px;
    min-width: 50px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap; /* 防止文字换行 */
}

.ai-update-main-image:hover {
    background: #5a67d8;
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.ai-update-main-image:active {
    transform: translateX(-50%) scale(0.95);
}



/* 提示词输入区域 */
.ai-prompt-section {
    width: 100%;
}

.ai-prompt-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    min-height: 72px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.ai-prompt-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-prompt-textarea::placeholder {
    color: #9ca3af;
}

/* 风格选择区域 */
.ai-style-section {
    width: 100%;
}

.ai-style-selector {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-style-selector:hover {
    border-color: #667eea;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.ai-dropdown-arrow {
    width: 16px;
    height: 16px;
    color: #9ca3af;
    transition: color 0.2s ease;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.ai-style-selector:hover .ai-dropdown-arrow {
    color: #667eea;
}

.ai-selected-style {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid #667eea;
    border-radius: 8px;
    font-size: 0.875rem;
}

.ai-style-name {
    font-weight: 600;
    color: #667eea;
}

.ai-style-change {
    background: none;
    border: none;
    color: #667eea;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.ai-style-change:hover {
    background: rgba(102, 126, 234, 0.1);
}

/* 生成设置区域 */
.ai-generate-section {
    width: 100%;
}

.ai-generate-controls {
    display: flex;
    gap: 1rem;
    align-items: end;
}



.ai-generate-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 2.75rem;
    white-space: nowrap;
}

.ai-generate-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.ai-generate-btn:disabled,
.ai-generate-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 加载动画 */
.ai-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: ai-spin 1s linear infinite;
}

@keyframes ai-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}





/* 风格网格 */
.ai-style-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

.ai-style-card {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
}

.ai-style-card:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
}

.ai-style-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: #e2e8f0;
}

.ai-style-before,
.ai-style-after {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
}

.ai-style-before img,
.ai-style-after img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-style-label {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.ai-style-info {
    padding: 1rem;
}

.ai-style-info .ai-style-name {
    font-size: 1rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0 0 0.5rem 0;
}

.ai-style-description {
    font-size: 0.875rem;
    color: #718096;
    line-height: 1.4;
    margin: 0;
}


/* 风格选择弹窗需要更少的padding */
#ai-style-modal .modal-content {
    padding: 0.75rem;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
}


/* 移动端优化 */
@media (max-width: 768px) {

    #ai-style-modal .modal-content {
        margin-left: 0 !important;
    }

    /* 移动端风格网格单列显示 */
    .ai-style-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .ai-upload-grid {
        gap: 0.5rem;
        grid-template-columns: 1fr 1fr; /* 移动端保持两列布局 */
        grid-template-rows: auto auto;
    }
    
    /* 移动端主图框样式调整 */
    .ai-upload-slot[data-slot="0"] {
        width: 60%; /* 移动端主图框减小尺寸 */
    }
    
    .ai-generate-controls {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .ai-generate-btn {
        width: 100%;
        justify-content: center;
    }
    
    /* 移动端上传区域优化 */
    .ai-upload-slot {
        min-height: 70px; /* 减小最小高度 */
    }
    
    .ai-upload-placeholder {
        padding: 0.25rem;
        gap: 0.25rem;
    }
    
    .ai-upload-placeholder svg {
        width: 18px;
        height: 18px;
    }
    
    .ai-upload-text {
        font-size: 0.7rem;
        text-align: center;
        line-height: 1.2;
    }
    
    /* 移动端更新按钮优化 */
    .ai-update-main-image {
        font-size: 0.7rem;
        min-width: 45px;
        bottom: -50px;
    }
}

/* 超小屏幕移动端优化 */
@media (max-width: 480px) {
    .ai-style-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .ai-upload-grid {
        gap: 0.375rem; /* 减小间距以适应小屏幕 */
        grid-template-columns: 1fr 1fr; /* 超小屏幕保持两列布局 */
        grid-template-rows: auto auto;
    }
    
    /* 超小屏幕主图框样式调整 */
    .ai-upload-slot[data-slot="0"] {
        width: 40%; /* 超小屏幕主图框减小尺寸 */
    }
    
    .ai-prompt-textarea {
        min-height: 60px;
    }
}

/* 张数选择下拉框样式 - 参考画布尺寸下拉框 */
.ai-count-section {
    width: 90px; /* 增加宽度，提供更好的显示效果 */
    min-width: 90px;
    overflow: visible; /* 确保下拉框可以显示 */
}

.ai-count-dropdown {
    position: relative;
    width: 100%;
    overflow: visible; /* 确保下拉框可以显示 */
}

.ai-count-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    min-height: 2.75rem;
}

.ai-count-trigger:hover {
    border-color: #667eea;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.ai-count-trigger:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-count-text {
    flex: 1;
    text-align: left;
    font-weight: 600;
    letter-spacing: 0.025em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-count-arrow {
    width: 16px;
    height: 16px;
    color: #9ca3af;
    transition: transform 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.ai-count-arrow.rotate-180 {
    transform: rotate(180deg);
    color: #667eea;
}

.ai-count-dropdown-menu {
    position: fixed; /* 改为fixed定位，相对于视口 */
    z-index: 1001;
    transform-origin: bottom; /* 改为bottom，向上展开 */
    /* 位置将通过JavaScript动态计算 */
}

.ai-count-dropdown-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #e2e8f0;
    padding: 0.5rem 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.98) 100%);
    max-height: 110px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

.ai-count-dropdown-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.625rem 1rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
    position: relative;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-count-dropdown-item:hover {
    color: #667eea;
    background: rgba(102, 126, 234, 0.08);
}

.ai-count-dropdown-item.active {
    color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    font-weight: 600;
}



.ai-count-icon {
    width: 16px;
    height: 16px;
    margin-right: 0.625rem;
    color: #9ca3af;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.ai-count-dropdown-item:hover .ai-count-icon,
.ai-count-dropdown-item.active .ai-count-icon {
    color: #667eea;
}

/* 下拉框动画 */
.ai-count-dropdown-enter {
    transition: opacity 0.15s ease;
}

.ai-count-dropdown-enter-start {
    opacity: 0;
}

.ai-count-dropdown-enter-end {
    opacity: 1;
}

.ai-count-dropdown-leave {
    transition: opacity 0.1s ease;
}

.ai-count-dropdown-leave-start {
    opacity: 1;
}

.ai-count-dropdown-leave-end {
    opacity: 0;
}

/* 生成区域布局调整 */
.ai-generate-section {
    display: flex;
    gap: 1rem;
    align-items: end;
    width: 100%;
    overflow: visible; /* 确保下拉框可以显示 */
}

.ai-generate-btn {
    flex: 1;
    min-width: 120px; /* 确保按钮有足够的最小宽度 */
}

/* 移动端优化 */
@media (max-width: 768px) {
    .ai-generate-section {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .ai-count-section {
        width: 100%;
    }
    
    .ai-generate-btn {
        width: 100%;
        justify-content: center;
    }
}

/* 超小屏幕移动端优化 */
@media (max-width: 480px) {
    .ai-count-dropdown-content {
        max-height: 110px; /* 减小下拉框高度以适应小屏幕 */
    }
}