* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f7fa;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
}

header.fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

nav {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

nav a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.3s;
}

nav a:hover, nav a.active {
    background: rgba(255,255,255,0.2);
    color: white;
}

main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

main.with-fixed-header {
    margin-top: 120px;
}

h2 {
    color: #333;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-head h2 {
    margin-bottom: 0;
}

.algorithm-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toolbar-msg {
    font-size: 0.9rem;
    color: #666;
}

.toolbar-msg.ok-text {
    color: #2e7d32;
}

.toolbar-msg.err-text {
    color: #c62828;
}

.toolbar-msg.loading-text {
    color: #667eea;
}

.assign-team {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: #f8f9ff;
    border-radius: 8px;
    border: 1px solid #e8eafa;
}

.assign-label {
    font-size: 0.82rem;
    color: #555;
    font-weight: 600;
}

.assign-team select {
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 0.85rem;
    max-width: 11rem;
}

.assign-feedback {
    font-size: 0.82rem;
    color: #666;
}

.assign-feedback.err-text {
    color: #c62828;
}

.assign-feedback.ok-text {
    color: #2e7d32;
}

.assign-feedback.loading-text {
    color: #667eea;
}

.team-line {
    margin-bottom: 0.5rem;
}

.team-badge {
    display: inline-block;
    font-size: 0.82rem;
    color: #5c4a8a;
    background: rgba(102, 126, 234, 0.12);
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    font-weight: 500;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: #555;
}

.filter-item select,
.filter-item input[type="search"] {
    min-width: 11rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.results-section-title {
    margin-top: 2.5rem;
    margin-bottom: 0.35rem;
}

.section-hint {
    color: #888;
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

.results-table-wrap {
    background: white;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
}

.results-merge-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-merge-table th,
.results-merge-table td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.results-merge-table th {
    color: #555;
    font-weight: 600;
    background: #fafbff;
}

.result-file-main {
    font-weight: 600;
    color: #333;
    line-height: 1.35;
}

.result-file-sub {
    margin-top: 0.2rem;
    font-size: 0.82rem;
    color: #777;
    line-height: 1.35;
}

.result-actions {
    white-space: nowrap;
}

.results-merge-table input[type="text"],
.results-merge-table select {
    width: 100%;
    min-width: 7rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid #d8d8d8;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #fff;
}

.result-meta-feedback {
    display: inline-block;
    margin-left: 0.35rem;
    font-size: 0.82rem;
    color: #666;
}

.result-meta-feedback.ok-text {
    color: #2e7d32;
}

.result-meta-feedback.err-text {
    color: #c62828;
}

.result-meta-feedback.loading-text {
    color: #667eea;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 1rem 0 0.5rem;
}

.pager-info {
    color: #555;
    font-size: 0.9rem;
}

.btn-inline {
    margin-right: 0.35rem;
    text-decoration: none;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
}

.detail-actions {
    margin-bottom: 1rem;
}

/* 新建算法弹窗 */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 14px;
    padding: 1.5rem 1.75rem;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    overflow: hidden;
}

.modal-dialog.modal-lg {
    max-width: 760px;
}

.modal-dialog.modal-xl {
    max-width: 1100px;
    width: min(1100px, 96vw);
    display: flex;
    flex-direction: column;
}

.modal-pre {
    margin-top: 0.75rem;
    background: #101010;
    color: #d9d9d9;
    border-radius: 8px;
    padding: 0.9rem;
    max-height: 52vh;
    overflow: auto;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

.modal-code-editor {
    width: 100%;
    min-height: 62vh;
    max-height: 70vh;
    background: #101010;
    color: #ddd;
    border: 1px solid #2e2e2e;
    border-radius: 8px;
    padding: 0.8rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.5;
    resize: vertical;
}

#modal-code .CodeMirror {
    height: 62vh;
    border: 1px solid #2e2e2e;
    border-radius: 8px;
    font-size: 0.88rem;
}

#modal-result-table-wrap {
    flex: 1;
    min-height: 0;
    max-height: 68vh;
    overflow: auto;
}

#modal-result-table-wrap .results-merge-table {
    min-width: 100%;
}

.modal-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.modal-dialog h3 {
    margin-bottom: 0.5rem;
    color: #333;
}

.modal-desc {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.modal-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
    font-size: 0.88rem;
    color: #444;
}

.modal-field select {
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 0.95rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.back-link {
    margin-bottom: 1rem;
}

.back-link a {
    color: #667eea;
    text-decoration: none;
}

.back-link a:hover {
    text-decoration: underline;
}

.meta {
    color: #666;
    margin-bottom: 1rem;
}

/* 算法卡片 */
.algorithm-list, .file-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.algorithm-card, .file-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: transform 0.3s, box-shadow 0.3s;
}

