/* 通用样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', 'SimHei', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部样式 */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* 主内容区域 */
.main-content {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 30px;
    align-items: start;
}

/* 控制面板 */
.control-panel {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    height: fit-content;
    max-height: 90vh;
    overflow-y: auto;
}

.panel-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.panel-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.panel-section h3 {
    color: #4a5568;
    margin-bottom: 15px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 模板选择网格 */
.template-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.template-item {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    background: white;
}

.template-item:hover {
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.template-item.selected {
    border-color: #667eea;
    background: #f7fafc;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.template-item img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 5px;
}

.template-item span {
    font-size: 12px;
    color: #666;
    display: block;
}

/* 自定义上传区域 */
.template-item.custom-upload {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-style: dashed;
    background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
}

.template-item.custom-upload:hover {
    background: linear-gradient(135deg, #f0f4ff 0%, #e0ebff 100%);
}

.template-item.custom-upload.selected {
    background: linear-gradient(135deg, #e6f2ff 0%, #d6e8ff 100%);
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px;
}

.upload-area i {
    font-size: 24px;
    color: #667eea;
}

.upload-area span {
    font-size: 12px;
    color: #4a5568;
    font-weight: 600;
}

/* 背景预览容器 */
.background-preview-container {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}

.background-preview-container:hover #remove-background-btn {
    opacity: 1;
}

#remove-background-btn {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* 自定义背景区域 */
.custom-background-section {
    border-top: 1px solid #eee;
    padding-top: 15px;
}

/* 切换开关样式 */
.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 12px;
    padding: 8px 0;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 24px;
    background: #e2e8f0;
    border-radius: 12px;
    transition: all 0.3s ease;
    border: 2px solid #e2e8f0;
}

.toggle-switch:hover {
    background: #cbd5e0;
    border-color: #cbd5e0;
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch {
    background: #667eea;
    border-color: #667eea;
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch .toggle-slider {
    transform: translateX(26px);
}

.toggle-label span {
    font-weight: 600;
    color: #4a5568;
    font-size: 14px;
}

.toggle-label:hover span {
    color: #2d3748;
}

/* 表单样式 */
.form-group {
    margin-bottom: 15px;
}

.form-group-small {
    flex: 1;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.form-group label,
.form-group-small label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #4a5568;
    font-size: 13px;
    position: relative;
    padding-left: 0;
}

/* 颜色预览样式 */
.form-group label:has(+ input[type="color"]),
.form-group-small label:has(+ input[type="color"]) {
    padding-left: 25px;
    transition: background 0.3s ease;
    border-radius: 4px;
}

.form-group input,
.form-group select,
.form-group textarea,
.form-group-small input,
.form-group-small select {
    width: 100%;
    padding: 8px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-group-small input:focus,
.form-group-small select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-group small {
    color: #718096;
    font-size: 11px;
    margin-top: 3px;
    display: block;
    line-height: 1.3;
}

/* 单选按钮组 */
.radio-group {
    display: flex;
    gap: 15px;
    margin-top: 5px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: normal;
    cursor: pointer;
    font-size: 13px;
}

.radio-group input[type="radio"] {
    width: auto;
    margin: 0;
}

/* 印章控制区域 */
.seal-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

/* 按钮样式 */
.btn {
    padding: 8px 15px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    text-decoration: none;
    width: 100%;
    margin-bottom: 8px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb, #f5576c);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
    color: white;
}

.btn-info {
    background: linear-gradient(135deg, #43e97b, #38f9d7);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, #ffa726, #fb8c00);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, #ff5722, #d32f2f);
    color: white;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 20px;
}

.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #667eea;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.btn-icon:hover {
    background-color: #f7fafc;
}

/* 预览面板 */
.preview-panel {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    min-height: 600px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #eee;
}

.preview-header h3 {
    color: #4a5568;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-controls span {
    font-weight: 600;
    color: #4a5568;
    min-width: 50px;
    text-align: center;
}

.preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    overflow: auto;
    position: relative;
}

.canvas-info {
    margin-top: 15px;
    text-align: center;
    color: #666;
    font-size: 13px;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
}

/* 证书画布 - 修改为横向 */
.certificate-canvas {
    width: 297mm;  /* 横向宽度 */
    height: 210mm; /* 横向高度 */
    position: relative;
    transform-origin: center;
    transition: transform 0.3s ease;
    background: white;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border-radius: 10px;
    overflow: hidden;
}

.certificate-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.elements-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* 可编辑元素 */
.editable-element {
    position: absolute;
    pointer-events: all;
    cursor: move;
    user-select: none;
    z-index: 10;
}

.editable-element.selected {
    outline: 2px dashed #667eea;
    outline-offset: 2px;
}

.editable-element.selected::after {
    content: '';
    position: absolute;
    top: -6px;
    right: -6px;
    width: 12px;
    height: 12px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
}

/* 文字元素 */
.text-element {
    padding: 5px;
    line-height: 1.2;
    word-wrap: break-word;
    /* 移除固定最大宽度，允许动态调整 */
    min-width: 50px;
    white-space: pre-wrap;
}

.text-element:hover {
    background: rgba(102, 126, 234, 0.1);
}

/* 文字元素调整手柄 */
.text-element.selected::before {
    content: '';
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 12px;
    height: 12px;
    background: #667eea;
    border-radius: 50%;
    cursor: se-resize;
    z-index: 11;
}

/* 印章元素 */
.seal-element {
    display: flex;
    align-items: center;
    justify-content: center;
}

.seal-element.text-seal {
    border: 3px solid;
    border-radius: 50%;
    font-weight: bold;
    text-align: center;
    line-height: 1.1;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.3) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 5px;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow: hidden;
}

.seal-element.image-seal img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.seal-element:hover {
    transform: scale(1.05);
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 批量模态框特殊样式 */
#batch-modal .modal-content {
    max-width: 95%;
    width: 95%;
    height: 90vh;
}

.modal-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 20px;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.close:hover {
    opacity: 1;
}

.modal-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

/* 批量模态框的主体 */
#batch-modal .modal-body {
    padding: 10px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-shrink: 0;
}

.modal-footer .btn {
    width: auto;
    margin: 0;
}

/* 批量预览 */
#batch-preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
}

.batch-certificate {
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    position: relative;
    width: 250px;
    height: 178px; /* 保持横向比例 */
    background: white;
}

.batch-certificate .certificate-canvas {
    width: 1250px; /* 5倍缩放基准 */
    height: 890px;  /* 5倍缩放基准 */
    transform: scale(0.2);
    transform-origin: top left;
    position: absolute;
    top: 0;
    left: 0;
}

/* 响应式设计 */
@media (max-width: 1400px) {
    .main-content {
        grid-template-columns: 350px 1fr;
        gap: 20px;
    }
    
    .certificate-canvas {
        width: 80vw;
        height: calc(80vw * 210 / 297); /* 保持横向比例 */
    }
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 320px 1fr;
        gap: 15px;
    }
    
    .control-panel {
        padding: 20px;
    }
    
    .certificate-canvas {
        width: 75vw;
        height: calc(75vw * 210 / 297);
    }
}

@media (max-width: 992px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .control-panel {
        order: 2;
        max-height: none;
    }
    
    .preview-panel {
        order: 1;
    }
    
    .template-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .certificate-canvas {
        width: 90vw;
        height: calc(90vw * 210 / 297);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .button-group {
        grid-template-columns: 1fr;
    }
    
    .certificate-canvas {
        width: 95vw;
        height: calc(95vw * 210 / 297);
        min-height: 300px;
    }
    
    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 打印样式 */
@media print {
    body {
        background: white;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
    
    .main-content {
        display: block;
    }
    
    .control-panel {
        display: none;
    }
    
    .preview-panel {
        box-shadow: none;
        padding: 0;
        background: none;
    }
    
    .preview-header {
        display: none;
    }
    
    .canvas-info {
        display: none;
    }
    
    .preview-container {
        background: none;
        padding: 0;
    }
    
    .certificate-canvas {
        box-shadow: none;
        border-radius: 0;
        width: 100%;
        height: auto;
        transform: none !important;
        page-break-after: always;
    }
    
    .editable-element.selected {
        outline: none;
    }
    
    .editable-element.selected::after {
        display: none;
    }
    
    .text-element.selected::before {
        display: none;
    }
    
    header {
        display: none;
    }
} 