/* ========================================
   Lucas2026 Admin - AI Chat 完整样式表
   修复重点：平台提示显示、深色模式覆盖、历史标识冲突、缺失样式
   ======================================== */

/* ===== 全局重置与变量 ===== */
:root {
    --primary: #667eea;
    --secondary: #764ba2;
    --openai-primary: #1e3a8a;
    --openai-secondary: #0f172a;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg-light: #f8f9ff;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 6px 12px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

[data-theme="dark"] {
    --bg-light: #0f172a;
    --card-bg: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.25);
    --shadow-hover: 0 6px 12px rgba(0, 0, 0, 0.35);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-light) 0%, #eef1ff 100%);
    color: var(--text);
    line-height: 1.5;
    padding: 20px;
    min-height: 100vh;
    transition: var(--transition);
}

/* ===== 布局容器 ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
}

@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
    }
}

/* ===== 头部区域 ===== */
header {
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
    transition: var(--transition);
}

.logo-section {
    text-align: center;
    margin-bottom: 16px;
}

.logo-container {
    display: inline-block;
    margin-bottom: 12px;
}

.logo {
    width: 100%;
    max-width: 320px;
    height: auto;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-top: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.5px;
}

/* ===== 平台选择器（修复深色模式覆盖问题） ===== */
.platform-selector {
    display: flex;
    gap: 8px;
    margin: 12px 0;
    justify-content: center;
    flex-wrap: wrap;
}

.platform-btn {
    padding: 10px 20px;
    border-radius: 12px;
    background: rgba(102, 126, 234, 0.1);
    border: 2px solid transparent;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
    color: var(--text);
    min-width: 140px;
    justify-content: center;
}

.platform-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: translateY(-1px);
}

.platform-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-color: #5a67d8;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.platform-btn[data-platform="openai"] {
    background: rgba(30, 58, 138, 0.1);
}

.platform-btn[data-platform="openai"]:hover {
    background: rgba(30, 58, 138, 0.2);
}

.platform-btn[data-platform="openai"].active {
    background: linear-gradient(135deg, var(--openai-primary) 0%, var(--openai-secondary) 100%);
    border-color: var(--openai-primary);
    box-shadow: 0 4px 12px rgba(30, 58, 138, 0.3);
}

/* 深色模式专属修复：避免覆盖平台颜色 */
[data-theme="dark"] .platform-btn:not(.active) {
    background: rgba(100, 116, 139, 0.15) !important;
    color: var(--text);
}

[data-theme="dark"] .platform-btn[data-platform="openai"]:not(.active) {
    background: rgba(30, 58, 138, 0.15) !important;
}

/* ===== API 密钥区域 ===== */
.api-key-section {
    margin: 16px 0;
}

.key-section {
    display: none;
    margin-bottom: 10px;
    animation: fadeIn 0.3s;
}

.key-section.active {
    display: block;
}

#deepseekApiKey, 
#openaiApiKey {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-size: 1rem;
    margin-bottom: 10px;
    background: var(--card-bg);
    color: var(--text);
    transition: var(--transition);
}

#deepseekApiKey:focus, 
#openaiApiKey:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#deepseekApiKey::placeholder,
#openaiApiKey::placeholder {
    color: var(--text-secondary);
    opacity: 1;
}

button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#saveOpenaiKeyBtn {
    background: linear-gradient(135deg, var(--openai-primary) 0%, var(--openai-secondary) 100%);
}

/* ===== 密钥状态指示器 ===== */
.key-status {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.85rem;
    padding: 0 5px;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
    font-size: 0.85rem;
}

.status-indicator::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
    flex-shrink: 0;
}

.status-indicator.valid::before {
    background: var(--success);
}

/* 深色模式增强：状态指示器圆点增加边框 */
[data-theme="dark"] .status-indicator::before {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

/* ===== 控制栏 ===== */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    margin-top: 16px;
    justify-content: center;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-selector label {
    font-weight: 500;
    color: var(--text-secondary);
}

#modelSelect {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 0.95rem;
    min-width: 180px;
    transition: var(--transition);
}