.algorithm-card:hover, .file-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.algorithm-card h3, .file-card h3 {
    color: #333;
    margin-bottom: 0.5rem;
}

.algorithm-card h3 a, .file-card h3 a {
    color: #333;
    text-decoration: none;
}

.algorithm-card h3 a:hover, .file-card h3 a:hover {
    color: #667eea;
}

.description, .algorithm {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.list-meta {
    color: #8a8a8a;
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
}

.actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.btn-run, .btn-view {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-run {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-run:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-view {
    background: #f0f0f0;
    color: #333;
}

.btn-view:hover {
    background: #e0e0e0;
}

.no-result {
    color: #999;
    font-size: 0.9rem;
}

.output {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.loading {
    color: #667eea;
    font-style: italic;
}

.result h4 {
    margin-bottom: 0.5rem;
    color: #333;
}

.result pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.85rem;
    margin: 0.5rem 0;
}

.stdout {
    color: #28a745;
}

.stderr {
    color: #dc3545;
}

.error {
    background: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border-radius: 6px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 100%;
}

.data-table th, .data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.data-table th {
    background: #f5f7fa;
    font-weight: 600;
    color: #333;
    position: sticky;
    top: 0;
    z-index: 1;
}

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

.note {
    margin-top: 1rem;
    color: #999;
    font-size: 0.85rem;
}

/* 可视化控制 */
.visualization-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: #333;
}

.control-group select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

#loadChart {
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

#loadChart:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* 图表容器 */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-wrapper {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.chart-wrapper.wide {
    grid-column: 1 / -1;
}

.chart-wrapper h3, .chart-wrapper h4 {
    color: #333;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.chart {
    width: 100%;
    height: 350px;
}

.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* 概览区域 */
.summary-section {
    margin-bottom: 2rem;
}

.summary-cards {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.summary-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 150px;
}

.summary-card .count {
    font-size: 2.5rem;
    font-weight: 700;
    color: #667eea;
}

.summary-card .label {
    color: #666;
    margin-top: 0.5rem;
}

/* 对比表格 */
.comparison-section {
    margin-bottom: 2rem;
}

.comparison-table-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    overflow-x: auto;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.comparison-table th, .comparison-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.comparison-table th {
    background: #f5f7fa;
    font-weight: 600;
    color: #333;
}

.comparison-table tr:hover {
    background: #f9fafc;
}

.algorithm-tag {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
}

/* 原始数据区域 */
.raw-data-section {
    margin-top: 2rem;
}

.raw-data-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.data-panel {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.data-panel h4 {
    color: #333;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.algo-badge {
    background: #f0f0f0;
    color: #666;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: normal;
}

.mini-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.mini-data-table th, .mini-data-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.mini-data-table th {
    background: #f5f7fa;
    font-weight: 600;
    color: #333;
}

.data-preview {
    max-height: 300px;
    overflow-y: auto;
}

/* 代码展示样式 */
body.code-page {
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

body.code-page h2 {
    color: #333;
}

.code-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.code-page-head h2 {
    margin-bottom: 0;
}

.code-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.code-toolbar .btn-view.active {
    background: #667eea;
    color: white;
}

.btn-save-code {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-save-code:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(17, 153, 142, 0.35);
}

.code-panel {
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

/* CodeMirror：预览与编辑共用 Python 语法高亮 */
.cm-host {
    flex: 1;
    min-height: 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #333;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.cm-host .CodeMirror {
    height: 100%;
    font-size: 0.9rem;
    line-height: 1.55;
}

.cm-host .CodeMirror-focused {
    outline: 2px solid rgba(102, 126, 234, 0.55);
    outline-offset: 0;
}

/* 表格页面样式 */
body.table-page {
    min-height: 100vh;
    overflow: hidden;
}

.data-table-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.table-scroll {
    flex: 1;
    overflow: auto;
    border-radius: 8px;
    border: 1px solid #eee;
    min-height: 0;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.4rem;
    }
    
    nav {
        flex-wrap: wrap;
    }
    
    .algorithm-list, .file-list, .charts-container {
        grid-template-columns: 1fr;
    }
    
    .visualization-controls {
        flex-direction: column;
    }
    
    .chart {
        height: 250px;
    }
    
    .chart-row {
        grid-template-columns: 1fr;
    }
    
    .raw-data-container {
        grid-template-columns: 1fr;
    }
}
