/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: #f0f2f5;
    color: #333;
    min-height: 100vh;
}

/* ===== OCR Mode Toggle ===== */
.ocr-mode-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: #f0f2f5;
    border-radius: 8px;
    padding: 4px;
    max-width: 320px;
}
.mode-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    text-align: center;
}
.mode-btn:hover { color: #1a237e; background: rgba(255,255,255,0.5); }
.mode-btn.active { background: #fff; color: #1a237e; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

/* ===== Manual Section ===== */
.manual-section { max-width: 900px; margin: 0 auto; }
.manual-section .col-card { min-height: auto; }
.manual-section .form-group { margin-bottom: 16px; }
.manual-section .form-group label {
    font-size: 14px;
    font-weight: 500;
    color: #444;
    margin-bottom: 8px;
    display: block;
}

/* ===== Header ===== */
.header {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    color: #fff;
    padding: 16px 32px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1200px; margin: 0 auto; }
.logo { font-size: 20px; font-weight: 600; }
.version { font-size: 12px; opacity: 0.7; background: rgba(255,255,255,0.15); padding: 2px 8px; border-radius: 10px; }

/* ===== Tab Nav ===== */
.tab-nav {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 32px 0;
    gap: 4px;
}
.tab-btn {
    padding: 12px 24px;
    border: none;
    background: #e8eaf6;
    color: #5c6bc0;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
}
.tab-btn:hover { background: #c5cae9; }
.tab-btn.active { background: #fff; color: #1a237e; box-shadow: 0 -2px 8px rgba(0,0,0,0.05); }

/* ===== Main Content ===== */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px 32px;
}
.tab-panel {
    display: none;
    background: #fff;
    border-radius: 0 8px 8px 8px;
    padding: 32px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.tab-panel.active { display: block; }

.panel-header { margin-bottom: 24px; }
.panel-header h2 { font-size: 22px; color: #1a237e; margin-bottom: 6px; }
.panel-desc { font-size: 14px; color: #666; }

/* ===== Two Column Layout ===== */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.col-card {
    background: #fafafa;
    border: 1px solid #e8eaf6;
    border-radius: 8px;
    padding: 20px;
}
.col-title {
    font-size: 16px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid;
}
.target-color { color: #1565c0; border-color: #1565c0; }
.other-color { color: #c62828; border-color: #c62828; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #555; margin-bottom: 6px; }
.form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s;
    appearance: auto;
}
.form-select:focus { border-color: #1a237e; outline: none; box-shadow: 0 0 0 2px rgba(26,35,126,0.1); }
.form-select:disabled { background: #f5f5f5; color: #999; }
.form-select-sm { max-width: 280px; }

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s;
}
.form-input:focus { border-color: #1a237e; outline: none; box-shadow: 0 0 0 2px rgba(26,35,126,0.1); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-grid .form-group { margin-bottom: 0; }

/* ===== Buttons ===== */
.btn-row { display: flex; gap: 12px; margin: 24px 0; }
.btn-primary {
    padding: 12px 32px;
    background: #1a237e;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover:not(:disabled) { background: #283593; }
.btn-primary:disabled { background: #bbb; cursor: not-allowed; }
.btn-secondary {
    padding: 12px 24px;
    background: #fff;
    color: #666;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover { border-color: #999; color: #333; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-lg { padding: 14px 40px; font-size: 16px; font-weight: 600; }

/* ===== Result Area ===== */
.result-area { margin-top: 24px; }
.hidden { display: none !important; }

.result-summary {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 20px 24px;
    background: linear-gradient(135deg, #e8eaf6 0%, #f5f5f5 100%);
    border-radius: 8px;
    margin-bottom: 20px;
}
.result-badge {
    font-size: 28px;
    font-weight: 700;
    padding: 12px 28px;
    border-radius: 8px;
    color: #fff;
    background: #1a237e;
    min-width: 100px;
    text-align: center;
}
.result-badge.duty-full { background: #c62828; }
.result-badge.duty-main { background: #e65100; }
.result-badge.duty-same { background: #2e7d32; }
.result-badge.duty-sub { background: #1565c0; }
.result-badge.duty-none { background: #757575; }

.result-diff { font-size: 16px; color: #333; }
.diff-num { font-size: 24px; font-weight: 700; color: #1a237e; }
.result-match { font-size: 14px; color: #666; }
.match-tag { font-weight: 600; padding: 2px 10px; border-radius: 10px; font-size: 12px; }
.match-tag.exact { background: #e8f5e9; color: #2e7d32; }
.match-tag.fuzzy { background: #fff3e0; color: #e65100; }

/* ===== OCR Duty Text ===== */
.ocr-duty-text { font-weight: 600; }
.ocr-duty-text.duty-full { color: #c62828; }
.ocr-duty-text.duty-main { color: #e65100; }
.ocr-duty-text.duty-same { color: #2e7d32; }
.ocr-duty-text.duty-sub { color: #1565c0; }
.ocr-duty-text.duty-none { color: #757575; }

/* ===== Verification Comparison ===== */
.verify-party-card { padding-bottom: 16px; }
.verify-identity {
    display: flex;
    gap: 16px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: #f5f7fa;
    border-radius: 6px;
    font-size: 13px;
    color: #555;
    flex-wrap: wrap;
}
.identity-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.identity-label {
    color: #888;
}
.identity-value {
    color: #333;
    font-weight: 500;
}
.verify-compare-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid #e8eaf6;
}
.verify-col { text-align: center; flex: 1; }
.verify-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 6px;
    font-weight: 500;
}
.verify-badge {
    font-size: 18px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 6px;
    color: #fff;
    background: #9e9e9e;
    display: inline-block;
    min-width: 80px;
}
.verify-badge.duty-full { background: #c62828; }
.verify-badge.duty-main { background: #e65100; }
.verify-badge.duty-same { background: #2e7d32; }
.verify-badge.duty-sub { background: #1565c0; }
.verify-badge.duty-none { background: #757575; }
.verify-badge.duty-unknown { background: #bdbdbd; color: #666; font-size: 14px; }

.verify-arrow {
    font-size: 20px;
    color: #9e9e9e;
    flex-shrink: 0;
}
.verify-match {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
}
.verify-match.match-yes { background: #e8f5e9; color: #2e7d32; }
.verify-match.match-no { background: #ffebee; color: #c62828; }
.verify-match.match-unknown { background: #fff3e0; color: #e65100; }

/* ===== Law Article Comparison ===== */
.verify-law-compare {
    display: flex;
    gap: 16px;
    padding: 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid #e8eaf6;
}
.verify-law-col {
    flex: 1;
    padding: 10px 12px;
    background: #f8f9ff;
    border-radius: 6px;
    border: 1px solid #e8eaf6;
}
.verify-law-label {
    font-size: 12px;
    color: #666;
    font-weight: 600;
    margin-bottom: 6px;
}
.verify-law-ref {
    font-size: 13px;
    font-weight: 600;
    color: #1a237e;
    margin-bottom: 6px;
    line-height: 1.5;
}
.verify-law-article {
    font-size: 12px;
    color: #555;
    line-height: 1.7;
    max-height: 120px;
    overflow-y: auto;
    background: #fff;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid #eee;
}
.verify-law-article:empty { display: none; }

/* ===== Detail Cards ===== */
.detail-card {
    background: #fafafa;
    border: 1px solid #e8eaf6;
    border-radius: 8px;
    padding: 16px;
}
.detail-card h4 { margin-bottom: 12px; font-size: 15px; }
.detail-item { margin-bottom: 8px; font-size: 13px; line-height: 1.6; }
.detail-item .label { font-weight: 600; color: #555; }
.detail-item .value { color: #333; }
.detail-item .article { color: #666; font-size: 12px; line-height: 1.5; margin-top: 4px; padding: 8px; background: #f5f5f5; border-radius: 4px; }

/* ===== Bar Chart (Pure CSS) ===== */
.chart-area { margin-top: 20px; }
.chart-area h4 { margin-bottom: 16px; font-size: 15px; color: #333; }
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    height: 200px;
    padding: 0 20px 30px;
    border-bottom: 2px solid #e0e0e0;
    position: relative;
}
.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}
.bar {
    width: 48px;
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease;
    position: relative;
    min-height: 4px;
}
.bar-label {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.bar-name {
    margin-top: 8px;
    font-size: 12px;
    color: #666;
    text-align: center;
}
.bar-0 { background: linear-gradient(180deg, #c62828, #e57373); }
.bar-1 { background: linear-gradient(180deg, #e65100, #ffb74d); }
.bar-2 { background: linear-gradient(180deg, #2e7d32, #81c784); }
.bar-3 { background: linear-gradient(180deg, #1565c0, #64b5f6); }
.bar-4 { background: linear-gradient(180deg, #757575, #bdbdbd); }

.small-chart { height: 150px; }
.small-chart .bar { width: 36px; }

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 24px;
    color: #999;
    font-size: 12px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .two-col { grid-template-columns: 1fr; }
    .tab-nav { flex-wrap: wrap; padding: 12px 16px 0; }
    .tab-btn { flex: 1; min-width: 120px; font-size: 13px; padding: 10px 12px; }
    .main-content { padding: 0 16px 16px; }
    .tab-panel { padding: 20px; }
    .form-grid { grid-template-columns: 1fr; }
    .result-summary { flex-direction: column; text-align: center; }
}

/* ===== Error State ===== */
.error-msg {
    background: #ffebee;
    color: #c62828;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    margin: 12px 0;
    border-left: 4px solid #c62828;
}

/* ===== OCR Tab Styles ===== */

/* Upload area */
.ocr-upload-panel { text-align: center; }
.upload-zone {
    border: 2px dashed #c5cae9;
    border-radius: 12px;
    padding: 40px 20px;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbff;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: #1a237e;
    background: #eef0ff;
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-text { font-size: 16px; color: #333; font-weight: 500; margin-bottom: 6px; }
.upload-hint { font-size: 12px; color: #999; }

/* Upload preview */
.upload-preview { margin: 16px 0; }
.upload-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}
.preview-name { font-size: 12px; color: #666; margin-top: 6px; }
.btn-reselect { margin-top: 8px; padding: 4px 12px; font-size: 12px; background: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; color: #555; }
.btn-reselect:hover { background: #e8e8e8; }

/* Loading */
.ocr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    color: #1a237e;
    font-size: 15px;
}
.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #e0e0e0;
    border-top-color: #1a237e;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result sections */
.ocr-result { margin-top: 16px; }
.ocr-section {
    background: #f8f9ff;
    border: 1px solid #e0e3f0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}
.ocr-section-title {
    font-size: 15px;
    color: #1a237e;
    margin-bottom: 12px;
}
.ocr-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.ocr-info-item {
    font-size: 13px;
    line-height: 1.6;
}
.ocr-info-item .label {
    font-weight: 600;
    color: #555;
    margin-right: 6px;
}
.ocr-info-item .value {
    color: #333;
}

/* Party card in OCR */
.ocr-party-card .ocr-info-item { margin-bottom: 8px; }

/* Mapping section inside party cards */
.ocr-mapping-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed #ddd;
}
.mapping-title {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin-bottom: 10px;
    margin-top: 12px;
}

/* Status badges for mapping validation */
.status-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
    display: inline-block;
    vertical-align: middle;
}
.status-exact { background: #e8f5e9; color: #2e7d32; }
.status-fuzzy { background: #fff3e0; color: #e65100; }
.status-mismatch { background: #ffebee; color: #c62828; }
.status-inferred { background: #e3f2fd; color: #1565c0; }

/* Unextracted field highlight - red border and background */
.unextracted-field {
    border: 2px solid #d32f2f !important;
    background-color: #ffebee !important;
    color: #d32f2f !important;
    font-weight: 600 !important;
}
.unextracted-field::placeholder {
    color: #d32f2f !important;
    opacity: 0.7 !important;
}
select.unextracted-field {
    border: 2px solid #d32f2f !important;
    background-color: #ffebee !important;
    color: #d32f2f !important;
}
select.unextracted-field option {
    color: #333;
    background-color: #fff;
}

/* Age row */
.ocr-age-row {
    margin-top: 16px;
    max-width: 300px;
}

/* Notes and warnings */
.ocr-notes {
    background: #fffde7;
    border: 1px solid #fff9c4;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 13px;
    color: #555;
    line-height: 1.6;
}
.ocr-warnings {
    background: #fff3e0;
    border: 1px solid #ffe0b2;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 13px;
    color: #e65100;
    line-height: 1.6;
}
.ocr-warnings ul { margin: 6px 0 0 18px; }
.ocr-warnings li { margin-bottom: 4px; }

/* OCR action buttons */
.ocr-actions { margin-top: 24px; }

/* ===== Model 2 - AI Text Extraction ===== */
.m2-extract-area {
    background: #f0f4ff;
    border: 1px solid #c5cae9;
    border-radius: 10px;
    padding: 20px;
}
.m2-extract-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.m2-extract-icon { font-size: 20px; }
.m2-extract-title {
    font-size: 15px;
    font-weight: 700;
    color: #1a237e;
}
.m2-extract-desc {
    font-size: 12px;
    color: #666;
    margin-left: 4px;
}
.m2-textarea {
    width: 100%;
    box-sizing: border-box;
    font-size: 13px;
    line-height: 1.7;
    padding: 12px;
    border: 1px solid #c5cae9;
    border-radius: 6px;
    resize: vertical;
    min-height: 100px;
    font-family: inherit;
    color: #333;
    background: #fff;
    transition: border-color 0.2s;
}
.m2-textarea:focus {
    outline: none;
    border-color: #5c6bc0;
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.15);
}
.m2-textarea::placeholder { color: #aaa; }
.m2-extract-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}
.btn-sm {
    padding: 6px 16px;
    font-size: 13px;
    border-radius: 6px;
}
.m2-extract-status {
    font-size: 12px;
    color: #666;
}
.m2-extract-status.status-loading { color: #1565c0; }
.m2-extract-status.status-success { color: #2e7d32; }
.m2-extract-status.status-partial { color: #e65100; }
.m2-extract-status.status-error { color: #c62828; }
/* 图片预览点击效果 */
.upload-preview img { cursor: zoom-in; }
.upload-preview img:hover { opacity: 0.85; }

/* 大图预览模态框 */
.image-viewer-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px 80px;
}
.image-viewer-modal.hidden { display: none; }
.image-viewer-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
}
.image-viewer-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;
}
.image-viewer-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}
.image-viewer-content img {
    max-width: 88vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    transition: width 0.2s ease, height 0.2s ease;
    cursor: default;
}
.image-viewer-content img.zoomed {
    max-width: none;
    max-height: none;
    cursor: grab;
}

/* 工具栏 */
.image-viewer-toolbar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    background: rgba(0,0,0,0.55);
    border-radius: 8px;
    padding: 6px 10px;
    z-index: 10001;
    backdrop-filter: blur(6px);
}
.iv-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.iv-btn:hover { background: rgba(255,255,255,0.25); }
.iv-btn:active { background: rgba(255,255,255,0.35); }
.image-viewer-close {
    position: fixed;
    top: 16px; right: 24px;
    font-size: 36px;
    color: #fff;
    cursor: pointer;
    z-index: 10000;
    line-height: 1;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    transition: opacity 0.2s;
}
.image-viewer-close:hover { opacity: 0.7; }