#modelSelect:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* ===== 联网搜索开关 ===== */
.web-search-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: var(--transition);
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.toggle-label {
    font-weight: 500;
    color: var(--text);
}

.tooltip-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(102, 126, 234, 0.15);
    color: var(--primary);
    border-radius: 50%;
    font-weight: bold;
    font-size: 0.75rem;
    cursor: help;
    transition: var(--transition);
}

.tooltip-icon:hover {
    background: rgba(102, 126, 234, 0.25);
    transform: scale(1.1);
}

/* ===== 主题切换按钮 ===== */
.theme-btn {
    background: rgba(148, 163, 184, 0.15) !important;
    color: var(--text) !important;
    padding: 8px 16px !important;
    min-width: auto !important;
}

.theme-btn:hover {
    background: rgba(100, 116, 139, 0.25) !important;
}

/* ===== 聊天容器 ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 220px);
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--card-bg);
    scroll-behavior: smooth;
}

/* 滚动条美化 */
.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 4px;
}

.chat-history::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
}

/* ===== 欢迎消息 ===== */
.welcome-message {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
    padding: 32px 24px;
    background: rgba(102, 126, 234, 0.05);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.welcome-message h2 {
    font-size: 1.8rem;
    margin-bottom: 16px;
    color: var(--text);
}

.welcome-message p {
    margin: 8px 0;
    color: var(--text-secondary);
    font-size: 1.05rem;
}

/* 平台提示（关键修复：移除CSS display控制，交由JS管理） */
.platform-note {
    margin: 15px 0;
    padding: 14px;
    border-radius: 12px;
    border-left: 3px solid #667eea;
    background: rgba(102, 126, 234, 0.08);
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.5;
}

.platform-note a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 500;
    transition: var(--transition);
}

.platform-note a:hover {
    color: var(--secondary);
}

.platform-note.deepseek-note {
    border-color: var(--primary);
    background: rgba(102, 126, 234, 0.08);
}

.platform-note.openai-note {
    border-color: var(--openai-primary);
    background: rgba(30, 58, 138, 0.08);
}

.security-note {
    margin-top: 12px;
    padding: 12px;
    background: rgba(22, 163, 74, 0.08);
    border-radius: 10px;
    border-left: 3px solid var(--success);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.web-search-note {
    margin-top: 12px;
    padding: 12px;
    background: rgba(245, 158, 11, 0.08);
    border-radius: 10px;
    border-left: 3px solid var(--warning);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* 高亮文本样式（修复缺失） */
.highlight {
    color: var(--error);
    font-weight: 600;
    background: rgba(239, 68, 68, 0.1);
    padding: 0 4px;
    border-radius: 4px;
    display: inline-block;
}

/* ===== 消息样式 ===== */
.message {
    max-width: 85%;
    padding: 16px 20px;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.3s;
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-radius: 18px 4px 4px 18px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px 18px 18px 4px;
    box-shadow: var(--shadow);
}

/* 平台标识徽章 */
.platform-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    width: fit-content;
}

.platform-badge .deepseek-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
}

.platform-badge .openai-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--openai-primary);
}

.message.assistant[data-platform="openai"] .platform-badge {
    background: rgba(30, 58, 138, 0.1);
}

/* 系统消息 */
.system-message {
    background: rgba(245, 158, 11, 0.15) !important;
    border-left: 3px solid var(--warning) !important;
    border-radius: 12px !important;
    padding: 16px !important;
    align-self: center !important;
    max-width: 90% !important;
    margin: 10px 0 !important;
    font-size: 0.95rem;
}

/* ===== 输入区域 ===== */
.input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    background: var(--card-bg);
}

#messageInput {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: 18px;
    font-size: 1.05rem;
    resize: none;
    min-height: 50px;
    max-height: 200px;
    background: var(--card-bg);
    color: var(--text);
    transition: var(--transition);
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#messageInput::placeholder {
    color: var(--text-secondary);
    opacity: 1;
}

#sendBtn {
    width: 50px;
    height: 50px;
    min-width: 50px;
    border-radius: 16px;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ===== 历史面板 ===== */
