* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    height: 100vh;
    padding: 20px;
    overflow: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* ========== Header ========== */
header {
    background: white;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
}

.nav-links {
    display: flex;
    gap: 10px;
    margin-right: 30px;
}

.nav-links a {
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    color: #666;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.nav-links a:hover {
    background: #e3f2fd;
    color: #1976d2;
}

.nav-links a.active {
    background: #1976d2;
    color: white;
    border-color: #1976d2;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    color: #666;
    font-size: 14px;
}

.btn-logout {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    color: #666;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.btn-logout:hover {
    border-color: #1976d2;
    color: #1976d2;
}

/* ========== Main Content ========== */
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ========== Session Sidebar ========== */
.session-sidebar {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-header {
    padding: 16px 18px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.sidebar-header h2 {
    color: #1976d2;
    font-size: 16px;
}

.btn-new-session {
    padding: 5px 12px;
    border: 1px solid #1976d2;
    border-radius: 6px;
    background: white;
    color: #1976d2;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-new-session:hover {
    background: #1976d2;
    color: white;
}

.tenant-selector {
    padding: 12px 14px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

/* Combo box */
.combo-box {
    position: relative;
}

.combo-box input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}

.combo-box input:focus {
    outline: none;
    border-color: #1976d2;
}

.combo-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
}

.combo-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
}

.combo-item:last-child {
    border-bottom: none;
}

.combo-item:hover {
    background: #e3f2fd;
}

.combo-id {
    font-weight: 500;
    color: #333;
}

.combo-score {
    font-size: 12px;
    font-weight: 600;
    color: #28a745;
    background: #e6f9ed;
    padding: 2px 6px;
    border-radius: 10px;
}

.combo-score.untrained {
    color: #999;
    background: #f0f0f0;
}

/* Session list */
.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.session-list-empty {
    text-align: center;
    color: #bbb;
    font-size: 13px;
    padding: 30px 10px;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    position: relative;
    border-left: 3px solid transparent;
}

.session-item:hover {
    background: #f0f7ff;
}

.session-item.active {
    background: #e3f2fd;
    border-left-color: #1976d2;
}

.session-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-item-meta {
    font-size: 11px;
    color: #999;
    margin-top: 3px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.session-item-accuracy {
    font-size: 11px;
    font-weight: 600;
    color: #28a745;
}

.session-item-status {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
}

.session-item-status.running {
    background: #fff3e0;
    color: #e65100;
}

.session-item-status.completed {
    background: #e8f5e9;
    color: #2e7d32;
}

.session-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: #ccc;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    display: none;
    align-items: center;
    justify-content: center;
}

.session-item:hover .session-item-delete {
    display: flex;
}

.session-item-delete:hover {
    background: #fee;
    color: #e53935;
}

/* ========== Chat Panel ========== */
.chat-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.chat-header {
    padding: 14px 24px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header h2 {
    color: #1976d2;
    font-size: 18px;
    margin: 0;
}

.chat-status {
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 500;
}

.chat-status.running {
    background: #fff3e0;
    color: #e65100;
}

.chat-status.completed {
    background: #e8f5e9;
    color: #2e7d32;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.btn-action {
    padding: 6px 14px;
    font-size: 13px;
    border: 1px solid #1976d2;
    border-radius: 6px;
    background: white;
    color: #1976d2;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-action:hover {
    background: #1976d2;
    color: white;
}

.btn-action:disabled {
    border-color: #ccc;
    color: #ccc;
    cursor: not-allowed;
}

.btn-action:disabled:hover {
    background: white;
    color: #ccc;
}

/* ========== Chat Messages ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.placeholder-content {
    text-align: center;
    color: #999;
}

.placeholder-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.placeholder-title {
    font-size: 18px;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}

.placeholder-hint {
    font-size: 14px;
    color: #999;
}

/* Message bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 90%;
}

.message.user {
    align-self: flex-end;
}

.message.assistant,
.message.system {
    align-self: flex-start;
}

.message-label {
    font-size: 12px;
    color: #999;
    margin-bottom: 4px;
}

.message.user .message-label {
    text-align: right;
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.message.user .message-content {
    background: #1976d2;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #f5f5f5;
    color: #333;
    border-bottom-left-radius: 4px;
}

/* System messages (status/diff) */
.message.system .message-content {
    background: #e3f2fd;
    color: #1565c0;
    border-left: 3px solid #1976d2;
    font-size: 13px;
    border-bottom-left-radius: 4px;
}

.message.system.success .message-content {
    background: #e8f5e9;
    color: #2e7d32;
    border-left-color: #43a047;
}

.message.system.error .message-content {
    background: #fce4ec;
    color: #c62828;
    border-left-color: #e53935;
}

.message.system.warning .message-content {
    background: #fff8e1;
    color: #e65100;
    border-left-color: #ff9800;
}

/* Accuracy badge in messages */
.accuracy-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 13px;
    margin-left: 6px;
}

