/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* 头部样式 */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header h1 {
    font-size: 28px;
    font-weight: 600;
}

.api-key-section {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.api-key-section label {
    font-weight: 500;
}

.api-key-section input {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.9);
    min-width: 250px;
}

.api-key-section select {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
}

/* 主要内容区域 */
.main-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 0;
    min-height: 600px;
}

/* 配置面板样式 */
.config-panel {
    background: #f8f9fa;
    padding: 25px;
    border-right: 1px solid #e9ecef;
    overflow-y: auto;
    max-height: 900px;
}

.panel-section {
    margin-bottom: 30px;
}

.panel-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #2c3e50;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #495057;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input[type="range"] {
    width: calc(100% - 40px);
    margin-right: 10px;
}

.form-group small {
    display: block;
    margin-top: 4px;
    color: #6c757d;
    font-size: 12px;
}

/* 模型选择样式 */
.model-selection {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-selection select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    background-color: white;
}

.model-selection input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
}

.model-selection select:focus,
.model-selection input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
}

/* 操作面板样式 */
.operation-panel {
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.upload-section,
.generate-section,
.result-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.upload-section h3,
.result-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.upload-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    transition: border-color 0.2s ease;
    position: relative;
}

.upload-area:hover {
    border-color: #667eea;
}

.upload-label {
    cursor: pointer;
    color: #6c757d;
    display: block;
}

.upload-label span {
    font-size: 16px;
}

.image-preview {
    margin-top: 15px;
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

/* 生成按钮样式 */
.generate-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s ease;
    width: 100%;
}

.generate-btn:hover {
    transform: translateY(-2px);
}

.generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 主要按钮样式 - 与generate-btn保持一致的风格 */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    color: #6c757d;
}

.generation-timers {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.generation-timer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f1f3f5;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    color: #495057;
    border-left: 4px solid #667eea;
}

.generation-timer .timer-label {
    font-weight: 600;
    color: #343a40;
}

.generation-timer .timer-status.success {
    color: #28a745;
}

.generation-timer .timer-status.error {
    color: #dc3545;
}

.generation-timer .timer-status.warning {
    color: #d39e00;
}

.spinner {
    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); }
}

/* 结果区域样式 */
.result-container {
    min-height: 200px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    background: #f8f9fa;
}

.status-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.status-message {
    padding: 12px 15px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.status-message.info {
    background: #e8f4ff;
    border-left: 4px solid #1c7ed6;
    color: #1c7ed6;
}

.status-message.error {
    background: #fdecec;
    border-left: 4px solid #dc3545;
    color: #c92a2a;
}

.status-message.warning {
    background: #fff4e6;
    border-left: 4px solid #f08c00;
    color: #f08c00;
}

.status-message .status-time {
    font-size: 12px;
    color: #868e96;
}

.text-result {
    background: white;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #28a745;
}

.image-result img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

.image-result-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    font-size: 14px;
    color: #495057;
}

.image-result-info p {
    margin: 5px 0;
    line-height: 1.4;
}

.image-result-info p:first-child {
    font-weight: 600;
    color: #2c3e50;
}

.error-result {
    background: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #dc3545;
}

/* 历史记录面板样式 */
.history-panel {
    background: #f8f9fa;
    padding: 25px;
    border-top: 1px solid #e9ecef;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.history-header h3 {
    color: #2c3e50;
}

.history-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary:hover {
    background: #5a6268;
}

.history-stats {
    font-size: 14px;
    color: #6c757d;
}

.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.history-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: transform 0.2s ease;
    position: relative;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.history-item-content {
    pointer-events: none;
}

.history-thumbnail-container {
    display: flex;
    gap: 5px;
    width: 100%;
    height: 120px;
    margin-bottom: 10px;
}

.history-thumbnail-container .history-image {
    width: 50%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 0;
}

.history-thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 10px;
}

.history-summary {
    font-size: 14px;
    color: #495057;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #6c757d;
}

.history-size {
    font-size: 12px;
    color: #6c757d;
    margin-top: 5px;
}

.history-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.history-btn {
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s ease;
}

.history-btn:hover {
    background: #f8f9fa;
}

.history-btn.delete {
    color: #dc3545;
    border-color: #dc3545;
}

.history-btn.delete:hover {
    background: #dc3545;
    color: white;
}

.empty-history {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 40px;
    grid-column: 1 / -1;
}

/* 统计面板样式 */
.stats-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.stats-panel h4 {
    margin-bottom: 15px;
    color: #2c3e50;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.stat-item {
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 5px;
}

