/* 全局样式 */
* {
    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, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部样式 */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

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

/* 系统提示词区域 */
.system-prompt-section {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
}

/* 配置区域 - 紧凑设计 */
.config-section {
    background: white;
    border-radius: 15px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
}

.config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.config-header h3 {
    color: #495057;
    font-size: 1.1rem;
    margin: 0;
}

.toggle-btn {
    padding: 6px 12px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    background: #5a6268;
}

.manage-btn {
    padding: 6px 12px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-right: 8px;
}

.manage-btn:hover {
    background: #0056b3;
}

.config-content {
    transition: all 0.3s ease;
    overflow: hidden;
}

.config-content.collapsed {
    max-height: 0;
    margin: 0;
    padding: 0;
}

.model-config {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.model-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #e9ecef;
}

.model-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.model-label {
    font-weight: 600;
    color: #495057;
    font-size: 0.9rem;
}

.model-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.compact-input {
    padding: 8px 10px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s ease;
}

.compact-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* 下拉选择组合样式 */
.input-with-dropdown {
    display: flex;
    gap: 5px;
    align-items: center;
}

.dropdown-select {
    padding: 8px 10px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 140px;
    flex-shrink: 0;
}

.dropdown-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.dropdown-select:hover {
    border-color: #adb5bd;
}

.api-input, .model-input {
    flex: 1;
    min-width: 0;
}

/* 当选择自定义时，输入框高亮 */
.api-input.custom-active, .model-input.custom-active {
    border-color: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.1);
}

.test-btn-small {
    padding: 4px 8px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.test-btn-small:hover {
    background: #218838;
}

.test-btn-small:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.connection-status-small {
    margin-top: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    text-align: center;
    min-height: 20px;
}

.connection-status-small.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.connection-status-small.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.connection-status-small.testing {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    animation: pulse 2s infinite;
}

/* 用户输入区域 - 紧凑设计 */
.input-section {
    background: linear-gradient(135deg, #999db6 0%, #7486a7 100%);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    border: 1px solid #e3ecff;
    position: sticky;
    bottom: 15px;
    z-index: 10;
}

/* 确保内部白色区域不超出边界 */
.input-section .user-input-container,
.input-section .input-container {
    background: white;
    border-radius: 8px;
    padding: 15px;
    margin: 0;
}

.system-prompt-container {
    margin-bottom: 20px;
}

.user-input-container {
    margin-bottom: 10px;
}

.input-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.input-row textarea {
    flex: 1;
}

.input-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 100px;
}

.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.prompt-header h3 {
    color: #495057;
    font-size: 1rem;
    margin: 0;
}

.prompt-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.prompt-controls {
    display: flex;
    gap: 15px;
    align-items: center;
}

.action-btn {
    padding: 6px 12px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

.preset-select {
    padding: 6px 10px;
    border: 1px solid #dee2e6;
    border-radius: 5px;
    font-size: 12px;
    background: white;
    cursor: pointer;
}

.help-text {
    text-align: center;
    margin-top: 8px;
    color: #6c757d;
}

.help-text small {
    font-size: 11px;
}

#user-prompt, #user-prompt-a, #user-prompt-b {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.3s ease;
}

#system-prompt, #system-prompt-a, #system-prompt-b {
    width: 100%;
    padding: 15px;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.3s ease;
}

#system-prompt {
    margin-bottom: 15px;
}

#system-prompt:focus, #user-prompt:focus,
#system-prompt-a:focus, #system-prompt-b:focus,
#user-prompt-a:focus, #user-prompt-b:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-button, .new-conversation-button {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.new-conversation-button {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: white;
}

.new-conversation-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 193, 7, 0.3);
}

.send-button:active, .new-conversation-button:active {
    transform: translateY(0);
}

.send-button:disabled, .new-conversation-button:disabled {
    background: #6c757d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.conversation-history {
    min-height: 500px;
    max-height: 70vh;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #f8f9fa;
    padding: 15px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
    font-style: italic;
    min-height: 300px;
}

