/* 全局样式重置和基础设置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --background-color: #f8fafc;
    --card-background: #ffffff;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: var(--card-background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* 头部样式 */
header {
    background: linear-gradient(135deg, var(--primary-color), #4f46e5);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* 主内容区域 */
main {
    padding: 30px;
}

/* 功能区 */
.function-area {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media (min-width: 768px) {
    .function-area {
        grid-template-columns: 1fr 2fr;
    }
}

.upload-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.upload-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 按钮样式 */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--secondary-color);
    color: white;
}

.btn:hover:not(:disabled) {
    background-color: var(--secondary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-primary {
    background-color: var(--primary-color);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover);
}

/* 图片预览区 */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.image-container {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8fafc;
    overflow: hidden;
}

#previewImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: all 0.3s ease;
}

.placeholder {
    text-align: center;
    color: var(--text-secondary);
}

.placeholder p {
    margin-top: 15px;
    font-size: 1rem;
}

.hidden {
    display: none !important;
}

/* 控制区 */
.control-section {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

@media (max-width: 767px) {
    .control-section {
        flex-direction: column;
    }
}

/* 结果区域 */
.result-area {
    margin-top: 40px;
    animation: fadeIn 0.5s ease;
}

.result-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    background-color: #f1f5f9;
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: #f8fafc;
}

.tab-content {
    background-color: #f8fafc;
    border-radius: var(--radius);
    padding: 20px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

/* 格式化数据样式 */
.formatted-data {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: var(--text-primary);
}

.data-table tr:hover {
    background-color: #f8fafc;
}

/* 原始数据样式 */
.raw-data {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 20px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
}

/* 数据映射样式 */
.mapping-data {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.mapping-item {
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    box-shadow: var(--shadow-sm);
}

.mapping-item h4 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mapping-item p {
    font-size: 1.1rem;
    font-weight: 500;
}

/* 结果操作按钮 */
.result-actions {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* 加载中遮罩 */
.loading-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loading-mask p {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* 错误模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background-color: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: slideIn 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: var(--error-color);
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 20px;
}

.modal-body p {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

/* 动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

/* 响应式调整 */
@media (max-width: 767px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    main {
        padding: 20px;
    }
    
    .image-container {
        min-height: 300px;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .tab-btn {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .mapping-data {
        grid-template-columns: 1fr;
    }
}

/* 模板驱动的提取结果区域样式 */
.template-result-area {
    margin-top: 40px;
    padding: 30px;
    background-color: var(--card-background);
    border-top: 1px solid var(--border-color);
    animation: fadeIn 0.5s ease;
}

.template-result-area h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.8rem;
    text-align: center;
}

.template-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
    justify-content: center;
}

.template-tab-btn {
    padding: 12px 24px;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.template-tab-btn:hover {
    background-color: #f1f5f9;
    color: var(--text-primary);
}

.template-tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: #f8fafc;
}

.template-tab-content {
    background-color: #f8fafc;
    border-radius: var(--radius);
    padding: 20px;
    min-height: 300px;
}

.template-tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.template-tab-pane.active {
    display: block;
}

/* 提取数据样式 */
.extracted-data-categories {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.data-category {
    background-color: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.data-category h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.2rem;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e7ff;
}

.category-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.template-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.template-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.template-value {
    font-size: 1rem;
    color: var(--text-primary);
    padding: 8px 12px;
    background-color: #f8fafc;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    word-break: break-word;
}

/* 缺失字段样式 */
.missing-fields-list {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 20px;
}

.missing-fields-list p {
    color: var(--error-color);
    font-weight: 600;
    margin-bottom: 15px;
}

.missing-fields-list ul {
    list-style-type: none;
    padding-left: 0;
}

.missing-fields-list li {
    padding: 8px 12px;
    background-color: white;
    border-radius: var(--radius);
    margin-bottom: 8px;
    border-left: 4px solid var(--error-color);
    color: var(--text-primary);
}

.no-missing-fields {
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--success-color);
    font-weight: 600;
}

/* 模板配置样式 */
.template-config {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 20px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
}

.template-config pre {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* 模板驱动结果区域的响应式调整 */
@media (max-width: 767px) {
    .template-result-area {
        padding: 20px;
    }
    
    .template-result-area h2 {
        font-size: 1.5rem;
    }
    
    .extracted-data-categories {
        grid-template-columns: 1fr;
    }
    
    .template-tabs {
        flex-wrap: wrap;
    }
    
    .template-tab-btn {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
}

/* 相机预览容器样式 */
.camera-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.camera-container.show {
    opacity: 1;
    visibility: visible;
}

.camera-preview-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 90vh;
    background-color: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.2);
}

#cameraPreview {
    width: 100%;
    height: auto;
    max-height: calc(90vh - 100px);
    object-fit: contain;
}

.camera-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    background-color: rgba(26, 32, 44, 0.95);
    border-top: 1px solid #2d3748;
}

.camera-controls .btn {
    min-width: 120px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.camera-controls .btn-primary {
    background-color: #3182ce;
    border-color: #3182ce;
    color: white;
}

.camera-controls .btn-primary:hover {
    background-color: #2c5aa0;
    border-color: #2c5aa0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(49, 130, 206, 0.3);
}

.camera-controls .btn-secondary {
    background-color: #4a5568;
    border-color: #4a5568;
    color: white;
}

.camera-controls .btn-secondary:hover {
    background-color: #2d3748;
    border-color: #2d3748;
    transform: translateY(-1px);
}

/* 响应式调整 */
@media (max-width: 768px) {
    .camera-preview-wrapper {
        max-width: 95%;
        max-height: 95vh;
    }
    
    .camera-controls {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }
    
    .camera-controls .btn {
        min-width: 100%;
        padding: 12px 20px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .camera-preview-wrapper {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}