.accuracy-badge.high {
    background: #e8f5e9;
    color: #2e7d32;
}

.accuracy-badge.medium {
    background: #fff8e1;
    color: #e65100;
}

.accuracy-badge.low {
    background: #fce4ec;
    color: #c62828;
}

/* Diff display in messages */
.diff-summary {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    font-size: 13px;
}

.diff-summary .diff-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.diff-summary .diff-row:last-child {
    border-bottom: none;
}

.diff-field {
    font-weight: 500;
}

.diff-expected {
    color: #2e7d32;
}

.diff-actual {
    color: #c62828;
}

/* Markdown in assistant messages */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
    margin: 12px 0 6px 0;
    color: #1976d2;
}

.message.assistant .message-content h1 { font-size: 18px; }
.message.assistant .message-content h2 { font-size: 16px; }
.message.assistant .message-content h3 { font-size: 14px; }

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message.assistant .message-content li {
    margin-bottom: 3px;
}

/* Code blocks — all message types */
.message-content code {
    background: #e8e8e8;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: pre-wrap;
    word-break: break-all;
}

.message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    max-width: 100%;
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    word-break: break-all;
}

.message.assistant .message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    table-layout: fixed;
    overflow-x: auto;
    display: block;
}

.message.assistant .message-content th,
.message.assistant .message-content td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    font-size: 13px;
    text-align: left;
}

.message.assistant .message-content th {
    background: #e3f2fd;
    font-weight: 600;
}

/* Streaming cursor */
.streaming-cursor::after {
    content: '|';
    animation: blink 0.8s infinite;
    color: #1976d2;
    font-weight: bold;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ========== Chat Input ========== */
.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.3s;
    max-height: 120px;
}

.chat-input-area textarea:focus {
    border-color: #1976d2;
}

.btn-attach {
    background: white;
    border: 1px solid #ddd;
    padding: 6px 10px;
    font-size: 18px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    transition: all 0.2s;
}

.btn-attach:hover {
    border-color: #1976d2;
    background: #f0f7ff;
}

