/* AI内容生产工具 - 优化版CSS */
/* 修复布局问题，适配新结构 */

/* ==================== 基础变量 ==================== */
:root {
    --primary-color: #4361ee;
    --secondary-color: #3a0ca3;
    --success-color: #4cc9f0;
    --info-color: #4895ef;
    --warning-color: #f72585;
    --danger-color: #e63946;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --border-color: #dee2e6;
    --sidebar-width: 380px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 5px 20px rgba(0, 0, 0, 0.15);
    --radius: 8px;
    --transition: all 0.3s ease;
}

/* ==================== 重置样式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #f5f7fa 0%, #f0f2f5 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== 顶部导航栏 ==================== */
.top-nav {
    background: white;
    padding: 0.8rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    height: 70px;
}

.nav-left h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* 按钮样式 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
}

/* 徽章 */
.badge {
    background: var(--warning-color);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    margin-left: 5px;
}

/* ==================== 历史记录下拉菜单 ==================== */
.history-dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius);
    width: 350px;
    max-height: 500px;
    overflow-y: auto;
    z-index: 1001;
    display: none;
    margin-top: 10px;
}

.history-dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-header h4 {
    color: var(--dark-color);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.history-items {
    padding: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.empty-history {
    padding: 20px;
    text-align: center;
    color: #666;
}

.history-item {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    border-radius: 4px;
    margin-bottom: 5px;
}

.history-item:hover {
    background: var(--light-color);
}

.history-item h5 {
    font-size: 0.9rem;
    color: var(--dark-color);
    margin-bottom: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-meta {
    font-size: 0.75rem;
    color: #666;
    display: flex;
    justify-content: space-between;
}

/* ==================== API配置模态框 ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--dark-color);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 1.2rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* 表单组 */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--dark-color);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.help-text {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 0.8rem;
}

.help-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.help-text a:hover {
    text-decoration: underline;
}

.test-connection {
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.test-result {
    font-size: 0.9rem;
    padding: 5px 10px;
    border-radius: 4px;
}

.test-result.success {
    background: #d4edda;
    color: #155724;
}

.test-result.error {
    background: #f8d7da;
    color: #721c24;
}

/* ==================== 主容器布局 ==================== */
.main-container {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 140px);
    overflow: hidden;
}

/* ==================== 左侧配置栏 ==================== */
.config-sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    flex-shrink: 0;
}

.sidebar-header h3 {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    margin-top: 0;
}

.content-type-tabs {
    display: flex;
    gap: 5px;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px;
    border-radius: 6px;
}

.tab-btn {
    flex: 1;
    padding: 8px 12px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
    font-size: 0.9rem;
}

.tab-btn.active {
    background: white;
    color: var(--primary-color);
}

.sidebar-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.config-form {
    display: none;
}

.config-form.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== 表单布局 ==================== */
.form-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.form-section:last-child {
    border-bottom: none;
}

.form-section h4 {
    color: var(--dark-color);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    margin-top: 0;
}

.row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

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

.col-6 {
    flex: 1;
}

.col-12 {
    flex: 1 0 100%;
}

textarea.form-control {
    min-height: 80px;
    resize: vertical;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23666' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

/* 文件上传样式 */
.file-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--light-color);
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 8px;
}

.file-label:hover {
    border-color: var(--primary-color);
    background: #eef2ff;
}

.file-input {
    display: none;
}

.file-name {
    font-size: 0.9rem;
    color: #666;
    margin-top: 5px;
}

/* 操作按钮 */
.action-buttons {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

/* ==================== 主内容区 ==================== */
.content-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    margin: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 0; /* 重要：让flex内容可以滚动 */
}

