/* 导入现代字体 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

/* 根变量定义 */
:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
    --bg-gray: #e9ecef;
    --text-dark: #333333;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
    
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 深色模式变量 */
.dark-mode {
    --bg-light: #2d2d2d;
    --bg-white: #1a1a1a;
    --bg-gray: #383838;
    --text-dark: #ffffff;
    --text-muted: #a0a0a0;
    --border-color: #444444;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* 主体样式 */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: var(--transition);
}

.dark-mode body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
}

/* 聊天容器 */
.chat-container {
    width: 100%;
    max-width: 800px;
    background: var(--bg-white);
    padding: 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    height: 85vh;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: var(--transition);
}

/* 消息区域 */
.messages {
    flex: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    padding: 20px;
    border-radius: var(--border-radius-sm);
    background: var(--bg-light);
    font-size: 16px;
    transition: var(--transition);
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) var(--bg-light);
}

/* 自定义滚动条 */
.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* 消息样式 */
.message {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    animation: slideIn 0.3s ease-out;
}

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

.message img,
.text-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.message-content {
    padding: 16px 20px;
    border-radius: var(--border-radius);
    max-width: 75%;
    font-size: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    position: relative;
    transition: var(--transition);
}

/* 用户消息样式 */
.message.user {
    flex-direction: row-reverse;
}

.message.user img,
.message.user .text-avatar {
    margin-left: 12px;
    margin-right: 0;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    text-align: right;
    border-bottom-right-radius: 4px;
}

/* 机器人消息样式 */
.message.bot .message-content {
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* 消息内容样式 */
.message-content .title {
    font-size: 1.25em;
    font-weight: 600;
    display: block;
    margin: 0 0 12px 0;
    color: inherit;
}

.message-content p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-content .bold-text {
    font-weight: 600;
    font-size: 1.05em;
}

.message-content .section-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: var(--primary-color);
}

.message-content .subsection {
    margin: 8px 0 8px 20px;
}

.message-content .subtitle {
    font-weight: 600;
}

/* 内联代码样式 */
.message-content .inline-code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.dark-mode .message-content .inline-code {
    background: rgba(255, 255, 255, 0.1);
}

/* 输入区域 */
.input-container {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--bg-light);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.input-container input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 16px;
    background: var(--bg-white);
    color: var(--text-dark);
    transition: var(--transition);
    font-family: inherit;
}

.input-container input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.input-container input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 按钮样式 */
.input-container button {
    padding: 12px 20px;
    min-width: 80px;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.input-container button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.input-container button:active {
    transform: translateY(0);
}

.input-container button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 下拉菜单样式 */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--bg-white);
    min-width: 180px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius-sm);
    z-index: 1000;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    animation: dropdownSlide 0.2s ease-out;
}

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

.dropdown-content.show {
    display: block;
}

.dropdown-item {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-dark);
    font-weight: 500;
}

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

.dropdown-item:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 加载状态 */
.loading {
    text-align: center;
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 20px;
    padding: 20px;
    background: var(--bg-light);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
}

/* 通知样式 */
.notification {
    font-family: inherit;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .chat-container {
        height: 90vh;
        padding: 16px;
        border-radius: var(--border-radius-sm);
    }

    .messages {
        padding: 16px;
        font-size: 15px;
    }

    .input-container {
        gap: 8px;
        padding: 12px;
    }

    .input-container input {
        font-size: 16px; /* 防止iOS缩放 */
        padding: 12px;
    }

    .input-container button {
        padding: 12px 16px;
        min-width: 60px;
        font-size: 14px;
    }

    .message img,
    .text-avatar {
        width: 32px;
        height: 32px;
    }

    .message-content {
        font-size: 15px;
        max-width: 80%;
        padding: 12px 16px;
    }
    
    .dropdown-content {
        min-width: 140px;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 85%;
    }
    
    .input-container {
        flex-wrap: wrap;
    }
    
    .input-container input {
        min-width: 200px;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-muted: #000000;
    }
    
    .dark-mode {
        --border-color: #ffffff;
        --text-muted: #ffffff;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 打印样式 */
@media print {
    body {
        background: white;
    }
    
    .chat-container {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .input-container {
        display: none;
    }
}