.history-panel {
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 24px;
    height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.history-panel h3 {
    font-size: 1.4rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 8px;
}

/* 滚动条美化 */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
}

.empty-history {
    text-align: center;
    color: var(--text-secondary);
    padding: 24px;
    font-style: italic;
}

/* 历史项（关键修复：重构平台标识） */
.history-item {
    padding: 14px;
    border-radius: 14px;
    background: rgba(102, 126, 234, 0.05);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item:hover {
    transform: translateX(4px);
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--primary);
}

.history-item.active {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

/* 平台专属历史项样式 */
.history-item[data-platform="openai"] {
    background: rgba(30, 58, 138, 0.05);
}

.history-item[data-platform="openai"]:hover {
    background: rgba(30, 58, 138, 0.1);
}

.history-item[data-platform="openai"].active {
    background: linear-gradient(135deg, rgba(30, 58, 138, 0.15) 0%, rgba(15, 23, 42, 0.15) 100%);
    border-color: var(--openai-primary);
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.2);
}

/* 历史项内容 */
.history-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.platform-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-tag {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
    flex-shrink: 0;
}

.history-item[data-platform="deepseek"] .model-tag {
    background: rgba(102, 126, 234, 0.2);
    color: var(--primary);
}

.history-item[data-platform="openai"] .model-tag {
    background: rgba(30, 58, 138, 0.2);
    color: var(--openai-primary);
}

.preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* 深色模式增强：历史项文字更清晰 */
[data-theme="dark"] .history-item {
    color: #e2e8f0;
}

[data-theme="dark"] .history-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ===== 清空历史按钮 ===== */
.clear-btn {
    background: rgba(239, 68, 68, 0.1) !important;
    color: var(--error) !important;
    margin-top: 16px;
    width: 100%;
    padding: 10px !important;
}

.clear-btn:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    transform: translateY(-1px) !important;
}

/* ===== 加载动画（修复缺失） ===== */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 动画 ===== */
@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(8px);
    }
    to { 
        opacity: 1; 
        transform: translateY(0);
    }
}

/* ===== 深色模式全局适配 ===== */
[data-theme="dark"] {
    background: linear-gradient(135deg, #0a0f1d 0%, #0d1323 100%);
}

[data-theme="dark"] header,
[data-theme="dark"] .chat-container,
[data-theme="dark"] .history-panel {
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

[data-theme="dark"] #messageInput,
[data-theme="dark"] #deepseekApiKey,
[data-theme="dark"] #openaiApiKey,
[data-theme="dark"] #modelSelect {
    background: #1e293b;
    border-color: #334155;
    color: var(--text);
}

[data-theme="dark"] #messageInput::placeholder,
[data-theme="dark"] #deepseekApiKey::placeholder,
[data-theme="dark"] #openaiApiKey::placeholder {
    color: #64748b;
}

[data-theme="dark"] .welcome-message {
    background: rgba(102, 126, 234, 0.08);
    border-color: #334155;
}

[data-theme="dark"] .message.assistant {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .system-message {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: #d97706 !important;
}

/* ===== 响应式设计 ===== */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        padding: 12px;
    }
    
    header {
        padding: 18px;
        margin-bottom: 16px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .platform-selector {
        flex-direction: column;
        align-items: stretch;
    }
    
    .platform-btn {
        width: 100%;
        justify-content: center;
        font-size: 1.1rem;
        min-width: auto;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .model-selector, 
    .web-search-toggle {
        width: 100%;
        justify-content: center;
    }
    
    .chat-container {
        height: calc(100vh - 280px);
    }
    
    .history-panel {
        height: auto;
        max-height: 400px;
        margin-top: 16px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .input-area {
        padding: 12px;
    }
    
    #messageInput {
        min-height: 44px;
        font-size: 1rem;
    }
    
    #sendBtn {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .logo {
        max-width: 280px;
    }
    
    .key-section {
        margin-bottom: 15px;
    }
    
    .status-indicator {
        font-size: 0.8rem;
        padding: 2px 6px;
    }
    
    .history-item .title {
        font-size: 0.95rem;
    }
    
    .model-tag {
        padding: 1px 6px;
        font-size: 0.7rem;
    }
}