/* 通用弹出框组件样式 - 参考ai-retouch-component */
.modal-component {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: modal-fade-in 0.3s ease forwards;
}

/* 背景遮罩 */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

/* 弹出框容器 */
.modal-container {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: min(800px, calc(100vw - 320px)); /* 确保不超出可用空间，为工具栏预留320px */
    max-height: 90vh;
    overflow: hidden;
    animation: modal-scale-in 0.3s ease forwards;
    z-index: 1001; /* 确保在overlay之上 */
}

/* 不同尺寸 */
.modal-small {
    max-width: min(400px, calc(100vw - 320px));
}

.modal-medium {
    max-width: min(600px, calc(100vw - 320px));
}

.modal-large {
    max-width: min(900px, calc(100vw - 320px));
}

/* PC端样式 */
@media (min-width: 769px) {
    .modal-header {
        cursor: default !important;
        user-select: auto !important;
        -webkit-user-select: auto !important;
        -moz-user-select: auto !important;
        -ms-user-select: auto !important;
    }
    
    .modal-header::before {
        display: none !important; /* PC端不显示拖拽指示器 */
    }
    
    .modal-container {
        max-width: min(800px, calc(100vw - 320px)); /* 为280px工具栏+40px边距预留空间 */
    }
}

/* 中等屏幕优化 */
@media (min-width: 769px) and (max-width: 1200px) {
    .modal-container {
        max-width: min(700px, calc(100vw - 280px)); /* 为240px工具栏+40px边距预留空间 */
        width: 85%;
    }
}

/* 小屏幕PC优化 */
@media (min-width: 769px) and (max-width: 1024px) {
    .modal-container {
        max-width: min(600px, calc(100vw - 260px)); /* 更保守的空间预留 */
        width: 80%;
    }
}

/* 移动端对齐到底部 */
@media (max-width: 768px) {
    .modal-component {
        align-items: flex-end; /* 移动端对齐到底部 */
        justify-content: stretch;
    }
}

/* 动画效果 */
@keyframes modal-fade-in {
    to { opacity: 1; }
}

@keyframes modal-scale-in {
    from { transform: scale(0.9); }
    to { transform: scale(1); }
}

/* 弹出框头部 */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e2e8f0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f7fafc;
    border-radius: 6px;
    color: #718096;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: #edf2f7;
    color: #4a5568;
}

/* 弹出框内容 */
.modal-content {
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(90vh - 160px); /* 为header(80px)和footer(80px)预留更多空间 */
    width: 100%;
    box-sizing: border-box;
    flex: 1; /* 让内容区域占据剩余空间 */
    min-height: 0; /* 确保flex子项可以收缩 */
}

/* 弹出框底部 */
.modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 0 0 16px 16px;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
}

/* 按钮样式 */
.modal-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.modal-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.modal-btn-secondary {
    background: #f7fafc;
    color: #4a5568;
    border: 1px solid #e2e8f0;
}

.modal-btn-secondary:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .modal-container {
        width: 100%;
        height: 75vh; /* 占据75%的视口高度，留出上方空间 */
        max-width: none;
        max-height: 75vh;
        border-radius: 16px 16px 0 0; /* 只保留顶部圆角 */
        position: fixed;
        bottom: 0; /* 固定在底部 */
        top: auto; /* 取消顶部定位 */
        animation: modal-slide-up 0.3s ease forwards;
        overflow: hidden; /* 确保内容不会溢出 */
        resize: none; /* 禁用浏览器默认的resize功能 */
    }
    
    @keyframes modal-slide-up {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .modal-header {
        padding: 1.5rem 1.5rem 1rem 1.5rem; /* 增加顶部padding为拖拽指示器留空间 */
        position: relative;
        min-height: 60px; /* 确保有足够高度 */
    }
    
    /* 移动端拖拽指示器 */
    .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        cursor: grab;
        transition: height 0.2s ease;
    }
    
    /* 移动端关闭按钮位置调整 */
    .modal-close {
        position: absolute;
        top: 20px; /* 在拖拽指示器下方，但在header顶部区域 */
        right: 1.5rem;
        margin: 0; /* 移除默认margin */
        z-index: 20; /* 确保在所有元素之上 */
        pointer-events: auto; /* 确保可以点击 */
    }
    
    .modal-header:active::before {
        cursor: grabbing;
        height: 6px; /* 拖拽时高度增加 */
        top: 9px; /* 调整位置保持居中 */
    }
    
    /* 让整个头部区域可拖拽（仅移动端） */
    .modal-header {
        cursor: grab;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
    
    .modal-header:active {
        cursor: grabbing;
    }
    
    /* 移动端标题位置调整 */
    .modal-title {
        margin-top: 8px; /* 与关闭按钮垂直对齐 */
    }
    
    .modal-content {
        padding: 1.5rem;
        max-height: calc(75vh - 80px); /* 减去头部高度，确保内容可滚动 */
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 1rem 1.5rem;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .modal-btn {
        width: 100%;
        justify-content: center;
    }
}

/* 超小屏幕移动端优化 */
@media (max-width: 480px) {
    .modal-container {
        height: 80vh; /* 小屏幕上稍微增加高度 */
        max-height: 80vh;
        overflow: hidden;
        resize: none;
    }
    
    .modal-content {
        max-height: calc(80vh - 80px);
    }
    
    .modal-header {
        padding: 1.25rem 1rem 0.75rem 1rem; /* 调整padding */
        min-height: 55px; /* 稍微减小高度 */
    }
    
    .modal-title {
        font-size: 1.125rem;
        margin-top: 6px; /* 超小屏幕的标题对齐 */
    }
    
    /* 超小屏幕关闭按钮位置 */
    .modal-close {
        top: 18px; /* 稍微往上调整 */
        right: 1rem;
        width: 28px;
        height: 28px;
        z-index: 20; /* 确保在所有元素之上 */
        pointer-events: auto; /* 确保可以点击 */
    }
    
    .modal-content {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
    }
}

/* 拖拽时的样式 */
.modal-container.dragging {
    cursor: move;
    user-select: none;
}

/* 调整大小手柄 */
.modal-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: se-resize;
    color: #cbd5e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    user-select: none;
}

.modal-resize-handle:hover {
    color: #a0aec0;
}

/* 滚动条样式 */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* 加载状态 */
.modal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #718096;
}

.modal-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e2e8f0;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.75rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 空状态 */
.modal-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    color: #718096;
    text-align: center;
}

.modal-empty-icon {
    width: 48px;
    height: 48px;
    color: #cbd5e0;
    margin-bottom: 1rem;
}

.modal-empty-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #4a5568;
    margin: 0 0 0.5rem 0;
}

.modal-empty-desc {
    font-size: 0.875rem;
    color: #718096;
    margin: 0;
    line-height: 1.5;
}

/* 错误状态 */
.modal-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
}

.modal-error-icon {
    width: 48px;
    height: 48px;
    color: #f56565;
    margin-bottom: 1rem;
}

.modal-error-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #e53e3e;
    margin: 0 0 0.5rem 0;
}

.modal-error-desc {
    font-size: 0.875rem;
    color: #718096;
    margin: 0;
    line-height: 1.5;
}