.content-header {
    padding: 20px;
    background: var(--light-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.header-left h2 {
    color: var(--dark-color);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.content-stats {
    margin-top: 5px;
    font-size: 0.85rem;
    color: #666;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.export-buttons {
    display: flex;
    gap: 10px;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-toggle::after {
    content: " ▾";
    font-size: 0.8em;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    box-shadow: var(--shadow);
    border-radius: 6px;
    padding: 5px 0;
    min-width: 180px;
    z-index: 100;
    display: none;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    color: var(--dark-color);
    text-decoration: none;
    transition: var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
}

.dropdown-item:hover {
    background: var(--light-color);
}

/* ==================== 内容区 ==================== */
.content-body {
    flex: 1;
    padding: 0;
    overflow-y: auto;
    position: relative;
    min-height: 0; /* 重要：让flex内容可以滚动 */
}

/* 加载状态 */
.loading-state {
    display: none;
    text-align: center;
    padding: 50px 20px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 100;
}

.loading-state.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner-container {
    max-width: 400px;
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.progress {
    height: 6px;
    background: #f0f0f0;
    border-radius: 3px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    width: 0%;
    border-radius: 3px;
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.loading-tips {
    margin-top: 30px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #666;
}

/* 占位符 */
.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.placeholder.hidden {
    display: none;
}

.placeholder-icon {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.placeholder h3 {
    color: #666;
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.placeholder p {
    margin-bottom: 10px;
    color: #777;
}

.placeholder-tips {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: #666;
}

/* 错误信息 */
.error-message {
    display: none;
    text-align: center;
    padding: 60px 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.error-message.hidden {
    display: none;
}

.error-message:not(.hidden) {
    display: flex;
}

.error-icon {
    font-size: 3rem;
    color: var(--danger-color);
    margin-bottom: 20px;
}

.error-message h3 {
    color: var(--danger-color);
    margin-bottom: 15px;
    font-size: 1.3rem;
}

#errorDetail {
    margin-bottom: 20px;
    color: #666;
    max-width: 500px;
    line-height: 1.5;
}

/* 生成内容区域 */
.generated-content {
    padding: 30px;
    line-height: 1.8;
    min-height: 100%;
    display: none;
}

.generated-content:not(.hidden) {
    display: block;
}

.generated-content .content-header {
    background: none;
    border-bottom: 2px solid var(--border-color);
    padding: 0 0 20px 0;
    margin-bottom: 30px;
}

.generated-content .content-header h1 {
    color: var(--primary-color);
    font-size: 2em;
    margin: 0 0 10px 0;
    padding: 0;
    border: none;
}

.content-meta {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: #666;
}

.content-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.content-body {
    font-size: 1rem;
    color: #333;
}

.content-body h1,
.content-body h2,
.content-body h3 {
    color: var(--dark-color);
    margin: 1.5em 0 0.8em;
    padding-bottom: 0.5em;
    border-bottom: 2px solid var(--border-color);
}

.content-body h1 {
    font-size: 2em;
    color: var(--primary-color);
}

.content-body h2 {
    font-size: 1.5em;
    color: var(--secondary-color);
}

.content-body h3 {
    font-size: 1.2em;
}

.content-body p {
    margin-bottom: 1em;
}

.content-body ul,
.content-body ol {
    margin: 1em 0;
    padding-left: 2em;
}

.content-body li {
    margin-bottom: 0.5em;
}

.content-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
}

.content-body th,
.content-body td {
    padding: 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.content-body th {
    background-color: var(--light-color);
    font-weight: 600;
}

.content-body blockquote {
    border-left: 4px solid var(--primary-color);
    padding: 1em;
    margin: 1.5em 0;
    background-color: #f8f9fa;
    font-style: italic;
}

.content-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    color: #666;
}

.disclaimer {
    font-style: italic;
    color: #777;
    font-size: 0.9rem;
}

.raw-content pre {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 6px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* 内容工具栏 */
.content-toolbar {
    padding: 15px 20px;
    background: var(--light-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    display: none;
}

.content-toolbar:not(.hidden) {
    display: flex;
}

.btn-toolbar {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--dark-color);
}

.btn-toolbar:hover {
    background: var(--light-color);
    border-color: var(--primary-color);
}

.btn-toolbar.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ==================== 底部 ==================== */
.footer {
    background: white;
    padding: 15px 2rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    flex-shrink: 0;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.footer-left p {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.footer-info {
    font-size: 0.8rem;
    color: #999;
    margin-top: 5px;
}

.footer-right {
    text-align: right;
}

.footer-right p {
    font-size: 0.85rem;
    color: #666;
    margin: 0 0 5px 0;
}

.footer-status {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 5px;
    font-size: 0.85rem;
}

.status-online {
    color: #28a745;
}

.status-offline {
    color: #dc3545;
}

/* ==================== Toast消息 ==================== */
.toast-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    border-radius: 8px;
    padding: 15px 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    z-index: 9999;
    transform: translateX(120%);
    transition: transform 0.3s ease;
    min-width: 300px;
    max-width: 400px;
    border-left: 4px solid #3498db;
}

.toast-message.show {
    transform: translateX(0);
}

.toast-success {
    border-left-color: #2ecc71;
}

.toast-error {
    border-left-color: #e74c3c;
}

.toast-warning {
    border-left-color: #f39c12;
}

.toast-info {
    border-left-color: #3498db;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast-content i {
    font-size: 1.2em;
}

.toast-success i { color: #2ecc71; }
.toast-error i { color: #e74c3c; }
.toast-warning i { color: #f39c12; }
.toast-info i { color: #3498db; }

/* ==================== 响应式设计 ==================== */
@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
    }
    
    .config-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 60vh;
    }
    
    .content-main {
        margin: 20px;
    }
}

@media (max-width: 768px) {
    .top-nav {
        padding: 0.8rem 1rem;
        flex-direction: column;
        gap: 10px;
        height: auto;
        min-height: 70px;
    }
    
    .nav-left, .nav-right {
        width: 100%;
        justify-content: center;
    }
    
    .row {
        flex-direction: column;
        gap: 10px;
    }
    
    .col-6 {
        width: 100%;
    }
    
    .content-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        padding: 15px;
    }
    
    .header-right {
        width: 100%;
        justify-content: center;
    }
    
    .export-buttons {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .footer-right {
        text-align: center;
    }
    
    .footer-status {
        justify-content: center;
    }
    
    .dropdown-content {
        width: 300px;
        right: -50%;
    }
    
    .modal-content {
        width: 95%;
    }
}

@media (max-width: 480px) {
    .sidebar-header {
        padding: 15px;
    }
    
    .sidebar-body {
        padding: 15px;
    }
    
    .content-main {
        margin: 10px;
    }
    
    .content-header {
        padding: 15px;
    }
    
    .generated-content {
        padding: 15px;
    }
    
    .export-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .dropdown-content {
        width: 280px;
        right: -30%;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .top-nav,
    .config-sidebar,
    .content-header,
    .content-toolbar,
    .footer,
    .toast-message {
        display: none !important;
    }
    
    .main-container {
        display: block;
        margin: 0;
    }
    
    .content-main {
        box-shadow: none;
        margin: 0;
        border-radius: 0;
    }
    
    .content-body {
        padding: 0;
    }
    
    .generated-content {
        padding: 0;
    }
    
    body {
        background: white;
        font-size: 12pt;
    }
    
    .generated-content .content-header {
        display: block;
        border: none;
        padding: 0 0 20pt 0;
    }
    
    .content-meta {
        display: none;
    }
}