.stat-item span:last-child {
    font-weight: 600;
    color: #2c3e50;
    font-size: 16px;
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h4 {
    color: #2c3e50;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #dc3545;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

/* 图片放大模态框 */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.image-modal-content {
    max-width: 90%;
    max-height: 90%;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
}

.image-modal-close:hover {
    color: #ccc;
}

/* 可点击图片样式 */
.clickable-image {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.clickable-image:hover {
    transform: scale(1.02);
}

/* 图片信息展示 */
.image-info {
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 12px;
    color: #6c757d;
}

.image-info p {
    margin: 5px 0;
}

.image-size {
    font-weight: bold;
    color: #2c3e50;
}

/* 历史记录图片样式 */
.history-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 10px;
    cursor: pointer;
    position: relative;
}

.history-image:hover {
    opacity: 0.8;
}

.history-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

/* 图片加载状态样式 */
.image-loading-source {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    z-index: 1;
}

.image-error {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    color: #6c757d;
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
}

.image-unavailable {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
    color: #6c757d;
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
}

/* 根据加载源添加边框颜色 */
.history-image[data-loading-source="server"] {
    border: 2px solid #28a745;
}

.history-image[data-loading-source="url"] {
    border: 2px solid #ffc107;
}

.history-image[data-loading-source="local-path"] {
    border: 2px solid #17a2b8;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .config-panel {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        max-height: none;
    }
    
    .container {
        margin: 10px;
    }
    
    .header {
        flex-direction: column;
        text-align: center;
    }
    
    .api-key-section {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 24px;
    }
    
    .api-key-section input {
        min-width: 200px;
    }
    
    .history-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .history-controls {
        justify-content: space-between;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .header {
        padding: 15px;
    }
    
    .config-panel,
    .operation-panel,
    .history-panel {
        padding: 15px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
}

/* 工具提示样式 */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: white;
    text-align: center;
    border-radius: 6px;
    padding: 5px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 调试面板样式 */
.debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 500px;
    max-height: 400px;
    background: #2d3748;
    color: #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #1a202c;
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid #4a5568;
}

.debug-header h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.debug-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.debug-controls button {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid #4a5568;
    background: #2d3748;
    color: #e2e8f0;
    cursor: pointer;
}

.debug-controls button:hover {
    background: #4a5568;
}

.debug-controls label {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.debug-controls input[type="checkbox"] {
    margin: 0;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    background: #1a202c;
    max-height: 250px;
}

.debug-summary {
    padding: 12px 16px;
    background: #1a202c;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #4a5568;
    font-size: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.debug-summary div {
    display: flex;
    justify-content: space-between;
}

.debug-log-entry {
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid #4a5568;
}

.debug-log-entry.request {
    background: #2b6cb0;
    border-left-color: #3182ce;
}

.debug-log-entry.success {
    background: #276749;
    border-left-color: #38a169;
}

.debug-log-entry.error {
    background: #742a2a;
    border-left-color: #e53e3e;
}

.debug-log-entry.info {
    background: #2c5282;
    border-left-color: #3182ce;
}

.debug-log-timestamp {
    color: #a0aec0;
    font-size: 11px;
    margin-bottom: 4px;
}

.debug-log-message {
    margin-bottom: 4px;
}

.debug-log-details {
    color: #cbd5e0;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
}

.debug-log-url {
    color: #63b3ed;
    font-size: 11px;
    margin-bottom: 4px;
    word-break: break-all;
}

.debug-log-status {
    font-weight: bold;
    margin-bottom: 2px;
}

.debug-log-status.success {
    color: #68d391;
}

.debug-log-status.error {
    color: #fc8181;
}

.debug-log-status.warning {
    color: #fbbf24;
}

.debug-log-data {
    background: #2d3748;
    padding: 4px;
    border-radius: 2px;
    margin-top: 4px;
    overflow-x: auto;
}

.debug-log-data pre {
    margin: 0;
    font-size: 11px;
    color: #e2e8f0;
}

/* 用户上传图片样式 */
.history-image.user-upload {
    position: relative;
    border: 2px solid #6366f1; /* 紫色边框表示用户上传 */
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
}

.user-upload-badge {
    position: absolute;
    top: -8px;
    left: 4px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
    z-index: 2;
}

.history-image.user-upload img {
    border-radius: 4px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.history-image.user-upload:hover img {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.history-image .image-info {
    margin-top: 4px;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.history-image .image-info small {
    color: #6b7280;
    font-size: 10px;
    line-height: 1.2;
    display: block;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* 用户上传图片在历史记录中的布局优化 */
.history-images-container .history-image.user-upload {
    max-width: 120px;
    margin-right: 8px;
}

.history-images-container .history-image.user-upload img {
    max-height: 80px;
    object-fit: cover;
}