.history-item {
    padding: 12px 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-item.user {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1565c0;
    border-left: 4px solid #2196f3;
}

.history-item.assistant {
    background: linear-gradient(135deg, #f3e5f5 0%, #e1bee7 100%);
    color: #7b1fa2;
    border-left: 4px solid #9c27b0;
}

.history-item .role {
    font-weight: bold;
    margin-bottom: 6px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-item .content {
    line-height: 1.5;
    white-space: pre-wrap;
}

/* 结果区域 */
.results-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 120px; /* 为底部输入区域留出空间 */
}

.result-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.result-left, .result-right {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
    border: 2px solid #e9ecef;
    min-height: 400px;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #dee2e6;
}

.result-header h3 {
    color: #495057;
    font-size: 1.2rem;
}

.status {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status.ready {
    background: #d1ecf1;
    color: #0c5460;
}

.status.loading {
    background: #fff3cd;
    color: #856404;
    animation: pulse 2s infinite;
}

.status.success {
    background: #d4edda;
    color: #155724;
}

.status.error {
    background: #f8d7da;
    color: #721c24;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.result-content {
    height: calc(100% - 60px);
    display: flex;
    flex-direction: column;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #6c757d;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
}

.time-info, .token-info {
    background: #e9ecef;
    padding: 4px 8px;
    border-radius: 4px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .model-config,
    .result-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .conversation-history {
        min-height: 400px;
        max-height: 60vh;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .config-section,
    .prompt-section,
    .results-section {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    .result-left, .result-right {
        min-height: 300px;
    }
    
    /* 移动端下拉选择样式优化 */
    .input-with-dropdown {
        flex-direction: column;
        gap: 5px;
        align-items: stretch;
    }
    
    .dropdown-select {
        min-width: auto;
        width: 100%;
    }
    
    .input-section {
        padding: 12px 15px;
        margin-top: 15px;
        bottom: 10px;
    }
    
    .input-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .input-actions {
        flex-direction: row;
        justify-content: stretch;
        gap: 8px;
    }
    
    .send-button, .new-conversation-button {
        flex: 1;
        padding: 10px 12px;
        font-size: 0.8rem;
    }
    
    .help-text {
        margin-top: 6px;
    }
    
    .help-text small {
        font-size: 10px;
    }
    
    /* 移动端分离输入布局 */
    .separate-inputs {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .prompt-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .prompt-controls {
        gap: 10px;
    }
    
    .toggle-label {
        font-size: 12px;
    }
}

/* 加载动画 */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 切换开关样式 */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-size: 13px;
    color: #495057;
    font-weight: 500;
    user-select: none;
}

/* 分离输入样式 */
.separate-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 15px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 13px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 5px;
}

.separate-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    padding-top: 10px;
    border-top: 1px solid #dee2e6;
}

.send-both {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    padding: 10px 20px;
    font-weight: 600;
}

.send-both:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.3);
}

.system-container {
    transition: all 0.3s ease;
}

.input-container {
    transition: all 0.3s ease;
}

/* 滚动条样式 */
.response-text::-webkit-scrollbar {
    width: 6px;
}

.response-text::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.response-text::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.response-text::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #dee2e6;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

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

.close {
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    color: white;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.close:hover {
    opacity: 1;
}

.modal-body {
    padding: 25px;
}

.add-item-section {
    margin-bottom: 30px;
}

.add-item-section h4 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1rem;
}

.add-item-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.modal-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 12px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.modal-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.add-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.items-list-section h4 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 1rem;
}

.items-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #f8f9fa;
}

.item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #e9ecef;
    background: white;
    margin-bottom: 1px;
}

.item-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.item-info {
    flex: 1;
}

.item-name {
    font-weight: 600;
    color: #495057;
    margin-bottom: 4px;
}

.item-value {
    font-size: 12px;
    color: #6c757d;
    word-break: break-all;
}

.item-actions {
    display: flex;
    gap: 8px;
}

.edit-btn, .delete-btn {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.edit-btn {
    background: #ffc107;
    color: #212529;
}

.edit-btn:hover {
    background: #e0a800;
}

.delete-btn {
    background: #dc3545;
    color: white;
}

.delete-btn:hover {
    background: #c82333;
}

.empty-list {
    padding: 30px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

/* 编辑状态样式 */
.item-row.editing .item-info {
    display: none;
}

.item-row.editing .edit-form {
    display: flex;
    gap: 8px;
    flex: 1;
    align-items: center;
}

.edit-form {
    display: none;
}

.edit-form input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 12px;
}

.save-btn, .cancel-btn {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.save-btn {
    background: #28a745;
    color: white;
}

.cancel-btn {
    background: #6c757d;
    color: white;
}
