/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* 左侧导航栏 */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 30px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

/* 搜索框 */
.search-box {
    padding: 15px 20px;
    position: relative;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.search-input {
    width: 100%;
    padding: 10px 35px 10px 15px;
    border: none;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.search-input::placeholder {
    color: #999;
}

.search-input:focus {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-clear-search {
    position: absolute;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.2);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 24px;
    padding: 0;
    text-align: center;
    transition: all 0.2s ease;
}

.btn-clear-search:hover {
    background: rgba(0, 0, 0, 0.3);
}

.category {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.category-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    opacity: 0.9;
}

.subject-list {
    list-style: none;
}

.subject-item {
    padding: 12px 15px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.subject-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(5px);
}

.subject-item.active {
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.subject-name {
    font-size: 15px;
    font-weight: 500;
}

.subject-meta {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 4px;
}

/* 右侧主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    min-width: 0;
    overflow: hidden;
}

/* 欢迎页 */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-content h2 {
    font-size: 32px;
    color: #667eea;
    margin-bottom: 16px;
}

.welcome-content > p {
    font-size: 18px;
    color: #666;
    margin-bottom: 40px;
}

.welcome-instructions {
    display: flex;
    flex-direction: column;
    gap: 24px;
    text-align: left;
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.instruction-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    flex-shrink: 0;
}

.instruction-item p {
    flex: 1;
    padding-top: 6px;
    font-size: 16px;
    color: #555;
}

/* 对话区域 */
.chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-header {
    padding: 20px 30px;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    flex-shrink: 0;
}

.chat-header h2 {
    font-size: 20px;
    color: #333;
}

.chat-header-actions {
    display: flex;
    gap: 10px;
}

.btn-export {
    padding: 8px 16px;
    background: #52c41a;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

.btn-export:hover {
    background: #389e0d;
}

.btn-new-conversation {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

.btn-new-conversation:hover {
    background: #5568d3;
}

/* 导出弹窗 */
.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.export-modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.export-modal-content h3 {
    margin: 0 0 24px 0;
    color: #333;
    font-size: 22px;
    text-align: center;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.export-option-btn {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px 20px;
    background: #f5f7fa;
    border: 2px solid #e8e8e8;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 15px;
}

.export-option-btn:hover {
    background: #667eea;
    border-color: #667eea;
    color: white;
    transform: translateX(5px);
}

.export-icon {
    font-size: 24px;
}

.export-label {
    font-weight: 500;
}

.export-close-btn {
    width: 100%;
    padding: 10px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

.export-close-btn:hover {
    background: #e0e0e0;
}

.chat-messages {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background-color: #f9fafb;
    min-height: 0;
}

.message {
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
    display: flex;
    flex-direction: column;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    align-items: flex-end;
}

.message-ai {
    align-items: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 12px;
    line-height: 1.7;
    font-size: 15px;
}

.message-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    padding: 0 4px;
    max-width: 70%;
}

.message-time {
    font-size: 12px;
    color: #999;
}

.btn-copy {
    padding: 4px 10px;
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    opacity: 0;
}

.message:hover .btn-copy {
    opacity: 1;
}

.btn-copy:hover {
    background: rgba(102, 126, 234, 0.2);
}

/* 错误消息样式 */
.message-error {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}

.error-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #fff3f3;
    border: 1px solid #ffccc7;
    border-radius: 8px;
    color: #ff4d4f;
    font-size: 14px;
}

.error-icon {
    font-size: 18px;
}

.error-text {
    flex: 1;
}

.btn-retry {
    padding: 6px 14px;
    background: #ff4d4f;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.3s ease;
}

.btn-retry:hover {
    background: #ff7875;
}

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

.message-ai .message-content {
    background: white;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Markdown样式支持 */
.message-ai .message-content h1,
.message-ai .message-content h2,
.message-ai .message-content h3,
.message-ai .message-content h4 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
    color: #667eea;
    line-height: 1.4;
}

.message-ai .message-content h1 { font-size: 24px; }
.message-ai .message-content h2 { font-size: 20px; }
.message-ai .message-content h3 { font-size: 18px; }
.message-ai .message-content h4 { font-size: 16px; }

.message-ai .message-content h1:first-child,
.message-ai .message-content h2:first-child,
.message-ai .message-content h3:first-child {
    margin-top: 0;
}

.message-ai .message-content p {
    margin-bottom: 12px;
    line-height: 1.8;
}

.message-ai .message-content p:last-child {
    margin-bottom: 0;
}

.message-ai .message-content ul,
.message-ai .message-content ol {
    margin: 12px 0;
    padding-left: 28px;
    list-style-position: outside;
}

.message-ai .message-content ul {
    list-style-type: disc;
}

.message-ai .message-content ol {
    list-style-type: decimal;
}

.message-ai .message-content li {
    margin-bottom: 8px;
    line-height: 1.7;
    padding-left: 4px;
}

.message-ai .message-content strong {
    font-weight: 600;
    color: #667eea;
}

.message-ai .message-content em {
    font-style: italic;
    color: #555;
}

.message-ai .message-content code {
    background: #f5f7fa;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #e83e8c;
}

.message-ai .message-content pre {
    background: #f5f7fa;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 12px 0;
}

.message-ai .message-content pre code {
    background: none;
    padding: 0;
    color: #333;
}

.message-ai .message-content blockquote {
    border-left: 4px solid #667eea;
    padding-left: 16px;
    margin: 12px 0;
    color: #666;
    font-style: italic;
}

.message-ai .message-content hr {
    border: none;
    border-top: 2px solid #e8e8e8;
    margin: 20px 0;
}

.message-ai .message-content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.message-ai .message-content a:hover {
    border-bottom-color: #667eea;
}

.typing-indicator {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 16px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    max-width: 70%;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 6px;
}

.typing-dot {
    width: 10px;
    height: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.typing-text {
    font-size: 14px;
    color: #667eea;
    font-weight: 500;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: scale(0.8) translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: scale(1.2) translateY(-8px);
        opacity: 1;
    }
}

/* 输入区域 */
.chat-input-area {
    padding: 20px 30px;
    border-top: 1px solid #e8e8e8;
    display: flex;
    gap: 12px;
    background: white;
    flex-shrink: 0;
    min-height: fit-content;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e8e8e8;
    border-radius: 8px;
    font-size: 15px;
    resize: none;
    font-family: inherit;
    transition: border-color 0.3s ease, opacity 0.3s ease;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-send {
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: #ccc;
}

/* 滚动条样式 */
.sidebar::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }
    
    .message-content {
        max-width: 80%;
    }
}

@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    .container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 40vh;
        min-width: 100%;
        border-right: none;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    }
    
    .sidebar-header h1 {
        font-size: 20px;
    }
    
    .search-box {
        padding: 10px 15px;
    }
    
    .category {
        padding: 15px;
    }
    
    .category-title {
        font-size: 14px;
    }
    
    .subject-item {
        padding: 10px 12px;
    }
    
    .subject-name {
        font-size: 14px;
    }
    
    .subject-meta {
        font-size: 11px;
    }
    
    .main-content {
        flex: 1;
    }
    
    .chat-header {
        padding: 15px 20px;
    }
    
    .chat-header h2 {
        font-size: 18px;
    }
    
    .chat-messages {
        padding: 20px 15px;
    }
    
    .message-content {
        max-width: 90%;
        font-size: 14px;
        padding: 12px 16px;
    }
    
    .message-ai .message-content h2 {
        font-size: 18px;
    }
    
    .message-ai .message-content h3 {
        font-size: 16px;
    }
    
    .message-footer {
        max-width: 90%;
    }
    
    .chat-input-area {
        padding: 15px;
        gap: 8px;
    }
    
    .chat-input {
        font-size: 14px;
        padding: 10px 12px;
    }
    
    .btn-send {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    .welcome-content h2 {
        font-size: 22px;
    }
    
    .instruction-item p {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        max-height: 35vh;
    }
    
    .sidebar-header {
        padding: 20px 15px;
    }
    
    .sidebar-header h1 {
        font-size: 18px;
    }
    
    .subtitle {
        font-size: 12px;
    }
    
    .message-content {
        max-width: 95%;
        font-size: 13px;
        padding: 10px 14px;
    }
    
    .chat-input-area {
        flex-direction: column;
        padding: 12px;
    }
    
    .btn-send {
        width: 100%;
        padding: 12px;
    }
    
    .btn-new-conversation {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .btn-copy {
        font-size: 11px;
        padding: 3px 8px;
    }
    
    .message-time {
        font-size: 11px;
    }
}



/* 流式消息样式 */
.message-streaming {
    position: relative;
}

.message-streaming .message-content {
    position: relative;
}

.streaming-cursor {
    display: inline-block;
    color: #667eea;
    font-weight: bold;
    margin-left: 2px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}