.btn-attach.has-files {
    border-color: #43a047;
    background: #e8f5e9;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send {
    background: #1976d2;
    color: white;
    padding: 8px 20px;
    font-size: 14px;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: #1565c0;
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-generate {
    background: #e65100;
    color: white;
    padding: 8px 16px;
    font-size: 13px;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-generate:hover:not(:disabled) {
    background: #bf360c;
}

.btn-generate:disabled {
    background: #ccc;
    cursor: not-allowed;
}
}

/* ========== 文件配置 - 居中模态弹窗 ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 5vh;
    overflow-y: auto;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-dialog {
    background: white;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    width: 760px;
    max-width: 96vw;
    min-height: 520px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 15px;
    color: #333;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: 4px;
    transition: all 0.15s;
}

.modal-close:hover {
    color: #e53935;
    background: #fce4ec;
}

.modal-body {
    padding: 14px 18px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.modal-body .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
    margin-bottom: 8px;
}

.modal-body .form-row:last-child {
    margin-bottom: 0;
}

.modal-body .form-group {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.modal-body .form-group label {
    display: block;
    color: #555;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 0;
    flex: 0 0 auto;
    width: 88px;
    text-align: left;
    line-height: 1.3;
}

.modal-body .form-group > input,
.modal-body .form-group > select,
.modal-body .form-group > textarea {
    flex: 1 1 0;
    min-width: 0;
}

/* file-list 强制换行到 input 下方，保持源/目标文件在同一行 */
.modal-body .form-group > .file-list {
    flex-basis: 100%;
    margin-left: 96px;
}

.modal-body .form-group input[type="file"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px dashed #ccc;
    border-radius: 6px;
    font-size: 12px;
    height: 34px;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 0.2s;
}

.modal-body .form-group input[type="file"]:hover {
    border-color: #1976d2;
}

.modal-body .form-group input[type="text"],
.modal-body .form-group input[type="number"] {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    height: 34px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.modal-body .form-group input[type="text"]:focus,
.modal-body .form-group input[type="number"]:focus {
    outline: none;
    border-color: #1976d2;
}

.modal-body .form-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    height: 34px;
    box-sizing: border-box;
    background: white;
    transition: border-color 0.2s;
}

.modal-body .form-group select:focus {
    outline: none;
    border-color: #1976d2;
}

.modal-body .form-row-full {
    grid-template-columns: 1fr;
}

.modal-body .form-row-full .form-group {
    align-items: stretch;
    flex-direction: column;
}

.modal-body .form-row-full .form-group label {
    width: 100%;
    margin-bottom: 4px;
    padding-top: 0;
}

.modal-body .form-group textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.modal-body .form-group textarea:focus {
    outline: none;
    border-color: #1976d2;
}

.file-list {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}

.file-list:empty {
    display: none;
}

.file-list .file-item {
    padding: 2px 6px;
    background: #f5f5f5;
    border-radius: 4px;
    margin-top: 2px;
    display: inline-block;
}

/* ========== Scrollbars ========== */
.chat-messages::-webkit-scrollbar,
.session-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.session-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.session-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.session-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .session-sidebar {
        max-height: 200px;
    }
}

/* ========== Animation ========== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ========== 下载按钮区 ========== */
.download-bar {
    border-left-color: #1976d2 !important;
}

.download-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.download-btn {
    display: inline-block;
    padding: 6px 14px;
    background: #e3f2fd;
    color: #1565c0;
    border-radius: 6px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid #90caf9;
}

.download-btn:hover {
    background: #bbdefb;
}

.analyze-btn {
    background: #fff3e0;
    color: #e65100;
    border-color: #ffcc80;
}

.analyze-btn:hover {
    background: #ffe0b2;
}

.prompt-btn {
    background: #f3e5f5;
    color: #7b1fa2;
    border-color: #ce93d8;
}

.prompt-btn:hover {
    background: #e1bee7;
}

/* ========== 迭代代码折叠 ========== */
.iteration-code-summary {
    padding: 8px 12px !important;
    background: #f5f5f5 !important;
    border-left-color: #78909c !important;
    color: #333 !important;
}

.code-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #546e7a;
    user-select: none;
}

.code-summary-header:hover {
    color: #1976d2;
}

.code-toggle-icon {
    font-size: 11px;
    color: #999;
}

.code-collapse {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.code-collapse.expanded {
    max-height: 600px;
    overflow-y: auto;
}

.code-collapse pre {
    margin-top: 8px !important;
    font-size: 12px !important;
    max-height: 560px;
    overflow: auto;
}

/* ========== 训练文件信息 ========== */
.session-files-content {
    font-size: 12px;
    color: #666;
}

.files-section {
    margin-bottom: 4px;
}

.file-download-link {
    color: #1565c0;
    text-decoration: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e3f2fd;
    font-size: 12px;
    display: inline-block;
    margin: 1px 2px;
}

.file-download-link:hover {
    background: #bbdefb;
    text-decoration: underline;
}

/* ========== 会话标题行 + 重命名按钮 ========== */
.session-item-title-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.session-item-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.session-item-rename {
    flex-shrink: 0;
    border: none;
    background: none;
    color: #999;
    font-size: 13px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.session-item:hover .session-item-rename {
    opacity: 1;
}

.session-item-rename:hover {
    color: #1976d2;
    background: #e3f2fd;
}
