/**
 * Modal弹窗工具样式文件
 * 纯CSS实现，确保弹窗完美居中
 * 
 * @author Liujun <734443463z@gmail.com>
 * @version 1.0.0
 * @date 2025-06-19
 */

/* Modal遮罩层 - 使用flexbox确保完美居中 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
    /* 使用flexbox实现完美居中 */
    justify-content: center;
    align-items: center;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

/* Modal容器 */
.modal-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.8) translateY(-50px);
    transition: transform 0.3s ease;
    position: relative;
    /* 确保容器不会超出视口 */
    margin: 20px;
}

.modal-overlay.show .modal-container {
    transform: scale(1) translateY(0);
}

/* Modal头部 */
.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
    border-radius: 12px 12px 0 0;
}

.modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #212529;
    display: flex;
    align-items: center;
}

.modal-icon {
    margin-right: 8px;
    font-size: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background-color: #f8f9fa;
    color: #333;
}

.modal-close:focus {
    outline: none;
    background-color: #e9ecef;
}

/* Modal内容 */
.modal-body {
    padding: 20px 24px;
    color: #495057;
    font-size: 14px;
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-body p {
    margin: 0;
    word-wrap: break-word;
}

/* Modal底部 */
.modal-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background-color: #fff;
    border-radius: 0 0 12px 12px;
}

/* 按钮样式 */
.modal-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
}

.modal-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.modal-btn-primary {
    background-color: #007bff;
    color: white;
}

.modal-btn-primary:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.modal-btn-secondary {
    background-color: #6c757d;
    color: white;
}

.modal-btn-secondary:hover {
    background-color: #545b62;
    transform: translateY(-1px);
}

.modal-btn-success {
    background-color: #28a745;
    color: white;
}

.modal-btn-success:hover {
    background-color: #1e7e34;
    transform: translateY(-1px);
}

.modal-btn-danger {
    background-color: #dc3545;
    color: white;
}

.modal-btn-danger:hover {
    background-color: #bd2130;
    transform: translateY(-1px);
}

.modal-btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.modal-btn-warning:hover {
    background-color: #d39e00;
    transform: translateY(-1px);
}

/* 加载动画 */
.modal-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: modal-spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

/* 加载Modal特殊样式 */
.modal-loading .modal-container {
    max-width: 300px;
}

.modal-loading .modal-body {
    text-align: center;
    padding: 30px;
}

/* 图标颜色 */
.text-success { 
    color: #28a745 !important; 
}

.text-danger { 
    color: #dc3545 !important; 
}

.text-warning { 
    color: #ffc107 !important; 
}

.text-info { 
    color: #17a2b8 !important; 
}

/* 响应式设计 */
@media (max-width: 576px) {
    .modal-container {
        width: 95%;
        margin: 10px;
        max-height: 90vh;
    }
    
    .modal-header {
        padding: 15px 20px 12px;
    }
    
    .modal-body {
        padding: 15px 20px;
        font-size: 13px;
    }
    
    .modal-footer {
        padding: 12px 20px 15px;
        flex-direction: column;
    }
    
    .modal-btn {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .modal-btn:last-child {
        margin-bottom: 0;
    }
}

/* 确保在所有设备上都能居中 */
@media (max-height: 600px) {
    .modal-container {
        max-height: 95vh;
    }
    
    .modal-body {
        max-height: 50vh;
    }
}

/* 防止页面滚动时的样式 */
body.modal-open {
    overflow: hidden;
}

/* 增强动画效果 */
.modal-overlay {
    backdrop-filter: blur(2px);
}

.modal-container {
    will-change: transform;
}

/* 键盘导航友好 */
.modal-btn:focus,
.modal-close:focus {
    z-index: 1;
} 

/* iframe模态框样式 */
.modal-iframe .modal-container {
    display: flex !important;
    flex-direction: column !important;
    /* 重要：完全移除默认限制，让JS设置的尺寸完全生效 */
    max-width: none !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    /* 移除默认的margin限制 */
    margin: 0 !important;
}

.modal-iframe .modal-header {
    flex-shrink: 0 !important;
    /* 确保头部不会被压缩 */
    min-height: 60px;
}

.modal-iframe .modal-body {
    flex: 1 !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    /* 确保body占据剩余空间 */
    min-height: 0;
}

.modal-iframe .modal-iframe-content {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    border-radius: 0 0 12px 12px;
    flex: 1 !important;
    /* 确保iframe完全填充 */
    min-height: 0;
}

/* iframe模态框响应式 - 只在小屏幕时生效 */
@media (max-width: 768px) {
    .modal-iframe .modal-container:not([style*="width"]) {
        width: 95% !important;
        height: 85vh !important;
        min-width: 320px;
        min-height: 300px;
    }
}

/* 确保iframe弹窗的overlay居中显示 */
.modal-iframe.modal-overlay {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Prompt输入框样式 */
.modal-prompt .modal-prompt-input {
    margin-top: 15px;
}

.modal-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.modal-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.modal-input::placeholder {
    color: #6c757d;
    opacity: 0.7;
}

/* Prompt弹窗特殊样式 */
.modal-prompt .modal-container {
    max-width: 500px;
}

.modal-prompt .modal-body {
    padding-bottom: 25px;
}

/* Prompt响应式设计 */
@media (max-width: 768px) {
    .modal-input {
        padding: 10px 12px;
        font-size: 14px;
    }
}